1 | <?php |
---|
2 | /* |
---|
3 | * ----------------------------------------------------------------------------- |
---|
4 | * Plugin Name: Advanced Menu Manager |
---|
5 | * ----------------------------------------------------------------------------- |
---|
6 | * Author : Grum |
---|
7 | * email : grum@piwigo.org |
---|
8 | * website : http://photos.grum.fr |
---|
9 | * PWG user : http://forum.piwigo.org/profile.php?id=3706 |
---|
10 | * |
---|
11 | * << May the Little SpaceFrog be with you ! >> |
---|
12 | * |
---|
13 | * ----------------------------------------------------------------------------- |
---|
14 | * |
---|
15 | * See main.inc.php for release information |
---|
16 | * |
---|
17 | * manage all the ajax requests |
---|
18 | * ----------------------------------------------------------------------------- |
---|
19 | */ |
---|
20 | |
---|
21 | |
---|
22 | define('PHPWG_ROOT_PATH',dirname(dirname(dirname(__FILE__))).'/'); |
---|
23 | |
---|
24 | /* |
---|
25 | * set ajax module in admin mode if request is used for admin interface |
---|
26 | */ |
---|
27 | if(!isset($_REQUEST['ajaxfct'])) $_REQUEST['ajaxfct']=''; |
---|
28 | if(preg_match('/^admin\./i', $_REQUEST['ajaxfct'])) |
---|
29 | { |
---|
30 | define('IN_ADMIN', true); |
---|
31 | } |
---|
32 | |
---|
33 | // the common.inc.php file loads all the main.inc.php plugins files |
---|
34 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php' ); |
---|
35 | include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCAjax.class.inc.php'); |
---|
36 | include_once('amm_root.class.inc.php'); |
---|
37 | |
---|
38 | load_language('plugin.lang', AMM_PATH); |
---|
39 | |
---|
40 | |
---|
41 | class AMM_Ajax extends AMM_root |
---|
42 | { |
---|
43 | /** |
---|
44 | * constructor |
---|
45 | */ |
---|
46 | public function __construct($prefixeTable, $filelocation) |
---|
47 | { |
---|
48 | parent::__construct($prefixeTable, $filelocation); |
---|
49 | $this->loadConfig(); |
---|
50 | $this->checkRequest(); |
---|
51 | $this->returnAjaxContent(); |
---|
52 | } |
---|
53 | |
---|
54 | /** |
---|
55 | * check the $_REQUEST values and set default values |
---|
56 | * |
---|
57 | */ |
---|
58 | protected function checkRequest() |
---|
59 | { |
---|
60 | global $user; |
---|
61 | |
---|
62 | if(!isset($_REQUEST['ajaxfct'])) $_REQUEST['ajaxfct']=''; |
---|
63 | if(!isset($_REQUEST['errcode'])) $_REQUEST['errcode']=''; |
---|
64 | if(!isset($_REQUEST['token'])) $_REQUEST['token']=''; |
---|
65 | |
---|
66 | // check if asked function is valid |
---|
67 | if(!($_REQUEST['ajaxfct']=='admin.links.get' or |
---|
68 | $_REQUEST['ajaxfct']=='admin.links.set' or |
---|
69 | $_REQUEST['ajaxfct']=='admin.links.list' or |
---|
70 | $_REQUEST['ajaxfct']=='admin.links.delete' or |
---|
71 | $_REQUEST['ajaxfct']=='admin.links.order' or |
---|
72 | $_REQUEST['ajaxfct']=='admin.links.setConfig' or |
---|
73 | $_REQUEST['ajaxfct']=='admin.randomPict.setConfig' or |
---|
74 | $_REQUEST['ajaxfct']=='admin.blocks.get' or |
---|
75 | $_REQUEST['ajaxfct']=='admin.blocks.set' or |
---|
76 | $_REQUEST['ajaxfct']=='admin.blocks.delete' or |
---|
77 | $_REQUEST['ajaxfct']=='admin.blocks.list' or |
---|
78 | $_REQUEST['ajaxfct']=='admin.album.setConfig' or |
---|
79 | $_REQUEST['ajaxfct']=='admin.coreBlocks.setConfig' |
---|
80 | )) $_REQUEST['ajaxfct']=''; |
---|
81 | |
---|
82 | if(preg_match('/^admin\./i', $_REQUEST['ajaxfct']) and !is_admin()) $_REQUEST['ajaxfct']=''; |
---|
83 | |
---|
84 | |
---|
85 | if($_REQUEST['ajaxfct']!='') |
---|
86 | { |
---|
87 | /* |
---|
88 | * no check for admin.links.list request |
---|
89 | */ |
---|
90 | |
---|
91 | /* |
---|
92 | * check admin.links.get request |
---|
93 | * check admin.blocks.get request |
---|
94 | */ |
---|
95 | if($_REQUEST['ajaxfct']=='admin.links.get' or |
---|
96 | $_REQUEST['ajaxfct']=='admin.blocks.get request') |
---|
97 | { |
---|
98 | if(!isset($_REQUEST['id'])) $_REQUEST['id']=''; |
---|
99 | |
---|
100 | if($_REQUEST['id']=='') $_REQUEST['ajaxfct']=''; |
---|
101 | } |
---|
102 | |
---|
103 | /* |
---|
104 | * check admin.links.set request |
---|
105 | */ |
---|
106 | if($_REQUEST['ajaxfct']=='admin.links.set') |
---|
107 | { |
---|
108 | if(!isset($_REQUEST['id'])) $_REQUEST['id']=''; |
---|
109 | if(!isset($_REQUEST['datas']['label'])) $_REQUEST['datas']['label']=''; |
---|
110 | if(!isset($_REQUEST['datas']['url'])) $_REQUEST['datas']['url']=''; |
---|
111 | if(!isset($_REQUEST['datas']['icon'])) $_REQUEST['datas']['icon']=''; |
---|
112 | if(!isset($_REQUEST['datas']['mode'])) $_REQUEST['datas']['mode']='0'; |
---|
113 | if(!isset($_REQUEST['datas']['visible'])) $_REQUEST['datas']['visible']='n'; |
---|
114 | if(!isset($_REQUEST['datas']['accessUsers']) or $_REQUEST['datas']['accessUsers']=='') $_REQUEST['datas']['accessUsers']=array(); |
---|
115 | if(!isset($_REQUEST['datas']['accessGroups']) or $_REQUEST['datas']['accessGroups']=='') $_REQUEST['datas']['accessGroups']=array(); |
---|
116 | |
---|
117 | if($_REQUEST['token']!=get_pwg_token() or |
---|
118 | $_REQUEST['datas']['label']=='' or |
---|
119 | $_REQUEST['datas']['url']=='' or |
---|
120 | $_REQUEST['datas']['icon']=='' or |
---|
121 | !($_REQUEST['datas']['mode']=='0' or $_REQUEST['datas']['mode']=='1') or |
---|
122 | !($_REQUEST['datas']['visible']=='y' or $_REQUEST['datas']['visible']=='n') |
---|
123 | ) $_REQUEST['ajaxfct']=''; |
---|
124 | } |
---|
125 | |
---|
126 | /* |
---|
127 | * check admin.links.delete request |
---|
128 | * check admin.blocks.delete request |
---|
129 | * |
---|
130 | */ |
---|
131 | if($_REQUEST['ajaxfct']=='admin.links.delete' or |
---|
132 | $_REQUEST['ajaxfct']=='admin.blocks.delete') |
---|
133 | { |
---|
134 | if(!isset($_REQUEST['id'])) $_REQUEST['id']=''; |
---|
135 | |
---|
136 | if($_REQUEST['id']=='' or |
---|
137 | $_REQUEST['token']!=get_pwg_token() |
---|
138 | ) $_REQUEST['ajaxfct']=''; |
---|
139 | } |
---|
140 | |
---|
141 | /* |
---|
142 | * check admin.links.order request |
---|
143 | */ |
---|
144 | if($_REQUEST['ajaxfct']=='admin.links.order') |
---|
145 | { |
---|
146 | if(!isset($_REQUEST['datas']['links']) or $_REQUEST['datas']['links']=='') $_REQUEST['datas']['links']=array(); |
---|
147 | |
---|
148 | if(count($_REQUEST['datas']['links'])<=1 or |
---|
149 | $_REQUEST['token']!=get_pwg_token() |
---|
150 | ) $_REQUEST['ajaxfct']=''; |
---|
151 | } |
---|
152 | |
---|
153 | |
---|
154 | /* |
---|
155 | * check admin.links.setConfig request |
---|
156 | */ |
---|
157 | if($_REQUEST['ajaxfct']=='admin.links.setConfig') |
---|
158 | { |
---|
159 | if(!isset($_REQUEST['datas']['showIcons'])) $_REQUEST['datas']['showIcons']=''; |
---|
160 | if(!isset($_REQUEST['datas']['title']) or $_REQUEST['datas']['title']=='') $_REQUEST['datas']['title']=array(); |
---|
161 | |
---|
162 | if($_REQUEST['token']!=get_pwg_token() or |
---|
163 | $_REQUEST['datas']['showIcons']=='' or |
---|
164 | count($_REQUEST['datas']['title'])==0 |
---|
165 | ) $_REQUEST['ajaxfct']=''; |
---|
166 | } |
---|
167 | |
---|
168 | |
---|
169 | |
---|
170 | /* |
---|
171 | * check admin.randomPict.setConfig request |
---|
172 | */ |
---|
173 | if($_REQUEST['ajaxfct']=='admin.randomPict.setConfig') |
---|
174 | { |
---|
175 | if(!isset($_REQUEST['datas']['blockHeight'])) $_REQUEST['datas']['blockHeight']=''; |
---|
176 | if(!isset($_REQUEST['datas']['blockTitles']) or $_REQUEST['datas']['blockTitles']=='') $_REQUEST['datas']['blockTitles']=array(); |
---|
177 | if(!isset($_REQUEST['datas']['infosName'])) $_REQUEST['datas']['infosName']=''; |
---|
178 | if(!isset($_REQUEST['datas']['infosComment'])) $_REQUEST['datas']['infosComment']=''; |
---|
179 | if(!isset($_REQUEST['datas']['freqDelay'])) $_REQUEST['datas']['freqDelay']=''; |
---|
180 | if(!isset($_REQUEST['datas']['selectMode'])) $_REQUEST['datas']['selectMode']=''; |
---|
181 | if(!isset($_REQUEST['datas']['selectCat']) or $_REQUEST['datas']['selectCat']=='') $_REQUEST['datas']['selectCat']=array(); |
---|
182 | |
---|
183 | if($_REQUEST['token']!=get_pwg_token() or |
---|
184 | !is_numeric($_REQUEST['datas']['blockHeight']) or |
---|
185 | count($_REQUEST['datas']['blockTitles'])==0 or |
---|
186 | !($_REQUEST['datas']['infosName']=='n' or |
---|
187 | $_REQUEST['datas']['infosName']=='o' or |
---|
188 | $_REQUEST['datas']['infosName']=='u') or |
---|
189 | !($_REQUEST['datas']['infosComment']=='n' or |
---|
190 | $_REQUEST['datas']['infosComment']=='o' or |
---|
191 | $_REQUEST['datas']['infosComment']=='u') or |
---|
192 | !is_numeric($_REQUEST['datas']['freqDelay']) or |
---|
193 | !($_REQUEST['datas']['selectMode']=='a' or |
---|
194 | $_REQUEST['datas']['selectMode']=='f' or |
---|
195 | $_REQUEST['datas']['selectMode']=='c') or |
---|
196 | ($_REQUEST['datas']['selectMode']=='c' and |
---|
197 | count($_REQUEST['datas']['selectCat'])==0) |
---|
198 | ) $_REQUEST['ajaxfct']=''; |
---|
199 | } |
---|
200 | |
---|
201 | |
---|
202 | /* |
---|
203 | * check admin.blocks.set request |
---|
204 | */ |
---|
205 | if($_REQUEST['ajaxfct']=='admin.blocks.set') |
---|
206 | { |
---|
207 | if(!isset($_REQUEST['id'])) $_REQUEST['id']=''; |
---|
208 | if(!isset($_REQUEST['datas']['nfo'])) $_REQUEST['datas']['nfo']=''; |
---|
209 | if(!isset($_REQUEST['datas']['visible'])) $_REQUEST['datas']['visible']=''; |
---|
210 | if(!isset($_REQUEST['datas']['langs']) or $_REQUEST['datas']['langs']=='') $_REQUEST['datas']['langs']=array(); |
---|
211 | |
---|
212 | if($_REQUEST['token']!=get_pwg_token() or |
---|
213 | $_REQUEST['datas']['nfo']=='' or |
---|
214 | !($_REQUEST['datas']['visible']=='y' or $_REQUEST['datas']['visible']=='n') or |
---|
215 | count($_REQUEST['datas']['langs'])==0 |
---|
216 | ) $_REQUEST['ajaxfct']=''; |
---|
217 | } |
---|
218 | |
---|
219 | |
---|
220 | |
---|
221 | |
---|
222 | /* |
---|
223 | * check admin.coreBlocks.setConfig request |
---|
224 | */ |
---|
225 | if($_REQUEST['ajaxfct']=='admin.coreBlocks.setConfig') |
---|
226 | { |
---|
227 | if(!isset($_REQUEST['datas']['menuItems']) or $_REQUEST['datas']['menuItems']=='') $_REQUEST['datas']['menuItems']=array(); |
---|
228 | if(!isset($_REQUEST['datas']['blocks']) or $_REQUEST['datas']['blocks']=='') $_REQUEST['datas']['blocks']=array(); |
---|
229 | |
---|
230 | if($_REQUEST['token']!=get_pwg_token() or |
---|
231 | count($_REQUEST['datas']['menuItems'])!=count($this->defaultMenus) |
---|
232 | ) $_REQUEST['ajaxfct']=''; |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | /* |
---|
237 | * check admin.album.setConfig request |
---|
238 | */ |
---|
239 | if($_REQUEST['ajaxfct']=='admin.album.setConfig') |
---|
240 | { |
---|
241 | if(!isset($_REQUEST['datas']['selectCat']) or $_REQUEST['datas']['selectCat']=='') $_REQUEST['datas']['selectCat']=array(); |
---|
242 | |
---|
243 | if($_REQUEST['token']!=get_pwg_token()) $_REQUEST['ajaxfct']=''; |
---|
244 | } |
---|
245 | |
---|
246 | |
---|
247 | } |
---|
248 | |
---|
249 | } //checkRequest |
---|
250 | |
---|
251 | |
---|
252 | /** |
---|
253 | * return ajax content |
---|
254 | */ |
---|
255 | protected function returnAjaxContent() |
---|
256 | { |
---|
257 | $result="KO!".l10n('g002_error_invalid_ajax_call'); |
---|
258 | switch($_REQUEST['ajaxfct']) |
---|
259 | { |
---|
260 | case 'admin.links.get': |
---|
261 | $result=$this->ajax_amm_admin_linksGet($_REQUEST['id']); |
---|
262 | break; |
---|
263 | case 'admin.links.set': |
---|
264 | $result=$this->ajax_amm_admin_linksSet($_REQUEST['id'],$_REQUEST['datas']['label'],$_REQUEST['datas']['url'],$_REQUEST['datas']['mode'],$_REQUEST['datas']['icon'],$_REQUEST['datas']['visible'],$_REQUEST['datas']['accessUsers'],$_REQUEST['datas']['accessGroups']); |
---|
265 | break; |
---|
266 | case 'admin.links.list': |
---|
267 | $result=$this->ajax_amm_admin_linksList(); |
---|
268 | break; |
---|
269 | case 'admin.links.order': |
---|
270 | $result=$this->ajax_amm_admin_linksOrder($_REQUEST['datas']['links']); |
---|
271 | break; |
---|
272 | case 'admin.links.delete': |
---|
273 | $result=$this->ajax_amm_admin_linksDelete($_REQUEST['id']); |
---|
274 | break; |
---|
275 | case 'admin.links.setConfig': |
---|
276 | $result=$this->ajax_amm_admin_linksSetConfig($_REQUEST['datas']); |
---|
277 | break; |
---|
278 | |
---|
279 | case 'admin.randomPict.setConfig': |
---|
280 | $result=$this->ajax_amm_admin_randomPictSetConfig($_REQUEST['datas']); |
---|
281 | break; |
---|
282 | |
---|
283 | case 'admin.blocks.get': |
---|
284 | $result=$this->ajax_amm_admin_blocksGet($_REQUEST['id']); |
---|
285 | break; |
---|
286 | case 'admin.blocks.set': |
---|
287 | $result=$this->ajax_amm_admin_blocksSet($_REQUEST['id'],$_REQUEST['datas']['visible'],$_REQUEST['datas']['nfo'],$_REQUEST['datas']['langs']); |
---|
288 | break; |
---|
289 | case 'admin.blocks.list': |
---|
290 | $result=$this->ajax_amm_admin_blocksList(); |
---|
291 | break; |
---|
292 | case 'admin.blocks.delete': |
---|
293 | $result=$this->ajax_amm_admin_blocksDelete($_REQUEST['id']); |
---|
294 | break; |
---|
295 | |
---|
296 | case 'admin.coreBlocks.setConfig': |
---|
297 | $result=$this->ajax_amm_admin_coreBlocksSetConfig($_REQUEST['datas']['menuItems'], $_REQUEST['datas']['blocks']); |
---|
298 | break; |
---|
299 | |
---|
300 | case 'admin.album.setConfig': |
---|
301 | $result=$this->ajax_amm_admin_albumSetConfig($_REQUEST['datas']); |
---|
302 | break; |
---|
303 | } |
---|
304 | GPCAjax::returnResult($result); |
---|
305 | } |
---|
306 | |
---|
307 | |
---|
308 | /* |
---|
309 | * ------------------------------------------------------------------------- |
---|
310 | * |
---|
311 | * ADMIN FUNCTIONS |
---|
312 | * |
---|
313 | * ------------------------------------------------------------------------- |
---|
314 | */ |
---|
315 | |
---|
316 | |
---|
317 | /* |
---|
318 | * ------------------------------------------------------------------------- |
---|
319 | * Links |
---|
320 | * ------------------------------------------------------------------------- |
---|
321 | */ |
---|
322 | |
---|
323 | /** |
---|
324 | * return a html formatted list of urls |
---|
325 | */ |
---|
326 | private function ajax_amm_admin_linksList() |
---|
327 | { |
---|
328 | global $template, $user; |
---|
329 | $local_tpl = new Template(AMM_PATH."admin/", ""); |
---|
330 | $local_tpl->set_filename('body_page', |
---|
331 | dirname($this->getFileLocation()).'/admin/amm_linkslinks_detail.tpl'); |
---|
332 | |
---|
333 | |
---|
334 | |
---|
335 | $datas['links']=array(); |
---|
336 | |
---|
337 | $links=$this->getLinks(); |
---|
338 | foreach($links as $link) |
---|
339 | { |
---|
340 | $datas['links'][]=array( |
---|
341 | 'id' => $link['id'], |
---|
342 | 'label' => $link['label'], |
---|
343 | 'url' => $link['url'], |
---|
344 | 'mode' => l10n("g002_mode_".$this->urlsModes[$link['mode']]), |
---|
345 | 'icon' => "plugins/".AMM_DIR."/links_pictures/".$link['icon'], |
---|
346 | 'visible' => l10n('g002_yesno_'.$link['visible']) |
---|
347 | ); |
---|
348 | } |
---|
349 | |
---|
350 | $local_tpl->assign('themeconf', $template->get_template_vars('themeconf')); |
---|
351 | $local_tpl->assign('datas', $datas); |
---|
352 | $local_tpl->assign('plugin', array('PATH' => AMM_PATH)); |
---|
353 | |
---|
354 | return($local_tpl->parse('body_page', true)); |
---|
355 | } |
---|
356 | |
---|
357 | |
---|
358 | /** |
---|
359 | * update links order |
---|
360 | * |
---|
361 | * @param Array $links |
---|
362 | * @return String : OK or KO |
---|
363 | */ |
---|
364 | private function ajax_amm_admin_linksOrder($links) |
---|
365 | { |
---|
366 | return($this->setLinksOrder($links)?'OK':'KO'); |
---|
367 | } |
---|
368 | |
---|
369 | |
---|
370 | /** |
---|
371 | * delete a link |
---|
372 | * |
---|
373 | * @param Integer $id : link id |
---|
374 | * @return String : OK or KO |
---|
375 | */ |
---|
376 | private function ajax_amm_admin_linksDelete($id) |
---|
377 | { |
---|
378 | return($this->deleteLink($id)?'OK':'KO'); |
---|
379 | } |
---|
380 | |
---|
381 | /** |
---|
382 | * return link content as a json string |
---|
383 | * |
---|
384 | * @param Integer $id : link id |
---|
385 | * @return String : json string |
---|
386 | */ |
---|
387 | private function ajax_amm_admin_linksGet($id) |
---|
388 | { |
---|
389 | $link=$this->getLink($id); |
---|
390 | $link['accessUsers']=explode(',', $link['accessUsers']); |
---|
391 | $link['accessGroups']=explode(',', $link['accessGroups']); |
---|
392 | return(json_encode($link)); |
---|
393 | } |
---|
394 | |
---|
395 | /** |
---|
396 | * set link values |
---|
397 | * if id is empty, create a new link |
---|
398 | * |
---|
399 | * @param String $id : link id |
---|
400 | * @param String $label : link label |
---|
401 | * @param String $url : link url |
---|
402 | * @param String $mode : link mode (open a new window or not) |
---|
403 | * @param String $icon : displayed icon |
---|
404 | * @param String $visible : link visibility |
---|
405 | * @return String : $id if OK, otherwise -1 |
---|
406 | */ |
---|
407 | private function ajax_amm_admin_linksSet($id, $label, $url, $mode, $icon, $visible, $accessUsers, $accessGroups) |
---|
408 | { |
---|
409 | return($this->setLink($id, $label, $url, $mode, $icon, $visible, implode(',', $accessUsers), implode(',', $accessGroups))); |
---|
410 | } |
---|
411 | |
---|
412 | /** |
---|
413 | * set the links config |
---|
414 | * |
---|
415 | * $config is an array with keys : |
---|
416 | * String 'showIcons' : values 'y' or 'n' |
---|
417 | * Array 'titles' : each array occurs is an array('id' => '', 'value' => '') |
---|
418 | * id = lang id ('fr_FR', 'en_UK', ...) |
---|
419 | * |
---|
420 | * @param Array $config |
---|
421 | * @return String : OK or KO |
---|
422 | */ |
---|
423 | private function ajax_amm_admin_linksSetConfig($config) |
---|
424 | { |
---|
425 | $this->config['amm_links_show_icons']=$config['showIcons']; |
---|
426 | |
---|
427 | $this->config['amm_links_title']=array(); |
---|
428 | foreach($config['title'] as $title) |
---|
429 | { |
---|
430 | $this->config['amm_links_title'][$title['id']]=base64_encode($title['value']); |
---|
431 | } |
---|
432 | |
---|
433 | $this->saveConfig(); |
---|
434 | |
---|
435 | return('OK!'.l10n('g002_config_saved')); |
---|
436 | } |
---|
437 | |
---|
438 | |
---|
439 | /* |
---|
440 | * ------------------------------------------------------------------------- |
---|
441 | * random picture |
---|
442 | * ------------------------------------------------------------------------- |
---|
443 | */ |
---|
444 | |
---|
445 | |
---|
446 | /** |
---|
447 | * set the random picture config |
---|
448 | * |
---|
449 | * $config is an array with keys : |
---|
450 | * Integer 'blockHeight' : if value=0, the browser assume an automatic size |
---|
451 | * Array 'blockTitles' : each array occurs is an array('id' => '', 'value' => '') |
---|
452 | * id = lang id ('fr_FR', 'en_UK', ...) |
---|
453 | * String 'infosName' : allow to display picture's name ; |
---|
454 | * can take 'n' (no), 'o' (over), or 'u' (under) |
---|
455 | * String 'infosComment' : allow to display picture's comment ; |
---|
456 | * can take 'n' (no), 'o' (over), or 'u' (under) |
---|
457 | * Integer 'freqDelay' : allow to choose change frequency (delay is in |
---|
458 | * milliseconds) |
---|
459 | * if value=0, there is no change |
---|
460 | * String 'selectMode' : allows to choose picture to be randomly selected |
---|
461 | * can take 'a' (all), 'f' (webmaster's favorites), 'c' (from categories) |
---|
462 | * Array 'selectCat' : list of selected categories (choosing a cat implies to choose all sub cat) |
---|
463 | * |
---|
464 | * @param Array $config |
---|
465 | * @return String : OK or KO |
---|
466 | */ |
---|
467 | private function ajax_amm_admin_randomPictSetConfig($config) |
---|
468 | { |
---|
469 | $this->config['amm_randompicture_selectMode']=$config['selectMode']; |
---|
470 | $this->config['amm_randompicture_selectCat']=$config['selectCat']; |
---|
471 | $this->config['amm_randompicture_showname']=$config['infosName']; |
---|
472 | $this->config['amm_randompicture_showcomment']=$config['infosComment']; |
---|
473 | $this->config['amm_randompicture_periodicchange']=$config['freqDelay']; |
---|
474 | $this->config['amm_randompicture_height']=($config['blockHeight']==99)?0:$config['blockHeight']; |
---|
475 | $this->config['amm_randompicture_title']=array(); |
---|
476 | foreach($config['blockTitles'] as $title) |
---|
477 | { |
---|
478 | $this->config['amm_randompicture_title'][$title['id']]=base64_encode($title['value']); |
---|
479 | } |
---|
480 | |
---|
481 | $this->saveConfig(); |
---|
482 | return('OK!'.l10n('g002_config_saved')); |
---|
483 | } |
---|
484 | |
---|
485 | |
---|
486 | |
---|
487 | /* |
---|
488 | * ------------------------------------------------------------------------- |
---|
489 | * personalised blocks |
---|
490 | * ------------------------------------------------------------------------- |
---|
491 | */ |
---|
492 | |
---|
493 | /** |
---|
494 | * return a html formatted list of blocks |
---|
495 | */ |
---|
496 | private function ajax_amm_admin_blocksList() |
---|
497 | { |
---|
498 | global $template, $user; |
---|
499 | |
---|
500 | $local_tpl = new Template(AMM_PATH."admin/", ""); |
---|
501 | $local_tpl->set_filename('body_page', |
---|
502 | dirname($this->getFileLocation()).'/admin/amm_personalised_detail.tpl'); |
---|
503 | |
---|
504 | |
---|
505 | |
---|
506 | $datas=array( |
---|
507 | 'blocks'=>array() |
---|
508 | ); |
---|
509 | |
---|
510 | $blocks=$this->getPersonalisedBlocks(false, '', true); |
---|
511 | foreach($blocks as $block) |
---|
512 | { |
---|
513 | $datas['blocks'][]=array( |
---|
514 | 'id' => $block['id'], |
---|
515 | 'nfo' => $block['nfo'], |
---|
516 | 'title' => $block['title'], |
---|
517 | 'visible' => l10n('g002_yesno_'.$block['visible']) |
---|
518 | ); |
---|
519 | } |
---|
520 | |
---|
521 | $local_tpl->assign('themeconf', $template->get_template_vars('themeconf')); |
---|
522 | $local_tpl->assign('datas', $datas); |
---|
523 | $local_tpl->assign('plugin', array('PATH' => AMM_PATH)); |
---|
524 | |
---|
525 | return($local_tpl->parse('body_page', true)); |
---|
526 | } |
---|
527 | |
---|
528 | /** |
---|
529 | * delete a block |
---|
530 | * |
---|
531 | * @param Integer $id : block id |
---|
532 | * @return String : OK or KO |
---|
533 | */ |
---|
534 | private function ajax_amm_admin_blocksDelete($id) |
---|
535 | { |
---|
536 | return($this->deletePersonalisedBlock($id)?'OK':'KO'); |
---|
537 | } |
---|
538 | |
---|
539 | /** |
---|
540 | * return block content as a json string |
---|
541 | * |
---|
542 | * @param Integer $id : block id |
---|
543 | * @return String : json string |
---|
544 | */ |
---|
545 | private function ajax_amm_admin_blocksGet($id) |
---|
546 | { |
---|
547 | return(json_encode($this->getPersonalisedBlock($id))); |
---|
548 | } |
---|
549 | |
---|
550 | /** |
---|
551 | * set block values |
---|
552 | * if id is empty, create a new block |
---|
553 | * |
---|
554 | * @param String $id : block id |
---|
555 | * @param String $visible : block visibility ('y' or 'n') |
---|
556 | * @param String $nfo : block description |
---|
557 | * @param Array $langs : block langs, each record is an array |
---|
558 | * array('title' => '', 'content' => '') |
---|
559 | * @return String : $id if OK, otherwise -1 |
---|
560 | */ |
---|
561 | private function ajax_amm_admin_blocksSet($id, $visible, $nfo, $lang) |
---|
562 | { |
---|
563 | return($this->setPersonalisedBlock($id, $visible, $nfo, $lang)); |
---|
564 | } |
---|
565 | |
---|
566 | /* |
---|
567 | * ------------------------------------------------------------------------- |
---|
568 | * core blocks |
---|
569 | * ------------------------------------------------------------------------- |
---|
570 | */ |
---|
571 | |
---|
572 | /** |
---|
573 | * set the menu config |
---|
574 | * - core blocks content |
---|
575 | * - blocks order&visibility |
---|
576 | * |
---|
577 | * @param Array $subMenus : for core blocks, sub menu items |
---|
578 | * array( |
---|
579 | * 'subMenuId' => array( |
---|
580 | * 'visibility' => (String), |
---|
581 | * 'order' => (Integer), |
---|
582 | * 'container' => (String), |
---|
583 | * ) |
---|
584 | * ) |
---|
585 | * @param Array $menus : menu blocks order&visibility |
---|
586 | * array( |
---|
587 | * 'block1' => array( |
---|
588 | * 'id' => (String), |
---|
589 | * 'order' => (Integer), |
---|
590 | * 'users' => array(), |
---|
591 | * 'groups' => array() |
---|
592 | * ) |
---|
593 | * ) |
---|
594 | * @return String : OK or KO |
---|
595 | */ |
---|
596 | private function ajax_amm_admin_coreBlocksSetConfig($subMenu, $menus) |
---|
597 | { |
---|
598 | foreach($subMenu as $key=>$val) |
---|
599 | { |
---|
600 | if(!isset($subMenu[$key]['visibilityUser']) or $subMenu[$key]['visibilityUser']=='') $subMenu[$key]['visibilityUser']=array(); |
---|
601 | if(!isset($subMenu[$key]['visibilityGroup']) or $subMenu[$key]['visibilityGroup']=='') $subMenu[$key]['visibilityGroup']=array(); |
---|
602 | |
---|
603 | $subMenu[$key]['visibility']=implode(',', $subMenu[$key]['visibilityUser']).'/'.implode(',', $subMenu[$key]['visibilityGroup']); |
---|
604 | unset($subMenu[$key]['visibilityUser']); |
---|
605 | unset($subMenu[$key]['visibilityGroup']); |
---|
606 | } |
---|
607 | $this->config['amm_blocks_items']=$subMenu; |
---|
608 | $this->saveConfig(); |
---|
609 | |
---|
610 | |
---|
611 | foreach($menus as $key=>$val) |
---|
612 | { |
---|
613 | if(!isset($menus[$key]['users']) or $menus[$key]['users']=='') $menus[$key]['users']=array(); |
---|
614 | if(!isset($menus[$key]['groups']) or $menus[$key]['groups']=='') $menus[$key]['groups']=array(); |
---|
615 | } |
---|
616 | $this->setRegisteredBlocks($menus); |
---|
617 | |
---|
618 | return('OK!'.l10n('g002_config_saved')); |
---|
619 | } |
---|
620 | |
---|
621 | |
---|
622 | |
---|
623 | /* |
---|
624 | * ------------------------------------------------------------------------- |
---|
625 | * album to menu |
---|
626 | * ------------------------------------------------------------------------- |
---|
627 | */ |
---|
628 | |
---|
629 | |
---|
630 | /** |
---|
631 | * set the album to menu config |
---|
632 | * |
---|
633 | * $config is an array with keys : |
---|
634 | * Array 'selectCat' : list of selected categories |
---|
635 | * |
---|
636 | * @param Array $config |
---|
637 | * @return String : OK or KO |
---|
638 | */ |
---|
639 | private function ajax_amm_admin_albumSetConfig($config) |
---|
640 | { |
---|
641 | $this->config['amm_albums_to_menu']=$config['selectCat']; |
---|
642 | |
---|
643 | $this->saveConfig(); |
---|
644 | return('OK!'.l10n('g002_config_saved')); |
---|
645 | } |
---|
646 | |
---|
647 | |
---|
648 | } //class |
---|
649 | |
---|
650 | |
---|
651 | $returned=new AMM_Ajax($prefixeTable, __FILE__); |
---|
652 | ?> |
---|
653 | |
---|