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 | include_once(PHPWG_ROOT_PATH . 'include/functions_mail.inc.php'); |
---|
29 | switch_lang_to(get_default_language()); |
---|
30 | } |
---|
31 | else if (script_basename() == 'picture' and $picture['current']['added_by'] == $user['id']) |
---|
32 | { // only "edit" button for photo owner |
---|
33 | } |
---|
34 | else |
---|
35 | { |
---|
36 | return; |
---|
37 | } |
---|
38 | |
---|
39 | $tpl_vars['U_SELF'] = $MultiView->get_clean_url(true); |
---|
40 | |
---|
41 | // photo page |
---|
42 | if (script_basename() == 'picture') |
---|
43 | { |
---|
44 | $url_self = duplicate_picture_url(); |
---|
45 | $tpl_vars['IS_PICTURE'] = true; |
---|
46 | |
---|
47 | // admin can add to caddie and set representattive |
---|
48 | if ($MultiView->is_admin()) |
---|
49 | { |
---|
50 | $template->clear_assign(array( |
---|
51 | 'U_SET_AS_REPRESENTATIVE', |
---|
52 | 'U_PHOTO_ADMIN', |
---|
53 | 'U_CADDIE', |
---|
54 | )); |
---|
55 | |
---|
56 | $template->set_prefilter('picture', 'admintools_remove_privacy'); |
---|
57 | |
---|
58 | $tpl_vars['U_CADDIE'] = add_url_params( |
---|
59 | $url_self, |
---|
60 | array('action'=>'add_to_caddie') |
---|
61 | ); |
---|
62 | |
---|
63 | $query = ' |
---|
64 | SELECT element_id FROM ' . CADDIE_TABLE . ' |
---|
65 | WHERE element_id = ' . $page['image_id'] .' |
---|
66 | ;'; |
---|
67 | $tpl_vars['IS_IN_CADDIE'] = pwg_db_num_rows(pwg_query($query)) > 0; |
---|
68 | |
---|
69 | if (isset($page['category'])) |
---|
70 | { |
---|
71 | $tpl_vars['CATEGORY_ID'] = $page['category']['id']; |
---|
72 | |
---|
73 | $tpl_vars['U_SET_REPRESENTATIVE'] = add_url_params( |
---|
74 | $url_self, |
---|
75 | array('action'=>'set_as_representative') |
---|
76 | ); |
---|
77 | |
---|
78 | $query = ' |
---|
79 | SELECT id FROM ' . CATEGORIES_TABLE.' |
---|
80 | WHERE id = ' . $page['category']['id'] .' |
---|
81 | AND representative_picture_id = ' . $page['image_id'] .' |
---|
82 | ;'; |
---|
83 | $tpl_vars['IS_REPRESENTATIVE'] = pwg_db_num_rows(pwg_query($query)) > 0; |
---|
84 | } |
---|
85 | |
---|
86 | $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=photo-' . $page['image_id'] |
---|
87 | .(isset($page['category']) ? '&cat_id=' . $page['category']['id'] : ''); |
---|
88 | } |
---|
89 | |
---|
90 | $tpl_vars['U_DELETE'] = add_url_params( |
---|
91 | $url_self, array( |
---|
92 | 'delete'=>'', |
---|
93 | 'pwg_token'=>get_pwg_token() |
---|
94 | ) |
---|
95 | ); |
---|
96 | |
---|
97 | // gets tags (full available list is loaded in ajax) |
---|
98 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); |
---|
99 | |
---|
100 | $query = ' |
---|
101 | SELECT id, name |
---|
102 | FROM '.IMAGE_TAG_TABLE.' AS it |
---|
103 | JOIN '.TAGS_TABLE.' AS t ON t.id = it.tag_id |
---|
104 | WHERE image_id = '.$page['image_id'].' |
---|
105 | ;'; |
---|
106 | $tag_selection = get_taglist($query); |
---|
107 | |
---|
108 | $tpl_vars['QUICK_EDIT'] = array( |
---|
109 | 'img' => $picture['current']['derivatives']['square']->get_url(), |
---|
110 | 'name' => $picture['current']['name'], |
---|
111 | 'comment' => $picture['current']['comment'], |
---|
112 | 'author' => $picture['current']['author'], |
---|
113 | 'level' => $picture['current']['level'], |
---|
114 | 'date_creation' => substr($picture['current']['date_creation'], 0, 10), |
---|
115 | 'date_creation_time' => substr($picture['current']['date_creation'], 11, 5), |
---|
116 | 'tag_selection' => $tag_selection, |
---|
117 | ); |
---|
118 | } |
---|
119 | // album page (admin only) |
---|
120 | else if ($MultiView->is_admin() and @$page['section'] == 'categories' and isset($page['category'])) |
---|
121 | { |
---|
122 | $url_self = duplicate_index_url(); |
---|
123 | |
---|
124 | $tpl_vars['IS_CATEGORY'] = true; |
---|
125 | $tpl_vars['CATEGORY_ID'] = $page['category']['id']; |
---|
126 | |
---|
127 | $template->clear_assign(array( |
---|
128 | 'U_EDIT', |
---|
129 | 'U_CADDIE', |
---|
130 | )); |
---|
131 | |
---|
132 | $tpl_vars['U_ADMIN_EDIT'] = $url_root . 'admin.php?page=album-' . $page['category']['id']; |
---|
133 | |
---|
134 | if (!empty($page['items'])) |
---|
135 | { |
---|
136 | $tpl_vars['U_CADDIE'] = add_url_params( |
---|
137 | $url_self, |
---|
138 | array('caddie'=>1) |
---|
139 | ); |
---|
140 | } |
---|
141 | |
---|
142 | $tpl_vars['QUICK_EDIT'] = array( |
---|
143 | 'img' => null, |
---|
144 | 'name' => $page['category']['name'], |
---|
145 | 'comment' => $page['category']['comment'], |
---|
146 | ); |
---|
147 | |
---|
148 | if (!empty($page['category']['representative_picture_id'])) |
---|
149 | { |
---|
150 | $query = ' |
---|
151 | SELECT * FROM '.IMAGES_TABLE.' |
---|
152 | WHERE id = '. $page['category']['representative_picture_id'] .' |
---|
153 | ;'; |
---|
154 | $image_infos = pwg_db_fetch_assoc(pwg_query($query)); |
---|
155 | |
---|
156 | $tpl_vars['QUICK_EDIT']['img'] = DerivativeImage::get_one(IMG_SQUARE, $image_infos)->get_url(); |
---|
157 | } |
---|
158 | } |
---|
159 | |
---|
160 | |
---|
161 | $template->assign(array( |
---|
162 | 'ADMINTOOLS_PATH' => './plugins/' . ADMINTOOLS_ID .'/', |
---|
163 | 'ato' => $tpl_vars, |
---|
164 | )); |
---|
165 | |
---|
166 | $template->set_filename('ato_public_controller', realpath(ADMINTOOLS_PATH . 'template/public_controller.tpl')); |
---|
167 | $template->parse('ato_public_controller'); |
---|
168 | |
---|
169 | if ($MultiView->is_admin()) |
---|
170 | { |
---|
171 | switch_lang_back(); |
---|
172 | } |
---|
173 | } |
---|
174 | |
---|
175 | /** |
---|
176 | * Disable privacy level switchbox |
---|
177 | */ |
---|
178 | function admintools_remove_privacy($content) |
---|
179 | { |
---|
180 | $search = '{if $display_info.privacy_level and isset($available_permission_levels)}'; |
---|
181 | $replace = '{if false}'; |
---|
182 | return str_replace($search, $replace, $content); |
---|
183 | } |
---|
184 | |
---|
185 | /** |
---|
186 | * Save picture form |
---|
187 | * @trigger loc_begin_picture |
---|
188 | */ |
---|
189 | function admintools_save_picture() |
---|
190 | { |
---|
191 | global $page, $conf, $MultiView, $user, $picture; |
---|
192 | |
---|
193 | if (!isset($_GET['delete']) and !isset($_POST['action']) and @$_POST['action'] != 'quick_edit') |
---|
194 | { |
---|
195 | return; |
---|
196 | } |
---|
197 | |
---|
198 | $query = 'SELECT added_by FROM '. IMAGES_TABLE .' WHERE id = '. $page['image_id'] .';'; |
---|
199 | list($added_by) = pwg_db_fetch_row(pwg_query($query)); |
---|
200 | |
---|
201 | if (!$MultiView->is_admin() and $user['id'] != $added_by) |
---|
202 | { |
---|
203 | return; |
---|
204 | } |
---|
205 | |
---|
206 | if (isset($_GET['delete']) and get_pwg_token()==@$_GET['pwg_token']) |
---|
207 | { |
---|
208 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); |
---|
209 | |
---|
210 | delete_elements(array($page['image_id']), true); |
---|
211 | invalidate_user_cache(); |
---|
212 | |
---|
213 | if (isset($page['category'])) |
---|
214 | { |
---|
215 | redirect( |
---|
216 | make_index_url( |
---|
217 | array( |
---|
218 | 'category' => $page['category'] |
---|
219 | ) |
---|
220 | ) |
---|
221 | ); |
---|
222 | } |
---|
223 | |
---|
224 | redirect(make_index_url()); |
---|
225 | } |
---|
226 | |
---|
227 | if ($_POST['action'] == 'quick_edit') |
---|
228 | { |
---|
229 | include_once(PHPWG_ROOT_PATH . 'admin/include/functions.php'); |
---|
230 | |
---|
231 | $data = array( |
---|
232 | 'name' => $_POST['name'], |
---|
233 | 'author' => $_POST['author'], |
---|
234 | ); |
---|
235 | |
---|
236 | if ($MultiView->is_admin()) |
---|
237 | { |
---|
238 | $data['level'] = $_POST['level']; |
---|
239 | } |
---|
240 | |
---|
241 | if ($conf['allow_html_descriptions']) |
---|
242 | { |
---|
243 | $data['comment'] = @$_POST['comment']; |
---|
244 | } |
---|
245 | else |
---|
246 | { |
---|
247 | $data['comment'] = strip_tags(@$_POST['comment']); |
---|
248 | } |
---|
249 | |
---|
250 | if (!empty($_POST['date_creation']) and strtotime($_POST['date_creation']) !== false) |
---|
251 | { |
---|
252 | $data['date_creation'] = $_POST['date_creation'] .' '. $_POST['date_creation_time']; |
---|
253 | } |
---|
254 | |
---|
255 | single_update( |
---|
256 | IMAGES_TABLE, |
---|
257 | $data, |
---|
258 | array('id' => $page['image_id']) |
---|
259 | ); |
---|
260 | |
---|
261 | $tag_ids = array(); |
---|
262 | if (!empty($_POST['tags'])) |
---|
263 | { |
---|
264 | $tag_ids = get_tag_ids($_POST['tags']); |
---|
265 | } |
---|
266 | set_tags($tag_ids, $page['image_id']); |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | /** |
---|
271 | * Save category form |
---|
272 | * @trigger loc_begin_index |
---|
273 | */ |
---|
274 | function admintools_save_category() |
---|
275 | { |
---|
276 | global $page, $conf, $MultiView; |
---|
277 | |
---|
278 | if (!$MultiView->is_admin()) |
---|
279 | { |
---|
280 | return; |
---|
281 | } |
---|
282 | |
---|
283 | if (@$_POST['action'] == 'quick_edit') |
---|
284 | { |
---|
285 | $data = array( |
---|
286 | 'name' => $_POST['name'], |
---|
287 | ); |
---|
288 | |
---|
289 | if ($conf['allow_html_descriptions']) |
---|
290 | { |
---|
291 | $data['comment'] = @$_POST['comment']; |
---|
292 | } |
---|
293 | else |
---|
294 | { |
---|
295 | $data['comment'] = strip_tags(@$_POST['comment']); |
---|
296 | } |
---|
297 | |
---|
298 | single_update( |
---|
299 | CATEGORIES_TABLE, |
---|
300 | $data, |
---|
301 | array('id' => $page['category']['id']) |
---|
302 | ); |
---|
303 | |
---|
304 | redirect(duplicate_index_url()); |
---|
305 | } |
---|
306 | } |
---|