source: extensions/AMenuManager/amm_root.class.inc.php @ 5545

Last change on this file since 5545 was 5545, checked in by grum, 14 years ago

Update the plugin for compatibility with Piwigo 2.1

  • Property svn:executable set to *
File size: 7.5 KB
RevLine 
[3681]1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : Advanced Menu Manager
4  Author     : Grum
5    email    : grum@grum.fr
[4382]6    website  : http://photos.grum.fr
[3681]7    PWG user : http://forum.piwigo.org/profile.php?id=3706
8
9    << May the Little SpaceFrog be with you ! >>
10  ------------------------------------------------------------------------------
11  See main.inc.php for release information
12
[4382]13  AMM_root : root class for plugin
[3681]14
15  --------------------------------------------------------------------------- */
16
17if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
18
[5545]19include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/CommonPlugin.class.inc.php');
20include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCUsersGroups.class.inc.php');
21include_once(PHPWG_PLUGINS_PATH.'GrumPluginClasses/classes/GPCCss.class.inc.php');
[3681]22
[4382]23
[5545]24class AMM_root extends CommonPlugin
[3681]25{
26  protected $css;   //the css object
[4382]27  protected $defaultMenus = array(
[5421]28    'favorites' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 0, 'translation' => 'My favorites'),
29    'most_visited' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 1, 'translation' => 'Most visited'),
30    'best_rated' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 2, 'translation' => 'Best rated'),
31    'random' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 3, 'translation' => 'Random pictures'),
32    'recent_pics' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 4, 'translation' => 'Recent pictures'),
33    'recent_cats' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 5, 'translation' => 'Recent categories'),
34    'calendar' => array('container' => 'special', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 6, 'translation' => 'Calendar'),
35    'qsearch' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 0, 'translation' => 'Quick search'),
[4395]36    'tags' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 1, 'translation' => 'Tags'),
37    'search' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 2, 'translation' => 'Search'),
[5421]38    'comments' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 3, 'translation' => 'Comments'),
[4395]39    'about' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 4, 'translation' => 'About'),
40    'rss' => array('container' => 'menu', 'visibility' => 'guest,generic,normal,webmaster,admin/', 'order' => 5, 'translation' => 'Notification')
[4382]41  );
[3681]42
[5545]43  public function __construct($prefixeTable, $filelocation)
[3681]44  {
[5545]45    $this->setPluginName("Advanced Menu Manager");
46    $this->setPluginNameFiles("amm");
[3681]47    parent::__construct($prefixeTable, $filelocation);
48
49    $list=array('urls', 'personalised');
[5545]50    $this->setTablesList($list);
[3681]51  }
52
[5545]53  public function __destruct()
54  {
55    unset($this->css);
56    unset($this->defaultMenus);
57    parent::__destruct();
58  }
59
[3681]60  /* ---------------------------------------------------------------------------
61  common AIP & PIP functions
62  --------------------------------------------------------------------------- */
63
64  /* this function initialize var $my_config with default values */
[5545]65  public function initConfig()
[3681]66  {
[5545]67    $this->config=array(
[3681]68      'amm_links_show_icons' => 'y',
69      'amm_links_title' => array(),
70      'amm_randompicture_showname' => 'n',     //n:no, o:over, u:under
71      'amm_randompicture_showcomment' => 'n',   //n:no, o:over, u:under
72      'amm_randompicture_periodicchange' => 0,   //0: no periodic change ; periodic change in milliseconds
[3690]73      'amm_randompicture_height' => 0,           //0: automatic, otherwise it's the fixed height in pixels
[3681]74      'amm_randompicture_title' => array(),
[4382]75      'amm_sections_items' => $this->defaultMenus
[3681]76    );
77
78    $languages=get_languages();
79    foreach($languages as $key => $val)
80    {
81      if($key=='fr_FR')
82      {
[5545]83        $this->config['amm_links_title'][$key]=base64_encode('Liens');
84        $this->config['amm_randompicture_title'][$key]=base64_encode('Une image au hasard');
[3681]85      }
86      else
87      {
[5545]88        $this->config['amm_links_title'][$key]=base64_encode('Links');
89        $this->config['amm_randompicture_title'][$key]=base64_encode('A random picture');
[3681]90      }
91    }
92  }
93
[5545]94  public function loadConfig()
[3681]95  {
[5545]96    parent::loadConfig();
[3681]97  }
98
[5545]99  public function initEvents()
[3681]100  {
101    add_event_handler('blockmanager_register_blocks', array(&$this, 'register_blocks') );
102  }
103
104  public function register_blocks( $menu_ref_arr )
105  {
106    $menu = & $menu_ref_arr[0];
107    if ($menu->get_id() != 'menubar')
108      return;
109    $menu->register_block( new RegisteredBlock( 'mbAMM_randompict', 'Random pictures', 'AMM'));
110    $menu->register_block( new RegisteredBlock( 'mbAMM_links', 'Links', 'AMM'));
111
112    $sections=$this->get_sections(true);
113    if(count($sections))
114    {
115      $id_done=array();
116      foreach($sections as $key => $val)
117      {
118        if(!isset($id_done[$val['id']]))
119        {
120          $menu->register_block( new RegisteredBlock( 'mbAMM_personalised'.$val['id'], $val['title'], 'AMM'));
121          $id_done[$val['id']]="";
122        }
123      }
124    }
125  }
126
127  // return an array of urls (each url is an array)
128  protected function get_urls($only_visible=false)
129  {
130    $returned=array();
131    $sql="SELECT * FROM ".$this->tables['urls'];
132    if($only_visible)
133    {
134      $sql.=" WHERE visible = 'y' ";
135    }
136    $sql.=" ORDER BY position";
137    $result=pwg_query($sql);
138    if($result)
139    {
[5426]140      while($row=pwg_db_fetch_assoc($result))
[3681]141      {
142        $row['label']=stripslashes($row['label']);
143        $returned[]=$row;
144      }
145    }
146    return($returned);
147  }
148
149  //return number of url
150  protected function get_count_url($only_visible=false)
151  {
152    $returned=0;
153    $sql="SELECT count(id) FROM ".$this->tables['urls'];
154    if($only_visible)
155    {
156      $sql.=" WHERE visible = 'y' ";
157    }
158    $result=pwg_query($sql);
159    if($result)
160    {
[5426]161      $tmp=pwg_db_fetch_row($result);
[3681]162      $returned=$tmp[0];
163    }
164    return($returned);
165  }
166
167  // return an array of sections (each section is an array)
168  protected function get_sections($only_visible=false, $lang="", $only_with_content=true)
169  {
170    global $user;
171
172    if($lang=="")
173    {
174      $lang=$user['language'];
175    }
176
177    $returned=array();
178    $sql="SELECT * FROM ".$this->tables['personalised']."
179WHERE (lang = '*' OR lang = '".$lang."') ";
180    if($only_visible)
181    {
182      $sql.=" AND visible = 'y' ";
183    }
184    if($only_with_content)
185    {
186      $sql.=" AND content != '' ";
187    }
188    $sql.=" ORDER BY id, lang DESC ";
189    $result=pwg_query($sql);
190    if($result)
191    {
[5426]192      while($row=pwg_db_fetch_assoc($result))
[3681]193      {
194        $returned[]=$row;
195      }
196    }
197    return($returned);
198  }
199
200
[4382]201  protected function sortSectionsItemsCompare($a, $b)
202  {
203    if($a['container']==$b['container'])
204    {
205      if($a['order']==$b['order']) return(0);
206      return(($a['order']<$b['order'])?-1:1);
207    }
208    else return(($a['container']<$b['container'])?-1:1);
209  }
[3681]210
[4382]211  protected function sortSectionsItems()
212  {
[5545]213    uasort($this->config['amm_sections_items'], array($this, "sortSectionsItemsCompare"));
[4382]214  }
215
[3681]216} // amm_root  class
217
218
[4382]219
[3681]220?>
Note: See TracBrowser for help on using the repository browser.