| 9 |
/** |
/** |
| 10 |
* Implementation of hook_help(). |
* Implementation of hook_help(). |
| 11 |
*/ |
*/ |
| 12 |
function controlpanel_help($section) { |
function controlpanel_help($path, $arg) { |
| 13 |
switch ($section) { |
switch ($path) { |
| 14 |
case 'admin/build/modules#description': |
case 'admin/build/modules#description': |
| 15 |
return t('Enables the use of a graphical Control Panel.'); |
return t('Enables the use of a graphical Control Panel.'); |
| 16 |
} |
} |
| 18 |
/** |
/** |
| 19 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 20 |
*/ |
*/ |
| 21 |
function controlpanel_menu($may_cache) { |
function controlpanel_menu() { |
| 22 |
global $user; |
global $user; |
| 23 |
$items = array(); |
$items = array(); |
| 24 |
if ($may_cache) { |
|
| 25 |
$items[] = array('path' => 'control_panel', 'title' => t('Control Panel'), |
$items['control_panel'] = array( |
| 26 |
'callback' => 'controlpanel_build_controlpanel', |
'title' => t('Control Panel'), |
| 27 |
'access' => user_access('access control panel')); |
'page callback' => 'controlpanel_build_controlpanel', |
| 28 |
// callback for use as an Admin control panel |
'access arguments' => array('access control panel') |
| 29 |
$items[] = array('path' => 'admin/control_panel', |
); |
| 30 |
'callback' => 'controlpanel_build_controlpanel', |
$items['admin/control_panel'] = array( |
| 31 |
'access' => user_access('access administration pages'), |
'page callback' => 'controlpanel_build_controlpanel', |
| 32 |
'type' => MENU_CALLBACK); |
'access arguments' => array('access administration pages'), |
| 33 |
// depricated callback |
'type' => MENU_CALLBACK |
| 34 |
$items[] = array('path' => 'admin/controlpanel', |
); |
| 35 |
'callback' => 'controlpanel_build_controlpanel', |
$items['admin/controlpanel'] = array( |
| 36 |
'access' => user_access('access administration pages'), |
'page callback' => 'controlpanel_build_controlpanel', |
| 37 |
'type' => MENU_CALLBACK); |
'access arguments' => array('access administration pages'), |
| 38 |
$items[] = array('path' => 'admin/control_panel_blank', |
'type' => MENU_CALLBACK |
| 39 |
'callback' => 'controlpanel_build_blank_page', |
); |
| 40 |
'access' => user_access('access administration pages'), |
$items['admin/control_panel_blank'] = array( |
| 41 |
'type' => MENU_CALLBACK); |
'page callback' => 'controlpanel_build_blank_page', |
| 42 |
$items[] = array( |
'access arguments' => array('access administration pages'), |
| 43 |
'path' => 'admin/settings/controlpanel', |
'type' => MENU_CALLBACK |
| 44 |
'title' => t('Control Panel'), |
); |
| 45 |
'description' => t('Configure Control Panel behavior.'), |
$items['admin/settings/controlpanel'] = array( |
| 46 |
'callback' => 'drupal_get_form', |
'title' => t('Control Panel'), |
| 47 |
'callback arguments' => 'controlpanel_settings', |
'description' => t('Configure Control Panel behavior.'), |
| 48 |
'access' => user_access('administer site configuration'), |
'page callback' => 'drupal_get_form', |
| 49 |
'type' => MENU_NORMAL_ITEM); |
'page arguments' => array('controlpanel_settings'), |
| 50 |
} |
'access arguments' => array('administer site configuration'), |
| 51 |
|
'type' => MENU_NORMAL_ITEM |
| 52 |
|
); |
| 53 |
|
|
| 54 |
return $items; |
return $items; |
| 55 |
} |
} |
| 56 |
|
|
| 57 |
function controlpanel_perm() { |
function controlpanel_perm() { |
| 58 |
return array(t('access control panel')); |
return array('access control panel'); |
| 59 |
} |
} |
| 60 |
|
|
| 61 |
function controlpanel_build_blank_page() { |
function controlpanel_build_blank_page() { |
| 62 |
return ' '; |
return ' '; |
| 63 |
} |
} |
| 65 |
/** |
/** |
| 66 |
* Menu callback: control panel. |
* Menu callback: control panel. |
| 67 |
*/ |
*/ |
| 68 |
function controlpanel_build_controlpanel($mid = NULL, $theme_page = TRUE, $block = NULL) { |
function controlpanel_build_controlpanel($menu_key = NULL, $theme_page = TRUE, $block = NULL) { |
| 69 |
static $sent = array(); |
static $sent = array(); |
| 70 |
if (file_exists('misc/collapse.js') && variable_get('controlpanel_child_collapsable' . $block, 1)) { |
if (file_exists('misc/collapse.js') && variable_get('controlpanel_child_collapsable' . $block, 1)) { |
| 71 |
if (!isset($sent['misc/collapse.js'])) { |
if (!isset($sent['misc/collapse.js'])) { |
| 73 |
$sent['misc/collapse.js'] = TRUE; |
$sent['misc/collapse.js'] = TRUE; |
| 74 |
} |
} |
| 75 |
} |
} |
| 76 |
if (!isset($sent[drupal_get_path('module','controlpanel') . '/controlpanel.css'])) { |
|
| 77 |
drupal_add_css(drupal_get_path('module', 'controlpanel') .'/controlpanel.css'); |
drupal_add_css(drupal_get_path('module', 'controlpanel') .'/controlpanel.css'); |
|
$sent[drupal_get_path('module','controlpanel') . '/controlpanel.css'] = TRUE; |
|
|
} |
|
| 78 |
|
|
| 79 |
$content = ''; |
$content = ''; |
|
$menu = menu_get_menu(); |
|
|
$menu_visible = $menu['visible']; |
|
| 80 |
|
|
| 81 |
if ($mid == NULL) { |
if ($menu_key == NULL) { |
| 82 |
$mid = variable_get('controlpanel_menu_source' . $block, 1); |
$menu_key = variable_get('controlpanel_menu_source' . $block, 1); |
| 83 |
} |
} |
| 84 |
|
|
| 85 |
|
list($menu_name, $mlid) = explode(':', $menu_key); |
| 86 |
|
$menu = menu_tree_all_data($menu_name); |
| 87 |
|
$panel_menu = _controlpanel_get_menu($menu, $mlid); |
| 88 |
|
|
| 89 |
if (variable_get('controlpanel_build_children' . $block, 0) != 0) { |
if (variable_get('controlpanel_build_children' . $block, 0) != 0) { |
| 90 |
$content .= '<fieldset class="control-panel-fieldset collapsible">'; |
$content .= '<fieldset class="control-panel-fieldset collapsible">'; |
| 91 |
$content .= '<legend>' . $menu['items'][$mid]['title'] . '</legend>'; |
$content .= '<legend>' . $panel_menu['link']['link_title'] . '</legend>'; |
| 92 |
} |
} |
| 93 |
$content .= theme('controlpanel_panel_view', $mid, $block); |
$content .= theme('controlpanel_panel_view', $panel_menu, $block); |
| 94 |
|
|
| 95 |
if (variable_get('controlpanel_build_children' . $block, 0) && (variable_get('controlpanel_child_levels' . $block, 2) > 1) && ($menu_visible[$mid]['children'])) { |
if (variable_get('controlpanel_build_children' . $block, 0) && (variable_get('controlpanel_child_levels' . $block, 2) > 1) && (is_array($panel_menu['below']))) { |
| 96 |
$content = theme('controlpanel_child_panel_view', $mid, 0, $content, $block); |
$content = theme('controlpanel_child_panel_view', $panel_menu['below'], 0, $content, $block); |
| 97 |
} |
} |
| 98 |
if (variable_get('controlpanel_build_children' . $block, 0) != 0) { |
if (variable_get('controlpanel_build_children' . $block, 0) != 0) { |
| 99 |
$content .= '</fieldset>'; |
$content .= '</fieldset>'; |
| 106 |
} |
} |
| 107 |
} |
} |
| 108 |
|
|
| 109 |
|
function _controlpanel_get_menu($parent_menu, $mlid) { |
| 110 |
|
foreach ($parent_menu as $key => $value) { |
| 111 |
|
if ($value['link']['mlid'] == $mlid) return $value; |
| 112 |
|
if (is_array($value['below'])) { |
| 113 |
|
$below = _controlpanel_get_menu($value['below'], $mlid); |
| 114 |
|
if (is_array($below)) return $below; |
| 115 |
|
} |
| 116 |
|
} |
| 117 |
|
return null; |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
function controlpanel_theme() { |
| 121 |
|
return array( |
| 122 |
|
'controlpanel_panel_view' => array( |
| 123 |
|
'arguments' => array('menu' => NULL, 'block' => NULL), |
| 124 |
|
), |
| 125 |
|
'controlpanel_child_panel_view' => array( |
| 126 |
|
'arguments' => array('menu' => NULL, 'depth' => NULL, 'content' => NULL, 'block' => NULL), |
| 127 |
|
), |
| 128 |
|
); |
| 129 |
|
} |
| 130 |
|
|
| 131 |
/** |
/** |
| 132 |
* Build a control panel |
* Build a control panel |
| 133 |
*/ |
*/ |
| 134 |
function theme_controlpanel_panel_view($pid, $block = NULL) { |
function theme_controlpanel_panel_view($menu, $block = NULL) { |
| 135 |
|
|
| 136 |
$content = ''; |
$content = ''; |
|
$menu = menu_get_menu(); |
|
|
$menu_visible = $menu['visible']; |
|
| 137 |
$theme_path = path_to_theme() . '/controlpanel/' . variable_get('controlpanel_icon_size' . $block, '48x48'); |
$theme_path = path_to_theme() . '/controlpanel/' . variable_get('controlpanel_icon_size' . $block, '48x48'); |
| 138 |
|
|
| 139 |
if (file_exists($theme_path . '/control_panel_default.png')) { |
if (file_exists($theme_path . '/control_panel_default.png')) { |
| 142 |
$image_directory = drupal_get_path('module', 'controlpanel') . '/images/' . variable_get('controlpanel_icon_size' . $block, '48x48'); |
$image_directory = drupal_get_path('module', 'controlpanel') . '/images/' . variable_get('controlpanel_icon_size' . $block, '48x48'); |
| 143 |
} |
} |
| 144 |
|
|
| 145 |
$content .= '<div id="control-panel-' . $pid . '" class="control-panel">'; |
$content .= '<div id="control-panel-' . $menu['link']['mlid'] . '" class="control-panel">'; |
| 146 |
if (isset($menu_visible[$pid]) && $menu_visible[$pid]['children']) { |
if (is_array($menu['below'])) { |
| 147 |
foreach ($menu_visible[$pid]['children'] as $mid) { |
foreach ($menu['below'] as $menu_item) { |
| 148 |
$content .= '<div class="control-panel-item control-panel-icon-size-' . variable_get('controlpanel_icon_size' . $block, '48x48') . '">'; |
if ($menu_item['link']['hidden'] == 0) { |
| 149 |
$content .= '<a href="' . url($menu_visible[$mid]['path']) . '">'; |
$content .= '<div class="control-panel-item control-panel-icon-size-' . variable_get('controlpanel_icon_size' . $block, '48x48') . '">'; |
| 150 |
$working_path = $menu_visible[$mid]['path']; |
$content .= '<a href="' . url($menu_item['link']['link_path']) . '">'; |
| 151 |
if (is_numeric(substr($working_path, strrpos($working_path, "/") + 1))) { |
$working_path = $menu_item['link']['link_path']; |
| 152 |
$working_path = substr($working_path, 0, strrpos($working_path, "/")); |
if (is_numeric(substr($working_path, strrpos($working_path, "/") + 1))) { |
| 153 |
} |
$working_path = substr($working_path, 0, strrpos($working_path, "/")); |
| 154 |
$file_name = $image_directory . '/' . str_replace('/', '_', $working_path) . '.png'; |
} |
| 155 |
if (file_exists($file_name)) { |
$file_name = $image_directory . '/' . str_replace('/', '_', $working_path) . '.png'; |
| 156 |
$src = $file_name; |
if (file_exists($file_name)) { |
| 157 |
} else { |
$src = $file_name; |
| 158 |
$src = $image_directory . '/control_panel_default.png'; |
} else { |
| 159 |
} |
$src = $image_directory . '/control_panel_default.png'; |
| 160 |
$content .= '<span style="display:block;">'; |
} |
| 161 |
$content .= '<img src="' . base_path() . $src . '" alt="'. $menu_visible[$mid]['title'] .'" title="'. $menu_visible[$mid]['title'] .'" />'; |
$content .= '<span style="display:block;">'; |
| 162 |
$content .= '<br />' . $menu_visible[$mid]['title']; |
$content .= '<img src="' . base_path() . $src . '" alt="'. $menu_item['link']['link_title'] .'" title="'. $menu_item['link']['link_title'] .'" />'; |
| 163 |
$content .= '</span>'; |
$content .= '<br />' . $menu_item['link']['link_title']; |
| 164 |
$content .= '</a>'; |
$content .= '</span>'; |
| 165 |
$content .= '</div>'; |
$content .= '</a>'; |
| 166 |
|
$content .= '</div>'; } |
| 167 |
} |
} |
| 168 |
} |
} |
| 169 |
$content .= '</div>'; |
$content .= '</div>'; |
| 170 |
return $content; |
return $content; |
| 171 |
} |
} |
| 172 |
|
|
| 173 |
/** |
/** |
| 174 |
* Build child panel(s) |
* Build child panel(s) |
| 175 |
*/ |
*/ |
| 176 |
function theme_controlpanel_child_panel_view($mid, $depth, $content, $block = NULL){ |
function theme_controlpanel_child_panel_view($menu, $depth, $content, $block = NULL){ |
|
$menu = menu_get_menu(); |
|
|
$menu_visible = $menu['visible']; |
|
| 177 |
if ($depth < variable_get('controlpanel_child_levels' . $block, 2)-1) { |
if ($depth < variable_get('controlpanel_child_levels' . $block, 2)-1) { |
| 178 |
foreach ($menu_visible[$mid]['children'] as $cid) { |
foreach ($menu as $menu_item) { |
| 179 |
if (isset($menu_visible[$cid]) && $menu_visible[$cid]['children']) { |
if (is_array($menu_item['below'])) { |
| 180 |
$content .= '<fieldset class="control-panel-fieldset collapsible collapsed">'; |
$content .= '<fieldset class="control-panel-fieldset collapsible collapsed">'; |
| 181 |
$content .= '<legend>' . $menu['items'][$cid]['title'] . '</legend>'; |
$content .= '<legend>' . $menu_item['link']['link_title'] . '</legend>'; |
| 182 |
$content .= theme('controlpanel_panel_view', $cid, $block); |
$content .= theme('controlpanel_panel_view', $menu_item, $block); |
| 183 |
$content .= '</fieldset>'; |
$content .= '</fieldset>'; |
| 184 |
$content = theme('controlpanel_child_panel_view', $cid, $depth + 1, $content, $block); |
$content = theme('controlpanel_child_panel_view', $menu_item, $depth + 1, $content, $block); |
| 185 |
} |
} |
| 186 |
} |
} |
| 187 |
} |
} |
| 227 |
); |
); |
| 228 |
|
|
| 229 |
// Generate a list of possible parents (not including this item or descendants). |
// Generate a list of possible parents (not including this item or descendants). |
| 230 |
$options = menu_parent_options(0); |
$options = menu_parent_options(menu_get_menus(), 0); |
| 231 |
$form['general']['controlpanel_menu_source' . $block] = array( |
$form['general']['controlpanel_menu_source' . $block] = array( |
| 232 |
'#type' => 'select', |
'#type' => 'select', |
| 233 |
'#title' => t('Source menu item'), |
'#title' => t('Source menu item'), |
| 295 |
return $block; |
return $block; |
| 296 |
} |
} |
| 297 |
} |
} |
| 298 |
|
|
| 299 |
?> |
?> |