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