1 | <?php |
---|
2 | defined('ADMINTOOLS_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | /** |
---|
5 | * Add main toolbar to current page |
---|
6 | * @trigger loc_after_page_header |
---|
7 | */ |
---|
8 | function admintools_add_public_controller() |
---|
9 | { |
---|
10 | global $MultiView, $conf, $template, $page, $user, $picture; |
---|
11 | |
---|
12 | if (script_basename() == 'picture' and empty($picture['current'])) |
---|
13 | { |
---|
14 | return; |
---|
15 | } |
---|
16 | |
---|
17 | $url_root = get_root_url(); |
---|
18 | $tpl_vars = array(); |
---|
19 | |
---|
20 | if ($MultiView->is_admin()) |
---|
21 | { // full options for admin |
---|
22 | $tpl_vars['U_SITE_ADMIN'] = $url_root . 'admin.php?page='; |
---|
23 | $tpl_vars['MULTIVIEW'] = $MultiView->get_data(); |
---|
24 | $tpl_vars['USER'] = $MultiView->get_user(); |
---|
25 | $tpl_vars['CURRENT_USERNAME'] = $user['id']==$conf['guest_id'] ? l10n('guest') : $user['username']; |
---|
26 | $tpl_vars['DELETE_CACHE'] = isset($conf['multiview_invalidate_cache']); |
---|
27 | |
---|
28 | if (($admin_lang = $MultiView->get_user_language()) !== false) |
---|
29 | { |
---|
30 | include_once(PHPWG_ROOT_PATH . 'include/functions_mail.inc.php'); |
---|
31 | switch_lang_to($admin_lang); |
---|
32 | } |
---|
33 | } |
---|
34 | else if ($conf['AdminTools']['public_quick_edit'] and |
---|
35 | script_basename() == 'picture' and $picture['current']['added_by'] == $user['id'] |
---|
36 | ) |
---|
37 | { // only "edit" button for photo owner |
---|
38 | } |
---|
39 | else |
---|
40 | { |
---|
41 | return; |
---|
42 | } |
---|
43 | |
---|
44 | $tpl_vars['POSITION'] = $conf['AdminTools']['closed_position']; |
---|
45 | $tpl_vars['DEFAULT_OPEN'] = $conf['AdminTools']['default_open']; |
---|
46 | $tpl_vars['U_SELF'] = $MultiView->get_clean_url(true); |
---|
47 | |
---|
48 | // photo page |
---|
49 | if (script_basename() == 'picture') |
---|
50 | { |
---|
51 | $url_self = duplicate_picture_url(); |
---|
52 | $tpl_vars['IS_PICTURE'] = true; |
---|
53 | |
---|
54 | // admin can add to caddie and set representattive |
---|
55 | if ($MultiView->is_admin()) |
---|
56 | { |
---|
57 | $template->clear_assign(array( |
---|
58 | 'U_SET_AS_REPRESENTATIVE', |
---|
59 | 'U_PHOTO_ADMIN', |
---|
60 | 'U_CADDIE', |
---|
61 | )); |
---|
62 | |
---|
63 | $template->set_prefilter('picture', 'admintools_remove_privacy'); |
---|
64 | |
---|
65 | $tpl_vars['U_CADDIE'] = add_url_params( |
---|
66 | $url_self, |
---|
67 | array('action'=>'add_to_caddie') |
---|
68 | ); |
---|
69 | |
---|
70 | $query = ' |
---|
71 | SELECT element_id FROM ' . CADDIE_TABLE . ' |
---|
72 | WHERE element_id = ' . $page['image_id'] .' |
---|
73 | ;'; |
---|
74 | $tpl_vars['IS_IN_CADDIE'] = pwg_db_num_rows(pwg_query($query)) > 0; |
---|
75 | |
---|
76 | if (isset($page['category'])) |
---|
77 | { |
---|
78 | $tpl_vars['CATEGORY_ID'] = $page['category']['id']; |
---|
79 | |
---|
80 | $tpl_vars['U_SET_REPRESENTATIVE'] = add_url_params( |
---|
81 | $url_self, |
---|
82 | array('action'=>'set_as_representative') |
---|
83 | ); |
---|
84 | |
---|
85 | $tpl_vars['IS_REPRESENTATIVE'] = $page['category']['representative_picture_id'] == $page['image_id']; |
---|
86 | } |
---|
87 | |
---|
88 | $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=photo-' . $page['image_id'] |
---|
89 | .(isset($page['category']) ? '&cat_id=' . $page['category']['id'] : ''); |
---|
90 | } |
---|
91 | |
---|
92 | $tpl_vars['U_DELETE'] = add_url_params( |
---|
93 | $url_self, array( |
---|
94 | 'delete'=>'', |
---|
95 | 'pwg_token'=>get_pwg_token() |
---|
96 | ) |
---|
97 | ); |
---|
98 | |
---|
99 | // gets tags (full available list is loaded in ajax) |
---|
100 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); |
---|
101 | |
---|
102 | $query = ' |
---|
103 | SELECT id, name |
---|
104 | FROM '.IMAGE_TAG_TABLE.' AS it |
---|
105 | JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id |
---|
106 | WHERE image_id = '.$page['image_id'].' |
---|
107 | ;'; |
---|
108 | $tag_selection = get_taglist($query); |
---|
109 | |
---|
110 | $tpl_vars['QUICK_EDIT'] = array( |
---|
111 | 'img' => $picture['current']['derivatives']['square']->get_url(), |
---|
112 | 'name' => $picture['current']['name'], |
---|
113 | 'comment' => $picture['current']['comment'], |
---|
114 | 'author' => $picture['current']['author'], |
---|
115 | 'level' => $picture['current']['level'], |
---|
116 | 'date_creation' => substr($picture['current']['date_creation'], 0, 10), |
---|
117 | 'date_creation_time' => substr($picture['current']['date_creation'], 11, 5), |
---|
118 | 'tag_selection' => $tag_selection, |
---|
119 | ); |
---|
120 | } |
---|
121 | // album page (admin only) |
---|
122 | else if ($MultiView->is_admin() and @$page['section'] == 'categories' and isset($page['category'])) |
---|
123 | { |
---|
124 | $url_self = duplicate_index_url(); |
---|
125 | |
---|
126 | $tpl_vars['IS_CATEGORY'] = true; |
---|
127 | $tpl_vars['CATEGORY_ID'] = $page['category']['id']; |
---|
128 | |
---|
129 | $template->clear_assign(array( |
---|
130 | 'U_EDIT', |
---|
131 | 'U_CADDIE', |
---|
132 | )); |
---|
133 | |
---|
134 | $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=album-' . $page['category']['id']; |
---|
135 | |
---|
136 | if (!empty($page['items'])) |
---|
137 | { |
---|
138 | $tpl_vars['U_CADDIE'] = add_url_params( |
---|
139 | $url_self, |
---|
140 | array('caddie'=>1) |
---|
141 | ); |
---|
142 | } |
---|
143 | |
---|
144 | $tpl_vars['QUICK_EDIT'] = array( |
---|
145 | 'img' => null, |
---|
146 | 'name' => $page['category']['name'], |
---|
147 | 'comment' => $page['category']['comment'], |
---|
148 | ); |
---|
149 | |
---|
150 | if (!empty($page['category']['representative_picture_id'])) |
---|
151 | { |
---|
152 | $query = ' |
---|
153 | SELECT * FROM '.IMAGES_TABLE.' |
---|
154 | WHERE id = '. $page['category']['representative_picture_id'] .' |
---|
155 | ;'; |
---|
156 | $image_infos = pwg_db_fetch_assoc(pwg_query($query)); |
---|
157 | |
---|
158 | $tpl_vars['QUICK_EDIT']['img'] = DerivativeImage::get_one(IMG_SQUARE, $image_infos)->get_url(); |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | $template->assign(array( |
---|
164 | 'ADMINTOOLS_PATH' => './plugins/' . ADMINTOOLS_ID .'/', |
---|
165 | 'ato' => $tpl_vars, |
---|
166 | )); |
---|
167 | |
---|
168 | $template->set_filename('ato_public_controller', realpath(ADMINTOOLS_PATH . 'template/public_controller.tpl')); |
---|
169 | $template->parse('ato_public_controller'); |
---|
170 | |
---|
171 | if ($MultiView->is_admin() && @$admin_lang !== false) |
---|
172 | { |
---|
173 | switch_lang_back(); |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | /** |
---|
178 | * Add main toolbar to current page |
---|
179 | * @trigger loc_after_page_header |
---|
180 | */ |
---|
181 | function admintools_add_admin_controller() |
---|
182 | { |
---|
183 | global $MultiView, $conf, $template, $page, $user; |
---|
184 | |
---|
185 | $url_root = get_root_url(); |
---|
186 | $tpl_vars = array(); |
---|
187 | |
---|
188 | $tpl_vars['MULTIVIEW'] = $MultiView->get_data(); |
---|
189 | $tpl_vars['DELETE_CACHE'] = isset($conf['multiview_invalidate_cache']); |
---|
190 | $tpl_vars['U_SELF'] = $MultiView->get_clean_admin_url(true); |
---|
191 | |
---|
192 | if (($admin_lang = $MultiView->get_user_language()) !== false) |
---|
193 | { |
---|
194 | include_once(PHPWG_ROOT_PATH . 'include/functions_mail.inc.php'); |
---|
195 | switch_lang_to($admin_lang); |
---|
196 | } |
---|
197 | |
---|
198 | $template->assign(array( |
---|
199 | 'ADMINTOOLS_PATH' => './plugins/' . ADMINTOOLS_ID .'/', |
---|
200 | 'ato' => $tpl_vars, |
---|
201 | )); |
---|
202 | |
---|
203 | $template->set_filename('ato_admin_controller', realpath(ADMINTOOLS_PATH . 'template/admin_controller.tpl')); |
---|
204 | $template->parse('ato_admin_controller'); |
---|
205 | |
---|
206 | if ($MultiView->is_admin() && @$admin_lang !== false) |
---|
207 | { |
---|
208 | switch_lang_back(); |
---|
209 | } |
---|
210 | } |
---|
211 | |
---|
212 | function admintools_add_admin_controller_setprefilter() |
---|
213 | { |
---|
214 | global $template; |
---|
215 | $template->set_prefilter('header', 'admintools_admin_prefilter'); |
---|
216 | } |
---|
217 | |
---|
218 | function admintools_admin_prefilter($content) |
---|
219 | { |
---|
220 | $search = '<a class="icon-brush tiptip" href="{$U_CHANGE_THEME}" title="{\'Switch to clear or dark colors for administration\'|translate}">{\'Change Admin Colors\'|translate}</a>'; |
---|
221 | $replace = '<span id="ato_container"><a class="icon-cog-alt" href="#">{\'Tools\'|translate}</a></span>'; |
---|
222 | return str_replace($search, $replace, $content); |
---|
223 | } |
---|
224 | |
---|
225 | /** |
---|
226 | * Disable privacy level switchbox |
---|
227 | */ |
---|
228 | function admintools_remove_privacy($content) |
---|
229 | { |
---|
230 | $search = '{if $display_info.privacy_level and isset($available_permission_levels)}'; |
---|
231 | $replace = '{if false}'; |
---|
232 | return str_replace($search, $replace, $content); |
---|
233 | } |
---|
234 | |
---|
235 | /** |
---|
236 | * Save picture form |
---|
237 | * @trigger loc_begin_picture |
---|
238 | */ |
---|
239 | function admintools_save_picture() |
---|
240 | { |
---|
241 | global $page, $conf, $MultiView, $user, $picture; |
---|
242 | |
---|
243 | if (!isset($_GET['delete']) and !isset($_POST['action']) and @$_POST['action'] != 'quick_edit') |
---|
244 | { |
---|
245 | return; |
---|
246 | } |
---|
247 | |
---|
248 | $query = 'SELECT added_by FROM '. IMAGES_TABLE .' WHERE id = '. $page['image_id'] .';'; |
---|
249 | list($added_by) = pwg_db_fetch_row(pwg_query($query)); |
---|
250 | |
---|
251 | if (!$MultiView->is_admin() and $user['id'] != $added_by) |
---|
252 | { |
---|
253 | return; |
---|
254 | } |
---|
255 | |
---|
256 | if (isset($_GET['delete']) and get_pwg_token()==@$_GET['pwg_token']) |
---|
257 | { |
---|
258 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); |
---|
259 | |
---|
260 | delete_elements(array($page['image_id']), true); |
---|
261 | invalidate_user_cache(); |
---|
262 | |
---|
263 | if (isset($page['rank_of'][ $page['image_id'] ])) |
---|
264 | { |
---|
265 | redirect( |
---|
266 | duplicate_index_url( |
---|
267 | array( |
---|
268 | 'start' => |
---|
269 | floor($page['rank_of'][ $page['image_id'] ] / $page['nb_image_page']) |
---|
270 | * $page['nb_image_page'] |
---|
271 | ) |
---|
272 | ) |
---|
273 | ); |
---|
274 | } |
---|
275 | else |
---|
276 | { |
---|
277 | redirect(make_index_url()); |
---|
278 | } |
---|
279 | } |
---|
280 | |
---|
281 | if ($_POST['action'] == 'quick_edit') |
---|
282 | { |
---|
283 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); |
---|
284 | |
---|
285 | $data = array( |
---|
286 | 'name' => $_POST['name'], |
---|
287 | 'author' => $_POST['author'], |
---|
288 | ); |
---|
289 | |
---|
290 | if ($MultiView->is_admin()) |
---|
291 | { |
---|
292 | $data['level'] = $_POST['level']; |
---|
293 | } |
---|
294 | |
---|
295 | if ($conf['allow_html_descriptions']) |
---|
296 | { |
---|
297 | $data['comment'] = @$_POST['comment']; |
---|
298 | } |
---|
299 | else |
---|
300 | { |
---|
301 | $data['comment'] = strip_tags(@$_POST['comment']); |
---|
302 | } |
---|
303 | |
---|
304 | if (!empty($_POST['date_creation']) and strtotime($_POST['date_creation']) !== false) |
---|
305 | { |
---|
306 | $data['date_creation'] = $_POST['date_creation'] .' '. $_POST['date_creation_time']; |
---|
307 | } |
---|
308 | |
---|
309 | single_update( |
---|
310 | IMAGES_TABLE, |
---|
311 | $data, |
---|
312 | array('id' => $page['image_id']) |
---|
313 | ); |
---|
314 | |
---|
315 | $tag_ids = array(); |
---|
316 | if (!empty($_POST['tags'])) |
---|
317 | { |
---|
318 | $tag_ids = get_tag_ids($_POST['tags']); |
---|
319 | } |
---|
320 | set_tags($tag_ids, $page['image_id']); |
---|
321 | } |
---|
322 | } |
---|
323 | |
---|
324 | /** |
---|
325 | * Save category form |
---|
326 | * @trigger loc_begin_index |
---|
327 | */ |
---|
328 | function admintools_save_category() |
---|
329 | { |
---|
330 | global $page, $conf, $MultiView; |
---|
331 | |
---|
332 | if (!$MultiView->is_admin()) |
---|
333 | { |
---|
334 | return; |
---|
335 | } |
---|
336 | |
---|
337 | if (@$_POST['action'] == 'quick_edit') |
---|
338 | { |
---|
339 | $data = array( |
---|
340 | 'name' => $_POST['name'], |
---|
341 | ); |
---|
342 | |
---|
343 | if ($conf['allow_html_descriptions']) |
---|
344 | { |
---|
345 | $data['comment'] = @$_POST['comment']; |
---|
346 | } |
---|
347 | else |
---|
348 | { |
---|
349 | $data['comment'] = strip_tags(@$_POST['comment']); |
---|
350 | } |
---|
351 | |
---|
352 | single_update( |
---|
353 | CATEGORIES_TABLE, |
---|
354 | $data, |
---|
355 | array('id' => $page['category']['id']) |
---|
356 | ); |
---|
357 | |
---|
358 | redirect(duplicate_index_url()); |
---|
359 | } |
---|
360 | } |
---|