diff options
Diffstat (limited to 'comments.php')
-rw-r--r-- | comments.php | 123 |
1 files changed, 36 insertions, 87 deletions
diff --git a/comments.php b/comments.php index 07b4581fe..a41e0c57a 100644 --- a/comments.php +++ b/comments.php @@ -2,7 +2,7 @@ // +-----------------------------------------------------------------------+ // | Piwigo - a PHP based photo gallery | // +-----------------------------------------------------------------------+ -// | Copyright(C) 2008-2013 Piwigo Team http://piwigo.org | +// | Copyright(C) 2008-2014 Piwigo Team http://piwigo.org | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | // +-----------------------------------------------------------------------+ @@ -38,6 +38,9 @@ if (!$conf['activate_comments']) // +-----------------------------------------------------------------------+ check_status(ACCESS_GUEST); +$url_self = PHPWG_ROOT_PATH.'comments.php' + .get_query_string_diff(array('delete','edit','validate','pwg_token')); + $sort_order = array( 'DESC' => l10n('descending'), 'ASC' => l10n('ascending') @@ -78,9 +81,9 @@ if (!in_array($conf['comments_page_nb_comments'], $items_number)) $since_options = array( 1 => array('label' => l10n('today'), 'clause' => 'date > '.pwg_db_get_recent_period_expression(1)), - 2 => array('label' => sprintf(l10n('last %d days'), 7), + 2 => array('label' => l10n('last %d days', 7), 'clause' => 'date > '.pwg_db_get_recent_period_expression(7)), - 3 => array('label' => sprintf(l10n('last %d days'), 30), + 3 => array('label' => l10n('last %d days', 30), 'clause' => 'date > '.pwg_db_get_recent_period_expression(30)), 4 => array('label' => l10n('the beginning'), 'clause' => '1=1') // stupid but generic @@ -148,8 +151,7 @@ if (isset($_GET['cat']) and 0 != $_GET['cat']) if (!empty($_GET['author'])) { $page['where_clauses'][] = - 'u.'.$conf['user_fields']['username'].' = \''.$_GET['author'].'\' - OR author = \''.$_GET['author'].'\''; + '(u.'.$conf['user_fields']['username'].' = \''.$_GET['author'].'\' OR author = \''.$_GET['author'].'\')'; } // search a specific comment (if you're coming directly from an admin @@ -285,12 +287,7 @@ if (isset($action)) if ($perform_redirect) { - $redirect_url = - PHPWG_ROOT_PATH - .'comments.php' - .get_query_string_diff(array('delete','edit','validate','pwg_token')); - - redirect($redirect_url); + redirect($url_self); } } } @@ -375,34 +372,6 @@ else $start = 0; } -$query = ' -SELECT COUNT(DISTINCT(com.id)) - FROM '.IMAGE_CATEGORY_TABLE.' AS ic - INNER JOIN '.COMMENTS_TABLE.' AS com - ON ic.image_id = com.image_id - LEFT JOIN '.USERS_TABLE.' As u - ON u.'.$conf['user_fields']['id'].' = com.author_id - WHERE '.implode(' - AND ', $page['where_clauses']).' -;'; -list($counter) = pwg_db_fetch_row(pwg_query($query)); - -$url = PHPWG_ROOT_PATH - .'comments.php' - .get_query_string_diff(array('start','delete','validate','pwg_token')); - -$navbar = create_navigation_bar($url, - $counter, - $start, - $page['items_number'], - ''); - -$template->assign('navbar', $navbar); - -$url_self = PHPWG_ROOT_PATH - .'comments.php' - .get_query_string_diff(array('edit','delete','validate','pwg_token')); - // +-----------------------------------------------------------------------+ // | last comments display | // +-----------------------------------------------------------------------+ @@ -412,8 +381,9 @@ $element_ids = array(); $category_ids = array(); $query = ' -SELECT com.id AS comment_id, +SELECT SQL_CALC_FOUND_ROWS com.id AS comment_id, com.image_id, + ic.category_id, com.author, com.author_id, u.'.$conf['user_fields']['email'].' AS user_email, @@ -429,13 +399,7 @@ SELECT com.id AS comment_id, ON u.'.$conf['user_fields']['id'].' = com.author_id WHERE '.implode(' AND ', $page['where_clauses']).' - GROUP BY comment_id, - com.image_id, - com.author, - com.author_id, - com.date, - com.content, - com.validated + GROUP BY comment_id ORDER BY '.$page['sort_by'].' '.$page['sort_order']; if ('all' != $page['items_number']) { @@ -447,44 +411,39 @@ $query.= ' $result = pwg_query($query); while ($row = pwg_db_fetch_assoc($result)) { - array_push($comments, $row); - array_push($element_ids, $row['image_id']); + $comments[] = $row; + $element_ids[] = $row['image_id']; + $category_ids[] = $row['category_id']; } +list($counter) = pwg_db_fetch_row(pwg_query('SELECT FOUND_ROWS()')); + +$url = PHPWG_ROOT_PATH.'comments.php' + .get_query_string_diff(array('start','edit','delete','validate','pwg_token')); + +$navbar = create_navigation_bar($url, + $counter, + $start, + $page['items_number'], + ''); + +$template->assign('navbar', $navbar); + if (count($comments) > 0) { // retrieving element informations - $elements = array(); $query = ' SELECT * FROM '.IMAGES_TABLE.' WHERE id IN ('.implode(',', $element_ids).') ;'; - $result = pwg_query($query); - while ($row = pwg_db_fetch_assoc($result)) - { - $elements[$row['id']] = $row; - } + $elements = hash_from_query($query, 'id'); // retrieving category informations - $query = ' -SELECT c.id, name, permalink, uppercats, com.id as comment_id - FROM '.CATEGORIES_TABLE.' AS c - LEFT JOIN '.IMAGE_CATEGORY_TABLE.' AS ic - ON c.id=ic.category_id - LEFT JOIN '.COMMENTS_TABLE.' AS com - ON ic.image_id=com.image_id - '.get_sql_condition_FandF - ( - array - ( - 'forbidden_categories' => 'c.id', - 'visible_categories' => 'c.id' - ), - 'WHERE' - ).' -;'; - $categories = hash_from_query($query, 'comment_id'); + $query = 'SELECT id, name, permalink, uppercats + FROM '.CATEGORIES_TABLE.' + WHERE id IN ('.implode(',', $category_ids).')'; + $categories = hash_from_query($query, 'id'); foreach ($comments as $comment) { @@ -503,7 +462,7 @@ SELECT c.id, name, permalink, uppercats, com.id as comment_id // link to the full size picture $url = make_picture_url( array( - 'category' => $categories[ $comment['comment_id'] ], + 'category' => $categories[ $comment['category_id'] ], 'image_id' => $comment['image_id'], 'image_file' => $elements[$comment['image_id']]['file'], ) @@ -537,13 +496,8 @@ SELECT c.id, name, permalink, uppercats, com.id as comment_id if (can_manage_comment('delete', $comment['author_id'])) { - $url = - get_root_url() - .'comments.php' - .get_query_string_diff(array('delete','validate','edit', 'pwg_token')); - $tpl_comment['U_DELETE'] = add_url_params( - $url, + $url_self, array( 'delete' => $comment['comment_id'], 'pwg_token' => get_pwg_token(), @@ -553,13 +507,8 @@ SELECT c.id, name, permalink, uppercats, com.id as comment_id if (can_manage_comment('edit', $comment['author_id'])) { - $url = - get_root_url() - .'comments.php' - .get_query_string_diff(array('edit', 'delete','validate', 'pwg_token')); - $tpl_comment['U_EDIT'] = add_url_params( - $url, + $url_self, array( 'edit' => $comment['comment_id'] ) @@ -582,7 +531,7 @@ SELECT c.id, name, permalink, uppercats, com.id as comment_id if ('true' != $comment['validated']) { $tpl_comment['U_VALIDATE'] = add_url_params( - $url, + $url_self, array( 'validate'=> $comment['comment_id'], 'pwg_token' => get_pwg_token(), |