Ignore:
Timestamp:
Apr 27, 2007, 2:22:41 AM (18 years ago)
Author:
rvelices
Message:

merge revisions 1980 and 1981 from trunk to branch-1_7
put some code from the huge section_init to 2 functions

  • parse_section_url does the exact opposite of make_section_in_url
  • parse_well_known_params_url does the exact opposite of add_well_known_params_in_url

maintenance on categories also invalidates the user cache

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/branch-1_7/include/section_init.inc.php

    r1955 r1982  
    123123}
    124124
    125 if (0 === strpos(@$tokens[$next_token], 'categor'))
     125$page = array_merge( $page, parse_section_url( $tokens, $next_token) );
     126if ( !isset($page['section']) )
    126127{
    127128  $page['section'] = 'categories';
    128   $next_token++;
    129 
    130   if (isset($tokens[$next_token]) )
    131   {
    132     if (preg_match('/^(\d+)(?:-(.+))?$/', $tokens[$next_token], $matches))
    133     {
    134       if ( isset($matches[2]) )
    135         $page['hit_by']['cat_url_name'] = $matches[2];
    136       $page['category'] = $matches[1];
    137       $next_token++;
    138     }
    139     else
    140     {
    141       if ( strpos($tokens[$next_token], 'created-')!==0
    142           and strpos($tokens[$next_token], 'posted-')!==0
    143           and strpos($tokens[$next_token], 'start-')!==0
    144           and $tokens[$next_token] != 'flat')
    145       {// try a permalink
    146         $cat_id = get_cat_id_from_permalink($tokens[$next_token]);
    147         if ( !isset($cat_id) )
    148         {//try old permalink
    149           $cat_id = get_cat_id_from_old_permalink($tokens[$next_token], true);
    150         }
    151         if ( isset($cat_id) )
    152         {
    153           $page['category'] = $cat_id;
    154           $page['hit_by']['cat_permalink'] = $tokens[$next_token];
    155         }
    156         else
    157         {
    158           page_not_found('Permalink for album not found');
    159         }
    160         unset($cat_id);
    161         $next_token++;
    162       }
    163       elseif ( script_basename()=='picture' )
    164       { //access a picture only by id, file or id-file without given section
    165         $page['flat']=true;
    166       }
    167     }
    168   }
    169   elseif ( script_basename()=='picture' )
    170   { //access a picture only by id, file or id-file without given section
    171     $page['flat']=true;
    172   }
    173 }
    174 else if (0 === strpos(@$tokens[$next_token], 'tag'))
    175 {
    176   $page['section'] = 'tags';
    177   $page['tags'] = array();
    178 
    179   $next_token++;
    180   $i = $next_token;
    181 
    182   $requested_tag_ids = array();
    183   $requested_tag_url_names = array();
    184 
    185   while (isset($tokens[$i]))
    186   {
    187     if ( preg_match('/^(created-|posted-|start-(\d)+)/', $tokens[$i]) )
     129
     130  switch (script_basename())
     131  {
     132    case 'picture':
    188133      break;
    189 
    190     if ( preg_match('/^(\d+)(?:-(.*))?/', $tokens[$i], $matches) )
    191     {
    192       array_push($requested_tag_ids, $matches[1]);
    193     }
    194     else
    195     {
    196       array_push($requested_tag_url_names, $tokens[$i]);
    197     }
    198     $i++;
    199   }
    200   $next_token = $i;
    201 
    202   if ( empty($requested_tag_ids) && empty($requested_tag_url_names) )
    203   {
    204     bad_request('at least one tag required');
    205   }
    206 
    207   $page['tags'] = find_tags($requested_tag_ids, $requested_tag_url_names);
    208   if ( empty($page['tags']) )
    209   {
    210     page_not_found('Requested tag does not exist', get_root_url().'tags.php' );
    211   }
    212 }
    213 else if (0 === strpos(@$tokens[$next_token], 'fav'))
    214 {
    215   $page['section'] = 'favorites';
    216   $next_token++;
    217 }
    218 else if ('most_visited' == @$tokens[$next_token])
    219 {
    220   $page['section'] = 'most_visited';
    221   $next_token++;
    222 }
    223 else if ('best_rated' == @$tokens[$next_token])
    224 {
    225   $page['section'] = 'best_rated';
    226   $next_token++;
    227 }
    228 else if ('recent_pics' == @$tokens[$next_token])
    229 {
    230   $page['section'] = 'recent_pics';
    231   $next_token++;
    232 }
    233 else if ('recent_cats' == @$tokens[$next_token])
    234 {
    235   $page['section'] = 'recent_cats';
    236   $next_token++;
    237 }
    238 else if ('search' == @$tokens[$next_token])
    239 {
    240   $page['section'] = 'search';
    241   $next_token++;
    242 
    243   preg_match('/(\d+)/', @$tokens[$next_token], $matches);
    244   if (!isset($matches[1]))
    245   {
    246     bad_request('search identifier is missing');
    247   }
    248   $page['search'] = $matches[1];
    249   $next_token++;
    250 }
    251 else if ('list' == @$tokens[$next_token])
    252 {
    253   $page['section'] = 'list';
    254   $next_token++;
    255 
    256   $page['list'] = array();
    257 
    258   // No pictures
    259   if (empty($tokens[$next_token]))
    260   {
    261     // Add dummy element list
    262     array_push($page['list'], -1);
    263   }
    264   // With pictures list
    265   else
    266   {
    267     if (!preg_match('/^\d+(,\d+)*$/', $tokens[$next_token]))
    268     {
    269       bad_request('wrong format on list GET parameter');
    270     }
    271     foreach (explode(',', $tokens[$next_token]) as $image_id)
    272     {
    273       array_push($page['list'], $image_id);
    274     }
    275   }
    276   $next_token++;
    277 }
    278 else
    279 {
    280   $page['section'] = 'categories';
    281 
    282   switch (script_basename())
    283   {
    284     case 'picture':
    285     {
    286       //access a picture only by id, file or id-file without given section
    287       $page['flat'] = true;
    288       break;
    289     }
    290134    case 'index':
    291135    {
     
    314158}
    315159
    316 $i = $next_token;
    317 
    318 while (isset($tokens[$i]))
    319 {
    320   if (preg_match('/^start-(\d+)/', $tokens[$i], $matches))
    321   {
    322     $page['start'] = $matches[1];
    323   }
    324 
    325   if ('categories' == $page['section'] and
    326       'flat' == $tokens[$i] and
     160
     161$page = array_merge( $page, parse_well_known_params_url( $tokens, $next_token) );
     162
     163
     164if ( script_basename()=='picture' and 'categories'==$page['section'] and
    327165      !isset($page['chronology_field']) )
    328   {
    329     // indicate a special list of images
    330     $page['flat'] = true;
    331   }
    332 
    333   if (preg_match('/^(posted|created)/', $tokens[$i] ))
    334   {
    335     $chronology_tokens = explode('-', $tokens[$i] );
    336 
    337     $page['chronology_field'] = $chronology_tokens[0];
    338 
    339     array_shift($chronology_tokens);
    340     $page['chronology_style'] = $chronology_tokens[0];
    341 
    342     array_shift($chronology_tokens);
    343     if ( count($chronology_tokens)>0 )
    344     {
    345       if ('list'==$chronology_tokens[0] or
    346           'calendar'==$chronology_tokens[0])
    347       {
    348         $page['chronology_view'] = $chronology_tokens[0];
    349         array_shift($chronology_tokens);
    350       }
    351       $page['chronology_date'] = $chronology_tokens;
    352     }
    353     unset($page['flat']);
    354   }
    355 
    356   $i++;
     166{ //access a picture only by id, file or id-file without given section
     167  $page['flat']=true;
    357168}
    358169
     
    391202  if (isset($page['category']))
    392203  {
    393     $result = get_cat_info($page['category']);
    394     if (empty($result))
    395     {
    396       page_not_found('Requested category does not exist' );
    397     }
    398 
    399     $page = array_merge(
    400       $page,
    401       array(
    402         'comment'            => $result['comment'],
    403         'category'          => $result,
     204    $page = array_merge(
     205      $page,
     206      array(
     207        'comment'           => $page['category']['comment'],
    404208        'title'             =>
    405           get_cat_display_name($result['upper_names'], '', false),
     209          get_cat_display_name($page['category']['upper_names'], '', false),
    406210        )
    407211      );
Note: See TracChangeset for help on using the changeset viewer.