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'] ] = 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); |
---|
43 | $template->set_prefilter('comments', 'replyto_add_link_comments_prefilter'); |
---|
44 | } |
---|
45 | } |
---|
46 | /* PICTURE page */ |
---|
47 | else if (script_basename() == 'picture') |
---|
48 | { |
---|
49 | $location = 'picture'; |
---|
50 | add_event_handler('user_comment_insertion', 'replyto_parse_picture_mail'); |
---|
51 | |
---|
52 | if ( !is_a_guest() OR $conf['comments_forall'] ) |
---|
53 | { |
---|
54 | $template->set_prefilter('picture', 'replyto_add_link_prefilter'); |
---|
55 | } |
---|
56 | } |
---|
57 | /* ALBUM page */ |
---|
58 | else if |
---|
59 | ( |
---|
60 | script_basename() == 'index' AND isset($page['section']) AND |
---|
61 | isset($pwg_loaded_plugins['Comments_on_Albums']) AND |
---|
62 | $page['section'] == 'categories' AND isset($page['category']) |
---|
63 | ) |
---|
64 | { |
---|
65 | $location = 'album'; |
---|
66 | add_event_handler('user_comment_insertion', 'replyto_parse_album_mail'); |
---|
67 | |
---|
68 | if ( !is_a_guest() OR $conf['comments_forall'] ) |
---|
69 | { |
---|
70 | $template->set_prefilter('comments_on_albums', 'replyto_add_link_prefilter'); |
---|
71 | } |
---|
72 | } |
---|
73 | |
---|
74 | |
---|
75 | /* we come from comments.php page */ |
---|
76 | if ( !empty($_GET['rt']) and !empty($_GET['rta']) ) |
---|
77 | { |
---|
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 | } |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | /** |
---|
90 | * add reply tag from values given in url |
---|
91 | */ |
---|
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 | */ |
---|
102 | function replyto_add_link_comments_prefilter($content, &$smarty) |
---|
103 | { |
---|
104 | // style |
---|
105 | $search[0] = '<ul class="commentsList">'; |
---|
106 | $replace[0] = ' |
---|
107 | {html_head} |
---|
108 | <style type="text/css"> |
---|
109 | .replyTo {ldelim} |
---|
110 | display:none; |
---|
111 | background:url({$REPLYTO_PATH}reply.png) left top no-repeat; |
---|
112 | height:16px; |
---|
113 | margin-left:20px; |
---|
114 | padding-left:20px; |
---|
115 | } |
---|
116 | li.commentElement:hover .replyTo {ldelim} |
---|
117 | display:inline; |
---|
118 | } |
---|
119 | .replyTo:hover {ldelim} |
---|
120 | background-position:left -16px; |
---|
121 | } |
---|
122 | </style> |
---|
123 | {/html_head}' |
---|
124 | .$search[0]; |
---|
125 | |
---|
126 | // button |
---|
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>'; |
---|
129 | |
---|
130 | return str_replace($search, $replace, $content); |
---|
131 | } |
---|
132 | |
---|
133 | /** |
---|
134 | * reply buttons on picture.php and index.php pages |
---|
135 | */ |
---|
136 | function replyto_add_link_prefilter($content, &$smarty) |
---|
137 | { |
---|
138 | // script & style |
---|
139 | $search[0] = '<ul class="commentsList">'; |
---|
140 | $replace[0] = ' |
---|
141 | {combine_script id=\'insertAtCaret\' require=\'jquery\' path=$REPLYTO_PATH|@cat:\'insertAtCaret.js\'} |
---|
142 | |
---|
143 | {footer_script require=\'insertAtCaret\'} |
---|
144 | function replyTo(commentID, author) {ldelim} |
---|
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} |
---|
152 | display:none; |
---|
153 | background:url({$REPLYTO_PATH}reply.png) left top no-repeat; |
---|
154 | height:16px; |
---|
155 | margin-left:20px; |
---|
156 | padding-left:20px; |
---|
157 | } |
---|
158 | li.commentElement:hover .replyTo {ldelim} |
---|
159 | display:inline; |
---|
160 | } |
---|
161 | .replyTo:hover {ldelim} |
---|
162 | background-position:left -16px; |
---|
163 | } |
---|
164 | </style> |
---|
165 | {/html_head}' |
---|
166 | .$search[0]; |
---|
167 | |
---|
168 | // button |
---|
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>'; |
---|
171 | |
---|
172 | // anchors |
---|
173 | $search[2] = '<li class="commentElement'; |
---|
174 | $replace[2] = '<a name="comment-{$comment.ID}"></a>'.$search[2]; |
---|
175 | |
---|
176 | $search[3] = '<div id="commentAdd">'; |
---|
177 | $replace[3] = $search[3].'<a name="commentform"></a>'; |
---|
178 | |
---|
179 | return str_replace($search, $replace, $content); |
---|
180 | } |
---|
181 | |
---|
182 | |
---|
183 | /** |
---|
184 | * Replace BBcode tag by a link with absolute url |
---|
185 | */ |
---|
186 | function replyto_parse($comment, $in_album = false) |
---|
187 | { |
---|
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 = ' |
---|
195 | SELECT |
---|
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] . ' |
---|
205 | ;'; |
---|
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); |
---|
212 | |
---|
213 | // retrieving category informations |
---|
214 | $query = ' |
---|
215 | SELECT |
---|
216 | id, |
---|
217 | name, |
---|
218 | permalink, |
---|
219 | uppercats |
---|
220 | FROM ' . CATEGORIES_TABLE . ' |
---|
221 | WHERE id = ' . $image['category_id'] . ' |
---|
222 | ;'; |
---|
223 | $image['cat'] = pwg_db_fetch_assoc(pwg_query($query)); |
---|
224 | |
---|
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 */ |
---|
240 | else if ( $in_album == 'album') |
---|
241 | { |
---|
242 | // retrieving category informations |
---|
243 | $query = ' |
---|
244 | SELECT |
---|
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] . ' |
---|
253 | ;'; |
---|
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); |
---|
260 | |
---|
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 | } |
---|
272 | } |
---|
273 | |
---|
274 | return preg_replace(REPLYTO_REGEX, $replace, $comment); |
---|
275 | } |
---|
276 | else |
---|
277 | { |
---|
278 | return $comment; |
---|
279 | } |
---|
280 | } |
---|
281 | |
---|
282 | /** |
---|
283 | * Replace BBcode tag by a link in notification mails |
---|
284 | */ |
---|
285 | function replyto_parse_picture_mail($comment) |
---|
286 | { |
---|
287 | $comment['content'] = replyto_parse($comment['content']); |
---|
288 | return $comment; |
---|
289 | } |
---|
290 | |
---|
291 | function replyto_parse_album_mail($comment) |
---|
292 | { |
---|
293 | $comment['content'] = replyto_parse($comment['content'], 'album'); |
---|
294 | return $comment; |
---|
295 | } |
---|
296 | |
---|
297 | ?> |
---|