1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | |
---|
5 | class 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->set_prefilter('header', array('stuffs', 'prefilter_picture_css')); |
---|
21 | pwgs_picture_special_sections(); |
---|
22 | } |
---|
23 | else |
---|
24 | { |
---|
25 | $template->set_prefilter( 'header', array('stuffs', 'prefilter_index_css') ); |
---|
26 | } |
---|
27 | |
---|
28 | $this->get_user_groups(); |
---|
29 | $this->get_modules(); |
---|
30 | $this->process_modules(); |
---|
31 | } |
---|
32 | |
---|
33 | /* Retrieve user groups */ |
---|
34 | function get_user_groups() |
---|
35 | { |
---|
36 | global $user; |
---|
37 | |
---|
38 | $query = 'SELECT group_id FROM ' . USER_GROUP_TABLE . ' WHERE user_id = ' . $user['id'] . ';'; |
---|
39 | $result = pwg_query($query); |
---|
40 | while ($row = mysql_fetch_assoc($result)) |
---|
41 | { |
---|
42 | array_push($this->user_groups, $row['group_id']); |
---|
43 | } |
---|
44 | } |
---|
45 | |
---|
46 | /* Retrieve modules from table */ |
---|
47 | function get_modules() |
---|
48 | { |
---|
49 | global $page, $user; |
---|
50 | |
---|
51 | if (!isset($page['stuffs_section'])) return; |
---|
52 | |
---|
53 | $query = ' |
---|
54 | SELECT DISTINCT id, name, path, datas, groups, show_title, id_line, width |
---|
55 | FROM ' . STUFFS_TABLE . ' |
---|
56 | LEFT JOIN ' . USER_GROUP_TABLE . ' |
---|
57 | ON user_id = '.$user['id'].' |
---|
58 | WHERE (users IS NULL OR users LIKE "%' . $user['status'] . '%") |
---|
59 | AND (groups IS NULL OR groups REGEXP CONCAT("(^|,)",group_id,"(,|$)")) |
---|
60 | AND level <= '.$user['level'].' |
---|
61 | AND '.$page['stuffs_section'].' = "true" |
---|
62 | ORDER BY pos ASC |
---|
63 | ;'; |
---|
64 | |
---|
65 | $result = pwg_query($query); |
---|
66 | |
---|
67 | while ($row = mysql_fetch_assoc($result)) |
---|
68 | { |
---|
69 | array_push($this->modules, $row); |
---|
70 | } |
---|
71 | } |
---|
72 | |
---|
73 | /* Process modules */ |
---|
74 | function process_modules() |
---|
75 | { |
---|
76 | global $pwg_loaded_plugins; |
---|
77 | |
---|
78 | foreach ($this->modules as $module) |
---|
79 | { |
---|
80 | if ($module['name'] == 'MainBlock') |
---|
81 | { |
---|
82 | $this->pos = 'end'; |
---|
83 | $show = unserialize($module['datas']); |
---|
84 | if (!$show) |
---|
85 | { |
---|
86 | add_event_handler('loc_end_index', 'hide_main_block'); |
---|
87 | } |
---|
88 | continue; |
---|
89 | } |
---|
90 | |
---|
91 | preg_match('#^'.preg_quote(PHPWG_PLUGINS_PATH).'([^/]*?)/#', $module['path'], $match); |
---|
92 | if (!isset($pwg_loaded_plugins[$match[1]])) |
---|
93 | { |
---|
94 | continue; |
---|
95 | } |
---|
96 | |
---|
97 | $datas = (!empty($module['datas']) ? unserialize($module['datas']) : false); |
---|
98 | $block = array(); |
---|
99 | |
---|
100 | @include($module['path'].'main.inc.php'); |
---|
101 | |
---|
102 | if (!empty($block['TEMPLATE'])) |
---|
103 | { |
---|
104 | $block['ID'] = $module['id']; |
---|
105 | if ($module['show_title'] == 'true') |
---|
106 | { |
---|
107 | $block['TITLE'] = trigger_event('render_stuffs_name', $module['name']); |
---|
108 | } |
---|
109 | if (is_admin()) |
---|
110 | { |
---|
111 | $block['U_EDIT'] = PHPWG_ROOT_PATH.'admin.php?page=plugin&section='.STUFFS_DIR.'%2Fadmin%2Fadmin.php&tab=edit_module&edit='.$module['id'].'&redirect='.urlencode(urlencode($_SERVER['REQUEST_URI'])); |
---|
112 | } |
---|
113 | $this->set_tpl_block($block, $module); |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | /* Set template blocks */ |
---|
118 | function set_tpl_block($block, $module) |
---|
119 | { |
---|
120 | if (!empty($module['id_line'])) |
---|
121 | { |
---|
122 | $block['id_line'] = $module['id_line']; |
---|
123 | $block['given_width'] = !empty($module['width']) ? $module['width'] : ''; |
---|
124 | |
---|
125 | if (!empty($this->blocks[$this->pos])) |
---|
126 | { |
---|
127 | $last = end($this->blocks[$this->pos]); |
---|
128 | $key = key($this->blocks[$this->pos]); |
---|
129 | $penul = prev($this->blocks[$this->pos]); |
---|
130 | |
---|
131 | if (isset($last['id_line']) and $last['id_line'] == $module['id_line']) |
---|
132 | { |
---|
133 | if (isset($penul['id_line']) and $penul['id_line'] == $module['id_line']) |
---|
134 | { |
---|
135 | $i = 3; |
---|
136 | !$block['given_width'] or $i--; |
---|
137 | !$last['given_width'] or $i--; |
---|
138 | !$penul['given_width'] or $i--; |
---|
139 | |
---|
140 | !$i or $default_width = intval((100 - $block['given_width'] - $last['given_width'] - $penul['given_width']) / $i); |
---|
141 | |
---|
142 | $penul['WIDTH'] = $penul['given_width'] ? $penul['given_width'] : $default_width; |
---|
143 | $block['WIDTH'] = $block['given_width'] ? $block['given_width'] : $default_width; |
---|
144 | |
---|
145 | $block['CLASS'] = 'right_block'; |
---|
146 | $block['new_line'] = false; |
---|
147 | $block['end_line'] = false; |
---|
148 | $last['end_line'] = true; |
---|
149 | $this->blocks[$this->pos][$key-1] = $penul; |
---|
150 | $this->blocks[$this->pos][$key] = $block; |
---|
151 | $this->blocks[$this->pos][] = $last; |
---|
152 | return; |
---|
153 | } |
---|
154 | else |
---|
155 | { |
---|
156 | if (empty($block['given_width']) and empty($last['given_width'])) |
---|
157 | { |
---|
158 | $last['WIDTH'] = 50; |
---|
159 | } |
---|
160 | elseif ($block['given_width']>0) |
---|
161 | { |
---|
162 | $last['WIDTH'] = 100 - $block['given_width']; |
---|
163 | } |
---|
164 | else |
---|
165 | { |
---|
166 | $last['WIDTH'] = $last['given_width']; |
---|
167 | } |
---|
168 | $block['CLASS'] = 'middle_block'; |
---|
169 | $last['CLASS'] = 'left_block'; |
---|
170 | $block['new_line'] = false; |
---|
171 | $block['end_line'] = true; |
---|
172 | $last['end_line'] = false; |
---|
173 | $this->blocks[$this->pos][$key] = $last; |
---|
174 | $this->blocks[$this->pos][] = $block; |
---|
175 | return; |
---|
176 | } |
---|
177 | } |
---|
178 | } |
---|
179 | } |
---|
180 | |
---|
181 | $block['new_line'] = true; |
---|
182 | $block['end_line'] = true; |
---|
183 | $block['CLASS'] = 'middle_block'; |
---|
184 | $this->blocks[$this->pos][] = $block; |
---|
185 | } |
---|
186 | |
---|
187 | static function prefilter_index_css($source, &$smarty) |
---|
188 | { |
---|
189 | $css = array( |
---|
190 | '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}plugins/'.STUFFS_DIR.'/theme/stuffs_index.css">' |
---|
191 | ); |
---|
192 | |
---|
193 | foreach ($smarty->get_template_vars('themes') as $theme) |
---|
194 | { |
---|
195 | if (file_exists(PHPWG_THEMES_PATH.$theme['id'].'/stuffs_index.css')) |
---|
196 | { |
---|
197 | array_push($css, '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}themes/'.$theme['id'].'/stuffs_index.css">'); |
---|
198 | } |
---|
199 | } |
---|
200 | |
---|
201 | $source = str_replace("\n</head>", "\n".implode( "\n", $css )."\n</head>", $source); |
---|
202 | |
---|
203 | return $source; |
---|
204 | } |
---|
205 | |
---|
206 | static function prefilter_picture_css($source, &$smarty) |
---|
207 | { |
---|
208 | $css = array( |
---|
209 | '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}plugins/'.STUFFS_DIR.'/theme/stuffs_picture.css">' |
---|
210 | ); |
---|
211 | |
---|
212 | foreach ($smarty->get_template_vars('themes') as $theme) |
---|
213 | { |
---|
214 | if (file_exists(PHPWG_THEMES_DIR.$theme['id'].'/stuffs_picture.css')) |
---|
215 | { |
---|
216 | array_push($css, '<link rel="stylesheet" type="text/css" href="{$ROOT_URL}themes/'.$theme['id'].'/stuffs_picture.css">'); |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | if (!empty($css)) |
---|
221 | { |
---|
222 | $source = str_replace("\n</head>", "\n".implode( "\n", $css )."\n</head>", $source); |
---|
223 | } |
---|
224 | |
---|
225 | return $source; |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | ?> |
---|