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

Last change on this file since 28915 was 28915, checked in by plg, 10 years ago

compatibility with Piwigo 2.7 (still compatible with Piwigo 2.6, but no more 2.5), change trigger_event into trigger_change

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