[11252] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
[11416] | 4 | define('REPLYTO_REGEX', '#\[reply=([0-9]+)\]([^\[\]]*)\[/reply\]#i'); |
---|
| 5 | |
---|
[11252] | 6 | /** |
---|
| 7 | * Add anchors and reply button to comments blocks |
---|
| 8 | */ |
---|
| 9 | function replyto_add_link() |
---|
| 10 | { |
---|
[12389] | 11 | global $pwg_loaded_plugins, $template, $page, $conf, $lang; |
---|
[11252] | 12 | $template->assign('REPLYTO_PATH', REPLYTO_PATH); |
---|
[15108] | 13 | $location = null; |
---|
[11252] | 14 | |
---|
| 15 | // comment form has different id |
---|
| 16 | if ( |
---|
| 17 | (isset($_GET['action']) AND $_GET['action'] == 'edit_comment') OR |
---|
| 18 | (isset($page['body_id']) AND $page['body_id'] == 'theCommentsPage') |
---|
| 19 | ) |
---|
| 20 | { |
---|
| 21 | $template->assign('replyto_form_name', 'editComment'); |
---|
| 22 | } |
---|
| 23 | else |
---|
| 24 | { |
---|
| 25 | $template->assign('replyto_form_name', 'addComment'); |
---|
| 26 | } |
---|
[11416] | 27 | |
---|
[15108] | 28 | /* COMMENTS page */ |
---|
| 29 | if (script_basename() == 'comments') |
---|
[11252] | 30 | { |
---|
[12389] | 31 | if ( !is_a_guest() OR $conf['comments_forall'] ) |
---|
| 32 | { |
---|
[15108] | 33 | $comments = &$template->get_template_vars('comments'); |
---|
| 34 | if (!count($comments)) return; |
---|
| 35 | |
---|
| 36 | // generates urls to picture or albums with necessary url params |
---|
| 37 | foreach ($comments as $tpl_var) |
---|
| 38 | { |
---|
| 39 | $replyto_links[ $tpl_var['ID'] ] = get_absolute_root_url().$tpl_var['U_PICTURE'].'&rt='.$tpl_var['ID'].'&rta='.$tpl_var['AUTHOR'].'#commentform'; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | $template->assign('replyto_links', $replyto_links); |
---|
[12389] | 43 | $template->set_prefilter('comments', 'replyto_add_link_comments_prefilter'); |
---|
| 44 | } |
---|
| 45 | } |
---|
[15108] | 46 | /* PICTURE page */ |
---|
| 47 | else if (script_basename() == 'picture') |
---|
[12389] | 48 | { |
---|
[15108] | 49 | $location = 'picture'; |
---|
[11325] | 50 | add_event_handler('user_comment_insertion', 'replyto_parse_picture_mail'); |
---|
[11416] | 51 | |
---|
[11252] | 52 | if ( !is_a_guest() OR $conf['comments_forall'] ) |
---|
| 53 | { |
---|
| 54 | $template->set_prefilter('picture', 'replyto_add_link_prefilter'); |
---|
| 55 | } |
---|
| 56 | } |
---|
[15108] | 57 | /* ALBUM page */ |
---|
| 58 | else if |
---|
[11252] | 59 | ( |
---|
[11416] | 60 | script_basename() == 'index' AND isset($page['section']) AND |
---|
[11252] | 61 | isset($pwg_loaded_plugins['Comments_on_Albums']) AND |
---|
| 62 | $page['section'] == 'categories' AND isset($page['category']) |
---|
| 63 | ) |
---|
| 64 | { |
---|
[15108] | 65 | $location = 'album'; |
---|
[11325] | 66 | add_event_handler('user_comment_insertion', 'replyto_parse_album_mail'); |
---|
[11416] | 67 | |
---|
[11252] | 68 | if ( !is_a_guest() OR $conf['comments_forall'] ) |
---|
| 69 | { |
---|
| 70 | $template->set_prefilter('comments_on_albums', 'replyto_add_link_prefilter'); |
---|
| 71 | } |
---|
| 72 | } |
---|
[12389] | 73 | |
---|
[15108] | 74 | |
---|
[12389] | 75 | /* we come from comments.php page */ |
---|
[15108] | 76 | if ( !empty($_GET['rt']) and !empty($_GET['rta']) ) |
---|
[12389] | 77 | { |
---|
[15108] | 78 | if ($location == 'picture') |
---|
| 79 | { |
---|
| 80 | $template->set_prefilter('picture', 'replyto_fillform_prefilter'); |
---|
| 81 | } |
---|
| 82 | else |
---|
| 83 | { |
---|
| 84 | $template->set_prefilter('comments_on_albums', 'replyto_fillform_prefilter'); |
---|
| 85 | } |
---|
[12389] | 86 | } |
---|
[11252] | 87 | } |
---|
| 88 | |
---|
[12389] | 89 | /** |
---|
[15108] | 90 | * add reply tag from values given in url |
---|
[12389] | 91 | */ |
---|
[15108] | 92 | function replyto_fillform_prefilter($content, &$smarty) |
---|
| 93 | { |
---|
| 94 | $search = '<ul class="commentsList">'; |
---|
| 95 | $replace = '{footer_script require=\'insertAtCaret\'}replyTo("'.$_GET['rt'].'", "'.$_GET['rta'].'");{/footer_script}'.$search; |
---|
| 96 | return str_replace($search, $replace, $content); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /** |
---|
| 100 | * reply buttons on comments.php page |
---|
| 101 | */ |
---|
[12389] | 102 | function replyto_add_link_comments_prefilter($content, &$smarty) |
---|
[15108] | 103 | { |
---|
| 104 | // style |
---|
| 105 | $search[0] = '<ul class="commentsList">'; |
---|
[12389] | 106 | $replace[0] = ' |
---|
| 107 | {html_head} |
---|
| 108 | <style type="text/css"> |
---|
| 109 | .replyTo {ldelim} |
---|
[15117] | 110 | display:none; |
---|
[15108] | 111 | background:url({$REPLYTO_PATH}reply.png) left top no-repeat; |
---|
[12389] | 112 | height:16px; |
---|
[15108] | 113 | margin-left:20px; |
---|
| 114 | padding-left:20px; |
---|
[12389] | 115 | } |
---|
[15117] | 116 | li.commentElement:hover .replyTo {ldelim} |
---|
| 117 | display:inline; |
---|
| 118 | } |
---|
[12389] | 119 | .replyTo:hover {ldelim} |
---|
[15108] | 120 | background-position:left -16px; |
---|
[12389] | 121 | } |
---|
| 122 | </style> |
---|
| 123 | {/html_head}' |
---|
| 124 | .$search[0]; |
---|
| 125 | |
---|
| 126 | // button |
---|
[15108] | 127 | $search[1] = '<span class="commentDate">{$comment.DATE}</span>'; |
---|
| 128 | $replace[1] = $search[1].'<a href="{$replyto_links[$comment.ID]}" class="replyTo">{\'Reply\'|@translate}</a>'; |
---|
[12389] | 129 | |
---|
| 130 | return str_replace($search, $replace, $content); |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | /** |
---|
[15108] | 134 | * reply buttons on picture.php and index.php pages |
---|
[12389] | 135 | */ |
---|
[11252] | 136 | function replyto_add_link_prefilter($content, &$smarty) |
---|
| 137 | { |
---|
[12389] | 138 | // script & style |
---|
[15108] | 139 | $search[0] = '<ul class="commentsList">'; |
---|
[11252] | 140 | $replace[0] = ' |
---|
| 141 | {combine_script id=\'insertAtCaret\' require=\'jquery\' path=$REPLYTO_PATH|@cat:\'insertAtCaret.js\'} |
---|
| 142 | |
---|
| 143 | {footer_script require=\'insertAtCaret\'} |
---|
[11416] | 144 | function replyTo(commentID, author) {ldelim} |
---|
[11252] | 145 | jQuery("#{$replyto_form_name} textarea").insertAtCaret("[reply=" + commentID + "]" + author + "[/reply] "); |
---|
| 146 | } |
---|
| 147 | {/footer_script} |
---|
| 148 | |
---|
| 149 | {html_head} |
---|
| 150 | <style type="text/css"> |
---|
| 151 | .replyTo {ldelim} |
---|
[15117] | 152 | display:none; |
---|
[15108] | 153 | background:url({$REPLYTO_PATH}reply.png) left top no-repeat; |
---|
[11252] | 154 | height:16px; |
---|
[15108] | 155 | margin-left:20px; |
---|
| 156 | padding-left:20px; |
---|
[11252] | 157 | } |
---|
[15117] | 158 | li.commentElement:hover .replyTo {ldelim} |
---|
| 159 | display:inline; |
---|
| 160 | } |
---|
[11252] | 161 | .replyTo:hover {ldelim} |
---|
[15108] | 162 | background-position:left -16px; |
---|
[11252] | 163 | } |
---|
| 164 | </style> |
---|
| 165 | {/html_head}' |
---|
| 166 | .$search[0]; |
---|
| 167 | |
---|
| 168 | // button |
---|
[15108] | 169 | $search[1] = '<span class="commentDate">{$comment.DATE}</span>'; |
---|
| 170 | $replace[1] = $search[1].'<a href="#commentform" class="replyTo" onclick="replyTo(\'{$comment.ID}\', \'{$comment.AUTHOR}\');">{\'Reply\'|@translate}</a>'; |
---|
[11252] | 171 | |
---|
[15108] | 172 | // anchors |
---|
| 173 | $search[2] = '<li class="commentElement'; |
---|
| 174 | $replace[2] = '<a name="comment-{$comment.ID}"></a>'.$search[2]; |
---|
[11252] | 175 | |
---|
[15108] | 176 | $search[3] = '<div id="commentAdd">'; |
---|
| 177 | $replace[3] = $search[3].'<a name="commentform"></a>'; |
---|
[11325] | 178 | |
---|
[11252] | 179 | return str_replace($search, $replace, $content); |
---|
| 180 | } |
---|
| 181 | |
---|
| 182 | |
---|
| 183 | /** |
---|
| 184 | * Replace BBcode tag by a link with absolute url |
---|
| 185 | */ |
---|
[11416] | 186 | function replyto_parse($comment, $in_album = false) |
---|
[11252] | 187 | { |
---|
[11416] | 188 | if (preg_match(REPLYTO_REGEX, $comment, $matches)) |
---|
| 189 | { |
---|
| 190 | /* try to parse a ReplyTo tag link for picture page */ |
---|
| 191 | if (!$in_album) |
---|
| 192 | { |
---|
| 193 | // picture informations |
---|
| 194 | $query = ' |
---|
[11252] | 195 | SELECT |
---|
[15108] | 196 | img.id, |
---|
| 197 | img.file, |
---|
| 198 | cat.category_id |
---|
| 199 | FROM ' . IMAGES_TABLE . ' AS img |
---|
| 200 | INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS cat |
---|
| 201 | ON cat.image_id = img.id |
---|
| 202 | INNER JOIN ' . COMMENTS_TABLE . ' AS com |
---|
| 203 | ON com.image_id = img.id |
---|
| 204 | WHERE com.id = ' . $matches[1] . ' |
---|
[11252] | 205 | ;'; |
---|
[11416] | 206 | $result = pwg_query($query); |
---|
| 207 | |
---|
| 208 | // make sure the target comment exists |
---|
| 209 | if (pwg_db_num_rows($result)) |
---|
| 210 | { |
---|
| 211 | $image = pwg_db_fetch_assoc($result); |
---|
[11252] | 212 | |
---|
[11416] | 213 | // retrieving category informations |
---|
| 214 | $query = ' |
---|
[11252] | 215 | SELECT |
---|
[15108] | 216 | id, |
---|
| 217 | name, |
---|
| 218 | permalink, |
---|
| 219 | uppercats |
---|
| 220 | FROM ' . CATEGORIES_TABLE . ' |
---|
| 221 | WHERE id = ' . $image['category_id'] . ' |
---|
[11252] | 222 | ;'; |
---|
[11416] | 223 | $image['cat'] = pwg_db_fetch_assoc(pwg_query($query)); |
---|
[11252] | 224 | |
---|
[11416] | 225 | // link to the full size picture |
---|
| 226 | $image['url'] = make_picture_url(array( |
---|
| 227 | 'category' => $image['cat'], |
---|
| 228 | 'image_id' => $image['id'], |
---|
| 229 | 'image_file' => $image['file'], |
---|
| 230 | )); |
---|
| 231 | |
---|
| 232 | $replace = '@ <a href="'.get_absolute_root_url().$image['url'].'#comment-$1">$2</a> :'; |
---|
| 233 | } |
---|
| 234 | else |
---|
| 235 | { |
---|
| 236 | $replace = ''; |
---|
| 237 | } |
---|
| 238 | } |
---|
| 239 | /* try to parse a ReplyTo tag link for an album */ |
---|
[12389] | 240 | else if ( $in_album == 'album') |
---|
[11416] | 241 | { |
---|
| 242 | // retrieving category informations |
---|
| 243 | $query = ' |
---|
[11252] | 244 | SELECT |
---|
[15108] | 245 | cat.id, |
---|
| 246 | cat.name, |
---|
| 247 | cat.permalink, |
---|
| 248 | cat.uppercats |
---|
| 249 | FROM ' . COA_TABLE . ' AS com |
---|
| 250 | INNER JOIN ' . CATEGORIES_TABLE . ' AS cat |
---|
| 251 | ON cat.id = com.category_id |
---|
| 252 | WHERE com.id = ' . $matches[1] . ' |
---|
[11252] | 253 | ;'; |
---|
[11416] | 254 | $result = pwg_query($query); |
---|
| 255 | |
---|
| 256 | // make sure the target comment exists |
---|
| 257 | if (pwg_db_num_rows($result)) |
---|
| 258 | { |
---|
| 259 | $category = pwg_db_fetch_assoc($result); |
---|
[11252] | 260 | |
---|
[11416] | 261 | // link to the album |
---|
| 262 | $category['url'] = make_index_url(array( |
---|
| 263 | 'category' => $category, |
---|
| 264 | )); |
---|
| 265 | |
---|
| 266 | $replace = '@ <a href="'.get_absolute_root_url().$category['url'].'#comment-$1">$2</a> :'; |
---|
| 267 | } |
---|
| 268 | else |
---|
| 269 | { |
---|
| 270 | $replace = ''; |
---|
| 271 | } |
---|
[11252] | 272 | } |
---|
[11416] | 273 | |
---|
| 274 | return preg_replace(REPLYTO_REGEX, $replace, $comment); |
---|
[11252] | 275 | } |
---|
| 276 | else |
---|
| 277 | { |
---|
| 278 | return $comment; |
---|
| 279 | } |
---|
| 280 | } |
---|
| 281 | |
---|
[11325] | 282 | /** |
---|
| 283 | * Replace BBcode tag by a link in notification mails |
---|
| 284 | */ |
---|
| 285 | function replyto_parse_picture_mail($comment) |
---|
| 286 | { |
---|
[11416] | 287 | $comment['content'] = replyto_parse($comment['content']); |
---|
[11325] | 288 | return $comment; |
---|
| 289 | } |
---|
| 290 | |
---|
| 291 | function replyto_parse_album_mail($comment) |
---|
| 292 | { |
---|
[11416] | 293 | $comment['content'] = replyto_parse($comment['content'], 'album'); |
---|
[11325] | 294 | return $comment; |
---|
| 295 | } |
---|
| 296 | |
---|
[11252] | 297 | ?> |
---|