diff options
author | plegall <plg@piwigo.org> | 2006-03-16 22:34:45 +0000 |
---|---|---|
committer | plegall <plg@piwigo.org> | 2006-03-16 22:34:45 +0000 |
commit | 5980db248ab4cc05e8596e07d7efc31048bcb8e8 (patch) | |
tree | 8cd6f048c590c0439b93e8a62f72c6300ff323c0 | |
parent | 853bf2a0a5bc77d6ad1d22dbe778eb6b7b1b12be (diff) |
bug fixed: create_navigation_bar take into account clean URL if requested.
deletion: argument link_class (HTML class of links) in function
create_navigation_bar was removed, useless since branch 1.5.
bug fixed: rate_items are now a configuration parameter (set in config file)
modification: new functions library functions_rate.inc.php to reduce
picture.php length.
bug fixed: categories were never expanded in the menu since clean URLs.
bug fixed: changing pictures sorting order in main page was always
rederecting to root category.
git-svn-id: http://piwigo.org/svn/trunk@1084 68402e56-0260-453c-a942-63ccdbb3a9ee
-rw-r--r-- | admin/element_set_global.php | 4 | ||||
-rw-r--r-- | admin/element_set_unit.php | 4 | ||||
-rw-r--r-- | admin/rating.php | 17 | ||||
-rw-r--r-- | admin/stats.php | 3 | ||||
-rw-r--r-- | admin/user_list.php | 3 | ||||
-rw-r--r-- | category.php | 11 | ||||
-rw-r--r-- | include/config_default.inc.php | 3 | ||||
-rw-r--r-- | include/functions.inc.php | 2 | ||||
-rw-r--r-- | include/functions_category.inc.php | 2 | ||||
-rw-r--r-- | include/functions_html.inc.php | 86 | ||||
-rw-r--r-- | include/functions_rate.inc.php | 165 | ||||
-rw-r--r-- | include/picture_comment.inc.php | 26 | ||||
-rw-r--r-- | include/picture_rate.inc.php | 4 | ||||
-rw-r--r-- | picture.php | 111 |
14 files changed, 249 insertions, 192 deletions
diff --git a/admin/element_set_global.php b/admin/element_set_global.php index cab192aa0..40b5ac6cb 100644 --- a/admin/element_set_global.php +++ b/admin/element_set_global.php @@ -457,8 +457,8 @@ if (count($page['cat_elements_id']) > 0) $base_url.get_query_string_diff(array('start')), count($page['cat_elements_id']), $page['start'], - $page['nb_images'], - ''); + $page['nb_images'] + ); $template->assign_vars(array('NAV_BAR' => $nav_bar)); $query = ' diff --git a/admin/element_set_unit.php b/admin/element_set_unit.php index 8ffd3142a..c43522894 100644 --- a/admin/element_set_unit.php +++ b/admin/element_set_unit.php @@ -188,8 +188,8 @@ if (count($page['cat_elements_id']) > 0) $base_url.get_query_string_diff(array('start')), count($page['cat_elements_id']), $page['start'], - $page['nb_images'], - ''); + $page['nb_images'] + ); $template->assign_vars(array('NAV_BAR' => $nav_bar)); diff --git a/admin/rating.php b/admin/rating.php index 072a2abdb..5d563d1a6 100644 --- a/admin/rating.php +++ b/admin/rating.php @@ -132,13 +132,16 @@ list($nb_images) = mysql_fetch_row(pwg_query($query)); $template->set_filenames(array('rating'=>'admin/rating.tpl')); -$navbar = create_navigation_bar( - PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start','del')), - $nb_images, - $start, - $elements_per_page, - ''); -$template->assign_vars(array('NAVBAR' => $navbar)); +$template->assign_vars( + array( + 'NAVBAR' => create_navigation_bar( + PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start','del')), + $nb_images, + $start, + $elements_per_page, + ) + ) + ); $template->assign_vars( diff --git a/admin/stats.php b/admin/stats.php index 081606e17..d11d0426a 100644 --- a/admin/stats.php +++ b/admin/stats.php @@ -302,8 +302,7 @@ create_navigation_bar( $url, $page['nb_logs'], $page['start'], - $conf['nb_logs_page'], - 'admin' + $conf['nb_logs_page'] ); $template->assign_block_vars( diff --git a/admin/user_list.php b/admin/user_list.php index 6bbb5eaa1..6f1b11938 100644 --- a/admin/user_list.php +++ b/admin/user_list.php @@ -747,8 +747,7 @@ $navbar = create_navigation_bar( $url, count($page['filtered_users']), $start, - $conf['users_page'], - '' + $conf['users_page'] ); $template->assign_vars(array('NAVBAR' => $navbar)); diff --git a/category.php b/category.php index cf41e75ab..4aeaf0f36 100644 --- a/category.php +++ b/category.php @@ -28,6 +28,7 @@ //--------------------------------------------------------------------- include define('PHPWG_ROOT_PATH','./'); include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); +include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); // +-----------------------------------------------------------------------+ // | Check Access and exit when user status is not ok | @@ -47,6 +48,7 @@ if ( isset( $_GET['act'] ) $url = 'category.php'; redirect( $url ); } + //---------------------------------------------- change of image display order if (isset($_GET['image_order'])) { @@ -57,14 +59,13 @@ if (isset($_GET['image_order'])) ); redirect( - make_index_URL( - array(), - array('image_order') + duplicate_index_URL( + array(), // nothing to redefine + array('start') // changing display order goes back to section first page ) ); } //-------------------------------------------------------------- initialization -include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); // detection of the start picture to display if (!isset($page['start'])) { @@ -85,7 +86,7 @@ if (isset($page['cat_nb_images']) $page['cat_nb_images'], $page['start'], $user['nb_image_page'], - 'back' + true ); } else diff --git a/include/config_default.inc.php b/include/config_default.inc.php index 3631b0895..da9a9de75 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -209,6 +209,9 @@ $conf['send_bcc_mail_webmaster'] = false; // elsewhere. $conf['check_upgrade_feed'] = true; +// rate_items: available rates for a picture +$conf['rate_items'] = array(0,1,2,3,4,5); + // +-----------------------------------------------------------------------+ // | metadata | // +-----------------------------------------------------------------------+ diff --git a/include/functions.inc.php b/include/functions.inc.php index 9b628a93c..c70789f46 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -1137,7 +1137,7 @@ function make_section_in_URL($params) if (!isset($params['section'])) { - if (isset($params['section'])) + if (isset($params['category'])) { $params['section'] = 'categories'; } diff --git a/include/functions_category.inc.php b/include/functions_category.inc.php index 8b5bd58a4..21560454d 100644 --- a/include/functions_category.inc.php +++ b/include/functions_category.inc.php @@ -75,7 +75,7 @@ SELECT name,id,date_last,nb_images,global_rank { $query.= ' AND (id_uppercat is NULL'; - if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) ) + if (isset($page['category'])) { $query.= ' OR id_uppercat IN ('.$page['uppercats'].')'; } diff --git a/include/functions_html.inc.php b/include/functions_html.inc.php index 6e8a6c4d8..959153297 100644 --- a/include/functions_html.inc.php +++ b/include/functions_html.inc.php @@ -75,12 +75,14 @@ function get_icon($date) return $page['get_icon_cache'][$date]; } -function create_navigation_bar($url, $nb_element, $start, - $nb_element_page, $link_class) +function create_navigation_bar( + $url, $nb_element, $start, $nb_element_page, $clean_url = false + ) { global $lang, $conf; $pages_around = $conf['paginate_pages_around']; + $start_str = $clean_url ? '/start-' : '&start='; $navbar = ''; @@ -102,10 +104,10 @@ function create_navigation_bar($url, $nb_element, $start, // link to first page ? if ($cur_page != 1) { - $navbar.= '<a href="'; - $navbar.= $url; - $navbar.= '" class="'.$link_class.'" rel="start">'.$lang['first_page']; - $navbar.= '</a>'; + $navbar.= + '<a href="'.$url.'" rel="start">' + .$lang['first_page'] + .'</a>'; } else { @@ -113,17 +115,16 @@ function create_navigation_bar($url, $nb_element, $start, } $navbar.= ' | '; // link on previous page ? - if ( $start != 0 ) + if ($start != 0) { $previous = $start - $nb_element_page; - $navbar.= '<a href="'; - $navbar.= $url; - if ($previous>0) - { - $navbar.= '&start='.$previous; - } - $navbar.= '" class="'.$link_class.'" rel="prev">'.$lang['previous_page']; - $navbar.= '</a>'; + + $navbar.= + '<a href="' + .$url.($previous > 0 ? $start_str.$previous : '') + .'" rel="prev">' + .$lang['previous_page'] + .'</a>'; } else { @@ -133,9 +134,8 @@ function create_navigation_bar($url, $nb_element, $start, if ($cur_page > $pages_around + 1) { - $navbar.= ' <a href="'; - $navbar.= $url; - $navbar.= '" class="'.$link_class.'">1</a>'; + $navbar.= ' <a href="'.$url.'">1</a>'; + if ($cur_page > $pages_around + 2) { $navbar.= ' ...'; @@ -154,43 +154,48 @@ function create_navigation_bar($url, $nb_element, $start, else if ($i != $cur_page) { $temp_start = ($i - 1) * $nb_element_page; - $navbar.= ' <a href="'; - $navbar.= $url; - if ($temp_start>0) - { - $navbar.= '&start='.$temp_start; - } - $navbar.= '" class="'.$link_class.'"'; - $navbar.='>'.$i.'</a>'; + + $navbar.= + ' ' + .'<a href="'.$url + .($temp_start > 0 ? $start_str.$temp_start : '') + .'">' + .$i + .'</a>'; } else { - $navbar.= ' <span class="pageNumberSelected">'; - $navbar.= $i.'</span>'; + $navbar.= + ' ' + .'<span class="pageNumberSelected">' + .$i + .'</span>'; } } if ($cur_page < ($maximum - $pages_around)) { $temp_start = ($maximum - 1) * $nb_element_page; + if ($cur_page < ($maximum - $pages_around - 1)) { $navbar.= ' ...'; } - $navbar.= ' <a href="'; - $navbar.= $url.'&start='.$temp_start; - $navbar.= '" class="'.$link_class.'">'.$maximum.'</a>'; + + $navbar.= ' <a href="'.$url.$start_str.$temp_start.'">'.$maximum.'</a>'; } $navbar.= ' | '; // link on next page ? - if ( $nb_element > $nb_element_page - && $start + $nb_element_page < $nb_element ) + if ($nb_element > $nb_element_page + and $start + $nb_element_page < $nb_element) { $next = $start + $nb_element_page; - $navbar.= '<a href="'; - $navbar.= $url.'&start='.$next; - $navbar.= '" class="'.$link_class.'" rel="next">'.$lang['next_page'].'</a>'; + + $navbar.= + '<a href="'.$url.$start_str.$next.'" rel="next">' + .$lang['next_page'] + .'</a>'; } else { @@ -202,10 +207,11 @@ function create_navigation_bar($url, $nb_element, $start, if ($cur_page != $maximum) { $temp_start = ($maximum - 1) * $nb_element_page; - $navbar.= '<a href="'; - $navbar.= $url.'&start='.$temp_start; - $navbar.= '" class="'.$link_class.'" rel="last">'.$lang['last_page']; - $navbar.= '</a>'; + + $navbar.= + '<a href="'.$url.$start_str.$temp_start.'" rel="last">' + .$lang['last_page'] + .'</a>'; } else { diff --git a/include/functions_rate.inc.php b/include/functions_rate.inc.php new file mode 100644 index 000000000..6eef19af6 --- /dev/null +++ b/include/functions_rate.inc.php @@ -0,0 +1,165 @@ +<?php +// +-----------------------------------------------------------------------+ +// | PhpWebGallery - a PHP based picture gallery | +// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | +// | Copyright (C) 2003-2006 PhpWebGallery Team - http://phpwebgallery.net | +// +-----------------------------------------------------------------------+ +// | branch : BSF (Best So Far) +// | file : $RCSfile$ +// | last update : $Date: 2006-03-15 03:26:25 +0100 (mer, 15 mar 2006) $ +// | last modifier : $Author: rvelices $ +// | revision : $Revision: 1081 $ +// | revision : $Revision: 1081 $ +// +-----------------------------------------------------------------------+ +// | This program is free software; you can redistribute it and/or modify | +// | it under the terms of the GNU General Public License as published by | +// | the Free Software Foundation | +// | | +// | This program is distributed in the hope that it will be useful, but | +// | WITHOUT ANY WARRANTY; without even the implied warranty of | +// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | +// | General Public License for more details. | +// | | +// | You should have received a copy of the GNU General Public License | +// | along with this program; if not, write to the Free Software | +// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | +// | USA. | +// +-----------------------------------------------------------------------+ + +/** + * rate a picture by a user + * + * @param int user identifier + * @param int image identifier + * @param int rate + * @return void + */ +function rate_picture($user_id, $image_id, $rate) +{ + global $conf; + + $query = ' +SELECT status + FROM '.USER_INFOS_TABLE.' + WHERE user_id = '.$user_id.' +;'; + list($user_status) = mysql_fetch_array(pwg_query($query)); + + if ('guest' == $user_status + or 'generic' == $user_status) + { + $user_anonymous = true; + } + else + { + $user_anonymous = false; + } + + if (isset($rate) + and $conf['rate'] + and (!$user_anonymous or $conf['rate_anonymous']) + and in_array($rate, $conf['rate_items'])) + { + if ($user_anonymous) + { + $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]); + if (count($ip_components) > 3) + { + array_pop($ip_components); + } + $anonymous_id = implode ('.', $ip_components); + + if (isset($_COOKIE['pwg_anonymous_rater'])) + { + if ($anonymous_id != $_COOKIE['pwg_anonymous_rater']) + { // client has changed his IP adress or he's trying to fool us + $query = ' +SELECT element_id + FROM '.RATE_TABLE.' + WHERE user_id = '.$user['id'].' + AND anonymous_id = \''.$anonymous_id.'\' +;'; + $already_there = array_from_query($query, 'element_id'); + + if (count($already_there) > 0) + { + $query = ' +DELETE + FROM '.RATE_TABLE.' + WHERE user_id = '.$user['id'].' + AND anonymous_id = \''.$_COOKIE['pwg_anonymous_rater'].'\' + AND element_id NOT IN ('.implode(',', $already_there).') +;'; + pwg_query($query); + } + + $query = ' +UPDATE + '.RATE_TABLE.' + SET anonymous_id = \'' .$anonymous_id.'\' + WHERE user_id = '.$user['id'].' + AND anonymous_id = \'' . $_COOKIE['pwg_anonymous_rater'].'\' +;'; + pwg_query($query); + + setcookie( + 'pwg_anonymous_rater', + $anonymous_id, + strtotime('+10 years'), + cookie_path() + ); + } + } + else + { + setcookie( + 'pwg_anonymous_rater', + $anonymous_id, + strtotime('+10 years'), + cookie_path() + ); + } + } + + $query = ' +DELETE + FROM '.RATE_TABLE.' + WHERE element_id = '.$image_id.' + AND user_id = '.$user_id.' +'; + if (isset($anonymous_id)) + { + $query.= ' AND anonymous_id = \''.$anonymous_id.'\''; + } + pwg_query($query); + $query = ' +INSERT + INTO '.RATE_TABLE.' + (user_id,anonymous_id,element_id,rate,date) + VALUES + (' + .$user_id.',' + .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").',' + .$image_id.',' + .$rate + .',NOW()) +;'; + pwg_query($query); + + // update of images.average_rate field + $query = ' +SELECT ROUND(AVG(rate),2) AS average_rate + FROM '.RATE_TABLE.' + WHERE element_id = '.$image_id.' +;'; + $row = mysql_fetch_array(pwg_query($query)); + $query = ' +UPDATE '.IMAGES_TABLE.' + SET average_rate = '.$row['average_rate'].' + WHERE id = '.$image_id.' +;'; + pwg_query($query); + } +} + +?>
\ No newline at end of file diff --git a/include/picture_comment.inc.php b/include/picture_comment.inc.php index 79373d2f7..6a40ea442 100644 --- a/include/picture_comment.inc.php +++ b/include/picture_comment.inc.php @@ -129,30 +129,17 @@ if ($page['show_comments']) $row = mysql_fetch_array( pwg_query( $query ) ); // navigation bar creation - $url = PHPWG_ROOT_PATH.'picture.php'; - $url.= get_query_string_diff(array('add_fav','start')); - -// $url = duplicate_picture_URL( -// array(), -// array('start') -// ); - - if (!isset($_GET['start']) - or !is_numeric($_GET['start']) - or (is_numeric($_GET['start']) and $_GET['start'] < 0)) + if (!isset($page['start'])) { $page['start'] = 0; } - else - { - $page['start'] = $_GET['start']; - } + $page['navigation_bar'] = create_navigation_bar( - $url, + duplicate_picture_URL(array(), array('start')), $row['nb_comments'], $page['start'], $conf['nb_comment_page'], - '' + true // We want a clean URL ); $template->assign_block_vars( @@ -198,7 +185,10 @@ SELECT id,author,date,image_id,content $template->assign_block_vars( 'comments.comment.delete', array( - 'U_COMMENT_DELETE' => $url.'&del='.$row['id'] + 'U_COMMENT_DELETE' => + $url_self + .'&action=delete_comment' + .'&comment_to_delete='.$row['id'] ) ); } diff --git a/include/picture_rate.inc.php b/include/picture_rate.inc.php index 67da9f0e8..7f765e759 100644 --- a/include/picture_rate.inc.php +++ b/include/picture_rate.inc.php @@ -30,8 +30,6 @@ * */ -$rate_items = array(0,1,2,3,4,5); - if ($conf['rate']) { $query = ' @@ -109,7 +107,7 @@ SELECT COUNT(rate) AS count ) ); - foreach ($rate_items as $num => $mark) + foreach ($conf['rate_items'] as $num => $mark) { $template->assign_block_vars( 'rate.rate_option', diff --git a/picture.php b/picture.php index f95f39124..432870611 100644 --- a/picture.php +++ b/picture.php @@ -27,6 +27,7 @@ define('PHPWG_ROOT_PATH','./'); include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); +include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php'); include(PHPWG_ROOT_PATH.'include/section_init.inc.php'); // Check Access and exit when user status is not ok @@ -194,115 +195,7 @@ UPDATE '.CATEGORIES_TABLE.' } case 'rate' : { - if (isset($_GET['rate']) - and $conf['rate'] - and (!$user['is_the_guest'] or $conf['rate_anonymous']) - and in_array($_GET['rate'], $rate_items)) - { - if ($user['is_the_guest']) - { - $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]); - if (count($ip_components) > 3) - { - array_pop($ip_components); - } - $anonymous_id = implode ('.', $ip_components); - - if (isset($_COOKIE['pwg_anonymous_rater'])) - { - if ($anonymous_id != $_COOKIE['pwg_anonymous_rater']) - { // client has changed his IP adress or he's trying to fool us - $query = ' -SELECT element_id FROM '. RATE_TABLE . ' - WHERE user_id=' . $user['id'] . ' - AND anonymous_id=\'' . $anonymous_id . '\''; - $result = pwg_query($query); - $already_there = array(); - while ($row = mysql_fetch_array($result)) - { - array_push($already_there, $row['element_id']); - } - - if (count($already_there) > 0) - { - $query = ' -DELETE - FROM '.RATE_TABLE.' - WHERE user_id = '.$user['id'].' - AND anonymous_id = \''.$_COOKIE['pwg_anonymous_rater'].'\' - AND element_id NOT IN ('.implode(',', $already_there).') -;'; - pwg_query($query); - } - - $query = ' -UPDATE - '.RATE_TABLE.' - SET anonymous_id = \'' .$anonymous_id.'\' - WHERE user_id = '.$user['id'].' - AND anonymous_id = \'' . $_COOKIE['pwg_anonymous_rater'].'\' -;'; - pwg_query($query); - - setcookie( - 'pwg_anonymous_rater', - $anonymous_id, - strtotime('+10 years'), - cookie_path() - ); - } - } - else - { - setcookie( - 'pwg_anonymous_rater', - $anonymous_id, - strtotime('+10 years'), - cookie_path() - ); - } - } - - $query = ' -DELETE - FROM '.RATE_TABLE.' - WHERE element_id = '.$page['image_id'] . ' - AND user_id = '.$user['id'].' -'; - if (isset($anonymous_id)) - { - $query.= ' AND anonymous_id = \''.$anonymous_id.'\''; - } - pwg_query($query); - $query = ' -INSERT - INTO '.RATE_TABLE.' - (user_id,anonymous_id,element_id,rate,date) - VALUES - (' - .$user['id'].',' - .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").',' - .$page['image_id'].',' - .$_GET['rate'] - .',NOW()) -;'; - pwg_query($query); - - // update of images.average_rate field - $query = ' -SELECT ROUND(AVG(rate),2) AS average_rate - FROM '.RATE_TABLE.' - WHERE element_id = '.$page['image_id'].' -;'; - $row = mysql_fetch_array(pwg_query($query)); - $query = ' -UPDATE '.IMAGES_TABLE.' - SET average_rate = '.$row['average_rate'].' - WHERE id = '.$page['image_id'].' -;'; - pwg_query($query); - } - + rate_picture($user['id'], $page['image_id'], $_GET['rate']); redirect($url_self); } case 'delete_comment' : |