Index: /trunk/i.php
===================================================================
--- /trunk/i.php	(revision 12919)
+++ /trunk/i.php	(revision 12920)
@@ -29,11 +29,4 @@
 defined('PWG_DERIVATIVE_DIR') or define('PWG_DERIVATIVE_DIR', $conf['data_location'].'i/');
 
-function get_moment()
-{
-  $t1 = explode( ' ', microtime() );
-  $t2 = explode( '.', $t1[0] );
-  $t2 = $t1[1].'.'.$t2[1];
-  return $t2;
-}
 function trigger_action() {}
 function get_extension( $filename )
@@ -128,5 +121,5 @@
 {
   $tmp = $step;
-  $step = get_moment();
+  $step = microtime(true);
   return intval(1000*($step - $tmp));
 }
@@ -264,5 +257,5 @@
 
 $page=array();
-$begin = $step = get_moment();
+$begin = $step = microtime(true);
 $timing=array();
 foreach( explode(',','load,rotate,crop,scale,sharpen,watermark,save,send') as $k )
@@ -415,5 +408,6 @@
   basename($page['src_path']), $o_size, $o_size[0]*$o_size[1],
   basename($page['derivative_path']), $d_size, $d_size[0]*$d_size[1],
+  function_exists('memory_get_peak_usage') ? round( memory_get_peak_usage()/(1024*1024), 1) : '',
   time_step($begin),
-  $timing);
+  '|', $timing);
 ?>
Index: /trunk/include/category_cats.inc.php
===================================================================
--- /trunk/include/category_cats.inc.php	(revision 12919)
+++ /trunk/include/category_cats.inc.php	(revision 12920)
@@ -190,5 +190,4 @@
     if ($row['level'] <= $user['level'])
     {
-      $row['tn_src'] = DerivativeImage::thumb_url($row);
       $infos_of_image[$row['id']] = $row;
     }
@@ -237,8 +236,13 @@
     while ($row = pwg_db_fetch_assoc($result))
     {
-      $row['tn_src'] =  DerivativeImage::thumb_url($row);
       $infos_of_image[$row['id']] = $row;
     }
   }
+  
+  foreach ($infos_of_image as &$info)
+  {
+    $info['src_image'] = new SrcImage($info);
+  }
+  unset($info);
 }
 
@@ -312,5 +316,5 @@
         array(
           'ID'    => $category['id'],
-          'TN_SRC'   => $representative_infos['tn_src'],
+          'representative'   => $representative_infos,
           'TN_ALT'   => strip_tags($category['name']),
 
@@ -334,21 +338,4 @@
                 'subcatify_category_description')),
           'NAME'  => $name,
-          
-          // Extra fields for usage in extra themes
-          'FILE_PATH' => $representative_infos['path'],
-          'FILE_POSTED' => $representative_infos['date_available'],
-          'FILE_CREATED' => $representative_infos['date_creation'],
-          'FILE_DESC' => $representative_infos['comment'],
-          'FILE_AUTHOR' => $representative_infos['author'],
-          'FILE_HIT' => $representative_infos['hit'],
-          'FILE_SIZE' => $representative_infos['filesize'],
-          'FILE_WIDTH' => $representative_infos['width'],
-          'FILE_HEIGHT' => $representative_infos['height'],
-          'FILE_METADATE' => $representative_infos['date_metadata_update'],
-          'FILE_HAS_HD' => $representative_infos['has_high'],
-          'FILE_HD_WIDTH' => $representative_infos['high_width'],
-          'FILE_HD_HEIGHT' => $representative_infos['high_height'],
-          'FILE_HD_FILESIZE' => $representative_infos['high_filesize'],
-          'FILE_RATING_SCORE' => $representative_infos['rating_score'],
         );
     if ($conf['index_new_icon'])
@@ -388,6 +375,10 @@
   }
 
+  $derivative_params = trigger_event('get_index_album_derivative_params', ImageStdParams::get_by_type(IMG_SMALL) );
   $tpl_thumbnails_var = trigger_event('loc_end_index_category_thumbnails', $tpl_thumbnails_var, $categories);
-  $template->assign( 'category_thumbnails', $tpl_thumbnails_var);
+  $template->assign( array(
+    'category_thumbnails' => $tpl_thumbnails_var,
+    'derivative_params' => $derivative_params,
+    ) );
 
   $template->assign_var_from_handle('CATEGORIES', 'index_category_thumbnails');
Index: /trunk/include/category_default.inc.php
===================================================================
--- /trunk/include/category_default.inc.php	(revision 12919)
+++ /trunk/include/category_default.inc.php	(revision 12920)
@@ -110,11 +110,13 @@
   }
 
-  $name = get_picture_title($row);
+  $name = render_element_name($row);
+  $desc = render_element_description($row);
 
   $tpl_var = array_merge( $row, array(
     'TN_SRC' => DerivativeImage::thumb_url($row),
     'TN_ALT' => htmlspecialchars(strip_tags($name)),
-    'TN_TITLE' => get_thumbnail_title($row),
+    'TN_TITLE' => get_thumbnail_title($row, $name, $desc),
     'URL' => $url,
+    'DESCRIPTION' => $desc,
     'src_image' => new SrcImage($row),
     ) );
@@ -146,10 +148,9 @@
     }
   }
-
   $tpl_var['NAME'] = $name;
   $tpl_thumbnails_var[] = $tpl_var;
 }
 
-$derivative_params = ImageStdParams::get_by_type( pwg_get_session_var('index_deriv', IMG_THUMB) );
+$derivative_params = trigger_event('get_index_derivative_params', ImageStdParams::get_by_type( pwg_get_session_var('index_deriv', IMG_THUMB) ) );
 
 $template->assign( array(
@@ -162,5 +163,5 @@
 $template->assign_var_from_handle('THUMBNAILS', 'index_thumbnails');
 unset($pictures, $selection, $tpl_thumbnails_var);
-$template->clear_assign( array('thumbnails') );
+$template->clear_assign( array('thumbnails', 'derivative_params') );
 pwg_debug('end include/category_default.inc.php');
 ?>
Index: /trunk/include/common.inc.php
===================================================================
--- /trunk/include/common.inc.php	(revision 12919)
+++ /trunk/include/common.inc.php	(revision 12920)
@@ -25,7 +25,5 @@
 
 // determine the initial instant to indicate the generation time of this page
-$t1 = explode( ' ', microtime() );
-$t2 = explode( '.', $t1[0] );
-$t2 = $t1[1].'.'.$t2[1];
+$t2 = microtime(true);
 
 @set_magic_quotes_runtime(0); // Disable magic_quotes_runtime
@@ -110,5 +108,5 @@
 include(PHPWG_ROOT_PATH . 'include/constants.php');
 include(PHPWG_ROOT_PATH . 'include/functions.inc.php');
-include(PHPWG_ROOT_PATH .'include/template.class.php');
+
 
 // Database connection
Index: /trunk/include/functions.inc.php
===================================================================
--- /trunk/include/functions.inc.php	(revision 12919)
+++ /trunk/include/functions.inc.php	(revision 12920)
@@ -34,4 +34,6 @@
 include_once( PHPWG_ROOT_PATH .'include/derivative_std_params.inc.php');
 include_once( PHPWG_ROOT_PATH .'include/derivative.inc.php');
+require_once( PHPWG_ROOT_PATH .'include/smarty/libs/Smarty.class.php');
+include_once( PHPWG_ROOT_PATH .'include/template.class.php');
 
 //----------------------------------------------------------- generic functions
@@ -53,8 +55,5 @@
 function get_moment()
 {
-  $t1 = explode( ' ', microtime() );
-  $t2 = explode( '.', $t1[0] );
-  $t2 = $t1[1].'.'.$t2[1];
-  return $t2;
+  return microtime(true);
 }
 
@@ -664,5 +663,5 @@
     return '';
   }
-  
+
   $query_string = '';
 
@@ -817,48 +816,4 @@
 
 /**
- * returns the title of the thumbnail based on photo properties
- */
-function get_thumbnail_title($info)
-{
-  global $conf, $user;
-
-  $title = get_picture_title($info);
-
-  $details = array();
-
-  if (!empty($info['hit']))
-  {
-    $details[] = $info['hit'].' '.strtolower(l10n('Visits'));
-  }
-
-  if ($conf['rate'] and !empty($info['rating_score']))
-  {
-    $details[] = strtolower(l10n('Rating score')).' '.$info['rating_score'];
-  }
-
-  if (isset($info['nb_comments']) and $info['nb_comments'] != 0)
-  {
-    $details[] = l10n_dec('%d comment', '%d comments', $info['nb_comments']);
-  }
-
-  if (count($details) > 0)
-  {
-    $title.= ' ('.implode(', ', $details).')';
-  }
-
-  if (!empty($info['comment']))
-  {
-    $info['comment'] = trigger_event('render_element_description', $info['comment']);
-    $title.= ' '.substr($info['comment'], 0, 100).(strlen($info['comment']) > 100 ? '...' : '');
-  }
-
-  $title = htmlspecialchars(strip_tags($title));
-
-  $title = trigger_event('get_thumbnail_title', $title, $info);
-
-  return $title;
-}
-
-/**
  * fill the current user caddie with given elements, if not already in
  * caddie
@@ -902,16 +857,4 @@
 {
   return str_replace('_',' ',get_filename_wo_extension($filename));
-}
-
-/**
- */
-function get_picture_title($info)
-{
-  if (isset($info['name']) and !empty($info['name']))
-  {
-    return trigger_event('render_element_description', $info['name']);
-  }
-
-  return  get_name_from_file($info['file']);
 }
 
@@ -1436,6 +1379,6 @@
 	return $time.':'.$valid_after_seconds.':'
 		.hash_hmac(
-			'md5', 
-			$time.substr($_SERVER['REMOTE_ADDR'],0,5).$valid_after_seconds.$aditionnal_data_to_hash, 
+			'md5',
+			$time.substr($_SERVER['REMOTE_ADDR'],0,5).$valid_after_seconds.$aditionnal_data_to_hash,
 			$conf['secret_key']);
 }
Index: /trunk/include/functions_html.inc.php
===================================================================
--- /trunk/include/functions_html.inc.php	(revision 12919)
+++ /trunk/include/functions_html.inc.php	(revision 12920)
@@ -3,5 +3,5 @@
 // | Piwigo - a PHP based photo gallery                                    |
 // +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
 // | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
 // | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
@@ -179,5 +179,5 @@
     }
   }
-  
+
   if ($single_link and isset($single_url))
   {
@@ -296,5 +296,5 @@
 {
   global $page;
-  
+
   foreach (array($a, $b) as $tag)
   {
@@ -534,3 +534,67 @@
 }
 
+/**
+ */
+function render_element_name($info)
+{
+  $name = $info['name'];
+  if (!empty($name))
+  {
+    $name = trigger_event('render_element_description', $name);
+    return $name;
+  }
+
+  return get_name_from_file($info['file']);
+}
+
+function render_element_description($info)
+{
+  $comment = $info['comment'];
+  if (!empty($comment))
+  {
+    $comment = trigger_event('render_element_description', $comment);
+    return $comment;
+  }
+  return '';
+}
+
+/**
+ * returns the title of the thumbnail based on photo properties
+ */
+function get_thumbnail_title($info, $title, $comment)
+{
+  global $conf, $user;
+
+  $details = array();
+
+  if (!empty($info['hit']))
+  {
+    $details[] = $info['hit'].' '.strtolower(l10n('Visits'));
+  }
+
+  if ($conf['rate'] and !empty($info['rating_score']))
+  {
+    $details[] = strtolower(l10n('Rating score')).' '.$info['rating_score'];
+  }
+
+  if (isset($info['nb_comments']) and $info['nb_comments'] != 0)
+  {
+    $details[] = l10n_dec('%d comment', '%d comments', $info['nb_comments']);
+  }
+
+  if (count($details) > 0)
+  {
+    $title.= ' ('.implode(', ', $details).')';
+  }
+
+  if (!empty($comment))
+  {
+    $title.= ' '.substr($info['comment'], 0, 100).(strlen($info['comment']) > 100 ? '...' : '');
+  }
+
+  $title = htmlspecialchars(strip_tags($title));
+  $title = trigger_event('get_thumbnail_title', $title, $info);
+  return $title;
+}
+
 ?>
Index: /trunk/include/functions_picture.inc.php
===================================================================
--- /trunk/include/functions_picture.inc.php	(revision 12919)
+++ /trunk/include/functions_picture.inc.php	(revision 12920)
@@ -3,5 +3,5 @@
 // | Piwigo - a PHP based photo gallery                                    |
 // +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
 // | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
 // | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
@@ -23,23 +23,4 @@
 
 
-
-/*
- * Returns the name of a photo according to its name and its filename.
- * @param name string
- * @param filename string
- * @return string
- */
-function get_image_name($name, $filename)
-{
-  if (!empty($name))
-  {
-    return $name;
-  }
-  else
-  {
-    return get_name_from_file($filename);
-  }
-}
-
 /*
  * @param element_info array containing element information from db;
Index: /trunk/include/template.class.php
===================================================================
--- /trunk/include/template.class.php	(revision 12919)
+++ /trunk/include/template.class.php	(revision 12920)
@@ -23,7 +23,4 @@
 
 
-require_once(PHPWG_ROOT_PATH.'include/smarty/libs/Smarty.class.php');
-
-
 class Template {
 
@@ -43,4 +40,5 @@
   // used by html_head smarty block to add content before </head>
   var $html_head_elements = array();
+  private $html_style = '';
 
   const COMBINED_SCRIPTS_TAG = '<!-- COMBINED_SCRIPTS -->';
@@ -113,4 +111,5 @@
     $this->smarty->register_modifier( 'get_extent', array(&$this, 'get_extent') );
     $this->smarty->register_block('html_head', array(&$this, 'block_html_head') );
+    $this->smarty->register_block('html_style', array(&$this, 'block_html_style') );
     $this->smarty->register_function('combine_script', array(&$this, 'func_combine_script') );
     $this->smarty->register_function('get_combined_scripts', array(&$this, 'func_get_combined_scripts') );
@@ -467,5 +466,5 @@
     }
 
-    if ( count($this->html_head_elements) )
+    if ( count($this->html_head_elements) || strlen($this->html_style) )
     {
       $search = "\n</head>";
@@ -473,7 +472,13 @@
       if ($pos !== false)
       {
-        $this->output = substr_replace( $this->output, "\n".implode( "\n", $this->html_head_elements ), $pos, 0 );
+        $rep = "\n".implode( "\n", $this->html_head_elements );
+        if (strlen($this->html_style))
+        {
+          $rep='<style type="text/css">'.$this->html_style.'</style>';
+        }
+        $this->output = substr_replace( $this->output, $rep, $pos, 0 );
       } //else maybe error or warning ?
       $this->html_head_elements = array();
+      $this->html_style = '';
     }
 
@@ -530,4 +535,13 @@
     { // second call
       $this->html_head_elements[] = $content;
+    }
+  }
+
+  function block_html_style($params, $content, &$smarty, &$repeat)
+  {
+    $content = trim($content);
+    if ( !empty($content) )
+    { // second call
+      $this->html_style .= $content;
     }
   }
@@ -843,5 +857,5 @@
     return call_user_func_array('sprintf',  $args );
   }
-  
+
   function derivative_url($type, $img)
   {
Index: /trunk/install.php
===================================================================
--- /trunk/install.php	(revision 12919)
+++ /trunk/install.php	(revision 12920)
@@ -225,5 +225,4 @@
 
 //----------------------------------------------------- template initialization
-include( PHPWG_ROOT_PATH .'include/template.class.php');
 $template = new Template(PHPWG_ROOT_PATH.'admin/themes', 'clear');
 $template->set_filenames( array('install' => 'install.tpl') );
Index: /trunk/picture.php
===================================================================
--- /trunk/picture.php	(revision 12919)
+++ /trunk/picture.php	(revision 12920)
@@ -3,5 +3,5 @@
 // | Piwigo - a PHP based photo gallery                                    |
 // +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
 // | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
 // | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
@@ -177,5 +177,5 @@
 
   global $page, $template;
-  
+
   if ($show_original)
   {
@@ -313,8 +313,4 @@
       break;
     }
-    case 'toggle_metadata' :
-    {
-      break;
-    }
     case 'add_to_caddie' :
     {
@@ -335,5 +331,5 @@
       check_input_parameter('comment_to_edit', $_GET, false, PATTERN_ID);
       $author_id = get_comment_author_id($_GET['comment_to_edit']);
-      
+
       if (can_manage_comment('edit', $author_id))
       {
@@ -365,5 +361,5 @@
               trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
           }
-          
+
           if ($perform_redirect)
           {
@@ -501,5 +497,5 @@
   $row['src_image'] = new SrcImage($row);
   $row['derivatives'] = DerivativeImage::get_all($row['src_image']);
-  
+
   if ($i=='current')
   {
@@ -531,16 +527,5 @@
 
   $picture[$i] = $row;
-
-  if ( !empty( $row['name'] ) )
-  {
-    $picture[$i]['name'] = $row['name'];
-  }
-  else
-  {
-    $file_wo_ext = get_filename_wo_extension($row['file']);
-    $picture[$i]['name'] = str_replace('_', ' ', $file_wo_ext);
-  }
-
-  $picture[$i]['name'] = trigger_event('render_element_description', $picture[$i]['name']);
+  $picture[$i]['TITLE'] = render_element_name($row);
 
   if ('previous'==$i and $page['previous_item']==$page['first_item'])
@@ -605,5 +590,5 @@
 }
 
-$title =  $picture['current']['name'];
+$title =  $picture['current']['TITLE'];
 $title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);
 
@@ -644,5 +629,4 @@
         $picture[$which_image],
         array(
-          'TITLE' => $picture[$which_image]['name'],
           'THUMB_SRC' => $picture[$which_image]['derivatives'][IMG_THUMB]->get_url(),
           // Params slideshow was transmit to navigation buttons
@@ -653,9 +637,9 @@
         )
       );
-    if ($conf['picture_download_icon'] and !empty($picture['current']['download_url']))
-    {
-      $template->append($which_image, array('U_DOWNLOAD' => $picture['current']['download_url']), true);
-    }
-  }
+  }
+}
+if ($conf['picture_download_icon'] and !empty($picture['current']['download_url']))
+{
+  $template->append('current', array('U_DOWNLOAD' => $picture['current']['download_url']), true);
 }
 
Index: /trunk/themes/default/template/mainpage_categories.tpl
===================================================================
--- /trunk/themes/default/template/mainpage_categories.tpl	(revision 12919)
+++ /trunk/themes/default/template/mainpage_categories.tpl	(revision 12920)
@@ -1,3 +1,11 @@
+{strip}{html_style}
+.thumbnailCategory DIV.illustration{ldelim}
+	width: {$derivative_params->max_width()+5}px;
+}
 
+.content .thumbnailCategory .description{ldelim}
+	height: {$derivative_params->max_height()+5}px;
+}
+{/html_style}{/strip}
 <ul class="thumbnailCategories">
 {foreach from=$category_thumbnails item=cat}
@@ -6,5 +14,5 @@
 			<div class="illustration">
 			<a href="{$cat.URL}">
-				<img src="{$cat.TN_SRC}" alt="{$cat.TN_ALT}" title="{$cat.NAME|@replace:'"':' '|@strip_tags:false} - {'display this album'|@translate}">
+				<img src="{$pwg->derivative_url($derivative_params, $cat.representative.src_image)}" alt="{$cat.TN_ALT}" title="{$cat.NAME|@replace:'"':' '|@strip_tags:false} - {'display this album'|@translate}">
 			</a>
 			</div>
Index: /trunk/themes/default/template/thumbnails.tpl
===================================================================
--- /trunk/themes/default/template/thumbnails.tpl	(revision 12919)
+++ /trunk/themes/default/template/thumbnails.tpl	(revision 12920)
@@ -1,5 +1,4 @@
 {if !empty($thumbnails)}{strip}
-{html_head}
-<style type="text/css">
+{html_style}
 {*Set some sizes according to maximum thumbnail width and height*}
 .thumbnails SPAN,
@@ -12,7 +11,14 @@
 	height: {$derivative_params->max_height()+2}px;
 }
-
-</style>
-{/html_head}
+{if $derivative_params->max_width() > 600}
+.thumbLegend {ldelim}font-size: 130%}
+{else}
+{if $derivative_params->max_width() > 400}
+.thumbLegend {ldelim}font-size: 110%}
+{else}
+.thumbLegend {ldelim}font-size: 90%}
+{/if}
+{/if}
+{/html_style}
 {foreach from=$thumbnails item=thumbnail}
 	<li>
Index: /trunk/themes/default/theme.css
===================================================================
--- /trunk/themes/default/theme.css	(revision 12919)
+++ /trunk/themes/default/theme.css	(revision 12920)
@@ -264,5 +264,4 @@
 /* Thumbnails */
 .thumbnails SPAN.thumbLegend {
-	font-size: 90%;
 	overflow: hidden;/* oversized legend is clipped */
 }
Index: /trunk/upgrade.php
===================================================================
--- /trunk/upgrade.php	(revision 12919)
+++ /trunk/upgrade.php	(revision 12920)
@@ -217,5 +217,4 @@
 // +-----------------------------------------------------------------------+
 
-include( PHPWG_ROOT_PATH .'include/template.class.php');
 $template = new Template(PHPWG_ROOT_PATH.'admin/themes', 'clear');
 $template->set_filenames(array('upgrade'=>'upgrade.tpl'));
