Index: /trunk/include/section_init.inc.php
===================================================================
--- /trunk/include/section_init.inc.php	(revision 20452)
+++ /trunk/include/section_init.inc.php	(revision 20453)
@@ -84,9 +84,16 @@
 
 $next_token = 0;
-if (script_basename() == 'picture') // basename without file extention
-{ // the first token must be the identifier for the picture
+
+// +-----------------------------------------------------------------------+
+// |                             picture page                              |
+// +-----------------------------------------------------------------------+
+// the first token must be the identifier for the picture
+if (script_basename() == 'picture')
+{
+  // url compatibility with versions below 1.6
   if ( isset($_GET['image_id'])
-       and isset($_GET['cat']) and is_numeric($_GET['cat']) )
-  {// url compatibility with versions below 1.6
+       and isset($_GET['cat']) 
+       and is_numeric($_GET['cat']) )
+  {
     $url = make_picture_url( array(
         'section' => 'categories',
@@ -96,4 +103,5 @@
     redirect($url);
   }
+  
   $token = $tokens[$next_token];
   $next_token++;
@@ -132,4 +140,5 @@
 }
 
+
 $page = array_merge( $page, parse_section_url( $tokens, $next_token) );
 
@@ -144,6 +153,6 @@
     case 'index':
     {
-      // No section defined, go to selected url
-      if (!empty($conf['random_index_redirect']) and empty($tokens[$next_token]) )
+      // No section defined, go to random url
+      if ( !empty($conf['random_index_redirect']) and empty($tokens[$next_token]) )
       {
         $random_index_redirect = array();
@@ -170,8 +179,10 @@
 
 $page = array_merge( $page, parse_well_known_params_url( $tokens, $next_token) );
+
+//access a picture only by id, file or id-file without given section
 if ( script_basename()=='picture' and 'categories'==$page['section'] and
       !isset($page['category']) and !isset($page['chronology_field']) )
-{ //access a picture only by id, file or id-file without given section
-  $page['flat']=true;
+{
+  $page['flat'] = true;
 }
 
@@ -202,10 +213,9 @@
   {
     $conf['order_by'] = str_replace(
-      'ORDER BY ',
-      'ORDER BY '.$orders[$image_order_id][1].',',
-      $conf['order_by']
-    );
+        'ORDER BY ',
+        'ORDER BY '.$orders[$image_order_id][1].',',
+        $conf['order_by']
+        );
     $page['super_order_by'] = true;
-
   }
   else
@@ -217,9 +227,8 @@
 
 $forbidden = get_sql_condition_FandF(
-      array
-        (
-          'forbidden_categories' => 'category_id',
-          'visible_categories' => 'category_id',
-          'visible_images' => 'id'
+      array(
+        'forbidden_categories' => 'category_id',
+        'visible_categories' => 'category_id',
+        'visible_images' => 'id'
         ),
       'AND'
@@ -234,25 +243,25 @@
   {
     $page = array_merge(
-      $page,
-      array(
-        'comment'           =>
-            trigger_event(
-              'render_category_description',
-              $page['category']['comment'],
-              'main_page_category_description'
+      $page, 
+      array(
+        'comment' => trigger_event(
+            'render_category_description',
+            $page['category']['comment'],
+            'main_page_category_description'
             ),
-        'title'             => get_cat_display_name($page['category']['upper_names'], '', false),
+        'title'   => get_cat_display_name($page['category']['upper_names'], '', false),
         )
       );
   }
   else
+  {
     $page['title'] = ''; // will be set later
-
-    
+  }
+
   // GET IMAGES LIST
   if
     (
       $page['startcat'] == 0 and
-      (!isset($page['chronology_field'])) and
+      (!isset($page['chronology_field'])) and // otherwise the calendar will requery all subitems
       (
         (isset($page['category'])) or
@@ -266,8 +275,10 @@
     }
 
+    // flat categories mode
     if (isset($page['flat']))
-    {// flat categories mode
+    {
+      // get all allowed sub-categories
       if ( isset($page['category']) )
-      { // get all allowed sub-categories
+      {
         $query = '
 SELECT id
@@ -276,11 +287,11 @@
     uppercats LIKE \''.$page['category']['uppercats'].',%\' '
     .get_sql_condition_FandF(
-      array
-        (
+        array(
           'forbidden_categories' => 'id',
           'visible_categories' => 'id',
-        ),
-      "\n  AND"
-          );
+          ),
+        "\n  AND"
+        );
+        
         $subcat_ids = array_from_query($query, 'id');
         $subcat_ids[] = $page['category']['id'];
@@ -298,10 +309,11 @@
       }
     }
+    // normal mode
     else
-    {// Normal mode
+    {
       $where_sql = 'category_id = '.$page['category']['id'];
     }
 
-    // Main query
+    // main query
     $query = '
 SELECT DISTINCT(image_id)
@@ -315,5 +327,5 @@
 
     $page['items'] = array_from_query($query, 'image_id');
-  } //otherwise the calendar will requery all subitems
+  }
 }
 // special sections
@@ -344,11 +356,12 @@
 // |                           search section                              |
 // +-----------------------------------------------------------------------+
-  if ($page['section'] == 'search')
+  else if ($page['section'] == 'search')
   {
     include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' );
 
     $search_result = get_search_results($page['search'], @$page['super_order_by'] );
+    //save the details of the query search
     if ( isset($search_result['qs']) )
-    {//save the details of the query search
+    {
       $page['qsearch_details'] = $search_result['qs'];
     }
@@ -359,5 +372,5 @@
         'items' => $search_result['items'],
         'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
-                  .l10n('Search results').'</a>',
+                    .l10n('Search results').'</a>',
         )
       );
@@ -393,32 +406,30 @@
     INNER JOIN '.IMAGES_TABLE.' ON image_id = id
   WHERE user_id = '.$user['id'].'
-'.get_sql_condition_FandF
-  (
-    array
-      (
+'.get_sql_condition_FandF(
+      array(
         'visible_images' => 'id'
-      ),
-    'AND'
-  ).'
+        ),
+      'AND'
+      ).'
   '.$conf['order_by'].'
 ;';
       $page = array_merge(
-	$page,
-	array(
-	  'items' => array_from_query($query, 'image_id'),
-         )
-      );
+        $page,
+        array(
+          'items' => array_from_query($query, 'image_id'),
+          )
+        );
 
       if (count($page['items'])>0)
       {
-	$template->assign(
-	  'favorite',
-	  array(
-	    'U_FAVORITE'    => add_url_params(
-	      make_index_url( array('section'=>'favorites') ),
-	      array('action'=>'remove_all_from_favorites')
-	       ),
-	     )
-           );
+        $template->assign(
+            'favorite',
+            array(
+              'U_FAVORITE' => add_url_params(
+                  make_index_url( array('section'=>'favorites') ),
+                  array('action'=>'remove_all_from_favorites')
+                  ),
+              )
+            );
       }
     }
@@ -432,8 +443,8 @@
     {
       $conf['order_by'] = str_replace(
-        'ORDER BY ',
-        'ORDER BY date_available DESC,',
-        $conf['order_by']
-        );
+          'ORDER BY ',
+          'ORDER BY date_available DESC,',
+          $conf['order_by']
+          );
     }
 
@@ -452,5 +463,5 @@
       array(
         'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
-                  .l10n('Recent photos').'</a>',
+                    .l10n('Recent photos').'</a>',
         'items' => array_from_query($query, 'id'),
         )
@@ -476,4 +487,5 @@
     $page['super_order_by'] = true;
     $conf['order_by'] = ' ORDER BY hit DESC, id DESC';
+    
     $query = '
 SELECT DISTINCT(id)
@@ -490,5 +502,5 @@
       array(
         'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
-                  .$conf['top_number'].' '.l10n('Most visited').'</a>',
+                    .$conf['top_number'].' '.l10n('Most visited').'</a>',
         'items' => array_from_query($query, 'id'),
         )
@@ -516,5 +528,5 @@
       array(
         'title' => '<a href="'.duplicate_index_url(array('start'=>0)).'">'
-                  .$conf['top_number'].' '.l10n('Best rated').'</a>',
+                    .$conf['top_number'].' '.l10n('Best rated').'</a>',
         'items' => array_from_query($query, 'id'),
         )
@@ -549,5 +561,4 @@
 // |                             chronology                                |
 // +-----------------------------------------------------------------------+
-
 if (isset($page['chronology_field']))
 {
@@ -586,5 +597,5 @@
   $page['meta_robots']=array('noindex'=>1, 'nofollow'=>1);
 }
-elseif ('tags' == $page['section'])
+elseif ('tags'==$page['section'])
 {
   if ( count($page['tag_ids'])>1 )
@@ -628,8 +639,6 @@
   if ($need_redirect)
   {
-    $redirect_url = ( script_basename()=='picture'
-        ? duplicate_picture_url()
-          : duplicate_index_url()
-      );
+    $redirect_url = script_basename()=='picture' ? duplicate_picture_url() : duplicate_index_url();
+    
     if (!headers_sent())
     { // this is a permanent redirection
