source: trunk/include/picture_rate.inc.php @ 1082

Last change on this file since 1082 was 1082, checked in by plg, 18 years ago

new: cleaner URL. Instead of category.php?cat=search&search=123&start=42,
you now have category.php?/search/123/start-42. Functions make_index_url and
make_picture_url build these new URLs. Functions duplicate_picture_url and
duplicate_index_url provide shortcuts to URL creation. The current main page
page is still category.php but this can be modified easily in make_index_url
function. In this first version, no backward compatibility. Calendar
definition in URL must be discussed with rvelices.

improvement: picture.php redesigned. First actions like "set as
representative" or "delete a comment" which all lead to a redirection. Then
the page (the big mess) and includes of new sub pages to manage specific
parts of the page (metadata, user comments, rates).

new: with the cleaner URL comes a new terminology. $pagecat doesn't
exist anymore. $pagesection is among 'categories', 'tags' (TODO),
'list', 'most_seen'... And sub parameters are set : $pagecategory if
$pagesection is "categories". See URL analyse in
include/section_init.inc.php for details.

File size: 3.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-09 00:14:53 +0100 (jeu, 09 mar 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1070 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28/**
29 * This file is included by the picture page to manage rates
30 *
31 */
32
33$rate_items = array(0,1,2,3,4,5);
34
35if ($conf['rate'])
36{
37  $query = '
38SELECT COUNT(rate) AS count
39     , ROUND(AVG(rate),2) AS average
40     , ROUND(STD(rate),2) AS STD
41  FROM '.RATE_TABLE.'
42  WHERE element_id = '.$picture['current']['id'].'
43;';
44  $row = mysql_fetch_array(pwg_query($query));
45  if ($row['count'] == 0)
46  {
47    $value = $lang['no_rate'];
48  }
49  else
50  {
51    $value = sprintf(
52      l10n('%.2f (rated %d times, standard deviation = %.2f)'),
53      $row['average'],
54      $row['count'],
55      $row['STD']
56      );
57  }
58
59  if ($conf['rate_anonymous'] or !$user['is_the_guest'])
60  {
61    if ($row['count']>0)
62    {
63      $query = 'SELECT rate
64      FROM '.RATE_TABLE.'
65      WHERE element_id = '.$page['image_id'] . '
66      AND user_id = '.$user['id'] ;
67
68      if ($user['is_the_guest'])
69      {
70        $ip_components = explode('.', $_SERVER['REMOTE_ADDR']);
71        if ( count($ip_components)>3 )
72        {
73          array_pop($ip_components);
74        }
75        $anonymous_id = implode ('.', $ip_components);
76        $query .= ' AND anonymous_id = \''.$anonymous_id . '\'';
77      }
78
79      $result = pwg_query($query);
80      if (mysql_num_rows($result) > 0)
81      {
82        $row = mysql_fetch_array($result);
83        $sentence = $lang['already_rated'];
84        $sentence.= ' ('.$row['rate'].'). ';
85        $sentence.= $lang['update_rate'];
86      }
87      else
88      {
89        $sentence = $lang['never_rated'].'. '.$lang['Rate'];
90      }
91    }
92    else
93    {
94      $sentence = $lang['never_rated'].'. '.$lang['Rate'];
95    }
96    $template->assign_block_vars(
97      'rate',
98      array(
99        'CONTENT' => $value,
100        'SENTENCE' => $sentence
101        )
102      );
103
104    $template->assign_block_vars('info_rate', array('CONTENT' => $value));
105
106    $template->assign_vars(
107      array(
108        'INFO_RATE' => $value
109        )
110      );
111
112    foreach ($rate_items as $num => $mark)
113    {
114      $template->assign_block_vars(
115        'rate.rate_option',
116        array(
117          'OPTION'    => $mark,
118          'URL'       => $url_self.'&amp;action=rate&amp;rate='.$mark,
119          'SEPARATOR' => ($num > 0 ? '|' : ''),
120          )
121        );
122    }
123  }
124}
125
126?>
Note: See TracBrowser for help on using the repository browser.