diff --git a/public_html/conf/config.inc.php b/public_html/conf/config.inc.php index 2bbb5626..6ec825dd 100644 --- a/public_html/conf/config.inc.php +++ b/public_html/conf/config.inc.php @@ -178,7 +178,7 @@ $GLOBALS['LSconfig'] = array( // Theme Default define('LS_THEME','default'); define('LS_TEMPLATES_DIR', 'templates'); -define('LS_IMAGES_DIR', 'images/'.LS_THEME); +define('LS_IMAGES_DIR', 'images'); define('LS_CSS_DIR', 'css/'.LS_THEME); //Debug diff --git a/public_html/includes/class/class.LSsession.php b/public_html/includes/class/class.LSsession.php index 9d9b415e..4ad5c514 100644 --- a/public_html/includes/class/class.LSsession.php +++ b/public_html/includes/class/class.LSsession.php @@ -133,16 +133,18 @@ class LSsession { */ private static function startLStemplate() { if ( self :: loadLSclass('LStemplate') ) { - self :: addJSconfigParam('LS_IMAGES_DIR',LS_IMAGES_DIR); - return LStemplate :: start( + $res = LStemplate :: start( array( 'smarty_path' => LSconfig :: get('Smarty'), 'template_dir' => LS_TEMPLATES_DIR, + 'image_dir' => LS_IMAGES_DIR, 'compile_dir' => LS_TMP_DIR, 'debug' => LSdebug, 'debug_smarty' => (isset($_REQUEST['LStemplate_debug'])), ) ); + self :: addJSconfigParam('LS_IMAGES_DIR',LStemplate :: getDefaultImageDirPath()); + return $res; } return False; } diff --git a/public_html/includes/class/class.LStemplate.php b/public_html/includes/class/class.LStemplate.php index 24e757a4..2feeae60 100644 --- a/public_html/includes/class/class.LStemplate.php +++ b/public_html/includes/class/class.LStemplate.php @@ -35,13 +35,21 @@ class LStemplate { * array( * 'smarty_path' => '/path/to/Smarty.php', * 'template_dir' => '/path/to/template/directory', + * 'image_dir' => '/path/to/image/directory', * 'compile_dir' => '/path/to/compile/directory', * 'debug' => True, * 'debug_smarty' => True * ) * **/ - private static $config = NULL; + private static $config = array ( + 'smarty_path' => 'smarty/libs/Smarty.class.php', + 'template_dir' => 'templates', + 'image_dir' => 'images', + 'compile_dir' => 'tmp', + 'debug' => False, + 'debug_smarty' => False + ); // Smarty object public static $_smarty = NULL; @@ -66,24 +74,26 @@ class LStemplate { * @retval boolean True on success, False instead **/ public static function start($config) { - self :: $config = $config; + foreach ($config as $key => $value) { + self :: $config[$key] = $value; + } - if (LSsession :: includeFile($config['smarty_path'])) { + if (LSsession :: includeFile(self :: $config['smarty_path'])) { self :: $_smarty = new Smarty(); - self :: $_smarty -> template_dir = $config['template_dir']; + self :: $_smarty -> template_dir = self :: $config['template_dir']; - if ( ! is_writable($config['compile_dir']) ) { - die(_('LStemplate : compile directory is not writable (dir : '.$config['compile_dir'].')')); + if ( ! is_writable(self :: $config['compile_dir']) ) { + die(_('LStemplate : compile directory is not writable (dir : '.self :: $config['compile_dir'].')')); } - self :: $_smarty -> compile_dir = $config['compile_dir']; + self :: $_smarty -> compile_dir = self :: $config['compile_dir']; - if ($config['debug']) { + if (self :: $config['debug']) { self :: $_smarty -> caching = 0; // cache files are always regenerated self :: $_smarty -> force_compile = TRUE; // recompile template if it is changed self :: $_smarty -> compile_check = TRUE; - if ($config['debug_smarty']) { + if (self :: $config['debug_smarty']) { // debug smarty self :: $_smarty -> debugging = true; } @@ -107,7 +117,7 @@ class LStemplate { } self :: $_smarty -> assign('LS_CSS_DIR',LS_CSS_DIR); - self :: $_smarty -> assign('LS_IMAGES_DIR',LS_IMAGES_DIR); + self :: $_smarty -> assign('LS_IMAGES_DIR',self :: getDefaultImageDirPath()); return True; } @@ -138,6 +148,36 @@ class LStemplate { return $root_dir.'/'.$default_dir.'/'.$file; } + /** + * Return the default path of images directory + * + * @retval string The path of the file + **/ + public static function getDefaultImageDirPath() { + if (is_dir(self :: $config['image_dir'].'/'.LS_THEME)) { + return self :: $config['image_dir'].'/'.LS_THEME; + } + return self :: $config['image_dir'].'/default'; + } + + + /** + * Return the path of the image file to use + * + * @param[in] string $image The image name (eg: mail) + * + * @retval string The path of the image file + **/ + public static function getImagePath($image) { + $exts=array('png','gif','jpg'); + foreach($exts as $ext) { + $path=self :: getFilePath("$image.$ext",self :: $config['image_dir'],False); + if ($path) return $path; + } + return self :: $config['image_dir']."/default/$image.png"; + } + + /** * Return the path of the Smarty template file to use * @@ -229,6 +269,11 @@ function LStemplate_smarty_tr($params) { echo __($msg); } +function LStemplate_smarty_img($params) { + extract($params); + echo LStemplate :: getImagePath($name); +} + // 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 50b802eb..d28da83f 100644 --- a/public_html/includes/class/class.LStemplate_smarty2_support.php +++ b/public_html/includes/class/class.LStemplate_smarty2_support.php @@ -105,4 +105,5 @@ LStemplate :: $_smarty -> register_resource('ls', array( // Register special template functions LStemplate :: $_smarty -> register_function('getFData','LStemplate_smarty_getFData'); LStemplate :: $_smarty -> register_function('tr','LStemplate_smarty_tr'); +LStemplate :: $_smarty -> register_function('img','LStemplate_smarty_img'); diff --git a/public_html/includes/class/class.LStemplate_smarty3_support.php b/public_html/includes/class/class.LStemplate_smarty3_support.php index ed264563..4ed45a0f 100644 --- a/public_html/includes/class/class.LStemplate_smarty3_support.php +++ b/public_html/includes/class/class.LStemplate_smarty3_support.php @@ -63,4 +63,5 @@ LStemplate :: $_smarty -> registerResource('ls', new Smarty_Resource_LdapSaisie( // Register special template functions LStemplate :: $_smarty -> registerPlugin("function","getFData", "LStemplate_smarty_getFData"); LStemplate :: $_smarty -> registerPlugin("function","tr", "LStemplate_smarty_tr"); +LStemplate :: $_smarty -> registerPlugin("function","img", "LStemplate_smarty_img"); diff --git a/public_html/templates/default/LSdefault.tpl b/public_html/templates/default/LSdefault.tpl index e060537f..881ee909 100644 --- a/public_html/templates/default/LSdefault.tpl +++ b/public_html/templates/default/LSdefault.tpl @@ -12,6 +12,6 @@