source: extensions/AMenuManager/amm_pip.class.inc.php @ 4363

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

[AMM] moving the JS for the "random image" outside the <DL> tag

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