From f4e97c81334a6bd0705e85d2cd5c1699977ee532 Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Tue, 18 Jun 2013 19:04:47 +0200 Subject: [PATCH] LStemplate : rename special smarty functions and added method getFilePath() --- .../includes/class/class.LStemplate.php | 60 ++++++++++++++----- .../class.LStemplate_smarty2_support.php | 4 +- .../class.LStemplate_smarty3_support.php | 4 +- public_html/includes/functions.php | 10 ---- 4 files changed, 48 insertions(+), 30 deletions(-) diff --git a/public_html/includes/class/class.LStemplate.php b/public_html/includes/class/class.LStemplate.php index 09efbcee..24e757a4 100644 --- a/public_html/includes/class/class.LStemplate.php +++ b/public_html/includes/class/class.LStemplate.php @@ -49,6 +49,12 @@ class LStemplate { // Smarty version private static $_smarty_version = NULL; + // Array of directories + private static $directories = array( + 'local', + LS_THEME + ); + /** * Start LStemplate * @@ -111,31 +117,43 @@ class LStemplate { } } + /** + * Return the path of the file to use + * + * @param[in] string $name The file name (eg: mail.png) + * @param[in] string $root_dir The root directory (eg: images) + * @param[in] string $default_dir The default directory (eg: default) + * + * @retval string The path of the file + **/ + public static function getFilePath($file,$root_dir,$default_dir='default') { + foreach(self :: $directories as $dir) { + if (file_exists($root_dir.'/'.$dir.'/'.$file)) { + return $root_dir.'/'.$dir.'/'.$file; + } + } + if (!$default_dir) { + return; + } + return $root_dir.'/'.$default_dir.'/'.$file; + } + /** * Return the path of the Smarty template file to use * * @param[in] string $template The template name (eg: top.tpl) - * + * * @retval string The path of the Smarty template file **/ public static function getTemplatePath($template) { - $directories=array( - 'local', - LS_THEME - ); - foreach($directories as $dir) { - if (file_exists(self :: $config['template_dir'].'/'.$dir.'/'.$template)) { - return self :: $config['template_dir'].'/'.$dir.'/'.$template; - } - } - return $config['template_dir'].'/default/'.$template; + return self :: getFilePath($template,self :: $config['template_dir']); } /** * Return the content of a Smarty template file. * * @param[in] string $template The template name (eg: top.tpl) - * + * * @retval string The content of the Smarty template file **/ public static function getTemplateSource($template) { @@ -152,7 +170,7 @@ class LStemplate { * template file. * * @param[in] string $template The template name (eg: top.tpl) - * + * * @retval string The timestamp of the last change of the Smarty template file **/ public static function getTemplateTimestamp($template) { @@ -170,7 +188,7 @@ class LStemplate { * * @param[in] string $name The variable name * @param[in] mixed $value The variable value - * + * * @retval void **/ public static function assign($name,$value) { @@ -181,7 +199,7 @@ class LStemplate { * Display a template * * @param[in] string $template The template name (eg: empty.tpl) - * + * * @retval void **/ public static function display($template) { @@ -192,7 +210,7 @@ class LStemplate { * Fetch a template * * @param[in] string $template The template name (eg: empty.tpl) - * + * * @retval string The template compiled **/ public static function fetch($template) { @@ -201,6 +219,16 @@ class LStemplate { } +function LStemplate_smarty_getFData($params) { + extract($params); + echo getFData($format,$data,$meth=NULL); +} + +function LStemplate_smarty_tr($params) { + extract($params); + echo __($msg); +} + // Errors LSerror :: defineError('LStemplate_01', _("LStemplate : Template %{file} not found.") diff --git a/public_html/includes/class/class.LStemplate_smarty2_support.php b/public_html/includes/class/class.LStemplate_smarty2_support.php index 6949a261..50b802eb 100644 --- a/public_html/includes/class/class.LStemplate_smarty2_support.php +++ b/public_html/includes/class/class.LStemplate_smarty2_support.php @@ -103,6 +103,6 @@ LStemplate :: $_smarty -> register_resource('ls', array( ); // Register special template functions -LStemplate :: $_smarty -> register_function('getFData','smarty_getFData'); -LStemplate :: $_smarty -> register_function('tr','smarty_tr'); +LStemplate :: $_smarty -> register_function('getFData','LStemplate_smarty_getFData'); +LStemplate :: $_smarty -> register_function('tr','LStemplate_smarty_tr'); diff --git a/public_html/includes/class/class.LStemplate_smarty3_support.php b/public_html/includes/class/class.LStemplate_smarty3_support.php index 8937b0df..ed264563 100644 --- a/public_html/includes/class/class.LStemplate_smarty3_support.php +++ b/public_html/includes/class/class.LStemplate_smarty3_support.php @@ -61,6 +61,6 @@ class Smarty_Resource_LdapSaisie extends Smarty_Resource_Custom { LStemplate :: $_smarty -> registerResource('ls', new Smarty_Resource_LdapSaisie()); // Register special template functions -LStemplate :: $_smarty -> registerPlugin("function","getFData", "smarty_getFData"); -LStemplate :: $_smarty -> registerPlugin("function","tr", "smarty_tr"); +LStemplate :: $_smarty -> registerPlugin("function","getFData", "LStemplate_smarty_getFData"); +LStemplate :: $_smarty -> registerPlugin("function","tr", "LStemplate_smarty_tr"); diff --git a/public_html/includes/functions.php b/public_html/includes/functions.php index 293ea3f7..44e74060 100644 --- a/public_html/includes/functions.php +++ b/public_html/includes/functions.php @@ -164,11 +164,6 @@ function _getFData_extractAndModify($data,$ch) { return $val; } -function smarty_getFData($params) { - extract($params); - echo getFData($format,$data,$meth=NULL); -} - function getFieldInFormat($format) { $fields=array(); $expr="%[{(]([A-Za-z0-9]+)(\:(-?[0-9])+)?(\:(-?[0-9]+))?(-)?(\!|\_)?(~)?[})]"; @@ -456,11 +451,6 @@ function LSdebugDefined() { return _($msg); } - function smarty_tr($params) { - extract($params); - echo __($msg); - } - /** * Supprime les accents d'une chaine *