-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjumpmenu.php
More file actions
182 lines (155 loc) · 5.76 KB
/
Copy pathjumpmenu.php
File metadata and controls
182 lines (155 loc) · 5.76 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
if (!defined("PHORUM")) return;
// Register the additional CSS code for this module.
function phorum_mod_jumpmenu_css_register($data)
{
if ($data['css'] != 'css') return $data;
$data['register'][] = array(
"module" => "jumpmenu",
"where" => "after",
"source" => "file(mods/jumpmenu/jumpmenu.css.php)"
);
$data['register'][] = array(
"module" => "jumpmenu",
"where" => "after",
"source" => "template(jumpmenu::css)"
);
return $data;
}
// Register the additional JavaScript code for this module.
function phorum_mod_jumpmenu_javascript_register($data)
{
$data[] = array(
"module" => "jumpmenu",
"source" => "file(mods/jumpmenu/jumpmenu.js)"
);
return $data;
}
// Construct the forum menu drop down box.
function phorum_mod_jumpmenu_common()
{
global $PHORUM;
// ----------------------------------------------------------------------
// Build HTML code for the menu.
// ----------------------------------------------------------------------
$forum_info = array();
$menus = array();
// Load the forum list.
// The two different constructions are used for making this module
// compatible with both Phorum 5.2 and 5.3.
if (file_exists('./include/forum_functions.php')) {
include "./include/forum_functions.php";
$forums = phorum_build_forum_list();
} else {
require_once PHORUM_PATH.'/include/api/forums.php';
$forums = phorum_api_forums_tree();
}
if (count($forums) == 0) return;
$folders = array();
foreach ($forums as $id => $forum)
{
$parent = $forum['parent_id'];
if (!isset($menus[$parent])) {
$menus[$parent] = array();
}
if ($forum['folder_flag']) {
$class = 'mod_jumpmenu_folder';
$href = '';
$rel = 'mod_jumpmenu_folder[' .
$forum['forum_id']. ',' .
$forum['parent_id'].
']';
// Remember the folders the we see.
if (isset($folders[$parent])) {
$folders[$parent][] = $forum['forum_id'];
} else {
$folders[$parent] = array($forum['forum_id']);
}
} else {
$rel = 'mod_jumpmenu_forum';
$class = 'mod_jumpmenu_forum';
$href = 'href="'.phorum_get_url(PHORUM_LIST_URL, $forum['forum_id']).'"';
$forum_info[] = $forum['forum_id'] . ":" . $forum['parent_id'];
}
$menus[$parent][$forum['forum_id']] =
"<a $href rel=\"$rel\" " .
"id=\"mod_jumpmenu_item_{$forum['forum_id']}\" " .
"class=\"mod_jumpmenu_menu_item $class\">" .
$forum['name'] .
"</a>";
}
// Allow other modules to add menu items to the root menu.
// They can fill the array with extra items. Each item should be an
// array, containing the fields:
//
// - name: the name of the menu item
// - url: the URL to jump to when the link is clicked
// - class (optional): CSS class to add to the default menu item classlist
//
if (isset($PHORUM['hooks']['jumpmenu_add'])) {
$extra_items = phorum_hook('jumpmenu_add', array());
}
if (!empty($extra_items))
{
$menus[$PHORUM['vroot']]["separator"] =
'<a href="#" rel="mod_jumpmenu_forum" ' .
'class="mod_jumpmenu_menu_separator"> </a>';
$id = 0;
foreach ($extra_items as $item)
{
if (!isset($item['url'])) $item['url'] = '#';
if (!isset($item['name'])) $item['name'] = '[no name set for item!]';
if (!isset($item['class'])) $item['class'] = '';
$class = "mod_jumpmenu_menu_item mod_jumpmenu_forum {$item['class']}";
$id++;
$menus[$PHORUM['vroot']]["extra$id"] =
"<a href=\"{$item['url']}\" rel=\"mod_jumpmenu_forum\" " .
"id=\"mod_jumpmenu_item_extra$id\" " .
"class=\"$class\">{$item['name']}</a>";
}
}
foreach ($menus as $id => $menu)
{
// Drop empty folders.
if (isset($folders[$id])) {
foreach ($folders[$id] as $relid) {
if (empty($menus[$relid])) unset($menus[$id][$relid]);
}
}
if (!empty($menus[$id])) {
$menus[$id] =
"<div rel=\"mod_jumpmenu_menu\" class=\"mod_jumpmenu_menu\" " .
"id=\"mod_jumpmenu_menu_$id\">\n" .
" <div class=\"mod_jumpmenu_menu_content\" " .
"id=\"mod_jumpmenu_menu_content_$id\">" .
implode('', $menus[$id]) .
'</div></div>';
} else {
unset($menus[$id]);
}
}
$setvroot = '<script type="text/javascript">' .
'PhorumJumpMenu.vroot = ' . $PHORUM['vroot'] .
'</script>';
$PHORUM['DATA']['JUMPMENU'] = $setvroot . implode('', $menus);
}
// Load the forum jump menu code before showing the footer.
function phorum_mod_jumpmenu_before_footer()
{
global $PHORUM;
if (empty($PHORUM['DATA']['JUMPMENU'])) return;
print $PHORUM['DATA']['JUMPMENU'];
include phorum_get_template("jumpmenu::before_footer");
print "<script type=\"text/javascript\">\n" .
"\$PJ(document).ready(function(){\n" .
" // Make sure that the menus are in the top level #phorum elt.\n" .
" // This is needed to make positioning of the menus robust.\n" .
" \$PJ('div.mod_jumpmenu_menu').each(function () {\n" .
" \$PJ('body').append(this);\n" .
" });\n" .
" // Initialize the Phorum jumpmenu.\n" .
" PhorumJumpMenu.init();\n" .
"});\n" .
"</script>\n";
}
?>