source: extensions/AMenuManager/amm_aip.class.inc.php @ 15907

Last change on this file since 15907 was 15366, checked in by grum, 12 years ago

feature:2642 - Compatibility with Piwigo 2.4

  • Property svn:executable set to *
File size: 17.8 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : Advanced Menu Manager
4  Author     : Grum
5    email    : grum@piwigo.org
6    website  : http://photos.grum.fr
7    PWG user : http://forum.phpwebgallery.net/profile.php?id=3706
8
9    << May the Little SpaceFrog be with you ! >>
10  ------------------------------------------------------------------------------
11  See main.inc.php for release information
12
13  AIP classe => manage integration in administration interface
14
15  --------------------------------------------------------------------------- */
16if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
17
18include_once(PHPWG_PLUGINS_PATH.'AMenuManager/amm_root.class.inc.php');
19include_once(PHPWG_ROOT_PATH.'include/block.class.php');
20include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
21include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTabSheet.class.inc.php');
22
23
24class AMM_AIP extends AMM_root
25{
26  protected $tabsheet;
27  protected $blocksId=array('menu' => 'Menu', 'special' => 'Specials');
28
29
30  public function __construct($prefixeTable, $filelocation)
31  {
32    parent::__construct($prefixeTable, $filelocation);
33
34    $this->loadConfig();
35    $this->initEvents();
36
37    $this->tabsheet = new tabsheet();
38    $this->tabsheet->add('setmenu',
39                          l10n('g002_setmenu'),
40                          $this->getAdminLink().'-setmenu');
41    $this->tabsheet->add('links',
42                          l10n('g002_addlinks'),
43                          $this->getAdminLink().'-links');
44    $this->tabsheet->add('randompict',
45                          l10n('g002_randompict'),
46                          $this->getAdminLink().'-randompict');
47    $this->tabsheet->add('personnalblock',
48                          l10n('g002_personnalblock'),
49                          $this->getAdminLink().'-personnalblock');
50    $this->tabsheet->add('album',
51                          l10n('g002_album'),
52                          $this->getAdminLink().'-album');
53    $this->css = new GPCCss(dirname($this->getFileLocation()).'/'.$this->getPluginNameFiles().".css");
54  }
55
56
57  /**
58   * manage plugin integration into piwigo's admin interface
59   */
60  public function manage()
61  {
62    global $template, $page;
63
64    $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/amm_admin.tpl");
65
66    $this->initRequest();
67
68    $this->tabsheet->select($_GET['tab']);
69    $this->tabsheet->assign();
70    $selected_tab=$this->tabsheet->get_selected();
71    $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]");
72
73    $template_plugin["AMM_VERSION"] = "<i>".$this->getPluginName()."</i> ".l10n('g002_version').AMM_VERSION;
74    $template_plugin["AMM_PAGE"] = $_GET['tab'];
75    $template_plugin["PATH"] = AMM_PATH;
76
77    $template->assign('plugin', $template_plugin);
78    $template->assign('token', get_pwg_token());
79
80
81    switch($_GET['tab'])
82    {
83      case 'links':
84        $this->displayLinksPage($_REQUEST['t']);
85        break;
86
87      case 'randompict':
88        $this->displayRandompicPage();
89        break;
90
91      case 'personnalblock':
92        $this->displayPersonalisedBlockPage();
93        break;
94
95      case 'setmenu':
96        $this->displayBlocksPage($_REQUEST['t']);
97        break;
98
99      case 'album':
100        $this->displayAlbumPage();
101        break;
102    }
103
104    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
105  }
106
107
108  /**
109   * initialize events call for the plugin
110   */
111  public function initEvents()
112  {
113    add_event_handler('loc_end_page_header', array(&$this->css, 'applyCSS'));
114    GPCCss::applyGpcCss();
115  }
116
117
118  /**
119   * if empty, initialize the $_REQUEST var
120   *
121   * if not empty, check validity for the request values
122   *
123   */
124  private function initRequest()
125  {
126    //initialise $REQUEST values if not defined
127    if(!array_key_exists('tab', $_GET)) $_GET['tab']='setmenu';
128
129    $tmp=explode('/', $_GET['tab'].'/');
130    $_GET['tab']=$tmp[0];
131    $_REQUEST['t']=$tmp[1];
132
133    if(!($_GET['tab']=='links' or
134         $_GET['tab']=='randompict' or
135         $_GET['tab']=='personnalblock' or
136         $_GET['tab']=='setmenu' or
137         $_GET['tab']=='album'
138        )
139      ) $_GET['tab']='setmenu';
140
141
142    /*
143     * checks for links page
144     */
145    if($_GET['tab']=='links')
146    {
147      if(!isset($_REQUEST['t'])) $_REQUEST['t']='links';
148
149      if(!($_REQUEST['t']=='links' or
150           $_REQUEST['t']=='config'
151          )
152        ) $_REQUEST['t']='config';
153    }
154
155
156    /*
157     * checks for blocks menu page
158     */
159    if($_GET['tab']=='setmenu')
160    {
161      if(!isset($_REQUEST['t'])) $_REQUEST['t']='position';
162
163      if(!($_REQUEST['t']=='position' or
164           $_REQUEST['t']=='blocksContent'
165          )
166        ) $_REQUEST['t']='position';
167    }
168
169  } //initRequest
170
171
172  /**
173   * display the links management page
174   */
175  private function displayLinksPage($tab)
176  {
177    global $template, $user;
178
179    GPCCore::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
180    GPCCore::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery'));
181    GPCCore::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
182    GPCCore::addHeaderJS('jquery.ui.position', 'themes/default/js/ui/jquery.ui.position.js', array('jquery.ui.widget'));
183    GPCCore::addHeaderJS('jquery.ui.sortable', 'themes/default/js/ui/jquery.ui.sortable.js', array('jquery.ui.widget'));
184    GPCCore::addHeaderJS('jquery.ui.dialog', 'themes/default/js/ui/jquery.ui.dialog.js', array('jquery.ui.widget'));
185
186    $template->set_filename('body_page',
187                            dirname($this->getFileLocation()).'/admin/amm_links.tpl');
188
189    $linksTabsheet = new GPCTabSheet('linksTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder2', 'itab2');
190    $linksTabsheet->select($tab);
191    $linksTabsheet->add('links',
192                          l10n('g002_setting_link_links'),
193                          $this->getAdminLink().'-links/links');
194    $linksTabsheet->add('config',
195                          l10n('g002_configlinks'),
196                          $this->getAdminLink().'-links/config');
197    $linksTabsheet->assign();
198
199    switch($tab)
200    {
201      case 'links':
202        $template->assign('sheetContent', $this->displayLinksPageLinks());
203        break;
204      case 'config':
205        $template->assign('sheetContent', $this->displayLinksPageConfig());
206        break;
207    }
208
209    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
210    $template->assign('pageNfo', l10n('g002_addlinks_nfo'));
211  }
212
213  /**
214   * display the randompict management page
215   */
216  private function displayRandompicPage()
217  {
218    global $template, $user;
219
220    GPCCore::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
221    GPCCore::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery'));
222    GPCCore::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery'));
223    GPCCore::addHeaderJS('jquery.ui.position', 'themes/default/js/ui/jquery.ui.position.js', array('jquery'));
224    GPCCore::addHeaderJS('jquery.ui.sortable', 'themes/default/js/ui/jquery.ui.sortable.js', array('jquery.ui.widget'));
225    GPCCore::addHeaderJS('jquery.ui.dialog', 'themes/default/js/ui/jquery.ui.dialog.js', array('jquery.ui.widget'));
226    GPCCore::addHeaderJS('jquery.ui.slider', 'themes/default/js/ui/jquery.ui.slider.js', array('jquery.ui.widget'));
227    GPCCore::addUI('inputList,inputText,inputRadio,categorySelector');
228    GPCCore::addHeaderJS('amm.rpc', 'plugins/AMenuManager/js/amm_randomPictConfig.js', array('jquery', 'gpc.inputList', 'gpc.inputText', 'gpc.inputRadio', 'gpc.categorySelector'));
229
230    $template->set_filename('body_page',
231                            dirname($this->getFileLocation()).'/admin/amm_randompicconfig.tpl');
232
233    $datas=array(
234      'config' => array(
235          'infosName' => $this->config['amm_randompicture_showname'],
236          'infosComment' => $this->config['amm_randompicture_showcomment'],
237          'freqDelay' => $this->config['amm_randompicture_periodicchange'],
238          'selectMode' => $this->config['amm_randompicture_selectMode'],
239          'selectCat' => json_encode($this->config['amm_randompicture_selectCat']),
240          'blockHeight' => $this->config['amm_randompicture_height'],
241          'blockTitles' => array()
242        ),
243      'selectedLang' => $user['language'],
244      'fromLang' => substr($user['language'],0,2),
245      'langs' => array()
246    );
247
248    $lang=get_languages();
249    foreach($lang as $key => $val)
250    {
251      $datas['langs'][$key] = $val;
252      $datas['config']['blockTitles'][$key] = isset($this->config['amm_randompicture_title'][$key])?base64_decode($this->config['amm_randompicture_title'][$key]):'';
253    }
254
255    $template->assign("datas", $datas);
256
257    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
258    $template->assign('pageNfo', l10n('g002_randompict_nfo'));
259  }
260
261  /**
262   * display the personnal blocks management page
263   */
264  private function displayPersonalisedBlockPage()
265  {
266    global $template, $user;
267
268    GPCCore::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
269    GPCCore::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
270    GPCCore::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
271    GPCCore::addHeaderJS('jquery.ui.position', 'themes/default/js/ui/jquery.ui.position.js', array('jquery.ui.widget'));
272    GPCCore::addHeaderJS('jquery.ui.sortable', 'themes/default/js/ui/jquery.ui.sortable.js', array('jquery.ui.widget'));
273    GPCCore::addHeaderJS('jquery.ui.dialog', 'themes/default/js/ui/jquery.ui.dialog.js', array('jquery.ui.widget'));
274    GPCCore::addUI('inputList,inputText,inputRadio');
275    GPCCore::addHeaderJS('amm.upbm', 'plugins/AMenuManager/js/amm_personalisedBlocks.js', array('jquery', 'gpc.inputList', 'gpc.inputText', 'gpc.inputRadio'));
276
277
278    $template->set_filename('body_page',
279                            dirname($this->getFileLocation()).'/admin/amm_personalised.tpl');
280
281    $datas=array(
282      'selectedLang' => $user['language'],
283      'fromLang' => substr($user['language'],0,2),
284      'langs' => get_languages()
285    );
286
287    $template->assign("datas", $datas);
288
289    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
290    $template->assign('pageNfo', l10n('g002_personnalblock_nfo'));
291  }
292
293  /**
294   * display the core blocks menu management page
295   */
296  private function displayBlocksPage($tab)
297  {
298    global $template, $conf;
299
300    GPCCore::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
301    GPCCore::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery'));
302    GPCCore::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
303    GPCCore::addHeaderJS('jquery.ui.position', 'themes/default/js/ui/jquery.ui.position.js', array('jquery.ui.widget'));
304    GPCCore::addHeaderJS('jquery.ui.sortable', 'themes/default/js/ui/jquery.ui.sortable.js', array('jquery.ui.widget'));
305    GPCCore::addUI('inputList');
306    GPCCore::addHeaderJS('amm.cbm', 'plugins/AMenuManager/js/amm_blocks.js', array('jquery', 'jquery.ui.sortable', 'gpc.inputList'));
307
308    $template->set_filename('body_page',
309                            dirname($this->getFileLocation()).'/admin/amm_coreBlocks.tpl');
310
311    $blocksTabsheet = new GPCTabSheet('blocksTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder2', 'itab2');
312    $blocksTabsheet->add('position',
313                          l10n('g002_setting_blocks_position'),
314                          '', false, "cbm.displayTabContent('position');");
315    $blocksTabsheet->add('config',
316                          l10n('g002_setting_core_blocks_content'),
317                          '', false, "cbm.displayTabContent('blocksContent');");
318    $blocksTabsheet->select($tab);
319    $blocksTabsheet->assign();
320
321
322    $users=new GPCUsers();
323    $groups=new GPCGroups();
324
325    $this->sortCoreBlocksItems();
326
327    foreach($this->config['amm_blocks_items'] as $menuId=>$menu)
328    {
329      $this->config['amm_blocks_items'][$menuId]['visibilityForm'] = $this->makeBlockVisibility($menu['visibility'], $menuId);
330      $this->config['amm_blocks_items'][$menuId]['translation']=$this->defaultMenus[$menuId]['translation'];
331      $this->defaultMenus[$menuId]['visibilityForm'] = $this->makeBlockVisibility("/", $menuId);
332    }
333
334    $registeredBlocks=$this->getRegisteredBlocks();
335    foreach($registeredBlocks as $key=>$val)
336    {
337      $registeredBlocks[$key]['users']=json_encode($registeredBlocks[$key]['users']);
338      $registeredBlocks[$key]['groups']=json_encode($registeredBlocks[$key]['groups']);
339    }
340
341    $datas=array(
342      'tab' => $tab,
343      'users' => $users->getList(),
344      'groups' => $groups->getList(),
345      'coreBlocks' => array(
346            'blocks' => $this->blocksId,
347            'defaultValues' => $this->defaultMenus,
348            'items' => $this->config['amm_blocks_items']
349          ),
350      'menuBlocks' => $registeredBlocks
351    );
352
353    $template->assign("datas", $datas);
354
355    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
356    $template->assign('pageNfo', l10n('g002_setmenu_nfo'));
357  }
358
359
360
361  /**
362   * display the album to menu management page
363   */
364  private function displayAlbumPage()
365  {
366    global $template, $user;
367
368    GPCCore::addUI('categorySelector');
369    GPCCore::addHeaderJS('amm.ac', 'plugins/AMenuManager/js/amm_albumConfig.js', array('jquery','gpc.categorySelector'));
370
371    $template->set_filename('body_page',
372                            dirname($this->getFileLocation()).'/admin/amm_album.tpl');
373
374    $datas=array(
375      'albums' => json_encode($this->config['amm_albums_to_menu'])
376    );
377
378    $template->assign("datas", $datas);
379
380    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
381    $template->assign('pageNfo', l10n('g002_album_nfo'));
382  }
383
384
385  /*
386   *  ---------------------------------------------------------------------------
387   * links functionnalities
388   * ---------------------------------------------------------------------------
389   */
390
391  /**
392   * display the links management page
393   */
394  private function displayLinksPageLinks()
395  {
396    global $template, $user;
397
398    GPCCore::addUI('inputList,inputRadio,inputText,inputCheckbox');
399    GPCCore::addHeaderJS('amm.ulm', 'plugins/AMenuManager/js/amm_links.js', array('jquery', 'gpc.inputList', 'gpc.inputText', 'gpc.inputRadio', 'gpc.inputCheckbox'));
400
401    $template->set_filename('sheet_page',
402                            dirname($this->getFileLocation()).'/admin/amm_linkslinks.tpl');
403
404    $users=new GPCUsers();
405    $groups=new GPCGroups();
406
407    $datas=array(
408      'access' => array('users' => $users->getList(), 'groups' => $groups->getList()),
409      'iconsValues' => array(),
410      'modesValues' => array(
411        array(
412          'value' => 0,
413          'label' => l10n("g002_mode_".$this->urlsModes[0])
414        ),
415        array(
416          'value' => 1,
417          'label' => l10n("g002_mode_".$this->urlsModes[1])
418        )
419      )
420    );
421
422    $directory=dir(dirname($this->getFileLocation()).'/links_pictures/');
423    while($file=$directory->read())
424    {
425      if(in_array(get_extension(strtolower($file)), array('jpg', 'jpeg','gif','png')))
426      {
427        $datas['iconsValues'][] = array(
428          'img' => AMM_PATH."links_pictures/".$file,
429          'value' => $file,
430          'label' => $file
431        );
432      }
433    }
434
435    $template->assign("datas", $datas);
436
437    return($template->parse('sheet_page', true));
438  }
439
440  /**
441   * display the links config page
442   */
443  private function displayLinksPageConfig()
444  {
445    global $template, $user;
446
447    GPCCore::addUI('inputList,inputRadio,inputText');
448    GPCCore::addHeaderJS('amm.ulc', 'plugins/AMenuManager/js/amm_linksConfig.js', array('jquery', 'gpc.inputList', 'gpc.inputText', 'gpc.inputRadio'));
449
450    $template->set_filename('sheet_page',
451                            dirname($this->getFileLocation()).'/admin/amm_linksconfig.tpl');
452
453    $datas=array(
454      'config' => array(
455          'showIcons' => $this->config['amm_links_show_icons'],
456          'titles' => array()
457        ),
458      'selectedLang' => $user['language'],
459      'fromLang' => substr($user['language'],0,2),
460      'langs' => array()
461    );
462
463    $lang=get_languages();
464    foreach($lang as $key => $val)
465    {
466      $datas['langs'][$key] = $val;
467      $datas['config']['titles'][$key] = isset($this->config['amm_links_title'][$key])?base64_decode($this->config['amm_links_title'][$key]):'';
468    }
469
470    $template->assign("datas", $datas);
471    return($template->parse('sheet_page', true));
472  }
473
474
475
476  /*
477   * ---------------------------------------------------------------------------
478   * blocks functionnalities
479   * ---------------------------------------------------------------------------
480   */
481
482  /**
483   * this function returns an HTML FORM to use with each menu items
484   *
485   * @param String $visibility : a formatted string like :
486   *                              users type1(,users typeX)/(groupId0)(,groupIdX)
487   * @param String $blockId    : block Id
488   * @return String : html ready to use
489  */
490  private function makeBlockVisibility($visibility, $menuId)
491  {
492    $local_tpl = new Template(AMM_PATH."admin/", "");
493    $local_tpl->set_filename('body_page',
494                  dirname($this->getFileLocation()).'/admin/amm_coreBlocks_detail.tpl');
495
496
497    $parameters=explode("/", $visibility);
498
499    /* submenu access system is :
500     *  - by default, everything is accesible
501     *  - items not accessible are defined
502     */
503    $users=new GPCUsers();
504    $users->setAlloweds(explode(',', $parameters[0]), false);
505    $groups=new GPCGroups();
506    $groups->setAlloweds(explode(',', $parameters[1]), false);
507
508    $local_tpl->assign('name', $menuId);
509    $local_tpl->assign('users', $users->getList());
510    $local_tpl->assign('groups', $groups->getList());
511
512    return($local_tpl->parse('body_page', true));
513  }
514
515
516} // AMM_AIP class
517
518?>
Note: See TracBrowser for help on using the repository browser.