From c41477dde8b4db607fed300c491b4e143cc8d883 Mon Sep 17 00:00:00 2001 From: slothman Date: Wed, 19 Mar 2008 11:32:13 +0000 Subject: [PATCH] Add function to allow Smarty to retrieve image dimensions --- include/functions_smarty.inc.php | 41 ++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/include/functions_smarty.inc.php b/include/functions_smarty.inc.php index b6f04e5..4af1ce2 100644 --- a/include/functions_smarty.inc.php +++ b/include/functions_smarty.inc.php @@ -755,6 +755,46 @@ function &serendipity_smarty_printTrackbacks($params, &$smarty) { return $out; } +/** + * 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 * @@ -847,6 +887,7 @@ function serendipity_smarty_init($vars = array()) { $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'); } -- 2.39.5