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

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

feature:2642- compatibility with Piwigo 2.4

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