Changeset 1084 for trunk/picture.php


Ignore:
Timestamp:
Mar 16, 2006, 11:34:45 PM (18 years ago)
Author:
plg
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/picture.php

    r1082 r1084  
    2828define('PHPWG_ROOT_PATH','./');
    2929include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
     30include_once(PHPWG_ROOT_PATH.'include/functions_rate.inc.php');
    3031include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
    3132
     
    195196    case 'rate' :
    196197    {
    197       if (isset($_GET['rate'])
    198           and $conf['rate']
    199           and (!$user['is_the_guest'] or $conf['rate_anonymous'])
    200           and in_array($_GET['rate'], $rate_items))
    201       {
    202         if ($user['is_the_guest'])
    203         {
    204           $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]);
    205           if (count($ip_components) > 3)
    206           {
    207             array_pop($ip_components);
    208           }
    209           $anonymous_id = implode ('.', $ip_components);
    210          
    211           if (isset($_COOKIE['pwg_anonymous_rater']))
    212           {
    213             if ($anonymous_id != $_COOKIE['pwg_anonymous_rater'])
    214             { // client has changed his IP adress or he's trying to fool us
    215               $query = '
    216 SELECT element_id FROM '. RATE_TABLE . '
    217   WHERE user_id=' . $user['id'] . '
    218   AND anonymous_id=\'' . $anonymous_id . '\'';
    219               $result = pwg_query($query);
    220               $already_there = array();
    221               while ($row = mysql_fetch_array($result))
    222               {
    223                 array_push($already_there, $row['element_id']);
    224               }
    225              
    226               if (count($already_there) > 0)
    227               {
    228                 $query = '
    229 DELETE
    230   FROM '.RATE_TABLE.'
    231   WHERE user_id = '.$user['id'].'
    232     AND anonymous_id = \''.$_COOKIE['pwg_anonymous_rater'].'\'
    233     AND element_id NOT IN ('.implode(',', $already_there).')
    234 ;';
    235                 pwg_query($query);
    236               }
    237 
    238               $query = '
    239 UPDATE
    240   '.RATE_TABLE.'
    241   SET anonymous_id = \'' .$anonymous_id.'\'
    242   WHERE user_id = '.$user['id'].'
    243     AND anonymous_id = \'' . $_COOKIE['pwg_anonymous_rater'].'\'
    244 ;';
    245               pwg_query($query);
    246 
    247               setcookie(
    248                 'pwg_anonymous_rater',
    249                 $anonymous_id,
    250                 strtotime('+10 years'),
    251                 cookie_path()
    252                 );
    253             }
    254           }
    255           else
    256           {
    257             setcookie(
    258               'pwg_anonymous_rater',
    259               $anonymous_id,
    260               strtotime('+10 years'),
    261               cookie_path()
    262               );
    263           }
    264         }
    265        
    266         $query = '
    267 DELETE
    268   FROM '.RATE_TABLE.'
    269   WHERE element_id = '.$page['image_id'] . '
    270   AND user_id = '.$user['id'].'
    271 ';
    272         if (isset($anonymous_id))
    273         {
    274           $query.= ' AND anonymous_id = \''.$anonymous_id.'\'';
    275         }
    276         pwg_query($query);
    277         $query = '
    278 INSERT
    279   INTO '.RATE_TABLE.'
    280   (user_id,anonymous_id,element_id,rate,date)
    281   VALUES
    282   ('
    283           .$user['id'].','
    284           .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").','
    285           .$page['image_id'].','
    286           .$_GET['rate']
    287           .',NOW())
    288 ;';
    289         pwg_query($query);
    290        
    291         // update of images.average_rate field
    292         $query = '
    293 SELECT ROUND(AVG(rate),2) AS average_rate
    294   FROM '.RATE_TABLE.'
    295   WHERE element_id = '.$page['image_id'].'
    296 ;';
    297         $row = mysql_fetch_array(pwg_query($query));
    298         $query = '
    299 UPDATE '.IMAGES_TABLE.'
    300   SET average_rate = '.$row['average_rate'].'
    301   WHERE id = '.$page['image_id'].'
    302 ;';
    303         pwg_query($query);
    304       }
    305      
     198      rate_picture($user['id'], $page['image_id'], $_GET['rate']);
    306199      redirect($url_self);
    307200    }
Note: See TracChangeset for help on using the changeset viewer.