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