LStemplate : rename special smarty functions and added method getFilePath()

This commit is contained in:
Benjamin Renard 2013-06-18 19:04:47 +02:00
parent dcdb484134
commit f4e97c8133
4 changed files with 48 additions and 30 deletions

View file

@ -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.")

View file

@ -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');

View file

@ -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");

View file

@ -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
*