aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/AMenuManager/amm_pip.class.inc.php
blob: dc34e1d841e72cf7724cd66e43d3af9593afcdf2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
/* -----------------------------------------------------------------------------
  Plugin     : Advanced Menu Manager
  Author     : Grum
    email    : grum@grum.dnsalias.com
    website  : http://photos.grum.dnsalias.com
    PWG user : http://forum.phpwebgallery.net/profile.php?id=3706

    << May the Little SpaceFrog be with you ! >>
  ------------------------------------------------------------------------------
  See main.inc.php for release information

  PIP classe => manage integration in public interface

  --------------------------------------------------------------------------- */
if (!defined('PHPWG_ROOT_PATH')) { die('Hacking attempt!'); }

include_once(PHPWG_PLUGINS_PATH.'AMenuManager/amm_root.class.inc.php');

class AMM_PIP extends AMM_root
{ 
  function AMM_PIP($prefixeTable, $filelocation)
  {
    parent::__construct($prefixeTable, $filelocation);

    $this->load_config();
    $this->init_events();
  }


  /* ---------------------------------------------------------------------------
  Public classe functions
  --------------------------------------------------------------------------- */


  /*
    initialize events call for the plugin
  */
  public function init_events()
  {
    add_event_handler('loc_begin_menubar', array(&$this, 'modify_menu') );
  }

  /* ---------------------------------------------------------------------------
  protected classe functions
  --------------------------------------------------------------------------- */
  public function modify_menu()
  {
    global $menu, $user;


    /*
      Add a new section (links)
    */
    $urls=$this->get_urls(true);
    if(($this->my_config['amm_links_active']=='y')and(count($urls)>0))
    {
      if($this->my_config['amm_links_show_icons']=='y')
      {
        for($i=0;$i<count($urls);$i++)
        {
          $urls[$i]['icon']=AMM_PATH."links_pictures/".$urls[$i]['icon'];
        }
      }

      $section = new Section('mbAMM_links', base64_decode($this->my_config['amm_links_title'][$user['language']]), dirname(__FILE__).'/menu_templates/menubar_links.tpl');
      $section->set_items(array(
        'LINKS' => $urls,
        'icons' => $this->my_config['amm_links_show_icons']
      ));
      $menu->add($section->get());
    }


    /*
      Add a new random picture section
    */
    if($this->my_config['amm_randompicture_active']=='y')
    {
      $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
FROM ".CATEGORIES_TABLE." c, ".IMAGES_TABLE." i, ".IMAGE_CATEGORY_TABLE." ic
WHERE c.status='public'
  AND c.id = ic.category_id
  AND ic.image_id = i.id
ORDER BY rndvalue
LIMIT 0,1
";
      $result=pwg_query($sql);
      if($result)
      {
        $nfo = mysql_fetch_array($result);
        $nfo['section']='category';
        $nfo['category']=array(
          'id' => $nfo['catid'],
          'name' => $nfo['name'],
          'permalink' => $nfo['permalink']
        );

        $section = new Section('mbAMM_randompict', base64_decode($this->my_config['amm_randompicture_title'][$user['language']]), dirname(__FILE__).'/menu_templates/menubar_randompic.tpl');
        $section->set_items(array(
          'LINK' => make_picture_url($nfo),
          'IMG' => get_thumbnail_url($nfo),
          'IMGNAME' => $nfo['imgname'],
          'IMGCOMMENT' => $nfo['comment'],
          'SHOWNAME' => $this->my_config['amm_randompicture_showname'],
          'SHOWCOMMENT' => $this->my_config['amm_randompicture_showcomment']
        ));
        $menu->add($section->get());
      }
    }

    /*
      Add personnal blocks random picture section
    */
    $sections=$this->get_sections(true);

    if(count($sections))
    {
      $id_done=array();
      foreach($sections as $key => $val)
      {
        if(!isset($id_done[$val['id']]))
        {
          $section = new Section('mbAMM_personalised'.$val['id'], $val['title'], dirname(__FILE__).'/menu_templates/menubar_personalised.tpl');
          $section->set_items(array(
            'CONTENT' => stripslashes($val['content'])));
          $menu->add($section->get());

          $id_done[$val['id']]="";
        }
      }
    }


    /*
      Hide sections
    */
    foreach($this->my_config['amm_sections_visible'] as $key => $val)
    {
      if($val=='n')
      {
        $menu->remove($key);
      }
    }

    /*
      hide items from special & menu sections
    */
    foreach(array('mbMenu' => 'amm_sections_modmenu', 'mbSpecial' =>'amm_sections_modspecial') as $key0 => $val0)
    {
      $section_menu=$menu->section($key0);
      foreach($this->my_config[$val0] as $key => $val)
      {
        if($val=='n')
        {
          unset($section_menu['ITEMS'][$key]);
        }
      }
      $menu->replace($section_menu);
    }

  }


} // AMM_PIP class


?>