1 | <?php /* |
---|
2 | Plugin Name: RV Menu Tree |
---|
3 | Version: 2.1.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 | if (!function_exists('rv_ua_is_handheld')) |
---|
11 | { |
---|
12 | function rv_ua_is_handheld() |
---|
13 | { |
---|
14 | if ( isset($_SESSION['is_handheld']) ) |
---|
15 | return $_SESSION['is_handheld']; |
---|
16 | $ret=false; |
---|
17 | if ( strpos($_SERVER['HTTP_USER_AGENT'], 'BlackBerry')!==false ) |
---|
18 | $ret=true; |
---|
19 | if ( session_id()!="" ) |
---|
20 | $_SESSION['is_handheld']=$ret; |
---|
21 | return $ret; |
---|
22 | } |
---|
23 | } |
---|
24 | |
---|
25 | add_event_handler('get_categories_menu_sql_where', 'rv_mt_get_categories_menu_sql_where', EVENT_HANDLER_PRIORITY_NEUTRAL, 3 ); |
---|
26 | |
---|
27 | function rv_mt_get_categories_menu_sql_where($where, $expand, $filter) |
---|
28 | { |
---|
29 | if (rv_ua_is_handheld()) return $where; |
---|
30 | |
---|
31 | $dirname = dirname(__FILE__); |
---|
32 | |
---|
33 | global $template, $page; |
---|
34 | $template->set_extent('rvtree_menubar_categories.tpl', 'mbCategories', $dirname.'//'); |
---|
35 | |
---|
36 | $template->assign('RVMT', array( |
---|
37 | 'PATH' => get_root_url().'plugins/'. basename($dirname).'/', |
---|
38 | 'CSS' => str_replace( 'url(', 'url('.get_root_url().'plugins/'.basename($dirname).'/',file_get_contents($dirname.'/rvtree-min.css')), |
---|
39 | 'ALL_OPEN' => $filter, |
---|
40 | 'UPPER_IDS' => isset($page['category']) ? array_flip( explode(',', $page['category']['uppercats'])) : null, |
---|
41 | ) |
---|
42 | ); |
---|
43 | |
---|
44 | if ($expand) |
---|
45 | return $where; |
---|
46 | if ($filter) |
---|
47 | { |
---|
48 | global $rv_mt_all_open; |
---|
49 | $rv_mt_all_open = true; |
---|
50 | return $where; |
---|
51 | } |
---|
52 | |
---|
53 | global $page; |
---|
54 | if ( !isset($page['category']) ) |
---|
55 | $where = 'id_uppercat IS NULL OR uppercats REGEXP \'^[0-9]+,[0-9]+$\''; |
---|
56 | else |
---|
57 | { |
---|
58 | $where = 'id_uppercat is NULL |
---|
59 | OR uppercats LIKE "'.$page['category']['upper_names'][0]['id'].',%" |
---|
60 | OR uppercats REGEXP \'^[0-9]+,[0-9]+$\''; |
---|
61 | } |
---|
62 | return $where; |
---|
63 | } |
---|
64 | |
---|
65 | |
---|
66 | function rv_mt_get_html_menu_category($menu, $categories, $selected_category) |
---|
67 | { |
---|
68 | $start = get_moment(); |
---|
69 | |
---|
70 | $ref_level = 0; |
---|
71 | $level = 0; |
---|
72 | $menu = ''; |
---|
73 | |
---|
74 | $upper_ids=array(); |
---|
75 | if ( null!=$selected_category) |
---|
76 | $upper_ids = array_flip( explode(',', $selected_category['uppercats']) ); |
---|
77 | |
---|
78 | $url_perma = make_index_url( array( 'category' => array('id'=>0, 'name'=>'', 'permalink'=> '@permalink@') ) ); |
---|
79 | $url_no_perma = make_index_url( array( 'category' => array('id'=>999999, 'name'=>'xxxnamexxx', 'permalink'=> '') ) ); |
---|
80 | |
---|
81 | foreach ($categories as $category) |
---|
82 | { |
---|
83 | $level = substr_count($category['global_rank'], '.') + 1; |
---|
84 | if ($level > $ref_level) |
---|
85 | { |
---|
86 | if ($ref_level==0) |
---|
87 | $menu.= "\n<ul class=\"rvTree\" id=\"theCategoryMenu\">"; |
---|
88 | else |
---|
89 | $menu.= "\n<ul>"; |
---|
90 | } |
---|
91 | elseif ($level == $ref_level) |
---|
92 | $menu.= "</li>"; |
---|
93 | elseif ($level < $ref_level) |
---|
94 | { |
---|
95 | // we may have to close more than one level at the same time... |
---|
96 | $menu.= "</li>"; |
---|
97 | $menu.= str_repeat("\n</ul></li>",($ref_level-$level)); |
---|
98 | } |
---|
99 | $ref_level = $level; |
---|
100 | |
---|
101 | $menu.= "\n<li"; |
---|
102 | $class_names = array(); |
---|
103 | if ($category['id'] == @$selected_category['id']) |
---|
104 | array_push( $class_names, 'selected'); |
---|
105 | global $rv_mt_all_open; |
---|
106 | |
---|
107 | if ($category['count_categories']>0) |
---|
108 | { |
---|
109 | if ( isset($rv_mt_all_open) and $rv_mt_all_open ) |
---|
110 | array_push( $class_names, 'liOpen'); |
---|
111 | elseif ( isset( $upper_ids[ $category['id'] ] ) ) |
---|
112 | { |
---|
113 | array_push( $class_names, 'liOpen'); |
---|
114 | unset($upper_ids[ $category['id'] ] ); |
---|
115 | } |
---|
116 | else |
---|
117 | array_push( $class_names, 'liClosed'); |
---|
118 | } |
---|
119 | |
---|
120 | if (count($class_names)) |
---|
121 | $menu.= ' class="'.implode($class_names,' ').'"'; |
---|
122 | $menu.= '>'; |
---|
123 | |
---|
124 | if ( empty($category['permalink']) ) |
---|
125 | $url = str_replace( array('999999', 'xxxnamexxx'), array($category['id'], str2url($category['name'])), $url_no_perma); |
---|
126 | else |
---|
127 | $url = str_replace('@permalink@', $category['permalink'], $url_perma); |
---|
128 | |
---|
129 | $title = get_display_images_count( |
---|
130 | $category['nb_images'], $category['count_images'], $category['count_categories'], |
---|
131 | false, |
---|
132 | ' / ' |
---|
133 | ); |
---|
134 | |
---|
135 | $menu.= '<a href="'.$url.'"'; |
---|
136 | if ($selected_category!=null and $category['id'] == $selected_category['id_uppercat']) |
---|
137 | $menu.= ' rel="up"'; |
---|
138 | $menu.= ' title="'.$title.'">' |
---|
139 | .trigger_event('render_category_name', $category['name'], 'get_html_menu_category') |
---|
140 | //.$category['name'] |
---|
141 | .'</a>'; |
---|
142 | |
---|
143 | if ( $category['count_images']>0 ) |
---|
144 | {// at least one direct or indirect image |
---|
145 | $menu.= '<span class="menuInfoCat' |
---|
146 | .($category['nb_images'] == 0 ? 'ByChild' : '') |
---|
147 | .'" title="'.$title.'"> ['.$category['count_images'].']</span>'; |
---|
148 | } |
---|
149 | $menu.= get_icon($category['max_date_last'], @$category['max_date_last']> @$category['date_last']); |
---|
150 | } |
---|
151 | |
---|
152 | $menu.= str_repeat("\n</li></ul>",($level)); |
---|
153 | $menu.= '<script type="text/javascript">RVTree.convertTree( document.getElementById("theCategoryMenu") );</script>'; |
---|
154 | |
---|
155 | $dirname = dirname(__FILE__); |
---|
156 | $head = '<style type="text/css">'. str_replace( 'url(', 'url('.get_root_url().'plugins/'.basename($dirname).'/',file_get_contents($dirname.'/rvtree-min.css')).'</style> |
---|
157 | <script type="text/javascript" src="'.get_root_url().'plugins/'. basename(dirname(__FILE__)).'/rvtree-min.js"></script>'; |
---|
158 | |
---|
159 | pwg_debug('rv_mt_get_html_menu_category took '.number_format(get_moment() - $start,3,'.',' ') ); |
---|
160 | global $template; |
---|
161 | $template->append( 'head_elements', $head); |
---|
162 | return $menu; |
---|
163 | } |
---|
164 | ?> |
---|