Changeset 11416
- Timestamp:
- Jun 17, 2011, 7:14:05 PM (13 years ago)
- Location:
- extensions/reply_to
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/reply_to/main.inc.php
r11325 r11416 4 4 Version: auto 5 5 Description: This plugin allows you to add Twitter-like reply links to comments. 6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid= 6 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=556 7 7 Author: Mistic 8 8 Author URI: http://www.strangeplanet.fr … … 19 19 load_language('plugin.lang', REPLYTO_PATH); 20 20 21 // add link and parse on picture page 22 if (script_basename() == 'picture') 23 { 24 add_event_handler('loc_begin_picture', 'replyto_add_link'); 25 } 26 // parse on comments page (picture section) 27 else if (script_basename() == 'comments' AND !isset($_GET['display_mode'])) 28 { 29 add_event_handler('render_comment_content', 'replyto_parse_picture', 60); 30 } 31 // parse comment admin side (picture section) 32 else if (script_basename() == 'admin' AND isset($_GET['page']) AND $_GET['page'] == 'comments' AND ( !isset($_GET['section']) OR $_GET['section'] == 'pictures' ) ) 33 { 34 add_event_handler('render_comment_content', 'replyto_parse_picture', 60); 35 } 36 // add link and parse on album page (compatibility with Comment on Albums) 37 else if (script_basename() == 'index') 38 { 39 add_event_handler('loc_begin_index', 'replyto_add_link'); 40 } 41 // parse on comments page (album section) 42 else if (script_basename() == 'comments' AND $_GET['display_mode'] == 'albums') 43 { 44 add_event_handler('render_comment_content', 'replyto_parse_album', 60); 45 } 46 // parse comment admin side (album section) 47 else if (script_basename() == 'admin' AND isset($_GET['page']) AND $_GET['page'] == 'comments' AND $_GET['section'] == 'albums') 48 { 49 add_event_handler('render_comment_content', 'replyto_parse_album', 60); 50 } 21 add_event_handler('render_comment_content', 'replyto_parse', 60, 2); 22 // add_event_handler('init', 'replyto_add_link'); // for comments page (section_init.inc is not called on this page) 23 add_event_handler('loc_end_section_init', 'replyto_add_link'); // for all the rest 51 24 52 25 ?> -
extensions/reply_to/reply_to.inc.php
r11326 r11416 1 1 <?php 2 2 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); 3 4 define('REPLYTO_REGEX', '#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i'); 3 5 4 6 /** … … 22 24 $template->assign('replyto_form_name', 'addComment'); 23 25 } 26 27 // must check our location + some additional tests 28 // if (script_basename() == 'comments') 29 // { 30 // if ( !is_a_guest() OR $conf['comments_forall'] ) 31 // { 32 // $template->set_prefilter('comments', 'replyto_add_link_prefilter'); 33 // } 34 // } 35 // else 36 if (script_basename() == 'picture') 37 { 38 add_event_handler('user_comment_insertion', 'replyto_parse_picture_mail'); 24 39 25 // must re-check our location + some additional tests26 if (script_basename() == 'picture')27 {28 add_event_handler('render_comment_content', 'replyto_parse_picture', 60);29 add_event_handler('user_comment_insertion', 'replyto_parse_picture_mail');30 40 if ( !is_a_guest() OR $conf['comments_forall'] ) 31 41 { … … 35 45 else if 36 46 ( 37 script_basename() == 'index' AND 47 script_basename() == 'index' AND isset($page['section']) AND 38 48 isset($pwg_loaded_plugins['Comments_on_Albums']) AND 39 49 $page['section'] == 'categories' AND isset($page['category']) 40 50 ) 41 51 { 42 add_event_handler('render_comment_content', 'replyto_parse_album', 60);43 52 add_event_handler('user_comment_insertion', 'replyto_parse_album_mail'); 53 44 54 if ( !is_a_guest() OR $conf['comments_forall'] ) 45 55 { … … 57 67 58 68 {footer_script require=\'insertAtCaret\'} 59 function reply to(commentID, author) {ldelim}69 function replyTo(commentID, author) {ldelim} 60 70 jQuery("#{$replyto_form_name} textarea").insertAtCaret("[reply=" + commentID + "]" + author + "[/reply] "); 61 71 } … … 82 92 {if not isset($comment.IN_EDIT)} 83 93 <div class="actions" style="float:right;"> 84 <a href="#commentform" title="{\'reply to this comment\'|@translate}" class="replyTo" onclick="reply to(\'{$comment.ID}\', \'{$comment.AUTHOR}\');"> </a>94 <a href="#commentform" title="{\'reply to this comment\'|@translate}" class="replyTo" onclick="replyTo(\'{$comment.ID}\', \'{$comment.AUTHOR}\');"> </a> 85 95 </div> 86 96 {/if}' … … 104 114 * Replace BBcode tag by a link with absolute url 105 115 */ 106 function replyto_parse_picture($comment) 107 { 108 if (preg_match('#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i', $comment, $matches)) 109 { 110 // picture informations 111 $query = ' 116 function replyto_parse($comment, $in_album = false) 117 { 118 if (preg_match(REPLYTO_REGEX, $comment, $matches)) 119 { 120 /* try to parse a ReplyTo tag link for picture page */ 121 if (!$in_album) 122 { 123 // picture informations 124 $query = ' 112 125 SELECT 113 126 img.id, … … 121 134 WHERE com.id = ' . $matches[1] . ' 122 135 ;'; 123 $result = pwg_query($query);124 125 // make sure the target comment exists126 if (pwg_db_num_rows($result))127 {128 $image = pwg_db_fetch_assoc($result);129 130 // retrieving category informations131 $query = '136 $result = pwg_query($query); 137 138 // make sure the target comment exists 139 if (pwg_db_num_rows($result)) 140 { 141 $image = pwg_db_fetch_assoc($result); 142 143 // retrieving category informations 144 $query = ' 132 145 SELECT 133 146 id, … … 138 151 WHERE id = ' . $image['category_id'] . ' 139 152 ;'; 140 $image['cat'] = pwg_db_fetch_assoc(pwg_query($query)); 141 142 // link to the full size picture 143 $image['url'] = make_picture_url(array( 144 'category' => $image['cat'], 145 'image_id' => $image['id'], 146 'image_file' => $image['file'], 147 )); 148 149 $search = "#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i"; 150 $replace = '@ <a href="'.get_absolute_root_url().$image['url'].'#comment-$1">$2</a> :'; 151 } 153 $image['cat'] = pwg_db_fetch_assoc(pwg_query($query)); 154 155 // link to the full size picture 156 $image['url'] = make_picture_url(array( 157 'category' => $image['cat'], 158 'image_id' => $image['id'], 159 'image_file' => $image['file'], 160 )); 161 162 $replace = '@ <a href="'.get_absolute_root_url().$image['url'].'#comment-$1">$2</a> :'; 163 } 164 else 165 { 166 $replace = ''; 167 } 168 } 169 /* try to parse a ReplyTo tag link for an album */ 152 170 else 153 { 154 $search = "#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i"; 155 $replace = ''; 156 } 157 158 return preg_replace($search, $replace, $comment); 159 } 160 else 161 { 162 return $comment; 163 } 164 } 165 166 function replyto_parse_album($comment) 167 { 168 if (preg_match('#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i', $comment, $matches)) 169 { 170 // check if the comment is really an album comment 171 // (both comments_on_albums script and default comments script are executed... 172 // with the same 'render_comment_content' event) 173 ## THIS CAN INDUCE ERRORS, MUST FIND A BETTER WAY 174 $query = ' 175 SELECT id 176 FROM ' . COA_TABLE . ' 177 WHERE content = "' . $comment .'" 178 ;'; 179 if (!pwg_db_num_rows(pwg_query($query))) 180 { 181 return $comment; 182 } 183 184 // retrieving category informations 185 $query = ' 171 { 172 // retrieving category informations 173 $query = ' 186 174 SELECT 187 175 cat.id, … … 194 182 WHERE com.id = ' . $matches[1] . ' 195 183 ;'; 196 $result = pwg_query($query); 197 198 // make sure the target comment exists 199 if (pwg_db_num_rows($result)) 200 { 201 $category = pwg_db_fetch_assoc($result); 202 203 // link to the album 204 $category['url'] = make_index_url(array( 205 'category' => $category, 206 )); 207 208 $search = "#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i"; 209 $replace = '@ <a href="'.get_absolute_root_url().$category['url'].'#comment-$1">$2</a> :'; 184 $result = pwg_query($query); 185 186 // make sure the target comment exists 187 if (pwg_db_num_rows($result)) 188 { 189 $category = pwg_db_fetch_assoc($result); 190 191 // link to the album 192 $category['url'] = make_index_url(array( 193 'category' => $category, 194 )); 195 196 $replace = '@ <a href="'.get_absolute_root_url().$category['url'].'#comment-$1">$2</a> :'; 197 } 198 else 199 { 200 $replace = ''; 201 } 210 202 } 211 else 212 { 213 $search = "#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i"; 214 $replace = ''; 215 } 216 217 return preg_replace($search, $replace, $comment); 203 204 return preg_replace(REPLYTO_REGEX, $replace, $comment); 218 205 } 219 206 else … … 228 215 function replyto_parse_picture_mail($comment) 229 216 { 230 $comment['content'] = replyto_parse _picture($comment['content']);217 $comment['content'] = replyto_parse($comment['content']); 231 218 return $comment; 232 219 } … … 234 221 function replyto_parse_album_mail($comment) 235 222 { 236 $comment['content'] = replyto_parse _album($comment['content']);223 $comment['content'] = replyto_parse($comment['content'], 'album'); 237 224 return $comment; 238 225 }
Note: See TracChangeset
for help on using the changeset viewer.