Index: /trunk/admin/include/functions.php
===================================================================
--- /trunk/admin/include/functions.php	(revision 605)
+++ /trunk/admin/include/functions.php	(revision 606)
@@ -785,3 +785,50 @@
   }
 }
+
+/**
+ * inserts multiple lines in a table
+ *
+ * @param string table_name
+ * @param array dbields
+ * @param array inserts
+ * @return void
+ */
+function mass_inserts($table_name, $dbfields, $inserts)
+{
+  // inserts all found categories
+  $query = '
+INSERT INTO '.$table_name.'
+  ('.implode(',', $dbfields).')
+   VALUES';
+  foreach ($inserts as $insert_id => $insert)
+  {
+    $query.= '
+  ';
+    if ($insert_id > 0)
+    {
+      $query.= ',';
+    }
+    $query.= '(';
+    foreach ($dbfields as $field_id => $dbfield)
+    {
+      if ($field_id > 0)
+      {
+        $query.= ',';
+      }
+      
+      if (!isset($insert[$dbfield]) or $insert[$dbfield] == '')
+      {
+        $query.= 'NULL';
+      }
+      else
+      {
+        $query.= "'".$insert[$dbfield]."'";
+      }
+    }
+    $query.=')';
+  }
+  $query.= '
+;';
+  pwg_query($query);
+}
 ?>
Index: /trunk/admin/infos_images.php
===================================================================
--- /trunk/admin/infos_images.php	(revision 605)
+++ /trunk/admin/infos_images.php	(revision 606)
@@ -320,7 +320,5 @@
   while ($row = mysql_fetch_array($result))
   {
-    $thumbnail_url = get_thumbnail_src($row['file'],
-                                       $row['storage_category_id'],
-                                       @$row['tn_ext']);
+    $thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
 
     $template->assign_block_vars(
Index: /trunk/admin/picture_modify.php
===================================================================
--- /trunk/admin/picture_modify.php	(revision 605)
+++ /trunk/admin/picture_modify.php	(revision 606)
@@ -200,7 +200,5 @@
 $dir_path = get_cat_display_name($current_category['name'], '-&gt;', '');
 
-$thumbnail_url = get_thumbnail_src($row['file'],
-                                   $row['storage_category_id'],
-                                   @$row['tn_ext']);
+$thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
 
 $url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id'];
Index: /trunk/admin/remote_site.php
===================================================================
--- /trunk/admin/remote_site.php	(revision 605)
+++ /trunk/admin/remote_site.php	(revision 606)
@@ -110,51 +110,4 @@
 
   return $database_dirs;
-}
-
-/**
- * inserts multiple lines in a table
- *
- * @param string table_name
- * @param array dbields
- * @param array inserts
- * @return void
- */
-function mass_inserts($table_name, $dbfields, $inserts)
-{
-  // inserts all found categories
-  $query = '
-INSERT INTO '.$table_name.'
-  ('.implode(',', $dbfields).')
-   VALUES';
-  foreach ($inserts as $insert_id => $insert)
-  {
-    $query.= '
-  ';
-    if ($insert_id > 0)
-    {
-      $query.= ',';
-    }
-    $query.= '(';
-    foreach ($dbfields as $field_id => $dbfield)
-    {
-      if ($field_id > 0)
-      {
-        $query.= ',';
-      }
-      
-      if (!isset($insert[$dbfield]) or $insert[$dbfield] == '')
-      {
-        $query.= 'NULL';
-      }
-      else
-      {
-        $query.= "'".$insert[$dbfield]."'";
-      }
-    }
-    $query.=')';
-  }
-  $query.= '
-;';
-  pwg_query($query);
 }
 
@@ -419,5 +372,6 @@
                              'keywords',
                              'name',
-                             'comment');
+                             'comment',
+                             'path');
       foreach ($optional_atts as $att)
       {
@@ -435,5 +389,5 @@
     $dbfields = array('file','storage_category_id','date_available','tn_ext',
                       'filesize','width','height','date_creation','author',
-                      'keywords','name','comment');
+                      'keywords','name','comment','path');
     mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
     $counts{'new_elements'}+= count($inserts);
Index: /trunk/admin/update.php
===================================================================
--- /trunk/admin/update.php	(revision 605)
+++ /trunk/admin/update.php	(revision 606)
@@ -32,5 +32,5 @@
 include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
 
-define('CURRENT_DATE', "'".date('Y-m-d')."'");
+define('CURRENT_DATE', date('Y-m-d'));
 // +-----------------------------------------------------------------------+
 // |                              functions                                |
@@ -408,8 +408,9 @@
         {
           $insert = array();
-          $insert['file'] = "'".$unregistered_element."'";
+          $insert['file'] = $unregistered_element;
           $insert['storage_category_id'] = $category_id;
           $insert['date_available'] = CURRENT_DATE;
-          $insert['tn_ext'] = "'".$tn_ext."'";
+          $insert['tn_ext'] = $tn_ext;
+          $insert['path'] = $dir.$unregistered_element;
 
           $counts['new_elements']++;
@@ -447,14 +448,15 @@
 
         $insert = array();
-        $insert['file'] = "'".$unregistered_element."'";
+        $insert['file'] = $unregistered_element;
+        $insert['path'] = $dir.$unregistered_element;
         $insert['storage_category_id'] = $category_id;
         $insert['date_available'] = CURRENT_DATE;
         if ( $tn_ext != '' )
         {
-          $insert['tn_ext'] = "'".$tn_ext."'";
+          $insert['tn_ext'] = $tn_ext;
         }
         if ( $representative_ext != '' )
         {
-          $insert['representative_ext'] = "'".$representative_ext."'";
+          $insert['representative_ext'] = $representative_ext;
         }
 
@@ -476,42 +478,7 @@
     $dbfields = array(
       'file','storage_category_id','date_available','tn_ext'
-      ,'representative_ext'
+      ,'representative_ext','path'
       );
-    $query = '
-INSERT INTO '.IMAGES_TABLE.'
-  ('.implode(',', $dbfields).')
-   VALUES
-   ';
-    foreach ($inserts as $insert_id => $insert)
-    {
-      $query.= '
-';
-      if ($insert_id > 0)
-      {
-        $query.= ',';
-      }
-      $query.= '(';
-      foreach ($dbfields as $field_id => $dbfield)
-      {
-        if ($field_id > 0)
-        {
-          $query.= ',';
-        }
-        
-        if (!isset($insert[$dbfield]) or $insert[$dbfield] == '')
-        {
-          $query.= 'NULL';
-        }
-        else
-        {
-          $query.= $insert[$dbfield];
-        }
-      }
-      $query.=')';
-    }
-    $query.= '
-;';
-
-    pwg_query($query);
+    mass_inserts(IMAGES_TABLE, $dbfields, $inserts);
 
     // what are the ids of the pictures in the $category_id ?
Index: /trunk/comments.php
===================================================================
--- /trunk/comments.php	(revision 605)
+++ /trunk/comments.php	(revision 606)
@@ -141,5 +141,5 @@
   // link to the full size picture
   $query = '
-SELECT name,file,storage_category_id as cat_id,tn_ext
+SELECT name,file,storage_category_id as cat_id,tn_ext,path
   FROM '.IMAGES_TABLE.'
   WHERE id = '.$row['image_id'].'
@@ -167,7 +167,5 @@
   $name.= ' [ '.$subrow['file'].' ]';
   // source of the thumbnail picture
-  $thumbnail_src = get_thumbnail_src($subrow['file'],
-                                     $subrow['cat_id'],
-                                     @$subrow['tn_ext']);
+  $thumbnail_src = get_thumbnail_src($subrow['path'], @$subrow['tn_ext']);
   // link to the full size picture
   $url = PHPWG_ROOT_PATH.'picture.php?cat='.$category_id;
Index: /trunk/include/category_calendar.inc.php
===================================================================
--- /trunk/include/category_calendar.inc.php	(revision 605)
+++ /trunk/include/category_calendar.inc.php	(revision 606)
@@ -220,5 +220,5 @@
   {
     $query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
+SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
   '.$page['where'].'
@@ -230,7 +230,5 @@
     $row = mysql_fetch_array(pwg_query($query));
     
-    $thumbnail_src = get_thumbnail_src($row['file'],
-                                       $row['storage_category_id'],
-                                       @$row['tn_ext']);
+    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
     
     $name = $calendar_year.' ('.$nb_pics.')';
@@ -267,5 +265,5 @@
   {
     $query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
+SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
   '.$page['where'].'
@@ -278,7 +276,5 @@
     $row = mysql_fetch_array(pwg_query($query));
     
-    $thumbnail_src = get_thumbnail_src($row['file'],
-                                       $row['storage_category_id'],
-                                       @$row['tn_ext']);
+    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
     
     $name = $lang['month'][$calendar_month];
@@ -323,5 +319,5 @@
   {
     $query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
+SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
   '.$page['where'].'
@@ -333,7 +329,5 @@
     $row = mysql_fetch_array(pwg_query($query));
     
-    $thumbnail_src = get_thumbnail_src($row['file'],
-                                       $row['storage_category_id'],
-                                       @$row['tn_ext']);
+    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
 
     list($year,$month,$day) = explode('-', $calendar_day);
@@ -386,5 +380,5 @@
     
     $query = '
-SELECT file,tn_ext,'.$conf['calendar_datefield'].',storage_category_id
+SELECT file,tn_ext,'.$conf['calendar_datefield'].',path
   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
   '.$page['where'].'
@@ -402,7 +396,5 @@
     $row = mysql_fetch_array(pwg_query($query));
     
-    $thumbnail_src = get_thumbnail_src($row['file'],
-                                       $row['storage_category_id'],
-                                       @$row['tn_ext']);
+    $thumbnail_src = get_thumbnail_src($row['path'], @$row['tn_ext']);
     
     $thumbnail_title = $lang['calendar_picture_hint'].$name;
Index: /trunk/include/category_default.inc.php
===================================================================
--- /trunk/include/category_default.inc.php	(revision 605)
+++ /trunk/include/category_default.inc.php	(revision 606)
@@ -39,5 +39,5 @@
   
 $query = '
-SELECT DISTINCT(id),file,date_available,category_id
+SELECT DISTINCT(id),path,file,date_available,category_id
        ,tn_ext,name,filesize,storage_category_id,average_rate
   FROM '.IMAGES_TABLE.' AS i
@@ -81,7 +81,5 @@
   }
   
-  $thumbnail_url = get_thumbnail_src($row['file'],
-                                     $row['storage_category_id'],
-                                     @$row['tn_ext']);
+  $thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']);
   
   // message in title for the thumbnail
Index: /trunk/include/category_recent_cats.inc.php
===================================================================
--- /trunk/include/category_recent_cats.inc.php	(revision 605)
+++ /trunk/include/category_recent_cats.inc.php	(revision 606)
@@ -67,5 +67,5 @@
   
   $query = '
-SELECT id,file,tn_ext,storage_category_id
+SELECT path,file,tn_ext
   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
   WHERE category_id = '.$row['category_id'].'
@@ -76,9 +76,7 @@
   LIMIT 0,1
 ;';
-  $subrow = mysql_fetch_array( pwg_query( $query ) );
+  $subrow = mysql_fetch_array(pwg_query($query));
 
-  $thumbnail_src = get_thumbnail_src($subrow['file'],
-                                     $subrow['storage_category_id'],
-                                     @$subrow['tn_ext']);
+  $thumbnail_src = get_thumbnail_src($subrow['path'], @$subrow['tn_ext']);
   
   $url_link = PHPWG_ROOT_PATH.'category.php?cat='.$row['category_id'];
Index: /trunk/include/category_subcats.inc.php
===================================================================
--- /trunk/include/category_subcats.inc.php	(revision 605)
+++ /trunk/include/category_subcats.inc.php	(revision 606)
@@ -65,5 +65,5 @@
     
   $query = '
-SELECT file,tn_ext,storage_category_id
+SELECT file,path,tn_ext
   FROM '.IMAGES_TABLE.', '.IMAGE_CATEGORY_TABLE.'
   WHERE category_id = '.$non_empty_id.'
@@ -87,6 +87,5 @@
   $image_row    = mysql_fetch_array($image_result);
 
-  $thumbnail_link = get_thumbnail_src($image_row['file'],
-                                      $image_row['storage_category_id'],
+  $thumbnail_link = get_thumbnail_src($image_row['path'],
                                       @$image_row['tn_ext']);
 
Index: /trunk/include/functions.inc.php
===================================================================
--- /trunk/include/functions.inc.php	(revision 605)
+++ /trunk/include/functions.inc.php	(revision 606)
@@ -571,36 +571,21 @@
  * given element
  *
- * this function could have taken only the element id as parameter but to
- * optimize database access we directly ask file, storage category
- * identifier and extension since when this function is called,
- * PhpWebGallery should have all these infos. No need to retrieve them
- * another time in the database.
- *
  * the returned string can represente the filepath of the thumbnail or the
  * filepath to the corresponding icon for non picture elements
  *
- * complete directories are cached to be used more than once during a page
- * generation (many thumbnails of the same category on the same page)
- *
- * @param string file
- * @param int storage_category_id
+ * @param string path
  * @param string tn_ext
  * @return string
  */
-function get_thumbnail_src($file, $storage_category_id, $tn_ext = '')
-{
-  global $conf, $user, $array_cat_directories;
-  
-  if (!isset($array_cat_directories[$storage_category_id]))
-  {
-    $array_cat_directories[$storage_category_id] =
-      get_complete_dir($storage_category_id);
-  }
-  
+function get_thumbnail_src($path, $tn_ext = '')
+{
+  global $conf, $user;
+
   if ($tn_ext != '')
   {
-    $src = $array_cat_directories[$storage_category_id];
-    $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
-    $src.= get_filename_wo_extension($file);
+    $src = substr_replace(get_filename_wo_extension($path),
+                          '/thumbnail/'.$conf['prefix_thumbnail'],
+                          strrpos($path,'/'),
+                          1);
     $src.= '.'.$tn_ext;
   }
@@ -609,7 +594,7 @@
     $src = PHPWG_ROOT_PATH;
     $src.= 'template/'.$user['template'].'/mimetypes/';
-    $src.= strtolower(get_extension($file)).'.png';
-  }
-
+    $src.= strtolower(get_extension($path)).'.png';
+  }
+  
   return $src;
 }
Index: /trunk/install/dbscheme.txt
===================================================================
--- /trunk/install/dbscheme.txt	(revision 605)
+++ /trunk/install/dbscheme.txt	(revision 606)
@@ -72,4 +72,5 @@
 column:date_metadata_update      table:images         type:date                     nullable:Y
 column:average_rate              table:images         type:float                    nullable:Y length:5,2 signed:N
+column:path                      table:images         type:varchar                  nullable:N length:255 binary:N
 column:user_id                   table:rate           type:smallint                 nullable:N length:5   signed:N
 column:element_id                table:rate           type:mediumint                nullable:N length:8   signed:N
Index: /trunk/install/phpwebgallery_structure.sql
===================================================================
--- /trunk/install/phpwebgallery_structure.sql	(revision 605)
+++ /trunk/install/phpwebgallery_structure.sql	(revision 606)
@@ -141,4 +141,5 @@
   date_metadata_update date default NULL,
   average_rate float(5,2) unsigned default NULL,
+  path varchar(255) NOT NULL default '',
   PRIMARY KEY  (id),
   KEY images_i2 (date_available),
Index: /trunk/picture.php
===================================================================
--- /trunk/picture.php	(revision 605)
+++ /trunk/picture.php	(revision 606)
@@ -143,10 +143,5 @@
   }
   
-  if ( !isset($array_cat_directories[$row['storage_category_id']]))
-  {
-    $array_cat_directories[$row['storage_category_id']] =
-      get_complete_dir( $row['storage_category_id'] );
-  }
-  $cat_directory = $array_cat_directories[$row['storage_category_id']];
+  $cat_directory = dirname($row['path']);
   $file_wo_ext = get_filename_wo_extension($row['file']);
 
@@ -166,5 +161,5 @@
   if ($picture[$i]['is_picture'])
   {
-    $picture[$i]['src'] = $cat_directory.$row['file'];
+    $picture[$i]['src'] = $row['path'];
     // if we are working on the "current" element, we search if there is a
     // high quality picture
@@ -182,10 +177,8 @@
   if (!$picture[$i]['is_picture'])
   {
-    $picture[$i]['download'] = $cat_directory.$row['file'];
-  }
-
-  $picture[$i]['thumbnail'] = get_thumbnail_src($row['file'],
-                                                $row['storage_category_id'],
-                                                @$row['tn_ext']);
+    $picture[$i]['download'] = $row['path'];
+  }
+
+  $picture[$i]['thumbnail'] = get_thumbnail_src($row['path'], @$row['tn_ext']);
   
   if ( !empty( $row['name'] ) )
Index: /trunk/tools/create_listing_file.php
===================================================================
--- /trunk/tools/create_listing_file.php	(revision 605)
+++ /trunk/tools/create_listing_file.php	(revision 606)
@@ -311,5 +311,5 @@
 function get_pictures($dir, $indent)
 {
-  global $conf;
+  global $conf, $page;
   
   // fs means FileSystem : $fs_files contains files in the filesystem found
@@ -322,4 +322,7 @@
 
   $elements = array();
+
+  $print_dir = preg_replace('/^\.\//', '', $dir);
+  $print_dir = preg_replace('/\/*$/', '/', $print_dir);
   
   foreach ($fs_files as $fs_file)
@@ -327,4 +330,5 @@
     $element = array();
     $element['file'] = $fs_file;
+    $element['path'] = $page['url'].$print_dir.$fs_file;
     $element['filesize'] = floor(filesize($dir.'/'.$fs_file) / 1024);
     
@@ -421,5 +425,5 @@
   $attributes = array('file','tn_ext','representative_ext','filesize',
                       'width','height','date_creation','author','keywords',
-                      'name','comment');
+                      'name','comment','path');
   foreach ($elements as $element)
   {
@@ -464,7 +468,7 @@
     $end = strrpos($_SERVER['PHP_SELF'], '/') + 1;
     $local_folder = substr($_SERVER['PHP_SELF'], 0, $end);
-    $url = 'http://'.$_SERVER['HTTP_HOST'].$local_folder;
+    $page['url'] = 'http://'.$_SERVER['HTTP_HOST'].$local_folder;
     
-    $listing.= ' url="'.$url.'"';
+    $listing.= ' url="'.$page['url'].'"';
     $listing.= '/>'."\n";
     
