source: extensions/AMenuManager/amm_pip.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: 7.9 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : Advanced Menu Manager
4  Author     : Grum
5    email    : grum@piwigo.org
6    website  : http://photos.grum.fr
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  PIP classe => manage integration in public interface
14
15  --------------------------------------------------------------------------- */
16if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }
17
18include_once(PHPWG_PLUGINS_PATH.'AMenuManager/amm_root.class.inc.php');
19include_once(PHPWG_PLUGINS_PATH.'grum_plugins_classes-2/ajax.class.inc.php');
20
21class AMM_PIP extends AMM_root
22{
23  protected $ajax;
24  protected $displayRandomImageBlock=true;
25
26  function AMM_PIP($prefixeTable, $filelocation)
27  {
28    parent::__construct($prefixeTable, $filelocation);
29    $this->ajax = new Ajax();
30    $this->css = new css(dirname($this->filelocation).'/'.$this->plugin_name_files."2.css");
31
32    $this->load_config();
33    $this->init_events();
34  }
35
36
37  /* ---------------------------------------------------------------------------
38  Public classe functions
39  --------------------------------------------------------------------------- */
40
41
42  /*
43    initialize events call for the plugin
44  */
45  public function init_events()
46  {
47    //TODELETE: add_event_handler('loc_begin_menubar', array(&$this, 'modify_menu') );
48    parent::init_events();
49    add_event_handler('loading_lang', array(&$this, 'load_lang'));
50    add_event_handler('blockmanager_apply', array(&$this, 'blockmanager_apply') );
51    add_event_handler('loc_end_page_header', array(&$this->css, 'apply_CSS'));
52    add_event_handler('loc_end_page_tail', array(&$this, 'applyJS'));
53  }
54
55  /*
56    load language file
57  */
58  public function load_lang()
59  {
60    global $lang;
61
62    //load_language('plugin.lang', AMM_PATH);
63
64    // ajax is managed here ; this permit to use user&language properties inside
65    // ajax content
66    $this->return_ajax_content();
67  }
68
69  public function blockmanager_apply( $menu_ref_arr )
70  {
71    global $user, $page;
72    $menu = & $menu_ref_arr[0];
73
74
75    /*
76      Add a new random picture section
77    */
78    if ( ( ($block = $menu->get_block( 'mbAMM_randompict' ) ) != null ) && ($user['nb_total_images'] > 0) )
79    {
80      $block->set_title(  base64_decode($this->my_config['amm_randompicture_title'][$user['language']]) );
81      $block->data = array(
82        "delay" => $this->my_config['amm_randompicture_periodicchange'],
83        "blockHeight" => $this->my_config['amm_randompicture_height'],
84        "firstPicture" => $this->ajax_amm_get_random_picture()
85      );
86      $block->template = dirname(__FILE__).'/menu_templates/menubar_randompic.tpl';
87    }
88    else
89    {
90      $this->displayRandomImageBlock=false;
91    }
92
93    /*
94      Add a new section (links)
95    */
96    if ( ($block = $menu->get_block( 'mbAMM_links' ) ) != null )
97    {
98      $urls=$this->get_urls(true);
99      if ( count($urls)>0 )
100      {
101        if($this->my_config['amm_links_show_icons']=='y')
102        {
103          for($i=0;$i<count($urls);$i++)
104          {
105            $urls[$i]['icon']=get_root_url().'plugins/'.AMM_DIR."/links_pictures/".$urls[$i]['icon'];
106          }
107        }
108
109        $block->set_title( base64_decode($this->my_config['amm_links_title'][$user['language']]) );
110        $block->template = dirname(__FILE__).'/menu_templates/menubar_links.tpl';
111
112        $block->data = array(
113          'LINKS' => $urls,
114          'icons' => $this->my_config['amm_links_show_icons']
115        );
116      }
117    }
118
119    /*
120      Add personnal blocks random picture section
121    */
122    $sections=$this->get_sections(true);
123
124    if(count($sections))
125    {
126      $id_done=array();
127      foreach($sections as $key => $val)
128      {
129        if(!isset($id_done[$val['id']]))
130        {
131          if ( ($block = $menu->get_block( 'mbAMM_personalised'.$val['id'] ) ) != null )
132          {
133            $block->set_title( $val['title'] );
134            $block->template = dirname(__FILE__).'/menu_templates/menubar_personalised.tpl';
135            $block->data = stripslashes($val['content']);
136          }
137          $id_done[$val['id']]="";
138        }
139      }
140    }
141
142
143    /*
144      hide items from special & menu sections
145    */
146    $blocks=Array();
147    $blocks['menu']=$menu->get_block('mbMenu');
148    $blocks['special']=$menu->get_block('mbSpecials');
149
150    $menuItems=array_merge($blocks['menu']->data, $blocks['special']->data);
151    $this->sortSectionsItems();
152
153    $blocks['menu']->data=Array();
154    $blocks['special']->data=Array();
155
156    foreach($this->my_config['amm_sections_items'] as $key => $val)
157    {
158      if(isset($menuItems[$key]))
159      {
160        $blocks[$val['container']]->data[$key]=$menuItems[$key];
161      }
162    }
163    if(count($blocks['menu']->data)==0) $menu->hide_block('mbMenu');
164    if(count($blocks['special']->data)==0) $menu->hide_block('mbSpecials');
165  }
166
167  /*
168    return ajax content
169  */
170  protected function return_ajax_content()
171  {
172    global $ajax, $template;
173
174    if(isset($_REQUEST['ajaxfct']))
175    {
176      if($_REQUEST['ajaxfct']=='randompic')
177      {
178        $result="<p class='errors'>".l10n('g002_error_invalid_ajax_call')."</p>";
179        switch($_REQUEST['ajaxfct'])
180        {
181          case 'randompic':
182            $result=$this->ajax_amm_get_random_picture();
183            break;
184        }
185        $this->ajax->return_result($result);
186      }
187    }
188  }
189
190
191  // return the html content for the random picture block
192  private function ajax_amm_get_random_picture()
193  {
194    global $user;
195
196    $local_tpl = new Template(AMM_PATH."menu_templates/", "");
197    $local_tpl->set_filename('body_page',
198                  dirname($this->filelocation).'/menu_templates/menubar_randompic_inner.tpl');
199
200      $sql="SELECT i.id as image_id, i.file as image_file, i.comment, i.path, i.tn_ext, c.id as catid, c.name, c.permalink, RAND() as rndvalue, i.name as imgname
201            FROM ".CATEGORIES_TABLE." c, ".IMAGES_TABLE." i, ".IMAGE_CATEGORY_TABLE." ic
202            WHERE c.id = ic.category_id
203              AND ic.image_id = i.id
204              AND i.level <= ".$user['level']." ";
205      if($user['forbidden_categories']!="")
206      {
207        $sql.=" AND c.id NOT IN (".$user['forbidden_categories'].") ";
208      }
209
210      $sql.=" ORDER BY rndvalue
211            LIMIT 0,1";
212
213
214      $result = pwg_query($sql);
215      if($result and $nfo = mysql_fetch_array($result))
216      {
217        $nfo['section']='category';
218        $nfo['category']=array(
219          'id' => $nfo['catid'],
220          'name' => $nfo['name'],
221          'permalink' => $nfo['permalink']
222        );
223
224        $template_datas = array(
225          'LINK' => make_picture_url($nfo),
226          'IMG' => get_thumbnail_url($nfo),
227          'IMGNAME' => $nfo['imgname'],
228          'IMGCOMMENT' => $nfo['comment'],
229          'SHOWNAME' => $this->my_config['amm_randompicture_showname'],
230          'SHOWCOMMENT' => $this->my_config['amm_randompicture_showcomment']
231        );
232      }
233      else
234      {
235        $template_datas = array();
236      }
237
238    $local_tpl->assign('datas', $template_datas);
239    $local_tpl->assign('plugin', array('PATH' => AMM_PATH));
240
241    return($local_tpl->parse('body_page', true));
242  }
243
244
245  public function applyJS()
246  {
247    global $user, $template;
248
249    if($this->displayRandomImageBlock)
250    {
251      $local_tpl = new Template(AMM_PATH."admin/", "");
252      $local_tpl->set_filename('body_page', dirname($this->filelocation).'/menu_templates/menubar_randompic.js.tpl');
253
254      $data = array(
255        "delay" => $this->my_config['amm_randompicture_periodicchange'],
256        "blockHeight" => $this->my_config['amm_randompicture_height'],
257        "firstPicture" => $this->ajax_amm_get_random_picture()
258      );
259
260      $local_tpl->assign('data', $data);
261
262      $template->append('footer_elements', $local_tpl->parse('body_page', true));
263    }
264
265  }
266
267} // AMM_PIP class
268
269
270?>
Note: See TracBrowser for help on using the repository browser.