Changeset 20453


Ignore:
Timestamp:
Jan 29, 2013, 7:46:23 PM (11 years ago)
Author:
mistic100
Message:

some code cleaning

File:
1 edited

Legend:

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

    r19703 r20453  
    8484
    8585$next_token = 0;
    86 if (script_basename() == 'picture') // basename without file extention
    87 { // the first token must be the identifier for the picture
     86
     87// +-----------------------------------------------------------------------+
     88// |                             picture page                              |
     89// +-----------------------------------------------------------------------+
     90// the first token must be the identifier for the picture
     91if (script_basename() == 'picture')
     92{
     93  // url compatibility with versions below 1.6
    8894  if ( isset($_GET['image_id'])
    89        and isset($_GET['cat']) and is_numeric($_GET['cat']) )
    90   {// url compatibility with versions below 1.6
     95       and isset($_GET['cat'])
     96       and is_numeric($_GET['cat']) )
     97  {
    9198    $url = make_picture_url( array(
    9299        'section' => 'categories',
     
    96103    redirect($url);
    97104  }
     105 
    98106  $token = $tokens[$next_token];
    99107  $next_token++;
     
    132140}
    133141
     142
    134143$page = array_merge( $page, parse_section_url( $tokens, $next_token) );
    135144
     
    144153    case 'index':
    145154    {
    146       // No section defined, go to selected url
    147       if (!empty($conf['random_index_redirect']) and empty($tokens[$next_token]) )
     155      // No section defined, go to random url
     156      if ( !empty($conf['random_index_redirect']) and empty($tokens[$next_token]) )
    148157      {
    149158        $random_index_redirect = array();
     
    170179
    171180$page = array_merge( $page, parse_well_known_params_url( $tokens, $next_token) );
     181
     182//access a picture only by id, file or id-file without given section
    172183if ( script_basename()=='picture' and 'categories'==$page['section'] and
    173184      !isset($page['category']) and !isset($page['chronology_field']) )
    174 { //access a picture only by id, file or id-file without given section
    175   $page['flat']=true;
     185{
     186  $page['flat'] = true;
    176187}
    177188
     
    202213  {
    203214    $conf['order_by'] = str_replace(
    204       'ORDER BY ',
    205       'ORDER BY '.$orders[$image_order_id][1].',',
    206       $conf['order_by']
    207     );
     215        'ORDER BY ',
     216        'ORDER BY '.$orders[$image_order_id][1].',',
     217        $conf['order_by']
     218        );
    208219    $page['super_order_by'] = true;
    209 
    210220  }
    211221  else
     
    217227
    218228$forbidden = get_sql_condition_FandF(
    219       array
    220         (
    221           'forbidden_categories' => 'category_id',
    222           'visible_categories' => 'category_id',
    223           'visible_images' => 'id'
     229      array(
     230        'forbidden_categories' => 'category_id',
     231        'visible_categories' => 'category_id',
     232        'visible_images' => 'id'
    224233        ),
    225234      'AND'
     
    234243  {
    235244    $page = array_merge(
    236       $page,
    237       array(
    238         'comment'           =>
    239             trigger_event(
    240               'render_category_description',
    241               $page['category']['comment'],
    242               'main_page_category_description'
     245      $page,
     246      array(
     247        'comment' => trigger_event(
     248            'render_category_description',
     249            $page['category']['comment'],
     250            'main_page_category_description'
    243251            ),
    244         'title'             => get_cat_display_name($page['category']['upper_names'], '', false),
     252        'title'   => get_cat_display_name($page['category']['upper_names'], '', false),
    245253        )
    246254      );
    247255  }
    248256  else
     257  {
    249258    $page['title'] = ''; // will be set later
    250 
    251    
     259  }
     260
    252261  // GET IMAGES LIST
    253262  if
    254263    (
    255264      $page['startcat'] == 0 and
    256       (!isset($page['chronology_field'])) and
     265      (!isset($page['chronology_field'])) and // otherwise the calendar will requery all subitems
    257266      (
    258267        (isset($page['category'])) or
     
    266275    }
    267276
     277    // flat categories mode
    268278    if (isset($page['flat']))
    269     {// flat categories mode
     279    {
     280      // get all allowed sub-categories
    270281      if ( isset($page['category']) )
    271       { // get all allowed sub-categories
     282      {
    272283        $query = '
    273284SELECT id
     
    276287    uppercats LIKE \''.$page['category']['uppercats'].',%\' '
    277288    .get_sql_condition_FandF(
    278       array
    279         (
     289        array(
    280290          'forbidden_categories' => 'id',
    281291          'visible_categories' => 'id',
    282         ),
    283       "\n  AND"
    284           );
     292          ),
     293        "\n  AND"
     294        );
     295       
    285296        $subcat_ids = array_from_query($query, 'id');
    286297        $subcat_ids[] = $page['category']['id'];
     
    298309      }
    299310    }
     311    // normal mode
    300312    else
    301     {// Normal mode
     313    {
    302314      $where_sql = 'category_id = '.$page['category']['id'];
    303315    }
    304316
    305     // Main query
     317    // main query
    306318    $query = '
    307319SELECT DISTINCT(image_id)
     
    315327
    316328    $page['items'] = array_from_query($query, 'image_id');
    317   } //otherwise the calendar will requery all subitems
     329  }
    318330}
    319331// special sections
     
    344356// |                           search section                              |
    345357// +-----------------------------------------------------------------------+
    346   if ($page['section'] == 'search')
     358  else if ($page['section'] == 'search')
    347359  {
    348360    include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' );
    349361
    350362    $search_result = get_search_results($page['search'], @$page['super_order_by'] );
     363    //save the details of the query search
    351364    if ( isset($search_result['qs']) )
    352     {//save the details of the query search
     365    {
    353366      $page['qsearch_details'] = $search_result['qs'];
    354367    }
     
    359372        'items' => $search_result['items'],
    360373        'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
    361                   .l10n('Search results').'</a>',
     374                    .l10n('Search results').'</a>',
    362375        )
    363376      );
     
    393406    INNER JOIN '.IMAGES_TABLE.' ON image_id = id
    394407  WHERE user_id = '.$user['id'].'
    395 '.get_sql_condition_FandF
    396   (
    397     array
    398       (
     408'.get_sql_condition_FandF(
     409      array(
    399410        'visible_images' => 'id'
    400       ),
    401     'AND'
    402   ).'
     411        ),
     412      'AND'
     413      ).'
    403414  '.$conf['order_by'].'
    404415;';
    405416      $page = array_merge(
    406         $page,
    407         array(
    408           'items' => array_from_query($query, 'image_id'),
    409          )
    410       );
     417        $page,
     418        array(
     419          'items' => array_from_query($query, 'image_id'),
     420          )
     421        );
    411422
    412423      if (count($page['items'])>0)
    413424      {
    414         $template->assign(
    415           'favorite',
    416           array(
    417             'U_FAVORITE'    => add_url_params(
    418               make_index_url( array('section'=>'favorites') ),
    419               array('action'=>'remove_all_from_favorites')
    420                ),
    421              )
    422            );
     425        $template->assign(
     426            'favorite',
     427            array(
     428              'U_FAVORITE' => add_url_params(
     429                  make_index_url( array('section'=>'favorites') ),
     430                  array('action'=>'remove_all_from_favorites')
     431                  ),
     432              )
     433            );
    423434      }
    424435    }
     
    432443    {
    433444      $conf['order_by'] = str_replace(
    434         'ORDER BY ',
    435         'ORDER BY date_available DESC,',
    436         $conf['order_by']
    437         );
     445          'ORDER BY ',
     446          'ORDER BY date_available DESC,',
     447          $conf['order_by']
     448          );
    438449    }
    439450
     
    452463      array(
    453464        'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
    454                   .l10n('Recent photos').'</a>',
     465                    .l10n('Recent photos').'</a>',
    455466        'items' => array_from_query($query, 'id'),
    456467        )
     
    476487    $page['super_order_by'] = true;
    477488    $conf['order_by'] = ' ORDER BY hit DESC, id DESC';
     489   
    478490    $query = '
    479491SELECT DISTINCT(id)
     
    490502      array(
    491503        'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
    492                   .$conf['top_number'].' '.l10n('Most visited').'</a>',
     504                    .$conf['top_number'].' '.l10n('Most visited').'</a>',
    493505        'items' => array_from_query($query, 'id'),
    494506        )
     
    516528      array(
    517529        'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
    518                   .$conf['top_number'].' '.l10n('Best rated').'</a>',
     530                    .$conf['top_number'].' '.l10n('Best rated').'</a>',
    519531        'items' => array_from_query($query, 'id'),
    520532        )
     
    549561// |                             chronology                                |
    550562// +-----------------------------------------------------------------------+
    551 
    552563if (isset($page['chronology_field']))
    553564{
     
    586597  $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
    587598}
    588 elseif ('tags' == $page['section'])
     599elseif ('tags'==$page['section'])
    589600{
    590601  if ( count($page['tag_ids'])>1 )
     
    628639  if ($need_redirect)
    629640  {
    630     $redirect_url = ( script_basename()=='picture'
    631         ? duplicate_picture_url()
    632           : duplicate_index_url()
    633       );
     641    $redirect_url = script_basename()=='picture' ? duplicate_picture_url() : duplicate_index_url();
     642   
    634643    if (!headers_sent())
    635644    { // this is a permanent redirection
Note: See TracChangeset for help on using the changeset viewer.