'control_panel', 'title' => t('control panel'), 'callback' => 'controlpanel_build_controlpanel', 'access' => user_access('access control panel')); // callback for use as an Admin control panel $items[] = array('path' => 'admin/control_panel', 'callback' => 'controlpanel_build_controlpanel', 'access' => user_access('access administration pages'), 'type' => MENU_CALLBACK); // depricated callback $items[] = array('path' => 'admin/controlpanel', 'callback' => 'controlpanel_build_controlpanel', 'access' => user_access('access administration pages'), 'type' => MENU_CALLBACK); $items[] = array('path' => 'admin/control_panel_blank', 'callback' => 'controlpanel_build_blank_page', 'access' => user_access('access administration pages'), 'type' => MENU_CALLBACK); } return $items; } function controlpanel_perm() { return array(t('access control panel')); } function controlpanel_build_blank_page() { return ' '; } /** * Menu callback: control panel. */ function controlpanel_build_controlpanel($mid = NULL, $theme_page = TRUE, $block = NULL) { static $sent = array(); if (file_exists('misc/collapse.js') && variable_get('controlpanel_child_collapsable' . $block, 1)) { if (!isset($sent['misc/collapse.js'])) { drupal_add_js('misc/collapse.js'); $sent['misc/collapse.js'] = TRUE; } } if (!isset($sent[drupal_get_path('module','controlpanel') . '/controlpanel.css'])) { drupal_set_html_head(''); $sent[drupal_get_path('module','controlpanel') . '/controlpanel.css'] = TRUE; } $content = ''; $menu = menu_get_menu(); $menu_visible = $menu['visible']; if ($mid == NULL) { $mid = variable_get('controlpanel_menu_source' . $block, 1); } if (variable_get('controlpanel_build_children' . $block, 0) != 0) { $content .= '
'; $content .= '' . $menu['items'][$mid]['title'] . ''; } $content .= theme('controlpanel_panel_view', $mid, $block); if (variable_get('controlpanel_build_children' . $block, 0) && (variable_get('controlpanel_child_levels' . $block, 2) > 1) && ($menu_visible[$mid]['children'])) { $content = theme('controlpanel_child_panel_view', $mid, 0, $content, $block); } if (variable_get('controlpanel_build_children' . $block, 0) != 0) { $content .= '
'; } if ($theme_page == TRUE) { print theme('page', $content); } else { return $content; } } /** * Build a control panel */ function theme_controlpanel_panel_view($pid, $block = NULL) { $content = ''; $menu = menu_get_menu(); $menu_visible = $menu['visible']; $theme_path = path_to_theme() . '/controlpanel/' . variable_get('controlpanel_icon_size' . $block, '48x48'); if (file_exists($theme_path . '/control_panel_default.png')) { $image_directory = $theme_path; } else { $image_directory = drupal_get_path('module', 'controlpanel') . '/images/' . variable_get('controlpanel_icon_size' . $block, '48x48'); } $content .= '
'; if (isset($menu_visible[$pid]) && $menu_visible[$pid]['children']) { foreach ($menu_visible[$pid]['children'] as $mid) { $content .= '
'; $content .= ''; $file_name = $image_directory . '/' . str_replace('/', '_', $menu_visible[$mid]['path']) . '.png'; if (file_exists($file_name)) { $src = $file_name; } else { $src = $image_directory . '/control_panel_default.png'; } $content .= ''; $content .= ''. $menu_visible[$mid]['title'] .''; $content .= '
' . $menu_visible[$mid]['title']; $content .= '
'; $content .= '
'; $content .= '
'; } } $content .= '
'; return $content; } /** * Build child panel(s) */ function theme_controlpanel_child_panel_view($mid, $depth, $content, $block = NULL){ $menu = menu_get_menu(); $menu_visible = $menu['visible']; if ($depth < variable_get('controlpanel_child_levels' . $block, 2)-1) { foreach ($menu_visible[$mid]['children'] as $cid) { if (isset($menu_visible[$cid]) && $menu_visible[$cid]['children']) { $content .= ''; $content = theme('controlpanel_child_panel_view', $cid, $depth + 1, $content, $block); } } } return $content; } /** * Implementation of hook_settings(). */ function controlpanel_settings() { $number_of_blocks = drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15)); $form = _controlpanel_settings_form(); $form['block'] = array( '#type' => 'fieldset', '#title' => t('Block settings'), '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['block']['controlpanel_number_of_blocks'] = array( '#type' => 'select', '#title' => t('Number of blocks'), '#default_value' => variable_get('controlpanel_number_of_blocks', 0), '#options' => $number_of_blocks, '#description' => t('Select the number of Control Panel blocks you wish to generate. Control Panel blocks are configured individually in the block configuration pages.') ); return $form; } function _controlpanel_settings_form($block = NULL){ // Clear the page cache, so that changed menus are reflected cache_clear_all(); // Also clear the menu cache. cache_clear_all('menu:', TRUE); $child_levels = drupal_map_assoc(array(2, 3, 4)); $icon_sizes = drupal_map_assoc(array('16x16', '24x24', '36x36', '48x48')); $form['general'] = array( '#type' => 'fieldset', '#title' => t('General settings'), '#collapsible' => TRUE, '#collapsed' => FALSE ); $form['general']['controlpanel_name' . $block] = array( '#type' => 'textfield', '#title' => t('Control Panel name'), '#default_value' => variable_get('controlpanel_name' . $block, 'control panel ' . $block), '#description' => t('Enter the name of this Control Panel.') ); // Generate a list of possible parents (not including this item or descendants). $options = menu_parent_options(0); $form['general']['controlpanel_menu_source' . $block] = array( '#type' => 'select', '#title' => t('Source menu item'), '#default_value' => variable_get('controlpanel_menu_source' . $block, 1), '#options' => $options); $form['general']['controlpanel_icon_size' . $block] = array( '#type' => 'select', '#title' => t('Icon size'), '#default_value' => variable_get('controlpanel_icon_size' . $block, '48x48'), '#options' => $icon_sizes, '#description' => t('Select the size of the control panel icons.') ); $form['child_panels'] = array( '#type' => 'fieldset', '#title' => t('Child Panels'), '#collapsible' => TRUE, '#collapsed' => TRUE ); $form['child_panels']['controlpanel_build_children' . $block] = array( '#type' => 'checkbox', '#title' => t('Build Child Menu Panels'), '#default_value' => variable_get('controlpanel_build_children' . $block, 0), '#tree' => FALSE, '#description' => t('Check this box to recursively build child panels.') ); $form['child_panels']['controlpanel_child_levels' . $block] = array( '#type' => 'select', '#title' => t('Number of levels'), '#default_value' => variable_get('controlpanel_child_levels' . $block, 2), '#options' => $child_levels, '#description' => t('Select how many control panel levels to build.') ); $form['child_panels']['controlpanel_child_collapsable' . $block] = array( '#type' => 'checkbox', '#title' => t('Make child panels collapsable'), '#default_value' => variable_get('controlpanel_child_collapsable' . $block, 1), '#tree' => FALSE, '#description' => t('Check this box to allow child panels to be collapsed.') ); return $form; } /** * Implementation of hook_block(). */ function controlpanel_block($op = 'list', $delta = 0, $edit = array()) { switch ($op) { case 'list': $num_of_blocks = variable_get('controlpanel_number_of_blocks', 0); for ($i = 1; $i <= $num_of_blocks; $i++){ $blocks[$i]['info'] = variable_get('controlpanel_name_block' . $i, t('Control panel ' . $i)) . ' (Control Panel)'; } return $blocks; case 'configure': return _controlpanel_settings_form('_block' . $delta); case 'save': variable_set('controlpanel_name_block' . $delta, $edit['controlpanel_name_block' . $delta]); variable_set('controlpanel_menu_source_block' . $delta, $edit['controlpanel_menu_source_block' . $delta]); variable_set('controlpanel_icon_size_block' . $delta, $edit['controlpanel_icon_size_block' . $delta]); variable_set('controlpanel_build_children_block' . $delta, $edit['controlpanel_build_children_block' . $delta]); variable_set('controlpanel_child_levels_block' . $delta, $edit['controlpanel_child_levels_block' . $delta]); variable_set('controlpanel_child_collapsable_block' . $delta, $edit['controlpanel_child_collapsable_block' . $delta]); case 'view': $block['subject'] = variable_get('controlpanel_name_block' . $delta, t('Control panel ' . $delta)); $block['content'] = controlpanel_build_controlpanel(NULL, FALSE, '_block' . $delta); return $block; } } ?>