[11252] | 1 | <?php |
---|
| 2 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
| 3 | |
---|
| 4 | /** |
---|
| 5 | * Add anchors and reply button to comments blocks |
---|
| 6 | */ |
---|
| 7 | function replyto_add_link() |
---|
| 8 | { |
---|
| 9 | global $pwg_loaded_plugins, $template, $page, $conf; |
---|
| 10 | $template->assign('REPLYTO_PATH', REPLYTO_PATH); |
---|
| 11 | |
---|
| 12 | // comment form has different id |
---|
| 13 | if ( |
---|
| 14 | (isset($_GET['action']) AND $_GET['action'] == 'edit_comment') OR |
---|
| 15 | (isset($page['body_id']) AND $page['body_id'] == 'theCommentsPage') |
---|
| 16 | ) |
---|
| 17 | { |
---|
| 18 | $template->assign('replyto_form_name', 'editComment'); |
---|
| 19 | } |
---|
| 20 | else |
---|
| 21 | { |
---|
| 22 | $template->assign('replyto_form_name', 'addComment'); |
---|
| 23 | } |
---|
| 24 | |
---|
| 25 | // must re-check our location + some additional tests |
---|
| 26 | if (script_basename() == 'picture') |
---|
| 27 | { |
---|
[11299] | 28 | add_event_handler('render_comment_content', 'replyto_parse_picture', 60); |
---|
[11252] | 29 | if ( !is_a_guest() OR $conf['comments_forall'] ) |
---|
| 30 | { |
---|
| 31 | $template->set_prefilter('picture', 'replyto_add_link_prefilter'); |
---|
| 32 | } |
---|
| 33 | } |
---|
| 34 | else if |
---|
| 35 | ( |
---|
| 36 | script_basename() == 'index' AND |
---|
| 37 | isset($pwg_loaded_plugins['Comments_on_Albums']) AND |
---|
| 38 | $page['section'] == 'categories' AND isset($page['category']) |
---|
| 39 | ) |
---|
| 40 | { |
---|
[11299] | 41 | add_event_handler('render_comment_content', 'replyto_parse_album', 60); |
---|
[11252] | 42 | if ( !is_a_guest() OR $conf['comments_forall'] ) |
---|
| 43 | { |
---|
| 44 | $template->set_prefilter('comments_on_albums', 'replyto_add_link_prefilter'); |
---|
| 45 | } |
---|
| 46 | } |
---|
| 47 | } |
---|
| 48 | |
---|
| 49 | function replyto_add_link_prefilter($content, &$smarty) |
---|
| 50 | { |
---|
| 51 | // script |
---|
| 52 | $search[0] = '<ul class="thumbnailCategories">'; |
---|
| 53 | $replace[0] = ' |
---|
| 54 | {combine_script id=\'insertAtCaret\' require=\'jquery\' path=$REPLYTO_PATH|@cat:\'insertAtCaret.js\'} |
---|
| 55 | |
---|
| 56 | {footer_script require=\'insertAtCaret\'} |
---|
| 57 | function replyto(commentID, author) {ldelim} |
---|
| 58 | jQuery("#{$replyto_form_name} textarea").insertAtCaret("[reply=" + commentID + "]" + author + "[/reply] "); |
---|
| 59 | } |
---|
| 60 | {/footer_script} |
---|
| 61 | |
---|
| 62 | {html_head} |
---|
| 63 | <style type="text/css"> |
---|
| 64 | .replyTo {ldelim} |
---|
| 65 | display:inline-block; |
---|
| 66 | width:16px; |
---|
| 67 | height:16px; |
---|
| 68 | background:url({$REPLYTO_PATH}reply.png) center top no-repeat; |
---|
| 69 | } |
---|
| 70 | .replyTo:hover {ldelim} |
---|
| 71 | background-position:center -16px; |
---|
| 72 | } |
---|
| 73 | </style> |
---|
| 74 | {/html_head}' |
---|
| 75 | .$search[0]; |
---|
| 76 | |
---|
| 77 | // button |
---|
| 78 | $search[1] = '<span class="author">'; |
---|
| 79 | $replace[1] = ' |
---|
| 80 | {if not isset($comment.IN_EDIT)} |
---|
| 81 | <div class="actions" style="float:right;"> |
---|
| 82 | <a title="{\'reply to this comment\'|@translate}" class="replyTo" onclick="replyto(\'{$comment.ID}\', \'{$comment.AUTHOR}\');"> </a> |
---|
| 83 | </div> |
---|
| 84 | {/if}' |
---|
| 85 | .$search[1]; |
---|
| 86 | |
---|
| 87 | // anchor |
---|
| 88 | $search[2] = '<div class="thumbnailCategory'; |
---|
| 89 | $replace[2] = ' |
---|
| 90 | <a name="comment-{$comment.ID}"></a>' |
---|
| 91 | .$search[2]; |
---|
| 92 | |
---|
| 93 | return str_replace($search, $replace, $content); |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | |
---|
| 97 | /** |
---|
| 98 | * Replace BBcode tag by a link with absolute url |
---|
| 99 | */ |
---|
| 100 | function replyto_parse_picture($comment) |
---|
| 101 | { |
---|
| 102 | if (preg_match('#\[reply=([1-9]+)\](.*)\[/reply\]#si', $comment, $matches)) |
---|
| 103 | { |
---|
| 104 | // picture informations |
---|
| 105 | $query = ' |
---|
| 106 | SELECT |
---|
| 107 | img.id, |
---|
| 108 | img.file, |
---|
| 109 | cat.category_id |
---|
| 110 | FROM ' . IMAGES_TABLE . ' AS img |
---|
| 111 | INNER JOIN ' . IMAGE_CATEGORY_TABLE . ' AS cat |
---|
| 112 | ON cat.image_id = img.id |
---|
| 113 | INNER JOIN ' . COMMENTS_TABLE . ' AS com |
---|
| 114 | ON com.image_id = img.id |
---|
| 115 | WHERE com.id = ' . $matches[1] . ' |
---|
| 116 | ;'; |
---|
| 117 | $result = pwg_query($query); |
---|
| 118 | |
---|
| 119 | // make sure the target comment exists |
---|
| 120 | if (pwg_db_num_rows($result)) |
---|
| 121 | { |
---|
| 122 | $image = pwg_db_fetch_assoc($result); |
---|
| 123 | |
---|
| 124 | // retrieving category informations |
---|
| 125 | $query = ' |
---|
| 126 | SELECT |
---|
| 127 | id, |
---|
| 128 | name, |
---|
| 129 | permalink, |
---|
| 130 | uppercats |
---|
| 131 | FROM ' . CATEGORIES_TABLE . ' |
---|
| 132 | WHERE id = ' . $image['category_id'] . ' |
---|
| 133 | ;'; |
---|
| 134 | $image['cat'] = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 135 | |
---|
| 136 | // link to the full size picture |
---|
| 137 | $image['url'] = make_picture_url(array( |
---|
| 138 | 'category' => $image['cat'], |
---|
| 139 | 'image_id' => $image['id'], |
---|
| 140 | 'image_file' => $image['file'], |
---|
| 141 | )); |
---|
| 142 | |
---|
| 143 | $search = "#\[reply=([1-9]+)\](.*)\[/reply\]#si"; |
---|
| 144 | $replace = '@ <a href="'.$image['url'].'#comment-$1">$2</a> :'; |
---|
| 145 | } |
---|
| 146 | else |
---|
| 147 | { |
---|
| 148 | $search = "#\[reply=([1-9]+)\](.*)\[/reply\]#si"; |
---|
| 149 | $replace = ''; |
---|
| 150 | } |
---|
| 151 | |
---|
| 152 | return preg_replace($search, $replace, $comment); |
---|
| 153 | } |
---|
| 154 | else |
---|
| 155 | { |
---|
| 156 | return $comment; |
---|
| 157 | } |
---|
| 158 | } |
---|
| 159 | |
---|
| 160 | function replyto_parse_album($comment) |
---|
| 161 | { |
---|
| 162 | if (preg_match('#\[reply=([1-9]+)\](.*)\[/reply\]#si', $comment, $matches)) |
---|
| 163 | { |
---|
| 164 | // check if the comment is really an album comment |
---|
| 165 | // (both comments_on_albums script and default comments script are executed... |
---|
| 166 | // with the same 'render_comment_content' event) |
---|
| 167 | $query = ' |
---|
| 168 | SELECT id |
---|
| 169 | FROM ' . COA_TABLE . ' |
---|
| 170 | WHERE content = "' . $comment .'" |
---|
| 171 | ;'; |
---|
| 172 | if (!pwg_db_num_rows(pwg_query($query))) |
---|
| 173 | { |
---|
| 174 | return $comment; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | // retrieving category informations |
---|
| 178 | $query = ' |
---|
| 179 | SELECT |
---|
| 180 | cat.id, |
---|
| 181 | cat.name, |
---|
| 182 | cat.permalink, |
---|
| 183 | cat.uppercats |
---|
| 184 | FROM ' . COA_TABLE . ' AS com |
---|
| 185 | INNER JOIN ' . CATEGORIES_TABLE . ' AS cat |
---|
| 186 | ON cat.id = com.category_id |
---|
| 187 | WHERE com.id = ' . $matches[1] . ' |
---|
| 188 | ;'; |
---|
| 189 | $result = pwg_query($query); |
---|
| 190 | |
---|
| 191 | // make sure the target comment exists |
---|
| 192 | if (pwg_db_num_rows($result)) |
---|
| 193 | { |
---|
| 194 | $category = pwg_db_fetch_assoc($result); |
---|
| 195 | |
---|
| 196 | // link to the album |
---|
| 197 | $category['url'] = make_index_url(array( |
---|
| 198 | 'category' => $category, |
---|
| 199 | )); |
---|
| 200 | |
---|
| 201 | $search = "#\[reply=([1-9]+)\](.*)\[/reply\]#si"; |
---|
| 202 | $replace = '@ <a href="'.$category['url'].'#comment-$1">$2</a> :'; |
---|
| 203 | } |
---|
| 204 | else |
---|
| 205 | { |
---|
| 206 | $search = "#\[reply=([1-9]+)\](.*)\[/reply\]#si"; |
---|
| 207 | $replace = ''; |
---|
| 208 | } |
---|
| 209 | |
---|
| 210 | return preg_replace($search, $replace, $comment); |
---|
| 211 | } |
---|
| 212 | else |
---|
| 213 | { |
---|
| 214 | return $comment; |
---|
| 215 | } |
---|
| 216 | } |
---|
| 217 | |
---|
| 218 | ?> |
---|