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

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

feature:2642- compatibility with Piwigo 2.4

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