follow simple menu maj

Signed-off-by: bachy <git@g-u-i.net>
This commit is contained in:
bachy
2012-01-08 19:40:28 +01:00
parent c22eb6bc11
commit f83a0b9aee
9 changed files with 460 additions and 108 deletions
+59 -98
View File
@@ -6,18 +6,19 @@
*/
/**
* Implementation of hook_menu().
* Implements hook_menu().
*/
function simplemenu_menu() {
$items = array();
$items['admin/config/simplemenu'] = array(
$items['admin/config/user-interface/simplemenu'] = array(
'title' => 'SimpleMenu',
'description' => 'Select the menu to display.',
'page callback' => 'drupal_get_form',
'page arguments' => array('simplemenu_admin_settings'),
'access arguments' => array('administer simplemenu'),
'file' => 'simplemenu.admin.inc',
'type' => MENU_NORMAL_ITEM,
);
return $items;
@@ -27,22 +28,29 @@ function simplemenu_menu() {
* Is simplemenu enabled for this page request?
*/
function simplemenu_enabled() {
static $enabled;
$enabled = &drupal_static(__FUNCTION__);
if (!isset($enabled)) {
global $theme;
$is_overlay = FALSE;
if (function_exists('overlay_get_mode')) {
$is_overlay = (overlay_get_mode() == 'child') ? TRUE : FALSE;
}
$exclusions = variable_get('simplemenu_exclusions', array());
$enabled = (!isset($exclusions[$theme]) || !$exclusions[$theme])
&& user_access('view simplemenu')
&& _simplemenu_page_visibility()
&& _simplemenu_superuser_active();
&& _simplemenu_superuser_active()
&& !$is_overlay;
}
return $enabled;
}
/**
* Implementation of hook_init().
* Implements hook_init().
*/
function simplemenu_init() {
// do a simple access check here, since theme isn't available to check yet
@@ -124,11 +132,11 @@ function _simplemenu_add_css() {
);
switch ($fix) {
case 'top':
$tags['@FIX@'] = "position: fixed;\n top: 0;";
$tags['@FIX@'] = "position: fixed;\n top: 0; left: 0;";
break;
case 'bottom':
$tags['@FIX@'] = "position: fixed;\n bottom: 0;";
$tags['@FIX@'] = "position: fixed;\n bottom: 0; left: 0;";
break;
default: // scroll
@@ -268,15 +276,17 @@ function simplemnu_get_zindex($name, $default) {
}
/**
* Implementation of hook_permission().
* Implements hook_permission().
*/
function simplemenu_permission() {
return array(
'view simplemenu' => array(
'title' => t('See and use the Simplemenu'),
'title' => t('View SimpleMenu'),
'description' => t('Display SimpleMenu to this user.'),
),
'administer simplemenu' => array(
'title' => t('Administer the Simplemenu'),
'title' => t('Administer SimpleMenu'),
'description' => t('Change settings of SimpleMenu.'),
),
);
}
@@ -373,14 +383,16 @@ function simplemenu_tree_remove_hidden($tree) {
* regardless of whether or not the menu item is expanded or not.
*/
function simplemenu_menu_tree($menu_name = 'management:0') {
static $menu_tree = array();
$menu_tree = &drupal_static(__FUNCTION__, array());
if (!isset($menu_output[$menu_name])) {
//$menu_tree[$menu_name] = simplemenu_tree_all_data($menu_name);
list($mname, $mlid) = explode(':', $menu_name);
$menu_tree[$menu_name] = menu_tree_all_data($mname);
// until we take $mlid in account, we can use $mname
// for the rest of the function
list($mname, $mlid) = explode(':', $menu_name);
if (!isset($menu_tree[$mname])) {
$menu_tree[$mname] = menu_tree_all_data($mname);
}
return $menu_tree[$menu_name];
return $menu_tree[$mname];
}
/**
@@ -393,66 +405,20 @@ function simplemenu_menu_tree($menu_name = 'management:0') {
* @todo we don't actually need $menu_name, $mlid would be sufficient
*/
function simplemenu_tree_all_data($root_menu = 'management:0') {
static $tree = array();
$tree = &drupal_static(__FUNCTION__, array());
list($menu_name, $mlid) = explode(':', $root_menu);
// Generate the cache ID for Drupal 7.
$cid = 'links:' . $menu_name . ':all-cid:' . $mlid . ':' . $GLOBALS['language']->language . ':0';
$max_depth = NULL;
$cid = 'links:' . $menu_name . ':all:' . $mlid . ':' . $GLOBALS['language']->language . ':' . (int) $max_depth;
if (!isset($tree[$cid])) {
// // If the static variable doesn't have the data, check {cache_menu}.
// $cache = cache_get($cid, 'cache_menu');
// if ($cache && isset($cache->data)) {
// $data = $cache->data;
// }
// else {
// // Build and run the query, and build the tree.
// $where = '';
// $args = array(':menu_name' => $menu_name);
// if ($mlid > 0) {
// $item = menu_link_load($mlid);
// if ($item) {
// // The tree is a subtree of $menu_name, so we need to restrict the query to
// // this subtree.
// $px = "p" . (int) $item['depth'];
// $where = " AND ml.$px = :ml AND ml.mlid != :mlid";
// $args[':ml'] = $item[$px];
// $args[':mlid'] = $mlid;
// }
// }
// // Select the links from the table, and recursively build the tree. We
// // LEFT JOIN since there is no match in {menu_router} for an external
// // link.
// $result = db_query("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.*
// FROM {menu_links} ml LEFT JOIN {menu_router} m ON m.path = ml.router_path
// WHERE ml.menu_name = :menu_name$where
// ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC", $args);
// $data['tree'] = menu_tree_data($result->fetchAssoc());
// $data['node_links'] = array();
// menu_tree_collect_node_links($data['tree'], $data['node_links']);
// // Cache the data.
// cache_set($cid, $data, 'cache_menu');
// }
// // Check access for the current user to each item in the tree.
// menu_tree_check_access($data['tree'], $data['node_links']);
// $tree[$cid] = $data['tree'];
// If the static variable doesn't have the data, check {cache_menu}.
$cache = cache_get($cid, 'cache_menu');
if ($cache && isset($cache->data)) {
// If the cache entry exists, it will just be the cid for the actual data.
// This avoids duplication of large amounts of data.
$cache = cache_get($cache->data, 'cache_menu');
if ($cache && isset($cache->data)) {
$data = $cache->data;
}
$data = $cache->data;
}
// If the tree data was not in the cache, $data will be NULL.
if (!isset($data)) {
else {
// Build the query using a LEFT JOIN since there is no match in
// {menu_router} for an external link.
$query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
@@ -467,6 +433,8 @@ function simplemenu_tree_all_data($root_menu = 'management:0') {
'page_callback',
'page_arguments',
'delivery_callback',
'tab_parent',
'tab_root',
'title',
'title_callback',
'title_arguments',
@@ -479,44 +447,39 @@ function simplemenu_tree_all_data($root_menu = 'management:0') {
$query->orderBy('p' . $i, 'ASC');
}
$query->condition('ml.menu_name', $menu_name);
if (isset($max_depth)) {
$query->condition('ml.depth', $max_depth, '<=');
}
if ($mlid) {
// The tree is for a single item, so we need to match the values in its
// p columns and 0 (the top level) with the plid values of other links.
$args = array(0);
for ($i = 1; $i < MENU_MAX_DEPTH; $i++) {
$args[] = $link["p$i"];
if ($mlid > 0) {
$item = menu_link_load($mlid);
if ($item) {
// The tree is a subtree of $menu_name, so we need to restrict the query to
// this subtree.
$px = "p" . (int) $item['depth'];
$and = db_and()->condition("ml.$px", $item[$px])->condition("ml.mlid", $mlid, '!=');
$query->condition($and);
}
$args = array_unique($args);
$query->condition('ml.plid', $args, 'IN');
$parents = $args;
$parents[] = $link['mlid'];
}
else {
// Get all links in this menu.
$parents = array();
}
// Select the links from the table, and build an ordered array of links
// using the query result object.
// Build an ordered array of links using the query result object.
$links = array();
foreach ($query->execute() as $item) {
$links[] = $item;
}
$data['tree'] = menu_tree_data($links, $parents);
$data['tree'] = menu_tree_data($links);
if (count($data['tree']) == 1) {
// Move the menu items from below to root
$key = key($data['tree']);
foreach ($data['tree'][$key]['below'] as $id => $item) {
$data['tree'][$id] = $item;
unset($data['tree'][$key]['below'][$id]);
}
}
$data['node_links'] = array();
menu_tree_collect_node_links($data['tree'], $data['node_links']);
// Cache the data, if it is not already in the cache.
$tree_cid = _menu_tree_cid($menu_name, $data);
if (!cache_get($tree_cid, 'cache_menu')) {
cache_set($tree_cid, $data, 'cache_menu');
}
// Cache the cid of the (shared) data using the menu and item-specific cid.
cache_set($cid, $tree_cid, 'cache_menu');
menu_tree_check_access($data['tree'], $data['node_links']);
cache_set($cid, $data, 'cache_menu');
}
// Check access for the current user to each item in the tree.
menu_tree_check_access($data['tree'], $data['node_links']);
$tree[$cid] = $data['tree'];
}
@@ -558,5 +521,3 @@ function _simplemenu_superuser_active() {
global $user;
return $user->uid != 1 || variable_get('simplemenu_uid1', 1) == 1;
}
// vim: ts=2 sw=2 et syntax=php