Changeset 1082


Ignore:
Timestamp:
Mar 15, 2006, 11:44:35 PM (18 years ago)
Author:
plg
Message:

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.

Location:
trunk
Files:
3 added
25 edited

Legend:

Unmodified
Added
Removed
  • trunk/about.php

    r1072 r1082  
    5252$template->assign_vars(
    5353  array(
    54     'U_HOME' => PHPWG_ROOT_PATH.'category.php'
     54    'U_HOME' => make_index_url(),
    5555    )
    5656  );
  • trunk/admin.php

    r1072 r1082  
    9696    'U_USERS'=> $link_start.'user_list',
    9797    'U_GROUPS'=> $link_start.'group_list',
    98     'U_RETURN'=> PHPWG_ROOT_PATH.'category.php',
     98    'U_RETURN'=> make_index_url(),
    9999    'U_ADMIN'=> PHPWG_ROOT_PATH.'admin.php',
    100100    'L_ADMIN' => $lang['admin'],
  • trunk/admin/cat_list.php

    r1072 r1082  
    270270    'category',
    271271    array(
    272       'NAME'=>$category['name'],
    273       'ID'=>$category['id'],
    274       'RANK'=>$category['rank']*10,
    275 
    276       'U_JUMPTO'=>PHPWG_ROOT_PATH.'category.php?cat='.$category['id'],
    277       'U_CHILDREN'=>$cat_list_url.'&parent_id='.$category['id'],     
    278       'U_EDIT'=>$base_url.'cat_modify&cat_id='.$category['id']
     272      'NAME'       => $category['name'],
     273      'ID'         => $category['id'],
     274      'RANK'       => $category['rank']*10,
     275
     276      'U_JUMPTO'   => make_index_url(
     277        array(
     278          'category' => $category['id'],
     279          )
     280        ),
     281     
     282      'U_CHILDREN' => $cat_list_url.'&parent_id='.$category['id'],     
     283      'U_EDIT'     => $base_url.'cat_modify&cat_id='.$category['id'],
    279284      )
    280285    );
  • trunk/admin/cat_modify.php

    r1072 r1082  
    270270}
    271271
    272 $template->assign_vars(array(
    273   'CATEGORIES_NAV'=>$navigation,
    274   'CAT_NAME'=>$category['name'],
    275   'CAT_COMMENT'=>$category['comment'],
    276  
    277   $status=>'checked="checked"',
    278   $lock=>'checked="checked"',
    279   $commentable=>'checked="checked"',
    280   $uploadable=>'checked="checked"',
    281  
    282   'L_EDIT_NAME'=>$lang['name'],
    283   'L_STORAGE'=>$lang['storage'],
    284   'L_REMOTE_SITE'=>$lang['remote_site'],
    285   'L_EDIT_COMMENT'=>$lang['description'],
    286   'L_EDIT_STATUS'=>$lang['conf_access'],
    287   'L_STATUS_PUBLIC'=>$lang['public'],
    288   'L_STATUS_PRIVATE'=>$lang['private'],
    289   'L_EDIT_LOCK'=>$lang['lock'],
    290   'L_EDIT_UPLOADABLE'=>$lang['editcat_uploadable'],
    291   'L_EDIT_COMMENTABLE'=>$lang['comments'],
    292   'L_YES'=>$lang['yes'],
    293   'L_NO'=>$lang['no'],
    294   'L_SUBMIT'=>$lang['submit'],
    295   'L_SET_RANDOM_REPRESENTANT'=>$lang['cat_representant'],
    296 
    297   'U_JUMPTO'=>PHPWG_ROOT_PATH.'category.php?cat='.$category['id'],
    298   'U_CHILDREN'=>$cat_list_url.'&parent_id='.$category['id'],
    299   'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_modify',
    300    
    301   'F_ACTION'=>$form_action
    302   ));
     272$template->assign_vars(
     273  array(
     274    'CATEGORIES_NAV'     => $navigation,
     275    'CAT_NAME'           => $category['name'],
     276    'CAT_COMMENT'        => $category['comment'],
     277   
     278    $status              => 'checked="checked"',
     279    $lock                => 'checked="checked"',
     280    $commentable         => 'checked="checked"',
     281    $uploadable          => 'checked="checked"',
     282   
     283    'L_EDIT_NAME'        => $lang['name'],
     284    'L_STORAGE'          => $lang['storage'],
     285    'L_REMOTE_SITE'      => $lang['remote_site'],
     286    'L_EDIT_COMMENT'     => $lang['description'],
     287    'L_EDIT_STATUS'      => $lang['conf_access'],
     288    'L_STATUS_PUBLIC'    => $lang['public'],
     289    'L_STATUS_PRIVATE'   => $lang['private'],
     290    'L_EDIT_LOCK'        => $lang['lock'],
     291    'L_EDIT_UPLOADABLE'  => $lang['editcat_uploadable'],
     292    'L_EDIT_COMMENTABLE' => $lang['comments'],
     293    'L_YES'              => $lang['yes'],
     294    'L_NO'               => $lang['no'],
     295    'L_SUBMIT'           => $lang['submit'],
     296    'L_SET_RANDOM_REPRESENTANT'=>$lang['cat_representant'],
     297
     298    'U_JUMPTO' => make_index_url(
     299      array(
     300        'category' => $category['id'],
     301        )
     302      ),
     303   
     304    'U_CHILDREN' => $cat_list_url.'&parent_id='.$category['id'],
     305    'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_modify',
     306   
     307    'F_ACTION' => $form_action,
     308    )
     309  );
    303310
    304311
  • trunk/admin/include/functions.php

    r1070 r1082  
    781781    $query = '
    782782UPDATE '.$tablename.' AS t1, '.$temporary_tablename.' AS t2
    783   SET '.implode("\n    , ",
    784                 array_map(
    785                   create_function('$s', 'return "t1.$s = t2.$s";')
    786                   , $dbfields['update'])).'
    787   WHERE '.implode("\n    AND ",
    788                 array_map(
    789                   create_function('$s', 'return "t1.$s = t2.$s";')
    790                   , $dbfields['primary'])).'
     783  SET '.
     784      implode(
     785        "\n    , ",
     786        array_map(
     787          create_function('$s', 'return "t1.$s = t2.$s";'),
     788          $dbfields['update']
     789          )
     790        ).'
     791  WHERE '.
     792      implode(
     793        "\n    AND ",
     794        array_map(
     795          create_function('$s', 'return "t1.$s = t2.$s";'),
     796          $dbfields['primary']
     797          )
     798        ).'
    791799;';
    792800    pwg_query($query);
     
    841849  foreach ($uppercats_array as $id => $uppercats)
    842850  {
    843     $data = array();
    844     $data['id'] = $id;
    845     $global_rank = preg_replace('/(\d+)/e',
    846                                 "\$ranks_array['$1']",
    847                                 str_replace(',', '.', $uppercats));
    848     $data['global_rank'] = $global_rank;
    849     array_push($datas, $data);
    850   }
    851 
    852   $fields = array('primary' => array('id'), 'update' => array('global_rank'));
    853   mass_updates(CATEGORIES_TABLE, $fields, $datas);
     851    array_push(
     852      $datas,
     853      array(
     854        'id'          => $id,
     855        'global_rank' => preg_replace(
     856          '/(\d+)/e',
     857          "\$ranks_array['$1']",
     858          str_replace(',', '.', $uppercats)
     859          ),
     860        )
     861      );
     862  }
     863
     864  mass_updates(
     865    CATEGORIES_TABLE,
     866    array(
     867      'primary' => array('id'),
     868      'update'  => array('global_rank')
     869      ),
     870    $datas
     871    );
    854872}
    855873
     
    12541272  // users present in user related tables must be present in the base user
    12551273  // table
    1256   $tables =
    1257     array(
    1258       USER_MAIL_NOTIFICATION_TABLE,
    1259       USER_FEED_TABLE,
    1260       USER_INFOS_TABLE,
    1261       USER_ACCESS_TABLE,
    1262       USER_CACHE_TABLE,
    1263       USER_GROUP_TABLE
    1264       );
     1274  $tables = array(
     1275    USER_MAIL_NOTIFICATION_TABLE,
     1276    USER_FEED_TABLE,
     1277    USER_INFOS_TABLE,
     1278    USER_ACCESS_TABLE,
     1279    USER_CACHE_TABLE,
     1280    USER_GROUP_TABLE
     1281    );
     1282 
    12651283  foreach ($tables as $table)
    12661284  {
     
    12691287  FROM '.$table.'
    12701288;';
    1271     $to_delete =
    1272       array_diff(
    1273         array_from_query($query, 'user_id'),
    1274         $base_users
    1275         );
     1289    $to_delete = array_diff(
     1290      array_from_query($query, 'user_id'),
     1291      $base_users
     1292      );
    12761293
    12771294    if (count($to_delete) > 0)
  • trunk/admin/picture_modify.php

    r1072 r1082  
    334334//    linked category
    335335// 4. if no category reachable, no jumpto link
    336 $base_url_img = PHPWG_ROOT_PATH.'picture.php';
    337 $base_url_img.= '?image_id='.$_GET['image_id'];
    338 $base_url_img.= '&cat=';
    339 unset($url_img);
    340336
    341337$query = '
     
    344340  WHERE image_id = '.$_GET['image_id'].'
    345341;';
     342
    346343$authorizeds = array_diff(
    347344  array_from_query($query, 'category_id'),
    348   explode(',', calculate_permissions($user['id'], $user['status']))
     345  explode(
     346    ',',
     347    calculate_permissions($user['id'], $user['status'])
     348    )
    349349  );
    350350
     
    352352    and in_array($_GET['cat_id'], $authorizeds))
    353353{
    354   $url_img = $base_url_img.$_GET['cat_id'];
     354  $url_img = make_picture_URL(
     355    array(
     356      'image_id' => $_GET['image_id'],
     357      'category' => $_GET['cat_id'],
     358      )
     359    );
    355360}
    356361else
     
    358363  foreach ($authorizeds as $category)
    359364  {
    360     $url_img = $base_url_img.$category;
     365    $url_img = make_picture_URL(
     366      array(
     367        'image_id' => $_GET['image_id'],
     368        'category' => $category,
     369        )
     370      );
    361371    break;
    362372  }
  • trunk/category.php

    r1081 r1082  
    5858
    5959  redirect(
    60     PHPWG_ROOT_PATH
    61     .'category.php'
    62     .get_query_string_diff(array('image_order'))
     60    make_index_URL(
     61      array(),
     62      array('image_order')
     63      )
    6364    );
    6465}
    6566//-------------------------------------------------------------- initialization
     67include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
    6668// detection of the start picture to display
    67 if ( !isset( $_GET['start'] )
    68      or !is_numeric( $_GET['start'] )
    69      or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
     69if (!isset($page['start']))
    7070{
    7171  $page['start'] = 0;
    7272}
    73 else
    74 {
    75   $page['start'] = $_GET['start'];
    76 }
    77 
    78 include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
    7973
    8074// access authorization check
    81 if (isset($page['cat']) and is_numeric($page['cat']))
    82 {
    83   check_restrictions($page['cat']);
    84 }
    85 
    86 if ( isset($page['cat_nb_images'])
     75if (isset($page['category']))
     76{
     77  check_restrictions($page['category']);
     78}
     79
     80if (isset($page['cat_nb_images'])
    8781    and $page['cat_nb_images'] > $user['nb_image_page'])
    8882{
    89   // $nav_url is used to create the navigation bar
    90   $nav_url = PHPWG_ROOT_PATH.'category.php?';
    91   if ( isset($page['cat']) )
    92   {
    93     $nav_url .= 'cat='.$page['cat'].'&amp;';
    94 
    95     switch ($page['cat'])
    96     {
    97       case 'search':
    98       {
    99         $nav_url.= 'search='.$_GET['search'].'&amp;';
    100         break;
    101       }
    102       case 'list':
    103       {
    104         $nav_url.= 'list='.$_GET['list'].'&amp;';
    105         break;
    106       }
    107     }
    108   }
    109 
    110   if ( isset($_GET['calendar']) )
    111   {
    112     $nav_url.= 'calendar='.$_GET['calendar'];
    113   }
    114   else
    115   {
    116     $nav_url = preg_replace('/&amp;$/', '', $nav_url);
    117   }
    118 
    11983  $page['navigation_bar'] = create_navigation_bar(
    120     $nav_url,
     84    duplicate_index_URL(array(), array('start')),
    12185    $page['cat_nb_images'],
    12286    $page['start'],
     
    13498{
    13599  fill_caddie($page['items']);
     100  // redirect();
    136101}
    137102
     
    146111$template->set_filenames( array('category'=>'category.tpl') );
    147112//-------------------------------------------------------------- category title
    148 if (isset($page['cat']) and is_numeric($page['cat']))
    149 {
    150   $template_title = get_cat_display_name($page['cat_name'],
    151                                          'category.php?cat=',
    152                                          false);
     113if (isset($page['category']))
     114{
     115  $template_title = get_cat_display_name(
     116    $page['cat_name'],
     117    'category.php?/category/',
     118    false
     119    );
    153120}
    154121else
     
    157124}
    158125
    159 if ( isset( $page['cat_nb_images'] ) and $page['cat_nb_images'] > 0 )
     126if (isset($page['cat_nb_images']) and $page['cat_nb_images'] > 0)
    160127{
    161128  $template_title.= ' ['.$page['cat_nb_images'].']';
     
    164131$icon_recent = get_icon(date('Y-m-d'));
    165132
    166 $calendar_view_link = PHPWG_ROOT_PATH.'category.php'
    167                         .get_query_string_diff(array('start','calendar'));
    168 if ( ! isset($_GET['calendar']) )
    169 {
    170   $calendar_view_link .= (empty($_GET)? '?':'&' ) . 'calendar=';
     133$calendar_view_link = duplicate_index_URL(
     134  array(),                            // nothing to redefine
     135  array('chronology_type', 'start')   // what to remove ?
     136  );
     137
     138if (!isset($page['chronology_type']))
     139{
     140  $calendar_view_link.= '/calendar-';
     141
    171142  $template->assign_block_vars(
    172143    'mode_created',
    173     array( 'URL' => $calendar_view_link.'created' )
    174     );
     144    array(
     145      'URL' => $calendar_view_link.'created'
     146      )
     147    );
     148 
    175149  $template->assign_block_vars(
    176150    'mode_posted',
    177     array( 'URL' => $calendar_view_link.'posted' )
    178     );
    179 
     151    array(
     152      'URL' => $calendar_view_link.'posted'
     153      )
     154    );
    180155}
    181156else
     
    183158  $template->assign_block_vars(
    184159    'mode_normal',
    185     array( 'URL' => $calendar_view_link )
    186     );
    187   if (get_query_string_diff( array('start','calendar') )=='')
    188   {
    189     $calendar_view_link .= '?';
    190   }
    191   else
    192   {
    193     $calendar_view_link .= '&';
    194   }
    195 
    196   $calendar_view_link .= 'calendar=';
    197   if ( strpos($_GET['calendar'], 'posted') === false)
     160    array(
     161      'URL' => $calendar_view_link
     162      )
     163    );
     164
     165  $calendar_view_link .= '/calendar-';
     166  if ($page['chronology_type'] == 'created')
    198167  {
    199168    $template->assign_block_vars(
    200169      'mode_posted',
    201       array( 'URL' => $calendar_view_link.'posted' )
     170      array(
     171        'URL' => $calendar_view_link.'posted'
     172        )
    202173      );
    203174  }
     
    206177    $template->assign_block_vars(
    207178      'mode_created',
    208       array( 'URL' => $calendar_view_link.'created' )
     179      array(
     180        'URL' => $calendar_view_link.'created'
     181        )
    209182      );
    210183  }
     
    213186$template->assign_vars(
    214187  array(
    215   'NB_PICTURE' => $user['nb_total_images'],
    216   'TITLE' => $template_title,
    217   'USERNAME' => $user['username'],
    218   'TOP_NUMBER'=>$conf['top_number'],
    219   'MENU_CATEGORIES_CONTENT'=>get_categories_menu(),
    220 
    221   'L_CATEGORIES' => $lang['categories'],
    222   'L_HINT_CATEGORY' => $lang['hint_category'],
    223   'L_SUBCAT' => $lang['sub-cat'],
    224   'L_IMG_AVAILABLE' => $lang['images_available'],
    225   'L_TOTAL' => $lang['total'],
    226   'L_SPECIAL_CATEGORIES' => $lang['special_categories'],
    227   'L_SUMMARY' => $lang['title_menu'],
    228   'L_UPLOAD' => $lang['upload_picture'],
    229   'L_COMMENT' => $lang['comments'],
    230   'L_IDENTIFY' => $lang['identification'],
    231   'L_PASSWORD' => $lang['password'],
    232   'L_HELLO' => $lang['hello'],
    233   'L_REGISTER' => $lang['ident_register'],
    234   'L_LOGOUT' => $lang['logout'],
    235   'L_ADMIN' => $lang['admin'],
    236   'L_ADMIN_HINT' => $lang['hint_admin'],
    237   'L_PROFILE' => $lang['customize'],
    238   'L_PROFILE_HINT' => $lang['hint_customize'],
    239   'L_REMEMBER_ME' => $lang['remember_me'],
    240 
    241   'F_IDENTIFY' => PHPWG_ROOT_PATH.'identification.php',
    242   'T_RECENT' => $icon_recent,
    243 
    244   'U_HOME' => PHPWG_ROOT_PATH.'category.php',
    245   'U_REGISTER' => PHPWG_ROOT_PATH.'register.php',
    246   'U_LOST_PASSWORD' => PHPWG_ROOT_PATH.'password.php',
    247   'U_LOGOUT' => PHPWG_ROOT_PATH.'category.php?act=logout',
    248   'U_ADMIN'=> PHPWG_ROOT_PATH.'admin.php',
    249   'U_PROFILE'=> PHPWG_ROOT_PATH.'profile.php',
    250   )
    251 );
    252 
    253 if (isset($page['cat']) and 'search' == $page['cat'])
     188    'NB_PICTURE' => $user['nb_total_images'],
     189    'TITLE' => $template_title,
     190    'USERNAME' => $user['username'],
     191    'TOP_NUMBER' => $conf['top_number'],
     192    'MENU_CATEGORIES_CONTENT' => get_categories_menu(),
     193
     194    'L_CATEGORIES' => $lang['categories'],
     195    'L_HINT_CATEGORY' => $lang['hint_category'],
     196    'L_SUBCAT' => $lang['sub-cat'],
     197    'L_IMG_AVAILABLE' => $lang['images_available'],
     198    'L_TOTAL' => $lang['total'],
     199    'L_SPECIAL_CATEGORIES' => $lang['special_categories'],
     200    'L_SUMMARY' => $lang['title_menu'],
     201    'L_UPLOAD' => $lang['upload_picture'],
     202    'L_COMMENT' => $lang['comments'],
     203    'L_IDENTIFY' => $lang['identification'],
     204    'L_PASSWORD' => $lang['password'],
     205    'L_HELLO' => $lang['hello'],
     206    'L_REGISTER' => $lang['ident_register'],
     207    'L_LOGOUT' => $lang['logout'],
     208    'L_ADMIN' => $lang['admin'],
     209    'L_ADMIN_HINT' => $lang['hint_admin'],
     210    'L_PROFILE' => $lang['customize'],
     211    'L_PROFILE_HINT' => $lang['hint_customize'],
     212    'L_REMEMBER_ME' => $lang['remember_me'],
     213   
     214    'F_IDENTIFY' => PHPWG_ROOT_PATH.'identification.php',
     215    'T_RECENT' => $icon_recent,
     216   
     217    'U_HOME' => make_index_URL(),
     218    'U_REGISTER' => PHPWG_ROOT_PATH.'register.php',
     219    'U_LOST_PASSWORD' => PHPWG_ROOT_PATH.'password.php',
     220    'U_LOGOUT' => make_index_URL().'&amp;act=logout',
     221    'U_ADMIN'=> PHPWG_ROOT_PATH.'admin.php',
     222    'U_PROFILE'=> PHPWG_ROOT_PATH.'profile.php',
     223    )
     224  );
     225
     226if ('search' == $page['section'])
    254227{
    255228  $template->assign_block_vars(
    256229    'search_rules',
    257230    array(
    258       'URL' => PHPWG_ROOT_PATH.'/search_rules.php?search_id='.$_GET['search'],
     231      'URL' => PHPWG_ROOT_PATH.'/search_rules.php?search_id='.$page['search'],
    259232      )
    260233    );
     
    272245        'URL' => $url,
    273246        'LABEL' => $label
    274         ));
     247        )
     248      );
    275249  }
    276250}
     
    284258    'special_cat',
    285259    array(
    286       'URL' => PHPWG_ROOT_PATH.'category.php?cat=fav',
     260      'URL' => make_index_URL(array('section' => 'favorites')),
    287261      'TITLE' => $lang['favorite_cat_hint'],
    288262      'NAME' => $lang['favorite_cat']
     
    293267  'special_cat',
    294268  array(
    295     'URL' => PHPWG_ROOT_PATH.'category.php?cat=most_visited',
     269    'URL' => make_index_URL(array('section' => 'most_visited')),
    296270    'TITLE' => $lang['most_visited_cat_hint'],
    297271    'NAME' => $lang['most_visited_cat']
     
    303277    'special_cat',
    304278    array(
    305       'URL' => PHPWG_ROOT_PATH.'category.php?cat=best_rated',
     279      'URL' => make_index_URL(array('section' => 'best_rated')),
    306280      'TITLE' => $lang['best_rated_cat_hint'],
    307281      'NAME' => $lang['best_rated_cat']
     
    321295  'special_cat',
    322296  array(
    323     'URL' => PHPWG_ROOT_PATH.'category.php?cat=recent_pics',
     297    'URL' => make_index_URL(array('section' => 'recent_pics')),
    324298    'TITLE' => $lang['recent_pics_cat_hint'],
    325299    'NAME' => $lang['recent_pics_cat']
     
    329303  'special_cat',
    330304  array(
    331     'URL' => PHPWG_ROOT_PATH.'category.php?cat=recent_cats',
     305    'URL' => make_index_URL(array('section' => 'recent_cats')),
    332306    'TITLE' => $lang['recent_cats_cat_hint'],
    333307    'NAME' => $lang['recent_cats_cat']
    334308    ));
     309
    335310// calendar
    336 if ( $conf['calendar_datefield'] == 'date_available' )
    337 {
    338   $calendar_link = 'posted';
    339 }
    340 else
    341 {
    342   $calendar_link = 'created';
    343 }
    344 $calendar_link .= '-monthly-c';
    345311$template->assign_block_vars(
    346312  'special_cat',
    347313  array(
    348     'URL' => PHPWG_ROOT_PATH.'category.php?calendar='.$calendar_link,
     314    'URL' =>
     315      make_index_URL()
     316      .'/calendar-'
     317      .($conf['calendar_datefield'] == 'date_available' ? 'posted' : 'created')
     318      .'-monthly-c',
    349319    'TITLE' => $lang['calendar_hint'],
    350320    'NAME' => $lang['calendar']
    351     ));
     321    )
     322  );
    352323//--------------------------------------------------------------------- summary
    353324
     
    386357
    387358// search link
    388 $template->assign_block_vars('summary', array(
    389 'TITLE'=>$lang['hint_search'],
    390 'NAME'=>$lang['search'],
    391 'U_SUMMARY'=> 'search.php',
    392 'REL'=> 'rel="search"'
    393 ));
     359$template->assign_block_vars(
     360  'summary',
     361  array(
     362    'TITLE'=>$lang['hint_search'],
     363    'NAME'=>$lang['search'],
     364    'U_SUMMARY'=> 'search.php',
     365    'REL'=> 'rel="search"'
     366    )
     367  );
    394368
    395369// comments link
    396 $template->assign_block_vars('summary', array(
    397 'TITLE'=>$lang['hint_comments'],
    398 'NAME'=>$lang['comments'],
    399 'U_SUMMARY'=> 'comments.php',
    400 ));
     370$template->assign_block_vars(
     371  'summary',
     372  array(
     373    'TITLE'=>$lang['hint_comments'],
     374    'NAME'=>$lang['comments'],
     375    'U_SUMMARY'=> 'comments.php',
     376    )
     377  );
    401378
    402379// about link
    403 $template->assign_block_vars('summary', array(
    404 'TITLE'=>$lang['about_page_title'],
    405 'NAME'=>$lang['About'],
    406 'U_SUMMARY'=> 'about.php?'.str_replace( '&', '&amp;', $_SERVER['QUERY_STRING'] )
    407 ));
     380$template->assign_block_vars(
     381  'summary',
     382  array(
     383    'TITLE'     => $lang['about_page_title'],
     384    'NAME'      => $lang['About'],
     385    'U_SUMMARY' => 'about.php?'.str_replace(
     386      '&',
     387      '&amp;',
     388      $_SERVER['QUERY_STRING']
     389      )
     390    )
     391  );
    408392
    409393// notification
     
    415399    'U_SUMMARY'=> PHPWG_ROOT_PATH.'notification.php',
    416400    'REL'=> 'rel="nofollow"'
    417 ));
    418 
    419 if (isset($page['cat'])
    420     and is_numeric($page['cat'])
    421     and is_admin())
     401    )
     402  );
     403
     404if (isset($page['category']) and is_admin())
    422405{
    423406  $template->assign_block_vars(
     
    425408    array(
    426409      'URL' =>
    427           PHPWG_ROOT_PATH.'admin.php?page=cat_modify'
    428           .'&amp;cat_id='.$page['cat']
     410        PHPWG_ROOT_PATH.'admin.php?page=cat_modify'
     411        .'&amp;cat_id='.$page['category']
    429412      )
    430413    );
     
    432415
    433416//------------------------------------------------------ main part : thumbnails
    434 if ( isset($page['thumbnails_include']) )
     417if (isset($page['thumbnails_include']))
    435418{
    436419  include(PHPWG_ROOT_PATH.$page['thumbnails_include']);
    437420}
    438421//------------------------------------------------------- category informations
    439 if ( $page['navigation_bar'] != ''
    440      or ( isset( $page['comment'] ) and $page['comment'] != '' ) )
     422if (
     423  $page['navigation_bar'] != ''
     424  or (isset($page['comment']) and $page['comment'] != '')
     425  )
    441426{
    442427  $template->assign_block_vars('cat_infos',array());
    443428}
    444429// navigation bar
    445 if ( $page['navigation_bar'] != '' )
     430if ($page['navigation_bar'] != '')
    446431{
    447432  $template->assign_block_vars(
    448433    'cat_infos.navigation',
    449     array('NAV_BAR' => $page['navigation_bar'])
    450     );
    451 }
    452 
    453 if ( ( isset($page['cat_nb_images']) and $page['cat_nb_images']>0 )
    454      and
    455     ( !isset($page['cat'])
    456       or ($page['cat'] != 'most_visited' and $page['cat'] != 'best_rated') )
    457    )
     434    array(
     435      'NAV_BAR' => $page['navigation_bar'],
     436      )
     437    );
     438}
     439
     440if (isset($page['cat_nb_images']) and $page['cat_nb_images'] > 0
     441    and $page['section'] != 'most_visited'
     442    and $page['section'] != 'best_rated')
    458443{
    459444  // image order
    460445  $template->assign_block_vars( 'preferred_image_order', array() );
    461446
    462   $order_idx = isset($_COOKIE['pwg_image_order']) ?
    463                    $_COOKIE['pwg_image_order'] : 0;
     447  $order_idx = isset($_COOKIE['pwg_image_order'])
     448    ? $_COOKIE['pwg_image_order']
     449    : 0
     450    ;
    464451
    465452  $orders = get_category_preferred_image_orders();
    466   for ( $i = 0; $i < count($orders); $i++)
     453  for ($i = 0; $i < count($orders); $i++)
    467454  {
    468455    if ($orders[$i][2])
    469456    {
    470       $url = PHPWG_ROOT_PATH.'category.php'
    471                .get_query_string_diff(array('image_order'));
    472       $url .= '&amp;image_order='.$i;
    473       $template->assign_block_vars( 'preferred_image_order.order', array(
    474         'DISPLAY' => $orders[$i][0],
    475         'URL' => $url,
    476         'SELECTED_OPTION' => ($order_idx==$i ? 'SELECTED' : '' ),
    477         ) );
     457      $template->assign_block_vars(
     458        'preferred_image_order.order',
     459        array(
     460          'DISPLAY' => $orders[$i][0],
     461          'URL' => duplicate_index_URL().'&amp;image_order='.$i,
     462          'SELECTED_OPTION' => ($order_idx==$i ? 'SELECTED' : ''),
     463          )
     464        );
    478465    }
    479466  }
    480467}
    481468
    482 if ( isset ( $page['cat'] ) )
     469if (isset($page['category']))
    483470{
    484471  // upload a picture in the category
    485   if (is_numeric($page['cat'])
    486 //      and $page['cat_site_id'] == 1
    487       and $page['cat_dir'] != ''
    488       and $page['cat_uploadable'])
    489   {
    490     $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['cat'];
     472  if ($page['cat_uploadable'])
     473  {
     474    $url = PHPWG_ROOT_PATH.'upload.php?cat='.$page['category'];
    491475    $template->assign_block_vars(
    492476      'upload',
    493       array('U_UPLOAD'=> $url )
     477      array(
     478        'U_UPLOAD'=> $url
     479        )
    494480      );
    495481  }
     482 
    496483  // category comment
    497   if ( isset( $page['comment'] ) and $page['comment'] != '' )
     484  if (isset($page['comment']) and $page['comment'] != '')
    498485  {
    499486    $template->assign_block_vars(
    500487      'cat_infos.comment',
    501       array('COMMENTS' => $page['comment'])
     488      array(
     489        'COMMENTS' => $page['comment']
     490        )
    502491      );
    503492  }
    504493}
    505494//------------------------------------------------------------ log informations
    506 pwg_log( 'category', $page['title'] );
     495pwg_log('category', $page['title']);
    507496
    508497$template->parse('category');
  • trunk/comments.php

    r1072 r1082  
    185185    'F_AUTHOR'=>@$_GET['author'],
    186186   
    187     'U_HOME' => PHPWG_ROOT_PATH.'category.php'
     187    'U_HOME' => make_index_url(),
    188188    )
    189189  );
  • trunk/identification.php

    r1068 r1082  
    6565    }
    6666    log_user( $row['id'], $remember_me);
    67     redirect(empty($redirect_to) ? 'category.php' : $redirect_to);
     67    redirect(empty($redirect_to) ? make_index_url() : $redirect_to);
    6868  }
    6969  else
     
    9595    'U_REGISTER' => PHPWG_ROOT_PATH.'register.php',
    9696    'U_LOST_PASSWORD' => PHPWG_ROOT_PATH.'password.php',
    97     'U_HOME' => PHPWG_ROOT_PATH.'category.php',
     97    'U_HOME' => make_index_url(),
    9898    'U_REDIRECT' => $redirect_to,
    9999
  • trunk/include/category_default.inc.php

    r1056 r1082  
    2727
    2828/**
    29  * This file is included by category.php to show thumbnails for the default
     29 * This file is included by the main page to show thumbnails for the default
    3030 * case
    3131 *
     
    8282 
    8383  // url link on picture.php page
    84   $url_link = PHPWG_ROOT_PATH.'picture.php?image_id='.$row['id'];
     84  $url_link = PHPWG_ROOT_PATH.'picture.php?/'.$row['id'];
    8585
    86   if (isset($page['cat']))
     86  switch ($page['section'])
    8787  {
    88     $url_link.= '&amp;cat='.$page['cat'];
    89 
    90     if ($page['cat'] == 'search')
     88    case 'categories' :
    9189    {
    92       $url_link.= '&amp;search='.$_GET['search'];
     90      $url_link.= '/category/'.$page['category'];
     91      break;
    9392    }
    94     else if ($page['cat'] == 'list')
     93    case 'tags' :
    9594    {
    96       $url_link.= '&amp;list='.$_GET['list'];
     95      // TODO
     96      break;
     97    }
     98    case 'search' :
     99    {
     100      $url_link.= '/search/'.$page['search'];
     101      break;
     102    }
     103    case 'list' :
     104    {
     105      $url_link.= '/list/'.implode(',', $page['list']);
     106      break;
     107    }
     108    default :
     109    {
     110      $url_link.= '/'.$page['section'];
    97111    }
    98112  }
    99113 
    100   if (isset($_GET['calendar']))
     114  if (isset($page['chronology']))
    101115  {
    102     $url_link.= '&amp;calendar='.$_GET['calendar'];
     116    $url_link.= '/chronology='.$page['chronology'];
    103117  }
    104118   
     
    126140      $name = str_replace('_', ' ', get_filename_wo_extension($row['file']));
    127141    }
    128     if ( isset($page['cat']) )
     142
     143    switch ($page['section'])
    129144    {
    130       if ($page['cat'] == 'best_rated')
     145      case 'best_rated' :
    131146      {
    132147        $name = '('.$row['average_rate'].') '.$name;
     148        break;
    133149      }
    134       elseif ($page['cat'] == 'most_visited')
     150      case 'most_visited' :
    135151      {
    136152        $name = '('.$row['hit'].') '.$name;
     153        break;
    137154      }
    138      
    139       if ($page['cat'] == 'search')
     155      case 'search' :
    140156      {
    141157        $name = replace_search($name, $_GET['search']);
     158        break;
    142159      }
    143160    }
     
    152169   
    153170  if ($user['show_nb_comments']
    154       and is_numeric($page['cat'])
     171      and isset($page['category'])
    155172      and $page['cat_commentable'])
    156173  {
  • trunk/include/category_recent_cats.inc.php

    r1004 r1082  
    2727
    2828/**
    29  * This file is included by category.php to show thumbnails for recent_cats
     29 * This file is included by the main page to show thumbnails for recent_cats
    3030 * category
    3131 *
     
    6666while ( $row = mysql_fetch_array( $result ) )
    6767{
    68   $name = get_cat_display_name_cache($row['uppercats'], '', false);
    69 
    70   $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
    71  
    72   $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['category_id'];
    73  
    7468  $template->assign_block_vars(
    7569    'thumbnails.line.thumbnail',
    7670    array(
    77       'IMAGE'                   => $thumbnail_src,
    78       'IMAGE_ALT'               => $row['file'],
    79       'IMAGE_TITLE'             => $lang['hint_category'],
    80        
    81       'U_IMG_LINK'              => $url_link
     71      'IMAGE'       => get_thumbnail_src($row['path'], @$row['tn_ext']),
     72      'IMAGE_ALT'   => $row['file'],
     73      'IMAGE_TITLE' => $lang['hint_category'],
     74     
     75      'U_IMG_LINK'  => make_index_url(
     76        array(
     77          'category' => $row['category_id'],
     78          )
     79        ),
    8280      )
    8381    );
     
    8684    'thumbnails.line.thumbnail.category_name',
    8785    array(
    88       'NAME' => $name
     86      'NAME' => get_cat_display_name_cache($row['uppercats'], '', false),
    8987      )
    9088    );
  • trunk/include/category_subcats.inc.php

    r1004 r1082  
    2727
    2828/**
    29  * This file is included by category.php to show thumbnails for a category
     29 * This file is included by the main page to show thumbnails for a category
    3030 * that have only subcategories
    3131 *
     
    3535SELECT id, name, date_last, representative_picture_id
    3636  FROM '.CATEGORIES_TABLE.'
    37   WHERE id_uppercat ';
    38 if (!isset($page['cat']) or !is_numeric($page['cat']))
    39 {
    40   $query.= 'is NULL';
    41 }
    42 else
    43 {
    44   $query.= '= '.$page['cat'];
    45 }
    46   $query.= '
     37  WHERE id_uppercat '.
     38  (!isset($page['category']) ? 'is NULL' : '= '.$page['category']).'
    4739    AND id NOT IN ('.$user['forbidden_categories'].')
    4840  ORDER BY rank
     
    143135  foreach ($cat_thumbnails as $item)
    144136  {
    145     $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['id'];
    146 
    147137    $template->assign_block_vars(
    148138      'thumbnails.line.thumbnail',
    149139      array(
    150         'IMAGE' => $images[$item['picture']],
    151         'IMAGE_ALT' => $item['name'],
     140        'IMAGE'       => $images[$item['picture']],
     141        'IMAGE_ALT'   => $item['name'],
    152142        'IMAGE_TITLE' => $lang['hint_category'],
    153         'IMAGE_TS' => get_icon(@$item['date_last']),
    154         'U_IMG_LINK' =>
    155           PHPWG_ROOT_PATH.'category.php?cat='.$item['category']
     143        'IMAGE_TS'    => get_icon(@$item['date_last']),
     144       
     145        'U_IMG_LINK'  => make_index_url(
     146          array(
     147            'category' => $item['category'],
     148            )
     149          ),
    156150        )
    157151      );
  • trunk/include/functions.inc.php

    r1070 r1082  
    583583  if ($tn_ext != '')
    584584  {
    585     $src = substr_replace(get_filename_wo_extension($path),
    586                           '/thumbnail/'.$conf['prefix_thumbnail'],
    587                           strrpos($path,'/'),
    588                           1);
     585    $src = substr_replace(
     586      get_filename_wo_extension($path),
     587      '/thumbnail/'.$conf['prefix_thumbnail'],
     588      strrpos($path,'/'),
     589      1
     590      );
    589591    $src.= '.'.$tn_ext;
    590592  }
     
    10011003  return $available_upgrade_ids;
    10021004}
     1005
     1006/**
     1007 * build an index URL for a specific section
     1008 *
     1009 * @param array
     1010 * @return string
     1011 */
     1012function make_index_URL($params = array())
     1013{
     1014  $url =
     1015    PHPWG_ROOT_PATH.'category.php?'
     1016    .'/'.make_section_in_URL($params)
     1017    ;
     1018 
     1019  if (isset($params['start']) and $params['start'] > 0)
     1020  {
     1021    $url.= '/start-'.$params['start'];
     1022  }
     1023
     1024  return $url;
     1025}
     1026
     1027/**
     1028 * build an index URL with current page parameters, but with redefinitions
     1029 * and removes.
     1030 *
     1031 * duplicate_index_URL(array('category' => 12), array('start')) will create
     1032 * an index URL on the current section (categories), but on a redefined
     1033 * category and without the start URL parameter.
     1034 *
     1035 * @param array redefined keys
     1036 * @param array removed keys
     1037 * @return string
     1038 */
     1039function duplicate_index_URL($redefined = array(), $removed = array())
     1040{
     1041  return make_index_URL(
     1042    params_for_duplication($redefined, $removed)
     1043    );
     1044}
     1045
     1046/**
     1047 * returns $page global array with key redefined and key removed
     1048 *
     1049 * @param array redefined keys
     1050 * @param array removed keys
     1051 * @return array
     1052 */
     1053function params_for_duplication($redefined, $removed)
     1054{
     1055  global $page;
     1056
     1057  if (count($removed) > 0)
     1058  {
     1059    $params = array();
     1060
     1061    foreach ($page as $page_item_key => $page_item_value)
     1062    {
     1063      if (!in_array($page_item_key, $removed))
     1064      {
     1065        $params[$page_item_key] = $page_item_value;
     1066      }
     1067    }
     1068  }
     1069  else
     1070  {
     1071    $params = $page;
     1072  }
     1073
     1074  foreach ($redefined as $redefined_param => $redefined_value)
     1075  {
     1076    $params[$redefined_param] = $redefined_value;
     1077  }
     1078
     1079  return $params;
     1080}
     1081
     1082/**
     1083 * create a picture URL with current page parameters, but with redefinitions
     1084 * and removes. See duplicate_index_URL.
     1085 *
     1086 * @param array redefined keys
     1087 * @param array removed keys
     1088 * @return string
     1089 */
     1090function duplicate_picture_URL($redefined = array(), $removed = array())
     1091{
     1092  return make_picture_URL(
     1093    params_for_duplication($redefined, $removed)
     1094    );
     1095}
     1096
     1097/**
     1098 * create a picture URL on a specific section for a specific picture
     1099 *
     1100 * @param array
     1101 * @return string
     1102 */
     1103function make_picture_URL($params)
     1104{
     1105  if (!isset($params['image_id']))
     1106  {
     1107    die('make_picture_URL: image_id is a required parameter');
     1108  }
     1109 
     1110  $url =
     1111    PHPWG_ROOT_PATH.'picture.php?'
     1112    .'/'.$params['image_id']
     1113    .'/'.make_section_in_URL($params)
     1114    ;
     1115
     1116  // first comment to start on
     1117  if (isset($params['start']) and $params['start'] > 0)
     1118  {
     1119    $url.= '/start-'.$params['start'];
     1120  }
     1121
     1122  return $url;
     1123}
     1124
     1125/**
     1126 * return the section token of an index or picture URL.
     1127 *
     1128 * Depending on section, other parameters are required (see function code
     1129 * for details)
     1130 *
     1131 * @param array
     1132 * @return string
     1133 */
     1134function make_section_in_URL($params)
     1135{
     1136  $section_string = '';
     1137 
     1138  if (!isset($params['section']))
     1139  {
     1140    if (isset($params['section']))
     1141    {
     1142      $params['section'] = 'categories';
     1143    }
     1144    else if (isset($params['tags']))
     1145    {
     1146      $params['section'] = 'tags';
     1147    }
     1148    else if (isset($params['list']))
     1149    {
     1150      $params['section'] = 'list';
     1151    }
     1152    else if (isset($params['search']))
     1153    {
     1154      $params['section'] = 'search';
     1155    }
     1156  }
     1157
     1158  if (!isset($params['section']))
     1159  {
     1160    $params['section'] = 'categories';
     1161  }
     1162 
     1163  switch($params['section'])
     1164  {
     1165    case 'categories' :
     1166    {
     1167      if (!isset($params['category']))
     1168      {
     1169        $section_string.= 'categories';
     1170      }
     1171      else
     1172      {
     1173        $section_string.= 'category/'.$params['category'];
     1174      }
     1175     
     1176      break;
     1177    }
     1178    case 'tags' :
     1179    {
     1180      if (!isset($params['tags']) or count($params['tags']) == 0)
     1181      {
     1182        die('make_section_in_URL: require at least one tag');
     1183      }
     1184
     1185      $section_string.= 'tags';
     1186
     1187      foreach ($params['tags'] as $tag)
     1188      {
     1189        $section_string.= '/'.$tag;
     1190      }
     1191     
     1192      break;
     1193    }
     1194    case 'search' :
     1195    {
     1196      if (!isset($params['search']))
     1197      {
     1198        die('make_section_in_URL: require a search identifier');
     1199      }
     1200     
     1201      $section_string.= 'search/'.$params['search'];
     1202
     1203      break;
     1204    }
     1205    case 'list' :
     1206    {
     1207      if (!isset($params['list']))
     1208      {
     1209        die('make_section_in_URL: require a list of items');
     1210      }
     1211
     1212      $section_string.= 'list/'.implode(',', $params['list']);
     1213     
     1214      break;
     1215    }
     1216    default :
     1217    {
     1218      $section_string.= $params['section'];
     1219    }
     1220  }
     1221
     1222  return $section_string;
     1223}
    10031224?>
  • trunk/include/functions_category.inc.php

    r1081 r1082  
    4747  if (in_array($category_id, explode(',', $user['forbidden_categories'])))
    4848  {
    49     $login_url = './identification.php?redirect='.
    50                   urlencode(urlencode($_SERVER['REQUEST_URI']));
    51     if ( ! $user['is_the_guest'] )
    52     {
    53       echo '<div style="text-align:center;">';
    54       echo $lang['hello'].' '.$user['username'].'! ';
    55       echo $lang['access_forbiden'].'<br />';
    56       echo '<a href="./category.php">'.$lang['thumbnails'].'</a> ';
    57       echo '</div>';
    58       exit();
     49    $login_url =
     50      './identification.php?redirect='
     51      .urlencode(urlencode($_SERVER['REQUEST_URI']));
     52   
     53    if (!$user['is_the_guest'])
     54    {
     55      die('Fatal: you are trying to reach a forbidden category');
    5956    }
    6057    else
  • trunk/include/functions_html.inc.php

    r1040 r1082  
    248248 */
    249249function get_cat_display_name($cat_informations,
    250                               $url = 'category.php?cat=',
     250                              $url = 'category.php?/category/',
    251251                              $replace_space = true)
    252252{
     
    301301 */
    302302function get_cat_display_name_cache($uppercats,
    303                                     $url = 'category.php?cat=',
     303                                    $url = 'category.php?/category/',
    304304                                    $replace_space = true)
    305305{
     
    356356
    357357/**
    358  * returns the HTML code for a category item in the menu (for category.php)
     358 * returns the HTML code for a category item in the menu (for the main page)
    359359 *
    360360 * HTML code generated uses logical list tags ul and each category is an
     
    375375  // $page_cat value remains 0 for special sections
    376376  $page_cat = 0;
    377   if (isset($page['cat']) and is_numeric($page['cat']) )
    378   {
    379     $page_cat = $page['cat'];
    380   }
     377  if (isset($page['category']))
     378  {
     379    $page_cat = $page['category'];
     380  }
     381 
    381382  foreach ($categories as $category)
    382383  {
     
    405406    $menu.= '>';
    406407 
    407     $url = PHPWG_ROOT_PATH.'category.php?cat='.$category['id'];
     408    $url = make_index_url(array('category' => $category['id']));
     409   
    408410    $menu.= "\n".'<a href="'.$url.'"';
    409411    if ($page_cat != 0
     
    467469
    468470function get_cat_display_name_from_id($cat_id,
    469                                       $url = 'category.php?cat=',
     471                                      $url = 'category.php?/category/',
    470472                                      $replace_space = true)
    471473{
  • trunk/include/index.php

    r675 r1082  
    2525// | USA.                                                                  |
    2626// +-----------------------------------------------------------------------+
    27 $url = '../category.php';
     27
     28$url = '../index.php';
    2829header( 'Request-URI: '.$url ); 
    2930header( 'Content-Location: '.$url ); 
  • trunk/include/section_init.inc.php

    r1051 r1082  
    4141 */
    4242
    43 unset($page['cat']);
    44 
    45 if (isset($_GET['cat']))
     43// "index.php?/category/12-foo/start-24&action=fill_caddie" must return :
     44//
     45// array(
     46//   'section'  => 'categories',
     47//   'category' => 12,
     48//   'start'    => 24
     49//   'action'   => 'fill_caddie'
     50//   );
     51
     52$page['section'] = 'categories';
     53
     54foreach (array_keys($_GET) as $keynum => $key)
    4655{
    47   if (is_numeric($_GET['cat']))
    48   {
    49     $page['cat'] = $_GET['cat'];
    50   }
    51   else if ($_GET['cat'] == 'fav'
    52            or $_GET['cat'] == 'most_visited'
    53            or $_GET['cat'] == 'best_rated'
    54            or $_GET['cat'] == 'recent_pics'
    55            or $_GET['cat'] == 'recent_cats')
    56   {
    57     $page['cat'] = $_GET['cat'];
    58   }
    59   else if ($_GET['cat'] == 'search')
    60   {
    61     if (!isset($_GET['search']))
    62     {
    63       die('search GET parameter is missing');
    64     }
    65     else if (!is_numeric($_GET['search']))
    66     {
    67       die('wrong format on search GET parameter');
     56  if (0 == $keynum)
     57  {
     58    // deleting first "/" if displayed
     59    $tokens = explode(
     60      '/',
     61      preg_replace('#^/#', '', $key)
     62      );
     63
     64    // $tokens = array(
     65    //   0 => category,
     66    //   1 => 12-foo,
     67    //   2 => start-24
     68    //   );
     69
     70    $next_token = 0;
     71
     72    if (basename($_SERVER['PHP_SELF']) == 'picture.php')
     73    {
     74      // the first token must be the numeric identifier of the picture
     75      preg_match('/(\d+)/', $tokens[$next_token], $matches);
     76      if (!isset($matches[1]))
     77      {
     78        die('Fatal: picture identifier is missing');
     79      }
     80      $page['image_id'] = $matches[1];
     81     
     82      $next_token++;
     83    }
     84   
     85    if (0 === strpos($tokens[$next_token], 'cat'))
     86    {
     87      $page['section'] = 'categories';
     88      $next_token++;
     89     
     90      if (isset($tokens[$next_token])
     91          and preg_match('/(\d+)/', $tokens[$next_token], $matches))
     92      {
     93        $page['category'] = $matches[1];
     94        $next_token++;
     95      }
     96    }
     97    else if (0 === strpos($tokens[$next_token], 'tag'))
     98    {
     99      $page['section'] = 'tags';
     100      $page['tags'] = array();
     101     
     102      $next_token++;
     103     
     104      for ($i = $next_token; ; $i++)
     105      {
     106        if (!isset($tokens[$i]))
     107        {
     108          break;
     109        }
     110       
     111        preg_match('/^(\d+)/', $tokens[$i], $matches);
     112        if (!isset($matches[1]))
     113        {
     114          if (0 == count($page['tags']))
     115          {
     116            die('Fatal: at least one tag required');
     117          }
     118          else
     119          {
     120            break;
     121          }
     122        }
     123        array_push($page['tags'], $matches[1]);
     124      }
     125     
     126      $next_token = $i;
     127    }
     128    else if (0 === strpos($tokens[$next_token], 'fav'))
     129    {
     130      $page['section'] = 'favorites';
     131      $next_token++;
     132    }
     133    else if ('most_visited' == $tokens[$next_token])
     134    {
     135      $page['section'] = 'most_visited';
     136      $next_token++;
     137    }
     138    else if ('best_rated' == $tokens[$next_token])
     139    {
     140      $page['section'] = 'best_rated';
     141      $next_token++;
     142    }
     143    else if ('recent_pics' == $tokens[$next_token])
     144    {
     145      $page['section'] = 'recent_pics';
     146      $next_token++;
     147    }
     148    else if ('recent_cats' == $tokens[$next_token])
     149    {
     150      $page['section'] = 'recent_cats';
     151      $next_token++;
     152    }
     153    else if ('search' == $tokens[$next_token])
     154    {
     155      $page['section'] = 'search';
     156      $next_token++;
     157     
     158      preg_match('/(\d+)/', $tokens[$next_token], $matches);
     159      if (!isset($matches[1]))
     160      {
     161        die('Fatal: search identifier is missing');
     162      }
     163      $page['search'] = $matches[1];
     164      $next_token++;
     165    }
     166    else if ('list' == $tokens[$next_token])
     167    {
     168      $page['section'] = 'list';
     169      $next_token++;
     170
     171      $page['list'] = array();
     172      if (!preg_match('/^\d+(,\d+)*$/', $tokens[$next_token]))
     173      {
     174        die('wrong format on list GET parameter');
     175      }
     176      foreach (explode(',', $tokens[$next_token]) as $image_id)
     177      {
     178        array_push($page['list'], $image_id);
     179      }
     180      $next_token++;
    68181    }
    69182    else
    70183    {
    71       $page['cat'] = 'search';
    72     }
    73   }
    74   else if ($_GET['cat'] == 'list')
    75   {
    76     if (!isset($_GET['list']))
    77     {
    78       die('list GET parameter is missing');
    79     }
    80     else if (!preg_match('/^\d+(,\d+)*$/', $_GET['list']))
    81     {
    82       die('wrong format on list GET parameter');
    83     }
    84     else
    85     {
    86       $page['cat'] = 'list';
    87     }
    88   }
    89   else
    90   {
    91     die('unknown cat GET parameter value');
     184      $page['section'] = 'categories';
     185      $next_token++;
     186    }
     187   
     188    for ($i = $next_token; ; $i++)
     189    {
     190      if (!isset($tokens[$i]))
     191      {
     192        break;
     193      }
     194     
     195      if (preg_match('/^start-(\d+)/', $tokens[$i], $matches))
     196      {
     197        $page['start'] = $matches[1];
     198      }
     199
     200      if (preg_match('/^calendar-(.+)$/', $tokens[$i], $matches))
     201      {
     202        // TODO: decide with rvelices how we name calendar/chronology is the
     203        // URL
     204        $_GET['calendar'] = $matches[1];
     205      }
     206    }
    92207  }
    93208}
     
    111226}
    112227
    113 if (isset($page['cat']))
     228// +-----------------------------------------------------------------------+
     229// |                              category                                 |
     230// +-----------------------------------------------------------------------+
     231if ('categories' == $page['section'])
    114232{
    115  
    116 // +-----------------------------------------------------------------------+
    117 // |                              category                                 |
    118 // +-----------------------------------------------------------------------+
    119   if (is_numeric($page['cat']))
    120   {
    121     $result = get_cat_info($page['cat']);
    122 
     233  if (isset($page['category']))
     234  {
     235    $result = get_cat_info($page['category']);
     236   
    123237    $page = array_merge(
    124238      $page,
     
    133247        'cat_id_uppercat'  => $result['id_uppercat'],
    134248        'uppercats'        => $result['uppercats'],
    135 
     249       
    136250        'title' => get_cat_display_name($result['name'], '', false),
    137251        )
    138252      );
    139     if ( !isset($_GET['calendar']) )
     253   
     254    if (!isset($_GET['calendar']))
    140255    {
    141256      $query = '
     
    143258  FROM '.IMAGE_CATEGORY_TABLE.'
    144259    INNER JOIN '.IMAGES_TABLE.' ON id = image_id
    145   WHERE category_id = '.$page['cat'].'
     260  WHERE category_id = '.$page['category'].'
    146261  '.$conf['order_by'].'
    147262;';
    148263      $page['items'] = array_from_query($query, 'image_id');
     264     
    149265      $page['thumbnails_include'] =
    150           $result['nb_images'] > 0
    151           ? 'include/category_default.inc.php'
    152           : 'include/category_subcats.inc.php';
    153     }//otherwise the calendar will requery all subitems
    154   }
    155   // special section
     266        $result['nb_images'] > 0
     267        ? 'include/category_default.inc.php'
     268        : 'include/category_subcats.inc.php';
     269    } //otherwise the calendar will requery all subitems
     270  }
    156271  else
    157272  {
    158     if (!empty($user['forbidden_categories']))
    159     {
    160       $forbidden =
    161         ' category_id NOT IN ('.$user['forbidden_categories'].')';
    162     }
    163     else
    164     {
    165       $forbidden = ' 1=1';
    166     }
    167          
     273    $page['title'] = $lang['no_category'];
     274    $page['thumbnails_include'] = 'include/category_subcats.inc.php';
     275  }
     276}
     277// special sections
     278else
     279{
     280  if (!empty($user['forbidden_categories']))
     281  {
     282    $forbidden =
     283      ' category_id NOT IN ('.$user['forbidden_categories'].')';
     284  }
     285  else
     286  {
     287    $forbidden = ' 1 = 1';
     288  }
    168289// +-----------------------------------------------------------------------+
    169290// |                           search section                              |
    170291// +-----------------------------------------------------------------------+
    171     if ( $page['cat'] == 'search' )
    172     {
    173       $query = '
     292  if ($page['section'] == 'search')
     293  {
     294    $query = '
    174295SELECT DISTINCT(id)
    175296  FROM '.IMAGES_TABLE.'
     
    180301;';
    181302
    182       $page = array_merge(
    183         $page,
    184         array(
    185           'title' => $lang['search_result'],
    186           'items' => array_from_query($query, 'id'),
    187           'thumbnails_include' => 'include/category_default.inc.php',
    188           )
    189         );
    190     }
     303    $page = array_merge(
     304      $page,
     305      array(
     306        'title' => $lang['search_result'],
     307        'items' => array_from_query($query, 'id'),
     308        'thumbnails_include' => 'include/category_default.inc.php',
     309        )
     310      );
     311  }
    191312// +-----------------------------------------------------------------------+
    192313// |                           favorite section                            |
    193314// +-----------------------------------------------------------------------+
    194     else if ($page['cat'] == 'fav')
    195     {
    196       check_user_favorites();
    197 
    198       $query = '
     315  else if ($page['section'] == 'favorites')
     316  {
     317    check_user_favorites();
     318
     319    $query = '
    199320SELECT image_id
    200321  FROM '.FAVORITES_TABLE.'
     
    204325;';
    205326
    206       $page = array_merge(
    207         $page,
    208         array(
    209           'title' => $lang['favorites'],
    210           'items' => array_from_query($query, 'image_id'),
    211           'thumbnails_include' => 'include/category_default.inc.php',
    212           )
    213         );
    214     }
     327    $page = array_merge(
     328      $page,
     329      array(
     330        'title' => $lang['favorites'],
     331        'items' => array_from_query($query, 'image_id'),
     332        'thumbnails_include' => 'include/category_default.inc.php',
     333        )
     334      );
     335  }
    215336// +-----------------------------------------------------------------------+
    216337// |                       recent pictures section                         |
    217338// +-----------------------------------------------------------------------+
    218     else if ($page['cat'] == 'recent_pics')
    219     {
    220       $query = '
     339  else if ($page['section'] == 'recent_pics')
     340  {
     341    $query = '
    221342SELECT DISTINCT(id)
    222343  FROM '.IMAGES_TABLE.'
    223344    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
    224345  WHERE date_available > \''.
    225         date('Y-m-d', time() - 60*60*24*$user['recent_period']).'\'
     346      date('Y-m-d', time() - 60*60*24*$user['recent_period']).'\'
    226347    AND '.$forbidden.'
    227348  '.$conf['order_by'].'
    228349;';
    229350
    230       $page = array_merge(
    231         $page,
    232         array(
    233           'title' => $lang['recent_pics_cat'],
    234           'items' => array_from_query($query, 'id'),
    235           'thumbnails_include' => 'include/category_default.inc.php',
    236           )
    237         );
    238     }
     351    $page = array_merge(
     352      $page,
     353      array(
     354        'title' => $lang['recent_pics_cat'],
     355        'items' => array_from_query($query, 'id'),
     356        'thumbnails_include' => 'include/category_default.inc.php',
     357        )
     358      );
     359  }
    239360// +-----------------------------------------------------------------------+
    240361// |                 recently updated categories section                   |
    241362// +-----------------------------------------------------------------------+
    242     else if ($page['cat'] == 'recent_cats')
    243     {
    244       $page = array_merge(
    245         $page,
    246         array(
    247           'title' => $lang['recent_cats_cat'],
    248           'cat_nb_images' => 0,
    249           'thumbnails_include' => 'include/category_recent_cats.inc.php',
    250           )
    251         );
    252     }
     363  else if ($page['section'] == 'recent_cats')
     364  {
     365    $page = array_merge(
     366      $page,
     367      array(
     368        'title' => $lang['recent_cats_cat'],
     369        'cat_nb_images' => 0,
     370        'thumbnails_include' => 'include/category_recent_cats.inc.php',
     371        )
     372      );
     373  }
    253374// +-----------------------------------------------------------------------+
    254375// |                        most visited section                           |
    255376// +-----------------------------------------------------------------------+
    256     else if ($page['cat'] == 'most_visited')
    257     {
    258       $page['super_order_by'] = true;
    259       $conf['order_by'] = ' ORDER BY hit DESC, file ASC';
    260       $query = '
     377  else if ($page['section'] == 'most_visited')
     378  {
     379    $page['super_order_by'] = true;
     380    $conf['order_by'] = ' ORDER BY hit DESC, file ASC';
     381    $query = '
    261382SELECT DISTINCT(id)
    262383  FROM '.IMAGES_TABLE.'
    263384    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
    264385  WHERE hit > 0
    265     AND '.$forbidden.
    266   $conf['order_by'].'
     386    AND '.$forbidden.'
     387    '.$conf['order_by'].'
    267388  LIMIT 0, '.$conf['top_number'].'
    268389;';
    269 
    270       $page = array_merge(
    271         $page,
    272         array(
    273           'title' => $conf['top_number'].' '.$lang['most_visited_cat'],
    274           'items' => array_from_query($query, 'id'),
    275           'thumbnails_include' => 'include/category_default.inc.php',
    276           )
    277         );
    278     }
     390   
     391    $page = array_merge(
     392      $page,
     393      array(
     394        'title' => $conf['top_number'].' '.$lang['most_visited_cat'],
     395        'items' => array_from_query($query, 'id'),
     396        'thumbnails_include' => 'include/category_default.inc.php',
     397        )
     398      );
     399  }
    279400// +-----------------------------------------------------------------------+
    280401// |                          best rated section                           |
    281402// +-----------------------------------------------------------------------+
    282     else if ($page['cat'] == 'best_rated')
    283     {
    284       $page['super_order_by'] = true;
    285       $conf['order_by'] = ' ORDER BY average_rate DESC, id ASC';
    286 
    287       $query ='
     403  else if ($page['section'] == 'best_rated')
     404  {
     405    $page['super_order_by'] = true;
     406    $conf['order_by'] = ' ORDER BY average_rate DESC, id ASC';
     407   
     408    $query ='
    288409SELECT DISTINCT(id)
    289410  FROM '.IMAGES_TABLE.'
    290411    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
    291412  WHERE average_rate IS NOT NULL
    292     AND '.$forbidden.
    293   $conf['order_by'].'
     413    AND '.$forbidden.'
     414    '.$conf['order_by'].'
    294415  LIMIT 0, '.$conf['top_number'].'
    295416;';
    296       $page = array_merge(
    297         $page,
    298         array(
    299           'title' => $conf['top_number'].' '.$lang['best_rated_cat'],
    300           'items' => array_from_query($query, 'id'),
    301           'thumbnails_include' => 'include/category_default.inc.php',
    302           )
    303         );
    304     }
     417    $page = array_merge(
     418      $page,
     419      array(
     420        'title' => $conf['top_number'].' '.$lang['best_rated_cat'],
     421        'items' => array_from_query($query, 'id'),
     422        'thumbnails_include' => 'include/category_default.inc.php',
     423        )
     424      );
     425  }
    305426// +-----------------------------------------------------------------------+
    306427// |                             list section                              |
    307428// +-----------------------------------------------------------------------+
    308     else if ($page['cat'] == 'list')
    309     {
    310       $query ='
     429  else if ($page['section'] == 'list')
     430  {
     431    $query ='
    311432SELECT DISTINCT(id)
    312433  FROM '.IMAGES_TABLE.'
    313434    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
    314   WHERE image_id IN ('.$_GET['list'].')
     435  WHERE image_id IN ('.implode(',', $page['list']).')
    315436    AND '.$forbidden.'
    316437  '.$conf['order_by'].'
    317438;';
    318       $page = array_merge(
    319         $page,
    320         array(
    321           'title' => $lang['random_cat'],
    322           'items' => array_from_query($query, 'id'),
    323           'thumbnails_include' => 'include/category_default.inc.php',
    324           )
    325         );
    326     }
    327 
    328     if (!isset($page['cat_nb_images']))
    329     {
    330       $page['cat_nb_images'] = count($page['items']);
    331     }
     439     
     440    $page = array_merge(
     441      $page,
     442      array(
     443        'title' => $lang['random_cat'],
     444        'items' => array_from_query($query, 'id'),
     445        'thumbnails_include' => 'include/category_default.inc.php',
     446        )
     447      );
     448  }
     449 
     450  if (!isset($page['cat_nb_images']))
     451  {
     452    $page['cat_nb_images'] = count($page['items']);
    332453  }
    333454}
    334 // +-----------------------------------------------------------------------+
    335 // |                            root category                              |
    336 // +-----------------------------------------------------------------------+
    337 else
    338 {
    339   $page['title'] = $lang['no_category'];
    340   $page['thumbnails_include'] = 'include/category_subcats.inc.php';
    341 }
    342 
    343 if ( isset($_GET['calendar']) )
     455
     456// +-----------------------------------------------------------------------+
     457// |                             chronology                                |
     458// +-----------------------------------------------------------------------+
     459
     460if (isset($_GET['calendar']))
    344461{
    345462  include_once( PHPWG_ROOT_PATH.'include/functions_calendar.inc.php' );
     
    347464}
    348465
     466// echo '<pre>'; print_r($page); echo '</pre>';
     467
     468
    349469?>
  • trunk/notification.php

    r1072 r1082  
    6464  array(
    6565    'FEED_URL' => PHPWG_ROOT_PATH.'feed.php?feed='.$page['feed'],
    66     'U_HOME' => PHPWG_ROOT_PATH.'category.php'
     66    'U_HOME' => make_index_url(),
    6767    )
    6868  );
  • trunk/password.php

    r1070 r1082  
    151151$template->assign_vars(
    152152  array(
    153     'U_HOME' => PHPWG_ROOT_PATH.'category.php'
     153    'U_HOME' => make_index_url(),
    154154    )
    155155  );
  • trunk/picture.php

    r1078 r1082  
    2626// +-----------------------------------------------------------------------+
    2727
    28 $rate_items = array(0,1,2,3,4,5);
    29 //--------------------------------------------------------------------- include
    3028define('PHPWG_ROOT_PATH','./');
    3129include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
    32 
    33 // +-----------------------------------------------------------------------+
    34 // | Check Access and exit when user status is not ok                      |
    35 // +-----------------------------------------------------------------------+
     30include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
     31
     32// Check Access and exit when user status is not ok
    3633check_status(ACCESS_GUEST);
    3734
    38 include(PHPWG_ROOT_PATH.'include/section_init.inc.php');
    39 //-------------------------------------------------- access authorization check
    40 if (isset($page['cat']) and is_numeric($page['cat']))
    41 {
    42   check_restrictions($page['cat']);
    43 }
    44 //-------------------------------------------------------------- initialization
     35// access authorization check
     36if (isset($page['category']))
     37{
     38  check_restrictions($page['category']);
     39}
     40
    4541// if this image_id doesn't correspond to this category, an error message is
    4642// displayed, and execution is stopped
    47 if (!in_array($_GET['image_id'], $page['items']))
    48 {
    49   echo '
    50 <div style="text-align:center;">'.$lang['access_forbiden'].'<br />
    51   <a href="'.PHPWG_ROOT_PATH.'category.php'.'">'.$lang['thumbnails'].'</a>
    52 </div>';
    53   exit();
    54 }
     43if (!in_array($page['image_id'], $page['items']))
     44{
     45  die('Fatal: this picture does not belong to this section');
     46}
     47
     48// +-----------------------------------------------------------------------+
     49// |                            initialization                             |
     50// +-----------------------------------------------------------------------+
    5551
    5652$page['rank_of'] = array_flip($page['items']);
     
    6056$page['first_rank']   = 0;
    6157$page['last_rank']    = count($page['items']) - 1;
    62 $page['current_rank'] = $page['rank_of'][ $_GET['image_id'] ];
     58$page['current_rank'] = $page['rank_of'][ $page['image_id'] ];
    6359
    6460// caching current item : readability purpose
    65 $page['current_item'] = $_GET['image_id'];
     61$page['current_item'] = $page['image_id'];
    6662
    6763if ($page['current_rank'] != $page['first_rank'])
     
    7268    'first',
    7369    array(
    74       'U_IMG' =>
    75         PHPWG_ROOT_PATH.'picture.php'.
    76         get_query_string_diff(
    77           array('image_id', 'add_fav', 'slideshow')
    78           ).
    79         '&amp;image_id='.$page['items'][ $page['first_rank'] ],
     70      'U_IMG' => duplicate_picture_URL(
     71        // redefinitions
     72        array(
     73          'image_id' => $page['items'][ $page['first_rank'] ],
     74          ),
     75        // removes
     76        array()
     77        )
    8078      )
    8179    );
     
    9290    'last',
    9391    array(
    94       'U_IMG' =>
    95         PHPWG_ROOT_PATH.'picture.php'.
    96         get_query_string_diff(
    97           array('image_id', 'add_fav', 'slideshow')
    98           ).
    99         '&amp;image_id='.$page['items'][ $page['last_rank'] ],
     92      'U_IMG' => duplicate_picture_URL(
     93        // redefinitions
     94        array(
     95          'image_id' => $page['items'][ $page['last_rank'] ],
     96          ),
     97        // removes
     98        array()
     99        )
    100100      )
    101101    );
     
    105105}
    106106
    107 //---------------------------------------- incrementation of the number of hits
    108 if ( count(array_intersect(
    109              array_keys($_GET),
    110              array('add_fav', 'caddie', 'rate', 'representative', 'del') )
    111           )==0 )
    112 {
    113   $query = '
    114   UPDATE '.IMAGES_TABLE.'
    115     SET hit = hit+1
    116     WHERE id = '.$_GET['image_id'].'
    117   ;';
    118   @pwg_query( $query );
    119 }
    120 
    121 //-------------------------------------------------------------- representative
    122 if (is_admin() and isset($_GET['representative']))
    123 {
    124   $query = '
     107$url_up = duplicate_index_URL(
     108  array(
     109    'start' =>
     110      floor($page['current_rank'] / $user['nb_image_page'])
     111      * $user['nb_image_page']
     112    ),
     113  array(
     114    'start',
     115    )
     116  );
     117
     118$url_self = duplicate_picture_URL();
     119
     120// +-----------------------------------------------------------------------+
     121// |                                actions                                |
     122// +-----------------------------------------------------------------------+
     123
     124/**
     125 * Actions are favorite adding, user comment deletion, setting the picture
     126 * as representative of the current category...
     127 *
     128 * Actions finish by a redirection
     129 */
     130
     131if (isset($_GET['action']))
     132{
     133  switch ($_GET['action'])
     134  {
     135    case 'add_to_favorites' :
     136    {
     137      $query = '
     138INSERT INTO '.FAVORITES_TABLE.'
     139  (image_id,user_id)
     140  VALUES
     141  ('.$page['image_id'].','.$user['id'].')
     142;';
     143      pwg_query($query);
     144
     145      redirect($url_self);
     146     
     147      break;
     148    }
     149    case 'remove_from_favorites' :
     150    {
     151      $query = '
     152DELETE FROM '.FAVORITES_TABLE.'
     153  WHERE user_id = '.$user['id'].'
     154    AND image_id = '.$page['image_id'].'
     155;';
     156      pwg_query($query);
     157
     158      if ('favorites' == $page['section'])
     159      {
     160        redirect($url_up);
     161      }
     162      else
     163      {
     164        redirect($url_self);
     165      }
     166     
     167      break;
     168    }
     169    case 'set_as_representative' :
     170    {
     171      if (is_admin() and isset($page['category']))
     172      {
     173        $query = '
    125174UPDATE '.CATEGORIES_TABLE.'
    126   SET representative_picture_id = '.$_GET['image_id'].'
    127   WHERE id = '.$page['cat'].'
    128 ;';
    129   pwg_query($query);
    130 
    131   $url =
    132     PHPWG_ROOT_PATH
    133     .'picture.php'
    134     .get_query_string_diff(array('representative'));
    135   redirect($url);
    136 }
    137 
    138 //-------------------------------------------------------------- caddie filling
    139 
    140 if (isset($_GET['caddie']))
    141 {
    142   fill_caddie(array($_GET['image_id']));
    143 
    144   $url =
    145     PHPWG_ROOT_PATH
    146     .'picture.php'
    147     .get_query_string_diff(array('caddie'));
    148   redirect($url);
    149 }
    150 
    151 
    152 //----------------------------------------------------------- rate registration
    153 if (isset($_GET['rate'])
    154     and $conf['rate']
    155     and ( !$user['is_the_guest'] or $conf['rate_anonymous'] )
    156     and in_array($_GET['rate'], $rate_items))
    157 {
    158   if ($user['is_the_guest'])
    159   {
    160     $ip_components = explode('.', $_SERVER["REMOTE_ADDR"]);
    161     if ( count($ip_components)>3 )
     175  SET representative_picture_id = '.$page['image_id'].'
     176  WHERE id = '.$page['category'].'
     177;';
     178        pwg_query($query);
     179      }
     180     
     181      redirect($url_self);
     182 
     183      break;
     184    }
     185    case 'toggle_metadata' :
    162186    {
    163       array_pop($ip_components);
     187      break;
    164188    }
    165     $anonymous_id = implode ('.', $ip_components);
    166 
    167     if ( isset($_COOKIE['pwg_anonymous_rater']) )
     189    case 'add_to_caddie' :
    168190    {
    169       if ($anonymous_id != $_COOKIE['pwg_anonymous_rater'] )
    170       { // client has changed his IP adress or he's trying to fool us
    171         $query = '
     191      fill_caddie(array($page['image_id']));
     192      redirect($url_self);
     193      break;
     194    }
     195    case 'rate' :
     196    {
     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 = '
    172216SELECT element_id FROM '. RATE_TABLE . '
    173217  WHERE user_id=' . $user['id'] . '
    174218  AND anonymous_id=\'' . $anonymous_id . '\'';
    175         $result = pwg_query($query);
    176         $already_there = array();
    177         while ( $row = mysql_fetch_array($result) )
     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 = '
     229DELETE
     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 = '
     239UPDATE
     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 = '
     267DELETE
     268  FROM '.RATE_TABLE.'
     269  WHERE element_id = '.$page['image_id'] . '
     270  AND user_id = '.$user['id'].'
     271';
     272        if (isset($anonymous_id))
    178273        {
    179           array_push( $already_there, $row['element_id'] );
     274          $query.= ' AND anonymous_id = \''.$anonymous_id.'\'';
    180275        }
    181 
    182         if ( count($already_there)>0 )
    183         {
    184           $query = '
    185 DELETE FROM '. RATE_TABLE . '
    186   WHERE user_id=' . $user['id'] . '
    187   AND anonymous_id=\'' . $_COOKIE['pwg_anonymous_rater'] . '\'
    188   AND element_id NOT IN (' . implode(',',$already_there) . ')';
    189           pwg_query($query);
    190         }
    191 
     276        pwg_query($query);
    192277        $query = '
    193 UPDATE '. RATE_TABLE . '
    194   SET anonymous_id=\'' . $anonymous_id . '\'
    195   WHERE user_id=' . $user['id'] . '
    196   AND anonymous_id=\'' . $_COOKIE['pwg_anonymous_rater'] . '\'';
    197         pwg_query($query);
    198 
    199         setcookie('pwg_anonymous_rater', $anonymous_id,
    200                    strtotime('+10 years'), cookie_path() );
    201       }
    202     }
    203     else
    204     {
    205       setcookie('pwg_anonymous_rater', $anonymous_id,
    206                  strtotime('+10 years'), cookie_path() );
    207     }
    208   }
    209 
    210   $query = '
    211 DELETE FROM '.RATE_TABLE.'
    212   WHERE element_id = '.$_GET['image_id'] . '
    213   AND user_id = '.$user['id']
    214 ;
    215   if (isset($anonymous_id))
    216   {
    217     $query.= ' AND anonymous_id=\'' . $anonymous_id .'\'';
    218   }
    219   pwg_query($query);
    220   $query = '
    221 INSERT INTO '.RATE_TABLE.'
     278INSERT
     279  INTO '.RATE_TABLE.'
    222280  (user_id,anonymous_id,element_id,rate,date)
    223281  VALUES
    224   ('.$user['id'].','.(isset($anonymous_id)?'\''.$anonymous_id.'\'':"''").','.
    225    $_GET['image_id'].','.$_GET['rate'].',NOW())
    226 ;';
    227   pwg_query($query);
    228 
    229   // update of images.average_rate field
    230   $query = '
     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 = '
    231293SELECT ROUND(AVG(rate),2) AS average_rate
    232294  FROM '.RATE_TABLE.'
    233   WHERE element_id = '.$_GET['image_id'].'
    234 ;';
    235   $row = mysql_fetch_array(pwg_query($query));
    236   $query = '
     295  WHERE element_id = '.$page['image_id'].'
     296;';
     297        $row = mysql_fetch_array(pwg_query($query));
     298        $query = '
    237299UPDATE '.IMAGES_TABLE.'
    238300  SET average_rate = '.$row['average_rate'].'
    239   WHERE id = '.$_GET['image_id'].'
    240 ;';
    241   pwg_query($query);
    242   $url =
    243     PHPWG_ROOT_PATH
    244     .'picture.php'
    245     .get_query_string_diff(array('rate'));
    246   redirect($url);
    247 }
    248 
     301  WHERE id = '.$page['image_id'].'
     302;';
     303        pwg_query($query);
     304      }
     305     
     306      redirect($url_self);
     307    }
     308    case 'delete_comment' :
     309    {
     310      if (isset($_GET['comment_to_delete'])
     311          and is_numeric($_GET['comment_to_delete'])
     312          and is_admin())
     313      {
     314        $query = '
     315DELETE FROM '.COMMENTS_TABLE.'
     316  WHERE id = '.$_GET['comment_to_delete'].'
     317;';
     318        pwg_query( $query );
     319      }
     320
     321      redirect($url_self);
     322    }
     323  }
     324}
     325
     326// incrementation of the number of hits, we do this only if no action
     327$query = '
     328UPDATE
     329  '.IMAGES_TABLE.'
     330  SET hit = hit+1
     331  WHERE id = '.$page['image_id'].'
     332;';
     333pwg_query($query);
    249334
    250335//---------------------------------------------------------- related categories
     
    253338  FROM '.IMAGE_CATEGORY_TABLE.'
    254339    INNER JOIN '.CATEGORIES_TABLE.' ON category_id = id
    255   WHERE image_id = '.$_GET['image_id'].'
     340  WHERE image_id = '.$page['image_id'].'
    256341    AND category_id NOT IN ('.$user['forbidden_categories'].')
    257342;';
     
    266351$picture = array();
    267352
    268 $ids = array($_GET['image_id']);
     353$ids = array($page['image_id']);
    269354if (isset($page['previous_item']))
    270355{
     
    362447  }
    363448
    364   $picture[$i]['url'] =
    365     PHPWG_ROOT_PATH.'picture.php'
    366     .get_query_string_diff(array('image_id', 'add_fav', 'slideshow'))
    367     .'&amp;image_id='.$row['id'];
    368 }
    369 
    370 $url_up = PHPWG_ROOT_PATH.'category.php?';
    371 if ( isset($page['cat']) )
    372 {
    373   $url_up .= 'cat='.$page['cat'];
    374 }
    375 elseif ( isset($_GET['calendar']) )
    376 {
    377   $url_up .= 'calendar='.$_GET['calendar'];
    378 }
    379 
    380 $url_up_start = floor( $page['current_rank'] / $user['nb_image_page'] );
    381 $url_up_start *= $user['nb_image_page'];
    382 if ($url_up_start>0)
    383 {
    384   $url_up .= '&amp;start='.$url_up_start;
    385 }
    386 
    387 if ( isset($page['cat']) )
    388 {
    389   if ( $page['cat'] == 'search' )
    390   {
    391     $url_up.= '&amp;search='.$_GET['search'];
    392   }
    393   if ( $page['cat'] == 'list' )
    394   {
    395     $url_up.= '&amp;list='.$_GET['list'];
    396   }
     449  $picture[$i]['url'] = duplicate_picture_URL(
     450    array(
     451      'image_id' => $row['id'],
     452      ),
     453    array(
     454      'start',
     455      )
     456    );
    397457}
    398458
    399459$url_admin =
    400460  PHPWG_ROOT_PATH.'admin.php?page=picture_modify'
    401   .'&amp;cat_id='. ( isset($page['cat']) ? $page['cat'] : '' )
    402   .'&amp;image_id='.$_GET['image_id'];
     461  .'&amp;cat_id='.(isset($page['category']) ? $page['category'] : '')
     462  .'&amp;image_id='.$page['image_id']
     463;
    403464
    404465$url_slide =
    405   $picture['current']['url'].'&amp;slideshow='.$conf['slideshow_period'];
    406 
    407 //--------------------------------------------------------- favorite management
    408 if ( isset( $_GET['add_fav'] ) )
    409 {
    410   $query = 'DELETE FROM '.FAVORITES_TABLE;
    411   $query.= ' WHERE user_id = '.$user['id'];
    412   $query.= ' AND image_id = '.$picture['current']['id'];
    413   $query.= ';';
    414   $result = pwg_query( $query );
    415 
    416   if ( $_GET['add_fav'] == 1 )
    417   {
    418     $query = 'INSERT INTO '.FAVORITES_TABLE;
    419     $query.= ' (image_id,user_id) VALUES';
    420     $query.= ' ('.$picture['current']['id'].','.$user['id'].')';
    421     $query.= ';';
    422     $result = pwg_query( $query );
    423   }
    424   if ( !$_GET['add_fav'] and isset($page['cat']) and 'fav'==$page['cat'] )
    425   {
    426     if (!isset($page['previous_item']) and !isset($page['next_item']))
    427     {
    428       // there is no favorite picture anymore we redirect the user to the
    429       // category page
    430       redirect($url_up);
    431     }
    432     else if (!isset($page['previous_item']))
    433     {
    434       $url = str_replace( '&amp;', '&', $picture['next']['url'] );
    435       redirect( $url );
    436     }
    437     else
    438     {
    439       $url = str_replace('&amp;', '&', $picture['prev']['url'] );
    440       redirect( $url );
    441     }
    442     redirect( $url );
    443   }
    444 }
    445 
    446 //------------------------------------------------------  comment registeration
    447 if ( isset( $_POST['content'] ) && !empty($_POST['content']) )
    448 {
    449   $register_comment = true;
    450   $author = !empty($_POST['author'])?$_POST['author']:$lang['guest'];
    451   // if a guest try to use the name of an already existing user, he must be
    452   // rejected
    453   if ( $author != $user['username'] )
    454   {
    455     $query = 'SELECT COUNT(*) AS user_exists';
    456     $query.= ' FROM '.USERS_TABLE;
    457     $query.= ' WHERE '.$conf['user_fields']['username']." = '".$author."'";
    458     $query.= ';';
    459     $row = mysql_fetch_array( pwg_query( $query ) );
    460     if ( $row['user_exists'] == 1 )
    461     {
    462       $template->assign_block_vars(
    463         'information',
    464         array('INFORMATION'=>$lang['comment_user_exists']));
    465       $register_comment = false;
    466     }
    467   }
    468 
    469   if ( $register_comment )
    470   {
    471     // anti-flood system
    472     $reference_date = time() - $conf['anti-flood_time'];
    473     $query = 'SELECT id FROM '.COMMENTS_TABLE;
    474     $query.= ' WHERE date > FROM_UNIXTIME('.$reference_date.')';
    475     $query.= " AND author = '".$author."'";
    476     $query.= ';';
    477     if ( mysql_num_rows( pwg_query( $query ) ) == 0
    478          or $conf['anti-flood_time'] == 0 )
    479     {
    480       list($dbnow) = mysql_fetch_row(pwg_query('SELECT NOW();'));
    481 
    482       $data = array();
    483       $data{'author'} = $author;
    484       $data{'date'} = $dbnow;
    485       $data{'image_id'} = $_GET['image_id'];
    486       $data{'content'} = htmlspecialchars( $_POST['content'], ENT_QUOTES);
    487 
    488       if (!$conf['comments_validation'] or is_admin())
    489       {
    490         $data{'validated'} = 'true';
    491         $data{'validation_date'} = $dbnow;
    492       }
    493       else
    494       {
    495         $data{'validated'} = 'false';
    496       }
    497 
    498       include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
    499       $fields = array('author', 'date', 'image_id', 'content', 'validated',
    500                       'validation_date');
    501       mass_inserts(COMMENTS_TABLE, $fields, array($data));
    502 
    503       // information message
    504       $message = $lang['comment_added'];
    505 
    506       if (!$conf['comments_validation'] or is_admin())
    507 
    508       if ( $conf['comments_validation'] and !is_admin() )
    509       {
    510         $message.= '<br />'.$lang['comment_to_validate'];
    511       }
    512       $template->assign_block_vars('information',
    513                                    array('INFORMATION'=>$message));
    514     }
    515     else
    516     {
    517       // information message
    518       $template->assign_block_vars(
    519         'information',
    520         array('INFORMATION'=>$lang['comment_anti-flood']));
    521     }
    522   }
    523 }
    524 // comment deletion
    525 if ( isset( $_GET['del'] )
    526      and is_numeric( $_GET['del'] )
    527      and is_admin() )
    528 {
    529   $query = 'DELETE FROM '.COMMENTS_TABLE;
    530   $query.= ' WHERE id = '.$_GET['del'];
    531   $query.= ';';
    532   pwg_query( $query );
    533 }
    534 
    535 //
    536 // Start output of page
    537 //
     466  $picture['current']['url']
     467  .'&amp;slideshow='.$conf['slideshow_period']
     468;
    538469
    539470$title =  $picture['current']['name'];
     
    572503}
    573504
    574 $picture_size = get_picture_size($original_width, $original_height,
    575                                  @$user['maxwidth'], @$user['maxheight']);
     505$picture_size = get_picture_size(
     506  $original_width,
     507  $original_height,
     508  @$user['maxwidth'],
     509  @$user['maxheight']
     510  );
    576511
    577512// metadata
     
    585520}
    586521
    587 $url_metadata = PHPWG_ROOT_PATH.'picture.php';
    588 $url_metadata .=  get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata'));
    589 if ($metadata_showable and !isset($_GET['show_metadata']))
    590 {
    591   $url_metadata.= '&amp;show_metadata=1';
    592 }
     522// $url_metadata = PHPWG_ROOT_PATH.'picture.php';
     523// $url_metadata .=  get_query_string_diff(array('add_fav', 'slideshow', 'show_metadata'));
     524// if ($metadata_showable and !isset($_GET['show_metadata']))
     525// {
     526//   $url_metadata.= '&amp;show_metadata=1';
     527// }
     528
     529// TODO: rewrite metadata display to toggle on/off user_infos.show_metadata
     530$url_metadata = duplicate_picture_URL();
    593531
    594532$page['body_id'] = 'thePicturePage';
     
    623561$template->set_filenames(array('picture'=>'picture.tpl'));
    624562
    625 $template->assign_vars(array(
    626   'CATEGORY' => $title_img,
    627   'PHOTO' => $title_nb,
    628   'TITLE' => $picture['current']['name'],
    629   'SRC_IMG' => $picture['current']['src'],
    630   'ALT_IMG' => $picture['current']['file'],
    631   'WIDTH_IMG' => $picture_size[0],
    632   'HEIGHT_IMG' => $picture_size[1],
    633 
    634   'LEVEL_SEPARATOR' => $conf['level_separator'],
    635 
    636   'L_HOME' => $lang['home'],
    637   'L_SLIDESHOW' => $lang['slideshow'],
    638   'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
    639   'L_PREV_IMG' =>$lang['previous_page'].' : ',
    640   'L_NEXT_IMG' =>$lang['next_page'].' : ',
    641   'L_ADMIN' =>$lang['link_info_image'],
    642   'L_COMMENT_TITLE' =>$lang['comments_title'],
    643   'L_ADD_COMMENT' =>$lang['comments_add'],
    644   'L_DELETE_COMMENT' =>$lang['comments_del'],
    645   'L_DELETE' =>$lang['delete'],
    646   'L_SUBMIT' =>$lang['submit'],
    647   'L_AUTHOR' =>  $lang['upload_author'],
    648   'L_COMMENT' =>$lang['comment'],
    649   'L_DOWNLOAD' => $lang['download'],
    650   'L_DOWNLOAD_HINT' => $lang['download_hint'],
    651   'L_PICTURE_METADATA' => $lang['picture_show_metadata'],
    652   'L_PICTURE_HIGH' => $lang['picture_high'],
    653   'L_UP_HINT' => $lang['home_hint'],
    654   'L_UP_ALT' => $lang['home'],
    655 
    656   'U_HOME' => (PHPWG_ROOT_PATH.'category.php'),
    657   'U_UP' => $url_up,
    658   'U_METADATA' => $url_metadata,
    659   'U_ADMIN' => $url_admin,
    660   'U_SLIDESHOW'=> $url_slide,
    661   'U_ADD_COMMENT' => str_replace( '&', '&amp;', $_SERVER['REQUEST_URI'] )
    662   )
    663 );
     563$template->assign_vars(
     564  array(
     565    'CATEGORY' => $title_img,
     566    'PHOTO' => $title_nb,
     567    'TITLE' => $picture['current']['name'],
     568    'SRC_IMG' => $picture['current']['src'],
     569    'ALT_IMG' => $picture['current']['file'],
     570    'WIDTH_IMG' => $picture_size[0],
     571    'HEIGHT_IMG' => $picture_size[1],
     572
     573    'LEVEL_SEPARATOR' => $conf['level_separator'],
     574
     575    'L_HOME' => $lang['home'],
     576    'L_SLIDESHOW' => $lang['slideshow'],
     577    'L_STOP_SLIDESHOW' => $lang['slideshow_stop'],
     578    'L_PREV_IMG' =>$lang['previous_page'].' : ',
     579    'L_NEXT_IMG' =>$lang['next_page'].' : ',
     580    'L_ADMIN' =>$lang['link_info_image'],
     581    'L_COMMENT_TITLE' =>$lang['comments_title'],
     582    'L_ADD_COMMENT' =>$lang['comments_add'],
     583    'L_DELETE_COMMENT' =>$lang['comments_del'],
     584    'L_DELETE' =>$lang['delete'],
     585    'L_SUBMIT' =>$lang['submit'],
     586    'L_AUTHOR' =>  $lang['upload_author'],
     587    'L_COMMENT' =>$lang['comment'],
     588    'L_DOWNLOAD' => $lang['download'],
     589    'L_DOWNLOAD_HINT' => $lang['download_hint'],
     590    'L_PICTURE_METADATA' => $lang['picture_show_metadata'],
     591    'L_PICTURE_HIGH' => $lang['picture_high'],
     592    'L_UP_HINT' => $lang['home_hint'],
     593    'L_UP_ALT' => $lang['home'],
     594
     595    'U_HOME' => make_index_URL(),
     596    'U_UP' => $url_up,
     597    'U_METADATA' => $url_metadata,
     598    'U_ADMIN' => $url_admin,
     599    'U_SLIDESHOW'=> $url_slide,
     600    'U_ADD_COMMENT' => $url_self,
     601    )
     602  );
    664603
    665604if ($conf['show_picture_name_on_title'])
     
    669608
    670609//------------------------------------------------------- upper menu management
     610
    671611// download link if file is not a picture
    672612if (!$picture['current']['is_picture'])
     
    674614  $template->assign_block_vars(
    675615    'download',
    676     array('U_DOWNLOAD' => $picture['current']['download']));
    677 }
     616    array(
     617      'U_DOWNLOAD' => $picture['current']['download']
     618      )
     619    );
     620}
     621
    678622// display a high quality link if present
    679623if (isset($picture['current']['high']))
    680624{
    681625  $uuid = uniqid(rand());
    682   $template->assign_block_vars('high', array(
    683     'U_HIGH' => $picture['current']['high'],
    684     'UUID'=>$uuid
    685   ));
     626 
     627  $template->assign_block_vars(
     628    'high',
     629    array(
     630      'U_HIGH' => $picture['current']['high'],
     631      'UUID'   => $uuid,
     632      )
     633    );
     634 
    686635  $template->assign_block_vars(
    687636    'download',
    688     array('U_DOWNLOAD' => PHPWG_ROOT_PATH.'action.php?dwn='
    689           .$picture['current']['high']
    690     )
    691   );
    692 }
     637    array(
     638      'U_DOWNLOAD' => PHPWG_ROOT_PATH.'action.php?dwn='
     639      .$picture['current']['high']
     640      )
     641    );
     642}
     643
    693644// button to set the current picture as representative
    694 if (is_admin() and
    695     isset($page['cat']) and is_numeric($page['cat']))
     645if (is_admin() and isset($page['category']))
    696646{
    697647  $template->assign_block_vars(
    698648    'representative',
    699649    array(
    700       'URL' =>
    701         PHPWG_ROOT_PATH.'picture.php'
    702         .get_query_string_diff(array('add_fav'))
    703         .'&amp;representative=1'
    704       )
    705     );
    706 }
    707 
     650      'URL' => $url_self.'&amp;action=set_as_representative'
     651      )
     652    );
     653}
     654
     655// caddie button
    708656if (is_admin())
    709657{
     
    711659    'caddie',
    712660    array(
    713       'URL' =>
    714         PHPWG_ROOT_PATH.'picture.php'
    715         .get_query_string_diff(array('add_fav')).'&amp;caddie=1')
    716     );
    717 }
    718 
    719 //------------------------------------------------------- favorite manipulation
    720 if ( !$user['is_the_guest'] )
     661      'URL' => $url_self.'&amp;action=add_to_caddie'
     662      )
     663    );
     664}
     665
     666// favorite manipulation
     667if (!$user['is_the_guest'])
    721668{
    722669  // verify if the picture is already in the favorite of the user
    723   $query = 'SELECT COUNT(*) AS nb_fav';
    724   $query.= ' FROM '.FAVORITES_TABLE.' WHERE image_id = '.$_GET['image_id'];
    725   $query.= ' AND user_id = '.$user['id'].';';
    726   $result = pwg_query( $query );
    727   $row = mysql_fetch_array( $result );
    728   if (!$row['nb_fav'])
    729   {
    730     $url = PHPWG_ROOT_PATH.'picture.php';
    731     $url.= get_query_string_diff(array('add_fav'));
    732     $url.= '&amp;add_fav=1';
     670  $query = '
     671SELECT COUNT(*) AS nb_fav
     672  FROM '.FAVORITES_TABLE.'
     673  WHERE image_id = '.$page['image_id'].'
     674    AND user_id = '.$user['id'].'
     675;';
     676  $result = pwg_query($query);
     677  $row = mysql_fetch_array($result);
     678 
     679  if ($row['nb_fav'] == 0)
     680  {
     681    $url = $url_self.'&amp;action=add_to_favorites';
    733682
    734683    $template->assign_block_vars(
    735684      'favorite',
    736685      array(
    737         'FAVORITE_IMG' => get_themeconf('icon_dir').'/favorite.png',
    738         'FAVORITE_HINT' =>$lang['add_favorites_hint'],
    739         'FAVORITE_ALT' =>$lang['add_favorites_alt'],
    740         'U_FAVORITE' => $url
    741         ));
     686        'FAVORITE_IMG'  => get_themeconf('icon_dir').'/favorite.png',
     687        'FAVORITE_HINT' => $lang['add_favorites_hint'],
     688        'FAVORITE_ALT'  => $lang['add_favorites_alt'],
     689        'U_FAVORITE'    => $url_self.'&amp;action=add_to_favorites',
     690        )
     691      );
    742692  }
    743693  else
    744694  {
    745     $url = PHPWG_ROOT_PATH.'picture.php';
    746     $url.= get_query_string_diff(array('add_fav'));
    747     $url.= '&amp;add_fav=0';
    748 
    749695    $template->assign_block_vars(
    750696      'favorite',
    751697      array(
    752         'FAVORITE_IMG' => get_themeconf('icon_dir').'/del_favorite.png',
    753         'FAVORITE_HINT' =>$lang['del_favorites_hint'],
    754         'FAVORITE_ALT' =>$lang['del_favorites_alt'],
    755         'U_FAVORITE'=> $url
    756         ));
     698        'FAVORITE_IMG'  => get_themeconf('icon_dir').'/del_favorite.png',
     699        'FAVORITE_HINT' => $lang['del_favorites_hint'],
     700        'FAVORITE_ALT'  => $lang['del_favorites_alt'],
     701        'U_FAVORITE'    => $url_self.'&amp;action=remove_from_favorites',
     702        )
     703      );
    757704  }
    758705}
     
    888835}
    889836
    890 //-------------------------------------------------------------------  metadata
    891 if ($metadata_showable and isset($_GET['show_metadata']))
    892 {
    893   include_once(PHPWG_ROOT_PATH.'/include/functions_metadata.inc.php');
    894   $template->assign_block_vars('metadata', array());
    895   if ($conf['show_exif'])
    896   {
    897     if (!function_exists('read_exif_data'))
    898     {
    899       die('Exif extension not available, admin should disable exif display');
    900     }
    901 
    902     if ($exif = @read_exif_data($picture['current']['src']))
    903     {
    904       $template->assign_block_vars(
    905         'metadata.headline',
    906         array('TITLE' => 'EXIF Metadata')
    907         );
    908 
    909       foreach ($conf['show_exif_fields'] as $field)
    910       {
    911         if (strpos($field, ';') === false)
    912         {
    913           if (isset($exif[$field]))
    914           {
    915             $key = $field;
    916             if (isset($lang['exif_field_'.$field]))
    917             {
    918               $key = $lang['exif_field_'.$field];
    919             }
    920 
    921             $template->assign_block_vars(
    922               'metadata.line',
    923               array(
    924                 'KEY' => $key,
    925                 'VALUE' => $exif[$field]
    926                 )
    927               );
    928           }
    929         }
    930         else
    931         {
    932           $tokens = explode(';', $field);
    933           if (isset($exif[$tokens[0]][$tokens[1]]))
    934           {
    935             $key = $tokens[1];
    936             if (isset($lang['exif_field_'.$tokens[1]]))
    937             {
    938               $key = $lang['exif_field_'.$tokens[1]];
    939             }
    940 
    941             $template->assign_block_vars(
    942               'metadata.line',
    943               array(
    944                 'KEY' => $key,
    945                 'VALUE' => $exif[$tokens[0]][$tokens[1]]
    946                 )
    947               );
    948           }
    949         }
    950       }
    951     }
    952   }
    953   if ($conf['show_iptc'])
    954   {
    955     $iptc = get_iptc_data($picture['current']['src'],
    956                           $conf['show_iptc_mapping']);
    957 
    958     if (count($iptc) > 0)
    959     {
    960       $template->assign_block_vars(
    961         'metadata.headline',
    962         array('TITLE' => 'IPTC Metadata')
    963         );
    964     }
    965 
    966     foreach ($iptc as $field => $value)
    967     {
    968       $key = $field;
    969       if (isset($lang[$field]))
    970       {
    971         $key = $lang[$field];
    972       }
    973 
    974       $template->assign_block_vars(
    975         'metadata.line',
    976         array(
    977           'KEY' => $key,
    978           'VALUE' => $value
    979           )
    980         );
    981     }
    982   }
    983 }
    984837//slideshow end
    985 if ( isset( $_GET['slideshow'] ) )
    986 {
    987   if ( !is_numeric( $_GET['slideshow'] ) ) $_GET['slideshow'] = $conf['slideshow_period'];
    988 
    989   $template->assign_block_vars('stop_slideshow', array(
    990   'U_SLIDESHOW'=>$picture['current']['url']
    991   ));
    992 }
    993 
    994 //------------------------------------------------------------------- rating
    995 if ($conf['rate'])
    996 {
    997   $query = '
    998 SELECT COUNT(rate) AS count
    999      , ROUND(AVG(rate),2) AS average
    1000      , ROUND(STD(rate),2) AS STD
    1001   FROM '.RATE_TABLE.'
    1002   WHERE element_id = '.$picture['current']['id'].'
    1003 ;';
    1004   $row = mysql_fetch_array(pwg_query($query));
    1005   if ($row['count'] == 0)
    1006   {
    1007     $value = $lang['no_rate'];
    1008   }
    1009   else
    1010   {
    1011     $value = sprintf(
    1012       l10n('%.2f (rated %d times, standard deviation = %.2f)'),
    1013       $row['average'],
    1014       $row['count'],
    1015       $row['STD']
    1016       );
    1017   }
    1018 
    1019   if ($conf['rate_anonymous'] or !$user['is_the_guest'])
    1020   {
    1021     if ($row['count']>0)
    1022     {
    1023       $query = 'SELECT rate
    1024       FROM '.RATE_TABLE.'
    1025       WHERE element_id = '.$_GET['image_id'] . '
    1026       AND user_id = '.$user['id'] ;
    1027 
    1028       if ($user['is_the_guest'])
    1029       {
    1030         $ip_components = explode('.', $_SERVER['REMOTE_ADDR']);
    1031         if ( count($ip_components)>3 )
    1032         {
    1033           array_pop($ip_components);
    1034         }
    1035         $anonymous_id = implode ('.', $ip_components);
    1036         $query .= ' AND anonymous_id = \''.$anonymous_id . '\'';
    1037       }
    1038 
    1039       $result = pwg_query($query);
    1040       if (mysql_num_rows($result) > 0)
    1041       {
    1042         $row = mysql_fetch_array($result);
    1043         $sentence = $lang['already_rated'];
    1044         $sentence.= ' ('.$row['rate'].'). ';
    1045         $sentence.= $lang['update_rate'];
    1046       }
    1047       else
    1048       {
    1049         $sentence = $lang['never_rated'].'. '.$lang['Rate'];
    1050       }
    1051     }
    1052     else
    1053     {
    1054       $sentence = $lang['never_rated'].'. '.$lang['Rate'];
    1055     }
    1056     $template->assign_block_vars(
    1057       'rate',
    1058       array(
    1059         'CONTENT' => $value,
    1060         'SENTENCE' => $sentence
    1061         ));
    1062 
    1063     $template->assign_block_vars('info_rate', array('CONTENT' => $value));
    1064 
    1065     $template->assign_vars(
    1066       array(
    1067         'INFO_RATE' => $value
    1068         )
    1069       );
    1070 
    1071     foreach ($rate_items as $num => $mark)
    1072     {
    1073       if ($num > 0)
    1074       {
    1075         $separator = '|';
    1076       }
    1077       else
    1078       {
    1079         $separator = '';
    1080       }
    1081 
    1082       $url = PHPWG_ROOT_PATH.'picture.php';
    1083       $url.= get_query_string_diff(array('add_fav'));
    1084       $url.= '&amp;rate='.$mark;
    1085 
    1086       $template->assign_block_vars(
    1087         'rate.rate_option',
    1088         array(
    1089           'OPTION' => $mark,
    1090           'URL' => $url,
    1091           'SEPARATOR' => $separator
    1092           ));
    1093     }
    1094   }
    1095 }
    1096 
    1097 //---------------------------------------------------- users's comments display
    1098 
    1099 // the picture is commentable if it belongs at least to one category which
    1100 // is commentable
    1101 $page['show_comments'] = false;
    1102 foreach ($related_categories as $category)
    1103 {
    1104   if ($category['commentable'] == 'true')
    1105   {
    1106     $page['show_comments'] = true;
    1107   }
    1108 }
    1109 
    1110 if ($page['show_comments'])
    1111 {
    1112   // number of comment for this picture
    1113   $query = 'SELECT COUNT(*) AS nb_comments';
    1114   $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
    1115   $query.= " AND validated = 'true'";
    1116   $query.= ';';
    1117   $row = mysql_fetch_array( pwg_query( $query ) );
    1118 
    1119   // navigation bar creation
    1120   $url = PHPWG_ROOT_PATH.'picture.php';
    1121   $url.= get_query_string_diff(array('add_fav','start'));
    1122 
    1123   if (!isset( $_GET['start'] )
    1124       or !is_numeric( $_GET['start'] )
    1125       or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) )
    1126   {
    1127     $page['start'] = 0;
    1128   }
    1129   else
    1130   {
    1131     $page['start'] = $_GET['start'];
    1132   }
    1133   $page['navigation_bar'] = create_navigation_bar( $url, $row['nb_comments'],
    1134                                                    $page['start'],
    1135                                                    $conf['nb_comment_page'],
    1136                                                    '' );
    1137   $template->assign_block_vars('comments', array(
    1138     'NB_COMMENT'=>$row['nb_comments'],
    1139     'NAV_BAR'=>$page['navigation_bar']));
    1140 
    1141   if ($row['nb_comments']>0)
    1142   {
    1143     $query = 'SELECT id,author,date,image_id,content';
    1144     $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$_GET['image_id'];
    1145     $query.= " AND validated = 'true'";
    1146     $query.= ' ORDER BY date ASC';
    1147     $query.= ' LIMIT '.$page['start'].', '.$conf['nb_comment_page'].';';
    1148     $result = pwg_query( $query );
    1149 
    1150     while ( $row = mysql_fetch_array( $result ) )
    1151     {
    1152       $template->assign_block_vars(
    1153         'comments.comment',
    1154         array(
    1155           'COMMENT_AUTHOR'=>empty($row['author'])?$lang['guest']:$row['author'],
    1156           'COMMENT_DATE'=>format_date($row['date'], 'mysql_datetime', true),
    1157     'COMMENT'=>parse_comment_content($row['content'])
    1158     ));
    1159 
    1160       if ( is_admin() )
    1161       {
    1162         $template->assign_block_vars(
    1163           'comments.comment.delete',
    1164           array('U_COMMENT_DELETE'=> $url.'&amp;del='.$row['id']
    1165             ));
    1166       }
    1167     }
    1168   }
    1169 
    1170   if (!$user['is_the_guest']
    1171       or ($user['is_the_guest'] and $conf['comments_forall']))
    1172   {
    1173     $template->assign_block_vars('comments.add_comment', array());
    1174     // display author field if the user is not logged in
    1175     if (!$user['is_the_guest'])
    1176     {
    1177       $template->assign_block_vars(
    1178         'comments.add_comment.author_known',
    1179         array('KNOWN_AUTHOR'=>$user['username'])
    1180         );
    1181     }
    1182     else
    1183     {
    1184       $template->assign_block_vars(
    1185         'comments.add_comment.author_field', array()
    1186         );
    1187     }
    1188   }
    1189 }
     838if (isset($_GET['slideshow']))
     839{
     840  if (!is_numeric($_GET['slideshow']))
     841  {
     842    $_GET['slideshow'] = $conf['slideshow_period'];
     843  }
     844
     845  $template->assign_block_vars(
     846    'stop_slideshow',
     847    array(
     848      'U_SLIDESHOW' => $picture['current']['url'],
     849      )
     850    );
     851}
     852
     853// +-----------------------------------------------------------------------+
     854// |                               sub pages                               |
     855// +-----------------------------------------------------------------------+
     856
     857include(PHPWG_ROOT_PATH.'include/picture_rate.inc.php');
     858include(PHPWG_ROOT_PATH.'include/picture_comment.inc.php');
     859include(PHPWG_ROOT_PATH.'include/picture_metadata.inc.php');
     860
    1190861//------------------------------------------------------------ log informations
    1191862pwg_log( 'picture', $title_img, $picture['current']['file'] );
  • trunk/profile.php

    r1072 r1082  
    159159   
    160160    // redirection
    161     $url = PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING'];
    162     redirect($url);
     161    redirect(make_index_url());
    163162  }
    164163}
     
    222221    'L_RETURN_HINT' =>  $lang['home_hint'],
    223222
    224     'U_RETURN' => PHPWG_ROOT_PATH.'category.php',
     223    'U_RETURN' => make_index_url(),
    225224   
    226225    'F_ACTION'=>$url_action,
  • trunk/random.php

    r1072 r1082  
    2929// |                          define and include                           |
    3030// +-----------------------------------------------------------------------+
     31
    3132define('PHPWG_ROOT_PATH','./');
    3233include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
     
    4142// +-----------------------------------------------------------------------+
    4243
    43 // we must not show pictures of a forbidden category
    44 $where = '';
    45 if ( $user['forbidden_categories'] != '' )
    46 {
    47   $where = 'WHERE category_id NOT IN ('.$user['forbidden_categories'].')';
    48 }
    49 
    5044$query = '
    5145SELECT DISTINCT(id)
    5246  FROM '.IMAGES_TABLE.'
    5347    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS ic ON id = ic.image_id
    54   '.$where.'
     48  '.(
     49    $user['forbidden_categories'] != ''
     50      ? 'WHERE category_id NOT IN ('.$user['forbidden_categories'].')'
     51      : ''
     52    ).'
    5553  ORDER BY RAND(NOW())
    5654  LIMIT 0, '.$conf['top_number'].'
    5755;';
    58 $result = pwg_query($query);
    59 $ids = array();
    60 while ($row = mysql_fetch_array($result))
    61 {
    62   array_push($ids, $row['id']);
    63 }
     56
    6457// +-----------------------------------------------------------------------+
    6558// |                                redirect                               |
    6659// +-----------------------------------------------------------------------+
    67 $url = PHPWG_ROOT_PATH.'category.php?cat=list&amp;list='.implode(',', $ids);
    68 redirect($url);
     60
     61redirect(make_index_URL(array('list' => array_from_query($query, 'id'))));
    6962?>
  • trunk/register.php

    r1068 r1082  
    5050    $user_id = get_userid($_POST['login']);
    5151    log_user( $user_id, false);
    52     redirect('category.php');
     52    redirect(make_index_url());
    5353  }
    5454}
     
    7575  'L_EMAIL' => $lang['mail_address'],
    7676
    77   'U_HOME' => PHPWG_ROOT_PATH.'category.php',
     77  'U_HOME' => make_index_url(),
    7878
    7979  'F_ACTION' => 'register.php',
  • trunk/search.php

    r1072 r1082  
    143143if (isset($_POST['submit']) and count($errors) == 0)
    144144{
    145   $url = 'category.php?cat=search&search='.$search_id;
    146   redirect($url);
     145  redirect(
     146    make_index_url(
     147      array(
     148        'section' => 'search',
     149        'search'  => $search_id,
     150        )
     151      )
     152    );
    147153}
    148154//----------------------------------------------------- template initialization
     
    194200  'S_SEARCH_ACTION' => 'search.php',
    195201  'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=search',
    196   'U_HOME' => 'category.php'
     202  'U_HOME' => make_index_url(),
    197203  )
    198204);
  • trunk/upload.php

    r1058 r1082  
    126126  $page['cat_name']       = $result['name'];
    127127  $page['cat_uploadable'] = $result['uploadable'];
    128   if ( url_is_remote($page['cat_dir']) or !$page['cat_uploadable'])
    129   {
    130     echo '<div style="text-align:center;">'.$lang['upload_forbidden'].'<br />';
    131     echo '<a href="./category.php">';
    132     echo $lang['thumbnails'].'</a></div>';
    133     exit();
     128 
     129  if (url_is_remote($page['cat_dir']) or !$page['cat_uploadable'])
     130  {
     131    die('Fatal: you take a wrong way, bye bye');
    134132  }
    135133}
     
    281279$comment = !empty($_POST['comment'])?$_POST['comment']:'';
    282280
    283 $template->assign_vars(array(
    284   'ADVISE_TITLE' => $advise_title,
    285   'NAME' => $username,
    286   'EMAIL' => $mail_address,
    287   'NAME_IMG' => $name,
    288   'AUTHOR_IMG' => $author,
    289   'DATE_IMG' => $date_creation,
    290   'COMMENT_IMG' => $comment,
    291 
    292   'L_TITLE' => $lang['upload_title'],
    293   'L_USERNAME' => $lang['upload_username'],
    294   'L_EMAIL' =>  $lang['mail_address'],
    295   'L_NAME_IMG' =>  $lang['upload_name'],
    296   'L_SUBMIT' =>  $lang['submit'],
    297   'L_AUTHOR' =>  $lang['upload_author'],
    298   'L_CREATION_DATE' =>  $lang['upload_creation_date'],
    299   'L_COMMENT' =>  $lang['comment'],
    300   'L_RETURN' =>  $lang['home'],
    301   'L_RETURN_HINT' =>  $lang['home_hint'],
    302   'L_UPLOAD_DONE' =>  $lang['upload_successful'],
    303   'L_MANDATORY' =>  $lang['mandatory'],
    304        
    305   'F_ACTION' => $u_form,
    306 
    307   'U_RETURN' => PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING']
    308   ));
     281$template->assign_vars(
     282  array(
     283    'ADVISE_TITLE' => $advise_title,
     284    'NAME' => $username,
     285    'EMAIL' => $mail_address,
     286    'NAME_IMG' => $name,
     287    'AUTHOR_IMG' => $author,
     288    'DATE_IMG' => $date_creation,
     289    'COMMENT_IMG' => $comment,
     290   
     291    'L_TITLE' => $lang['upload_title'],
     292    'L_USERNAME' => $lang['upload_username'],
     293    'L_EMAIL' =>  $lang['mail_address'],
     294    'L_NAME_IMG' =>  $lang['upload_name'],
     295    'L_SUBMIT' =>  $lang['submit'],
     296    'L_AUTHOR' =>  $lang['upload_author'],
     297    'L_CREATION_DATE' =>  $lang['upload_creation_date'],
     298    'L_COMMENT' =>  $lang['comment'],
     299    'L_RETURN' =>  $lang['home'],
     300    'L_RETURN_HINT' =>  $lang['home_hint'],
     301    'L_UPLOAD_DONE' =>  $lang['upload_successful'],
     302    'L_MANDATORY' =>  $lang['mandatory'],
     303   
     304    'F_ACTION' => $u_form,
     305
     306    'U_RETURN' => make_index_url(array('category' => $page['cat'])),
     307    )
     308  );
    309309 
    310310if ( !$page['upload_successful'] )
Note: See TracChangeset for help on using the changeset viewer.