aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2006-03-16 22:34:45 +0000
committerplegall <plg@piwigo.org>2006-03-16 22:34:45 +0000
commit5980db248ab4cc05e8596e07d7efc31048bcb8e8 (patch)
tree8cd6f048c590c0439b93e8a62f72c6300ff323c0 /include
parent853bf2a0a5bc77d6ad1d22dbe778eb6b7b1b12be (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
Diffstat (limited to '')
-rw-r--r--include/config_default.inc.php3
-rw-r--r--include/functions.inc.php2
-rw-r--r--include/functions_category.inc.php2
-rw-r--r--include/functions_html.inc.php86
-rw-r--r--include/functions_rate.inc.php165
-rw-r--r--include/picture_comment.inc.php26
-rw-r--r--include/picture_rate.inc.php4
7 files changed, 225 insertions, 63 deletions
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-' : '&amp;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.= '&amp;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.= '&nbsp;<a href="';
- $navbar.= $url;
- $navbar.= '" class="'.$link_class.'">1</a>';
+ $navbar.= '&nbsp;<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.= '&nbsp;<a href="';
- $navbar.= $url;
- if ($temp_start>0)
- {
- $navbar.= '&amp;start='.$temp_start;
- }
- $navbar.= '" class="'.$link_class.'"';
- $navbar.='>'.$i.'</a>';
+
+ $navbar.=
+ '&nbsp;'
+ .'<a href="'.$url
+ .($temp_start > 0 ? $start_str.$temp_start : '')
+ .'">'
+ .$i
+ .'</a>';
}
else
{
- $navbar.= '&nbsp;<span class="pageNumberSelected">';
- $navbar.= $i.'</span>';
+ $navbar.=
+ '&nbsp;'
+ .'<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.'&amp;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.'&amp;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.'&amp;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.'&amp;del='.$row['id']
+ 'U_COMMENT_DELETE' =>
+ $url_self
+ .'&amp;action=delete_comment'
+ .'&amp;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',