Manage CSS path with LStemplate

This commit is contained in:
Benjamin Renard 2013-06-19 03:06:29 +02:00
parent 89a46b0c75
commit 09432db48e
9 changed files with 35 additions and 20 deletions

View file

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

View file

@ -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.="<link rel='stylesheet' type='text/css' href='".$file['path'].$file['file']."' />\n";
$Css_txt.="<link rel='stylesheet' type='text/css' href='".$file."' />\n";
}
LStemplate :: assign('LSsession_css',$Css_txt);

View file

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

View file

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

View file

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

View file

@ -6,8 +6,8 @@
<meta http-equiv="content-type" content="text/html; charset={$LSencoding}">
<title>LdapSaisie{if $pagetitle != ''} - {$pagetitle}{/if}</title>
<link rel="icon" type="image/png" href="images/default/favicon.png" />
<link rel="stylesheet" type="text/css" href="{$LS_CSS_DIR}/base.css" title="Normal" />
<link rel="stylesheet" type="text/css" href="{$LS_CSS_DIR}/base_print.css" media='print' title="Normal" />
<link rel="stylesheet" type="text/css" href="{css name='base.css'}" title="Normal" />
<link rel="stylesheet" type="text/css" href="{css name='base_print.css'}" media='print' title="Normal" />
{$LSsession_css}
</head>
<body>

View file

@ -5,7 +5,7 @@
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>LdapSaisie{if $pagetitle != ''} - {$pagetitle}{/if}</title>
<link rel="icon" type="image/png" href="images/default/favicon.png" />
<link rel="stylesheet" type="text/css" href="{$LS_CSS_DIR}/login.css" media="screen" title="Normal" />
<link rel="stylesheet" type="text/css" href="{css name='login.css'}" media="screen" title="Normal" />
{$LSsession_css}
{$LSsession_js}
</head>

View file

@ -4,7 +4,7 @@
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>LdapSaisie{if $pagetitle != ''} - {$pagetitle}{/if}</title>
<link rel="stylesheet" type="text/css" href="{$LS_CSS_DIR}/recoverpassword.css" media="screen" title="Normal" />
<link rel="stylesheet" type="text/css" href="{css name='recoverpassword.css'}" media="screen" title="Normal" />
{$LSsession_css}
{$LSsession_js}
</head>

View file

@ -6,8 +6,8 @@
<meta http-equiv="content-type" content="text/html; charset={$LSencoding}">
<title>LdapSaisie{if $pagetitle != ''} - {$pagetitle}{/if}</title>
<link rel="icon" type="image/png" href="images/default/favicon.png" />
<link rel="stylesheet" type="text/css" href="{$LS_CSS_DIR}/base.css" title="Normal" />
<link rel="stylesheet" type="text/css" href="{$LS_CSS_DIR}/base_print.css" media='print' title="Normal" />
<link rel="stylesheet" type="text/css" href="{css name='base.css'}" title="Normal" />
<link rel="stylesheet" type="text/css" href="{css name='base_print.css'}" media='print' title="Normal" />
{$LSsession_css}
</head>
<body>