aboutsummaryrefslogtreecommitdiffstats
path: root/include/template.class.php
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2012-01-24 19:24:47 +0000
committerrvelices <rv-github@modusoptimus.com>2012-01-24 19:24:47 +0000
commit4372d7aa112a2eedb4e3959a87c779984c698e2c (patch)
treeeffb299c1e7af6d56d68ea1916845184553e3b6b /include/template.class.php
parent3b3e586b0d9a0a4da92d5040bfb08937afdc239f (diff)
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
Diffstat (limited to '')
-rw-r--r--include/template.class.php40
1 files changed, 40 insertions, 0 deletions
diff --git a/include/template.class.php b/include/template.class.php
index 90d7d58b8..10556a361 100644
--- a/include/template.class.php
+++ b/include/template.class.php
@@ -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