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_ROOT_PATH.'include/block.class.php'); |
---|
20 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php'); |
---|
21 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCUsersGroups.class.inc.php'); |
---|
22 | |
---|
23 | |
---|
24 | class AMM_root extends CommonPlugin |
---|
25 | { |
---|
26 | protected $defaultMenus = array( |
---|
27 | /* about visibility & accessibility system : |
---|
28 | * - by default, everything is visible (users & groups) |
---|
29 | * - items not visibles are listed (in release < 3.3.4, this rule wa applied to groups only) |
---|
30 | * |
---|
31 | * on the user interface, checked items are visibles => not checked items are stored |
---|
32 | */ |
---|
33 | 'favorites' => array('container' => 'special', 'visibility' => '/', 'order' => 0, 'translation' => 'My favorites'), |
---|
34 | 'most_visited' => array('container' => 'special', 'visibility' => '/', 'order' => 1, 'translation' => 'Most visited'), |
---|
35 | 'best_rated' => array('container' => 'special', 'visibility' => '/', 'order' => 2, 'translation' => 'Best rated'), |
---|
36 | 'random' => array('container' => 'special', 'visibility' => '/', 'order' => 3, 'translation' => 'Random pictures'), |
---|
37 | 'recent_pics' => array('container' => 'special', 'visibility' => '/', 'order' => 4, 'translation' => 'Recent pictures'), |
---|
38 | 'recent_cats' => array('container' => 'special', 'visibility' => '/', 'order' => 5, 'translation' => 'Recent categories'), |
---|
39 | 'calendar' => array('container' => 'special', 'visibility' => '/', 'order' => 6, 'translation' => 'Calendar'), |
---|
40 | 'qsearch' => array('container' => 'menu', 'visibility' => '/', 'order' => 0, 'translation' => 'Quick search'), |
---|
41 | 'tags' => array('container' => 'menu', 'visibility' => '/', 'order' => 1, 'translation' => 'Tags'), |
---|
42 | 'search' => array('container' => 'menu', 'visibility' => '/', 'order' => 2, 'translation' => 'Search'), |
---|
43 | 'comments' => array('container' => 'menu', 'visibility' => '/', 'order' => 3, 'translation' => 'Comments'), |
---|
44 | 'about' => array('container' => 'menu', 'visibility' => '/', 'order' => 4, 'translation' => 'About'), |
---|
45 | 'rss' => array('container' => 'menu', 'visibility' => '/', 'order' => 5, 'translation' => 'Notification') |
---|
46 | ); |
---|
47 | protected $urlsModes=array(0 => 'new_window', 1 => 'current_window'); |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | public function __construct($prefixeTable, $filelocation) |
---|
52 | { |
---|
53 | $this->setPluginName("Advanced Menu Manager"); |
---|
54 | $this->setPluginNameFiles("amm"); |
---|
55 | parent::__construct($prefixeTable, $filelocation); |
---|
56 | |
---|
57 | $list=array('urls', 'personalised', 'personalised_langs', 'blocks'); |
---|
58 | $this->setTablesList($list); |
---|
59 | } |
---|
60 | |
---|
61 | public function __destruct() |
---|
62 | { |
---|
63 | unset($this->defaultMenus); |
---|
64 | parent::__destruct(); |
---|
65 | } |
---|
66 | |
---|
67 | /* |
---|
68 | * --------------------------------------------------------------------------- |
---|
69 | * common AIP & PIP functions |
---|
70 | * --------------------------------------------------------------------------- |
---|
71 | */ |
---|
72 | |
---|
73 | /** |
---|
74 | * this function initialize config var with default values |
---|
75 | */ |
---|
76 | public function initConfig() |
---|
77 | { |
---|
78 | $this->config=array( |
---|
79 | 'amm_links_show_icons' => 'y', |
---|
80 | 'amm_links_title' => array(), |
---|
81 | 'amm_randompicture_preload' => 25, //number preloaded random pictures |
---|
82 | 'amm_randompicture_showname' => 'n', //n:no, o:over, u:under |
---|
83 | 'amm_randompicture_showcomment' => 'n', //n:no, o:over, u:under |
---|
84 | 'amm_randompicture_periodicchange' => 0, //0: no periodic change ; periodic change in milliseconds |
---|
85 | 'amm_randompicture_height' => 0, //0: automatic, otherwise it's the fixed height in pixels |
---|
86 | 'amm_randompicture_title' => array(), |
---|
87 | 'amm_randompicture_selectMode' => 'a', // a:all, f:webmaster's favorites, c:categories |
---|
88 | 'amm_randompicture_selectCat' => array(), // categories id list |
---|
89 | 'amm_blocks_items' => $this->defaultMenus, |
---|
90 | 'amm_albums_to_menu' => array(), |
---|
91 | 'amm_old_blk_menubar' => '', // keep a copy of piwigo's menubar config |
---|
92 | 'newInstall' => 'n' |
---|
93 | ); |
---|
94 | |
---|
95 | $languages=get_languages(); |
---|
96 | foreach($languages as $key => $val) |
---|
97 | { |
---|
98 | if($key=='fr_FR') |
---|
99 | { |
---|
100 | $this->config['amm_links_title'][$key]=base64_encode('Liens'); |
---|
101 | $this->config['amm_randompicture_title'][$key]=base64_encode('Une image au hasard'); |
---|
102 | } |
---|
103 | else |
---|
104 | { |
---|
105 | $this->config['amm_links_title'][$key]=base64_encode('Links'); |
---|
106 | $this->config['amm_randompicture_title'][$key]=base64_encode('A random picture'); |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | public function registerBlocks( $menu_ref_arr ) |
---|
112 | { |
---|
113 | $menu = & $menu_ref_arr[0]; |
---|
114 | if ($menu->get_id() != 'menubar') return; |
---|
115 | |
---|
116 | $menu->register_block( new RegisteredBlock( 'mbAMM_randompict', 'Random pictures', 'AMM')); |
---|
117 | $menu->register_block( new RegisteredBlock( 'mbAMM_links', 'Links', 'AMM')); |
---|
118 | |
---|
119 | $blocks=$this->getPersonalisedBlocks(); |
---|
120 | if(count($blocks)) |
---|
121 | { |
---|
122 | $idDone=array(); |
---|
123 | foreach($blocks as $key => $val) |
---|
124 | { |
---|
125 | if(!isset($idDone[$val['id']])) |
---|
126 | { |
---|
127 | $menu->register_block( new RegisteredBlock( 'mbAMM_personalised'.$val['id'], $val['title'], 'AMM')); |
---|
128 | $idDone[$val['id']]=""; |
---|
129 | } |
---|
130 | } |
---|
131 | } |
---|
132 | |
---|
133 | $this->loadConfig(); |
---|
134 | |
---|
135 | if(count($this->config['amm_albums_to_menu'])>0) |
---|
136 | { |
---|
137 | $sql="SELECT id, name |
---|
138 | FROM ".CATEGORIES_TABLE." |
---|
139 | WHERE id IN(".implode(',', $this->config['amm_albums_to_menu']).");"; |
---|
140 | |
---|
141 | $result=pwg_query($sql); |
---|
142 | if($result) |
---|
143 | { |
---|
144 | while($row=pwg_db_fetch_assoc($result)) |
---|
145 | { |
---|
146 | $row['name']=trigger_event('render_category_name', $row['name'], 'amm_album_to_menu'); |
---|
147 | |
---|
148 | $menu->register_block( new RegisteredBlock( 'mbAMM_album'.$row['id'], $row['name'].' ('.l10n('g002_album2menu').') ', 'AMM')); |
---|
149 | } |
---|
150 | } |
---|
151 | } |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | /* |
---|
156 | * --------------------------------------------------------------------------- |
---|
157 | * |
---|
158 | * Links functions |
---|
159 | * |
---|
160 | * --------------------------------------------------------------------------- |
---|
161 | */ |
---|
162 | |
---|
163 | /** |
---|
164 | * return an array of links (each url is an array) |
---|
165 | * |
---|
166 | * @param Bool onlyVisible : if true, only visible links are returned |
---|
167 | * @return Array |
---|
168 | */ |
---|
169 | protected function getLinks($onlyVisible=false) |
---|
170 | { |
---|
171 | $returned=array(); |
---|
172 | $sql="SELECT id, label, url, mode, icon, position, visible, accessUsers, accessGroups |
---|
173 | FROM ".$this->tables['urls']; |
---|
174 | if($onlyVisible) |
---|
175 | { |
---|
176 | $sql.=" WHERE visible = 'y' "; |
---|
177 | } |
---|
178 | $sql.=" ORDER BY position ASC, id ASC"; |
---|
179 | $result=pwg_query($sql); |
---|
180 | if($result) |
---|
181 | { |
---|
182 | while($row=pwg_db_fetch_assoc($result)) |
---|
183 | { |
---|
184 | $returned[]=$row; |
---|
185 | } |
---|
186 | } |
---|
187 | return($returned); |
---|
188 | } |
---|
189 | |
---|
190 | /** |
---|
191 | * return values for a given link |
---|
192 | * |
---|
193 | * @param String $id : link id |
---|
194 | * @return Array |
---|
195 | */ |
---|
196 | protected function getLink($id) |
---|
197 | { |
---|
198 | $returned=array(); |
---|
199 | $sql="SELECT id, label, url, mode, icon, position, visible, accessUsers, accessGroups |
---|
200 | FROM ".$this->tables['urls']." |
---|
201 | WHERE id = '$id';"; |
---|
202 | $result=pwg_query($sql); |
---|
203 | if($result) |
---|
204 | { |
---|
205 | while($row=pwg_db_fetch_assoc($result)) |
---|
206 | { |
---|
207 | $returned=$row; |
---|
208 | } |
---|
209 | } |
---|
210 | return($returned); |
---|
211 | } |
---|
212 | |
---|
213 | /** |
---|
214 | * set values for a link |
---|
215 | * if link id is empty : create a new link |
---|
216 | * if not, update link |
---|
217 | * |
---|
218 | * @param String $id : link id |
---|
219 | * @return Integer : -1 if fails |
---|
220 | * otherwise link id |
---|
221 | */ |
---|
222 | protected function setLink($id, $label, $url, $mode, $icon, $visible, $accessUsers, $accessGroups) |
---|
223 | { |
---|
224 | if($id=='') |
---|
225 | { |
---|
226 | $sql="INSERT INTO ".$this->tables['urls']." VALUES |
---|
227 | ('', |
---|
228 | '".$label."', |
---|
229 | '".$url."', |
---|
230 | '$mode', |
---|
231 | '$icon', |
---|
232 | 0, |
---|
233 | '$visible', |
---|
234 | '$accessUsers', |
---|
235 | '$accessGroups' |
---|
236 | );"; |
---|
237 | } |
---|
238 | else |
---|
239 | { |
---|
240 | $sql="UPDATE ".$this->tables['urls']." |
---|
241 | SET label='".$label."', |
---|
242 | url='".$url."', |
---|
243 | mode='$mode', |
---|
244 | icon='$icon', |
---|
245 | visible='$visible', |
---|
246 | accessUsers='".$accessUsers."', |
---|
247 | accessGroups='".$accessGroups."' |
---|
248 | WHERE id='$id';"; |
---|
249 | } |
---|
250 | $result=pwg_query($sql); |
---|
251 | if($result) |
---|
252 | { |
---|
253 | if($id=='') |
---|
254 | { |
---|
255 | return(pwg_db_insert_id()); |
---|
256 | } |
---|
257 | else |
---|
258 | { |
---|
259 | return($id); |
---|
260 | } |
---|
261 | } |
---|
262 | return(-1); |
---|
263 | } |
---|
264 | |
---|
265 | /** |
---|
266 | * delete a given link |
---|
267 | * |
---|
268 | * @param String $id : link id |
---|
269 | * @return Bool : true if deleted, otherwise false |
---|
270 | */ |
---|
271 | protected function deleteLink($id) |
---|
272 | { |
---|
273 | $sql="DELETE FROM ".$this->tables['urls']." |
---|
274 | WHERE id = '$id';"; |
---|
275 | $result=pwg_query($sql); |
---|
276 | if($result) return(true); |
---|
277 | return(false); |
---|
278 | } |
---|
279 | |
---|
280 | |
---|
281 | |
---|
282 | /** |
---|
283 | * return number of links |
---|
284 | * |
---|
285 | * @param Bool onlyVisible : if true, only visible links are counted |
---|
286 | * @return Array |
---|
287 | */ |
---|
288 | protected function getLinksCount($onlyVisible=false) |
---|
289 | { |
---|
290 | $returned=0; |
---|
291 | $sql="SELECT count(id) FROM ".$this->tables['urls']; |
---|
292 | if($onlyVisible) |
---|
293 | { |
---|
294 | $sql.=" WHERE visible = 'y' "; |
---|
295 | } |
---|
296 | $result=pwg_query($sql); |
---|
297 | if($result) |
---|
298 | { |
---|
299 | $tmp=pwg_db_fetch_row($result); |
---|
300 | $returned=$tmp[0]; |
---|
301 | } |
---|
302 | return($returned); |
---|
303 | } |
---|
304 | |
---|
305 | /** |
---|
306 | * set order from given links |
---|
307 | * |
---|
308 | * @param Array $links : array |
---|
309 | * each item is an array ('id' => '', 'order' =>'') |
---|
310 | * @return Bool : |
---|
311 | */ |
---|
312 | protected function setLinksOrder($links) |
---|
313 | { |
---|
314 | $returned=true; |
---|
315 | |
---|
316 | foreach($links as $link) |
---|
317 | { |
---|
318 | $sql="UPDATE ".$this->tables['urls']." |
---|
319 | SET position='".$link['order']."' |
---|
320 | WHERE id='".$link['id']."';"; |
---|
321 | $result=pwg_query($sql); |
---|
322 | if(!$result) $returned=false; |
---|
323 | } |
---|
324 | return($returned); |
---|
325 | } |
---|
326 | |
---|
327 | |
---|
328 | /* |
---|
329 | * --------------------------------------------------------------------------- |
---|
330 | * |
---|
331 | * Personalised Blocks functions |
---|
332 | * |
---|
333 | * --------------------------------------------------------------------------- |
---|
334 | */ |
---|
335 | |
---|
336 | |
---|
337 | /** |
---|
338 | * return an array of personalised blocks (each block is an array) |
---|
339 | * |
---|
340 | * @param Bool onlyVisible : if true, only visibles blocks are returned |
---|
341 | * @return Array |
---|
342 | */ |
---|
343 | protected function getPersonalisedBlocks($onlyVisible=false, $lang='', $emptyContent=false) |
---|
344 | { |
---|
345 | global $user; |
---|
346 | |
---|
347 | if($lang=="") $lang=$user['language']; |
---|
348 | |
---|
349 | $returned=array(); |
---|
350 | $sql="SELECT pt.id, pt.visible, pt.nfo, ptl.lang, ptl.title, ptl.content |
---|
351 | FROM ".$this->tables['personalised']." pt |
---|
352 | LEFT JOIN ".$this->tables['personalised_langs']." ptl |
---|
353 | ON pt.id=ptl.id |
---|
354 | WHERE (ptl.lang = '*' OR ptl.lang = '".pwg_db_real_escape_string($lang)."') "; |
---|
355 | |
---|
356 | if($onlyVisible) $sql.=" AND pt.visible = 'y' "; |
---|
357 | if($emptyContent==false) $sql.=" AND ptl.content != '' "; |
---|
358 | |
---|
359 | $sql.=" ORDER BY pt.id, ptl.lang ASC "; |
---|
360 | |
---|
361 | $result=pwg_query($sql); |
---|
362 | if($result) |
---|
363 | { |
---|
364 | while($row=pwg_db_fetch_assoc($result)) |
---|
365 | { |
---|
366 | $returned[]=$row; |
---|
367 | } |
---|
368 | } |
---|
369 | return($returned); |
---|
370 | } |
---|
371 | |
---|
372 | /** |
---|
373 | * return values for a given personalised block |
---|
374 | * |
---|
375 | * @param String $id : link id |
---|
376 | * @return Array |
---|
377 | */ |
---|
378 | protected function getPersonalisedBlock($id) |
---|
379 | { |
---|
380 | $returned=array( |
---|
381 | 'visible' => false, |
---|
382 | 'nfo' => '', |
---|
383 | 'langs' => array() |
---|
384 | ); |
---|
385 | |
---|
386 | $sql="SELECT visible, nfo |
---|
387 | FROM ".$this->tables['personalised']." |
---|
388 | WHERE id='$id';"; |
---|
389 | |
---|
390 | $result=pwg_query($sql); |
---|
391 | if($result) |
---|
392 | { |
---|
393 | while($row=pwg_db_fetch_assoc($result)) |
---|
394 | { |
---|
395 | $returned['visible']=$row['visible']; |
---|
396 | $returned['nfo']=$row['nfo']; |
---|
397 | } |
---|
398 | |
---|
399 | $sql="SELECT lang, title, content |
---|
400 | FROM ".$this->tables['personalised_langs']." |
---|
401 | WHERE id='$id' |
---|
402 | ORDER BY lang ASC;"; |
---|
403 | |
---|
404 | $result=pwg_query($sql); |
---|
405 | if($result) |
---|
406 | { |
---|
407 | while($row=pwg_db_fetch_assoc($result)) |
---|
408 | { |
---|
409 | $returned['langs'][$row['lang']]=$row; |
---|
410 | } |
---|
411 | } |
---|
412 | } |
---|
413 | return($returned); |
---|
414 | } |
---|
415 | |
---|
416 | /** |
---|
417 | * set values for a personalised block |
---|
418 | * if block id is empty : create a new block |
---|
419 | * if not, update block |
---|
420 | * |
---|
421 | * @param String $id : block id |
---|
422 | * @return Integer : -1 if fails |
---|
423 | * otherwise block id |
---|
424 | */ |
---|
425 | protected function setPersonalisedBlock($id, $visible, $nfo, $langs) |
---|
426 | { |
---|
427 | $ok=false; |
---|
428 | |
---|
429 | if($id=='') |
---|
430 | { |
---|
431 | $sql="INSERT INTO ".$this->tables['personalised']." VALUES |
---|
432 | ('', |
---|
433 | '$visible', |
---|
434 | '".$nfo."' |
---|
435 | );"; |
---|
436 | $result=pwg_query($sql); |
---|
437 | if($result) $ok=true; |
---|
438 | $id=pwg_db_insert_id(); |
---|
439 | } |
---|
440 | else |
---|
441 | { |
---|
442 | $sql="UPDATE ".$this->tables['personalised']." |
---|
443 | SET visible='$visible', |
---|
444 | nfo='".$nfo."' |
---|
445 | WHERE id='$id';"; |
---|
446 | $result=pwg_query($sql); |
---|
447 | if($result) |
---|
448 | { |
---|
449 | $sql="DELETE FROM ".$this->tables['personalised_langs']." |
---|
450 | WHERE id='$id';"; |
---|
451 | $result=pwg_query($sql); |
---|
452 | |
---|
453 | if($result) $ok=true; |
---|
454 | } |
---|
455 | } |
---|
456 | |
---|
457 | if($ok) |
---|
458 | { |
---|
459 | $values=array(); |
---|
460 | foreach($langs as $key => $lang) |
---|
461 | { |
---|
462 | $values[]="('$id', |
---|
463 | '".$lang['lang']."', |
---|
464 | '".$lang['title']."', |
---|
465 | '".$lang['content']."')"; |
---|
466 | } |
---|
467 | $sql="INSERT INTO ".$this->tables['personalised_langs']." VALUES ".implode(',', $values); |
---|
468 | $result=pwg_query($sql); |
---|
469 | |
---|
470 | if($result) $ok=true; |
---|
471 | } |
---|
472 | |
---|
473 | if($ok) return($id); |
---|
474 | return(-1); |
---|
475 | } |
---|
476 | |
---|
477 | /** |
---|
478 | * delete a given personalised block |
---|
479 | * |
---|
480 | * @param String $id : block id |
---|
481 | * @return Bool : true if deleted, otherwise false |
---|
482 | */ |
---|
483 | protected function deletePersonalisedBlock($id) |
---|
484 | { |
---|
485 | $sql="DELETE FROM ".$this->tables['personalised']." |
---|
486 | WHERE id = '$id';"; |
---|
487 | $result=pwg_query($sql); |
---|
488 | if($result) |
---|
489 | { |
---|
490 | $sql="DELETE FROM ".$this->tables['personalised_langs']." |
---|
491 | WHERE id = '$id';"; |
---|
492 | $result=pwg_query($sql); |
---|
493 | |
---|
494 | if($result) return(true); |
---|
495 | } |
---|
496 | |
---|
497 | return(false); |
---|
498 | } |
---|
499 | |
---|
500 | |
---|
501 | |
---|
502 | /** |
---|
503 | * return an array of all registered blocks |
---|
504 | * each array item is an array : |
---|
505 | * String 'id' => '' |
---|
506 | * Integer 'order' => 0 |
---|
507 | * Array 'users' => array() |
---|
508 | * Array 'groups' => array() |
---|
509 | * String 'name' => '' |
---|
510 | * String 'owner' => '' |
---|
511 | * |
---|
512 | * @param Bool $userFiltered : true if returned blocks are filtered to current |
---|
513 | * user |
---|
514 | * @return Array |
---|
515 | */ |
---|
516 | protected function getRegisteredBlocks($userFiltered=false) |
---|
517 | { |
---|
518 | global $conf, $user; |
---|
519 | |
---|
520 | $returned=array(); |
---|
521 | $order=0; |
---|
522 | $users=new GPCUsers(); |
---|
523 | $groups=new GPCGroups(); |
---|
524 | |
---|
525 | $menu = new BlockManager('menubar'); |
---|
526 | $menu->load_registered_blocks(); |
---|
527 | $registeredBlocks = $menu->get_registered_blocks(); |
---|
528 | |
---|
529 | $nbExistingGroups=0; |
---|
530 | $sql="SELECT COUNT(id) AS nbGroup |
---|
531 | FROM ".GROUPS_TABLE.";"; |
---|
532 | $result=pwg_query($sql); |
---|
533 | if($result) |
---|
534 | { |
---|
535 | while($row=pwg_db_fetch_assoc($result)) |
---|
536 | { |
---|
537 | $nbExistingGroups=$row['nbGroup']; |
---|
538 | } |
---|
539 | } |
---|
540 | |
---|
541 | |
---|
542 | $userGroups=array(); |
---|
543 | $sql="SELECT group_id |
---|
544 | FROM ".USER_GROUP_TABLE." |
---|
545 | WHERE user_id = '".$user['id']."';"; |
---|
546 | $result=pwg_query($sql); |
---|
547 | if($result) |
---|
548 | { |
---|
549 | while($row=pwg_db_fetch_assoc($result)) |
---|
550 | { |
---|
551 | $userGroups[$row['group_id']]=''; |
---|
552 | } |
---|
553 | } |
---|
554 | |
---|
555 | $sql="SELECT id, `order`, users, groups |
---|
556 | FROM ".$this->tables['blocks']." |
---|
557 | ORDER BY `order`;"; |
---|
558 | $result=pwg_query($sql); |
---|
559 | if($result) |
---|
560 | { |
---|
561 | while($row=pwg_db_fetch_assoc($result)) |
---|
562 | { |
---|
563 | $row['users']=(trim($row['users'])=='')?array():explode(',', $row['users']); |
---|
564 | $row['groups']=(trim($row['groups'])=='')?array():explode(',', $row['groups']); |
---|
565 | |
---|
566 | if(isset($registeredBlocks[$row['id']])) |
---|
567 | { |
---|
568 | $ok=true; |
---|
569 | if($userFiltered) |
---|
570 | { |
---|
571 | // filter access enabled |
---|
572 | |
---|
573 | $users->setAlloweds($row['users'], false); |
---|
574 | if($users->isAllowed($user['status'])) |
---|
575 | { |
---|
576 | // user is authorized, check group |
---|
577 | if(count($userGroups)) |
---|
578 | { |
---|
579 | // users is attached to one group or more, check access for each group |
---|
580 | // at least, one group must have right access |
---|
581 | $nbOk=count($userGroups); |
---|
582 | |
---|
583 | $groups->setAlloweds($row['groups'], false); |
---|
584 | foreach($row['groups'] as $val) |
---|
585 | { |
---|
586 | if(isset($userGroups[$val]) and !$groups->isAllowed($val)) $nbOk--; |
---|
587 | } |
---|
588 | |
---|
589 | // no group is authorized to access the menu |
---|
590 | if($nbOk==0) $ok=false; |
---|
591 | } |
---|
592 | elseif($nbExistingGroups>0 and count($row['groups'])>0) |
---|
593 | { |
---|
594 | // if user is not attached to any group and if at least there 1 |
---|
595 | // existing group, no authorization to access to the menu |
---|
596 | $ok=false; |
---|
597 | } |
---|
598 | } |
---|
599 | else |
---|
600 | { |
---|
601 | // user not authorized |
---|
602 | $ok=false; |
---|
603 | } |
---|
604 | } |
---|
605 | |
---|
606 | if($ok) |
---|
607 | { |
---|
608 | $returned[$row['id']]=array( |
---|
609 | 'id' => $row['id'], |
---|
610 | 'order' => $row['order'], |
---|
611 | 'users' => $row['users'], |
---|
612 | 'groups'=> $row['groups'], |
---|
613 | 'name' => $registeredBlocks[$row['id']]->get_name(), |
---|
614 | 'owner' => $registeredBlocks[$row['id']]->get_owner() |
---|
615 | ); |
---|
616 | $order=$row['order']; |
---|
617 | } |
---|
618 | unset($registeredBlocks[$row['id']]); |
---|
619 | } |
---|
620 | } |
---|
621 | } |
---|
622 | |
---|
623 | /* |
---|
624 | * add new blocks, unknown from plugin |
---|
625 | * by default, users & groups are visibles |
---|
626 | */ |
---|
627 | foreach($registeredBlocks as $key=>$val) |
---|
628 | { |
---|
629 | $order+=10; |
---|
630 | |
---|
631 | $returned[$key]=array( |
---|
632 | 'id' => $key, |
---|
633 | 'order' => $order, |
---|
634 | 'users' => array(), |
---|
635 | 'groups'=> array(), |
---|
636 | 'name' => $val->get_name(), |
---|
637 | 'owner' => $val->get_owner() |
---|
638 | ); |
---|
639 | } |
---|
640 | |
---|
641 | return($returned); |
---|
642 | } |
---|
643 | |
---|
644 | |
---|
645 | /** |
---|
646 | * set order for registered blocks |
---|
647 | * |
---|
648 | * note : Piwigo's order is maintened |
---|
649 | * |
---|
650 | * @param Array $block : array of block ; each items is an array |
---|
651 | * String 'id' => '' |
---|
652 | * Integer 'order' => '' |
---|
653 | * Array 'users' => array() |
---|
654 | * Array 'groups' => array() |
---|
655 | * @return Bool : true, false is something is wrong |
---|
656 | */ |
---|
657 | protected function setRegisteredBlocks($blocks) |
---|
658 | { |
---|
659 | $returned=true; |
---|
660 | |
---|
661 | $sql="DELETE FROM ".$this->tables['blocks']; |
---|
662 | pwg_query($sql); |
---|
663 | |
---|
664 | foreach($blocks as $block) |
---|
665 | { |
---|
666 | $sql="INSERT INTO ".$this->tables['blocks']." VALUES ( |
---|
667 | '".$block['id']."', |
---|
668 | '".$block['order']."', |
---|
669 | '".implode(',', $block['users'])."', |
---|
670 | '".implode(',', $block['groups'])."' |
---|
671 | );"; |
---|
672 | $result=pwg_query($sql); |
---|
673 | if(!$result) $returned=false; |
---|
674 | } |
---|
675 | |
---|
676 | return($returned); |
---|
677 | } |
---|
678 | |
---|
679 | |
---|
680 | static public function checkPluginRelease() |
---|
681 | { |
---|
682 | global $template, $prefixeTable, $conf; |
---|
683 | |
---|
684 | |
---|
685 | if($conf['amm_config']['installed']!=AMM_VERSION2) |
---|
686 | { |
---|
687 | /* the plugin was updated without being deactivated |
---|
688 | * deactivate + activate the plugin to process the database upgrade |
---|
689 | */ |
---|
690 | include(AMM_PATH."amm_install.class.inc.php"); |
---|
691 | $amm=new AMM_Install($prefixeTable, dirname(__FILE__)); |
---|
692 | $amm->deactivate(); |
---|
693 | $amm->activate(); |
---|
694 | if(is_object($template)) $template->delete_compiled_templates(); |
---|
695 | } |
---|
696 | } |
---|
697 | |
---|
698 | |
---|
699 | |
---|
700 | |
---|
701 | |
---|
702 | protected function sortCoreBlocksItemsCompare($a, $b) |
---|
703 | { |
---|
704 | if($a['container']==$b['container']) |
---|
705 | { |
---|
706 | if($a['order']==$b['order']) return(0); |
---|
707 | return(($a['order']<$b['order'])?-1:1); |
---|
708 | } |
---|
709 | else return(($a['container']<$b['container'])?-1:1); |
---|
710 | } |
---|
711 | |
---|
712 | protected function sortCoreBlocksItems() |
---|
713 | { |
---|
714 | uasort($this->config['amm_blocks_items'], array($this, "sortCoreBlocksItemsCompare")); |
---|
715 | } |
---|
716 | |
---|
717 | } // amm_root class |
---|
718 | |
---|
719 | |
---|
720 | |
---|
721 | ?> |
---|