source: branches/1.6/include/picture_rate.inc.php @ 27047

Last change on this file since 27047 was 1285, checked in by rvelices, 19 years ago

bug 359: transform rating html A links to FORM because some bots rate
pictures (even if rel="nofollow" is set)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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-04-28 04:37:28 +0000 (Fri, 28 Apr 2006) $
10// | last modifier : $Author: rvelices $
11// | revision      : $Revision: 1285 $
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
33if ($conf['rate'])
34{
35  $query = '
36SELECT COUNT(rate) AS count
37     , ROUND(AVG(rate),2) AS average
38     , ROUND(STD(rate),2) AS STD
39  FROM '.RATE_TABLE.'
40  WHERE element_id = '.$picture['current']['id'].'
41;';
42  $row = mysql_fetch_array(pwg_query($query));
43  if ($row['count'] == 0)
44  {
45    $value = $lang['no_rate'];
46  }
47  else
48  {
49    $value = sprintf(
50      l10n('%.2f (rated %d times, standard deviation = %.2f)'),
51      $row['average'],
52      $row['count'],
53      $row['STD']
54      );
55  }
56
57  $user_rate = null;
58  if ($conf['rate_anonymous'] or is_autorize_status(ACCESS_CLASSIC) )
59  {
60    if ($row['count']>0)
61    {
62      $query = 'SELECT rate
63      FROM '.RATE_TABLE.'
64      WHERE element_id = '.$page['image_id'] . '
65      AND user_id = '.$user['id'] ;
66
67      if ( !is_autorize_status(ACCESS_CLASSIC) )
68      {
69        $ip_components = explode('.', $_SERVER['REMOTE_ADDR']);
70        if ( count($ip_components)>3 )
71        {
72          array_pop($ip_components);
73        }
74        $anonymous_id = implode ('.', $ip_components);
75        $query .= ' AND anonymous_id = \''.$anonymous_id . '\'';
76      }
77
78      $result = pwg_query($query);
79      if (mysql_num_rows($result) > 0)
80      {
81        $row = mysql_fetch_array($result);
82        $user_rate = $row['rate'];
83      }
84    }
85
86    $template->assign_block_vars(
87      'rate',
88      array(
89        'SENTENCE' =>isset($user_rate) ? l10n('update_rate') : l10n('new_rate'),
90        'F_ACTION' => add_url_params(
91                        $url_self,
92                        array('action'=>'rate')
93                      )
94        )
95      );
96
97    $template->assign_block_vars('info_rate', array('CONTENT' => $value));
98
99    foreach ($conf['rate_items'] as $num => $mark)
100    {
101      $template->assign_block_vars(
102        'rate.rate_option',
103        array(
104          'OPTION'    => $mark,
105          'SEPARATOR' => ($num > 0 ? '|' : ''),
106          )
107        );
108      if (isset($user_rate) and $user_rate==$mark)
109      {
110        $template->assign_block_vars('rate.rate_option.my_rate', array() );
111      }
112      else
113      {
114        $template->assign_block_vars('rate.rate_option.not_my_rate', array() );
115      }
116    }
117  }
118}
119
120?>
Note: See TracBrowser for help on using the repository browser.