1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | /** |
---|
5 | * detect 'subscriptions' section and load the page |
---|
6 | */ |
---|
7 | function stc_detect_section() |
---|
8 | { |
---|
9 | global $tokens, $page; |
---|
10 | |
---|
11 | if ($tokens[0] == 'subscriptions') |
---|
12 | { |
---|
13 | $page['section'] = 'subscriptions'; |
---|
14 | $page['title'] = l10n('Comments notifications'); |
---|
15 | } |
---|
16 | } |
---|
17 | |
---|
18 | function stc_load_section() |
---|
19 | { |
---|
20 | global $page; |
---|
21 | |
---|
22 | if (isset($page['section']) and $page['section'] == 'subscriptions') |
---|
23 | { |
---|
24 | include(SUBSCRIBE_TO_PATH.'include/subscribtions_page.inc.php'); |
---|
25 | } |
---|
26 | } |
---|
27 | |
---|
28 | |
---|
29 | /** |
---|
30 | * send notifications and/or add subscriber on comment insertion |
---|
31 | * @param: array comment |
---|
32 | */ |
---|
33 | function stc_comment_insertion($comm) |
---|
34 | { |
---|
35 | global $page, $template; |
---|
36 | |
---|
37 | if ($comm['action'] == 'validate') |
---|
38 | { |
---|
39 | send_comment_to_subscribers($comm); |
---|
40 | } |
---|
41 | |
---|
42 | if ( !empty($_POST['stc_mode']) and $_POST['stc_mode'] != -1 ) |
---|
43 | { |
---|
44 | if ($comm['action'] != 'reject') |
---|
45 | { |
---|
46 | if (isset($comm['image_id'])) |
---|
47 | { |
---|
48 | switch ($_POST['stc_mode']) |
---|
49 | { |
---|
50 | case 'all-images': |
---|
51 | subscribe_to_comments(@$_POST['stc_mail'], 'all-images'); |
---|
52 | break; |
---|
53 | case 'album-images': |
---|
54 | if (empty($page['category']['id'])) break; |
---|
55 | subscribe_to_comments(@$_POST['stc_mail'], 'album-images', $page['category']['id']); |
---|
56 | break; |
---|
57 | case 'image': |
---|
58 | subscribe_to_comments(@$_POST['stc_mail'], 'image', $comm['image_id']); |
---|
59 | break; |
---|
60 | } |
---|
61 | } |
---|
62 | else if (isset($comm['category_id'])) |
---|
63 | { |
---|
64 | switch ($_POST['stc_mode']) |
---|
65 | { |
---|
66 | case 'all-albums': |
---|
67 | subscribe_to_comments(@$_POST['stc_mail'], 'all-albums'); |
---|
68 | break; |
---|
69 | case 'album': |
---|
70 | subscribe_to_comments(@$_POST['stc_mail'], 'album', $comm['category_id']); |
---|
71 | break; |
---|
72 | } |
---|
73 | } |
---|
74 | } |
---|
75 | else |
---|
76 | { |
---|
77 | $template->assign('STC_MODE', $_POST['stc_mode']); |
---|
78 | $template->assign('STC_MAIL', @$_POST['stc_mail']); |
---|
79 | } |
---|
80 | } |
---|
81 | } |
---|
82 | |
---|
83 | |
---|
84 | /** |
---|
85 | * send notifications on comment validation |
---|
86 | * @param: array|int comment_id |
---|
87 | * @param: string type (image|category) |
---|
88 | */ |
---|
89 | function stc_comment_validation($comm_ids, $type='image') |
---|
90 | { |
---|
91 | if (!is_array($comm_ids)) $comm_ids = array($comm_ids); |
---|
92 | |
---|
93 | if ($type == 'image') |
---|
94 | { |
---|
95 | $query = ' |
---|
96 | SELECT |
---|
97 | id, |
---|
98 | image_id, |
---|
99 | author, |
---|
100 | content |
---|
101 | FROM '.COMMENTS_TABLE.' |
---|
102 | WHERE id IN('.implode(',', $comm_ids).') |
---|
103 | ;'; |
---|
104 | } |
---|
105 | else if ($type == 'category') |
---|
106 | { |
---|
107 | $query = ' |
---|
108 | SELECT |
---|
109 | id, |
---|
110 | category_id, |
---|
111 | author, |
---|
112 | content |
---|
113 | FROM '.COA_TABLE.' |
---|
114 | WHERE id IN('.implode(',', $comm_ids).') |
---|
115 | ;'; |
---|
116 | } |
---|
117 | |
---|
118 | $comms = hash_from_query($query, 'id'); |
---|
119 | foreach ($comms as $comm) |
---|
120 | { |
---|
121 | send_comment_to_subscribers($comm); |
---|
122 | } |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | /** |
---|
127 | * add field and link on picture page |
---|
128 | */ |
---|
129 | function stc_on_picture() |
---|
130 | { |
---|
131 | global $template, $picture, $page, $user, $conf; |
---|
132 | |
---|
133 | // standalone subscription |
---|
134 | if (isset($_POST['stc_submit'])) |
---|
135 | { |
---|
136 | switch ($_POST['stc_mode']) |
---|
137 | { |
---|
138 | case 'all-images': |
---|
139 | subscribe_to_comments(@$_POST['stc_mail'], 'all-images'); |
---|
140 | break; |
---|
141 | case 'album-images': |
---|
142 | if (empty($page['category']['id'])) break; |
---|
143 | subscribe_to_comments(@$_POST['stc_mail'], 'album-images', $page['category']['id']); |
---|
144 | break; |
---|
145 | case 'image': |
---|
146 | subscribe_to_comments(@$_POST['stc_mail'], 'image', $picture['current']['id']); |
---|
147 | break; |
---|
148 | } |
---|
149 | } |
---|
150 | else if (isset($_GET['stc_unsubscribe'])) |
---|
151 | { |
---|
152 | if (un_subscribe_to_comments(null, $_GET['stc_unsubscribe'])) |
---|
153 | { |
---|
154 | array_push($page['infos'], l10n('Successfully unsubscribed your email address from receiving notifications.')); |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | // if registered user with mail we check if already subscribed |
---|
159 | if ( !is_a_guest() and !empty($user['email']) ) |
---|
160 | { |
---|
161 | $subscribed = false; |
---|
162 | |
---|
163 | // registered to all pictures |
---|
164 | if (!$subscribed) |
---|
165 | { |
---|
166 | $query = ' |
---|
167 | SELECT id |
---|
168 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
169 | WHERE |
---|
170 | email = "'.$user['email'].'" |
---|
171 | AND type = "all-images" |
---|
172 | AND validated = "true" |
---|
173 | ;'; |
---|
174 | $result = pwg_query($query); |
---|
175 | |
---|
176 | if (pwg_db_num_rows($result)) |
---|
177 | { |
---|
178 | $template->assign(array( |
---|
179 | 'SUBSCRIBED_ALL_IMAGES' => true, |
---|
180 | 'MANAGE_LINK' => make_stc_url('manage', $user['email']), |
---|
181 | )); |
---|
182 | $subscribed = true; |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | // registered to pictures in this album |
---|
187 | if ( !$subscribed and !empty($page['category']['id']) ) |
---|
188 | { |
---|
189 | $query = ' |
---|
190 | SELECT id |
---|
191 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
192 | WHERE |
---|
193 | email = "'.$user['email'].'" |
---|
194 | AND element_id = '.$page['category']['id'].' |
---|
195 | AND type = "album-images" |
---|
196 | AND validated = "true" |
---|
197 | ;'; |
---|
198 | $result = pwg_query($query); |
---|
199 | |
---|
200 | if (pwg_db_num_rows($result)) |
---|
201 | { |
---|
202 | list($stc_id) = pwg_db_fetch_row($result); |
---|
203 | $template->assign(array( |
---|
204 | 'SUBSCRIBED_ALBUM_IMAGES' => true, |
---|
205 | 'UNSUB_LINK' => add_url_params($picture['current']['url'], array('stc_unsubscribe'=>$stc_id)), |
---|
206 | )); |
---|
207 | $subscribed = true; |
---|
208 | } |
---|
209 | } |
---|
210 | |
---|
211 | // registered to this picture |
---|
212 | if (!$subscribed) |
---|
213 | { |
---|
214 | $query = ' |
---|
215 | SELECT id |
---|
216 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
217 | WHERE |
---|
218 | email = "'.$user['email'].'" |
---|
219 | AND element_id = '.$picture['current']['id'].' |
---|
220 | AND type = "image" |
---|
221 | AND validated = "true" |
---|
222 | ;'; |
---|
223 | $result = pwg_query($query); |
---|
224 | |
---|
225 | if (pwg_db_num_rows($result)) |
---|
226 | { |
---|
227 | list($stc_id) = pwg_db_fetch_row($result); |
---|
228 | $template->assign(array( |
---|
229 | 'SUBSCRIBED_IMAGE' => true, |
---|
230 | 'UNSUB_LINK' => add_url_params($picture['current']['url'], array('stc_unsubscribe'=>$stc_id)), |
---|
231 | )); |
---|
232 | $subscribed = true; |
---|
233 | } |
---|
234 | } |
---|
235 | } |
---|
236 | else |
---|
237 | { |
---|
238 | $template->assign('STC_ASK_MAIL', true); |
---|
239 | } |
---|
240 | |
---|
241 | $template->assign('STC_ON_PICTURE', true); |
---|
242 | if ( !empty($page['category']['id']) ) $template->assign('STC_ALLOW_ALBUM_IMAGES', true); |
---|
243 | if ( $conf['Subscribe_to_Comments']['allow_global_subscriptions'] or is_admin() ) $template->assign('STC_ALLOW_GLOBAL', true); |
---|
244 | |
---|
245 | $template->set_prefilter('picture', 'stc_main_prefilter'); |
---|
246 | } |
---|
247 | |
---|
248 | |
---|
249 | /** |
---|
250 | * add field and link on album page |
---|
251 | */ |
---|
252 | function stc_on_album() |
---|
253 | { |
---|
254 | global $page, $template, $pwg_loaded_plugins, $user, $conf; |
---|
255 | |
---|
256 | if ( |
---|
257 | script_basename() != 'index' or !isset($page['section']) or |
---|
258 | !isset($pwg_loaded_plugins['Comments_on_Albums']) or |
---|
259 | $page['section'] != 'categories' or !isset($page['category']) |
---|
260 | ) |
---|
261 | { |
---|
262 | return; |
---|
263 | } |
---|
264 | |
---|
265 | if (isset($_POST['stc_submit'])) |
---|
266 | { |
---|
267 | switch ($_POST['stc_mode']) |
---|
268 | { |
---|
269 | case 'all-albums': |
---|
270 | subscribe_to_comments(@$_POST['stc_mail'], 'all-albums'); |
---|
271 | break; |
---|
272 | case 'album': |
---|
273 | subscribe_to_comments(@$_POST['stc_mail'], 'album', $page['category']['id']); |
---|
274 | break; |
---|
275 | } |
---|
276 | } |
---|
277 | else if (isset($_GET['stc_unsubscribe'])) |
---|
278 | { |
---|
279 | if (un_subscribe_to_comments(null, $_GET['stc_unsubscribe'])) |
---|
280 | { |
---|
281 | array_push($page['infos'], l10n('Successfully unsubscribed your email address from receiving notifications.')); |
---|
282 | } |
---|
283 | } |
---|
284 | |
---|
285 | // if registered user we check if already subscribed |
---|
286 | if ( !is_a_guest() and !empty($user['email']) ) |
---|
287 | { |
---|
288 | $subscribed = false; |
---|
289 | |
---|
290 | // registered to all albums |
---|
291 | if (!$subscribed) |
---|
292 | { |
---|
293 | $query = ' |
---|
294 | SELECT id |
---|
295 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
296 | WHERE |
---|
297 | email = "'.$user['email'].'" |
---|
298 | AND type = "all-albums" |
---|
299 | AND validated = "true" |
---|
300 | ;'; |
---|
301 | $result = pwg_query($query); |
---|
302 | |
---|
303 | if (pwg_db_num_rows($result)) |
---|
304 | { |
---|
305 | $template->assign(array( |
---|
306 | 'SUBSCRIBED_ALL_ALBUMS' => true, |
---|
307 | 'MANAGE_LINK' => make_stc_url('manage', $user['email']), |
---|
308 | )); |
---|
309 | $subscribed = true; |
---|
310 | } |
---|
311 | } |
---|
312 | |
---|
313 | // registered to this album |
---|
314 | if (!$subscribed) |
---|
315 | { |
---|
316 | $query = ' |
---|
317 | SELECT id |
---|
318 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
319 | WHERE |
---|
320 | email = "'.$user['email'].'" |
---|
321 | AND element_id = '.$page['category']['id'].' |
---|
322 | AND type = "album" |
---|
323 | AND validated = "true" |
---|
324 | ;'; |
---|
325 | $result = pwg_query($query); |
---|
326 | |
---|
327 | if (pwg_db_num_rows($result)) |
---|
328 | { |
---|
329 | list($stc_id) = pwg_db_fetch_row($result); |
---|
330 | $element_url = make_index_url(array( |
---|
331 | 'section' => 'categories', |
---|
332 | 'category' => $page['category'], |
---|
333 | )); |
---|
334 | |
---|
335 | $template->assign(array( |
---|
336 | 'SUBSCRIBED_ALBUM' => true, |
---|
337 | 'UNSUB_LINK' => add_url_params($element_url, array('stc_unsubscribe'=>$stc_id)), |
---|
338 | )); |
---|
339 | $subscribed = true; |
---|
340 | } |
---|
341 | } |
---|
342 | } |
---|
343 | else |
---|
344 | { |
---|
345 | $template->assign('STC_ASK_MAIL', true); |
---|
346 | } |
---|
347 | |
---|
348 | $template->assign('STC_ON_ALBUM', true); |
---|
349 | if ( $conf['Subscribe_to_Comments']['allow_global_subscriptions'] or is_admin() ) $template->assign('STC_ALLOW_GLOBAL', true); |
---|
350 | |
---|
351 | $template->set_prefilter('comments_on_albums', 'stc_main_prefilter'); |
---|
352 | } |
---|
353 | |
---|
354 | |
---|
355 | /** |
---|
356 | * main prefilter |
---|
357 | */ |
---|
358 | function stc_main_prefilter($content, &$smarty) |
---|
359 | { |
---|
360 | ## subscribe at any moment ## |
---|
361 | $search = '{if isset($comments)}'; |
---|
362 | $replace = file_get_contents(SUBSCRIBE_TO_PATH.'template/form_standalone.tpl'); |
---|
363 | $content = str_replace($search, $replace.$search, $content); |
---|
364 | |
---|
365 | ## subscribe while add a comment ## |
---|
366 | $search = '{$comment_add.CONTENT}</textarea></p>'; |
---|
367 | $replace = file_get_contents(SUBSCRIBE_TO_PATH.'template/form_comment.tpl'); |
---|
368 | $content = str_replace($search, $search.$replace, $content); |
---|
369 | |
---|
370 | return $content; |
---|
371 | } |
---|
372 | |
---|
373 | |
---|
374 | /** |
---|
375 | * delete subscriptions to deleted images or categories |
---|
376 | */ |
---|
377 | function stc_delete_elements($ids) |
---|
378 | { |
---|
379 | $query = ' |
---|
380 | DELETE FROM '.SUBSCRIBE_TO_TABLE.' |
---|
381 | WHERE |
---|
382 | element_id IN ('.implode(',', $ids).') |
---|
383 | AND type = "image" |
---|
384 | '; |
---|
385 | pwg_query($query); |
---|
386 | } |
---|
387 | function stc_delete_categories($ids) |
---|
388 | { |
---|
389 | $query = ' |
---|
390 | DELETE FROM '.SUBSCRIBE_TO_TABLE.' |
---|
391 | WHERE |
---|
392 | element_id IN ('.implode(',', $ids).') |
---|
393 | AND (type = "album" OR type = "album-images") |
---|
394 | '; |
---|
395 | pwg_query($query); |
---|
396 | } |
---|
397 | |
---|
398 | |
---|
399 | /** |
---|
400 | * add link to management page for registered users |
---|
401 | */ |
---|
402 | function stc_profile_link() |
---|
403 | { |
---|
404 | global $template, $user; |
---|
405 | |
---|
406 | if (!empty($user['email'])) |
---|
407 | { |
---|
408 | $template->assign('MANAGE_LINK', make_stc_url('manage', $user['email']) ); |
---|
409 | $template->set_prefilter('profile_content', 'stc_profile_link_prefilter'); |
---|
410 | } |
---|
411 | } |
---|
412 | function stc_profile_link_prefilter($content, &$smarty) |
---|
413 | { |
---|
414 | $search = '<p class="bottomButtons">'; |
---|
415 | $replace = '<p style="font-size:1.1em;text-decoration:underline;"><a href="{$MANAGE_LINK}" rel="nofollow">{\'Manage my subscriptions\'|@translate}</a></p>'; |
---|
416 | |
---|
417 | return str_replace($search, $replace.$search, $content); |
---|
418 | } |
---|
419 | |
---|
420 | ?> |
---|