/[drupal]/contributions/modules/frameprevention/frameprevention.module
ViewVC logotype

Contents of /contributions/modules/frameprevention/frameprevention.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.9 - (show annotations) (download) (as text)
Thu Mar 5 04:46:27 2009 UTC (8 months, 3 weeks ago) by deekayen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.8: +5 -2 lines
File MIME type: text/x-php
support new title requirement in D7 unstable 2 hook perm
1 <?php
2 // $Id: frameprevention.module,v 1.8 2008/07/29 13:29:39 deekayen Exp $
3
4 /**
5 * @file
6 *
7 * Prevent your Drupal site from being framed.
8 * For Drupal version 6.x.
9 *
10 * @author Ralf Dorfner
11 * @author David Kent Norman
12 */
13
14 /**
15 * Implementation of hook_perm().
16 *
17 * Valid permissions for the frameprevention module.
18 *
19 * @return array
20 */
21 function frameprevention_perm() {
22 return array(
23 'administer frameprevention' => array(
24 'title' => t('Administer frameprevention'),
25 'description' => t('Enable/disable frame prevention and set location exceptions for breaking out of frames.')
26 )
27 );
28 }
29
30 /**
31 * Implementation of hook_init().
32 */
33 function frameprevention_init() {
34 if (variable_get('frameprevention_enabled', 0)) {
35 if (!frameprevention_check()) {
36 $data = "\n<script type=\"text/javascript\">\n";
37 $data .= " /* <![CDATA[ */\n if(top.frames.length > 0) top.location.href=self.location;\n /* ]]> */\n";
38 $data .= "</script>\n";
39
40 drupal_set_html_head($data);
41 }
42 }
43 }
44
45 /**
46 * Implementation of hook_menu().
47 *
48 * @return array
49 */
50 function frameprevention_menu() {
51 $items = array();
52
53 $items['admin/settings/frameprevention'] = array(
54 'title' => 'Frameprevention',
55 'description' => 'Prevent your site from being framed.',
56 'page callback' => 'drupal_get_form',
57 'page arguments' => array('frameprevention_admin_settings'),
58 'access callback' => 'user_access',
59 'access arguments' => array('administer frameprevention'),
60 'type' => MENU_NORMAL_ITEM
61 );
62
63 return $items;
64 }
65
66 function frameprevention_admin_settings() {
67 $form = array();
68
69 $form['fp'] = array(
70 '#type' => 'fieldset',
71 '#title' => t('Prevent your site from being framed'),
72 '#tree' => FALSE
73 );
74 $form['fp']['frameprevention_enabled'] = array(
75 '#type' => 'checkbox',
76 '#title' => t('Enable Frameprevention'),
77 '#default_value' => variable_get('frameprevention_enabled', 0)
78 );
79 $form['fp']['frameprevention_pages'] = array(
80 '#type' => 'textarea',
81 '#title' => t('Pages'),
82 '#default_value' => variable_get('frameprevention_pages', 'img_assist/*'),
83 '#cols' => 30,
84 '#rows' => 5,
85 '#description' => t('List of pages the module is <b>disabled</b>. Use the <em>*</em> character for wildcard, each entry in a new line.')
86 );
87
88 return system_settings_form($form);
89 }
90
91 /**
92 * @return integer
93 */
94 function frameprevention_check() {
95 $pages = variable_get('frameprevention_pages', 'img_assist/*');
96 $path = drupal_get_path_alias($_GET['q']);
97 $regexp = '/^('. preg_replace(array('/(\r\n?|\n)/', '/\\\\\*/', '/(^|\|)\\\\<front\\\\>($|\|)/'), array('|', '.*', '\1'. variable_get('site_frontpage', 'node') .'\2'), preg_quote($pages, '/')) .')$/';
98 return preg_match($regexp, $path);
99 }

  ViewVC Help
Powered by ViewVC 1.1.2