source: extensions/PWG_Stuffs/trunk/class.inc.php @ 14792

Last change on this file since 14792 was 12515, checked in by patdenice, 12 years ago

Update LastCom module for piwigo 2.3.
Don't hide main block if an additional page is defined as home page.

File size: 5.6 KB
Line 
1<?php
2
3if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
4
5class stuffs
6{
7  var $user_groups = array();
8  var $modules = array();
9  var $blocks = array();
10  var $pos = 'begin';
11  var $prefixe = 'PLUGIN_INDEX_CONTENT_';
12
13  function stuffs()
14  {
15    global $page, $template;
16
17    if ($page['stuffs_section'] == 'on_picture')
18    {
19      $this->prefixe = 'PLUGIN_PICTURE_';
20      $template->func_combine_css(array(
21        'path' => 'plugins/PWG_Stuffs/theme/stuffs_picture.css',
22        ),
23        $smarty
24      );
25      pwgs_picture_special_sections();
26    }
27    else
28    {
29      $template->func_combine_css(array(
30        'path' => 'plugins/PWG_Stuffs/theme/stuffs_index.css',
31        ),
32        $smarty
33      );
34    }
35
36    $this->get_user_groups();
37    $this->get_modules();
38    $this->process_modules();
39  }
40
41  /* Retrieve user groups  */
42  function get_user_groups()
43  {
44    global $user;
45
46    $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';';
47    $result = pwg_query($query);
48    while ($row = mysql_fetch_assoc($result))
49    {
50      array_push($this->user_groups, $row['group_id']);
51    }
52  }
53
54  /* Retrieve modules from table */
55  function get_modules()
56  {
57    global $page, $user;
58
59    if (!isset($page['stuffs_section'])) return;
60
61    $query = '
62SELECT DISTINCT id, name, path, datas, groups, show_title, id_line, width
63FROM ' . STUFFS_TABLE . '
64LEFT JOIN ' . USER_GROUP_TABLE . '
65  ON user_id = '.$user['id'].'
66WHERE (users IS NULL OR users LIKE "%' . $user['status'] . '%")
67  AND (groups IS NULL OR groups REGEXP CONCAT("(^|,)",group_id,"(,|$)"))
68  AND level <= '.$user['level'].'
69  AND '.$page['stuffs_section'].' = "true"
70ORDER BY pos ASC
71;';
72
73    $result = pwg_query($query);
74
75    while ($row = mysql_fetch_assoc($result))
76    {
77      array_push($this->modules, $row);
78    }
79  }
80
81  /* Process modules */
82  function process_modules()
83  {
84    global $pwg_loaded_plugins, $conf;
85
86    foreach ($this->modules as $module)
87    {
88      if ($module['name'] == 'MainBlock')
89      {
90        $this->pos = 'end';
91        $show = unserialize($module['datas']);
92        if (!$show and empty($conf['AP']['homepage']))
93        {
94          add_event_handler('loc_end_index', 'hide_main_block');
95        }
96        continue;
97      }
98
99      preg_match('#^'.preg_quote(PHPWG_PLUGINS_PATH).'([^/]*?)/#', $module['path'], $match);
100      if (!isset($pwg_loaded_plugins[$match[1]]))
101      {
102        continue;
103      }
104
105      $datas = (!empty($module['datas']) ? unserialize($module['datas']) : false);
106      $block = array();
107
108      @include($module['path'].'main.inc.php');
109
110      if (!empty($block['TEMPLATE']))
111      {
112        $block['ID'] = $module['id'];
113        if ($module['show_title'] == 'true')
114        {
115          $block['TITLE'] = trigger_event('render_stuffs_name', $module['name']);
116        }
117        if (is_admin())
118        {
119          $block['U_EDIT'] = get_root_url().'admin.php?page=plugin-'.STUFFS_DIR.'-edit_module&amp;edit='.$module['id'].'&amp;redirect='.urlencode(urlencode($_SERVER['REQUEST_URI']));
120        }
121        $this->set_tpl_block($block, $module);
122      }
123    }
124  }
125  /* Set template blocks  */
126  function set_tpl_block($block, $module)
127  {
128    if (!empty($module['id_line']))
129    {
130      $block['id_line'] = $module['id_line'];
131      $block['given_width'] = !empty($module['width']) ? $module['width'] : '';
132
133      if (!empty($this->blocks[$this->pos]))
134      {
135        $last = end($this->blocks[$this->pos]);
136        $key = key($this->blocks[$this->pos]);
137        $penul = prev($this->blocks[$this->pos]);
138
139        if (isset($last['id_line']) and $last['id_line'] == $module['id_line'])
140        {
141          if (isset($penul['id_line']) and $penul['id_line'] == $module['id_line'])
142          {
143            $i = 3;
144            !$block['given_width'] or $i--;
145            !$last['given_width'] or $i--;
146            !$penul['given_width'] or $i--;
147
148            !$i or $default_width = intval((100 - $block['given_width'] - $last['given_width'] - $penul['given_width']) / $i);
149
150            $penul['WIDTH'] = $penul['given_width'] ? $penul['given_width'] : $default_width;
151            $block['WIDTH'] = $block['given_width'] ? $block['given_width'] : $default_width;
152
153            $block['CLASS'] = 'right_block';
154            $block['new_line'] = false;
155            $block['end_line'] = false;
156            $last['end_line'] = true;
157            $this->blocks[$this->pos][$key-1] = $penul;
158            $this->blocks[$this->pos][$key] = $block;
159            $this->blocks[$this->pos][] = $last;
160            return;
161          }
162          else
163          {
164            if (empty($block['given_width']) and empty($last['given_width']))
165            {
166              $last['WIDTH'] = 50;
167            }
168            elseif ($block['given_width']>0)
169            {
170              $last['WIDTH'] = 100 - $block['given_width'];
171            }
172            else
173            {
174              $last['WIDTH'] = $last['given_width'];
175            }
176            $block['CLASS'] = 'middle_block';
177            $last['CLASS'] = 'left_block';
178            $block['new_line'] = false;
179            $block['end_line'] = true;
180            $last['end_line'] = false;
181            $this->blocks[$this->pos][$key] = $last;
182            $this->blocks[$this->pos][] = $block;
183            return;
184          }
185        }
186      }
187    }
188
189    $block['new_line'] = true;
190    $block['end_line'] = true;
191    $block['CLASS'] = 'middle_block';
192    $this->blocks[$this->pos][] = $block;
193  }
194}
195
196?>
Note: See TracBrowser for help on using the repository browser.