feature 2548 multisize

- added define_derivative template functiion for themes and plugins
- code cleanup, new events ...

git-svn-id: http://piwigo.org/svn/trunk@12954 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices
2012-01-24 19:24:47 +00:00
parent 3b3e586b0d
commit 4372d7aa11
6 changed files with 139 additions and 88 deletions

View File

@@ -114,6 +114,7 @@ class Template {
$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') );
$this->smarty->register_function('define_derivative', array(&$this, 'func_define_derivative') );
$this->smarty->register_compiler_function('get_combined_css', array(&$this, 'func_get_combined_css') );
$this->smarty->register_block('footer_script', array(&$this, 'block_footer_script') );
$this->smarty->register_prefilter( array('Template', 'prefilter_white_space') );
@@ -546,6 +547,45 @@ class Template {
}
}
function func_define_derivative($params, &$smarty)
{
!empty($params['name']) or fatal_error('define_derviative missing name');
if (isset($params['type']))
{
$derivative = ImageStdParams::get_by_type($params['type']);
$smarty->assign( $params['name'], $derivative);
return;
}
!empty($params['width']) or fatal_error('define_derviative missing width');
!empty($params['height']) or fatal_error('define_derviative missing height');
$derivative = new DerivativeParams( SizingParams::classic( intval($params['width']), intval($params['height'])) );
if (isset($params['crop']))
{
if (is_bool($params['crop']))
{
$derivative->sizing->max_crop = $params['crop'] ? 1:0;
}
else
{
$derivative->sizing->max_crop = round($params['crop']/100, 2);
}
if ($derivative->sizing->max_crop)
{
$minw = empty($params['min_width']) ? $derivative->max_width() : intval($params['min_width']);
$minw <= $derivative->max_width() or fatal_error('define_derviative invalid min_width');
$minh = empty($params['min_height']) ? $derivative->max_height() : intval($params['min_height']);
$minh <= $derivative->max_height() or fatal_error('define_derviative invalid min_height');
$derivative->sizing->min_size = array($minw, $minh);
}
}
ImageStdParams::apply_global($derivative);
$smarty->assign( $params['name'], $derivative);
}
/**
* 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