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