- Timestamp:
- Nov 11, 2011, 2:56:45 PM (12 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
extensions/Subscribe_to_comments/include/subscribe_to_comments.inc.php
r12561 r12600 29 29 function stc_comment_insertion($comm) 30 30 { 31 global $page; 31 global $page, $template; 32 33 $infos = $errors = array(); 32 34 33 35 if ($comm['action'] == 'validate') … … 40 42 if (isset($comm['image_id'])) 41 43 { 42 subscribe_to_comments($comm['image_id'], @$_POST['stc_mail'], 'image');44 $return = subscribe_to_comments($comm['image_id'], @$_POST['stc_mail'], 'image'); 43 45 } 44 46 else if (isset($comm['category_id'])) 45 47 { 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': 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') 56 93 { 57 94 $query = ' … … 64 101 WHERE id = '.$comm_id.' 65 102 ;'; 66 break; 67 } 68 69 case 'category': 103 } 104 else if ($type == 'category') 70 105 { 71 106 $query = ' … … 78 113 WHERE id = '.$comm_id.' 79 114 ;'; 80 break; 81 } 82 } 83 84 $comm = pwg_db_fetch_assoc(pwg_query($query)); 85 send_comment_to_subscribers($comm); 115 } 116 117 $comm = pwg_db_fetch_assoc(pwg_query($query)); 118 send_comment_to_subscribers($comm); 119 } 86 120 } 87 121 … … 92 126 function stc_on_picture() 93 127 { 94 global $template, $picture; 128 global $template, $picture, $page; 129 130 $infos = $array = array(); 95 131 96 132 if (isset($_POST['stc_check_stdl'])) 97 133 { 98 subscribe_to_comments($picture['current']['id'], @$_POST['stc_mail_stdl'], 'image'); 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)); 99 168 } 100 169 … … 104 173 function stc_on_picture_prefilter($template, &$smarty) 105 174 { 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 175 global $user, $picture; 128 176 129 177 ## subscribe at any moment ## … … 143 191 email = "'.$user['email'].'" 144 192 AND image_id = '.$picture['current']['id'].' 193 AND validated = "true" 145 194 ;'; 146 195 if (pwg_db_num_rows(pwg_query($query))) … … 148 197 $replace[1].= ' 149 198 {\'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}';199 <a href="'.add_url_params($picture['current']['url'], array('stc_unsubscribe'=>'1')).'">{\'Unsubscribe\'|@translate}'; 151 200 $no_form = true; 152 201 } … … 194 243 </form>'; 195 244 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 245 228 246 ## subscribe while add a comment ## 229 247 $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">'; 230 231 $replace[0] = ' 248 $replace[0] = null; 249 250 if (!isset($no_form)) 251 { 252 $replace[0].= ' 232 253 <label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>'; 254 } 233 255 if (is_a_guest()) 234 256 { … … 246 268 $replace[0].= $search[0]; 247 269 270 return str_replace($search, $replace, $template); 271 } 272 273 274 /** 275 * add field and on album page 276 */ 277 function stc_on_album() 278 { 279 global $page, $template, $pwg_loaded_plugins; 280 281 $infos = $errors = array(); 282 283 if ( 284 script_basename() != 'index' or !isset($page['section']) or 285 !isset($pwg_loaded_plugins['Comments_on_Albums']) or 286 $page['section'] != 'categories' or !isset($page['category']) 287 ) 288 { 289 return; 290 } 291 292 if (isset($_POST['stc_check_stdl'])) 293 { 294 $return = subscribe_to_comments($page['category']['id'], @$_POST['stc_mail_stdl'], 'category'); 295 if ($return === 'confirm_mail') 296 { 297 array_push($infos, l10n('Please check your email inbox to confirm your subscription.')); 298 } 299 else if ($return === true) 300 { 301 array_push($infos, l10n('You have been added to the list of subscribers for this album.')); 302 } 303 else 304 { 305 array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.')); 306 } 307 } 308 else if (isset($_GET['stc_unsubscribe'])) 309 { 310 if (un_subscribe_to_comments($page['category']['id'], null, 'category')) 311 { 312 array_push($infos, l10n('Successfully unsubscribed your email address from receiving notifications.')); 313 } 314 } 315 316 // messages management 317 if (!empty($errors)) 318 { 319 $errors_bak = $template->get_template_vars('errors'); 320 if (empty($errors_bak)) $errors_bak = array(); 321 $template->assign('errors', array_merge($errors_bak, $errors)); 322 $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA 323 } 324 if (!empty($infos)) 325 { 326 $infos_bak = $template->get_template_vars('infos'); 327 if (empty($infos_bak)) $infos_bak = array(); 328 $template->assign('infos', array_merge($infos_bak, $infos)); 329 $template->set_prefilter('index', 'coa_messages'); 330 } 331 332 $template->set_prefilter('comments_on_albums', 'stc_on_album_prefilter'); 333 } 334 335 function stc_on_album_prefilter($template, &$smarty) 336 { 337 global $user, $page; 248 338 249 339 ## subscribe at any moment ## … … 263 353 email = "'.$user['email'].'" 264 354 AND category_id = '.$page['category']['id'].' 355 AND validated = "true" 265 356 ;'; 266 357 if (pwg_db_num_rows(pwg_query($query))) 267 358 { 359 $url_params['section'] = 'categories'; 360 $url_params['category'] = $page['category']; 361 362 $element_url = make_index_url($url_params); 363 268 364 $replace[1].= ' 269 365 {\'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}';366 <a href="'.add_url_params($element_url, array('stc_unsubscribe'=>'1')).'">{\'Unsubscribe\'|@translate}'; 271 367 $no_form = true; 272 368 } … … 314 410 </form>'; 315 411 412 413 ## subscribe while add a comment ## 414 $search[0] = '<input type="submit" value="{\'Submit\'|@translate}">'; 415 $replace[0] = null; 416 417 if (!isset($no_form)) 418 { 419 $replace[0].= ' 420 <label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label>'; 421 } 422 if (is_a_guest()) 423 { 424 $replace[0].= ' 425 <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label> 426 {footer_script require="jquery"}{literal} 427 jQuery(document).ready(function() { 428 $("input[name=stc_check]").change(function() { 429 if ($(this).is(":checked")) $("#stc_mail").css("display", ""); 430 else $("#stc_mail").css("display", "none"); 431 }); 432 }); 433 {/literal}{/footer_script}'; 434 } 435 $replace[0].= $search[0]; 436 316 437 return str_replace($search, $replace, $template); 317 438 } 318 439 440 441 /** 442 * add link to management page for registered users 443 */ 444 function stc_menubar_apply($menu_ref_arr) 445 { 446 global $template; 447 $menu = &$menu_ref_arr[0]; 448 449 if ( !is_a_guest() and ($block = $menu->get_block('mbIdentification')) != null ) 450 { 451 $template->set_prefilter('menubar', 'stc_menubar_apply_prefilter'); 452 } 453 } 454 455 function stc_menubar_apply_prefilter($content, &$smarty) 456 { 457 global $user; 458 459 $search = '{if isset($U_REGISTER)}'; 460 $replace = '<li><a href="'.make_stc_url('manage', $user['email']).'" title="{\'Manage my subscriptions\'|@translate}" rel="nofollow">{\'Manage my subscriptions\'|@translate}</a></li>'; 461 return str_replace($search, $replace.$search, $content); 462 } 319 463 ?>
Note: See TracChangeset
for help on using the changeset viewer.