[php-blog-cvs] r2187 - trunk/include
A reliable, secure & extensible PHP blog | Not mainstream since 2002
Brought to you by:
garvinhicking,
jhermanns
From: slothman at B. <slo...@ma...> - 2008-03-19 11:32:15
|
Author: slothman Date: 2008-03-19 12:32:13 +0100 (Wed, 19 Mar 2008) New Revision: 2187 Modified: trunk/include/functions_smarty.inc.php Log: Add function to allow Smarty to retrieve image dimensions Modified: trunk/include/functions_smarty.inc.php =================================================================== --- trunk/include/functions_smarty.inc.php 2008-03-19 11:30:30 UTC (rev 2186) +++ trunk/include/functions_smarty.inc.php 2008-03-19 11:32:13 UTC (rev 2187) @@ -756,6 +756,46 @@ } /** + * Get the Serendipity dimensions for an image + * + * @access public + * @param array Smarty parameter input array: + * file: The image file to get image data for + * assign: The variable to assign the image data array to + * @param object Smarty object + * @return string Empty + */ +function serendipity_smarty_getImageSize($params, &$smarty) { + global $serendipity; + + if (!isset($params['file'])) { + $smarty->trigger_error(__FUNCTION__ .": missing 'file' parameter"); + return; + } + if (!isset($params['assign'])) { + $smarty->trigger_error(__FUNCTION__ .": missing 'assign' parameter"); + return; + } + + // Is it a correct filesystem absolute path? + $file = $params['file']; + // Most likely the user specified an HTTP path + if (!file_exists($file)) { + $file = $_SERVER['DOCUMENT_ROOT'] . $file; + } + // Maybe wants a template file (returns filesystem path) + if (!file_exists($file)) { + $file = serendipity_getTemplateFile($params['file']); + } + // If no file, trigger an error + if (!file_exists($file)) { + $smarty->trigger_error(__FUNCTION__ .': file ' . $params['file'] . 'not found '); + return; + } + $smarty->assign($params['assign'], serendipity_getimagesize($file)); +} + +/** * Smarty Prefilter: Replace constants to direkt $smarty.const. access * * @access public @@ -847,6 +887,7 @@ $serendipity['smarty']->register_function('serendipity_getTotalCount', 'serendipity_smarty_getTotalCount'); $serendipity['smarty']->register_function('pickKey', 'serendipity_smarty_pickKey'); $serendipity['smarty']->register_function('serendipity_showCommentForm', 'serendipity_smarty_showCommentForm'); + $serendipity['smarty']->register_function('serendipity_getImageSize', 'serendipity_smarty_getImageSize'); $serendipity['smarty']->register_prefilter('serendipity_replaceSmartyVars'); } |