1 | <?php |
---|
2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
3 | |
---|
4 | /** |
---|
5 | * detect 'subscriptions' section and load page |
---|
6 | */ |
---|
7 | function stc_detect_section() { |
---|
8 | global $tokens, $page; |
---|
9 | |
---|
10 | if ($tokens[0] == 'subscriptions') |
---|
11 | { |
---|
12 | $page['section'] = 'subscriptions'; |
---|
13 | } |
---|
14 | } |
---|
15 | |
---|
16 | function stc_load_section() { |
---|
17 | global $page; |
---|
18 | |
---|
19 | if (isset($page['section']) and $page['section'] == 'subscriptions') |
---|
20 | { |
---|
21 | include(SUBSCRIBE_TO_PATH.'include/subscribtions_page.inc.php'); |
---|
22 | } |
---|
23 | } |
---|
24 | |
---|
25 | |
---|
26 | /** |
---|
27 | * send notifications and/or add subscriber |
---|
28 | */ |
---|
29 | function stc_comment_insertion($comm) |
---|
30 | { |
---|
31 | global $page, $template; |
---|
32 | |
---|
33 | $infos = $errors = array(); |
---|
34 | |
---|
35 | if ($comm['action'] == 'validate') |
---|
36 | { |
---|
37 | send_comment_to_subscribers($comm); |
---|
38 | } |
---|
39 | |
---|
40 | if ( !empty($_POST['stc_check']) and ( $comm['action'] == 'validate' or $comm['action'] == 'moderate' ) ) |
---|
41 | { |
---|
42 | if (isset($comm['image_id'])) |
---|
43 | { |
---|
44 | $return = subscribe_to_comments($comm['image_id'], @$_POST['stc_mail'], 'image'); |
---|
45 | } |
---|
46 | else if (isset($comm['category_id'])) |
---|
47 | { |
---|
48 | $return = subscribe_to_comments($comm['category_id'], @$_POST['stc_mail'], 'category'); |
---|
49 | |
---|
50 | } |
---|
51 | |
---|
52 | if (isset($return)) |
---|
53 | { |
---|
54 | if ($return === 'confirm_mail') |
---|
55 | { |
---|
56 | array_push($infos, l10n('Please check your email inbox to confirm your subscription.')); |
---|
57 | } |
---|
58 | else if ($return === true) |
---|
59 | { |
---|
60 | array_push($infos, l10n('You have been added to the list of subscribers for this '.(isset($comm['image_id'])?'picture':'album').'.')); |
---|
61 | } |
---|
62 | else |
---|
63 | { |
---|
64 | array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.')); |
---|
65 | } |
---|
66 | |
---|
67 | // messages management |
---|
68 | if (!empty($errors)) |
---|
69 | { |
---|
70 | $errors_bak = $template->get_template_vars('errors'); |
---|
71 | if (empty($errors_bak)) $errors_bak = array(); |
---|
72 | $template->assign('errors', array_merge($errors_bak, $errors)); |
---|
73 | $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA |
---|
74 | } |
---|
75 | if (!empty($infos)) |
---|
76 | { |
---|
77 | $infos_bak = $template->get_template_vars('infos'); |
---|
78 | if (empty($infos_bak)) $infos_bak = array(); |
---|
79 | $template->assign('infos', array_merge($infos_bak, $infos)); |
---|
80 | $template->set_prefilter('index', 'coa_messages'); |
---|
81 | } |
---|
82 | } |
---|
83 | } |
---|
84 | } |
---|
85 | |
---|
86 | function stc_comment_validation($comm_ids, $type='image') |
---|
87 | { |
---|
88 | if (!is_array($comm_ids)) $comm_ids = array($comm_ids); |
---|
89 | |
---|
90 | foreach($comm_ids as $comm_id) |
---|
91 | { |
---|
92 | if ($type == 'image') |
---|
93 | { |
---|
94 | $query = ' |
---|
95 | SELECT |
---|
96 | id, |
---|
97 | image_id, |
---|
98 | author, |
---|
99 | content |
---|
100 | FROM '.COMMENTS_TABLE.' |
---|
101 | WHERE id = '.$comm_id.' |
---|
102 | ;'; |
---|
103 | } |
---|
104 | else if ($type == 'category') |
---|
105 | { |
---|
106 | $query = ' |
---|
107 | SELECT |
---|
108 | id, |
---|
109 | category_id, |
---|
110 | author, |
---|
111 | content |
---|
112 | FROM '.COA_TABLE.' |
---|
113 | WHERE id = '.$comm_id.' |
---|
114 | ;'; |
---|
115 | } |
---|
116 | |
---|
117 | $comm = pwg_db_fetch_assoc(pwg_query($query)); |
---|
118 | send_comment_to_subscribers($comm); |
---|
119 | } |
---|
120 | } |
---|
121 | |
---|
122 | |
---|
123 | /** |
---|
124 | * add field and link on picture page |
---|
125 | */ |
---|
126 | function stc_on_picture() |
---|
127 | { |
---|
128 | global $template, $picture, $page; |
---|
129 | |
---|
130 | $infos = $array = array(); |
---|
131 | |
---|
132 | if (isset($_POST['stc_submit'])) |
---|
133 | { |
---|
134 | $return = subscribe_to_comments($picture['current']['id'], @$_POST['stc_mail_stdl'], 'image'); |
---|
135 | if ($return === 'confirm_mail') |
---|
136 | { |
---|
137 | array_push($infos, l10n('Please check your email inbox to confirm your subscription.')); |
---|
138 | } |
---|
139 | else if ($return === true) |
---|
140 | { |
---|
141 | array_push($infos, l10n('You have been added to the list of subscribers for this picture.')); |
---|
142 | } |
---|
143 | else |
---|
144 | { |
---|
145 | array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.')); |
---|
146 | } |
---|
147 | } |
---|
148 | else if (isset($_GET['stc_unsubscribe'])) |
---|
149 | { |
---|
150 | if (un_subscribe_to_comments($picture['current']['id'], null, 'image')) |
---|
151 | { |
---|
152 | array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.')); |
---|
153 | } |
---|
154 | } |
---|
155 | |
---|
156 | // messages management |
---|
157 | if (!empty($errors)) |
---|
158 | { |
---|
159 | $errors_bak = $template->get_template_vars('errors'); |
---|
160 | if (empty($errors_bak)) $errors_bak = array(); |
---|
161 | $template->assign('errors', array_merge($errors_bak, $errors)); |
---|
162 | } |
---|
163 | if (!empty($infos)) |
---|
164 | { |
---|
165 | $infos_bak = $template->get_template_vars('infos'); |
---|
166 | if (empty($infos_bak)) $infos_bak = array(); |
---|
167 | $template->assign('infos', array_merge($infos_bak, $infos)); |
---|
168 | } |
---|
169 | |
---|
170 | $template->set_prefilter('picture', 'stc_on_picture_prefilter'); |
---|
171 | } |
---|
172 | |
---|
173 | function stc_on_picture_prefilter($content, &$smarty) |
---|
174 | { |
---|
175 | global $user, $picture; |
---|
176 | |
---|
177 | // if registered user with mail we check if already subscribed |
---|
178 | $subscribed = false; |
---|
179 | if ( !is_a_guest() and !empty($user['email']) ) |
---|
180 | { |
---|
181 | $query = ' |
---|
182 | SELECT id |
---|
183 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
184 | WHERE |
---|
185 | email = "'.$user['email'].'" |
---|
186 | AND image_id = '.$picture['current']['id'].' |
---|
187 | AND validated = "true" |
---|
188 | ;'; |
---|
189 | if (pwg_db_num_rows(pwg_query($query))) |
---|
190 | { |
---|
191 | $subscribed = true; |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | ## subscribe at any moment ## |
---|
196 | $search = '#\<\/div\>(.{0,5})\{\/if\}(.{0,5})\{\*comments\*\}#is'; |
---|
197 | |
---|
198 | $replace = ' |
---|
199 | <form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone"> |
---|
200 | <fieldset>'; |
---|
201 | |
---|
202 | if ($subscribed) |
---|
203 | { |
---|
204 | $replace.= ' |
---|
205 | {\'You are currently subscribed to comments of this picture.\'|@translate} |
---|
206 | <a href="'.add_url_params($picture['current']['url'], array('stc_unsubscribe'=>'1')).'">{\'Unsubscribe\'|@translate}'; |
---|
207 | } |
---|
208 | else |
---|
209 | { |
---|
210 | $replace.= ' |
---|
211 | <legend>{\'Subscribe without commenting\'|@translate}</legend>'; |
---|
212 | if ( is_a_guest() or empty($user['email']) ) // email input for guest or users without mail |
---|
213 | { |
---|
214 | $replace.= ' |
---|
215 | <label>{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label> |
---|
216 | <label><input type="submit" name="stc_submit" value="{\'Submit\'|@translate}"></label>'; |
---|
217 | } |
---|
218 | else |
---|
219 | { |
---|
220 | $replace.= ' |
---|
221 | <label><input type="submit" name="stc_submit" value="{\'Subscribe\'|@translate}"></label>'; |
---|
222 | } |
---|
223 | } |
---|
224 | |
---|
225 | $replace.= ' |
---|
226 | </fieldset> |
---|
227 | </form> |
---|
228 | </div> |
---|
229 | {/if}{*comments*}'; |
---|
230 | |
---|
231 | $content = preg_replace($search, $replace, $content); |
---|
232 | |
---|
233 | |
---|
234 | ## subscribe while add a comment ## |
---|
235 | $search = '<input type="submit" value="{\'Submit\'|@translate}">'; |
---|
236 | $replace = null; |
---|
237 | |
---|
238 | if (!$subscribed) |
---|
239 | { |
---|
240 | $replace.= ' |
---|
241 | <label>{\'Notify me of followup comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>'; |
---|
242 | } |
---|
243 | if ( is_a_guest() or empty($user['email']) ) |
---|
244 | { |
---|
245 | $replace.= ' |
---|
246 | <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label> |
---|
247 | {footer_script require="jquery"}{literal} |
---|
248 | jQuery(document).ready(function() { |
---|
249 | $("input[name=stc_check]").change(function() { |
---|
250 | if ($(this).is(":checked")) $("#stc_mail").css("display", ""); |
---|
251 | else $("#stc_mail").css("display", "none"); |
---|
252 | }); |
---|
253 | }); |
---|
254 | {/literal}{/footer_script}'; |
---|
255 | } |
---|
256 | $replace.= $search; |
---|
257 | |
---|
258 | $content = str_replace($search, $replace, $content); |
---|
259 | |
---|
260 | return $content; |
---|
261 | } |
---|
262 | |
---|
263 | |
---|
264 | /** |
---|
265 | * add field and on album page |
---|
266 | */ |
---|
267 | function stc_on_album() |
---|
268 | { |
---|
269 | global $page, $template, $pwg_loaded_plugins; |
---|
270 | |
---|
271 | $infos = $errors = array(); |
---|
272 | |
---|
273 | if ( |
---|
274 | script_basename() != 'index' or !isset($page['section']) or |
---|
275 | !isset($pwg_loaded_plugins['Comments_on_Albums']) or |
---|
276 | $page['section'] != 'categories' or !isset($page['category']) |
---|
277 | ) |
---|
278 | { |
---|
279 | return; |
---|
280 | } |
---|
281 | |
---|
282 | if (isset($_POST['stc_submit'])) |
---|
283 | { |
---|
284 | $return = subscribe_to_comments($page['category']['id'], @$_POST['stc_mail_stdl'], 'category'); |
---|
285 | if ($return === 'confirm_mail') |
---|
286 | { |
---|
287 | array_push($infos, l10n('Please check your email inbox to confirm your subscription.')); |
---|
288 | } |
---|
289 | else if ($return === true) |
---|
290 | { |
---|
291 | array_push($infos, l10n('You have been added to the list of subscribers for this album.')); |
---|
292 | } |
---|
293 | else |
---|
294 | { |
---|
295 | array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.')); |
---|
296 | } |
---|
297 | } |
---|
298 | else if (isset($_GET['stc_unsubscribe'])) |
---|
299 | { |
---|
300 | if (un_subscribe_to_comments($page['category']['id'], null, 'category')) |
---|
301 | { |
---|
302 | array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.')); |
---|
303 | } |
---|
304 | } |
---|
305 | |
---|
306 | // messages management |
---|
307 | if (!empty($errors)) |
---|
308 | { |
---|
309 | $errors_bak = $template->get_template_vars('errors'); |
---|
310 | if (empty($errors_bak)) $errors_bak = array(); |
---|
311 | $template->assign('errors', array_merge($errors_bak, $errors)); |
---|
312 | $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA |
---|
313 | } |
---|
314 | if (!empty($infos)) |
---|
315 | { |
---|
316 | $infos_bak = $template->get_template_vars('infos'); |
---|
317 | if (empty($infos_bak)) $infos_bak = array(); |
---|
318 | $template->assign('infos', array_merge($infos_bak, $infos)); |
---|
319 | $template->set_prefilter('index', 'coa_messages'); |
---|
320 | } |
---|
321 | |
---|
322 | $template->set_prefilter('comments_on_albums', 'stc_on_album_prefilter'); |
---|
323 | } |
---|
324 | |
---|
325 | function stc_on_album_prefilter($content, &$smarty) |
---|
326 | { |
---|
327 | global $user, $page; |
---|
328 | |
---|
329 | // if registered user we check if already subscribed |
---|
330 | $subscribed = false; |
---|
331 | if ( !is_a_guest() and !empty($user['email']) ) |
---|
332 | { |
---|
333 | $query = ' |
---|
334 | SELECT id |
---|
335 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
336 | WHERE |
---|
337 | email = "'.$user['email'].'" |
---|
338 | AND category_id = '.$page['category']['id'].' |
---|
339 | AND validated = "true" |
---|
340 | ;'; |
---|
341 | if (pwg_db_num_rows(pwg_query($query))) |
---|
342 | { |
---|
343 | $subscribed = true; |
---|
344 | } |
---|
345 | } |
---|
346 | |
---|
347 | ## subscribe at any moment ## |
---|
348 | $search = '#\<\/div\>(.{0,5})\{\/if\}(.{0,5})\{\*comments\*\}#is'; |
---|
349 | |
---|
350 | $replace = ' |
---|
351 | <form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone"> |
---|
352 | <fieldset>'; |
---|
353 | |
---|
354 | if ($subscribed) |
---|
355 | { |
---|
356 | $url_params['section'] = 'categories'; |
---|
357 | $url_params['category'] = $page['category']; |
---|
358 | |
---|
359 | $element_url = make_index_url($url_params); |
---|
360 | |
---|
361 | $replace.= ' |
---|
362 | {\'You are currently subscribed to comments of this album.\'|@translate} |
---|
363 | <a href="'.add_url_params($element_url, array('stc_unsubscribe'=>'1')).'">{\'Unsubscribe\'|@translate}'; |
---|
364 | } |
---|
365 | else |
---|
366 | { |
---|
367 | $replace.= ' |
---|
368 | <legend>{\'Subscribe without commenting\'|@translate}</legend>'; |
---|
369 | if ( is_a_guest() or empty($user['email']) ) // email input for guest or users without mail |
---|
370 | { |
---|
371 | $replace.= ' |
---|
372 | <label>{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label> |
---|
373 | <label><input type="submit" name="stc_submit" value="{\'Submit\'|@translate}"></label>'; |
---|
374 | } |
---|
375 | else |
---|
376 | { |
---|
377 | $replace.= ' |
---|
378 | <label><input type="submit" name="stc_submit" value="{\'Subscribe\'|@translate}"></label>'; |
---|
379 | } |
---|
380 | } |
---|
381 | |
---|
382 | $replace.= ' |
---|
383 | </fieldset> |
---|
384 | </form> |
---|
385 | </div> |
---|
386 | {/if}{*comments*}'; |
---|
387 | |
---|
388 | $content = preg_replace($search, $replace, $content); |
---|
389 | |
---|
390 | |
---|
391 | ## subscribe while add a comment ## |
---|
392 | $search = '<input type="submit" value="{\'Submit\'|@translate}">'; |
---|
393 | $replace = null; |
---|
394 | |
---|
395 | if (!$subscribed) |
---|
396 | { |
---|
397 | $replace.= ' |
---|
398 | <label>{\'Notify me of followup comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>'; |
---|
399 | } |
---|
400 | if ( is_a_guest() or empty($user['email']) ) |
---|
401 | { |
---|
402 | $replace.= ' |
---|
403 | <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label> |
---|
404 | {footer_script require="jquery"}{literal} |
---|
405 | jQuery(document).ready(function() { |
---|
406 | $("input[name=stc_check]").change(function() { |
---|
407 | if ($(this).is(":checked")) $("#stc_mail").css("display", ""); |
---|
408 | else $("#stc_mail").css("display", "none"); |
---|
409 | }); |
---|
410 | }); |
---|
411 | {/literal}{/footer_script}'; |
---|
412 | } |
---|
413 | $replace.= $search; |
---|
414 | |
---|
415 | $content = str_replace($search, $replace, $content); |
---|
416 | |
---|
417 | return $content; |
---|
418 | } |
---|
419 | |
---|
420 | |
---|
421 | /** |
---|
422 | * add link to management page for registered users |
---|
423 | */ |
---|
424 | function stc_profile_link() |
---|
425 | { |
---|
426 | global $template, $user; |
---|
427 | |
---|
428 | if (!empty($user['email'])) |
---|
429 | { |
---|
430 | $template->set_prefilter('profile_content', 'stc_profile_link_prefilter'); |
---|
431 | } |
---|
432 | } |
---|
433 | |
---|
434 | function stc_profile_link_prefilter($content, &$smarty) |
---|
435 | { |
---|
436 | global $user; |
---|
437 | |
---|
438 | $search = '<p class="bottomButtons">'; |
---|
439 | $replace = '<a href="'.make_stc_url('manage', $user['email']).'" title="{\'Manage my subscriptions to comments\'|@translate}" rel="nofollow">{\'Manage my subscriptions to comments\'|@translate}</a><br>'; |
---|
440 | |
---|
441 | return str_replace($search, $search.$replace, $content); |
---|
442 | } |
---|
443 | ?> |
---|