feature 2548 multisize - code cleanup + better usage in category_cats + i.php logs memory usage peak

git-svn-id: http://piwigo.org/svn/trunk@12920 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices 2012-01-17 21:58:18 +00:00
parent e1bd64fdfc
commit cc01941ed9
14 changed files with 150 additions and 169 deletions

14
i.php
View file

@ -28,13 +28,6 @@ include(PHPWG_ROOT_PATH . 'include/config_default.inc.php');
defined('PWG_LOCAL_DIR') or define('PWG_LOCAL_DIR', 'local/');
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 )
{
@ -127,7 +120,7 @@ function ierror($msg, $code)
function time_step( &$step )
{
$tmp = $step;
$step = get_moment();
$step = microtime(true);
return intval(1000*($step - $tmp));
}
@ -263,7 +256,7 @@ function send_derivative($expires)
$page=array();
$begin = $step = get_moment();
$begin = $step = microtime(true);
$timing=array();
foreach( explode(',','load,rotate,crop,scale,sharpen,watermark,save,send') as $k )
{
@ -414,6 +407,7 @@ $timing['send'] = time_step($step);
ilog('perf',
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);
?>

View file

@ -189,7 +189,6 @@ SELECT *
{
if ($row['level'] <= $user['level'])
{
$row['tn_src'] = DerivativeImage::thumb_url($row);
$infos_of_image[$row['id']] = $row;
}
else
@ -236,10 +235,15 @@ SELECT *
$result = pwg_query($query);
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);
}
if (count($user_representative_updates_for))
@ -311,7 +315,7 @@ if (count($categories) > 0)
$tpl_var =
array(
'ID' => $category['id'],
'TN_SRC' => $representative_infos['tn_src'],
'representative' => $representative_infos,
'TN_ALT' => strip_tags($category['name']),
'URL' => make_index_url(
@ -333,23 +337,6 @@ if (count($categories) > 0)
@$category['comment'],
'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'])
{
@ -387,8 +374,12 @@ if (count($categories) > 0)
$tpl_thumbnails_var[] = $tpl_var;
}
$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');
}

View file

@ -109,13 +109,15 @@ foreach ($pictures as $row)
$row['NB_COMMENTS'] = $row['nb_comments'] = (int)@$nb_comments_of[$row['id']];
}
$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),
) );
@ -145,12 +147,11 @@ foreach ($pictures as $row)
break;
}
}
$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(
'derivative_params' =>$derivative_params,
@ -161,6 +162,6 @@ $template->assign('thumbnails', $tpl_thumbnails_var);
$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');
?>

View file

@ -24,9 +24,7 @@
defined('PHPWG_ROOT_PATH') or trigger_error('Hacking attempt!', E_USER_ERROR);
// 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
@ -109,7 +107,7 @@ if(isset($conf['show_php_errors']) && !empty($conf['show_php_errors']))
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
try

View file

@ -33,6 +33,8 @@ include_once( PHPWG_ROOT_PATH .'include/functions_plugins.inc.php' );
include_once( PHPWG_ROOT_PATH .'include/derivative_params.inc.php');
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
@ -52,10 +54,7 @@ function micro_seconds()
// are precised : e.g. 1052343429.89276600
function get_moment()
{
$t1 = explode( ' ', microtime() );
$t2 = explode( '.', $t1[0] );
$t2 = $t1[1].'.'.$t2[1];
return $t2;
return microtime(true);
}
// The function get_elapsed_time returns the number of seconds (with 3
@ -815,50 +814,6 @@ function get_thumbnail_location($element_info)
return $path;
}
/**
* 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
@ -903,18 +858,6 @@ function get_name_from_file($filename)
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']);
}
/**
* returns the corresponding value from $lang if existing. Else, the key is
* returned

View file

@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | 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 |
// +-----------------------------------------------------------------------+
@ -533,4 +533,68 @@ function register_default_menubar_blocks( $menu_ref_arr )
$menu->register_block( new RegisteredBlock( 'mbIdentification', 'Identification', 'piwigo') );
}
/**
*/
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;
}
?>

View file

@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | 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 |
// +-----------------------------------------------------------------------+
@ -22,25 +22,6 @@
// +-----------------------------------------------------------------------+
/*
* 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;
* at least 'id', 'path', 'has_high' should be present

View file

@ -22,9 +22,6 @@
// +-----------------------------------------------------------------------+
require_once(PHPWG_ROOT_PATH.'include/smarty/libs/Smarty.class.php');
class Template {
var $smarty;
@ -42,6 +39,7 @@ class Template {
// 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 -->';
var $scriptLoader;
@ -112,6 +110,7 @@ class Template {
$this->smarty->register_modifier( 'explode', array('Template', 'mod_explode') );
$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') );
$this->smarty->register_function('combine_css', array(&$this, 'func_combine_css') );
@ -466,15 +465,21 @@ class Template {
$this->css_by_priority = array();
}
if ( count($this->html_head_elements) )
if ( count($this->html_head_elements) || strlen($this->html_style) )
{
$search = "\n</head>";
$pos = strpos( $this->output, $search );
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 = '';
}
echo $this->output;
@ -532,6 +537,15 @@ class Template {
}
}
function block_html_style($params, $content, &$smarty, &$repeat)
{
$content = trim($content);
if ( !empty($content) )
{ // second call
$this->html_style .= $content;
}
}
/**
* combine_script smarty function allows inclusion of a javascript file in the current page.
* The engine will combine several js files into a single one in order to reduce the number of

View file

@ -224,7 +224,6 @@ if (version_compare(PHP_VERSION, REQUIRED_PHP_VERSION, '<'))
}
//----------------------------------------------------- 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') );
if (!isset($step))

View file

@ -2,7 +2,7 @@
// +-----------------------------------------------------------------------+
// | 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 |
// +-----------------------------------------------------------------------+
@ -312,10 +312,6 @@ UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
break;
}
case 'toggle_metadata' :
{
break;
}
case 'add_to_caddie' :
{
fill_caddie(array($page['image_id']));
@ -530,18 +526,7 @@ while ($row = pwg_db_fetch_assoc($result))
);
$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'])
{
@ -604,7 +589,7 @@ else
$template->set_filenames( array('picture' => 'picture.tpl'));
}
$title = $picture['current']['name'];
$title = $picture['current']['TITLE'];
$title_nb = ($page['current_rank'] + 1).'/'.count($page['items']);
// metadata
@ -643,7 +628,6 @@ foreach (array('first','previous','next','last', 'current') as $which_image)
array_merge(
$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
'U_IMG' =>
@ -652,12 +636,12 @@ foreach (array('first','previous','next','last', 'current') as $which_image)
)
)
);
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);
}
if ($page['slideshow'])

View file

@ -1,11 +1,19 @@
{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}
<li>
<div class="thumbnailCategory">
<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>
<div class="description">

View file

@ -1,6 +1,5 @@
{if !empty($thumbnails)}{strip}
{html_head}
<style type="text/css">
{html_style}
{*Set some sizes according to maximum thumbnail width and height*}
.thumbnails SPAN,
.thumbnails .wrap2 A,
@ -11,9 +10,16 @@
.thumbnails .wrap2{ldelim}
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>
<span class="wrap1">

View file

@ -263,7 +263,6 @@ TD.calDayHead {
/* Thumbnails */
.thumbnails SPAN.thumbLegend {
font-size: 90%;
overflow: hidden;/* oversized legend is clipped */
}

View file

@ -216,7 +216,6 @@ define('CURRENT_DATE', $dbnow);
// | template initialization |
// +-----------------------------------------------------------------------+
include( PHPWG_ROOT_PATH .'include/template.class.php');
$template = new Template(PHPWG_ROOT_PATH.'admin/themes', 'clear');
$template->set_filenames(array('upgrade'=>'upgrade.tpl'));
$template->assign(array(