Changeset 12561
- Timestamp:
- Nov 6, 2011, 7:33:55 PM (12 years ago)
- Location:
- extensions/Subscribe_to_comments
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/Subscribe_to_comments/include/functions.inc.php
r12560 r12561 15 15 $exclude = null; 16 16 if (!empty($_POST['stc_mail'])) $exclude = pwg_db_real_escape_string($_POST['stc_mail']); 17 if (!is_a_guest()) $exclude = $user['email'];17 else if (!is_a_guest()) $exclude = $user['email']; 18 18 19 19 // get subscribers emails … … 30 30 31 31 set_make_full_url(); 32 switch ($type) 33 { 34 case 'image': 35 { 36 // get image infos 37 $query = ' 32 if ($type == 'image') 33 { 34 // get image infos 35 $query = ' 38 36 SELECT 39 37 id, … … 43 41 WHERE id = '.$comm['image_id'].' 44 42 ;'; 45 $element = pwg_db_fetch_assoc(pwg_query($query)); 46 47 if (empty($element['name'])) 48 { 49 $element['name'] = get_name_from_file($element['file']); 50 } 43 $element = pwg_db_fetch_assoc(pwg_query($query)); 51 44 52 $url_params = array('image_id' => $element['id']); 53 if (!empty($page['category'])) 54 { 55 $url_params['section'] = 'categories'; 56 $url_params['category'] = $page['category']; 57 } 58 59 $element['url'] = make_picture_url($url_params); 60 break; 45 if (empty($element['name'])) 46 { 47 $element['name'] = get_name_from_file($element['file']); 61 48 } 62 49 63 case 'category' : 50 $url_params = array('image_id' => $element['id']); 51 if (!empty($page['category'])) 64 52 { 65 // get category infos 66 $query = ' 53 $url_params['section'] = 'categories'; 54 $url_params['category'] = $page['category']; 55 } 56 57 $element['url'] = make_picture_url($url_params); 58 } 59 else if ($type == 'category') 60 { 61 // get category infos 62 $query = ' 67 63 SELECT 68 64 id, 69 name 65 name, 66 permalink 70 67 FROM '.CATEGORIES_TABLE.' 71 68 WHERE id = '.$comm['category_id'].' 72 69 ;'; 73 $element = pwg_db_fetch_assoc(pwg_query($query)); 74 75 $url_params['section'] = 'categories'; 76 $url_params['category'] = $element; 77 78 79 $element['url'] = make_index_url($url_params); 80 break; 81 } 70 $element = pwg_db_fetch_assoc(pwg_query($query)); 71 72 $url_params['section'] = 'categories'; 73 $url_params['category'] = $element; 74 75 $element['url'] = make_index_url($url_params); 82 76 } 83 77 … … 117 111 } 118 112 113 119 114 /* 120 115 * add an email to subscribers list … … 128 123 129 124 $infos = $errors = array(); 130 131 125 if ( is_a_guest() and empty($email) ) 132 126 { 133 127 array_push($errors, l10n('Invalid email adress, your are not subscribed to comments.')); 128 129 $orig = $template->get_template_vars('errors'); 130 if (empty($orig)) $orig = array(); 131 $template->assign('errors', array_merge($orig, $errors)); 132 133 if ($type == 'category') $template->set_prefilter('index', 'coa_messages'); // here we use a prefilter existing in COA 134 134 135 return; 135 136 } 136 else if ( !is_a_guest())137 else if (!is_a_guest()) 137 138 { 138 139 $email = $user['email']; 139 140 } 140 141 142 // don't care if already registered 141 143 $query = ' 142 144 INSERT IGNORE INTO '.SUBSCRIBE_TO_TABLE.'( … … 155 157 pwg_query($query); 156 158 159 // send validation mail 157 160 if (is_a_guest() and pwg_db_insert_id() != 0) 158 161 { 162 $element_name = ($type == 'image') ? $picture['current']['name'] : $page['category']['name']; 163 159 164 $mail_args = array( 160 165 'subject' => '['.strip_tags($conf['gallery_title']).'] Please confirm your subscribtion to comments', … … 163 168 164 169 $mail_args['content'] = ' 165 You requested to subscribe by email to comments on <b>'.$ picture['current']['name'].'</b>.<br>170 You requested to subscribe by email to comments on <b>'.$element_name.'</b>.<br> 166 171 <br> 167 172 We care about your inbox, so we want to confirm this request. Please click the confirm link to activate the subscription.<br> … … 175 180 array_push($infos, l10n('Please check your email inbox to confirm your subscription.')); 176 181 } 182 // just displat confirmation message 183 else if (pwg_db_insert_id() != 0) 184 { 185 array_push($infos, l10n('You have been added to the list of subscribers for this '.($type=='image' ? 'picture' : 'album').'.')); 186 } 187 177 188 178 189 if (!empty($infos)) 179 190 { 180 $template->assign('infos', array_merge($template->get_template_vars('infos'), $infos)); 181 } 182 if (!empty($errors)) 183 { 184 $template->assign('errors', array_merge($template->get_template_vars('errors'), $errors)); 185 } 186 } 191 $orig = $template->get_template_vars('infos'); 192 if (empty($orig)) $orig = array(); 193 $template->assign('infos', array_merge($orig, $infos)); 194 195 if ($type == 'category') $template->set_prefilter('index', 'coa_messages'); 196 } 197 } 198 187 199 188 200 /** … … 194 206 function make_stc_url($action, $email) 195 207 { 196 if ( empty($action) or empty($email) ) return null; 208 if ( empty($action) or empty($email) ) 209 { 210 trigger_error('make_stc_url missing action and/or mail', E_USER_WARNING); 211 return null; 212 } 197 213 198 214 global $conf; … … 219 235 } 220 236 237 221 238 /** 222 239 * crypt a string using mcrypt extension or a binary method … … 266 283 } 267 284 285 268 286 /** 269 287 * variant of base64 functions usable into url -
extensions/Subscribe_to_comments/language/en_UK/plugin.lang.php
r12560 r12561 6 6 $lang['You have been successfully unsubscribed, good bye.'] = 'You have been successfully unsubscribed, good bye.'; 7 7 $lang['Your subscribtion has been validated, thanks you.'] = 'Your subscribtion has been validated, thanks you.'; 8 $lang['You have been added to the list of subscribers for this picture.'] = 'You have been added to the list of subscribers for this picture.'; 9 $lang['You have been added to the list of subscribers for this album.'] = 'You have been added to the list of subscribers for this album.'; 10 $lang['You are currently subscribed to comments of this picture.'] = 'You are currently subscribed to comments of this picture.'; 11 $lang['You are currently subscribed to comments of this album.'] = 'You are currently subscribed to comments of this album.'; 12 $lang['Unsubscribe'] = 'Unsubscribe'; 8 13 9 14 ?> -
extensions/Subscribe_to_comments/language/fr_FR/plugin.lang.php
r12560 r12561 4 4 $lang['Invalid email adress, your are not subscribed to comments.'] = 'Email invalide, vous n\'avez pas été inscrit.'; 5 5 $lang['Please check your email inbox to confirm your subscription.'] = 'Veuillez consulter votre boite mail pour confirmer votre inscription.'; 6 $lang['You have been successfully unsubscribed, good bye.'] = 'Vous avez supprimé de la liste de notification, au revoir.'; 7 $lang['Your subscribtion has been validated, thanks you.'] = 'Votre inscription a bien été validée, merci..'; 6 $lang['You have been successfully unsubscribed, good bye.'] = 'Vous avez été supprimé de la liste de notification, au revoir.'; 7 $lang['Your subscribtion has been validated, thanks you.'] = 'Votre inscription a bien été validée, merci.'; 8 $lang['You have been added to the list of subscribers for this picture.'] = 'Vous avez été ajouté à la liste des inscrits pour les commentaires de cette photo.'; 9 $lang['You have been added to the list of subscribers for this album.'] = 'Vous avez été ajouté à la liste des inscrits pour les commentaires de cet album.'; 10 $lang['You are currently subscribed to comments of this picture.'] = 'Vous êtes actuellement inscrit aux commentaires de cette photo.'; 11 $lang['You are currently subscribed to comments of this album.'] = 'Vous êtes actuellement inscrit aux commentaires de cet album.'; 12 $lang['Unsubscribe'] = 'Se désinscrire'; 8 13 9 14 ?> -
extensions/Subscribe_to_comments/main.inc.php
r12560 r12561 4 4 Version: auto 5 5 Description: This plugin allows you to subscribe to comments by mail. 6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid= 6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=587 7 7 Author: Mistic 8 8 Author URI: http://www.strangeplanet.fr … … 20 20 include_once(SUBSCRIBE_TO_PATH.'include/functions.inc.php'); 21 21 22 load_language('plugin.lang', SUBSCRIBE_TO_PATH); 23 24 // send mails 22 25 add_event_handler('user_comment_insertion', 'stc_comment_insertion'); 23 26 add_event_handler('user_comment_validation', 'stc_comment_validation', EVENT_HANDLER_PRIORITY_NEUTRAL, 2); 27 28 // subscribe 24 29 add_event_handler('loc_end_picture', 'stc_on_picture'); 30 add_event_handler('loc_begin_index', 'stc_on_album'); 31 32 // management 25 33 add_event_handler('loc_end_section_init', 'stc_detect_section'); 26 add_event_handler('loc_end_index', 'stc_load_section'); 34 add_event_handler('loc_end_index', 'stc_load_section'); 27 35 28 36 ?> -
extensions/Subscribe_to_comments/subscribe_to_comments.inc.php
r12560 r12561 88 88 89 89 /** 90 * add s fieldson picture page90 * add field and link on picture page 91 91 */ 92 92 function stc_on_picture() 93 93 { 94 global $template; 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 } 95 100 96 101 $template->set_prefilter('picture', 'stc_on_picture_prefilter'); … … 99 104 function stc_on_picture_prefilter($template, &$smarty) 100 105 { 101 $search = '<input type="submit" value="{\'Submit\'|@translate}">'; 102 103 $replace = ' 104 <label>{\'Subscribe to new comments\'|@translate} <input type="checkbox" name="stc_check" value="1"></label> 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].= ' 105 116 <label id="stc_mail" style="display:none;">{\'Email address\'|@translate} <input type="text" name="stc_mail"></label> 106 117 {footer_script require="jquery"}{literal} … … 111 122 }); 112 123 }); 113 {/literal} 114 {/footer_script} 115 '.$search; 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>'; 116 195 117 196 return str_replace($search, $replace, $template); 118 197 } 119 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 120 319 ?>
Note: See TracChangeset
for help on using the changeset viewer.