View source
<?php
function quickbar_init() {
if (quickbar_is_enabled()) {
global $user;
$roles = unserialize(variable_get('quickbar_role_weights', ''));
if (is_array($roles)) {
asort($roles);
foreach ($roles as $rid => $weight) {
if (!empty($user->roles[$rid]) && ($menu = variable_get('quickbar_' . $rid, 0))) {
$path = drupal_get_path('module', 'quickbar');
drupal_add_js($path . '/js/quickbar.js');
drupal_add_css($path . '/theme/quickbar.css');
$iconsets = module_invoke_all('quickbar_iconset_info');
$iconset = variable_get('quickbar_iconset_' . $rid, 'quickbar');
drupal_add_css($iconsets[$iconset]['css']);
break;
}
}
}
}
}
function quickbar_landing_page_access($path) {
static $paths;
if (!isset($paths)) {
$cache = cache_get('quickbar_paths');
$paths = $cache && !empty($cache->data) ? $cache->data : array();
}
if (!isset($paths[$path])) {
$item = db_fetch_array(db_query("SELECT mlid, menu_name FROM {menu_links} ml WHERE ml.link_path = '%s' AND module = 'system'", $path));
$result = db_query("\n SELECT m.load_functions, m.to_arg_functions, m.access_callback, m.access_arguments, m.page_callback, m.page_arguments, m.title, m.title_callback, m.title_arguments, m.type, m.description, ml.*\n FROM {menu_links} ml\n LEFT JOIN {menu_router} m ON ml.router_path = m.path\n WHERE ml.plid = %d AND ml.menu_name = '%s' AND hidden = 0", $item['mlid'], $item['menu_name']);
$paths[$path] = FALSE;
while ($item = db_fetch_array($result)) {
$item['options'] = unserialize($item['options']);
if ($item['external']) {
if (!empty($item['options']['alter'])) {
drupal_alter('translated_menu_link', $item, $map);
}
if ($item['access']) {
$paths[$path] = TRUE;
break;
}
}
else {
$map = explode('/', $item['link_path']);
_menu_link_map_translate($map, $item['to_arg_functions']);
$item['href'] = implode('/', $map);
if (strpos($item['href'], '%') !== FALSE) {
continue;
}
if (!isset($item['access'])) {
if (!_menu_load_objects($item, $map)) {
continue;
}
_menu_check_access($item, $map);
}
if (!$item['access']) {
continue;
}
$paths[$path] = TRUE;
break;
}
}
cache_set('quickbar_paths', $paths);
}
return $paths[$path];
}
function quickbar_perm() {
return array(
'administer quickbar',
);
}
function quickbar_theme($cache, $type, $theme, $path) {
$path = drupal_get_path('module', 'quickbar');
$items['quickbar'] = array(
'arguments' => array(
'tree' => array(),
'rid' => NULL,
),
'template' => 'quickbar',
'path' => $path . '/theme',
'file' => 'theme.inc',
);
$items['quickbar_form'] = array(
'arguments' => array(
'form' => NULL,
),
'file' => 'quickbar.admin.inc',
);
return $items;
}
function quickbar_menu() {
return array(
'admin/settings/quickbar' => array(
'title' => t('Quickbar Configuration'),
'description' => t('Configure toolbars'),
'page callback' => 'drupal_get_form',
'page arguments' => array(
'quickbar_form',
),
'access callback' => 'user_access',
'access arguments' => array(
'administer quickbar',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'quickbar.admin.inc',
),
'admin/settings/quickbar/%/edit' => array(
'title' => t('Configure Toolbar'),
'description' => t('Configure the toolbar for a certain role.'),
'page callback' => '_quickbar_configure_page',
'page arguments' => array(
3,
),
'access callback' => 'user_access',
'access arguments' => array(
'administer quickbar',
),
'type' => MENU_NORMAL_ITEM,
'file' => 'quickbar.admin.inc',
),
);
}
function quickbar_is_enabled() {
global $user;
if (module_exists('admin_select')) {
$data = unserialize($user->data);
if (isset($data['admin_select'])) {
if ($data['admin_select'] !== 'quickbar') {
return FALSE;
}
}
}
global $theme_info;
if (!isset($theme_info->info['quickbar']) || $theme_info->info['quickbar'] !== 0) {
return TRUE;
}
return FALSE;
}
function quickbar_preprocess_page(&$vars, $hook) {
$body_classes = array(
$vars['body_classes'],
);
global $user;
$roles = unserialize(variable_get('quickbar_role_weights', ''));
if (is_array($roles)) {
asort($roles);
foreach ($roles as $rid => $weight) {
if (variable_get('quickbar_sticky_' . $rid, FALSE)) {
$body_classes[] = 'quickbar-sticky';
}
$vars['body_classes'] = implode(' ', $body_classes);
if (isset($user->roles[$rid])) {
break;
}
}
}
}
function quickbar_footer($main = 0) {
$links = '';
if (quickbar_is_enabled()) {
global $user;
$roles = unserialize(variable_get('quickbar_role_weights', ''));
if (is_array($roles)) {
asort($roles);
foreach ($roles as $rid => $weight) {
if (!empty($user->roles[$rid]) && ($menu = variable_get('quickbar_' . $rid, 0))) {
if (variable_get('quickbar_sticky_' . $rid, FALSE)) {
$body_classes[] = 'quickbar-sticky';
}
$links = quickbar_menu_tree($menu);
$links = theme('quickbar', $links, $rid);
break;
}
}
}
}
return $links;
}
function quickbar_get_menu_tree($menu) {
$tree = menu_tree_all_data($menu);
foreach ($tree as $k => $item) {
if ($item['link']['link_path'] == 'admin' && !empty($item['below'])) {
unset($tree[$k]);
$tree = array_merge($tree, $item['below']);
}
}
return $tree;
}
function quickbar_menu_tree($menu) {
$links = array();
$tree = quickbar_get_menu_tree($menu);
quickbar_menu_tree_links($tree, $links);
return $links;
}
function quickbar_menu_navigation_links($tree, $admin_only = FALSE) {
$links = array();
foreach ($tree as $item) {
if (!$item['link']['hidden']) {
$class = '';
$id = str_replace('/', '-', $item['link']['href']);
$id = str_replace('<front>', 'front', $id);
$l = $item['link']['localized_options'];
$l['href'] = $item['link']['href'];
$l['title'] = "<span class='icon'></span>" . $item['link']['title'];
$l['attributes'] = array(
'id' => 'quickbar-link-' . $id,
);
$l['html'] = TRUE;
if (module_exists('menu_item_container')) {
global $base_url;
if (strpos($l['href'], 'menu-item-container') !== FALSE) {
$current_path = explode('=', drupal_get_destination());
$l['href'] = $base_url . '/' . drupal_get_path_alias(str_replace('%2F', '/', $current_path[1])) . '#';
if (drupal_is_front_page()) {
$l['href'] = $base_url . '#';
}
}
}
$class = ' path-' . $id;
if (quickbar_in_active_trail($item['link']['href'])) {
$class .= ' active-trail';
}
$links['menu-' . $item['link']['mlid'] . $class] = $l;
}
}
return $links;
}
function quickbar_menu_tree_links($tree, &$links, $parent = 'admin', $depth = 0) {
$links[$depth][$parent] = array();
$l = quickbar_menu_navigation_links($tree, TRUE);
if (!empty($l)) {
$links[$depth][$parent] = $l;
}
foreach ($tree as $item) {
if (!$item['link']['hidden']) {
if (!empty($item['below'])) {
quickbar_menu_tree_links($item['below'], $links, $item['link']['href'], $depth + 1);
}
}
}
}
function quickbar_in_active_trail($path, $reset = FALSE) {
static $active_paths;
if (!isset($active_paths) || $reset) {
$active_paths = array();
$trail = menu_get_active_trail();
foreach ($trail as $item) {
if (!empty($item['href'])) {
$active_paths[] = $item['href'];
}
}
}
return in_array($path, $active_paths);
}
function quickbar_quickbar_iconset_info() {
$iconsets = array(
'quickbar' => array(
'title' => 'Admin 1.x',
'css' => drupal_get_path('module', 'quickbar') . '/theme/icons.css',
),
);
$themes = list_themes();
if (array_key_exists('rubik', $themes)) {
$iconsets['quickbar_rubik'] = array(
'title' => 'Rubik',
'css' => drupal_get_path('theme', 'rubik') . '/icons.css',
);
}
return $iconsets;
}
function quickbar_admin_select_info() {
$info = array();
$info['quickbar'] = array(
'title' => t('Quickbar'),
'access arguments' => array(
'access content',
),
'suppress callback' => 'quickbar_suppress',
);
return $info;
}
function quickbar_suppress() {
global $theme_info;
$theme_info->info['quickbar'] = FALSE;
}