comparison modules/book/book.module @ 5:2427550111ae 6.2

Drupal 6.2
author Franck Deroche <webmaster@defr.org>
date Tue, 23 Dec 2008 14:30:08 +0100
parents c1f4ac30525a
children fff6d4c8c043
comparison
equal deleted inserted replaced
4:d94886ac61a0 5:2427550111ae
1 <?php 1 <?php
2 // $Id: book.module,v 1.454.2.2 2008/02/13 11:20:47 goba Exp $ 2 // $Id: book.module,v 1.454.2.3 2008/03/25 14:03:02 goba Exp $
3 3
4 /** 4 /**
5 * @file 5 * @file
6 * Allows users to structure the pages of a site in a hierarchy or outline. 6 * Allows users to structure the pages of a site in a hierarchy or outline.
7 */ 7 */
1042 * An subtree of menu links in an array, in the order they should be rendered. 1042 * An subtree of menu links in an array, in the order they should be rendered.
1043 */ 1043 */
1044 function book_menu_subtree_data($item) { 1044 function book_menu_subtree_data($item) {
1045 static $tree = array(); 1045 static $tree = array();
1046 1046
1047 $cid = 'links:'. $item['menu_name'] .':subtree:'. $item['mlid']; 1047 // Generate a cache ID (cid) specific for this $menu_name and $item.
1048 $cid = 'links:'. $item['menu_name'] .':subtree-cid:'. $item['mlid'];
1048 1049
1049 if (!isset($tree[$cid])) { 1050 if (!isset($tree[$cid])) {
1050 $cache = cache_get($cid, 'cache_menu'); 1051 $cache = cache_get($cid, 'cache_menu');
1051 if ($cache && isset($cache->data)) { 1052 if ($cache && isset($cache->data)) {
1052 $data = $cache->data; 1053 // If the cache entry exists, it will just be the cid for the actual data.
1053 } 1054 // This avoids duplication of large amounts of data.
1054 else { 1055 $cache = cache_get($cache->data, 'cache_menu');
1056 if ($cache && isset($cache->data)) {
1057 $data = $cache->data;
1058 }
1059 }
1060 // If the subtree data was not in the cache, $data will be NULL.
1061 if (!isset($data)) {
1055 $match = array("menu_name = '%s'"); 1062 $match = array("menu_name = '%s'");
1056 $args = array($item['menu_name']); 1063 $args = array($item['menu_name']);
1057 $i = 1; 1064 $i = 1;
1058 while ($i <= MENU_MAX_DEPTH && $item["p$i"]) { 1065 while ($i <= MENU_MAX_DEPTH && $item["p$i"]) {
1059 $match[] = "p$i = %d"; 1066 $match[] = "p$i = %d";
1068 ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC"; 1075 ORDER BY p1 ASC, p2 ASC, p3 ASC, p4 ASC, p5 ASC, p6 ASC, p7 ASC, p8 ASC, p9 ASC";
1069 1076
1070 $data['tree'] = menu_tree_data(db_query($sql, $args), array(), $item['depth']); 1077 $data['tree'] = menu_tree_data(db_query($sql, $args), array(), $item['depth']);
1071 $data['node_links'] = array(); 1078 $data['node_links'] = array();
1072 menu_tree_collect_node_links($data['tree'], $data['node_links']); 1079 menu_tree_collect_node_links($data['tree'], $data['node_links']);
1073 // Cache the data. 1080 // Compute the real cid for book subtree data.
1074 cache_set($cid, $data, 'cache_menu'); 1081 $tree_cid = 'links:'. $menu_name .':subtree-data:'. md5(serialize($data));
1082 // Cache the data, if it is not already in the cache.
1083 if (!cache_get($tree_cid, 'cache_menu')) {
1084 cache_set($tree_cid, $data, 'cache_menu');
1085 }
1086 // Cache the cid of the (shared) data using the menu and item-specific cid.
1087 cache_set($cid, $tree_cid, 'cache_menu');
1075 } 1088 }
1076 // Check access for the current user to each item in the tree. 1089 // Check access for the current user to each item in the tree.
1077 menu_tree_check_access($data['tree'], $data['node_links']); 1090 menu_tree_check_access($data['tree'], $data['node_links']);
1078 $tree[$cid] = $data['tree']; 1091 $tree[$cid] = $data['tree'];
1079 } 1092 }