Changeset 1084


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.

Location:
trunk
Files:
1 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/element_set_global.php

    r1072 r1084  
    458458    count($page['cat_elements_id']),
    459459    $page['start'],
    460     $page['nb_images'],
    461     '');
     460    $page['nb_images']
     461    );
    462462  $template->assign_vars(array('NAV_BAR' => $nav_bar));
    463463
  • trunk/admin/element_set_unit.php

    r1072 r1084  
    189189    count($page['cat_elements_id']),
    190190    $page['start'],
    191     $page['nb_images'],
    192     '');
     191    $page['nb_images']
     192    );
    193193  $template->assign_vars(array('NAV_BAR' => $nav_bar));
    194194
  • trunk/admin/rating.php

    r1072 r1084  
    133133$template->set_filenames(array('rating'=>'admin/rating.tpl'));
    134134
    135 $navbar = create_navigation_bar(
    136            PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start','del')),
    137                                 $nb_images,
    138                                 $start,
    139                                 $elements_per_page,
    140                                 '');
    141 $template->assign_vars(array('NAVBAR' => $navbar));
     135$template->assign_vars(
     136  array(
     137    'NAVBAR' => create_navigation_bar(
     138      PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start','del')),
     139      $nb_images,
     140      $start,
     141      $elements_per_page,
     142      )
     143    )
     144  );
    142145
    143146
  • trunk/admin/stats.php

    r1072 r1084  
    303303  $page['nb_logs'],
    304304  $page['start'],
    305   $conf['nb_logs_page'],
    306   'admin'
     305  $conf['nb_logs_page']
    307306  );
    308307
  • trunk/admin/user_list.php

    r1079 r1084  
    748748  count($page['filtered_users']),
    749749  $start,
    750   $conf['users_page'],
    751   ''
     750  $conf['users_page']
    752751  );
    753752
  • trunk/category.php

    r1083 r1084  
    2929define('PHPWG_ROOT_PATH','./');
    3030include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
     31include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
    3132
    3233// +-----------------------------------------------------------------------+
     
    4849  redirect( $url );
    4950}
     51
    5052//---------------------------------------------- change of image display order
    5153if (isset($_GET['image_order']))
     
    5860
    5961  redirect(
    60     make_index_URL(
    61       array(),
    62       array('image_order')
     62    duplicate_index_URL(
     63      array(),        // nothing to redefine
     64      array('start')  // changing display order goes back to section first page
    6365      )
    6466    );
    6567}
    6668//-------------------------------------------------------------- initialization
    67 include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
    6869// detection of the start picture to display
    6970if (!isset($page['start']))
     
    8687    $page['start'],
    8788    $user['nb_image_page'],
    88     'back'
     89    true
    8990    );
    9091}
  • trunk/include/config_default.inc.php

    r1078 r1084  
    210210$conf['check_upgrade_feed'] = true;
    211211
     212// rate_items: available rates for a picture
     213$conf['rate_items'] = array(0,1,2,3,4,5);
     214
    212215// +-----------------------------------------------------------------------+
    213216// |                               metadata                                |
  • trunk/include/functions.inc.php

    r1082 r1084  
    11381138  if (!isset($params['section']))
    11391139  {
    1140     if (isset($params['section']))
     1140    if (isset($params['category']))
    11411141    {
    11421142      $params['section'] = 'categories';
  • trunk/include/functions_category.inc.php

    r1082 r1084  
    7676    $query.= '
    7777    AND (id_uppercat is NULL';
    78     if ( isset( $page['cat'] ) and is_numeric( $page['cat'] ) )
     78    if (isset($page['category']))
    7979    {
    8080      $query.= ' OR id_uppercat IN ('.$page['uppercats'].')';
  • trunk/include/functions_html.inc.php

    r1082 r1084  
    7676}
    7777
    78 function create_navigation_bar($url, $nb_element, $start,
    79                                $nb_element_page, $link_class)
     78function create_navigation_bar(
     79  $url, $nb_element, $start, $nb_element_page, $clean_url = false
     80  )
    8081{
    8182  global $lang, $conf;
    8283
    8384  $pages_around = $conf['paginate_pages_around'];
     85  $start_str = $clean_url ? '/start-' : '&start=';
    8486 
    8587  $navbar = '';
     
    103105    if ($cur_page != 1)
    104106    {
    105       $navbar.= '<a href="';
    106       $navbar.= $url;
    107       $navbar.= '" class="'.$link_class.'" rel="start">'.$lang['first_page'];
    108       $navbar.= '</a>';
     107      $navbar.=
     108        '<a href="'.$url.'" rel="start">'
     109        .$lang['first_page']
     110        .'</a>';
    109111    }
    110112    else
     
    114116    $navbar.= ' | ';
    115117    // link on previous page ?
    116     if ( $start != 0 )
     118    if ($start != 0)
    117119    {
    118120      $previous = $start - $nb_element_page;
    119       $navbar.= '<a href="';
    120       $navbar.= $url;
    121       if ($previous>0)
    122       {
    123         $navbar.= '&amp;start='.$previous;
    124       }
    125       $navbar.= '" class="'.$link_class.'" rel="prev">'.$lang['previous_page'];
    126       $navbar.= '</a>';
     121     
     122      $navbar.=
     123        '<a href="'
     124        .$url.($previous > 0 ? $start_str.$previous : '')
     125        .'" rel="prev">'
     126        .$lang['previous_page']
     127        .'</a>';
    127128    }
    128129    else
     
    134135    if ($cur_page > $pages_around + 1)
    135136    {
    136       $navbar.= '&nbsp;<a href="';
    137       $navbar.= $url;
    138       $navbar.= '" class="'.$link_class.'">1</a>';
     137      $navbar.= '&nbsp;<a href="'.$url.'">1</a>';
     138     
    139139      if ($cur_page > $pages_around + 2)
    140140      {
     
    155155      {
    156156        $temp_start = ($i - 1) * $nb_element_page;
    157         $navbar.= '&nbsp;<a href="';
    158         $navbar.= $url;
    159         if ($temp_start>0)
    160         {
    161           $navbar.= '&amp;start='.$temp_start;
    162         }
    163         $navbar.= '" class="'.$link_class.'"';
    164         $navbar.='>'.$i.'</a>';
     157       
     158        $navbar.=
     159          '&nbsp;'
     160          .'<a href="'.$url
     161          .($temp_start > 0 ? $start_str.$temp_start : '')
     162          .'">'
     163          .$i
     164          .'</a>';
    165165      }
    166166      else
    167167      {
    168         $navbar.= '&nbsp;<span class="pageNumberSelected">';
    169         $navbar.= $i.'</span>';
     168        $navbar.=
     169          '&nbsp;'
     170          .'<span class="pageNumberSelected">'
     171          .$i
     172          .'</span>';
    170173      }
    171174    }
     
    174177    {
    175178      $temp_start = ($maximum - 1) * $nb_element_page;
     179     
    176180      if ($cur_page < ($maximum - $pages_around - 1))
    177181      {
    178182        $navbar.= ' ...';
    179183      }
    180       $navbar.= ' <a href="';
    181       $navbar.= $url.'&amp;start='.$temp_start;
    182       $navbar.= '" class="'.$link_class.'">'.$maximum.'</a>';
     184     
     185      $navbar.= ' <a href="'.$url.$start_str.$temp_start.'">'.$maximum.'</a>';
    183186    }
    184187   
    185188    $navbar.= ' | ';
    186189    // link on next page ?
    187     if ( $nb_element > $nb_element_page
    188          && $start + $nb_element_page < $nb_element )
     190    if ($nb_element > $nb_element_page
     191        and $start + $nb_element_page < $nb_element)
    189192    {
    190193      $next = $start + $nb_element_page;
    191       $navbar.= '<a href="';
    192       $navbar.= $url.'&amp;start='.$next;
    193       $navbar.= '" class="'.$link_class.'" rel="next">'.$lang['next_page'].'</a>';
     194     
     195      $navbar.=
     196        '<a href="'.$url.$start_str.$next.'" rel="next">'
     197        .$lang['next_page']
     198        .'</a>';
    194199    }
    195200    else
     
    203208    {
    204209      $temp_start = ($maximum - 1) * $nb_element_page;
    205       $navbar.= '<a href="';
    206       $navbar.= $url.'&amp;start='.$temp_start;
    207       $navbar.= '" class="'.$link_class.'" rel="last">'.$lang['last_page'];
    208       $navbar.= '</a>';
     210     
     211      $navbar.=
     212        '<a href="'.$url.$start_str.$temp_start.'" rel="last">'
     213        .$lang['last_page']
     214        .'</a>';
    209215    }
    210216    else
  • trunk/include/picture_comment.inc.php

    r1082 r1084  
    130130
    131131  // navigation bar creation
    132   $url = PHPWG_ROOT_PATH.'picture.php';
    133   $url.= get_query_string_diff(array('add_fav','start'));
    134 
    135 //   $url = duplicate_picture_URL(
    136 //     array(),
    137 //     array('start')
    138 //     );
    139 
    140   if (!isset($_GET['start'])
    141       or !is_numeric($_GET['start'])
    142       or (is_numeric($_GET['start']) and $_GET['start'] < 0))
     132  if (!isset($page['start']))
    143133  {
    144134    $page['start'] = 0;
    145135  }
    146   else
    147   {
    148     $page['start'] = $_GET['start'];
    149   }
     136 
    150137  $page['navigation_bar'] = create_navigation_bar(
    151     $url,
     138    duplicate_picture_URL(array(), array('start')),
    152139    $row['nb_comments'],
    153140    $page['start'],
    154141    $conf['nb_comment_page'],
    155     ''
     142    true // We want a clean URL
    156143    );
    157144 
     
    199186          'comments.comment.delete',
    200187          array(
    201             'U_COMMENT_DELETE' => $url.'&amp;del='.$row['id']
     188            'U_COMMENT_DELETE' =>
     189              $url_self
     190              .'&amp;action=delete_comment'
     191              .'&amp;comment_to_delete='.$row['id']
    202192            )
    203193          );
  • trunk/include/picture_rate.inc.php

    r1082 r1084  
    3030 *
    3131 */
    32 
    33 $rate_items = array(0,1,2,3,4,5);
    3432
    3533if ($conf['rate'])
     
    110108      );
    111109
    112     foreach ($rate_items as $num => $mark)
     110    foreach ($conf['rate_items'] as $num => $mark)
    113111    {
    114112      $template->assign_block_vars(
  • 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.