1 | <?php |
---|
2 | /* ----------------------------------------------------------------------------- |
---|
3 | Plugin : Advanced Menu Manager |
---|
4 | Author : Grum |
---|
5 | email : grum@grum.fr |
---|
6 | website : http://photos.grum.fr |
---|
7 | PWG user : http://forum.piwigo.org/profile.php?id=3706 |
---|
8 | |
---|
9 | << May the Little SpaceFrog be with you ! >> |
---|
10 | ------------------------------------------------------------------------------ |
---|
11 | See main.inc.php for release information |
---|
12 | |
---|
13 | AMM_root : root class for plugin |
---|
14 | |
---|
15 | --------------------------------------------------------------------------- */ |
---|
16 | |
---|
17 | if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); } |
---|
18 | |
---|
19 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/common_plugin.class.inc.php'); |
---|
20 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/users_groups.class.inc.php'); |
---|
21 | include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/css.class.inc.php'); |
---|
22 | |
---|
23 | |
---|
24 | class AMM_root extends common_plugin |
---|
25 | { |
---|
26 | protected $css; //the css object |
---|
27 | protected $defaultMenus = array( |
---|
28 | 'favorites' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 0, 'translation' => 'favorite_cat'), |
---|
29 | 'most_visited' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 1, 'translation' => 'most_visited_cat'), |
---|
30 | 'best_rated' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 2, 'translation' => 'best_rated_cat'), |
---|
31 | 'random' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 3, 'translation' => 'random_cat'), |
---|
32 | 'recent_pics' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 4, 'translation' => 'recent_pics_cat'), |
---|
33 | 'recent_cats' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 5, 'translation' => 'recent_cats_cat'), |
---|
34 | 'calendar' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 6, 'translation' => 'calendar'), |
---|
35 | 'qsearch' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 0, 'translation' => 'qsearch'), |
---|
36 | 'tags' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 1, 'translation' => 'Tags'), |
---|
37 | 'search' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 2, 'translation' => 'Search'), |
---|
38 | 'comments' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 3, 'translation' => 'comments'), |
---|
39 | 'about' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 4, 'translation' => 'About'), |
---|
40 | 'rss' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 5, 'translation' => 'Notification') |
---|
41 | ); |
---|
42 | |
---|
43 | function AMM_root($prefixeTable, $filelocation) |
---|
44 | { |
---|
45 | $this->plugin_name="Advanced Menu Manager"; |
---|
46 | $this->plugin_name_files="amm"; |
---|
47 | parent::__construct($prefixeTable, $filelocation); |
---|
48 | |
---|
49 | $list=array('urls', 'personalised'); |
---|
50 | $this->set_tables_list($list); |
---|
51 | } |
---|
52 | |
---|
53 | /* --------------------------------------------------------------------------- |
---|
54 | common AIP & PIP functions |
---|
55 | --------------------------------------------------------------------------- */ |
---|
56 | |
---|
57 | /* this function initialize var $my_config with default values */ |
---|
58 | public function init_config() |
---|
59 | { |
---|
60 | $this->my_config=array( |
---|
61 | 'amm_links_show_icons' => 'y', |
---|
62 | 'amm_links_title' => array(), |
---|
63 | 'amm_randompicture_showname' => 'n', //n:no, o:over, u:under |
---|
64 | 'amm_randompicture_showcomment' => 'n', //n:no, o:over, u:under |
---|
65 | 'amm_randompicture_periodicchange' => 0, //0: no periodic change ; periodic change in milliseconds |
---|
66 | 'amm_randompicture_height' => 0, //0: automatic, otherwise it's the fixed height in pixels |
---|
67 | 'amm_randompicture_title' => array(), |
---|
68 | 'amm_sections_items' => $this->defaultMenus |
---|
69 | ); |
---|
70 | |
---|
71 | $languages=get_languages(); |
---|
72 | foreach($languages as $key => $val) |
---|
73 | { |
---|
74 | if($key=='fr_FR') |
---|
75 | { |
---|
76 | $this->my_config['amm_links_title'][$key]=base64_encode('Liens'); |
---|
77 | $this->my_config['amm_randompicture_title'][$key]=base64_encode('Une image au hasard'); |
---|
78 | } |
---|
79 | else |
---|
80 | { |
---|
81 | $this->my_config['amm_links_title'][$key]=base64_encode('Links'); |
---|
82 | $this->my_config['amm_randompicture_title'][$key]=base64_encode('A random picture'); |
---|
83 | } |
---|
84 | } |
---|
85 | } |
---|
86 | |
---|
87 | public function load_config() |
---|
88 | { |
---|
89 | parent::load_config(); |
---|
90 | } |
---|
91 | |
---|
92 | public function init_events() |
---|
93 | { |
---|
94 | add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') ); |
---|
95 | } |
---|
96 | |
---|
97 | public function register_blocks( $menu_ref_arr ) |
---|
98 | { |
---|
99 | $menu = & $menu_ref_arr[0]; |
---|
100 | if ($menu->get_id() != 'menubar') |
---|
101 | return; |
---|
102 | $menu->register_block( new RegisteredBlock( 'mbAMM_randompict', 'Random pictures', 'AMM')); |
---|
103 | $menu->register_block( new RegisteredBlock( 'mbAMM_links', 'Links', 'AMM')); |
---|
104 | |
---|
105 | $sections=$this->get_sections(true); |
---|
106 | if(count($sections)) |
---|
107 | { |
---|
108 | $id_done=array(); |
---|
109 | foreach($sections as $key => $val) |
---|
110 | { |
---|
111 | if(!isset($id_done[$val['id']])) |
---|
112 | { |
---|
113 | $menu->register_block( new RegisteredBlock( 'mbAMM_personalised'.$val['id'], $val['title'], 'AMM')); |
---|
114 | $id_done[$val['id']]=""; |
---|
115 | } |
---|
116 | } |
---|
117 | } |
---|
118 | } |
---|
119 | |
---|
120 | // return an array of urls (each url is an array) |
---|
121 | protected function get_urls($only_visible=false) |
---|
122 | { |
---|
123 | $returned=array(); |
---|
124 | $sql="SELECT * FROM ".$this->tables['urls']; |
---|
125 | if($only_visible) |
---|
126 | { |
---|
127 | $sql.=" WHERE visible = 'y' "; |
---|
128 | } |
---|
129 | $sql.=" ORDER BY position"; |
---|
130 | $result=pwg_query($sql); |
---|
131 | if($result) |
---|
132 | { |
---|
133 | while($row=mysql_fetch_array($result)) |
---|
134 | { |
---|
135 | $row['label']=stripslashes($row['label']); |
---|
136 | $returned[]=$row; |
---|
137 | } |
---|
138 | } |
---|
139 | return($returned); |
---|
140 | } |
---|
141 | |
---|
142 | //return number of url |
---|
143 | protected function get_count_url($only_visible=false) |
---|
144 | { |
---|
145 | $returned=0; |
---|
146 | $sql="SELECT count(id) FROM ".$this->tables['urls']; |
---|
147 | if($only_visible) |
---|
148 | { |
---|
149 | $sql.=" WHERE visible = 'y' "; |
---|
150 | } |
---|
151 | $result=pwg_query($sql); |
---|
152 | if($result) |
---|
153 | { |
---|
154 | $tmp=mysql_fetch_row($result); |
---|
155 | $returned=$tmp[0]; |
---|
156 | } |
---|
157 | return($returned); |
---|
158 | } |
---|
159 | |
---|
160 | // return an array of sections (each section is an array) |
---|
161 | protected function get_sections($only_visible=false, $lang="", $only_with_content=true) |
---|
162 | { |
---|
163 | global $user; |
---|
164 | |
---|
165 | if($lang=="") |
---|
166 | { |
---|
167 | $lang=$user['language']; |
---|
168 | } |
---|
169 | |
---|
170 | $returned=array(); |
---|
171 | $sql="SELECT * FROM ".$this->tables['personalised']." |
---|
172 | WHERE (lang = '*' OR lang = '".$lang."') "; |
---|
173 | if($only_visible) |
---|
174 | { |
---|
175 | $sql.=" AND visible = 'y' "; |
---|
176 | } |
---|
177 | if($only_with_content) |
---|
178 | { |
---|
179 | $sql.=" AND content != '' "; |
---|
180 | } |
---|
181 | $sql.=" ORDER BY id, lang DESC "; |
---|
182 | $result=pwg_query($sql); |
---|
183 | if($result) |
---|
184 | { |
---|
185 | while($row=mysql_fetch_array($result)) |
---|
186 | { |
---|
187 | $returned[]=$row; |
---|
188 | } |
---|
189 | } |
---|
190 | return($returned); |
---|
191 | } |
---|
192 | |
---|
193 | |
---|
194 | protected function sortSectionsItemsCompare($a, $b) |
---|
195 | { |
---|
196 | if($a['container']==$b['container']) |
---|
197 | { |
---|
198 | if($a['order']==$b['order']) return(0); |
---|
199 | return(($a['order']<$b['order'])?-1:1); |
---|
200 | } |
---|
201 | else return(($a['container']<$b['container'])?-1:1); |
---|
202 | } |
---|
203 | |
---|
204 | protected function sortSectionsItems() |
---|
205 | { |
---|
206 | uasort($this->my_config['amm_sections_items'], array($this, "sortSectionsItemsCompare")); |
---|
207 | } |
---|
208 | |
---|
209 | } // amm_root class |
---|
210 | |
---|
211 | |
---|
212 | |
---|
213 | ?> |
---|