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

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

<html><head><meta name="qrichtext" content="1" /></head><body style="font-size:9pt;font-family:Sans Serif">
<p>[AMM] allow to group and reorder menu items (mantis 1132,1133)</p>
</body></html>

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