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

Last change on this file since 11475 was 10255, checked in by grum, 13 years ago

bug:2144
Compatibility with Piwigo 2.2 (fix css problem + GPC 3.5 needed)

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