- Timestamp:
- Jun 11, 2012, 10:10:56 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Subscribe_to_comments/include/subscribe_to_comments.inc.php
r12709 r15641 3 3 4 4 /** 5 * detect 'subscriptions' section and load page5 * detect 'subscriptions' section and load the page 6 6 */ 7 7 function stc_detect_section() … … 12 12 { 13 13 $page['section'] = 'subscriptions'; 14 $page['title'] = l10n('Comments notifications'); 14 15 } 15 16 } … … 27 28 28 29 /** 29 * send notifications and/or add subscriber 30 * send notifications and/or add subscriber on comment insertion 31 * @param: array comment 30 32 */ 31 33 function stc_comment_insertion($comm) … … 33 35 global $page, $template; 34 36 35 $infos = $errors = array();36 37 37 if ($comm['action'] == 'validate') 38 38 { … … 40 40 } 41 41 42 if ( !empty($_POST['stc_check']) and ( $comm['action'] == 'validate' or $comm['action'] == 'moderate' ) ) 43 { 44 if (isset($comm['image_id'])) 45 { 46 $return = subscribe_to_comments($comm['image_id'], @$_POST['stc_mail'], 'image'); 47 } 48 else if (isset($comm['category_id'])) 49 { 50 $return = subscribe_to_comments($comm['category_id'], @$_POST['stc_mail'], 'category'); 51 52 } 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 69 // messages management 70 stc_add_messages($errors, $infos, true); 71 } 72 } 73 } 74 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 */ 75 89 function stc_comment_validation($comm_ids, $type='image') 76 90 { 77 91 if (!is_array($comm_ids)) $comm_ids = array($comm_ids); 78 92 79 foreach($comm_ids as $comm_id) 80 { 81 if ($type == 'image') 82 { 83 $query = ' 93 if ($type == 'image') 94 { 95 $query = ' 84 96 SELECT 85 97 id, … … 88 100 content 89 101 FROM '.COMMENTS_TABLE.' 90 WHERE id = '.$comm_id.'91 ;'; 92 93 94 95 102 WHERE id IN('.implode(',', $comm_ids).') 103 ;'; 104 } 105 else if ($type == 'category') 106 { 107 $query = ' 96 108 SELECT 97 109 id, … … 100 112 content 101 113 FROM '.COA_TABLE.' 102 WHERE id = '.$comm_id.' 103 ;'; 104 } 105 106 $comm = pwg_db_fetch_assoc(pwg_query($query)); 114 WHERE id IN('.implode(',', $comm_ids).') 115 ;'; 116 } 117 118 $comms = hash_from_query($query, 'id'); 119 foreach ($comms as $comm) 120 { 107 121 send_comment_to_subscribers($comm); 108 122 } … … 115 129 function stc_on_picture() 116 130 { 117 global $template, $picture, $page, $user; 118 119 $infos = $errors = array(); 120 131 global $template, $picture, $page, $user, $conf; 132 133 // standalone subscription 121 134 if (isset($_POST['stc_submit'])) 122 135 { 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 else133 {134 array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.'));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; 135 148 } 136 149 } 137 150 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 } 144 145 // messages management 146 stc_add_messages($errors, $infos); 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 } 147 157 148 158 // if registered user with mail we check if already subscribed 149 159 if ( !is_a_guest() and !empty($user['email']) ) 150 160 { 151 $query = ' 152 SELECT id 153 FROM '.SUBSCRIBE_TO_TABLE.' 154 WHERE 155 email = "'.$user['email'].'" 156 AND image_id = '.$picture['current']['id'].' 157 AND validated = "true" 158 ;'; 159 if (pwg_db_num_rows(pwg_query($query))) 160 { 161 $template->assign(array( 162 'SUBSCRIBED' => true, 163 'UNSUB_LINK' => add_url_params($picture['current']['url'], array('stc_unsubscribe'=>'1')), 164 )); 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 } 165 234 } 166 235 } 167 236 else 168 237 { 169 $template->assign('ASK_MAIL', true); 170 } 171 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'); 176 } 177 178 /** 179 * add field and on album page 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 180 251 */ 181 252 function stc_on_album() 182 253 { 183 global $page, $template, $pwg_loaded_plugins, $user; 184 185 $infos = $errors = array(); 254 global $page, $template, $pwg_loaded_plugins, $user, $conf; 186 255 187 256 if ( … … 196 265 if (isset($_POST['stc_submit'])) 197 266 { 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.')); 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; 210 275 } 211 276 } 212 277 else if (isset($_GET['stc_unsubscribe'])) 213 278 { 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 } 219 220 // messages management 221 stc_add_messages($errors, $infos, true); 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 } 222 284 223 285 // if registered user we check if already subscribed 224 286 if ( !is_a_guest() and !empty($user['email']) ) 225 287 { 226 $query = ' 227 SELECT id 228 FROM '.SUBSCRIBE_TO_TABLE.' 229 WHERE 230 email = "'.$user['email'].'" 231 AND category_id = '.$page['category']['id'].' 232 AND validated = "true" 233 ;'; 234 if (pwg_db_num_rows(pwg_query($query))) 235 { 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 )); 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 } 244 341 } 245 342 } 246 343 else 247 344 { 248 $template->assign(' ASK_MAIL', true);249 } 250 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 255 } 256 257 258 /** 259 * prefilter for common themes345 $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 260 357 */ 261 358 function stc_main_prefilter($content, &$smarty) 262 { 359 { 263 360 ## subscribe at any moment ## 264 $search = '#\<\/div\>(.{0,10})\{\/if\}(.{0,10})\{\*comments\*\}#is'; 265 266 $replace = ' 267 <form method="post" action="{$comment_add.F_ACTION}" class="filter" id="stc_standalone"> 268 <fieldset> 269 {if $SUBSCRIBED} 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> 274 {if $ASK_MAIL} 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); 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); 286 364 287 365 ## subscribe while add a comment ## 288 $search = '#<input type="hidden" name="key" value="{\$comment_add\.KEY}"([ /]*)>#'; 289 290 $replace = ' 291 <input type="hidden" name="key" value="{$comment_add.KEY}"$1> 292 {if !$SUBSCRIBED} 293 <label>{\'Notify me of followup comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label><br> 294 295 {if $ASK_MAIL} 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); 366 $search = '<p><textarea name="content" id="contentid" rows="5" cols="50">{$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); 309 369 310 370 return $content; 311 371 } 312 372 313 /**314 * prefilter for simple/stripped themes315 */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>324 {if $SUBSCRIBED}325 {\'You are currently subscribed to comments of this album.\'|@translate}326 <a href="{$UNSUB_LINK}">{\'Unsubscribe\'|@translate}327 {else}328 <legend>{\'Subscribe without commenting\'|@translate}</legend>329 {if $ASK_MAIL}330 <label>{\'Email address\'|@translate} <input type="text" name="stc_mail_stdl"></label>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}336 </fieldset>337 </form>338 </div>$1{/if}$2{if !empty($navbar) }{include file=\'navigation_bar.tpl\'|@get_extent:\'navbar\'}{/if}';339 340 $content = preg_replace($search, $replace, $content);341 342 ## subscribe while add a comment ##343 $search = '#<input type="hidden" name="key" value="{\$comment_add\.KEY}"([ /]*)>#';344 345 $replace = '346 <input type="hidden" name="key" value="{$comment_add.KEY}"$1>347 {if !$SUBSCRIBED}348 <label>{\'Notify me of followup comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label><br>349 350 {if $ASK_MAIL}351 <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label><br>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 });359 {/literal}{/footer_script}360 {/if}361 {/if}';362 363 $content = preg_replace($search, $replace, $content);364 365 return $content;366 }367 373 368 374 /** … … 375 381 if (!empty($user['email'])) 376 382 { 383 $template->assign('MANAGE_LINK', make_stc_url('manage', $user['email']) ); 377 384 $template->set_prefilter('profile_content', 'stc_profile_link_prefilter'); 378 385 } 379 386 } 380 381 387 function stc_profile_link_prefilter($content, &$smarty) 382 388 { 383 global $user;384 385 389 $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); 389 } 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 } 390 $replace = '<p style="font-size:1.1em;text-decoration:underline;"><a href="{$MANAGE_LINK}" rel="nofollow">{\'Manage my subscriptions to comments\'|@translate}</a></p>'; 391 392 return str_replace($search, $replace.$search, $content); 393 } 394 413 395 ?>
Note: See TracChangeset
for help on using the changeset viewer.