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

Contents of /contributions/modules/sections/sections.module

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


Revision 1.23 - (show annotations) (download) (as text)
Mon Jun 2 17:16:19 2008 UTC (17 months, 3 weeks ago) by hass
Branch: MAIN
CVS Tags: HEAD
Changes since 1.22: +3 -3 lines
File MIME type: text/x-php
#265532: _sections_in_section() function fails on sites with db prefix
1 <?php
2 // $Id: sections.module,v 1.21.2.9 2008/06/02 17:12:55 hass Exp $
3
4 /**
5 * @file
6 * Allows you to define sections of your site and apply themes to those sections.
7 */
8
9 /**
10 * Implementation of hook_help().
11 */
12 function sections_help($path, $arg) {
13 switch ($path) {
14 case 'admin/modules#description':
15 return t('Allows you to define sections of your site and apply themes to those sections.');
16 }
17 }
18
19 /**
20 * Implementation of hook_perm().
21 *
22 * Since the access to our new custom pages will be granted based on
23 * special permissions, we need to define what those permissions are here.
24 * This ensures that they are available to enable on the user role
25 * administration pages.
26 */
27 function sections_perm() {
28 return array('administer sections');
29 }
30
31 /**
32 * Implementation of hook_menu().
33 */
34 function sections_menu() {
35 $access = array('administer sections');
36
37 $items['admin/build/sections'] = array(
38 'title' => 'Sections',
39 'description' => 'Define sections of your site and apply themes to them.',
40 'page callback' => 'drupal_get_form',
41 'page arguments' => array('sections_admin_display_form'),
42 'access arguments' => $access,
43 'file' => 'sections.admin.inc',
44 'type' => MENU_NORMAL_ITEM
45 );
46 $items['admin/build/sections/list'] = array(
47 'title' => 'List',
48 'page callback' => 'drupal_get_form',
49 'page arguments' => array('sections_admin_display_form'),
50 'access arguments' => $access,
51 'weight' => -10,
52 'file' => 'sections.admin.inc',
53 'type' => MENU_DEFAULT_LOCAL_TASK
54 );
55 $items['admin/build/sections/add'] = array(
56 'title' => 'Add section',
57 'page callback' => 'drupal_get_form',
58 'page arguments' => array('sections_admin_settings_form'),
59 'access arguments' => $access,
60 'file' => 'sections.admin.inc',
61 'type' => MENU_LOCAL_TASK
62 );
63 $items['admin/build/sections/edit/%section'] = array(
64 'title' => 'Edit section',
65 'page callback' => 'drupal_get_form',
66 'page arguments' => array('sections_admin_settings_form', 4),
67 'access arguments' => $access,
68 'file' => 'sections.admin.inc',
69 'type' => MENU_CALLBACK
70 );
71 $items['admin/build/sections/delete/%section'] = array(
72 'title' => 'Delete section',
73 'page callback' => 'drupal_get_form',
74 'page arguments' => array('sections_delete_form', 4),
75 'access arguments' => $access,
76 'file' => 'sections.admin.inc',
77 'type' => MENU_CALLBACK
78 );
79
80 return $items;
81 }
82
83 /**
84 * Implementation of hook_theme()
85 */
86 function sections_theme() {
87 return array(
88 'sections_admin_display_form' => array(
89 'file' => 'sections.admin.inc',
90 'arguments' => array('form' => NULL),
91 ),
92 );
93 }
94
95 /**
96 * Implementation of hook_init().
97 */
98 function sections_init() {
99
100 if ($section = _sections_in_section()) {
101 // only switch to custom theme if theme is active, to prohibit a destroyed site
102 foreach (list_themes() as $key => $theme) {
103 if ($theme->status == 1 && $theme->name == $section->theme) {
104 global $custom_theme;
105 $custom_theme = $section->theme;
106 }
107 }
108 }
109
110 }
111
112 /**
113 * Menu helper function to verify if section exists.
114 */
115 function section_load($section) {
116 return db_fetch_object(db_query("SELECT * FROM {sections_data} WHERE sid = %d", $section));
117 }
118
119 /**
120 * An API for modules that want to know about sections.
121 *
122 * This API is a function that lets you find out about settings.
123 *
124 * @param
125 * Optional $setting a string containing the section you wnat to test against.
126 *
127 * @return
128 * Depends on the parameter.
129 * If you do not give $section, it will return the section object, if found.
130 * If you give $section, it will return TRUE if you are in that section
131 * Otherwise it will return FALSE
132 */
133 function _sections_in_section($section = NULL) {
134 global $user;
135 $output = FALSE;
136
137 if (is_string($section)) {
138 // Caller wants to know if shes in the section she provided.
139 if ($section == _sections_in_section()) {
140 $output = TRUE;
141 }
142 }
143 else {
144 // Caller wants to know in which section she is.
145 $rids = array_keys($user->roles);
146 $res = db_query(db_rewrite_sql('SELECT DISTINCT s.* FROM {sections_data} s LEFT JOIN {sections_roles} r ON s.sid = r.sid WHERE s.status = 1 AND (r.rid IN ('. db_placeholders($rids) .') OR r.rid IS NULL) ORDER BY s.weight', 's', 'sid'), $rids);
147 while ($row = db_fetch_object($res)) {
148 if ($row->visibility < 2) {
149 $path = drupal_get_path_alias($_GET['q']);
150 // Compare with the internal and path alias (if any).
151 $page_match = drupal_match_path($path, $row->path);
152 if ($path != $_GET['q']) {
153 $page_match = $page_match || drupal_match_path($_GET['q'], $row->path);
154 }
155 // When $row->visibility has a value of 0, the block is displayed on
156 // all pages except those listed in $row->path. When set to 1, it
157 // is displayed only on those pages listed in $row->path.
158 if ($page_match = !($row->visibility xor $page_match)) {
159 $output = $row;
160 }
161 }
162 else {
163 if (drupal_eval($row->path)) {
164 $output = $row;
165 }
166 }
167 }
168 }
169 return $output;
170 }
171
172 /**
173 * Add template suggestion for page templates.
174 */
175 function sections_preprocess_page(&$variables) {
176 // Add multiple suggestions.
177 if ($section = _sections_in_section()) {
178 // Try to find a page template with section id.
179 $variables['template_files'][] = 'sections-page-'. $section->sid;
180
181 // Try to find a page template named like the section.
182 $filter = '![^abcdefghijklmnopqrstuvwxyz0-9-_]+!s';
183 $string_clean = preg_replace($filter, '-', drupal_strtolower($section->name));
184 $variables['template_files'][] = 'sections-page-'. $string_clean;
185 }
186 }

  ViewVC Help
Powered by ViewVC 1.1.2