Manage image path with LStemplate

This commit is contained in:
Benjamin Renard 2013-06-19 00:53:26 +02:00
parent f4e97c8133
commit 6f97d3d7e0
19 changed files with 90 additions and 41 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -12,6 +12,6 @@
<div id='LSlang_select'>
{foreach from=$LSlanguages item=lang}
<img src='{$LS_IMAGES_DIR}/{$lang}.png' alt='{$lang}' title='{$lang}'/>
<img src='{img name=$lang}' alt='{$lang}' title='{$lang}'/>
{/foreach}
</div>

View file

@ -18,9 +18,9 @@
<div class='LSformElement_image{if $LSformElement_image_errors} LSformElement_image_errors{/if}'>
{if $LSformElement_image_actions!='' && !$LSformElement_image_errors}
<ul class='LSformElement_image_actions'>
<li><img src='{$LS_IMAGES_DIR}/zoom.png' class='LSformElement_image_actions LSformElement_image_action_zoom' id='LSformElement_image_action_zoom_{$LSformElement_image.id}' /></li>
<li><img src='{img name="zoom"}' class='LSformElement_image_actions LSformElement_image_action_zoom' id='LSformElement_image_action_zoom_{$LSformElement_image.id}' /></li>
{foreach from=$LSformElement_image_actions item=item}
<li><img src='{$LS_IMAGES_DIR}/{$item}.png' class='LSformElement_image_actions LSformElement_image_action_{$item}' id='LSformElement_image_action_{$item}_{$LSformElement_image.id}' /></li>
<li><img src='{img name=$item}' class='LSformElement_image_actions LSformElement_image_action_{$item}' id='LSformElement_image_action_{$item}_{$LSformElement_image.id}' /></li>
{/foreach}
</ul>
{/if}
@ -31,7 +31,7 @@
<dl class='LSform'>
{foreach from=$tab.args item=arg}
{if $LSform_fields[$arg]}
<dt class='LSform{if $LSform_fields[$arg].errors != ''} LSform-errors{/if}'>{$LSform_fields[$arg].label}{if $LSform_fields[$arg].required} *{/if}{if $LSform_fields[$arg].help_info!=""} <img class='LStips' src="{$LS_IMAGES_DIR}/help.png" alt='?' title="{$LSform_fields[$arg].help_info}"/>{/if}</dt>
<dt class='LSform{if $LSform_fields[$arg].errors != ''} LSform-errors{/if}'>{$LSform_fields[$arg].label}{if $LSform_fields[$arg].required} *{/if}{if $LSform_fields[$arg].help_info!=""} <img class='LStips' src="{img name='help'}" alt='?' title="{$LSform_fields[$arg].help_info}"/>{/if}</dt>
<dd class='LSform'>{$LSform_fields[$arg].html}{if $LSform_fields[$arg].add != ''} <span class='LSform-addfield'>+ Ajouter un champ</span>{/if}</dd>
{if $LSform_fields[$arg].errors != ''}
{foreach from=$LSform_fields[$arg].errors item=error}
@ -51,9 +51,9 @@
<div class='LSformElement_image{if $LSformElement_image_errors} LSformElement_image_errors{/if}'>
{if $LSformElement_image_actions!='' && !$LSformElement_image_errors}
<ul class='LSformElement_image_actions'>
<li><img src='{$LS_IMAGES_DIR}/zoom.png' class='LSformElement_image_actions LSformElement_image_action_zoom' id='LSformElement_image_action_zoom_{$LSformElement_image.id}' /></li>
<li><img src='{img name='zoom'}' class='LSformElement_image_actions LSformElement_image_action_zoom' id='LSformElement_image_action_zoom_{$LSformElement_image.id}' /></li>
{foreach from=$LSformElement_image_actions item=item}
<li><img src='{$LS_IMAGES_DIR}/{$item}.png' class='LSformElement_image_actions LSformElement_image_action_{$item}' id='LSformElement_image_action_{$item}_{$LSformElement_image.id}' /></li>
<li><img src='{img name=$item}' class='LSformElement_image_actions LSformElement_image_action_{$item}' id='LSformElement_image_action_{$item}_{$LSformElement_image.id}' /></li>
{/foreach}
</ul>
{/if}
@ -64,7 +64,7 @@
<div class='LSform'>
<dl class='LSform'>
{foreach from=$LSform_fields item=field}
<dt class='LSform{if $field.errors != ''} LSform-errors{/if}'>{$field.label}{if $field.required} *{/if}{if $field.help_info!=""} <img class='LStips' src="{$LS_IMAGES_DIR}/help.png" alt='?' title="{$field.help_info}"/>{/if}</dt>
<dt class='LSform{if $field.errors != ''} LSform-errors{/if}'>{$field.label}{if $field.required} *{/if}{if $field.help_info!=""} <img class='LStips' src="{img name='help'}" alt='?' title="{$field.help_info}"/>{/if}</dt>
<dd class='LSform'>{$field.html}{if $field.add != ''} <span class='LSform-addfield'>+ Ajouter un champ</span>{/if}</dd>
{if $field.errors != ''}
{foreach from=$field.errors item=error}

View file

@ -1,7 +1,7 @@
{if $freeze}
{if $value or $parseValue}
{if $parseValue}
<span class='LSformElement_supannLabeledValue'>{if $label}<img src='{$LS_IMAGES_DIR}/LSformElement_supannLabeledValue_label_{$label}.png' alt='[{$label}]' title='{$label}' /> {/if}<span title='{$parseValue.value}'>{$value}</span></span>
<span class='LSformElement_supannLabeledValue'>{if $label}<img src='{img name="LSformElement_supannLabeledValue_label_$label"}' alt='[{$label}]' title='{$label}' /> {/if}<span title='{$parseValue.value}'>{$value}</span></span>
{else}
<span class='LSformElement_supannLabeledValue_unparsed'>{$value}</span>
{/if}

View file

@ -1,7 +1,7 @@
{if $freeze}
{if $value or $parseValue}
{if $parseValue}
<span class='LSformElement_supannRoleEntite'>{if $label_role}<img src='{$LS_IMAGES_DIR}/LSformElement_supannRoleEntite_label_{$label_role}.png' alt='[{$label_role}]' title='{$label_role}' /> {/if}<span title='{$parseValue.role.value}'>{$role}</span> : {if $label_code}<img src='{$LS_IMAGES_DIR}/LSformElement_supannRoleEntite_label_{$label_code}.png' alt='[{$label_code}]' title='{$label_code}' /> {/if}<span title='{$parseValue.code.value}'>{$code}</span> ({if $label_type}<img src='{$LS_IMAGES_DIR}/LSformElement_supannRoleEntite_label_{$label_type}.png' alt='[{$label_type}]' title='{$label_type}' /> {/if}<span title='{$parseValue.type.value}'>{$type}</span>)</span>
<span class='LSformElement_supannRoleEntite'>{if $label_role}<img src='{img name="LSformElement_supannRoleEntite_label_$label_role}' alt='[{$label_role}]' title='{$label_role}' /> {/if}<span title='{$parseValue.role.value}'>{$role}</span> : {if $label_code}<img src='{img name="LSformElement_supannRoleEntite_label_$label_code"}' alt='[{$label_code}]' title='{$label_code}' /> {/if}<span title='{$parseValue.code.value}'>{$code}</span> ({if $label_type}<img src='{img name="LSformElement_supannRoleEntite_label_$label_type"}' alt='[{$label_type}]' title='{$label_type}' /> {/if}<span title='{$parseValue.type.value}'>{$type}</span>)</span>
{else}
<span class='LSformElement_supannRoleEntite_unparsed'>{$value}</span>
{/if}

View file

@ -2,7 +2,7 @@
{if $item.actions!=''}
<ul class='LSview-actions'>
{foreach from=$item.actions item=action}
<li class='LSview-actions'><a href='{$action.url}' class='LSview-actions LSrelation_modify' id='{$item.id}'><img src='{$LS_IMAGES_DIR}/{$action.action}.png' alt='{$action.label}' title='{$action.label}' /> {$action.label}</a></li>
<li class='LSview-actions'><a href='{$action.url}' class='LSview-actions LSrelation_modify' id='{$item.id}'><img src='{img name=$action.action}' alt='{$action.label}' title='{$action.label}' /> {$action.label}</a></li>
{/foreach}
</ul>
{/if}

View file

@ -14,7 +14,7 @@
{include file='ls:LSdefault.tpl'}
<div class='loginform'>
<img src='{$LS_IMAGES_DIR}/logo.png' alt='Logo' id='loginform_logo' />
<img src='{img name='logo.png' alt='Logo' id='loginform_logo' />
<div id='loading_zone'></div>
<form action='{$loginform_action}' method='post'>
<dl class='loginform'>
@ -39,7 +39,7 @@
<dd><input type='submit' value='{$loginform_label_submit}' /></dd>
</dl>
</form>
<span>{$lang_label} : <img id='LSlang' src='{$LS_IMAGES_DIR}/{$LSlang}.png' alt='{$LSlang}' title='{$LSlang}'/></span>
<span>{$lang_label} : <img id='LSlang' src='{img name=$LSlang}' alt='{$LSlang}' title='{$LSlang}'/></span>
<a href='index.php?LSsession_recoverPassword' class='LSsession_recoverPassword LSsession_recoverPassword_hidden'>{$loginform_label_recoverPassword}</a>
</div>
</body>

View file

@ -3,7 +3,7 @@
{if $LSview_actions != ''}
<ul class='LSview-actions'>
{foreach from=$LSview_actions item=item}
<li class='LSview-actions'><a href='{$item.url}' class='LSview-actions'><img src='{$LS_IMAGES_DIR}/{$item.action}.png' alt='{$item.label}' title='{$item.label}' /> {$item.label}</a></li>
<li class='LSview-actions'><a href='{$item.url}' class='LSview-actions'><img src='{img name=$item.action}' alt='{$item.label}' title='{$item.label}' /> {$item.label}</a></li>
{/foreach}
</ul>
{/if}

View file

@ -3,7 +3,7 @@
{if $LSview_actions != ''}
<p class='LSview-actions'>
{foreach from=$LSview_actions item=item}
<a href='{$item.url}' class='LSview-actions'><img src='{$LS_IMAGES_DIR}/{$item.action}.png' alt='{$item.label}' title='{$item.label}' /></a>
<a href='{$item.url}' class='LSview-actions'><img src='{img name=$item.action}' alt='{$item.label}' title='{$item.label}' /></a>
{/foreach}
</p>
{/if}

View file

@ -13,7 +13,7 @@
{include file='ls:LSdefault.tpl'}
<div class='recoverpasswordform'>
<img src='{$LS_IMAGES_DIR}/logo.png' alt='Logo' id='recoverpasswordform_logo' />
<img src='{img name='logo'}' alt='Logo' id='recoverpasswordform_logo' />
<div id='loading_zone'></div>
<form action='{$recoverpasswordform_action}' method='post'>
<dl class='recoverpasswordform'>
@ -28,7 +28,7 @@
</form>
<p id='recoverpassword_msg'>{$recoverpassword_msg}</p>
<span>{$lang_label} : <img id='LSlang' src='{$LS_IMAGES_DIR}/{$LSlang}.png' alt='{$LSlang}' title='{$LSlang}'/></span>
<span>{$lang_label} : <img id='LSlang' src='{img name=$LSlang}' alt='{$LSlang}' title='{$LSlang}'/></span>
<a href='index.php' id='recoverpassword_back'>{$recoverpasswordform_label_back}</a>
</div>
</body>

View file

@ -18,7 +18,7 @@
<div class='LSselect_search'>
<input type='text' name='pattern' class='LSview_search' value="{$searchForm.values.pattern}"/>
<input type='submit' value='{$searchForm.labels.submit}' name='{$searchForm.names.submit}' class='LSview_search' />
<img src='{$LS_IMAGES_DIR}/refresh.png' alt='{$searchForm.labels.refresh}' title='{$searchForm.labels.refresh}' id='LSselect_refresh_btn' />
<img src='{img name='refresh'}' alt='{$searchForm.labels.refresh}' title='{$searchForm.labels.refresh}' id='LSselect_refresh_btn' />
<p id='LSview_search_param'>
<label class='LSview_search'>{$searchForm.labels.approx} : <input type='checkbox' name='approx' class='LSview_search' {if $searchForm.values.approx!=''}checked="true"{/if} /></label>
{if $searchForm.recursive}<label class='LSview_search'>{$searchForm.labels.recursive} : <input type='checkbox' name='recursive' class='LSview_search' {if $searchForm.values.recursive!=''}checked="true"{/if}/></label>{/if}

View file

@ -4,7 +4,7 @@
<th class='LSobject-list{if $LSsearch->sort} sortBy_displayName{/if}'>
{if $LSsearch->sortBy == 'displayName'}
<strong>{$LSsearch->label_objectName}</strong>
<img src='{$LS_IMAGES_DIR}/{$LSsearch->sortDirection}.png' class='LSobject-list-ordersense' alt='{$LSsearch->sortDirection}'/>
<img src='{img name=$LSsearch->sortDirection}' class='LSobject-list-ordersense' alt='{$LSsearch->sortDirection}'/>
{else}
{$LSsearch->label_objectName}
{/if}
@ -14,7 +14,7 @@
{if $LSsearch->sort}
{if $LSsearch->sortBy == 'subDn'}
<strong>{$LSsearch->label_level}</strong>
<img src='{$LS_IMAGES_DIR}/{$LSsearch->sortDirection}.png' class='LSobject-list-ordersense' alt='{$LSsearch->sortDirection}'/>
<img src='{img name=$LSsearch->sortDirection}' class='LSobject-list-ordersense' alt='{$LSsearch->sortDirection}'/>
{else}
{$LSsearch->label_level}
{/if}

View file

@ -17,12 +17,12 @@
<table id='main'>
<tr>
<td rowspan=2 id='left'>
<a href='index.php'><img src='{$LS_IMAGES_DIR}/logo.png' alt='Logo' id='logo'/></a>
<a href='index.php'><img src='{img name='logo'}' alt='Logo' id='logo'/></a>
{if $LSsession_subDn!=""}
<form action="index.php" method='post' id='LSsession_topDn_form'>
<label>{$label_level}
<a href="index.php?LSsession_refresh"><img src='{$LS_IMAGES_DIR}/refresh.png' alt='{$_refresh}' title='{$_refresh}' /></a>
<a href="index.php?LSsession_refresh"><img src='{img name='refresh'}' alt='{$_refresh}' title='{$_refresh}' /></a>
<select name='LSsession_topDn' id='LSsession_topDn'>
{html_options values=$LSsession_subDn_indexes output=$LSsession_subDn_names selected=$LSsession_subDn}
</select>
@ -36,7 +36,7 @@
</ul>
</td>
<td id='status'>
<span>{$lang_label} : <img id='LSlang' src='{$LS_IMAGES_DIR}/{$LSlang}.png' alt='{$LSlang}' title='{$LSlang}'/></span>
<span>{$lang_label} : <img id='LSlang' src='{img name=$LSlang}' alt='{$LSlang}' title='{$LSlang}'/></span>
<form action='' methode='post' style='display: none' class='LSlang_hidden'>
<select name='lang'>
{foreach from=$LSlanguages item=lang}
@ -45,7 +45,7 @@
</select>
<input type='submit' value='->'/>
</form>
{if $displaySelfAccess}{$connected_as} <span id='user_name'>{$LSsession_username}</span>{/if}{if $displayLogoutBtn} <a href='index.php?LSsession_logout'><img src='{$LS_IMAGES_DIR}/logout.png' alt='Logout' title='Logout' /></a>{/if}
{if $displaySelfAccess}{$connected_as} <span id='user_name'>{$LSsession_username}</span>{/if}{if $displayLogoutBtn} <a href='index.php?LSsession_logout'><img src='{img name='logout'}' alt='Logout' title='Logout' /></a>{/if}
</td>
</tr>
<tr>

View file

@ -4,7 +4,7 @@
<ul class='LSview-actions'>
{foreach from=$LSview_actions item=item}
{if is_array($item)}
<li class='LSview-actions'><a href='{$item.url}' class='LSview-actions{if $item.class} {$item.class}{/if}' ><img src='{$LS_IMAGES_DIR}/{$item.action}.png' alt='{$item.label}' title='{$item.label}' />{if !isset($item.hideLabel) || !$item.hideLabel} {$item.label}{/if}</a></li>
<li class='LSview-actions'><a href='{$item.url}' class='LSview-actions{if $item.class} {$item.class}{/if}' ><img src='{img name=$item.action}' alt='{$item.label}' title='{$item.label}' />{if !isset($item.hideLabel) || !$item.hideLabel} {$item.label}{/if}</a></li>
{/if}
{/foreach}
</ul>

View file

@ -22,7 +22,7 @@
<ul class='LSview-actions'>
{foreach from=$LSview_actions item=item}
{if is_array($item)}
<li class='LSview-actions'><a href='{$item.url}' class='LSview-actions'><img src='{$LS_IMAGES_DIR}/{$item.action}.png' alt='{tr msg=$label}' title='{tr msg=$label}' /> {tr msg=$item.label}</a></li>
<li class='LSview-actions'><a href='{$item.url}' class='LSview-actions'><img src='{img name=$item.action}' alt='{tr msg=$label}' title='{tr msg=$label}' /> {tr msg=$item.label}</a></li>
{/if}
{/foreach}
</ul>
@ -45,7 +45,7 @@
<a href='view.php?LSobject={$LSsearch->LSobject}&amp;sortBy=displayName&amp;nocache={$smarty.now}'>
{if $LSsearch->sortBy == 'displayName'}
<strong>{$LSsearch->label_objectName}</strong>
<img src='{$LS_IMAGES_DIR}/{$LSsearch->sortDirection}.png' class='LSobject-list-ordersense' alt='{$LSsearch->sortDirection}'/>
<img src='{img name=$LSsearch->sortDirection}' class='LSobject-list-ordersense' alt='{$LSsearch->sortDirection}'/>
{else}
{$LSsearch->label_objectName}
{/if}
@ -60,7 +60,7 @@
<a href='view.php?LSobject={$LSsearch->LSobject}&amp;sortBy=subDn&amp;nocache={$smarty.now}'>
{if $LSsearch->sortBy == 'subDn'}
<strong>{$LSsearch->label_level}</strong>
<img src='{$LS_IMAGES_DIR}/{$LSsearch->sortDirection}.png' class='LSobject-list-ordersense' alt='{$LSsearch->sortDirection}'/>
<img src='{img name=$LSsearch->sortDirection}' class='LSobject-list-ordersense' alt='{$LSsearch->sortDirection}'/>
{else}
{$LSsearch->label_level}
{/if}
@ -78,7 +78,7 @@
{if $LSsearch->displaySubDn}<td class='LSobject-list'>{$object->subDn}</td>{/if}
<td class='LSobject-list LSobject-list-actions'>
{foreach from=$object->actions item=item}
<a href='{$item.url}' class='LSobject-list-actions'><img src='{$LS_IMAGES_DIR}/{$item.action}.png' alt='{$item.label}' title='{$item.label}'/></a>
<a href='{$item.url}' class='LSobject-list-actions'><img src='{img name=$item.action}' alt='{$item.label}' title='{$item.label}'/></a>
{/foreach}
</td>
</tr>