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

Last change on this file since 3690 was 3690, checked in by grum, 15 years ago

Update AMM 2.1.1 - bug resolved + improvement
See main.inc.php file for details

  • Property svn:executable set to *
File size: 5.3 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : Advanced Menu Manager
4  Author     : Grum
5    email    : grum@grum.fr
6    website  : http://photos.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 classe 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
22class AMM_root extends common_plugin
23{
24  protected $css;   //the css object
25
26  function AMM_root($prefixeTable, $filelocation)
27  {
28    $this->plugin_name="Advanced Menu Manager";
29    $this->plugin_name_files="amm";
30    parent::__construct($prefixeTable, $filelocation);
31
32    $list=array('urls', 'personalised');
33    $this->set_tables_list($list);
34  }
35
36  /* ---------------------------------------------------------------------------
37  common AIP & PIP functions
38  --------------------------------------------------------------------------- */
39
40  /* this function initialize var $my_config with default values */
41  public function init_config()
42  {
43    $this->my_config=array(
44      'amm_links_show_icons' => 'y',
45      'amm_links_title' => array(),
46      'amm_randompicture_showname' => 'n',     //n:no, o:over, u:under
47      'amm_randompicture_showcomment' => 'n',   //n:no, o:over, u:under
48      'amm_randompicture_periodicchange' => 0,   //0: no periodic change ; periodic change in milliseconds
49      'amm_randompicture_height' => 0,           //0: automatic, otherwise it's the fixed height in pixels
50      'amm_randompicture_title' => array(),
51      'amm_sections_modspecials' => array(
52        'favorites' => 'y',
53        'most_visited' => 'y',
54        'best_rated' => 'y',
55        'random' => 'y',
56        'recent_pics' => 'y',
57        'recent_cats' => 'y',
58        'calendar' => 'y'
59      ),
60      'amm_sections_modmenu' => array(
61        'qsearch' => 'y',
62        'tags' => 'y',
63        'search' => 'y',
64        'comments' => 'y',
65        'about' => 'y',
66        'rss' => 'y'
67      )
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
194} // amm_root  class
195
196
197?>
Note: See TracBrowser for help on using the repository browser.