Ignore:
Timestamp:
Mar 22, 2006, 2:01:47 AM (18 years ago)
Author:
rvelices
Message:

URL rewriting: capable of fully working with urls without ?

URL rewriting: works with image file instead of image id (change
make_picture_url to generate urls with file name instead of image id)

URL rewriting: completely works with category/best_rated and
picture/best_rated/534 (change 'category.php?' to 'category' in make_index_url
and 'picture.php?' to 'picture' in make_picture_url to see it)

fix: picture category display in upper bar

fix: function rate_picture variables and use of the new user type

fix: caddie icon appears now on category page

fix: admin element_set sql query was using storage_category_id column
(column has moved to #image_categories)

fix: replaced some old $_GET[xxx] with $page[xxx]

fix: pictures have metadata url (use ? parameter - might change later)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/functions_rate.inc.php

    • Property svn:eol-style set to native
    • Property svn:keywords set to Author Date Id Revision
    r1084 r1092  
    77// | branch        : BSF (Best So Far)
    88// | file          : $RCSfile$
    9 // | last update   : $Date: 2006-03-15 03:26:25 +0100 (mer, 15 mar 2006) $
    10 // | last modifier : $Author: rvelices $
    11 // | revision      : $Revision: 1081 $
    12 // | revision      : $Revision: 1081 $
     9// | last update   : $Date$
     10// | last modifier : $Author$
     11// | revision      : $Revision$
    1312// +-----------------------------------------------------------------------+
    1413// | This program is free software; you can redistribute it and/or modify  |
     
    3029 * rate a picture by a user
    3130 *
    32  * @param int user identifier
    3331 * @param int image identifier
    3432 * @param int rate
    3533 * @return void
    3634 */
    37 function rate_picture($user_id, $image_id, $rate)
     35function rate_picture($image_id, $rate)
    3836{
    39   global $conf;
     37  global $conf, $user;
    4038
    41   $query = '
    42 SELECT status
    43   FROM '.USER_INFOS_TABLE.'
    44   WHERE user_id = '.$user_id.'
    45 ;';
    46   list($user_status) = mysql_fetch_array(pwg_query($query));
     39  if (!isset($rate)
     40      or !$conf['rate']
     41      or !in_array($rate, $conf['rate_items']))
     42  {
     43    return;
     44  }
    4745
    48   if ('guest' == $user_status
    49       or 'generic' == $user_status)
     46  $user_anonymous = is_autorize_status(ACCESS_CLASSIC) ? false : true;
     47
     48  if ($user_anonymous and !$conf['rate_anonymous'])
    5049  {
    51     $user_anonymous = true;
     50    return;
    5251  }
    53   else
     52
     53  if ($user_anonymous)
    5454  {
    55     $user_anonymous = false;
    56   }
    57  
    58   if (isset($rate)
    59       and $conf['rate']
    60       and (!$user_anonymous or $conf['rate_anonymous'])
    61       and in_array($rate, $conf['rate_items']))
    62   {
    63     if ($user_anonymous)
     55    $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]);
     56    if (count($ip_components) > 3)
    6457    {
    65       $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]);
    66       if (count($ip_components) > 3)
    67       {
    68         array_pop($ip_components);
    69       }
    70       $anonymous_id = implode ('.', $ip_components);
    71          
    72       if (isset($_COOKIE['pwg_anonymous_rater']))
    73       {
    74         if ($anonymous_id != $_COOKIE['pwg_anonymous_rater'])
    75         { // client has changed his IP adress or he's trying to fool us
    76           $query = '
     58      array_pop($ip_components);
     59    }
     60    $anonymous_id = implode ('.', $ip_components);
     61
     62    if (isset($_COOKIE['pwg_anonymous_rater']))
     63    {
     64      if ($anonymous_id != $_COOKIE['pwg_anonymous_rater'])
     65      { // client has changed his IP adress or he's trying to fool us
     66        $query = '
    7767SELECT element_id
    7868  FROM '.RATE_TABLE.'
     
    8070    AND anonymous_id = \''.$anonymous_id.'\'
    8171;';
    82           $already_there = array_from_query($query, 'element_id');
    83          
    84           if (count($already_there) > 0)
    85           {
    86             $query = '
     72        $already_there = array_from_query($query, 'element_id');
     73
     74        if (count($already_there) > 0)
     75        {
     76          $query = '
    8777DELETE
    8878  FROM '.RATE_TABLE.'
     
    9181    AND element_id NOT IN ('.implode(',', $already_there).')
    9282;';
    93             pwg_query($query);
    94           }
     83           pwg_query($query);
     84         }
    9585
    96           $query = '
     86         $query = '
    9787UPDATE
    9888  '.RATE_TABLE.'
     
    10191    AND anonymous_id = \'' . $_COOKIE['pwg_anonymous_rater'].'\'
    10292;';
    103           pwg_query($query);
     93         pwg_query($query);
    10494
    105           setcookie(
     95         setcookie(
    10696            'pwg_anonymous_rater',
    10797            $anonymous_id,
    10898            strtotime('+10 years'),
    10999            cookie_path()
    110             );
    111         }
    112       }
    113       else
    114       {
    115         setcookie(
     100           );
     101      } // end client changed ip
     102    } // end client has cookie
     103    else
     104    {
     105      setcookie(
    116106          'pwg_anonymous_rater',
    117107          $anonymous_id,
     
    119109          cookie_path()
    120110          );
    121       }
    122111    }
    123    
    124     $query = '
     112  } // end anonymous user
     113  $query = '
    125114DELETE
    126115  FROM '.RATE_TABLE.'
    127116  WHERE element_id = '.$image_id.'
    128   AND user_id = '.$user_id.'
     117  AND user_id = '.$user['id'].'
    129118';
    130     if (isset($anonymous_id))
    131     {
    132       $query.= ' AND anonymous_id = \''.$anonymous_id.'\'';
    133     }
    134     pwg_query($query);
    135     $query = '
     119  if (isset($anonymous_id))
     120  {
     121    $query.= ' AND anonymous_id = \''.$anonymous_id.'\'';
     122  }
     123  pwg_query($query);
     124  $query = '
    136125INSERT
    137126  INTO '.RATE_TABLE.'
     
    139128  VALUES
    140129  ('
    141       .$user_id.','
    142       .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").','
    143       .$image_id.','
    144       .$rate
    145       .',NOW())
     130    .$user['id'].','
     131    .(isset($anonymous_id) ? '\''.$anonymous_id.'\'' : "''").','
     132    .$image_id.','
     133    .$rate
     134    .',NOW())
    146135;';
    147     pwg_query($query);
    148        
    149     // update of images.average_rate field
    150     $query = '
     136  pwg_query($query);
     137
     138  // update of images.average_rate field
     139  $query = '
    151140SELECT ROUND(AVG(rate),2) AS average_rate
    152141  FROM '.RATE_TABLE.'
    153142  WHERE element_id = '.$image_id.'
    154143;';
    155     $row = mysql_fetch_array(pwg_query($query));
    156     $query = '
     144  $row = mysql_fetch_array(pwg_query($query));
     145  $query = '
    157146UPDATE '.IMAGES_TABLE.'
    158147  SET average_rate = '.$row['average_rate'].'
    159148  WHERE id = '.$image_id.'
    160149;';
    161     pwg_query($query);
    162   }
     150  pwg_query($query);
    163151}
    164152
Note: See TracChangeset for help on using the changeset viewer.