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