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

Contents of /contributions/modules/dbfmgreybox/dbfmgreybox.module

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


Revision 1.1 - (show annotations) (download) (as text)
Fri Nov 9 16:15:20 2007 UTC (2 years ago) by rooey
Branch: MAIN
CVS Tags: DRUPAL-5--3-2, DRUPAL-5--3-1, DRUPAL-5--3-0, DRUPAL-5--2-0, DRUPAL-5--1-0, DRUPAL-5--1-1, DRUPAL-5--2-0-ALPHA1, DRUPAL-5--1-2, HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-php
by Rooey. Initial checkin.
1 <?php
2 // $Id: dbfmgreybox.module,v 1.9.2.6 2007/06/21 02:19:55 frjo Exp $
3
4 /**
5 * @file
6 * Author: Geoff Eagles based on work by Fredrik Jonsson
7 * The dbfmgreybox module is a simple wrapper for the jquery plugin
8 * dbfmgreybox http://jquery.com/blog/2006/02/10/dbfmgreybox-redux
9 */
10
11 /**
12 * Menu callback for admin_settings.
13 */
14 function dbfmgreybox_admin_settings() {
15 $form['dbfmgreybox_options'] = array(
16 '#type' => 'fieldset',
17 '#title' => t('Greybox configuration options')
18 );
19
20 //fill in which pages need to use dbfmgreybox
21 $form['dbfmgreybox_options']['dbfmgreybox_pages'] = array(
22 '#type' => 'textarea',
23 '#title' => t('Activate dbfmgreybox on specific page types'),
24 '#default_value' => variable_get('dbfmgreybox_pages', "dbfm,\nnode edit,\nnode add"),
25 '#description' => t('Enter one page type per line with a comma at the end of the line (for neatness). Example types might be "node" for all node pages or "node add" which limits the user to having dbfmgreybox only when adding nodes. "blog front" would just allow use on the front page of a blog. The reason you would want to disallow dbfmgreybox is because it saves loading the java code into the page header - pages should load faster! and it reduces possible interactions with other javascript'));
26
27 return system_settings_form($form);
28 }
29
30 /**
31 * Implementation of hook_menu().
32 */
33 function dbfmgreybox_menu($may_cache) {
34 global $user;
35
36 $items = array();
37
38 if ($may_cache) {
39 $items[] = array(
40 'path' => 'admin/settings/dbfmgreybox',
41 'title' => t('dbfmgreybox'),
42 'description' => t('Configure dbfmgreybox behavior.'),
43 'callback' => 'drupal_get_form',
44 'callback arguments' => 'dbfmgreybox_admin_settings',
45 'access' => user_access('administer site configuration'),
46 'type' => MENU_NORMAL_ITEM
47 );
48 }
49 else {
50 //used to add information to the header of all other modules that need dbfmgreybox
51
52 //rather than adding dbfmgreybox to every header we just add it to those pages that need it
53 //that saves the huge overhead of adding it eveywhere.
54 $path = drupal_get_path_alias($_GET['q']);
55 $page_list = variable_get('dbfmgreybox_pages', '');
56
57 //split the page list into an array of strings
58 $page_array = explode(',', $page_list);
59
60 foreach ($page_array as $pagetest) {
61
62 //now, wherever there's a space, split the page line into an array
63 //there might be no spaces but we just don't care
64 $page_elements = explode(' ',$pagetest);
65 //now we have to check that each element can be matched to the path
66 //and occurs in order
67 foreach ($page_elements as $matchthis) {
68 $mypos = stripos($path,trim($matchthis));
69 if ($mypos === FALSE) {
70 //nope it's not a match (bombs out on 1st fail)
71 $i = -1;
72 break;
73 }
74 $i = $mypos;
75 }
76 // we have to make sure that every word on the line is matched
77 if ($i > -1) {
78 _dbfmgreybox_doheader();
79 break;
80 }
81 }
82
83 }
84 return $items;
85 }
86
87 /**
88 * Loads the js and css files into your page header - though only if your page isn't on the disallowed list.
89 */
90 function _dbfmgreybox_doheader() {
91 $path = drupal_get_path('module', 'dbfmgreybox');
92 drupal_add_css($path .'/dbfmgreybox.css');
93 drupal_add_js($path .'/dbfmgreybox.js');
94 }
95

  ViewVC Help
Powered by ViewVC 1.1.2