source: extensions/AMenuManager/amm_pip.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: 6.8 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  }
52
53  /*
54    load language file
55  */
56  public function load_lang()
57  {
58    global $lang;
59
60    //load_language('plugin.lang', AMM_PATH);
61
62    // ajax is managed here ; this permit to use user&language properties inside
63    // ajax content
64    $this->return_ajax_content();
65  }
66
67  public function blockmanager_apply( $menu_ref_arr )
68  {
69    global $user;
70    $menu = & $menu_ref_arr[0];
71
72global $page;
73
74    /*
75      Add a new random picture section
76    */
77    if ( ( ($block = $menu->get_block( 'mbAMM_randompict' ) ) != null ) && ($user['nb_total_images'] > 0) )
78    {
79      $block->set_title(  base64_decode($this->my_config['amm_randompicture_title'][$user['language']]) );
80      $block->data = array(
81        "delay" => $this->my_config['amm_randompicture_periodicchange'],
82        "blockHeight" => $this->my_config['amm_randompicture_height'],
83        "firstPicture" => $this->ajax_amm_get_random_picture()
84      );
85      $block->template = dirname(__FILE__).'/menu_templates/menubar_randompic.tpl';
86    }
87
88    /*
89      Add a new section (links)
90    */
91    if ( ($block = $menu->get_block( 'mbAMM_links' ) ) != null )
92    {
93      $urls=$this->get_urls(true);
94      if ( count($urls)>0 )
95      {
96        if($this->my_config['amm_links_show_icons']=='y')
97        {
98          for($i=0;$i<count($urls);$i++)
99          {
100            $urls[$i]['icon']=get_root_url().'plugins/'.AMM_DIR."/links_pictures/".$urls[$i]['icon'];
101          }
102        }
103
104        $block->set_title( base64_decode($this->my_config['amm_links_title'][$user['language']]) );
105        $block->template = dirname(__FILE__).'/menu_templates/menubar_links.tpl';
106
107        $block->data = array(
108          'LINKS' => $urls,
109          'icons' => $this->my_config['amm_links_show_icons']
110        );
111      }
112    }
113
114    /*
115      Add personnal blocks random picture section
116    */
117    $sections=$this->get_sections(true);
118
119    if(count($sections))
120    {
121      $id_done=array();
122      foreach($sections as $key => $val)
123      {
124        if(!isset($id_done[$val['id']]))
125        {
126          if ( ($block = $menu->get_block( 'mbAMM_personalised'.$val['id'] ) ) != null )
127          {
128            $block->set_title( $val['title'] );
129            $block->template = dirname(__FILE__).'/menu_templates/menubar_personalised.tpl';
130            $block->data = stripslashes($val['content']);
131          }
132          $id_done[$val['id']]="";
133        }
134      }
135    }
136
137    /*
138      hide items from special & menu sections
139    */
140    foreach(array('mbMenu' => 'amm_sections_modmenu', 'mbSpecials' =>'amm_sections_modspecials') as $key0 => $val0)
141    {
142      if ( ($block = $menu->get_block( $key0 ) ) != null )
143      {
144        foreach($this->my_config[$val0] as $key => $val)
145        {
146          if($val=='n')
147          {
148            unset( $block->data[$key] );
149          }
150        }
151      }
152    }
153}
154
155  /*
156    return ajax content
157  */
158  protected function return_ajax_content()
159  {
160    global $ajax, $template;
161
162    if(isset($_REQUEST['ajaxfct']))
163    {
164      if($_REQUEST['ajaxfct']=='randompic')
165      {
166        $result="<p class='errors'>".l10n('g002_error_invalid_ajax_call')."</p>";
167        switch($_REQUEST['ajaxfct'])
168        {
169          case 'randompic':
170            $result=$this->ajax_amm_get_random_picture();
171            break;
172        }
173        $this->ajax->return_result($result);
174      }
175    }
176  }
177
178
179  // return the html content for the random picture block
180  private function ajax_amm_get_random_picture()
181  {
182    global $user;
183
184    $local_tpl = new Template(AMM_PATH."menu_templates/", "");
185    $local_tpl->set_filename('body_page',
186                  dirname($this->filelocation).'/menu_templates/menubar_randompic_inner.tpl');
187
188      $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
189            FROM ".CATEGORIES_TABLE." c, ".IMAGES_TABLE." i, ".IMAGE_CATEGORY_TABLE." ic
190            WHERE c.id = ic.category_id
191              AND ic.image_id = i.id
192              AND i.level <= ".$user['level']." ";
193      if($user['forbidden_categories']!="")
194      {
195        $sql.=" AND c.id NOT IN (".$user['forbidden_categories'].") ";
196      }
197
198      $sql.=" ORDER BY rndvalue
199            LIMIT 0,1";
200
201
202      $result = pwg_query($sql);
203      if($result and $nfo = mysql_fetch_array($result))
204      {
205        $nfo['section']='category';
206        $nfo['category']=array(
207          'id' => $nfo['catid'],
208          'name' => $nfo['name'],
209          'permalink' => $nfo['permalink']
210        );
211
212        $template_datas = array(
213          'LINK' => make_picture_url($nfo),
214          'IMG' => get_thumbnail_url($nfo),
215          'IMGNAME' => $nfo['imgname'],
216          'IMGCOMMENT' => $nfo['comment'],
217          'SHOWNAME' => $this->my_config['amm_randompicture_showname'],
218          'SHOWCOMMENT' => $this->my_config['amm_randompicture_showcomment']
219        );
220      }
221      else
222      {
223        $template_datas = array();
224      }
225
226    $local_tpl->assign('datas', $template_datas);
227    $local_tpl->assign('plugin', array('PATH' => AMM_PATH));
228
229    return($local_tpl->parse('body_page', true));
230  }
231
232} // AMM_PIP class
233
234
235?>
Note: See TracBrowser for help on using the repository browser.