1 | <?php |
---|
2 | /* inspired by comments.php */ |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | load_language('plugin.lang', COA_PATH); |
---|
5 | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | add a button for switch page | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | $template->assign('COA_MODE', (isset($_GET['display_mode']) and $_GET['display_mode'] == 'albums') ? 'albums' : 'photos'); |
---|
10 | $template->set_prefilter('comments', 'coa_add_button'); |
---|
11 | |
---|
12 | function coa_add_button($content, &$smarty) |
---|
13 | { |
---|
14 | $search ='<form class="filter" action="{$F_ACTION}" method="get">'; |
---|
15 | $replacement = ' |
---|
16 | <form class="filter"> |
---|
17 | <fieldset> |
---|
18 | <legend>{\'Display comments on\'|@translate}</legend> |
---|
19 | <span style="font-size:1.1em;"><a href="comments.php" {if $COA_MODE=="photos"}style="font-weight:bold;"{/if}>{\'Photos\'|@translate}</a> | |
---|
20 | <a href="comments.php?display_mode=albums" {if $COA_MODE=="albums"}style="font-weight:bold;"{/if}>{\'Albums\'|@translate}</a></span> |
---|
21 | </fieldset> |
---|
22 | </form>'; |
---|
23 | |
---|
24 | return str_replace($search, $replacement.$search, $content); |
---|
25 | } |
---|
26 | |
---|
27 | |
---|
28 | // +-----------------------------------------------------------------------+ |
---|
29 | // comments on albums page | |
---|
30 | // +-----------------------------------------------------------------------+ |
---|
31 | if ( isset($_GET['display_mode']) and $_GET['display_mode'] == 'albums' ) |
---|
32 | { |
---|
33 | include_once(COA_PATH.'include/functions_comment.inc.php'); // custom functions |
---|
34 | |
---|
35 | // reset some template vars |
---|
36 | $template->clear_assign(array('comments', 'navbar', 'sort_by_options')); |
---|
37 | |
---|
38 | // sort_by : database fields proposed for sorting comments list |
---|
39 | $sort_by = array( |
---|
40 | 'date' => l10n('comment date'), |
---|
41 | 'category_id' => l10n('album') |
---|
42 | ); |
---|
43 | $template->assign('sort_by_options', $sort_by); |
---|
44 | |
---|
45 | // clean where_clauses from unknown column |
---|
46 | foreach ($page['where_clauses'] as &$cond) |
---|
47 | { |
---|
48 | if (strpos($cond, 'ic.image_id') !== false) |
---|
49 | { |
---|
50 | $cond = get_sql_condition_FandF(array( |
---|
51 | 'forbidden_categories' => 'category_id', |
---|
52 | 'visible_categories' => 'category_id' |
---|
53 | ), |
---|
54 | '', true); |
---|
55 | } |
---|
56 | } |
---|
57 | unset($cond); |
---|
58 | |
---|
59 | // +-----------------------------------------------------------------------+ |
---|
60 | // | comments management | |
---|
61 | // +-----------------------------------------------------------------------+ |
---|
62 | $comment_id = null; |
---|
63 | $action = null; |
---|
64 | |
---|
65 | $actions = array('delete_albums', 'validate_albums', 'edit_albums'); // different indexes to not interfer with the main process |
---|
66 | foreach ($actions as $loop_action) |
---|
67 | { |
---|
68 | if (isset($_GET[$loop_action])) |
---|
69 | { |
---|
70 | $action = $loop_action; |
---|
71 | check_input_parameter($action, $_GET, false, PATTERN_ID); |
---|
72 | $comment_id = $_GET[$action]; |
---|
73 | break; |
---|
74 | } |
---|
75 | } |
---|
76 | |
---|
77 | if (isset($action)) |
---|
78 | { |
---|
79 | $comment_author_id = get_comment_author_id_albums($comment_id); |
---|
80 | |
---|
81 | if (can_manage_comment(str_replace('_albums', null, $action), $comment_author_id)) |
---|
82 | { |
---|
83 | $perform_redirect = false; |
---|
84 | |
---|
85 | if ('delete_albums' == $action) |
---|
86 | { |
---|
87 | check_pwg_token(); |
---|
88 | delete_user_comment_albums($comment_id); |
---|
89 | $perform_redirect = true; |
---|
90 | } |
---|
91 | if ('validate_albums' == $action) |
---|
92 | { |
---|
93 | check_pwg_token(); |
---|
94 | validate_user_comment_albums($comment_id); |
---|
95 | $perform_redirect = true; |
---|
96 | } |
---|
97 | if ('edit_albums' == $action) |
---|
98 | { |
---|
99 | if (!empty($_POST['content'])) |
---|
100 | { |
---|
101 | check_pwg_token(); |
---|
102 | update_user_comment_albums( |
---|
103 | array( |
---|
104 | 'comment_id' => $_GET['edit_albums'], |
---|
105 | 'category_id' => $_POST['image_id'], |
---|
106 | 'content' => $_POST['content'] |
---|
107 | ), |
---|
108 | $_POST['key'] |
---|
109 | ); |
---|
110 | |
---|
111 | $perform_redirect = true; |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | $edit_comment = $_GET['edit_albums']; |
---|
116 | } |
---|
117 | } |
---|
118 | if ($perform_redirect) |
---|
119 | { |
---|
120 | $redirect_url = |
---|
121 | PHPWG_ROOT_PATH |
---|
122 | .'comments.php' |
---|
123 | .get_query_string_diff(array('delete_albums','validate_albums','edit_albums','pwg_token')); |
---|
124 | |
---|
125 | redirect($redirect_url); |
---|
126 | } |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | // +-----------------------------------------------------------------------+ |
---|
131 | // | navigation bar | |
---|
132 | // +-----------------------------------------------------------------------+ |
---|
133 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
134 | { |
---|
135 | $start = $_GET['start']; |
---|
136 | } |
---|
137 | else |
---|
138 | { |
---|
139 | $start = 0; |
---|
140 | } |
---|
141 | |
---|
142 | $query = ' |
---|
143 | SELECT COUNT(DISTINCT(com.id)) |
---|
144 | FROM '.COA_TABLE.' AS com |
---|
145 | LEFT JOIN '.USERS_TABLE.' As u |
---|
146 | ON u.'.$conf['user_fields']['id'].' = com.author_id |
---|
147 | WHERE '.implode(' |
---|
148 | AND ', $page['where_clauses']).' |
---|
149 | ;'; |
---|
150 | list($counter) = pwg_db_fetch_row(pwg_query($query)); |
---|
151 | |
---|
152 | $url = PHPWG_ROOT_PATH |
---|
153 | .'comments.php' |
---|
154 | .get_query_string_diff(array('start','delete_albums','validate_albums','edit_albums','pwg_token')); |
---|
155 | |
---|
156 | $navbar = create_navigation_bar( |
---|
157 | $url, |
---|
158 | $counter, |
---|
159 | $start, |
---|
160 | $page['items_number'], |
---|
161 | '' |
---|
162 | ); |
---|
163 | |
---|
164 | $template->assign('navbar', $navbar); |
---|
165 | |
---|
166 | // +-----------------------------------------------------------------------+ |
---|
167 | // | last comments display | |
---|
168 | // +-----------------------------------------------------------------------+ |
---|
169 | $comments = array(); |
---|
170 | $element_ids = array(); |
---|
171 | $category_ids = array(); |
---|
172 | |
---|
173 | $query = ' |
---|
174 | SELECT |
---|
175 | com.id AS comment_id, |
---|
176 | com.category_id, |
---|
177 | com.author, |
---|
178 | com.author_id, |
---|
179 | u.'.$conf['user_fields']['username'].' AS username, |
---|
180 | u.'.$conf['user_fields']['email'].' AS user_email, |
---|
181 | com.email, |
---|
182 | com.date, |
---|
183 | com.website_url, |
---|
184 | com.content, |
---|
185 | com.validated |
---|
186 | FROM '.COA_TABLE.' AS com |
---|
187 | LEFT JOIN '.USERS_TABLE.' As u |
---|
188 | ON u.'.$conf['user_fields']['id'].' = com.author_id |
---|
189 | WHERE '.implode(' |
---|
190 | AND ', $page['where_clauses']).' |
---|
191 | GROUP BY |
---|
192 | comment_id, |
---|
193 | com.category_id, |
---|
194 | com.author, |
---|
195 | com.author_id, |
---|
196 | com.date, |
---|
197 | com.content, |
---|
198 | com.validated |
---|
199 | ORDER BY '.$page['sort_by'].' '.$page['sort_order']; |
---|
200 | if ('all' != $page['items_number']) |
---|
201 | { |
---|
202 | $query.= ' |
---|
203 | LIMIT '.$page['items_number'].' OFFSET '.$start; |
---|
204 | } |
---|
205 | $query.= ' |
---|
206 | ;'; |
---|
207 | $result = pwg_query($query); |
---|
208 | |
---|
209 | while ($row = pwg_db_fetch_assoc($result)) |
---|
210 | { |
---|
211 | array_push($comments, $row); |
---|
212 | array_push($element_ids, $row['category_id']); |
---|
213 | } |
---|
214 | |
---|
215 | if (count($comments) > 0) |
---|
216 | { |
---|
217 | // retrieving category informations |
---|
218 | $query = ' |
---|
219 | SELECT |
---|
220 | cat.id, |
---|
221 | cat.name, |
---|
222 | cat.permalink, |
---|
223 | cat.uppercats, |
---|
224 | com.id as comment_id, |
---|
225 | img.id AS image_id, |
---|
226 | img.path |
---|
227 | FROM '.CATEGORIES_TABLE.' AS cat |
---|
228 | LEFT JOIN '.COA_TABLE.' AS com |
---|
229 | ON com.category_id = cat.id |
---|
230 | LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc |
---|
231 | ON ucc.cat_id = cat.id AND ucc.user_id = '.$user['id'].' |
---|
232 | LEFT JOIN '.IMAGES_TABLE.' AS img |
---|
233 | ON img.id = ucc.user_representative_picture_id |
---|
234 | '.get_sql_condition_FandF( |
---|
235 | array( |
---|
236 | 'forbidden_categories' => 'cat.id', |
---|
237 | 'visible_categories' => 'cat.id' |
---|
238 | ), |
---|
239 | 'WHERE' |
---|
240 | ).' |
---|
241 | AND cat.id IN ('.implode(',', $element_ids).') |
---|
242 | ;'; |
---|
243 | $categories = hash_from_query($query, 'comment_id'); |
---|
244 | |
---|
245 | foreach ($comments as $comment) |
---|
246 | { |
---|
247 | // source of the thumbnail picture |
---|
248 | $comment['src_image'] = new SrcImage($categories[$comment['comment_id']]); |
---|
249 | |
---|
250 | // category url |
---|
251 | $comment['cat_url'] = duplicate_index_url( |
---|
252 | array( |
---|
253 | 'category' => array( |
---|
254 | 'id' => $categories[$comment['comment_id']]['id'], |
---|
255 | 'name' => $categories[$comment['comment_id']]['name'], |
---|
256 | 'permalink' => $categories[$comment['comment_id']]['permalink'], |
---|
257 | ), |
---|
258 | array('start') |
---|
259 | ) |
---|
260 | ); |
---|
261 | |
---|
262 | $email = null; |
---|
263 | if (!empty($comment['user_email'])) |
---|
264 | { |
---|
265 | $email = $comment['user_email']; |
---|
266 | } |
---|
267 | else if (!empty($comment['email'])) |
---|
268 | { |
---|
269 | $email = $comment['email']; |
---|
270 | } |
---|
271 | |
---|
272 | // comment content |
---|
273 | $tpl_comment = array( |
---|
274 | 'ID' => $comment['comment_id'], |
---|
275 | 'U_PICTURE' => $comment['cat_url'], |
---|
276 | 'ALT' => trigger_event('render_category_name', $categories[$comment['comment_id']]['name']), |
---|
277 | 'src_image' => $comment['src_image'], |
---|
278 | 'AUTHOR' => trigger_event('render_comment_author', $comment['author']), |
---|
279 | 'WEBSITE_URL' => $comment['website_url'], |
---|
280 | 'DATE' => format_date($comment['date'], true), |
---|
281 | 'CONTENT' => trigger_event('render_comment_content', $comment['content'], 'album'), |
---|
282 | ); |
---|
283 | |
---|
284 | if (is_admin()) |
---|
285 | { |
---|
286 | $tpl_comment['EMAIL'] = $email; |
---|
287 | } |
---|
288 | |
---|
289 | // rights |
---|
290 | if (can_manage_comment('delete', $comment['author_id'])) |
---|
291 | { |
---|
292 | $tpl_comment['U_DELETE'] = add_url_params( |
---|
293 | $url, |
---|
294 | array( |
---|
295 | 'delete_albums' => $comment['comment_id'], |
---|
296 | 'pwg_token' => get_pwg_token(), |
---|
297 | ) |
---|
298 | ); |
---|
299 | } |
---|
300 | if (can_manage_comment('edit', $comment['author_id'])) |
---|
301 | { |
---|
302 | $tpl_comment['U_EDIT'] = add_url_params( |
---|
303 | $url, |
---|
304 | array( |
---|
305 | 'edit_albums' => $comment['comment_id'], |
---|
306 | ) |
---|
307 | ); |
---|
308 | |
---|
309 | if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment)) |
---|
310 | { |
---|
311 | $tpl_comment['IN_EDIT'] = true; |
---|
312 | $key = get_ephemeral_key(2, $comment['category_id']); |
---|
313 | $tpl_comment['KEY'] = $key; |
---|
314 | $tpl_comment['IMAGE_ID'] = $comment['category_id']; |
---|
315 | $tpl_comment['CONTENT'] = $comment['content']; |
---|
316 | $tpl_comment['PWG_TOKEN'] = get_pwg_token(); |
---|
317 | } |
---|
318 | } |
---|
319 | if (can_manage_comment('validate', $comment['author_id'])) |
---|
320 | { |
---|
321 | if ('true' != $comment['validated']) |
---|
322 | { |
---|
323 | $tpl_comment['U_VALIDATE'] = add_url_params( |
---|
324 | $url, |
---|
325 | array( |
---|
326 | 'validate_albums'=> $comment['comment_id'], |
---|
327 | 'pwg_token' => get_pwg_token(), |
---|
328 | ) |
---|
329 | ); |
---|
330 | } |
---|
331 | } |
---|
332 | |
---|
333 | $template->append('comments', $tpl_comment); |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | // +-----------------------------------------------------------------------+ |
---|
338 | // | template | |
---|
339 | // +-----------------------------------------------------------------------+ |
---|
340 | // add a line to display category name |
---|
341 | $template->set_prefilter('comments', 'coa_change_comments_list'); |
---|
342 | |
---|
343 | function coa_change_comments_list($content, &$smarty) { |
---|
344 | $search = '<a href="{$comment.U_PICTURE}">'; |
---|
345 | $replacement = $search.'{$comment.ALT}<br/>'; |
---|
346 | return str_replace($search, $replacement, $content); |
---|
347 | } |
---|
348 | } |
---|
349 | |
---|
350 | ?> |
---|