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