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

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

Add plugin Advanced Menu Manager 2.1.0

  • Property svn:executable set to *
File size: 6.4 KB
Line 
1<?php
2/* -----------------------------------------------------------------------------
3  Plugin     : Advanced Menu Manager
4  Author     : Grum
5    email    : grum@grum.dnsalias.com
6    website  : http://photos.grum.dnsalias.com
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 )
78    {
79      $block->set_title(  base64_decode($this->my_config['amm_randompicture_title'][$user['language']]) );
80      $block->data = array("delay" => $this->my_config['amm_randompicture_periodicchange']);
81      $block->template = dirname(__FILE__).'/menu_templates/menubar_randompic.tpl';
82    }
83
84    /*
85      Add a new section (links)
86    */
87    if ( ($block = $menu->get_block( 'mbAMM_links' ) ) != null )
88    {
89      $urls=$this->get_urls(true);
90      if ( count($urls)>0 )
91      {
92        if($this->my_config['amm_links_show_icons']=='y')
93        {
94          for($i=0;$i<count($urls);$i++)
95          {
96            $urls[$i]['icon']=get_root_url().'plugins/'.AMM_DIR."/links_pictures/".$urls[$i]['icon'];
97          }
98        }
99
100        $block->set_title( base64_decode($this->my_config['amm_links_title'][$user['language']]) );
101        $block->template = dirname(__FILE__).'/menu_templates/menubar_links.tpl';
102
103        $block->data = array(
104          'LINKS' => $urls,
105          'icons' => $this->my_config['amm_links_show_icons']
106        );
107      }
108    }
109
110    /*
111      Add personnal blocks random picture section
112    */
113    $sections=$this->get_sections(true);
114
115    if(count($sections))
116    {
117      $id_done=array();
118      foreach($sections as $key => $val)
119      {
120        if(!isset($id_done[$val['id']]))
121        {
122          if ( ($block = $menu->get_block( 'mbAMM_personalised'.$val['id'] ) ) != null )
123          {
124            $block->set_title( $val['title'] );
125            $block->template = dirname(__FILE__).'/menu_templates/menubar_personalised.tpl';
126            $block->data = stripslashes($val['content']);
127          }
128          $id_done[$val['id']]="";
129        }
130      }
131    }
132
133    /*
134      hide items from special & menu sections
135    */
136    foreach(array('mbMenu' => 'amm_sections_modmenu', 'mbSpecials' =>'amm_sections_modspecials') as $key0 => $val0)
137    {
138      if ( ($block = $menu->get_block( $key0 ) ) != null )
139      {
140        foreach($this->my_config[$val0] as $key => $val)
141        {
142          if($val=='n')
143          {
144            unset( $block->data[$key] );
145          }
146        }
147      }
148    }
149}
150
151  /*
152    return ajax content
153  */
154  protected function return_ajax_content()
155  {
156    global $ajax, $template;
157
158    if(isset($_REQUEST['ajaxfct']))
159    {
160      if($_REQUEST['ajaxfct']=='randompic')
161      {
162        $result="<p class='errors'>".l10n('g002_error_invalid_ajax_call')."</p>";
163        switch($_REQUEST['ajaxfct'])
164        {
165          case 'randompic':
166            $result=$this->ajax_amm_get_random_picture();
167            break;
168        }
169        $this->ajax->return_result($result);
170      }
171    }
172  }
173
174
175  // return the html content for the random picture block
176  private function ajax_amm_get_random_picture()
177  {
178    $local_tpl = new Template(AMM_PATH."menu_templates/", "");
179    $local_tpl->set_filename('body_page',
180                  dirname($this->filelocation).'/menu_templates/menubar_randompic_inner.tpl');
181
182      $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
183FROM ".CATEGORIES_TABLE." c, ".IMAGES_TABLE." i, ".IMAGE_CATEGORY_TABLE." ic
184WHERE c.status='public'
185  AND c.id = ic.category_id
186  AND ic.image_id = i.id
187ORDER BY rndvalue
188LIMIT 0,1
189";
190
191
192
193      $result = pwg_query($sql);
194      if($result and $nfo = mysql_fetch_array($result))
195      {
196        $nfo['section']='category';
197        $nfo['category']=array(
198          'id' => $nfo['catid'],
199          'name' => $nfo['name'],
200          'permalink' => $nfo['permalink']
201        );
202
203        $template_datas = array(
204          'LINK' => make_picture_url($nfo),
205          'IMG' => get_thumbnail_url($nfo),
206          'IMGNAME' => $nfo['imgname'],
207          'IMGCOMMENT' => $nfo['comment'],
208          'SHOWNAME' => $this->my_config['amm_randompicture_showname'],
209          'SHOWCOMMENT' => $this->my_config['amm_randompicture_showcomment']
210        );
211      }
212      else
213      {
214        $template_datas = array();
215      }
216
217    $local_tpl->assign('datas', $template_datas);
218    $local_tpl->assign('plugin', array('PATH' => AMM_PATH));
219
220    return($local_tpl->parse('body_page', true));
221  }
222
223} // AMM_PIP class
224
225
226?>
Note: See TracBrowser for help on using the repository browser.