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

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

bug:2695 fixed

  • Property svn:executable set to *
File size: 18.0 KB
RevLine 
[3681]1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : Advanced Menu Manager
4  Author     : Grum
[8962]5    email    : grum@piwigo.org
[16445]6    website  : http://www.grum.fr
[3681]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');
[4382]18include_once(PHPWG_ROOT_PATH.'include/block.class.php');
[3681]19include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
[8962]20include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCTabSheet.class.inc.php');
[3681]21
[8962]22
[3681]23class AMM_AIP extends AMM_root
24{
25  protected $tabsheet;
[8962]26  protected $blocksId=array('menu' => 'Menu', 'special' => 'Specials');
[3681]27
28
[8962]29  public function __construct($prefixeTable, $filelocation)
[3681]30  {
31    parent::__construct($prefixeTable, $filelocation);
32
[5545]33    $this->loadConfig();
34    $this->initEvents();
[3681]35
36    $this->tabsheet = new tabsheet();
37    $this->tabsheet->add('setmenu',
38                          l10n('g002_setmenu'),
[15366]39                          $this->getAdminLink().'-setmenu');
[3681]40    $this->tabsheet->add('links',
41                          l10n('g002_addlinks'),
[15366]42                          $this->getAdminLink().'-links');
[3681]43    $this->tabsheet->add('randompict',
44                          l10n('g002_randompict'),
[15366]45                          $this->getAdminLink().'-randompict');
[3681]46    $this->tabsheet->add('personnalblock',
47                          l10n('g002_personnalblock'),
[15366]48                          $this->getAdminLink().'-personnalblock');
[8962]49    $this->tabsheet->add('album',
50                          l10n('g002_album'),
[15366]51                          $this->getAdminLink().'-album');
[3681]52  }
53
54
[8962]55  /**
56   * manage plugin integration into piwigo's admin interface
57   */
[3681]58  public function manage()
59  {
[4382]60    global $template, $page;
[3681]61
62    $template->set_filename('plugin_admin_content', dirname(__FILE__)."/admin/amm_admin.tpl");
63
[8962]64    $this->initRequest();
[3681]65
[15366]66    $this->tabsheet->select($_GET['tab']);
[3681]67    $this->tabsheet->assign();
68    $selected_tab=$this->tabsheet->get_selected();
69    $template->assign($this->tabsheet->get_titlename(), "[".$selected_tab['caption']."]");
70
[5545]71    $template_plugin["AMM_VERSION"] = "<i>".$this->getPluginName()."</i> ".l10n('g002_version').AMM_VERSION;
[15366]72    $template_plugin["AMM_PAGE"] = $_GET['tab'];
[3681]73    $template_plugin["PATH"] = AMM_PATH;
74
75    $template->assign('plugin', $template_plugin);
[16006]76    GPCCore::setTemplateToken();
[3681]77
[15366]78    switch($_GET['tab'])
[3681]79    {
[8962]80      case 'links':
[15366]81        $this->displayLinksPage($_REQUEST['t']);
[8962]82        break;
[3681]83
[8962]84      case 'randompict':
85        $this->displayRandompicPage();
86        break;
[3681]87
[8962]88      case 'personnalblock':
89        $this->displayPersonalisedBlockPage();
90        break;
[3681]91
[8962]92      case 'setmenu':
[15366]93        $this->displayBlocksPage($_REQUEST['t']);
[8962]94        break;
95
96      case 'album':
97        $this->displayAlbumPage();
98        break;
[3681]99    }
100
101    $template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
[8962]102  }
[3681]103
[5545]104  public function initEvents()
[3681]105  {
[16006]106    parent::initEvents();
107    add_event_handler('blockmanager_register_blocks', array(&$this, 'registerBlocks') );
[3681]108  }
109
110
[16006]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
[8962]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()
[3681]128  {
[8962]129    //initialise $REQUEST values if not defined
[15366]130    if(!array_key_exists('tab', $_GET)) $_GET['tab']='setmenu';
[3681]131
[15366]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'
[8962]141        )
[15366]142      ) $_GET['tab']='setmenu';
[3681]143
144
[8962]145    /*
146     * checks for links page
147     */
[15366]148    if($_GET['tab']=='links')
[8962]149    {
[15366]150      if(!isset($_REQUEST['t'])) $_REQUEST['t']='links';
[3681]151
[15366]152      if(!($_REQUEST['t']=='links' or
153           $_REQUEST['t']=='config'
[8962]154          )
[15366]155        ) $_REQUEST['t']='config';
[3681]156    }
157
[8962]158
159    /*
160     * checks for blocks menu page
161     */
[15366]162    if($_GET['tab']=='setmenu')
[3681]163    {
[15366]164      if(!isset($_REQUEST['t'])) $_REQUEST['t']='position';
[3681]165
[15366]166      if(!($_REQUEST['t']=='position' or
167           $_REQUEST['t']=='blocksContent'
[8962]168          )
[15366]169        ) $_REQUEST['t']='position';
[3681]170    }
171
[8962]172  } //initRequest
[3681]173
174
[8962]175  /**
176   * display the links management page
177   */
178  private function displayLinksPage($tab)
179  {
180    global $template, $user;
[3681]181
[15366]182    GPCCore::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
[16737]183    GPCCore::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
[15366]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'));
[3681]188
189    $template->set_filename('body_page',
[8962]190                            dirname($this->getFileLocation()).'/admin/amm_links.tpl');
[3681]191
[10255]192    $linksTabsheet = new GPCTabSheet('linksTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder2', 'itab2');
[8962]193    $linksTabsheet->select($tab);
194    $linksTabsheet->add('links',
195                          l10n('g002_setting_link_links'),
[15366]196                          $this->getAdminLink().'-links/links');
[8962]197    $linksTabsheet->add('config',
198                          l10n('g002_configlinks'),
[15366]199                          $this->getAdminLink().'-links/config');
[8962]200    $linksTabsheet->assign();
201
202    switch($tab)
[3681]203    {
[8962]204      case 'links':
205        $template->assign('sheetContent', $this->displayLinksPageLinks());
206        break;
207      case 'config':
208        $template->assign('sheetContent', $this->displayLinksPageConfig());
209        break;
[3681]210    }
211
212    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
[8962]213    $template->assign('pageNfo', l10n('g002_addlinks_nfo'));
[3681]214  }
215
[8962]216  /**
217   * display the randompict management page
218   */
219  private function displayRandompicPage()
[3681]220  {
221    global $template, $user;
[8962]222
[15366]223    GPCCore::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
[16737]224    GPCCore::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
225    GPCCore::addHeaderJS('jquery.ui.mouse', 'themes/default/js/ui/jquery.ui.mouse.js', array('jquery.ui.widget'));
226    GPCCore::addHeaderJS('jquery.ui.position', 'themes/default/js/ui/jquery.ui.position.js', array('jquery.ui.widget'));
[15366]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'));
[8962]232
[3681]233    $template->set_filename('body_page',
[8962]234                            dirname($this->getFileLocation()).'/admin/amm_randompicconfig.tpl');
[3681]235
[8962]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']),
[10247]243          'blockHeight' => $this->config['amm_randompicture_height'],
[8962]244          'blockTitles' => array()
245        ),
246      'selectedLang' => $user['language'],
247      'fromLang' => substr($user['language'],0,2),
248      'langs' => array()
[3681]249    );
250
251    $lang=get_languages();
252    foreach($lang as $key => $val)
253    {
[8962]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]):'';
[3681]256    }
257
[8962]258    $template->assign("datas", $datas);
[3681]259
260    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
[8962]261    $template->assign('pageNfo', l10n('g002_randompict_nfo'));
[3681]262  }
263
[8962]264  /**
265   * display the personnal blocks management page
266   */
267  private function displayPersonalisedBlockPage()
[3681]268  {
269    global $template, $user;
270
[15366]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'));
[3681]279
280
[8962]281    $template->set_filename('body_page',
282                            dirname($this->getFileLocation()).'/admin/amm_personalised.tpl');
[3681]283
[8962]284    $datas=array(
285      'selectedLang' => $user['language'],
286      'fromLang' => substr($user['language'],0,2),
287      'langs' => get_languages()
288    );
[3681]289
[8962]290    $template->assign("datas", $datas);
[3681]291
292    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
[8962]293    $template->assign('pageNfo', l10n('g002_personnalblock_nfo'));
[3681]294  }
295
[8962]296  /**
297   * display the core blocks menu management page
298   */
299  private function displayBlocksPage($tab)
[3681]300  {
[8962]301    global $template, $conf;
[3681]302
[15366]303    GPCCore::addHeaderJS('jquery.ui', 'themes/default/js/ui/jquery.ui.core.js', array('jquery'));
[16737]304    GPCCore::addHeaderJS('jquery.ui.widget', 'themes/default/js/ui/jquery.ui.widget.js', array('jquery.ui'));
[15366]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'));
[8962]308    GPCCore::addUI('inputList');
[15366]309    GPCCore::addHeaderJS('amm.cbm', 'plugins/AMenuManager/js/amm_blocks.js', array('jquery', 'jquery.ui.sortable', 'gpc.inputList'));
[3681]310
[8962]311    $template->set_filename('body_page',
312                            dirname($this->getFileLocation()).'/admin/amm_coreBlocks.tpl');
[3681]313
[10255]314    $blocksTabsheet = new GPCTabSheet('blocksTabsheet', $this->tabsheet->get_titlename(), 'tabsheet2 gcBorder2', 'itab2');
[8962]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();
[3681]323
324
[8962]325    $users=new GPCUsers();
326    $groups=new GPCGroups();
[3681]327
[16484]328    $registeredBlocks=$this->getRegisteredBlocks();
329    foreach($registeredBlocks as $key=>$val)
330    {
331      $registeredBlocks[$key]['users']=json_encode($registeredBlocks[$key]['users']);
332      $registeredBlocks[$key]['groups']=json_encode($registeredBlocks[$key]['groups']);
333    }
334
[16485]335    $this->sortCoreBlocksItems();
[16484]336
[8962]337    foreach($this->config['amm_blocks_items'] as $menuId=>$menu)
[3681]338    {
[8962]339      $this->config['amm_blocks_items'][$menuId]['visibilityForm'] = $this->makeBlockVisibility($menu['visibility'], $menuId);
340      $this->config['amm_blocks_items'][$menuId]['translation']=$this->defaultMenus[$menuId]['translation'];
341      $this->defaultMenus[$menuId]['visibilityForm'] = $this->makeBlockVisibility("/", $menuId);
[3681]342    }
343
[8962]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    );
[5421]355
[8962]356    $template->assign("datas", $datas);
[4389]357
[3681]358    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
[8962]359    $template->assign('pageNfo', l10n('g002_setmenu_nfo'));
[3681]360  }
361
362
[8962]363
364  /**
365   * display the album to menu management page
366   */
367  private function displayAlbumPage()
[3681]368  {
369    global $template, $user;
[8962]370
[15366]371    GPCCore::addUI('categorySelector');
372    GPCCore::addHeaderJS('amm.ac', 'plugins/AMenuManager/js/amm_albumConfig.js', array('jquery','gpc.categorySelector'));
[8962]373
[3681]374    $template->set_filename('body_page',
[8962]375                            dirname($this->getFileLocation()).'/admin/amm_album.tpl');
[3681]376
[8962]377    $datas=array(
378      'albums' => json_encode($this->config['amm_albums_to_menu'])
[3681]379    );
380
[8962]381    $template->assign("datas", $datas);
[3681]382
383    $template->assign_var_from_handle('AMM_BODY_PAGE', 'body_page');
[8962]384    $template->assign('pageNfo', l10n('g002_album_nfo'));
[3681]385  }
386
387
[8962]388  /*
389   *  ---------------------------------------------------------------------------
390   * links functionnalities
391   * ---------------------------------------------------------------------------
392   */
[3681]393
[8962]394  /**
395   * display the links management page
396   */
397  private function displayLinksPageLinks()
[3681]398  {
399    global $template, $user;
400
[8962]401    GPCCore::addUI('inputList,inputRadio,inputText,inputCheckbox');
[15366]402    GPCCore::addHeaderJS('amm.ulm', 'plugins/AMenuManager/js/amm_links.js', array('jquery', 'gpc.inputList', 'gpc.inputText', 'gpc.inputRadio', 'gpc.inputCheckbox'));
[3681]403
[8962]404    $template->set_filename('sheet_page',
405                            dirname($this->getFileLocation()).'/admin/amm_linkslinks.tpl');
[3681]406
[8962]407    $users=new GPCUsers();
408    $groups=new GPCGroups();
[3681]409
[8962]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      )
[3681]423    );
424
[8962]425    $directory=dir(dirname($this->getFileLocation()).'/links_pictures/');
426    while($file=$directory->read())
[3681]427    {
[8962]428      if(in_array(get_extension(strtolower($file)), array('jpg', 'jpeg','gif','png')))
[3681]429      {
[8962]430        $datas['iconsValues'][] = array(
431          'img' => AMM_PATH."links_pictures/".$file,
432          'value' => $file,
433          'label' => $file
[3681]434        );
435      }
436    }
437
[8962]438    $template->assign("datas", $datas);
[3681]439
[8962]440    return($template->parse('sheet_page', true));
[3681]441  }
442
[8962]443  /**
444   * display the links config page
445   */
446  private function displayLinksPageConfig()
[3681]447  {
[8962]448    global $template, $user;
[3681]449
[15366]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'));
[3681]452
[8962]453    $template->set_filename('sheet_page',
454                            dirname($this->getFileLocation()).'/admin/amm_linksconfig.tpl');
[3681]455
[8962]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    );
[3681]465
[8962]466    $lang=get_languages();
467    foreach($lang as $key => $val)
[3681]468    {
[8962]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]):'';
[3681]471    }
472
[8962]473    $template->assign("datas", $datas);
474    return($template->parse('sheet_page', true));
[3681]475  }
476
477
478
[8962]479  /*
480   * ---------------------------------------------------------------------------
481   * blocks functionnalities
482   * ---------------------------------------------------------------------------
483   */
[3681]484
[8962]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)
[3681]494  {
495    $local_tpl = new Template(AMM_PATH."admin/", "");
496    $local_tpl->set_filename('body_page',
[8962]497                  dirname($this->getFileLocation()).'/admin/amm_coreBlocks_detail.tpl');
[3681]498
499
[8962]500    $parameters=explode("/", $visibility);
[3681]501
[8962]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);
[3681]510
[8962]511    $local_tpl->assign('name', $menuId);
512    $local_tpl->assign('users', $users->getList());
513    $local_tpl->assign('groups', $groups->getList());
[3681]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.