source: tags/build-Butterfly01/plugins/AMenuManager/amm_pip.class.inc.php @ 2818

Last change on this file since 2818 was 2488, checked in by rvelices, 16 years ago
  • based on test_menu by grum (thanks to you) - integration of dynamic menu bar to pwg
  • the menubar is composed now of dynamic blocks that can be ordered/hidden
  • plugins can add their own blocks
File size: 4.6 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');
19
20class AMM_PIP extends AMM_root
21{ 
22  function AMM_PIP($prefixeTable, $filelocation)
23  {
24    parent::__construct($prefixeTable, $filelocation);
25
26    $this->load_config();
27    $this->init_events();
28  }
29
30
31  /* ---------------------------------------------------------------------------
32  Public classe functions
33  --------------------------------------------------------------------------- */
34
35
36  /*
37    initialize events call for the plugin
38  */
39  public function init_events()
40  {
41    //TODELETE: add_event_handler('loc_begin_menubar', array(&$this, 'modify_menu') );
42    parent::init_events();
43    add_event_handler('blockmanager_apply', array(&$this, 'blockmanager_apply') );
44  }
45
46  public function blockmanager_apply( $menu_ref_arr )
47  {
48    $menu = & $menu_ref_arr[0];
49
50    /*
51      Add a new random picture section
52    */
53    if ( ($block = $menu->get_block( 'mbAMM_randompict' ) ) != null )
54    {
55      $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
56FROM ".CATEGORIES_TABLE." c, ".IMAGES_TABLE." i, ".IMAGE_CATEGORY_TABLE." ic
57WHERE c.status='public'
58  AND c.id = ic.category_id
59  AND ic.image_id = i.id
60ORDER BY rndvalue
61LIMIT 0,1
62";
63      $result=pwg_query($sql);
64      if($result)
65      {
66        $nfo = mysql_fetch_array($result);
67        $nfo['section']='category';
68        $nfo['category']=array(
69          'id' => $nfo['catid'],
70          'name' => $nfo['name'],
71          'permalink' => $nfo['permalink']
72        );
73        global $user;
74        $block->set_title(  base64_decode($this->my_config['amm_randompicture_title'][$user['language']]) );
75        $block->template = dirname(__FILE__).'/menu_templates/menubar_randompic.tpl';
76        $block->data = array(
77          'LINK' => make_picture_url($nfo),
78          'IMG' => get_thumbnail_url($nfo),
79          'IMGNAME' => $nfo['imgname'],
80          'IMGCOMMENT' => $nfo['comment'],
81          'SHOWNAME' => $this->my_config['amm_randompicture_showname'],
82          'SHOWCOMMENT' => $this->my_config['amm_randompicture_showcomment']
83        );
84      }
85    }
86
87    /*
88      Add a new section (links)
89    */
90    if ( ($block = $menu->get_block( 'mbAMM_links' ) ) != null )
91    {
92      $urls=$this->get_urls(true);
93      if ( count($urls)>0 )
94      {
95        if($this->my_config['amm_links_show_icons']=='y')
96        {
97          for($i=0;$i<count($urls);$i++)
98          {
99            $urls[$i]['icon']=get_root_url().'plugins/'.AMM_DIR."/links_pictures/".$urls[$i]['icon'];
100          }
101        }
102       
103        $block->set_title( base64_decode($this->my_config['amm_links_title'][$user['language']]) );
104        $block->template = dirname(__FILE__).'/menu_templates/menubar_links.tpl';
105
106        $block->data = array(
107          'LINKS' => $urls,
108          'icons' => $this->my_config['amm_links_show_icons']
109        );
110      }
111    }
112
113    /*
114      Add personnal blocks random picture section
115    */
116    $sections=$this->get_sections(true);
117
118    if(count($sections))
119    {
120      $id_done=array();
121      foreach($sections as $key => $val)
122      {
123        if(!isset($id_done[$val['id']]))
124        {
125          if ( ($block = $menu->get_block( 'mbAMM_personalised'.$val['id'] ) ) != null )
126          {
127            $block->set_title( $val['title'] );
128            $block->template = dirname(__FILE__).'/menu_templates/menubar_personalised.tpl';
129            $block->data = stripslashes($val['content']);
130          }
131          $id_done[$val['id']]="";
132        }
133      }
134    }
135
136    /*
137      hide items from special & menu sections
138    */
139    foreach(array('mbMenu' => 'amm_sections_modmenu', 'mbSpecials' =>'amm_sections_modspecials') as $key0 => $val0)
140    {
141      if ( ($block = $menu->get_block( $key0 ) ) != null )
142      {
143        foreach($this->my_config[$val0] as $key => $val)
144        {
145          if($val=='n')
146          {
147            unset( $block->data[$key] );
148          }
149        }
150      }
151    }
152        }
153
154} // AMM_PIP class
155
156
157?>
Note: See TracBrowser for help on using the repository browser.