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

Contents of /contributions/modules/controlpanel/controlpanel.module

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


Revision 1.31 - (show annotations) (download) (as text)
Fri Feb 27 19:49:00 2009 UTC (8 months, 4 weeks ago) by der
Branch: MAIN
CVS Tags: DRUPAL-6--1-2, HEAD
Changes since 1.30: +21 -14 lines
File MIME type: text/x-php
fix for showing top level menus as control panels
1 <?php
2 // $Id: controlpanel.module,v 1.22 2006/02/28 15:49:18 der Exp $
3
4 /**
5 * @file
6 * Enables the use of graphical Control Panels that can be used for site navigation.
7 */
8
9 /**
10 * Implementation of hook_help().
11 */
12 function controlpanel_help($path, $arg) {
13 switch ($path) {
14 case 'admin/build/modules#description':
15 return t('Enables the use of a graphical Control Panel.');
16 }
17 }
18 /**
19 * Implementation of hook_menu().
20 */
21 function controlpanel_menu() {
22 global $user;
23 $items = array();
24
25 $items['control_panel'] = array(
26 'title' => t('Control Panel'),
27 'page callback' => 'controlpanel_build_controlpanel',
28 'access arguments' => array('access control panel')
29 );
30 $items['admin/control_panel'] = array(
31 'page callback' => 'controlpanel_build_controlpanel',
32 'access arguments' => array('access administration pages'),
33 'type' => MENU_CALLBACK
34 );
35 $items['admin/controlpanel'] = array(
36 'page callback' => 'controlpanel_build_controlpanel',
37 'access arguments' => array('access administration pages'),
38 'type' => MENU_CALLBACK
39 );
40 $items['admin/control_panel_blank'] = array(
41 'page callback' => 'controlpanel_build_blank_page',
42 'access arguments' => array('access administration pages'),
43 'type' => MENU_CALLBACK
44 );
45 $items['admin/settings/controlpanel'] = array(
46 'title' => t('Control Panel'),
47 'description' => t('Configure Control Panel behavior.'),
48 'page callback' => 'drupal_get_form',
49 'page arguments' => array('controlpanel_settings'),
50 'access arguments' => array('administer site configuration'),
51 'type' => MENU_NORMAL_ITEM
52 );
53
54 return $items;
55 }
56
57 function controlpanel_perm() {
58 return array('access control panel');
59 }
60
61 function controlpanel_build_blank_page() {
62 return ' ';
63 }
64
65 /**
66 * Menu callback: control panel.
67 */
68 function controlpanel_build_controlpanel($menu_key = NULL, $theme_page = TRUE, $block = NULL) {
69 static $sent = array();
70 if (file_exists('misc/collapse.js') && variable_get('controlpanel_child_collapsable' . $block, 1)) {
71 if (!isset($sent['misc/collapse.js'])) {
72 drupal_add_js('misc/collapse.js','core');
73 $sent['misc/collapse.js'] = TRUE;
74 }
75 }
76
77 drupal_add_css(drupal_get_path('module', 'controlpanel') .'/controlpanel.css');
78
79 $content = '';
80
81 if ($menu_key == NULL) {
82 $menu_key = variable_get('controlpanel_menu_source' . $block, 'navigation:0');
83 }
84
85 list($menu_name, $mlid) = explode(':', $menu_key);
86 $menu = menu_tree_all_data($menu_name);
87
88 $panel_menu = _controlpanel_get_menu($menu, $mlid, $menu_name);
89
90 if (variable_get('controlpanel_build_children' . $block, 1) != 0) {
91 $css_class = variable_get('controlpanel_child_collapsable' . $block, 1) ? 'control-panel-fieldset collapsible' : 'control-panel-fieldset';
92 $content .= '<fieldset class="'.$css_class.'">';
93 $content .= '<legend>' . $panel_menu['link']['title'] . '</legend>';
94 }
95 $content .= theme('controlpanel_panel_view', $panel_menu, $block);
96
97 if (variable_get('controlpanel_build_children' . $block, 1) && (variable_get('controlpanel_child_levels' . $block, 2) > 1) && (is_array($panel_menu['below'])) && (count($panel_menu['below']) > 0)) {
98 $content = theme('controlpanel_child_panel_view', $panel_menu['below'], 0, $content, $block);
99 }
100 if (variable_get('controlpanel_build_children' . $block, 1) != 0) {
101 $content .= '</fieldset>';
102 }
103
104 if ($theme_page == TRUE) {
105 print theme('page', $content);
106 } else {
107 return $content;
108 }
109 }
110
111 function _controlpanel_get_menu($parent_menu, $mlid, $menu_name = null) {
112 if ($mlid == 0) {
113 return array('link' => array('title' => $menu_name,
114 'mlid' => 0,
115 'href' => null),
116 'below' => $parent_menu);
117 }
118 foreach ($parent_menu as $key => $value) {
119 if ($value['link']['mlid'] == $mlid) return $value;
120 if (is_array($value['below'])) {
121 $below = _controlpanel_get_menu($value['below'], $mlid);
122 if (is_array($below) && (count($panel_menu['below']) > 0)) return $below;
123 }
124 }
125 return null;
126 }
127
128 function controlpanel_theme() {
129 return array(
130 'controlpanel_panel_view' => array(
131 'arguments' => array('menu' => NULL, 'block' => NULL),
132 ),
133 'controlpanel_child_panel_view' => array(
134 'arguments' => array('menu' => NULL, 'depth' => NULL, 'content' => NULL, 'block' => NULL),
135 ),
136 );
137 }
138
139 /**
140 * Build a control panel
141 */
142 function theme_controlpanel_panel_view($menu, $block = NULL) {
143
144 $content = '';
145 $theme_path = path_to_theme() . '/controlpanel/' . variable_get('controlpanel_icon_size' . $block, '48x48');
146
147 if (file_exists($theme_path . '/control_panel_default.png')) {
148 $image_directory = $theme_path;
149 } else {
150 $image_directory = drupal_get_path('module', 'controlpanel') . '/images/' . variable_get('controlpanel_icon_size' . $block, '48x48');
151 }
152
153 $content .= '<div id="control-panel-' . $menu['link']['mlid'] . '" class="control-panel">';
154 if (is_array($menu['below'])) {
155 foreach ($menu['below'] as $menu_item) {
156 if ($menu_item['link']['hidden'] == 0) {
157 $content .= '<div class="control-panel-item control-panel-icon-size-' . variable_get('controlpanel_icon_size' . $block, '48x48') . '">';
158 $content .= '<a href="' . url($menu_item['link']['href']) . '">';
159 $working_path = drupal_get_path_alias($menu_item['link']['href']);
160 if (is_numeric(substr($working_path, strrpos($working_path, "/") + 1))) {
161 $working_path = substr($working_path, 0, strrpos($working_path, "/"));
162 }
163 $file_name = $image_directory . '/' . str_replace('/', '_', $working_path) . '.png';
164 if (file_exists($file_name)) {
165 $src = $file_name;
166 } else {
167 $src = $image_directory . '/control_panel_default.png';
168 }
169 $content .= '<span style="display:block;">';
170 $content .= '<img src="' . base_path() . $src . '" alt="'. $menu_item['link']['title'] .'" title="'. strip_tags($menu_item['link']['description']) .'" />';
171 $content .= '<br />' . $menu_item['link']['title'];
172 $content .= '</span>';
173 $content .= '</a>';
174 $content .= '</div>'; }
175 }
176 }
177 $content .= '</div>';
178 return $content;
179 }
180
181 /**
182 * Build child panel(s)
183 */
184 function theme_controlpanel_child_panel_view($menu, $depth, $content, $block = NULL){
185 if ($depth < variable_get('controlpanel_child_levels' . $block, 2)-1) {
186 foreach ($menu as $menu_item) {
187 if (is_array($menu_item['below']) && (count($menu_item['below']) > 0)) {
188 $css_class = variable_get('controlpanel_child_collapsable', 1) ? 'control-panel-fieldset collapsible collapsed' : 'control-panel-fieldset';
189 $content .= '<fieldset class="'.$css_class.'">';
190 $content .= '<legend>' . $menu_item['link']['title'] . '</legend>';
191 $content .= theme('controlpanel_panel_view', $menu_item, $block);
192 $content .= '</fieldset>';
193 $content = theme('controlpanel_child_panel_view', $menu_item, $depth + 1, $content, $block);
194 }
195 }
196 }
197 return $content;
198 }
199 /**
200 * Implementation of hook_settings().
201 */
202 function controlpanel_settings() {
203 $number_of_blocks = drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15));
204 $form = _controlpanel_settings_form();
205
206 $form['block'] = array(
207 '#type' => 'fieldset', '#title' => t('Block settings'),
208 '#collapsible' => TRUE, '#collapsed' => TRUE
209 );
210 $form['block']['controlpanel_number_of_blocks'] = array(
211 '#type' => 'select', '#title' => t('Number of blocks'), '#default_value' => variable_get('controlpanel_number_of_blocks', 0), '#options' => $number_of_blocks,
212 '#description' => t('Select the number of Control Panel blocks you wish to generate. Control Panel blocks are configured individually in the block configuration pages.')
213 );
214
215 return system_settings_form($form);
216 }
217
218 function _controlpanel_settings_form($block = NULL){
219 // Clear the page cache, so that changed menus are reflected
220 cache_clear_all();
221 // Also clear the menu cache.
222 cache_clear_all(NULL, 'cache_menu');
223
224 $child_levels = drupal_map_assoc(array(2, 3, 4));
225 $icon_sizes = drupal_map_assoc(array('16x16', '24x24', '36x36', '48x48'));
226
227 $form['general'] = array(
228 '#type' => 'fieldset', '#title' => t('General settings'),
229 '#collapsible' => TRUE, '#collapsed' => FALSE
230 );
231 $form['general']['controlpanel_name' . $block] = array(
232 '#type' => 'textfield',
233 '#title' => t('Control Panel name'),
234 '#default_value' => variable_get('controlpanel_name' . $block, 'control panel ' . $block),
235 '#description' => t('Enter the name of this Control Panel.')
236 );
237
238 // Generate a list of possible parents (not including this item or descendants).
239 $options = menu_parent_options(menu_get_menus(), 0);
240 $form['general']['controlpanel_menu_source' . $block] = array(
241 '#type' => 'select',
242 '#title' => t('Source menu item'),
243 '#default_value' => variable_get('controlpanel_menu_source' . $block, 'navigation:0'),
244 '#options' => $options);
245
246 $form['general']['controlpanel_icon_size' . $block] = array(
247 '#type' => 'select',
248 '#title' => t('Icon size'),
249 '#default_value' => variable_get('controlpanel_icon_size' . $block, '48x48'), '#options' => $icon_sizes,
250 '#description' => t('Select the size of the control panel icons.')
251 );
252 $form['child_panels'] = array(
253 '#type' => 'fieldset',
254 '#title' => t('Child Panels'),
255 '#collapsible' => TRUE,
256 '#collapsed' => TRUE
257 );
258 $form['child_panels']['controlpanel_build_children' . $block] = array(
259 '#type' => 'checkbox',
260 '#title' => t('Build Child Menu Panels'),
261 '#default_value' => variable_get('controlpanel_build_children' . $block, 1),
262 '#tree' => FALSE,
263 '#description' => t('Check this box to recursively build child panels.')
264 );
265 $form['child_panels']['controlpanel_child_levels' . $block] = array(
266 '#type' => 'select',
267 '#title' => t('Number of levels'),
268 '#default_value' => variable_get('controlpanel_child_levels' . $block, 2), '#options' => $child_levels,
269 '#description' => t('Select how many control panel levels to build.')
270 );
271 $form['child_panels']['controlpanel_child_collapsable' . $block] = array(
272 '#type' => 'checkbox',
273 '#title' => t('Make child panels collapsable'),
274 '#default_value' => variable_get('controlpanel_child_collapsable' . $block, 1),
275 '#tree' => FALSE,
276 '#description' => t('Check this box to allow child panels to be collapsed.')
277 );
278 return $form;
279 }
280
281 /**
282 * Implementation of hook_block().
283 */
284 function controlpanel_block($op = 'list', $delta = 0, $edit = array()) {
285 switch ($op) {
286 case 'list':
287 $num_of_blocks = variable_get('controlpanel_number_of_blocks', 0);
288 for ($i = 1; $i <= $num_of_blocks; $i++){
289 $blocks[$i]['info'] = variable_get('controlpanel_name_block' . $i, t('Control panel ' . $i)) . ' (Control Panel)';
290 }
291 return $blocks;
292 case 'configure':
293 return _controlpanel_settings_form('_block' . $delta);
294 case 'save':
295 variable_set('controlpanel_name_block' . $delta, $edit['controlpanel_name_block' . $delta]);
296 variable_set('controlpanel_menu_source_block' . $delta, $edit['controlpanel_menu_source_block' . $delta]);
297 variable_set('controlpanel_icon_size_block' . $delta, $edit['controlpanel_icon_size_block' . $delta]);
298 variable_set('controlpanel_build_children_block' . $delta, $edit['controlpanel_build_children_block' . $delta]);
299 variable_set('controlpanel_child_levels_block' . $delta, $edit['controlpanel_child_levels_block' . $delta]);
300 variable_set('controlpanel_child_collapsable_block' . $delta, $edit['controlpanel_child_collapsable_block' . $delta]);
301 case 'view':
302 $block['subject'] = variable_get('controlpanel_name_block' . $delta, t('Control panel ' . $delta));
303 $block['content'] = controlpanel_build_controlpanel(NULL, FALSE, '_block' . $delta);
304 return $block;
305 }
306 }
307
308 ?>

  ViewVC Help
Powered by ViewVC 1.1.2