source: trunk/plugins/AMenuManager/amm_pip.class.inc.php @ 5272

Last change on this file since 5272 was 2605, checked in by rub, 16 years ago

Fix issue on AMM plugin when there are no public available.

It's necessary to remove status public for a selection of available pictures (public or private)

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 and $nfo = mysql_fetch_array($result))
65      {
66        $nfo['section']='category';
67        $nfo['category']=array(
68          'id' => $nfo['catid'],
69          'name' => $nfo['name'],
70          'permalink' => $nfo['permalink']
71        );
72        global $user;
73        $block->set_title(  base64_decode($this->my_config['amm_randompicture_title'][$user['language']]) );
74        $block->template = dirname(__FILE__).'/menu_templates/menubar_randompic.tpl';
75        $block->data = array(
76          'LINK' => make_picture_url($nfo),
77          'IMG' => get_thumbnail_url($nfo),
78          'IMGNAME' => $nfo['imgname'],
79          'IMGCOMMENT' => $nfo['comment'],
80          'SHOWNAME' => $this->my_config['amm_randompicture_showname'],
81          'SHOWCOMMENT' => $this->my_config['amm_randompicture_showcomment']
82        );
83      }
84    }
85
86    /*
87      Add a new section (links)
88    */
89    if ( ($block = $menu->get_block( 'mbAMM_links' ) ) != null )
90    {
91      $urls=$this->get_urls(true);
92      if ( count($urls)>0 )
93      {
94        if($this->my_config['amm_links_show_icons']=='y')
95        {
96          for($i=0;$i<count($urls);$i++)
97          {
98            $urls[$i]['icon']=get_root_url().'plugins/'.AMM_DIR."/links_pictures/".$urls[$i]['icon'];
99          }
100        }
101       
102        $block->set_title( base64_decode($this->my_config['amm_links_title'][$user['language']]) );
103        $block->template = dirname(__FILE__).'/menu_templates/menubar_links.tpl';
104
105        $block->data = array(
106          'LINKS' => $urls,
107          'icons' => $this->my_config['amm_links_show_icons']
108        );
109      }
110    }
111
112    /*
113      Add personnal blocks random picture section
114    */
115    $sections=$this->get_sections(true);
116
117    if(count($sections))
118    {
119      $id_done=array();
120      foreach($sections as $key => $val)
121      {
122        if(!isset($id_done[$val['id']]))
123        {
124          if ( ($block = $menu->get_block( 'mbAMM_personalised'.$val['id'] ) ) != null )
125          {
126            $block->set_title( $val['title'] );
127            $block->template = dirname(__FILE__).'/menu_templates/menubar_personalised.tpl';
128            $block->data = stripslashes($val['content']);
129          }
130          $id_done[$val['id']]="";
131        }
132      }
133    }
134
135    /*
136      hide items from special & menu sections
137    */
138    foreach(array('mbMenu' => 'amm_sections_modmenu', 'mbSpecials' =>'amm_sections_modspecials') as $key0 => $val0)
139    {
140      if ( ($block = $menu->get_block( $key0 ) ) != null )
141      {
142        foreach($this->my_config[$val0] as $key => $val)
143        {
144          if($val=='n')
145          {
146            unset( $block->data[$key] );
147          }
148        }
149      }
150    }
151        }
152
153} // AMM_PIP class
154
155
156?>
Note: See TracBrowser for help on using the repository browser.