1 | <?php /* |
---|
2 | Plugin Name: RV Menu Tree |
---|
3 | Version: 2.7.a |
---|
4 | Plugin URI: http://piwigo.org/ext/extension_view.php?eid=238 |
---|
5 | Description: Replaces the categories in the menu bar with a nicer one (javascript). |
---|
6 | Author: rvelices |
---|
7 | Author URI: http://www.modusoptimus.com |
---|
8 | */ |
---|
9 | |
---|
10 | |
---|
11 | add_event_handler('loc_begin_page_header', 'rv_mt_begin_page_header'); |
---|
12 | function rv_mt_begin_page_header() |
---|
13 | { |
---|
14 | global $template; |
---|
15 | $template->func_combine_css( array('path'=>'plugins/rv_menutree/menutree.css') ); |
---|
16 | } |
---|
17 | |
---|
18 | add_event_handler('get_categories_menu_sql_where', 'rv_mt_get_categories_menu_sql_where', EVENT_HANDLER_PRIORITY_NEUTRAL, 2 ); |
---|
19 | |
---|
20 | function rv_mt_get_categories_menu_sql_where($where, $expand) |
---|
21 | { |
---|
22 | if (mobile_theme()) |
---|
23 | return $where; |
---|
24 | add_event_handler('blockmanager_apply', 'rv_mt_menubar_categories'); |
---|
25 | |
---|
26 | if ($expand) |
---|
27 | return $where; |
---|
28 | |
---|
29 | global $page; |
---|
30 | if ( !isset($page['category']) ) |
---|
31 | $where = 'id_uppercat IS NULL OR uppercats REGEXP \'^[0-9]+,[0-9]+$\''; |
---|
32 | else |
---|
33 | { |
---|
34 | $where = 'id_uppercat is NULL |
---|
35 | OR uppercats LIKE "'.$page['category']['upper_names'][0]['id'].',%" |
---|
36 | OR uppercats REGEXP \'^[0-9]+,[0-9]+$\''; |
---|
37 | } |
---|
38 | return $where; |
---|
39 | } |
---|
40 | |
---|
41 | function rv_mt_menubar_categories($menu_ref_arr) |
---|
42 | { |
---|
43 | $menu = & $menu_ref_arr[0]; |
---|
44 | |
---|
45 | if (($block = $menu->get_block('mbCategories')) != null) |
---|
46 | { |
---|
47 | global $template, $page; |
---|
48 | |
---|
49 | $upper_ids = isset($page['category']['uppercats']) ? array_flip( explode(',', $page['category']['uppercats'])) : null; |
---|
50 | $refLevel = 0; |
---|
51 | foreach($block->data['MENU_CATEGORIES'] as &$cat) |
---|
52 | { |
---|
53 | $level = $cat['LEVEL']; |
---|
54 | if ($level>$refLevel) |
---|
55 | $pre = '<ul'.($refLevel==0?' class=rvTree id=theCategoryMenu':'').'>'; |
---|
56 | else |
---|
57 | $pre = '</li>'.str_repeat('</ul></li>', $refLevel-$level); |
---|
58 | |
---|
59 | $class= $cat['SELECTED'] ? 'selected ' : ''; |
---|
60 | if ($cat['count_categories'] > 0) |
---|
61 | $class .= isset($upper_ids[$cat['id']]) ? 'liOpen':'liClosed'; |
---|
62 | if (!empty($class)) |
---|
63 | $class=' class="'.$class.'"'; |
---|
64 | $cat['PRE'] = $pre; |
---|
65 | $cat['CLASS'] = $class; |
---|
66 | $refLevel = $level; |
---|
67 | } |
---|
68 | unset($cat); |
---|
69 | $rvmt_base_name = basename(dirname(__FILE__)); |
---|
70 | $template->assign(array( |
---|
71 | 'RVMT_BASE_NAME' => $rvmt_base_name, |
---|
72 | 'RVMT_POST' => str_repeat('</li></ul>', $refLevel), |
---|
73 | ) |
---|
74 | ); |
---|
75 | $block->template = realpath(PHPWG_ROOT_PATH.'plugins/'.$rvmt_base_name.'/template/rv_menutree_categories.tpl'); |
---|
76 | } |
---|
77 | } |
---|
78 | ?> |
---|