1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: $plugin_is_filter = 5 | ADMIN_PLUGIN | THEME_PLUGIN;
17: $plugin_description = gettext("A menu creation facility. The <em>Menu</em> tab admin interface lets you create arbitrary menu trees.");
18: $plugin_author = "Malte Müller (acrylian), Stephen Billard (sbillard)";
19:
20: $option_interface = 'menu_manager';
21:
22: if (OFFSET_PATH) {
23: require_once(dirname(dirname(__FILE__)) . '/template-functions.php');
24: zp_register_filter('admin_tabs', 'menu_tabs');
25: } else {
26: zp_register_filter('admin_toolbox_global', 'menu_admin_toolbox_global');
27: }
28:
29: if (!defined('MENU_TRUNCATE_STRING'))
30: define('MENU_TRUNCATE_STRING', getOption('menu_truncate_string'));
31: if (!defined('MENU_TRUNCATE_INDICATOR'))
32: define('MENU_TRUNCATE_INDICATOR', getOption('menu_truncate_indicator'));
33:
34: 35: 36: 37: 38: 39:
40: class menu_manager {
41:
42: 43: 44: 45:
46: function __construct() {
47: setOptionDefault('menu_truncate_string', 0);
48: setOptionDefault('menu_truncate_indicator', '');
49: }
50:
51: function getOptionsSupported() {
52: global $_common_truncate_handler;
53:
54: $options = array(
55: gettext('Truncate indicator*') => array('key' => 'menu_truncate_indicator', 'type' => OPTION_TYPE_TEXTBOX,
56: 'order' => 2,
57: 'disabled' => $_common_truncate_handler,
58: 'desc' => gettext('Append this string to truncated titles.')),
59: gettext('Truncate titles*') => array('key' => 'menu_truncate_string', 'type' => OPTION_TYPE_TEXTBOX,
60: 'order' => 1,
61: 'desc' => gettext('Limit titles to this many characters. Zero means no limit.'))
62: );
63: if ($_common_truncate_handler) {
64: $options['note'] = array('key' => 'menu_truncate_note', 'type' => OPTION_TYPE_NOTE,
65: 'order' => 8,
66: 'desc' => '<p class="notebox">' . $_common_truncate_handler . '</p>');
67: } else {
68: $_common_truncate_handler = gettext('* These options may be set via the <a href="javascript:gotoName(\'menu_manager\');"><em>menu_manager</em></a> plugin options.');
69: $options['note'] = array('key' => 'menu_truncate_note',
70: 'type' => OPTION_TYPE_NOTE,
71: 'order' => 8,
72: 'desc' => gettext('<p class="notebox">*<strong>Note:</strong> The setting of these options are shared with other plugins.</p>'));
73: }
74: return $options;
75: }
76:
77: function handleOption($option, $currentValue) {
78:
79: }
80:
81: }
82:
83: 84: 85: 86:
87: function menu_admin_toolbox_global($zf) {
88: if (zp_loggedin(ADMIN_RIGHTS)) {
89: echo "<li>";
90: printLinkHTML($zf . '/' . PLUGIN_FOLDER . '/menu_manager/menu_tab.php', gettext("Menu"), NULL, NULL, NULL);
91: echo "</li>\n";
92: }
93: }
94:
95: 96: 97: 98: 99: 100: 101:
102: function menu_tabs($tabs) {
103: if (zp_loggedin()) {
104: $newtabs = array();
105: foreach ($tabs as $key => $tab) {
106: if ($key == 'tags') {
107: $newtabs['menu'] = array('text' => gettext("menu"),
108: 'link' => WEBPATH . "/" . ZENFOLDER . '/' . PLUGIN_FOLDER . '/menu_manager/menu_tab.php?page=menu&tab=menu',
109: 'default' => 'menu',
110: 'subtabs' => NULL);
111: }
112: $newtabs[$key] = $tab;
113: }
114: return $newtabs;
115: }
116: return $tabs;
117: }
118:
119: 120: 121: 122: 123:
124:
125: $_menu_manager_items = array();
126:
127: 128: 129: 130: 131: 132: 133:
134: function getMenuItems($menuset, $visible) {
135: global $_menu_manager_items;
136: if (array_key_exists($menuset, $_menu_manager_items) &&
137: array_key_exists($visible, $_menu_manager_items[$menuset])) {
138: return $_menu_manager_items[$menuset][$visible];
139: }
140: switch ($visible) {
141: case 'visible':
142: $where = " WHERE `show` = 1 AND menuset = " . db_quote($menuset);
143: break;
144: case 'hidden':
145: $where = " WHERE `show` = 0 AND menuset = " . db_quote($menuset);
146: break;
147: default:
148: $where = " WHERE menuset = " . db_quote($menuset);
149: $visible = 'all';
150: break;
151: }
152: $result = query_full_array("SELECT * FROM " . prefix('menu') . $where . " ORDER BY sort_order", false, 'sort_order');
153: $_menu_manager_items[$menuset][$visible] = $result;
154: return $_menu_manager_items[$menuset][$visible];
155: }
156:
157: 158: 159: 160: 161: 162:
163: function getItem($id) {
164: $menuset = checkChosenMenuset();
165: $result = query_single_row("SELECT * FROM " . prefix('menu') . " WHERE menuset = " . db_quote($menuset) . " AND id = " . $id);
166: return $result;
167: }
168:
169: 170: 171: 172: 173:
174: function checkChosenMenuset($default = 'default') {
175: if (isset($_GET['menuset'])) {
176: $menuset = sanitize($_GET['menuset']);
177: } else if (isset($_POST['menuset'])) {
178: $menuset = sanitize($_POST['menuset']);
179: } else {
180: $menuset = $default;
181: }
182: return $menuset;
183: }
184:
185: 186: 187: 188: 189:
190: function checkChosenItemStatus() {
191: if (isset($_GET['visible'])) {
192: return sanitize($_GET['visible']);
193: } else {
194: return 'all';
195: }
196: }
197:
198: 199: 200: 201: 202:
203: function getItemTitleAndURL($item) {
204: global $_zp_gallery;
205: $themename = $_zp_gallery->getCurrentTheme();
206: $array = array("title" => '', "url" => '', "name" => '', 'protected' => false, 'theme' => $themename);
207: $valid = true;
208: $title = get_language_string($item['title']);
209: switch ($item['type']) {
210: case "galleryindex":
211: $array = array("title" => get_language_string($item['title']), "url" => WEBPATH, "name" => WEBPATH, 'protected' => false, 'theme' => $themename);
212: break;
213: case "album":
214: $folderFS = internalToFilesystem($item['link']);
215: $localpath = ALBUM_FOLDER_SERVERPATH . $folderFS;
216: $dynamic = hasDynamicAlbumSuffix($folderFS) && !is_dir($folderFS);
217: $valid = file_exists($localpath) && ($dynamic || is_dir($localpath));
218: if (!$valid || strpos($localpath, '..') !== false) {
219: $valid = false;
220: $url = '';
221: $protected = 0;
222: } else {
223: $obj = newAlbum($item['link']);
224: $url = $obj->getLink(0);
225: $protected = $obj->isProtected();
226: $title = $obj->getTitle();
227: }
228: $array = array("title" => $title, "url" => $url, "name" => $item['link'], 'protected' => $protected, 'theme' => $themename);
229: break;
230: case "zenpagepage":
231: if(class_exists('zenpage')) {
232: $sql = 'SELECT * FROM ' . prefix('pages') . ' WHERE `titlelink`="' . $item['link'] . '"';
233: $result = query_single_row($sql);
234: if (is_array($result)) {
235: $obj = new ZenpagePage($item['link']);
236: $url = $obj->getLink(0);
237: $protected = $obj->isProtected();
238: $title = $obj->getTitle();
239: } else {
240: $valid = false;
241: $url = '';
242: $protected = 0;
243: }
244: $array = array("title" => $title, "url" => $url, "name" => $item['link'], 'protected' => $protected, 'theme' => $themename);
245: }
246: break;
247: case "zenpagenewsindex":
248: if(class_exists('zenpage')) {
249: $url = getNewsIndexURL();
250: $array = array("title" => get_language_string($item['title']), "url" => $url, "name" => $url, 'protected' => false);
251: }
252: break;
253: case "zenpagecategory":
254: if(class_exists('zenpage')) {
255: $sql = "SELECT title FROM " . prefix('news_categories') . " WHERE titlelink = '" . $item['link'] . "'";
256: $obj = query_single_row($sql, false);
257: if ($obj) {
258: $obj = new ZenpageCategory($item['link']);
259: $title = $obj->getTitle();
260: $protected = $obj->isProtected();
261: $url = $obj->getLink(0);
262: } else {
263: $valid = false;
264: $url = '';
265: $protected = 0;
266: }
267: $array = array("title" => $title, "url" => $url, "name" => $item['link'], 'protected' => $protected, 'theme' => $themename);
268: }
269: break;
270: case "custompage":
271: $root = SERVERPATH . '/' . THEMEFOLDER . '/' . $themename . '/';
272: if (file_exists($root . $item['link'] . '.php')) {
273: $url = zp_apply_filter('getLink', rewrite_path(_PAGE_ . '/' . $item['link'], "/index.php?p=" . $item['link']), $item['link'] . '.php', NULL);
274: } else {
275: $valid = false;
276: $url = '';
277: }
278: $array = array("title" => $title, "url" => $url, "name" => $item['link'], 'protected' => false, 'theme' => $themename);
279: break;
280: case "customlink":
281: $array = array("title" => get_language_string($item['title']), "url" => $item['link'], "name" => $item['link'], 'protected' => false, 'theme' => $themename);
282: break;
283: case 'menulabel':
284: $array = array("title" => get_language_string($item['title']), "url" => NULL, 'name' => $item['title'], 'protected' => false, 'theme' => $themename);
285: break;
286: default:
287: $array = array("title" => get_language_string($item['title']), "url" => $item['link'], "name" => $item['link'], 'protected' => false, 'theme' => $themename);
288: break;
289: }
290: $limit = MENU_TRUNCATE_STRING;
291: $array['valid'] = $valid;
292: if ($limit) {
293: $array['title'] = shortenContent($array['title'], $limit, MENU_TRUNCATE_INDICATOR);
294: }
295: return $array;
296: }
297:
298: 299: 300:
301:
302: 303: 304: 305:
306: function getMenuVisibility() {
307: if (zp_loggedin(VIEW_ALL_RIGHTS)) {
308: return "all";
309: } else {
310: return "visible";
311: }
312: }
313:
314: 315: 316: 317: 318: 319: 320: 321: 322: 323:
324: function inventMenuItem($menuset, $visibility) {
325: global $_zp_gallery_page, $_zp_current_album, $_zp_current_image, $_zp_current_search, $_menu_manager_items,
326: $_zp_current_zenpage_news, $_zp_current_zenpage_page;
327: $currentkey = $insertpoint = NULL;
328: $newitems = array();
329: switch ($_zp_gallery_page) {
330: case 'image.php':
331: $name = '';
332: if (in_context(ZP_SEARCH_LINKED) && !in_context(ZP_ALBUM_LINKED)) {
333: $dynamic = $_zp_current_search->getDynamicAlbum();
334: if (empty($dynamic)) {
335: foreach ($_menu_manager_items[$menuset][$visibility] as $key => $item) {
336: if ($item['type'] == 'custompage' && $item['link'] == 'search') {
337: $insertpoint = $item['sort_order'];
338: $currentkey = $insertpoint . '-9999';
339: break;
340: }
341: }
342: }
343: } else {
344: $name = $_zp_current_album->name;
345: }
346: if (!empty($name)) {
347: foreach ($_menu_manager_items[$menuset][$visibility] as $key => $item) {
348: if ($item['type'] == 'album' && $item['title'] == $name) {
349: $insertpoint = $item['sort_order'];
350: $currentkey = $insertpoint . '-9999';
351: break;
352: }
353: }
354: }
355: if (!empty($currentkey)) {
356: $item = array('id' => 9999, 'sort_order' => $currentkey, 'parentid' => $item['id'], 'type' => 'image',
357: 'include_li' => true, 'title' => $_zp_current_image->getTitle(),
358: 'show' => 1, 'link' => '', 'menuset' => $menuset);
359: }
360: break;
361: case 'news.php':
362: if (in_context(ZP_SEARCH_LINKED)) {
363: foreach ($_menu_manager_items[$menuset][$visibility] as $key => $item) {
364: if ($item['type'] == 'custompage' && $item['link'] == 'search') {
365: $insertpoint = $item['sort_order'];
366: $currentkey = $insertpoint . '-9999';
367: break;
368: }
369: }
370: } else {
371: foreach ($_menu_manager_items[$menuset][$visibility] as $key => $item) {
372: if ($item['type'] == 'zenpagenewsindex') {
373: $insertpoint = $item['sort_order'];
374: $currentkey = $insertpoint . '-9999';
375: break;
376: }
377: }
378: }
379: if (!empty($currentkey)) {
380: if (is_NewsArticle()) {
381: $item = array('id' => 9999, 'sort_order' => $currentkey, 'parentid' => $item['id'], 'type' => 'zenpagenews',
382: 'include_li' => true, 'title' => $_zp_current_zenpage_news->getTitle(),
383: 'show' => 1, 'link' => '', 'menuset' => $menuset);
384: } else {
385: $currentkey = false;
386: }
387: }
388: break;
389: case 'pages.php':
390: if (in_context(ZP_SEARCH_LINKED)) {
391: foreach ($_menu_manager_items[$menuset][$visibility] as $key => $item) {
392: if ($item['type'] == 'custompage' && $item['link'] == 'search') {
393: $insertpoint = $item['sort_order'];
394: $currentkey = $insertpoint . '-9999';
395: $item = array('id' => 9999, 'sort_order' => $currentkey, 'parentid' => $item['id'], 'type' => 'zenpagepage',
396: 'include_li' => true, 'title' => $_zp_current_zenpage_page->getTitle(),
397: 'show' => 1, 'link' => '', 'menuset' => $menuset);
398: break;
399: }
400: }
401: }
402: break;
403: }
404: if (!empty($currentkey)) {
405: foreach ($_menu_manager_items[$menuset][$visibility] as $key => $olditem) {
406: $newitems[$key] = $olditem;
407: if ($olditem['sort_order'] == $insertpoint) {
408: $newitems[$currentkey] = $item;
409: }
410: }
411: $_menu_manager_items[$menuset][$visibility] = $newitems;
412: }
413: return $currentkey;
414: }
415:
416: 417: 418: 419: 420:
421: function getCurrentMenuItem($menuset) {
422: $currentpageURL = rtrim(str_replace('\\', '/', html_encode(getRequestURI())), '/');
423:
424: if (isset($_GET['page'])) {
425: if (MOD_REWRITE) {
426: if (isset($_GET['album'])) {
427: $target = '/' . _PAGE_ . '/' . sanitize($_GET['page']);
428: } else {
429: $target = '/' . sanitize($_GET['page']);
430: }
431: $i = strrpos($currentpageURL, $target);
432: if ($i == (strlen($currentpageURL) - strlen($target))) {
433: $currentpageURL = substr($currentpageURL, 0, $i);
434: }
435: } else {
436: $target = '&page=' . sanitize($_GET['page']);
437: $i = strpos($currentpageURL, $target);
438: if ($i !== false) {
439: $currentpageURL = substr($currentpageURL, 0, $i) . substr($currentpageURL, $i + strlen($target));
440: }
441: }
442: }
443: $visibility = 'all';
444: $items = getMenuItems($menuset, $visibility);
445: $currentkey = NULL;
446: foreach ($items as $key => $item) {
447: switch ($item['type']) {
448: case 'menulabel':
449: case 'menufunction':
450: case 'html':
451: break;
452: default:
453: $checkitem = getItemTitleAndURL($item);
454: if ($currentpageURL == html_encode(rtrim($checkitem['url'], '/'))) {
455: $currentkey = $key;
456: break 2;
457: }
458: break;
459: }
460: }
461: if (is_null($currentkey)) {
462: $currentkey = inventMenuItem($menuset, $visibility);
463: }
464: return $currentkey;
465: }
466:
467: 468: 469: 470: 471:
472: function getMenumanagerPredicessor($menuset = 'default') {
473: $sortorder = getCurrentMenuItem($menuset);
474: $items = getMenuItems($menuset, getMenuVisibility());
475: if (count($items) == 0)
476: return NULL;
477: if (empty($sortorder))
478: return NULL;
479: $order = explode('-', $sortorder);
480: $next = array_pop($order) - 1;
481: $saveorder = $order;
482: while ($next >= 0) {
483: $order = $saveorder;
484: array_push($order, sprintf('%03u', $next));
485: $sortorder = implode('-', $order);
486: if (array_key_exists($sortorder, $items) && $items[$sortorder]['type'] != 'menulabel') {
487: return getItemTitleAndURL($items[$sortorder]);
488: }
489: $next--;
490: }
491: return NULL;
492: }
493:
494: 495: 496: 497: 498: 499: 500: 501:
502: function printMenumanagerPrevLink($text, $menuset = 'default', $title = NULL, $class = NULL, $id = NULL) {
503: $itemarray = getMenumanagerPredicessor($menuset);
504: if (is_array($itemarray)) {
505: if (is_null($title))
506: $title = $itemarray['title'];
507: printLinkHTML($itemarray['url'], $text, $title, $class, $id);
508: } else {
509: echo '<span class="disabledlink">' . html_encode($text) . '</span>';
510: }
511: }
512:
513: 514: 515: 516: 517:
518: function getMenumanagerSuccessor($menuset = 'default') {
519: $sortorder = getCurrentMenuItem($menuset);
520: $items = getMenuItems($menuset, getMenuVisibility());
521: if (count($items) == 0)
522: return NULL;
523: if (empty($sortorder))
524: return NULL;
525: $order = explode('-', $sortorder);
526: $next = array_pop($order) + 1;
527: $short_order = $order;
528: array_push($order, sprintf('%03u', $next));
529: $sortorder = implode('-', $order);
530: while ($next <= 999) {
531: $order = $short_order;
532: array_push($order, sprintf('%03u', $next));
533: $sortorder = implode('-', $order);
534: if (array_key_exists($sortorder, $items)) {
535: if ($items[$sortorder]['type'] != 'menulabel') {
536: return getItemTitleAndURL($items[$sortorder]);
537: }
538: }
539: $next++;
540: }
541: return NULL;
542: }
543:
544: 545: 546: 547: 548: 549: 550: 551:
552: function printMenumanagerNextLink($text, $menuset = 'default', $title = NULL, $class = NULL, $id = NULL) {
553: $itemarray = getMenumanagerSuccessor($menuset);
554: if (is_array($itemarray)) {
555: if (is_null($title))
556: $title = $itemarray['title'];
557: printLinkHTML($itemarray['url'], $text, $title, $class, $id);
558: } else {
559: echo '<span class="disabledlink">' . html_encode($text) . '</span>';
560: }
561: }
562:
563: 564: 565: 566: 567: 568: 569: 570: 571: 572: 573: 574:
575: function printMenuemanagerPageListWithNav($prevtext, $nexttext, $menuset = 'default', $class = 'pagelist', $nextprev = true, $id = NULL, $firstlast = true, $navlen = 9) {
576: $currentitem = getMenuFromLink(html_encode(urldecode(getRequestURI())), $menuset);
577: if (is_null($currentitem))
578: return;
579: $orders = explode('-', $currentitem['sort_order']);
580: array_pop($orders);
581: $lookfor = implode('-', $orders) . '-';
582: $sql = 'SELECT `sort_order` FROM ' . prefix('menu') . ' WHERE `sort_order` LIKE "' . $lookfor . '%" ORDER BY `sort_order` ASC';
583: $result = query_full_array($sql, false, 'sort_order');
584: if (is_array($result)) {
585: $l = strlen($lookfor) + 3;
586: foreach ($result as $key => $item) {
587: if (strlen($key) > $l)
588: unset($result[$key]);
589: }
590: $itemlist = array_keys($result);
591: $total = count($itemlist);
592: $current = array_search($currentitem['sort_order'], $itemlist) + 1;
593: if ($total < 2) {
594: $class .= ' disabled_nav';
595: }
596: if ($navlen == 0)
597: $navlen = $total;
598: $extralinks = 2;
599: if ($firstlast)
600: $extralinks = $extralinks + 2;
601: $len = floor(($navlen - $extralinks) / 2);
602: $j = max(round($extralinks / 2), min($current - $len - (2 - round($extralinks / 2)), $total - $navlen + $extralinks - 1));
603: $ilim = min($total, max($navlen - round($extralinks / 2), $current + floor($len)));
604: $k1 = round(($j - 2) / 2) + 1;
605: $k2 = $total - round(($total - $ilim) / 2);
606: $items = getMenuItems($menuset, getMenuVisibility());
607: echo "<div" . (($id) ? " id=\"$id\"" : "") . " class=\"$class\">\n";
608: echo "<ul class=\"$class\">\n";
609: if ($nextprev) {
610: echo "<li class=\"prev\">";
611: printMenumanagerPrevLink($prevtext, $menuset, $prevtext, gettext("Previous Page"));
612: echo "</li>\n";
613: }
614: if ($firstlast) {
615: echo '<li class="' . ($current == 1 ? 'current' : 'first') . '">';
616: $itemarray = getItemTitleAndURL($items[$itemlist[0]]);
617: printLinkHTML($itemarray['url'], 1, gettext("Page 1"));
618: echo "</li>\n";
619: if ($j > 2) {
620: echo "<li>";
621: $itemarray = getItemTitleAndURL($items[$itemlist[$k1 - 1]]);
622: printLinkHTML($itemarray['url'], ($j - 1 > 2) ? '...' : $k1, sprintf(ngettext('Page %u', 'Page %u', $k1), $k1));
623: echo "</li>\n";
624: }
625: }
626: for ($i = $j; $i <= $ilim; $i++) {
627: echo "<li" . (($i == $current) ? " class=\"current\"" : "") . ">";
628: $itemarray = getItemTitleAndURL($items[$itemlist[$i - 1]]);
629: if ($i == $current) {
630: $title = sprintf(ngettext('Page %1$u (Current Page)', 'Page %1$u (Current Page)', $i), $i);
631: } else {
632: $title = sprintf(ngettext('Page %1$u', 'Page %1$u', $i), $i);
633: }
634: printLinkHTML($itemarray['url'], $i, $title);
635: echo "</li>\n";
636: }
637: if ($i < $total) {
638: echo "<li>";
639: $itemarray = getItemTitleAndURL($items[$itemlist[$k2 - 1]]);
640: printLinkHTML($itemarray['url'], ($total - $i > 1) ? '...' : $k2, sprintf(ngettext('Page %u', 'Page %u', $k2), $k2));
641: echo "</li>\n";
642: }
643: if ($firstlast && $i <= $total) {
644: echo "\n <li class=\"last\">";
645: $itemarray = getItemTitleAndURL($items[$itemlist[$total - 1]]);
646: printLinkHTML($itemarray['url'], $total, sprintf(ngettext('Page {%u}', 'Page {%u}', $total), $total));
647: echo "</li>";
648: }
649: if ($nextprev) {
650: echo "<li class=\"next\">";
651: printMenumanagerNextLink($nexttext, gettext("Next Page"));
652: echo "</li>\n";
653: }
654: echo "</ul>\n";
655: echo "</div>\n";
656: }
657: }
658:
659: 660: 661: 662: 663: 664: 665: 666: 667:
668: function printMenuemanagerPageList($menuset = 'default', $class = 'pagelist', $id = NULL, $firstlast = true, $navlen = 9) {
669: printMenuemanagerPageListWithNav(null, null, $menuset, false, $class, $id, false, $navlen);
670: }
671:
672: 673: 674: 675: 676:
677: function getParentMenuItems($menuset = 'default') {
678: $sortorder = getCurrentMenuItem($menuset);
679: $items = getMenuItems($menuset, getMenuVisibility());
680: if (count($items) > 0) {
681: if ($sortorder) {
682: $parents = array();
683: $order = explode('-', $sortorder);
684: array_pop($order);
685: $look = array();
686: while (count($order) > 0) {
687: $look = implode('-', $order);
688: array_pop($order);
689: if (array_key_exists($look, $items)) {
690: array_unshift($parents, $items[$look]);
691: }
692: }
693: if (!empty($parents)) {
694: sortMultiArray($parents, 'sort_order', $descending = false, $natsort = false, $case_sensitive = false);
695: return $parents;
696: }
697: }
698: }
699: return false;
700: }
701:
702: 703: 704: 705: 706: 707: 708: 709: 710: 711: 712: 713: 714: 715: 716: 717: 718: 719:
720: function printMenumanagerBreadcrumb($menuset = 'default', $before = '', $between = ' | ', $after = ' | ') {
721: $parents = getParentMenuItems($menuset);
722: if ($parents) {
723: if ($before) {
724: echo '<span class="beforetext">' . html_encode($before) . '</span>';
725: }
726: if ($between) {
727: $between = '<span class="betweentext">' . html_encode($between) . '</span>';
728: }
729: $i = 0;
730: foreach ($parents as $item) {
731: if ($i > 0) {
732: echo $between;
733: }
734: $itemarray = getItemTitleAndURL($item);
735: if ($item['type'] == 'menulabel') {
736: echo html_encode($itemarray['title']);
737: } else {
738: printLinkHTML($itemarray['url'], $itemarray['title'], $itemarray['title']);
739: }
740: $i++;
741: }
742: if ($after) {
743: echo '<span class="aftertext">' . html_encode($after) . '</span>';
744: }
745: }
746: }
747:
748: 749: 750: 751: 752: 753:
754: function getMenuFromLink($link, $menuset = 'default') {
755: $link = rtrim(str_replace('\\', '/', $link), '/');
756: $items = getMenuItems($menuset, getMenuVisibility());
757: foreach ($items as $item) {
758: $itemarray = getItemTitleAndURL($item);
759: if ($itemarray['url'] == $link)
760: return $item;
761: }
762: return NULL;
763: }
764:
765: 766: 767: 768: 769: 770:
771: function submenuOf($link, $menuset = 'default') {
772: $link_menu = getMenuFromLink($link, $menuset);
773: if (is_array($link_menu)) {
774: $current = getCurrentMenuItem($menuset);
775: $items = getMenuItems($menuset, getMenuVisibility());
776: if (!is_null($current)) {
777: $sortorder = $link_menu['sort_order'];
778: if (strlen($current) > strlen($sortorder)) {
779: $p = strpos($current, $sortorder);
780: return $p === 0;
781: }
782: }
783: }
784: return false;
785: }
786:
787: 788: 789: 790: 791: 792: 793: 794: 795: 796: 797: 798:
799: function createMenuIfNotExists($menuitems, $menuset = 'default') {
800: $count = db_count('menu', 'WHERE menuset=' . db_quote($menuset));
801: if ($count == 0) {
802: require_once(dirname(__FILE__) . '/menu_manager/menu_manager-admin-functions.php');
803: $success = 1;
804: $orders = array();
805: foreach ($menuitems as $key => $result) {
806: if (array_key_exists('nesting', $result)) {
807: $nesting = $result['nesting'];
808: } else {
809: $nesting = 0;
810: }
811: while ($nesting + 1 < count($orders))
812: array_pop($orders);
813: while ($nesting + 1 > count($orders))
814: array_push($orders, -1);
815: $result['id'] = 0;
816: if (isset($result['include_li'])) {
817: $includeli = $result['include_li'];
818: } else {
819: $includeli = 1;
820: }
821: $type = $result['type'];
822: switch ($type) {
823: case 'all_items':
824: $orders[$nesting] ++;
825: query("INSERT INTO " . prefix('menu') . " (`title`,`link`,`type`,`show`,`menuset`,`sort_order`) " .
826: "VALUES ('" . gettext('Home') . "', '" . WEBPATH . '/' . "','galleryindex','1'," . db_quote($menuset) . ',' . db_quote($orders), true);
827: $orders[$nesting] = addAlbumsToDatabase($menuset, $orders);
828: if (extensionEnabled('zenpage')) {
829: $orders[$nesting] ++;
830: query("INSERT INTO " . prefix('menu') . " (title`,`link`,`type`,`show`,`menuset`,`sort_order`) " .
831: "VALUES ('" . gettext('News index') . "', '" . getNewsIndexURL() . "','zenpagenewsindex','1'," . db_quote($menuset) . ',' . db_quote(sprintf('%03u', $base + 1)), true);
832: $orders[$nesting] = addPagesToDatabase($menuset, $orders) + 1;
833: $orders[$nesting] = addCategoriesToDatabase($menuset, $orders);
834: }
835: $type = false;
836: break;
837: case 'all_albums':
838: $orders[$nesting] ++;
839: $orders[$nesting] = addAlbumsToDatabase($menuset, $orders);
840: $type = false;
841: break;
842: case 'all_zenpagepages':
843: $orders[$nesting] ++;
844: $orders[$nesting] = addPagesToDatabase($menuset, $orders);
845: $type = false;
846: break;
847: case 'all_zenpagecategorys':
848: $orders[$nesting] ++;
849: $orders[$nesting] = addCategoriesToDatabase($menuset, $orders);
850: $type = false;
851: break;
852: case 'album':
853: $result['title'] = NULL;
854: if (empty($result['link'])) {
855: $success = -1;
856: debugLog(sprintf(gettext('createMenuIfNotExists item %s has an empty link.'), $key));
857: }
858: break;
859: case 'galleryindex':
860: $result['link'] = NULL;
861: if (empty($result['title'])) {
862: $success = -1;
863: debugLog(sprintf(gettext('createMenuIfNotExists item %s has an empty title.'), $key));
864: }
865: break;
866: case 'zenpagepage':
867: $result['title'] = NULL;
868: if (empty($result['link'])) {
869: $success = -1;
870: debugLog(sprintf(gettext('createMenuIfNotExists item %s has an empty link.'), $key));
871: }
872: break;
873: case 'zenpagenewsindex':
874: $result['link'] = NULL;
875: if (empty($result['title'])) {
876: $success = -1;
877: debugLog(sprintf(gettext('createMenuIfNotExists item %s has an empty title.'), $key));
878: }
879: break;
880: case 'zenpagecategory':
881: $result['title'] = NULL;
882: if (empty($result['link'])) {
883: $success = -1;
884: debugLog(sprintf(gettext('createMenuIfNotExists item %s has an empty link.'), $key));
885: }
886: break;
887: case 'custompage':
888: if (empty($result['title']) || empty($result['link'])) {
889: $success = -1;
890: debugLog(sprintf(gettext('createMenuIfNotExists item %s has an empty title or link.'), $key));
891: }
892: break;
893: case 'customlink':
894: if (empty($result['title'])) {
895: $success = -1;
896: debugLog(sprintf(gettext('createMenuIfNotExists item %s has an empty title.'), $key));
897: } else if (empty($result['link'])) {
898: $result['link'] = seoFriendly(get_language_string($result['title']));
899: }
900: break;
901: case 'menulabel':
902: if (empty($result['title'])) {
903: $success = -1;
904: debugLog(sprintf(gettext('createMenuIfNotExists item %s has an empty title.'), $key));
905: }
906: $result['link'] = sha1($result['title']);
907: break;
908: case 'menufunction':
909: if (empty($result['title']) || empty($result['link'])) {
910: $success = -1;
911: debugLog(sprintf(gettext('createMenuIfNotExists item %s has an empty title or link.'), $key));
912: }
913: break;
914: case 'html':
915: if (empty($result['title']) || empty($result['link'])) {
916: $success = -1;
917: debugLog(sprintf(gettext('createMenuIfNotExists item %s has an empty title or link.'), $key));
918: }
919: break;
920: default:
921: $success = -1;
922: debugLog(sprintf(gettext('createMenuIfNotExists item %s has an invalid type.'), $key));
923: break;
924: }
925: if ($success > 0 && $type) {
926: $orders[$nesting] ++;
927: $sort_order = '';
928: for ($i = 0; $i < count($orders); $i++) {
929: $sort_order .= sprintf('%03u', $orders[$i]) . '-';
930: }
931: $sort_order = substr($sort_order, 0, -1);
932: $sql = "INSERT INTO " . prefix('menu') . " (`title`,`link`,`type`,`show`,`menuset`,`sort_order`,`include_li`) " .
933: "VALUES (" . db_quote($result['title']) .
934: ", " . db_quote($result['link']) .
935: "," . db_quote($result['type']) . "," . $result['show'] .
936: "," . db_quote($menuset) . "," . db_quote($sort_order) . ",$includeli)";
937: if (!query($sql, false)) {
938: $success = -2;
939: debugLog(sprintf(gettext('createMenuIfNotExists item %1$s query (%2$s) failed: %3$s.'), $key, $sql, db_error()));
940: }
941: }
942: }
943: } else {
944: $success = 0;
945: }
946: if ($success < 0) {
947: trigger_error(gettext('createMenuIfNotExists has posted processing errors to your debug log.'), E_USER_NOTICE);
948: }
949: return $success;
950: }
951:
952: 953: 954: 955: 956: 957:
958: function getMenuItemChilds($menuset = 'default', $allchilds = false) {
959: $sortorder = getCurrentMenuItem($menuset);
960: $items = getMenuItems($menuset, getMenuVisibility());
961: if (count($items) > 0) {
962: if ($sortorder) {
963: $length = strlen($sortorder);
964: $level = explode('-', $sortorder);
965: $level = count($level);
966: $childs = array();
967: foreach ($items as $item) {
968: $itemlevel = explode('-', $item['sort_order']);
969: $itemlevel = count($itemlevel);
970: if ($allchilds) {
971: $is_validchild = true;
972: } else {
973: if ($itemlevel == $level + 1) {
974: $is_validchild = true;
975: } else {
976: $is_validchild = false;
977: }
978: }
979: if (substr($item['sort_order'], 0, $length) == $sortorder && $item['sort_order'] != $sortorder && $is_validchild) {
980: array_push($childs, $item);
981: }
982: }
983: if (!empty($childs)) {
984: return $childs;
985: }
986: }
987: }
988: return false;
989: }
990:
991: 992: 993: 994: 995: 996: 997: 998: 999: 1000: 1001: 1002: 1003: 1004: 1005: 1006: 1007: 1008: 1009:
1010: function printCustomMenu($menuset = 'default', $option = 'list', $css_id = '', $css_class_topactive = '', $css_class = '', $css_class_active = '', $showsubs = 0, $counter = false) {
1011: global $_zp_zenpage, $_zp_gallery_page, $_zp_current_zenpage_page, $_zp_current_category;
1012: $itemcounter = '';
1013: if ($css_id != "") {
1014: $css_id = " id='" . $css_id . "'";
1015: }
1016: if ($showsubs === true)
1017: $showsubs = 9999999999;
1018:
1019: $sortorder = getCurrentMenuItem($menuset);
1020: $items = getMenuItems($menuset, getMenuVisibility());
1021:
1022: if (count($items) == 0)
1023: return;
1024: $currentitem_parentid = @$items[$sortorder]['parentid'];
1025: if ($startlist = !($option == 'omit-top' || $option == 'list-sub')) {
1026: echo "<ul$css_id>";
1027: }
1028: $pageid = @$items[$sortorder]['id'];
1029: $baseindent = max(1, count(explode("-", $sortorder)));
1030: $indent = 1;
1031: $open = array($indent => 0);
1032: $parents = array(NULL);
1033: $order = explode('-', $sortorder);
1034: $mylevel = count($order);
1035: $myparentsort = array_shift($order);
1036:
1037: for ($c = 0; $c <= $mylevel; $c++) {
1038: $parents[$c] = NULL;
1039: }
1040: foreach ($items as $item) {
1041: $itemarray = getItemTitleAndURL($item);
1042: $itemURL = $itemarray['url'];
1043: $itemtitle = $itemarray['title'];
1044: $level = max(1, count(explode('-', $item['sort_order'])));
1045: $process = (($level <= $showsubs && $option == "list")
1046: || ($option == 'list' || $option == 'list-top') && $level == 1
1047: || (($option == 'list' || ($option == 'omit-top' && $level > 1)) && (($item['id'] == $pageid)
1048: || ($item['parentid'] == $pageid)
1049: || ($level < $mylevel && $level > 1 && strpos($item['sort_order'], $myparentsort) === 0))
1050: || (($level == $mylevel) && ($currentitem_parentid == $item['parentid']))
1051: ) || ($option == 'list-sub' && ($item['parentid'] == $pageid)
1052: )
1053: );
1054: if ($process) {
1055: if ($level > $indent) {
1056: echo "\n" . str_pad("\t", $indent, "\t") . "<ul class=\"$css_class menu_{$item['type']}\">\n";
1057: $indent++;
1058: $parents[$indent] = NULL;
1059: $open[$indent] = 0;
1060: } else if ($level < $indent) {
1061: $parents[$indent] = NULL;
1062: while ($indent > $level) {
1063: if ($open[$indent]) {
1064: $open[$indent] --;
1065: echo "</li>\n";
1066: }
1067: $indent--;
1068: echo str_pad("\t", $indent, "\t") . "</ul>\n";
1069: }
1070: } else {
1071: if ($open[$indent]) {
1072: echo str_pad("\t", $indent, "\t") . "</li>\n";
1073: $open[$indent] --;
1074: } else {
1075: echo "\n";
1076: }
1077: }
1078:
1079: if ($open[$indent]) {
1080: echo "</li>\n";
1081: $open[$indent] --;
1082: }
1083:
1084: echo str_pad("\t", $indent - 1, "\t");
1085: $open[$indent] += $item['include_li'];
1086: $parents[$indent] = $item['id'];
1087: if ($counter) {
1088: switch ($item['type']) {
1089: case'album':
1090: $albumobj = newAlbum($item['link']);
1091: $numimages = $albumobj->getNumImages();
1092: $numsubalbums = $albumobj->getNumAlbums();
1093: $itemcounter = ' <span style="white-space:nowrap;"><small>(';
1094: if ($numsubalbums != 0) {
1095: $itemcounter .= sprintf(ngettext('%u album', '%u albums', $numsubalbums), $numsubalbums);
1096: }
1097: if ($numimages != 0) {
1098: if ($numsubalbums != 0) {
1099: $itemcounter .= ' ';
1100: }
1101: $itemcounter .= sprintf(ngettext('%u image', '%u images', $numimages), $numimages);
1102: }
1103: $itemcounter .= ')</small></span>';
1104:
1105: break;
1106: case'zenpagecategory':
1107: if ((zp_loggedin(ZENPAGE_NEWS_RIGHTS | ALL_NEWS_RIGHTS))) {
1108: $published = "all";
1109: } else {
1110: $published = "published";
1111: }
1112: $catobj = new ZenpageCategory($item['link']);
1113: $catcount = count($catobj->getArticles(0, $published));
1114: $itemcounter = "<small> (" . $catcount . ")</small>";
1115: break;
1116: }
1117: }
1118: if ($item['id'] == $pageid && !is_null($pageid)) {
1119: if ($level == 1) {
1120: $class = $css_class_topactive;
1121: } else {
1122: $class = $css_class_active;
1123: }
1124: echo '<li class="menu_' . trim($item['type'] . ' ' . $class) . '">' . $itemtitle . $itemcounter;
1125: } else {
1126: if (strpos($sortorder, $item['sort_order']) === 0) {
1127: $class = ' ' . $css_class_active . '-' . ($mylevel - $level);
1128: } else {
1129: $class = '';
1130: }
1131: if ($item['include_li']) {
1132: echo '<li class="menu_' . $item['type'] . $class . '">';
1133: }
1134: if ($item['span_id'] || $item['span_class']) {
1135: echo '<span';
1136: if ($item['span_id'])
1137: echo ' id="' . $item['span_id'] . '"';
1138: if ($item['span_class'])
1139: echo ' class="' . $item['span_class'] . '"';
1140: echo '>';
1141: }
1142: switch ($item['type']) {
1143: case 'html':
1144: echo $item['link'];
1145: break;
1146: case 'menufunction':
1147: $i = strpos($itemURL, '(');
1148: if ($i) {
1149: if (function_exists(trim(substr($itemURL, 0, $i)))) {
1150: eval($itemURL);
1151: }
1152: }
1153: break;
1154: case 'menulabel':
1155: echo $itemtitle;
1156: break;
1157: default:
1158: if (empty($itemURL)) {
1159: $itemURL = FULLWEBPATH;
1160: }
1161: echo '<a href="' . $itemURL . '" title="' . getBare($itemtitle) . '">' . $itemtitle . '</a>' . $itemcounter;
1162: break;
1163: }
1164: if ($item['span_id'] || $item['span_class']) {
1165: echo '</span>';
1166: }
1167: }
1168: }
1169: }
1170:
1171: while ($indent > 1) {
1172: if ($open[$indent]) {
1173: echo "</li>\n";
1174: $open[$indent] --;
1175: }
1176: $indent--;
1177: echo str_pad("\t", $indent, "\t") . "</ul>";
1178: }
1179: if ($open[$indent]) {
1180: echo "</li>\n";
1181: $open[$indent] --;
1182: } else {
1183: echo "\n";
1184: }
1185: if ($startlist) {
1186: echo "</ul>\n";
1187: }
1188: }
1189:
1190: ?>
1191: