[166] | 1 | <?php |
---|
[354] | 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[3049] | 5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
[2297] | 6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
| 7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // | This program is free software; you can redistribute it and/or modify | |
---|
| 10 | // | it under the terms of the GNU General Public License as published by | |
---|
| 11 | // | the Free Software Foundation | |
---|
| 12 | // | | |
---|
| 13 | // | This program is distributed in the hope that it will be useful, but | |
---|
| 14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
| 15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
| 16 | // | General Public License for more details. | |
---|
| 17 | // | | |
---|
| 18 | // | You should have received a copy of the GNU General Public License | |
---|
| 19 | // | along with this program; if not, write to the Free Software | |
---|
| 20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
| 21 | // | USA. | |
---|
| 22 | // +-----------------------------------------------------------------------+ |
---|
[166] | 23 | |
---|
[579] | 24 | // +-----------------------------------------------------------------------+ |
---|
| 25 | // | initialization | |
---|
| 26 | // +-----------------------------------------------------------------------+ |
---|
[1598] | 27 | define('PHPWG_ROOT_PATH','./'); |
---|
| 28 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
[3445] | 29 | include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php'); |
---|
[345] | 30 | |
---|
[1072] | 31 | // +-----------------------------------------------------------------------+ |
---|
| 32 | // | Check Access and exit when user status is not ok | |
---|
| 33 | // +-----------------------------------------------------------------------+ |
---|
| 34 | check_status(ACCESS_GUEST); |
---|
| 35 | |
---|
[796] | 36 | $sort_order = array( |
---|
[2223] | 37 | 'DESC' => l10n('descending'), |
---|
| 38 | 'ASC' => l10n('ascending') |
---|
[796] | 39 | ); |
---|
| 40 | |
---|
| 41 | // sort_by : database fields proposed for sorting comments list |
---|
| 42 | $sort_by = array( |
---|
[2223] | 43 | 'date' => l10n('comment date'), |
---|
| 44 | 'image_id' => l10n('picture') |
---|
[796] | 45 | ); |
---|
| 46 | |
---|
| 47 | // items_number : list of number of items to display per page |
---|
| 48 | $items_number = array(5,10,20,50,'all'); |
---|
| 49 | |
---|
| 50 | // since when display comments ? |
---|
| 51 | // |
---|
| 52 | $since_options = array( |
---|
| 53 | 1 => array('label' => l10n('today'), |
---|
| 54 | 'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 1 DAY)'), |
---|
| 55 | 2 => array('label' => sprintf(l10n('last %d days'), 7), |
---|
| 56 | 'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 7 DAY)'), |
---|
| 57 | 3 => array('label' => sprintf(l10n('last %d days'), 30), |
---|
| 58 | 'clause' => 'date > SUBDATE(CURDATE(), INTERVAL 30 DAY)'), |
---|
| 59 | 4 => array('label' => l10n('the beginning'), |
---|
| 60 | 'clause' => '1=1') // stupid but generic |
---|
| 61 | ); |
---|
| 62 | |
---|
[1716] | 63 | $page['since'] = isset($_GET['since']) ? $_GET['since'] : 4; |
---|
[796] | 64 | |
---|
| 65 | // on which field sorting |
---|
| 66 | // |
---|
| 67 | $page['sort_by'] = 'date'; |
---|
| 68 | // if the form was submitted, it overloads default behaviour |
---|
[2757] | 69 | if (isset($_GET['sort_by']) and isset($sort_by[$_GET['sort_by']]) ) |
---|
[393] | 70 | { |
---|
[796] | 71 | $page['sort_by'] = $_GET['sort_by']; |
---|
[393] | 72 | } |
---|
[796] | 73 | |
---|
| 74 | // order to sort |
---|
| 75 | // |
---|
[2223] | 76 | $page['sort_order'] = 'DESC'; |
---|
[796] | 77 | // if the form was submitted, it overloads default behaviour |
---|
[2757] | 78 | if (isset($_GET['sort_order']) and isset($sort_order[$_GET['sort_order']])) |
---|
[393] | 79 | { |
---|
[2223] | 80 | $page['sort_order'] = $_GET['sort_order']; |
---|
[393] | 81 | } |
---|
[796] | 82 | |
---|
| 83 | // number of items to display |
---|
| 84 | // |
---|
[1814] | 85 | $page['items_number'] = 10; |
---|
[796] | 86 | if (isset($_GET['items_number'])) |
---|
| 87 | { |
---|
| 88 | $page['items_number'] = $_GET['items_number']; |
---|
| 89 | } |
---|
[3600] | 90 | if ( !is_numeric($page['items_number']) and $page['items_number']!='all' ) |
---|
[3520] | 91 | { |
---|
| 92 | $page['items_number'] = 10; |
---|
| 93 | } |
---|
[796] | 94 | |
---|
[1716] | 95 | $page['where_clauses'] = array(); |
---|
| 96 | |
---|
[796] | 97 | // which category to filter on ? |
---|
| 98 | if (isset($_GET['cat']) and 0 != $_GET['cat']) |
---|
| 99 | { |
---|
[1716] | 100 | $page['where_clauses'][] = |
---|
[796] | 101 | 'category_id IN ('.implode(',', get_subcat_ids(array($_GET['cat']))).')'; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | // search a particular author |
---|
| 105 | if (isset($_GET['author']) and !empty($_GET['author'])) |
---|
| 106 | { |
---|
[3487] | 107 | $page['where_clauses'][] = |
---|
| 108 | 'u.'.$conf['user_fields']['username'].' = \''.$_GET['author'].'\' |
---|
| 109 | OR author = \''.$_GET['author'].'\''; |
---|
[796] | 110 | } |
---|
| 111 | |
---|
| 112 | // search a substring among comments content |
---|
| 113 | if (isset($_GET['keyword']) and !empty($_GET['keyword'])) |
---|
| 114 | { |
---|
[1716] | 115 | $page['where_clauses'][] = |
---|
[796] | 116 | '('. |
---|
| 117 | implode(' AND ', |
---|
| 118 | array_map( |
---|
| 119 | create_function( |
---|
| 120 | '$s', |
---|
| 121 | 'return "content LIKE \'%$s%\'";' |
---|
| 122 | ), |
---|
[2012] | 123 | preg_split('/[\s,;]+/', $_GET['keyword'] ) |
---|
[796] | 124 | ) |
---|
| 125 | ). |
---|
| 126 | ')'; |
---|
| 127 | } |
---|
| 128 | |
---|
[1716] | 129 | $page['where_clauses'][] = $since_options[$page['since']]['clause']; |
---|
| 130 | |
---|
[1598] | 131 | // which status to filter on ? |
---|
[1716] | 132 | if ( !is_admin() ) |
---|
[1598] | 133 | { |
---|
[1716] | 134 | $page['where_clauses'][] = 'validated="true"'; |
---|
[1598] | 135 | } |
---|
| 136 | |
---|
[1716] | 137 | $page['where_clauses'][] = get_sql_condition_FandF |
---|
| 138 | ( |
---|
| 139 | array |
---|
| 140 | ( |
---|
| 141 | 'forbidden_categories' => 'category_id', |
---|
| 142 | 'visible_categories' => 'category_id', |
---|
| 143 | 'visible_images' => 'ic.image_id' |
---|
| 144 | ), |
---|
| 145 | '', true |
---|
| 146 | ); |
---|
[1598] | 147 | |
---|
[579] | 148 | // +-----------------------------------------------------------------------+ |
---|
| 149 | // | comments management | |
---|
| 150 | // +-----------------------------------------------------------------------+ |
---|
[1617] | 151 | if (isset($_GET['delete']) and is_numeric($_GET['delete']) |
---|
[3445] | 152 | and (is_admin() || $conf['user_can_delete_comment'])) |
---|
[1617] | 153 | {// comments deletion |
---|
[3445] | 154 | delete_user_comment($_GET['delete']); |
---|
[1617] | 155 | } |
---|
[1598] | 156 | |
---|
[1617] | 157 | if (isset($_GET['validate']) and is_numeric($_GET['validate']) |
---|
| 158 | and !is_adviser() ) |
---|
| 159 | { // comments validation |
---|
| 160 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 161 | $query = ' |
---|
[579] | 162 | UPDATE '.COMMENTS_TABLE.' |
---|
| 163 | SET validated = \'true\' |
---|
[1617] | 164 | , validation_date = NOW() |
---|
[1598] | 165 | WHERE id='.$_GET['validate'].' |
---|
[579] | 166 | ;'; |
---|
[1617] | 167 | pwg_query($query); |
---|
[579] | 168 | } |
---|
[1617] | 169 | |
---|
[3445] | 170 | if (isset($_GET['edit']) and is_numeric($_GET['edit']) |
---|
| 171 | and (is_admin() || $conf['user_can_edit_comment'])) |
---|
| 172 | { |
---|
[3487] | 173 | if (!empty($_POST['content'])) |
---|
[3445] | 174 | { |
---|
[3487] | 175 | update_user_comment(array('comment_id' => $_GET['edit'], |
---|
[3445] | 176 | 'image_id' => $_POST['image_id'], |
---|
| 177 | 'content' => $_POST['content']), |
---|
| 178 | $_POST['key'] |
---|
[3487] | 179 | ); |
---|
[3445] | 180 | |
---|
| 181 | $edit_comment = null; |
---|
| 182 | } |
---|
[3487] | 183 | else |
---|
[3445] | 184 | { |
---|
| 185 | $edit_comment = $_GET['edit']; |
---|
| 186 | } |
---|
| 187 | } |
---|
| 188 | |
---|
[579] | 189 | // +-----------------------------------------------------------------------+ |
---|
| 190 | // | page header and options | |
---|
| 191 | // +-----------------------------------------------------------------------+ |
---|
[355] | 192 | |
---|
[2268] | 193 | $title= l10n('User comments'); |
---|
[850] | 194 | $page['body_id'] = 'theCommentsPage'; |
---|
| 195 | |
---|
[579] | 196 | $template->set_filenames(array('comments'=>'comments.tpl')); |
---|
[2223] | 197 | $template->assign( |
---|
[579] | 198 | array( |
---|
[796] | 199 | 'F_ACTION'=>PHPWG_ROOT_PATH.'comments.php', |
---|
[2134] | 200 | 'F_KEYWORD'=>@htmlspecialchars(stripslashes($_GET['keyword'])), |
---|
| 201 | 'F_AUTHOR'=>@htmlspecialchars(stripslashes($_GET['author'])), |
---|
[579] | 202 | ) |
---|
| 203 | ); |
---|
[355] | 204 | |
---|
[796] | 205 | // +-----------------------------------------------------------------------+ |
---|
| 206 | // | form construction | |
---|
| 207 | // +-----------------------------------------------------------------------+ |
---|
| 208 | |
---|
| 209 | // Search in a particular category |
---|
[2223] | 210 | $blockname = 'categories'; |
---|
[796] | 211 | |
---|
| 212 | $query = ' |
---|
[1861] | 213 | SELECT id, name, uppercats, global_rank |
---|
[1677] | 214 | FROM '.CATEGORIES_TABLE.' |
---|
| 215 | '.get_sql_condition_FandF |
---|
| 216 | ( |
---|
| 217 | array |
---|
| 218 | ( |
---|
| 219 | 'forbidden_categories' => 'id', |
---|
| 220 | 'visible_categories' => 'id' |
---|
| 221 | ), |
---|
| 222 | 'WHERE' |
---|
| 223 | ).' |
---|
[796] | 224 | ;'; |
---|
| 225 | display_select_cat_wrapper($query, array(@$_GET['cat']), $blockname, true); |
---|
| 226 | |
---|
| 227 | // Filter on recent comments... |
---|
[2223] | 228 | $tpl_var=array(); |
---|
[796] | 229 | foreach ($since_options as $id => $option) |
---|
| 230 | { |
---|
[2223] | 231 | $tpl_var[ $id ] = $option['label']; |
---|
[355] | 232 | } |
---|
[2223] | 233 | $template->assign( 'since_options', $tpl_var); |
---|
| 234 | $template->assign( 'since_options_selected', $page['since']); |
---|
[796] | 235 | |
---|
| 236 | // Sort by |
---|
[2223] | 237 | $template->assign( 'sort_by_options', $sort_by); |
---|
| 238 | $template->assign( 'sort_by_options_selected', $page['sort_by']); |
---|
[796] | 239 | |
---|
| 240 | // Sorting order |
---|
[2223] | 241 | $template->assign( 'sort_order_options', $sort_order); |
---|
| 242 | $template->assign( 'sort_order_options_selected', $page['sort_order']); |
---|
[796] | 243 | |
---|
| 244 | |
---|
| 245 | // Number of items |
---|
| 246 | $blockname = 'items_number_option'; |
---|
[2223] | 247 | $tpl_var=array(); |
---|
[796] | 248 | foreach ($items_number as $option) |
---|
| 249 | { |
---|
[2223] | 250 | $tpl_var[ $option ] = is_numeric($option) ? $option : l10n($option); |
---|
[796] | 251 | } |
---|
[2223] | 252 | $template->assign( 'item_number_options', $tpl_var); |
---|
| 253 | $template->assign( 'item_number_options_selected', $page['items_number']); |
---|
[796] | 254 | |
---|
[2223] | 255 | |
---|
[579] | 256 | // +-----------------------------------------------------------------------+ |
---|
[796] | 257 | // | navigation bar | |
---|
| 258 | // +-----------------------------------------------------------------------+ |
---|
| 259 | |
---|
| 260 | if (isset($_GET['start']) and is_numeric($_GET['start'])) |
---|
| 261 | { |
---|
| 262 | $start = $_GET['start']; |
---|
| 263 | } |
---|
| 264 | else |
---|
| 265 | { |
---|
| 266 | $start = 0; |
---|
| 267 | } |
---|
| 268 | |
---|
| 269 | $query = ' |
---|
[3450] | 270 | SELECT COUNT(DISTINCT(com.id)) |
---|
[796] | 271 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
| 272 | INNER JOIN '.COMMENTS_TABLE.' AS com |
---|
| 273 | ON ic.image_id = com.image_id |
---|
[1716] | 274 | WHERE '.implode(' |
---|
| 275 | AND ', $page['where_clauses']).' |
---|
[796] | 276 | ;'; |
---|
| 277 | list($counter) = mysql_fetch_row(pwg_query($query)); |
---|
| 278 | |
---|
[1598] | 279 | $url = PHPWG_ROOT_PATH |
---|
| 280 | .'comments.php' |
---|
| 281 | .get_query_string_diff(array('start','delete','validate')); |
---|
[796] | 282 | |
---|
| 283 | $navbar = create_navigation_bar($url, |
---|
| 284 | $counter, |
---|
| 285 | $start, |
---|
| 286 | $page['items_number'], |
---|
| 287 | ''); |
---|
| 288 | |
---|
[3172] | 289 | $template->assign('navbar', $navbar); |
---|
[796] | 290 | |
---|
| 291 | // +-----------------------------------------------------------------------+ |
---|
[579] | 292 | // | last comments display | |
---|
| 293 | // +-----------------------------------------------------------------------+ |
---|
[355] | 294 | |
---|
[796] | 295 | $comments = array(); |
---|
| 296 | $element_ids = array(); |
---|
| 297 | $category_ids = array(); |
---|
| 298 | |
---|
[579] | 299 | $query = ' |
---|
[796] | 300 | SELECT com.id AS comment_id |
---|
| 301 | , com.image_id |
---|
| 302 | , ic.category_id |
---|
| 303 | , com.author |
---|
[3450] | 304 | , com.author_id |
---|
[796] | 305 | , com.date |
---|
| 306 | , com.content |
---|
[1598] | 307 | , com.validated |
---|
[796] | 308 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic |
---|
[3487] | 309 | INNER JOIN '.COMMENTS_TABLE.' AS com |
---|
[796] | 310 | ON ic.image_id = com.image_id |
---|
[1716] | 311 | WHERE '.implode(' |
---|
| 312 | AND ', $page['where_clauses']).' |
---|
[796] | 313 | GROUP BY comment_id |
---|
| 314 | ORDER BY '.$page['sort_by'].' '.$page['sort_order']; |
---|
| 315 | if ('all' != $page['items_number']) |
---|
| 316 | { |
---|
| 317 | $query.= ' |
---|
| 318 | LIMIT '.$start.','.$page['items_number']; |
---|
| 319 | } |
---|
| 320 | $query.= ' |
---|
[579] | 321 | ;'; |
---|
[587] | 322 | $result = pwg_query($query); |
---|
[1598] | 323 | while ($row = mysql_fetch_assoc($result)) |
---|
[393] | 324 | { |
---|
[796] | 325 | array_push($comments, $row); |
---|
| 326 | array_push($element_ids, $row['image_id']); |
---|
| 327 | array_push($category_ids, $row['category_id']); |
---|
[393] | 328 | } |
---|
[796] | 329 | |
---|
| 330 | if (count($comments) > 0) |
---|
[579] | 331 | { |
---|
[796] | 332 | // retrieving element informations |
---|
| 333 | $elements = array(); |
---|
[579] | 334 | $query = ' |
---|
[796] | 335 | SELECT id, name, file, path, tn_ext |
---|
[579] | 336 | FROM '.IMAGES_TABLE.' |
---|
[796] | 337 | WHERE id IN ('.implode(',', $element_ids).') |
---|
[579] | 338 | ;'; |
---|
[796] | 339 | $result = pwg_query($query); |
---|
[1598] | 340 | while ($row = mysql_fetch_assoc($result)) |
---|
[579] | 341 | { |
---|
[796] | 342 | $elements[$row['id']] = $row; |
---|
[579] | 343 | } |
---|
[721] | 344 | |
---|
[796] | 345 | // retrieving category informations |
---|
[579] | 346 | $query = ' |
---|
[1866] | 347 | SELECT id, name, permalink, uppercats |
---|
[796] | 348 | FROM '.CATEGORIES_TABLE.' |
---|
| 349 | WHERE id IN ('.implode(',', $category_ids).') |
---|
| 350 | ;'; |
---|
[1866] | 351 | $categories = hash_from_query($query, 'id'); |
---|
[796] | 352 | |
---|
| 353 | foreach ($comments as $comment) |
---|
[579] | 354 | { |
---|
[796] | 355 | if (!empty($elements[$comment['image_id']]['name'])) |
---|
[166] | 356 | { |
---|
[1598] | 357 | $name=$elements[$comment['image_id']]['name']; |
---|
[166] | 358 | } |
---|
[796] | 359 | else |
---|
| 360 | { |
---|
[1598] | 361 | $name=get_name_from_file($elements[$comment['image_id']]['file']); |
---|
[796] | 362 | } |
---|
[1090] | 363 | |
---|
[796] | 364 | // source of the thumbnail picture |
---|
[1598] | 365 | $thumbnail_src = get_thumbnail_url( $elements[$comment['image_id']] ); |
---|
[1090] | 366 | |
---|
[796] | 367 | // link to the full size picture |
---|
[1090] | 368 | $url = make_picture_url( |
---|
| 369 | array( |
---|
[1861] | 370 | 'category' => $categories[ $comment['category_id'] ], |
---|
[1090] | 371 | 'image_id' => $comment['image_id'], |
---|
| 372 | 'image_file' => $elements[$comment['image_id']]['file'], |
---|
| 373 | ) |
---|
| 374 | ); |
---|
| 375 | |
---|
[2223] | 376 | $tpl_comment = |
---|
[796] | 377 | array( |
---|
[1004] | 378 | 'U_PICTURE' => $url, |
---|
[848] | 379 | 'TN_SRC' => $thumbnail_src, |
---|
[1598] | 380 | 'ALT' => $name, |
---|
[3600] | 381 | 'AUTHOR' => trigger_event('render_comment_author', $comment['author']), |
---|
[3122] | 382 | 'DATE'=>format_date($comment['date'], true), |
---|
[1598] | 383 | 'CONTENT'=>trigger_event('render_comment_content',$comment['content']), |
---|
[2223] | 384 | ); |
---|
[1598] | 385 | |
---|
[3487] | 386 | if (can_manage_comment('delete', $comment['author_id'])) |
---|
[1598] | 387 | { |
---|
[3445] | 388 | $url = get_root_url().'comments.php' |
---|
| 389 | .get_query_string_diff(array('delete','validate','edit')); |
---|
[3487] | 390 | $tpl_comment['U_DELETE'] = |
---|
[3445] | 391 | add_url_params($url, |
---|
| 392 | array('delete'=>$comment['comment_id']) |
---|
| 393 | ); |
---|
| 394 | } |
---|
[3450] | 395 | if (can_manage_comment('edit', $comment['author_id'])) |
---|
[3445] | 396 | { |
---|
| 397 | $url = get_root_url().'comments.php' |
---|
| 398 | .get_query_string_diff(array('edit', 'delete','validate')); |
---|
[3487] | 399 | $tpl_comment['U_EDIT'] = |
---|
[3445] | 400 | add_url_params($url, |
---|
| 401 | array('edit'=>$comment['comment_id']) |
---|
| 402 | ); |
---|
[3487] | 403 | if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment)) |
---|
[1598] | 404 | { |
---|
[3445] | 405 | $tpl_comment['IN_EDIT'] = true; |
---|
| 406 | $key = get_comment_post_key($comment['image_id']); |
---|
| 407 | $tpl_comment['KEY'] = $key; |
---|
| 408 | $tpl_comment['IMAGE_ID'] = $comment['image_id']; |
---|
| 409 | $tpl_comment['CONTENT'] = $comment['content']; |
---|
[1598] | 410 | } |
---|
| 411 | } |
---|
[3445] | 412 | |
---|
| 413 | if ( is_admin() && $comment['validated'] != 'true') |
---|
| 414 | { |
---|
[3487] | 415 | $tpl_comment['U_VALIDATE'] = |
---|
[3445] | 416 | add_url_params($url, |
---|
| 417 | array('validate'=>$comment['comment_id']) |
---|
| 418 | ); |
---|
| 419 | } |
---|
[2223] | 420 | $template->append('comments', $tpl_comment); |
---|
[166] | 421 | } |
---|
[579] | 422 | } |
---|
| 423 | // +-----------------------------------------------------------------------+ |
---|
| 424 | // | html code display | |
---|
| 425 | // +-----------------------------------------------------------------------+ |
---|
[2107] | 426 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
[2223] | 427 | $template->pparse('comments'); |
---|
[1598] | 428 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
[2107] | 429 | ?> |
---|