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