From 09432db48e6700cfd6b859ce6b3b1790b73ba6fd Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Wed, 19 Jun 2013 03:06:29 +0200 Subject: [PATCH] Manage CSS path with LStemplate --- public_html/conf/config.inc.php | 2 +- .../includes/class/class.LSsession.php | 20 +++++++++---------- .../includes/class/class.LStemplate.php | 19 ++++++++++++++++-- .../class.LStemplate_smarty2_support.php | 1 + .../class.LStemplate_smarty3_support.php | 1 + public_html/templates/default/blank.tpl | 4 ++-- public_html/templates/default/login.tpl | 2 +- .../templates/default/recoverpassword.tpl | 2 +- public_html/templates/default/top.tpl | 4 ++-- 9 files changed, 35 insertions(+), 20 deletions(-) diff --git a/public_html/conf/config.inc.php b/public_html/conf/config.inc.php index 6ec825dd..584463de 100644 --- a/public_html/conf/config.inc.php +++ b/public_html/conf/config.inc.php @@ -179,7 +179,7 @@ $GLOBALS['LSconfig'] = array( define('LS_THEME','default'); define('LS_TEMPLATES_DIR', 'templates'); define('LS_IMAGES_DIR', 'images'); -define('LS_CSS_DIR', 'css/'.LS_THEME); +define('LS_CSS_DIR', 'css'); //Debug define('LSdebug',false); diff --git a/public_html/includes/class/class.LSsession.php b/public_html/includes/class/class.LSsession.php index f798dc7f..934c82ab 100644 --- a/public_html/includes/class/class.LSsession.php +++ b/public_html/includes/class/class.LSsession.php @@ -138,6 +138,7 @@ class LSsession { 'smarty_path' => LSconfig :: get('Smarty'), 'template_dir' => LS_TEMPLATES_DIR, 'image_dir' => LS_IMAGES_DIR, + 'css_dir' => LS_CSS_DIR, 'compile_dir' => LS_TMP_DIR, 'debug' => LSdebug, 'debug_smarty' => (isset($_REQUEST['LStemplate_debug'])), @@ -1262,18 +1263,18 @@ class LSsession { /** * Ajoute une feuille de style au chargement de la page * - * Remarque : les scripts doivents être dans le dossier LS_CSS_DIR. - * * @param[in] $script Le nom du fichier css à charger. * * @retval void */ public static function addCssFile($file,$path=NULL) { - $cssFile=array( - 'file' => $file, - 'path' => $path - ); - self :: $CssFiles[$path.$file]=$cssFile; + if ($path) { + $file = $path.$file; + } + else { + $file = LStemplate :: getCSSPath($file); + } + self :: $CssFiles[$file]=$file; } /** @@ -1328,10 +1329,7 @@ class LSsession { self :: addCssFile("LSdefault.css"); $Css_txt=''; foreach (self :: $CssFiles as $file) { - if (!$file['path']) { - $file['path']=LS_CSS_DIR.'/'; - } - $Css_txt.="\n"; + $Css_txt.="\n"; } LStemplate :: assign('LSsession_css',$Css_txt); diff --git a/public_html/includes/class/class.LStemplate.php b/public_html/includes/class/class.LStemplate.php index 669cf937..984577c0 100644 --- a/public_html/includes/class/class.LStemplate.php +++ b/public_html/includes/class/class.LStemplate.php @@ -36,6 +36,7 @@ class LStemplate { * 'smarty_path' => '/path/to/Smarty.php', * 'template_dir' => '/path/to/template/directory', * 'image_dir' => '/path/to/image/directory', + * 'css_dir' => '/path/to/css/directory', * 'compile_dir' => '/path/to/compile/directory', * 'debug' => True, * 'debug_smarty' => True @@ -46,6 +47,7 @@ class LStemplate { 'smarty_path' => 'smarty/libs/Smarty.class.php', 'template_dir' => 'templates', 'image_dir' => 'images', + 'css_dir' => 'css', 'compile_dir' => 'tmp', 'debug' => False, 'debug_smarty' => False @@ -116,8 +118,6 @@ class LStemplate { die(_("LStemplate : Smarty version not recognized.")); } - self :: $_smarty -> assign('LS_CSS_DIR',LS_CSS_DIR); - return True; } else { @@ -163,6 +163,16 @@ class LStemplate { return self :: $config['image_dir']."/default/$image.png"; } + /** + * Return the path of the CSS file to use + * + * @param[in] string $css The CSS name (eg: main.css) + * + * @retval string The path of the CSS file + **/ + public static function getCSSPath($css) { + return self :: getFilePath($css,self :: $config['css_dir']); + } /** * Return the path of the Smarty template file to use @@ -260,6 +270,11 @@ function LStemplate_smarty_img($params) { echo "image.php?i=$name"; } +function LStemplate_smarty_css($params) { + extract($params); + echo LStemplate :: getCSSPath($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 d28da83f..57d598d9 100644 --- a/public_html/includes/class/class.LStemplate_smarty2_support.php +++ b/public_html/includes/class/class.LStemplate_smarty2_support.php @@ -106,4 +106,5 @@ LStemplate :: $_smarty -> register_resource('ls', array( LStemplate :: $_smarty -> register_function('getFData','LStemplate_smarty_getFData'); LStemplate :: $_smarty -> register_function('tr','LStemplate_smarty_tr'); LStemplate :: $_smarty -> register_function('img','LStemplate_smarty_img'); +LStemplate :: $_smarty -> register_function('css','LStemplate_smarty_css'); diff --git a/public_html/includes/class/class.LStemplate_smarty3_support.php b/public_html/includes/class/class.LStemplate_smarty3_support.php index 4ed45a0f..36d43a36 100644 --- a/public_html/includes/class/class.LStemplate_smarty3_support.php +++ b/public_html/includes/class/class.LStemplate_smarty3_support.php @@ -64,4 +64,5 @@ LStemplate :: $_smarty -> registerResource('ls', new Smarty_Resource_LdapSaisie( LStemplate :: $_smarty -> registerPlugin("function","getFData", "LStemplate_smarty_getFData"); LStemplate :: $_smarty -> registerPlugin("function","tr", "LStemplate_smarty_tr"); LStemplate :: $_smarty -> registerPlugin("function","img", "LStemplate_smarty_img"); +LStemplate :: $_smarty -> registerPlugin("function","css", "LStemplate_smarty_css"); diff --git a/public_html/templates/default/blank.tpl b/public_html/templates/default/blank.tpl index 781f34ff..9e52c6e5 100644 --- a/public_html/templates/default/blank.tpl +++ b/public_html/templates/default/blank.tpl @@ -6,8 +6,8 @@ LdapSaisie{if $pagetitle != ''} - {$pagetitle}{/if} - - + + {$LSsession_css} diff --git a/public_html/templates/default/login.tpl b/public_html/templates/default/login.tpl index 29be8bd4..3a4c88a7 100644 --- a/public_html/templates/default/login.tpl +++ b/public_html/templates/default/login.tpl @@ -5,7 +5,7 @@ LdapSaisie{if $pagetitle != ''} - {$pagetitle}{/if} - + {$LSsession_css} {$LSsession_js} diff --git a/public_html/templates/default/recoverpassword.tpl b/public_html/templates/default/recoverpassword.tpl index 0ca9c9c4..6a8eb286 100644 --- a/public_html/templates/default/recoverpassword.tpl +++ b/public_html/templates/default/recoverpassword.tpl @@ -4,7 +4,7 @@ LdapSaisie{if $pagetitle != ''} - {$pagetitle}{/if} - + {$LSsession_css} {$LSsession_js} diff --git a/public_html/templates/default/top.tpl b/public_html/templates/default/top.tpl index f252b439..1ee6562f 100644 --- a/public_html/templates/default/top.tpl +++ b/public_html/templates/default/top.tpl @@ -6,8 +6,8 @@ LdapSaisie{if $pagetitle != ''} - {$pagetitle}{/if} - - + + {$LSsession_css}