forked from jsreese/monster_menus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmm_renderer.inc
95 lines (78 loc) · 2.97 KB
/
mm_renderer.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
// $Id: mm_renderer.inc 5381 2011-05-03 17:05:32Z dwilga $
/**
* @file
* Class used by mm_content_render_tree().
*/
class mmRenderer {
public function __construct() {
// To avoid having to sort, this array must be in increasing order
$this->state_to_css = array( // Do not translate these with t()
MM_GET_TREE_STATE_COLLAPSED => 'collapsed',
MM_GET_TREE_STATE_DENIED => 'denied',
MM_GET_TREE_STATE_EXPANDED => 'expanded',
MM_GET_TREE_STATE_HERE => 'here',
MM_GET_TREE_STATE_HIDDEN => 'hidden-entry',
MM_GET_TREE_STATE_LEAF => 'leaf',
MM_GET_TREE_STATE_NOT_WORLD => 'not-world',
MM_GET_TREE_STATE_RECYCLE => 'recycle-bin',
);
$this->state_cache = array();
$keys = array_keys($this->state_to_css);
$this->state_max = array_pop($keys);
}
public function state_class($leaf) {
if (!isset($this->state_cache[$leaf->state])) {
$state = $leaf->state;
$state_css = array();
$i = 0;
$bit = 0;
while ($state && $bit != $this->state_max) {
$bit = 1 << $i++;
if ($state & $bit && isset($this->state_to_css[$bit])) {
$state_css[] = $this->state_to_css[$bit];
$state ^= $bit;
}
}
$this->state_cache[$leaf->state] = join(' ', $state_css);
}
return $this->state_cache[$leaf->state];
}
public function prefix_all() {
return "<ul class=\"menu\">";
}
public function suffix_all() {
return '</ul>';
}
public function prefix_leaf($leaf, $item, $link_item) {
return '<li class="' . $this->state_class($leaf) . '">';
}
public function link_leaf($leaf, $item, $link_item) {
// if( $leaf->nodecount === '0' ) $item['title'] .= t(' [no pages]');
$atts = !empty($item['description']) ? array('title' => $item['description']) : array();
if ($link_item['path'] != $_GET['q'] &&
($leaf->state & (MM_GET_TREE_STATE_EXPANDED|MM_GET_TREE_STATE_HERE)) == (MM_GET_TREE_STATE_EXPANDED|MM_GET_TREE_STATE_HERE))
$atts['class'] = 'active';
if ($leaf->state & MM_GET_TREE_STATE_HIDDEN) $item['title'] .= ' ' . t('(hidden)');
if ($leaf->state & MM_GET_TREE_STATE_DENIED) $atts['rel'] = 'nofollow';
return l($item['title'], $link_item['path'], array('attributes' => $atts, 'query' => isset($item['query']) ? $item['query'] : NULL));
}
public function suffix_leaf($leaf, $item, $link_item) {
return "</li>\n";
}
public function prefix_parent($leaf, $item) {
return "\n<ul class=\"menu\">";
}
public function suffix_parent($leaf, $item) {
return "</ul>\n";
}
public function is_visible($leaf) {
if ($leaf->name == MM_ENTRY_NAME_RECYCLE) {
return mm_content_user_can_recycle($leaf->mmtid, 'r');
}
if (isset($leaf->perms) && ($leaf->perms['w'] || $leaf->perms['a'] || $leaf->perms['u'])) {
return TRUE;
}
return !variable_get('mm_hide_empty_pages', FALSE) || $leaf->nodecount !== '0'; // returns true if $leaf->nodecount is not set
}
}