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; |
---|
32 | |
---|
33 | if ($comm['action'] == 'validate') |
---|
34 | { |
---|
35 | send_comment_to_subscribers($comm); |
---|
36 | } |
---|
37 | |
---|
38 | if ( !empty($_POST['stc_check']) and ( $comm['action'] == 'validate' or $comm['action'] == 'moderate' ) ) |
---|
39 | { |
---|
40 | if (isset($comm['image_id'])) |
---|
41 | { |
---|
42 | subscribe_to_comments($comm['image_id'], @$_POST['stc_mail'], 'image'); |
---|
43 | } |
---|
44 | else if (isset($comm['category_id'])) |
---|
45 | { |
---|
46 | subscribe_to_comments($comm['category_id'], @$_POST['stc_mail'], 'category'); |
---|
47 | } |
---|
48 | } |
---|
49 | } |
---|
50 | |
---|
51 | function stc_comment_validation($comm_id, $type='image') |
---|
52 | { |
---|
53 | switch ($type) |
---|
54 | { |
---|
55 | case 'image': |
---|
56 | { |
---|
57 | $query = ' |
---|
58 | SELECT |
---|
59 | id, |
---|
60 | image_id, |
---|
61 | author, |
---|
62 | content |
---|
63 | FROM '.COMMENTS_TABLE.' |
---|
64 | WHERE id = '.$comm_id.' |
---|
65 | ;'; |
---|
66 | break; |
---|
67 | } |
---|
68 | |
---|
69 | case 'category': |
---|
70 | { |
---|
71 | $query = ' |
---|
72 | SELECT |
---|
73 | id, |
---|
74 | category_id, |
---|
75 | author, |
---|
76 | content |
---|
77 | FROM '.COA_TABLE.' |
---|
78 | WHERE id = '.$comm_id.' |
---|
79 | ;'; |
---|
80 | break; |
---|
81 | } |
---|
82 | } |
---|
83 | |
---|
84 | $comm = pwg_db_fetch_assoc(pwg_query($query)); |
---|
85 | send_comment_to_subscribers($comm); |
---|
86 | } |
---|
87 | |
---|
88 | |
---|
89 | /** |
---|
90 | * add field and link on picture page |
---|
91 | */ |
---|
92 | function stc_on_picture() |
---|
93 | { |
---|
94 | global $template, $picture; |
---|
95 | |
---|
96 | if (isset($_POST['stc_check_stdl'])) |
---|
97 | { |
---|
98 | subscribe_to_comments($picture['current']['id'], @$_POST['stc_mail_stdl'], 'image'); |
---|
99 | } |
---|
100 | |
---|
101 | $template->set_prefilter('picture', 'stc_on_picture_prefilter'); |
---|
102 | } |
---|
103 | |
---|
104 | function stc_on_picture_prefilter($template, &$smarty) |
---|
105 | { |
---|
106 | global $user, $picture; |
---|
107 | |
---|
108 | ## subscribe while add a comment ## |
---|
109 | $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">'; |
---|
110 | |
---|
111 | $replace[0] = ' |
---|
112 | <label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>'; |
---|
113 | if (is_a_guest()) |
---|
114 | { |
---|
115 | $replace[0].= ' |
---|
116 | <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label> |
---|
117 | {footer_script require="jquery"}{literal} |
---|
118 | jQuery(document).ready(function() { |
---|
119 | $("input[name=stc_check]").change(function() { |
---|
120 | if ($(this).is(":checked")) $("#stc_mail").css("display", ""); |
---|
121 | else $("#stc_mail").css("display", "none"); |
---|
122 | }); |
---|
123 | }); |
---|
124 | {/literal}{/footer_script}'; |
---|
125 | } |
---|
126 | $replace[0].= $search[0]; |
---|
127 | |
---|
128 | |
---|
129 | ## subscribe at any moment ## |
---|
130 | $search[1] = '{if isset($comment_add)}'; |
---|
131 | |
---|
132 | $replace[1] = $search[1].' |
---|
133 | <form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone"> |
---|
134 | <fieldset>'; |
---|
135 | |
---|
136 | // if registered user we check if already subscribed |
---|
137 | if (!is_a_guest()) |
---|
138 | { |
---|
139 | $query = ' |
---|
140 | SELECT id |
---|
141 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
142 | WHERE |
---|
143 | email = "'.$user['email'].'" |
---|
144 | AND image_id = '.$picture['current']['id'].' |
---|
145 | ;'; |
---|
146 | if (pwg_db_num_rows(pwg_query($query))) |
---|
147 | { |
---|
148 | $replace[1].= ' |
---|
149 | {\'You are currently subscribed to comments of this picture.\'|@translate} |
---|
150 | <a href="'.make_stc_url('unsubscribe-image', $user['email'], $picture['current']['id']).'">{\'Unsubscribe\'|@translate}'; |
---|
151 | $no_form = true; |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | if (!isset($no_form)) |
---|
156 | { |
---|
157 | $replace[1].= ' |
---|
158 | <label><a href="#" id="stc_check_stdl">{\'Subscribe to new comments\'|@translate}</a> <input type="checkbox" name="stc_check_stdl" value="1" style="display:none;"></label>'; |
---|
159 | |
---|
160 | // form for guests |
---|
161 | if (is_a_guest()) |
---|
162 | { |
---|
163 | $replace[1].= ' |
---|
164 | <label style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label> |
---|
165 | <label style="display:none;"><input type="submit" value="{\'Submit\'|@translate}"></label> |
---|
166 | {footer_script require="jquery"}{literal} |
---|
167 | jQuery(document).ready(function() { |
---|
168 | $("a#stc_check_stdl").click(function() { |
---|
169 | $("input[name=stc_check_stdl]").prop("checked", true); |
---|
170 | $("#stc_standalone label").toggle(); |
---|
171 | return false; |
---|
172 | }); |
---|
173 | }); |
---|
174 | {/literal}{/footer_script}'; |
---|
175 | } |
---|
176 | // simple link for registered users |
---|
177 | else |
---|
178 | { |
---|
179 | $replace[1].= ' |
---|
180 | {footer_script require="jquery"}{literal} |
---|
181 | jQuery(document).ready(function() { |
---|
182 | $("a#stc_check_stdl").click(function() { |
---|
183 | $("input[name=stc_check_stdl]").prop("checked", true); |
---|
184 | $(this).parents("form#stc_standalone").submit(); |
---|
185 | return false; |
---|
186 | }); |
---|
187 | }); |
---|
188 | {/literal}{/footer_script}'; |
---|
189 | } |
---|
190 | } |
---|
191 | |
---|
192 | $replace[1].= ' |
---|
193 | </fieldset> |
---|
194 | </form>'; |
---|
195 | |
---|
196 | return str_replace($search, $replace, $template); |
---|
197 | } |
---|
198 | |
---|
199 | |
---|
200 | /** |
---|
201 | * add field and on album page |
---|
202 | */ |
---|
203 | function stc_on_album() |
---|
204 | { |
---|
205 | global $page, $template, $pwg_loaded_plugins; |
---|
206 | |
---|
207 | if ( |
---|
208 | script_basename() != 'index' or !isset($page['section']) or |
---|
209 | !isset($pwg_loaded_plugins['Comments_on_Albums']) or |
---|
210 | $page['section'] != 'categories' or !isset($page['category']) |
---|
211 | ) |
---|
212 | { |
---|
213 | return; |
---|
214 | } |
---|
215 | |
---|
216 | if (isset($_POST['stc_check_stdl'])) |
---|
217 | { |
---|
218 | subscribe_to_comments($page['category']['id'], @$_POST['stc_mail_stdl'], 'category'); |
---|
219 | } |
---|
220 | |
---|
221 | $template->set_prefilter('comments_on_albums', 'stc_on_album_prefilter'); |
---|
222 | } |
---|
223 | |
---|
224 | function stc_on_album_prefilter($template, &$smarty) |
---|
225 | { |
---|
226 | global $user, $page; |
---|
227 | |
---|
228 | ## subscribe while add a comment ## |
---|
229 | $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">'; |
---|
230 | |
---|
231 | $replace[0] = ' |
---|
232 | <label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>'; |
---|
233 | if (is_a_guest()) |
---|
234 | { |
---|
235 | $replace[0].= ' |
---|
236 | <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label> |
---|
237 | {footer_script require="jquery"}{literal} |
---|
238 | jQuery(document).ready(function() { |
---|
239 | $("input[name=stc_check]").change(function() { |
---|
240 | if ($(this).is(":checked")) $("#stc_mail").css("display", ""); |
---|
241 | else $("#stc_mail").css("display", "none"); |
---|
242 | }); |
---|
243 | }); |
---|
244 | {/literal}{/footer_script}'; |
---|
245 | } |
---|
246 | $replace[0].= $search[0]; |
---|
247 | |
---|
248 | |
---|
249 | ## subscribe at any moment ## |
---|
250 | $search[1] = '{if isset($comment_add)}'; |
---|
251 | |
---|
252 | $replace[1] = $search[1].' |
---|
253 | <form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone"> |
---|
254 | <fieldset>'; |
---|
255 | |
---|
256 | // if registered user we check if already subscribed |
---|
257 | if (!is_a_guest()) |
---|
258 | { |
---|
259 | $query = ' |
---|
260 | SELECT id |
---|
261 | FROM '.SUBSCRIBE_TO_TABLE.' |
---|
262 | WHERE |
---|
263 | email = "'.$user['email'].'" |
---|
264 | AND category_id = '.$page['category']['id'].' |
---|
265 | ;'; |
---|
266 | if (pwg_db_num_rows(pwg_query($query))) |
---|
267 | { |
---|
268 | $replace[1].= ' |
---|
269 | {\'You are currently subscribed to comments of this album.\'|@translate} |
---|
270 | <a href="'.make_stc_url('unsubscribe-category', $user['email'], $page['category']['id']).'">{\'Unsubscribe\'|@translate}'; |
---|
271 | $no_form = true; |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | if (!isset($no_form)) |
---|
276 | { |
---|
277 | $replace[1].= ' |
---|
278 | <label><a href="#" id="stc_check_stdl">{\'Subscribe to new comments\'|@translate}</a> <input type="checkbox" name="stc_check_stdl" value="1" style="display:none;"></label>'; |
---|
279 | |
---|
280 | // form for guests |
---|
281 | if (is_a_guest()) |
---|
282 | { |
---|
283 | $replace[1].= ' |
---|
284 | <label style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label> |
---|
285 | <label style="display:none;"><input type="submit" value="{\'Submit\'|@translate}"></label> |
---|
286 | {footer_script require="jquery"}{literal} |
---|
287 | jQuery(document).ready(function() { |
---|
288 | $("a#stc_check_stdl").click(function() { |
---|
289 | $("input[name=stc_check_stdl]").prop("checked", true); |
---|
290 | $("#stc_standalone label").toggle(); |
---|
291 | return false; |
---|
292 | }); |
---|
293 | }); |
---|
294 | {/literal}{/footer_script}'; |
---|
295 | } |
---|
296 | // simple link for registered users |
---|
297 | else |
---|
298 | { |
---|
299 | $replace[1].= ' |
---|
300 | {footer_script require="jquery"}{literal} |
---|
301 | jQuery(document).ready(function() { |
---|
302 | $("a#stc_check_stdl").click(function() { |
---|
303 | $("input[name=stc_check_stdl]").prop("checked", true); |
---|
304 | $(this).parents("form#stc_standalone").submit(); |
---|
305 | return false; |
---|
306 | }); |
---|
307 | }); |
---|
308 | {/literal}{/footer_script}'; |
---|
309 | } |
---|
310 | } |
---|
311 | |
---|
312 | $replace[1].= ' |
---|
313 | </fieldset> |
---|
314 | </form>'; |
---|
315 | |
---|
316 | return str_replace($search, $replace, $template); |
---|
317 | } |
---|
318 | |
---|
319 | ?> |
---|