Rework on template files to use blocks

This commit is contained in:
Benjamin Renard 2020-05-07 12:16:12 +02:00
parent cd8908391d
commit de73ffdd60
21 changed files with 106 additions and 112 deletions

View file

@ -393,4 +393,5 @@ input[type='submit'].LSview_search {
max-width: 50%; max-width: 50%;
border-radius: 1em; border-radius: 1em;
font-weight: bold; font-weight: bold;
white-space: pre-wrap;
} }

View file

@ -651,7 +651,7 @@ class LSsession {
self :: displayLoginForm(); self :: displayLoginForm();
} }
else { else {
self :: setTemplate('blank.tpl'); self :: setTemplate('base.tpl');
LSerror :: addErrorCode('LSsession_10'); LSerror :: addErrorCode('LSsession_10');
} }
return; return;
@ -934,6 +934,19 @@ class LSsession {
return self :: $LSuserObject; return self :: $LSuserObject;
} }
/**
* Check if user is connected
*
* @author Benjamin Renard <brenard@easter-eggs.com
*
* @retval boolean True if user connected, false instead
*/
public static function isConnected() {
if (self :: $LSuserObject)
return true;
return false;
}
/** /**
* Retourne le DN de l'utilisateur connecté * Retourne le DN de l'utilisateur connecté
* *
@ -1423,7 +1436,7 @@ class LSsession {
LSdebug_print(); LSdebug_print();
} }
if (!self :: $template) if (!self :: $template)
self :: setTemplate('empty.tpl'); self :: setTemplate('base_connected.tpl');
LStemplate :: assign('connected_as',_("Connected as")); LStemplate :: assign('connected_as',_("Connected as"));

View file

@ -67,6 +67,12 @@ class LStemplate {
// Registered events // Registered events
private static $_events = array(); private static $_events = array();
// Deprecated templates files
private static $deprecated_template_files = array (
'accueil.tpl', 'blank.tpl', 'empty.tpl',
'top.tpl', 'bottom.tpl',
);
/** /**
* Start LStemplate * Start LStemplate
* *
@ -261,12 +267,19 @@ class LStemplate {
/** /**
* Return the path of the Smarty template file to use * Return the path of the Smarty template file to use
* *
* @param[in] string $template The template name (eg: top.tpl) * @param[in] string $template The template name (eg: base.tpl)
* @param[in] bool $with_nocache If true, include nocache URL param (default: false) * @param[in] bool $with_nocache If true, include nocache URL param (default: false)
* *
* @retval string The path of the Smarty template file * @retval string The path of the Smarty template file
**/ **/
public static function getTemplatePath($template, $with_nocache=false) { public static function getTemplatePath($template, $with_nocache=false) {
if (in_array($template, self :: $deprecated_template_files))
LSlog :: fatal(
getFData(
_("LStemplate : Request template '%{tpl}' is now deprecated. Please refer to upgrade documentation to adapt your templates."),
$template
)
);
return self :: getFilePath($template, self :: $config['template_dir'], null, $with_nocache); return self :: getFilePath($template, self :: $config['template_dir'], null, $with_nocache);
} }
@ -287,7 +300,7 @@ class LStemplate {
/** /**
* Return the content of a Smarty template file. * Return the content of a Smarty template file.
* *
* @param[in] string $template The template name (eg: top.tpl) * @param[in] string $template The template name (eg: base.tpl)
* *
* @retval string The content of the Smarty template file * @retval string The content of the Smarty template file
**/ **/
@ -299,7 +312,7 @@ class LStemplate {
// template name in lower first systematically // template name in lower first systematically
return ''; return '';
} }
$tpl_path=self :: getTemplatePath('empty.tpl'); $tpl_path = self :: getTemplatePath(LSsession :: isConnected()?'base_connected.tpl':'base.tpl');
LSerror::addErrorCode('LStemplate_01',$template); LSerror::addErrorCode('LStemplate_01',$template);
} }
return implode('',file($tpl_path)); return implode('',file($tpl_path));
@ -309,7 +322,7 @@ class LStemplate {
* Return the timestamp of the last change of a Smarty * Return the timestamp of the last change of a Smarty
* template file. * template file.
* *
* @param[in] string $template The template name (eg: top.tpl) * @param[in] string $template The template name (eg: base.tpl)
* *
* @retval string The timestamp of the last change of the Smarty template file * @retval string The timestamp of the last change of the Smarty template file
**/ **/
@ -338,7 +351,7 @@ class LStemplate {
/** /**
* Display a template * Display a template
* *
* @param[in] string $template The template name (eg: empty.tpl) * @param[in] string $template The template name (eg: base_connected.tpl)
* *
* @retval void * @retval void
**/ **/
@ -361,7 +374,7 @@ class LStemplate {
/** /**
* Fetch a template * Fetch a template
* *
* @param[in] string $template The template name (eg: empty.tpl) * @param[in] string $template The template name (eg: base_connected.tpl)
* *
* @retval string The template compiled * @retval string The template compiled
**/ **/

View file

@ -39,7 +39,7 @@ function handle_index($request) {
LStemplate :: assign('pagetitle', _('Home')); LStemplate :: assign('pagetitle', _('Home'));
// Template // Template
LSsession :: setTemplate('accueil.tpl'); LSsession :: setTemplate('homepage.tpl');
// Display template // Display template
LSsession :: displayTemplate(); LSsession :: displayTemplate();

View file

@ -1,4 +1,5 @@
{include file='ls:top.tpl'} {extends file='ls:base_connected.tpl'}
{block name="content"}
<div id='LSaccessRightsMatrixView'> <div id='LSaccessRightsMatrixView'>
<h1>{$pagetitle}</h1> <h1>{$pagetitle}</h1>
<ul class="LSaccessRightsMatrixView_tabs"> <ul class="LSaccessRightsMatrixView_tabs">
@ -84,4 +85,4 @@
{/if} {/if}
</div> </div>
</div> </div>
{include file='ls:bottom.tpl'} {/block}

View file

@ -1,3 +0,0 @@
{include file='ls:top.tpl'}
<h1>{$pagetitle}</h1>
{include file='ls:bottom.tpl'}

View file

@ -6,15 +6,20 @@
<title>LdapSaisie{if $pagetitle != ''} - {$pagetitle|escape:"htmlall"}{/if}</title> <title>LdapSaisie{if $pagetitle != ''} - {$pagetitle|escape:"htmlall"}{/if}</title>
<base href="{$public_root_url}/"/> <base href="{$public_root_url}/"/>
<link rel="icon" href="image/favicon" /> <link rel="icon" href="image/favicon" />
{block name="css"}
<link rel="stylesheet" type="text/css" href="{css name='base.css'}" 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" /> <link rel="stylesheet" type="text/css" href="{css name='base_print.css'}" media='print' title="Normal" />
{include file='ls:LSsession_css.tpl'} {include file='ls:LSsession_css.tpl'}
{/block}
{block name="head"}{/block}
</head> </head>
<body> <body>
{include file='ls:LSdefault.tpl'} {include file='ls:LSdefault.tpl'}
{include file='ls:LSsession_js.tpl'} {block name="body"}{/block}
{include file='ls:LSsession_js.tpl'}
{block name="js"}{/block}
</body> </body>
</html> </html>

View file

@ -1,19 +1,5 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" {extends file='ls:base.tpl'}
"http://www.w3.org/TR/html4/loose.dtd"> {block name="body"}
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset={$LSencoding}">
<title>LdapSaisie{if $pagetitle != ''} - {$pagetitle|escape:"htmlall"}{/if}</title>
<base href="{$public_root_url}/"/>
<link rel="icon" href="image/favicon" />
<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" />
{include file='ls:LSsession_css.tpl'}
</head>
<body>
{include file='ls:LSdefault.tpl'}
<table id='main'> <table id='main'>
<tr> <tr>
<td rowspan=2 id='left'> <td rowspan=2 id='left'>
@ -66,3 +52,10 @@
</tr> </tr>
<tr> <tr>
<td id='right'> <td id='right'>
{block name="content"}{/block}
</td>
</tr>
</table>
{/block}

View file

@ -1,6 +0,0 @@
</td>
</tr>
</table>
{include file='ls:LSsession_js.tpl'}
</body>
</html>

View file

@ -1,4 +1,5 @@
{include file='ls:top.tpl'} {extends file='ls:base_connected.tpl'}
{block name="content"}
{if $pagetitle != ''}<h1 id='LSform_title'>{$pagetitle|escape:"htmlall"}</h1>{/if} {if $pagetitle != ''}<h1 id='LSform_title'>{$pagetitle|escape:"htmlall"}</h1>{/if}
{if !empty($listAvailableDataEntryForm)} {if !empty($listAvailableDataEntryForm)}
@ -11,4 +12,4 @@
{/if} {/if}
{include file='ls:LSform.tpl'} {include file='ls:LSform.tpl'}
{include file='ls:bottom.tpl'} {/block}

View file

@ -1,2 +0,0 @@
{include file='ls:top.tpl'}
{include file='ls:bottom.tpl'}

View file

@ -1,18 +1,12 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" {if isset($LSsession_username) && $LSsession_username}
"http://www.w3.org/TR/html4/loose.dtd"> {assign var="extended_tpl" value="ls:base_connected.tpl"}
<html> {assign var="extended_block" value="content"}
<head> {else}
<meta http-equiv="content-type" content="text/html; charset={$LSencoding}"> {assign var="extended_tpl" value="ls:base.tpl"}
<title>LdapSaisie - {if isset($pagetitle) && $pagetitle}{$pagetitle|escape:"htmlall"}{else}{$error}{/if}</title> {assign var="extended_block" value="body"}
<base href="{$public_root_url}/"/> {/if}
<link rel="icon" href="image/favicon" /> {extends file=$extended_tpl}
<link rel="stylesheet" type="text/css" href="{css name='base.css'}" title="Normal" /> {block name=$extended_block}
<link rel="stylesheet" type="text/css" href="{css name='base_print.css'}" media='print' title="Normal" />
{include file='ls:LSsession_css.tpl'}
</head>
<body>
{include file='ls:LSdefault.tpl'}
<div id="error"> <div id="error">
<h1>{$error}</h1> <h1>{$error}</h1>
@ -24,6 +18,4 @@
{/if} {/if}
</div> </div>
{include file='ls:LSsession_js.tpl'} {/block}
</body>
</html>

View file

@ -1,6 +1,5 @@
{include file='ls:top.tpl'} {extends file='ls:base_connected.tpl'}
{block name="content"}
<form action='search' method='post' class='LSview_search' id='LSsearch_form'> <form action='search' method='post' class='LSview_search' id='LSsearch_form'>
<div class='LSview_search'> <div class='LSview_search'>
<input type='text' name='pattern' class='LSview_search' value='{$pattern|escape:"htmlall"}'/> <input type='text' name='pattern' class='LSview_search' value='{$pattern|escape:"htmlall"}'/>
@ -26,4 +25,4 @@
{/foreach} {/foreach}
</form> </form>
{include file='ls:bottom.tpl'} {/block}

View file

@ -0,0 +1,4 @@
{extends file='ls:base_connected.tpl'}
{block name="content"}
<h1>{$pagetitle}</h1>
{/block}

View file

@ -1,4 +1,5 @@
{include file='ls:top.tpl'} {extends file='ls:base_connected.tpl'}
{block name="content"}
{if $pagetitle != ''}<h1 id='LSview_title'>{$pagetitle|escape:"htmlall"}</h1>{/if} {if $pagetitle != ''}<h1 id='LSview_title'>{$pagetitle|escape:"htmlall"}</h1>{/if}
<div class='LSform'> <div class='LSform'>
@ -86,4 +87,4 @@
{/if} {/if}
{/if} {/if}
{include file='ls:bottom.tpl'} {/block}

View file

@ -1,18 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" {extends file='ls:base.tpl'}
"http://www.w3.org/TR/html4/loose.dtd"> {block name="css"}
<html> <link rel="stylesheet" type="text/css" href="{css name='login.css'}" media="screen" title="Normal" />
<head> {include file='ls:LSsession_css.tpl'}
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> {/block}
<title>LdapSaisie{if $pagetitle != ''} - {$pagetitle|escape:"htmlall"}{/if}</title> {block name="body"}
<base href="{$public_root_url}/"/>
<link rel="icon" href="image/favicon" />
<link rel="stylesheet" type="text/css" href="{css name='login.css'}" media="screen" title="Normal" />
{include file='ls:LSsession_css.tpl'}
</head>
<body>
{include file='ls:LSdefault.tpl'}
<div class='loginform'> <div class='loginform'>
<img src='{img name='logo'}' alt='Logo' id='loginform_logo' /> <img src='{img name='logo'}' alt='Logo' id='loginform_logo' />
<div id='loading_zone'></div> <div id='loading_zone'></div>
@ -42,6 +33,4 @@
<span>{tr msg="Language"} : <img id='LSlang' src='{img name=$LSlang}' alt='{$LSlang|escape:"htmlall"}' title='{$LSlang|escape:"htmlall"}'/></span> <span>{tr msg="Language"} : <img id='LSlang' src='{img name=$LSlang}' alt='{$LSlang|escape:"htmlall"}' title='{$LSlang|escape:"htmlall"}'/></span>
<a href='?LSsession_recoverPassword' class='LSsession_recoverPassword LSsession_recoverPassword_hidden'>{tr msg="Forgot your password ?"}</a> <a href='?LSsession_recoverPassword' class='LSsession_recoverPassword LSsession_recoverPassword_hidden'>{tr msg="Forgot your password ?"}</a>
</div> </div>
{include file='ls:LSsession_js.tpl'} {/block}
</body>
</html>

View file

@ -1,4 +1,5 @@
{include file='ls:top.tpl'} {extends file='ls:base_connected.tpl'}
{block name="content"}
{if $pagetitle != ''}<h1 id='LSform_title'>{$pagetitle|escape:"htmlall"}</h1>{/if} {if $pagetitle != ''}<h1 id='LSform_title'>{$pagetitle|escape:"htmlall"}</h1>{/if}
{if $LSview_actions != ''} {if $LSview_actions != ''}
<ul class='LSview-actions'> <ul class='LSview-actions'>
@ -9,5 +10,4 @@
{/if} {/if}
{include file='ls:LSform.tpl'} {include file='ls:LSform.tpl'}
{/block}
{include file='ls:bottom.tpl'}

View file

@ -1,4 +1,5 @@
{include file='ls:top.tpl'} {extends file='ls:base_connected.tpl'}
{block name="content"}
{if $pagetitle != ''}<h1>{$pagetitle|escape:"htmlall"}</h1>{/if} {if $pagetitle != ''}<h1>{$pagetitle|escape:"htmlall"}</h1>{/if}
{if $LSview_actions != ''} {if $LSview_actions != ''}
<p class='LSview-actions'> <p class='LSview-actions'>
@ -10,4 +11,4 @@
<p class='question'>{$question}</p> <p class='question'>{$question}</p>
<a href='{$validation_url}' class='question'>{$validation_label|escape:"htmlall"}</a> <a href='{$validation_url}' class='question'>{$validation_label|escape:"htmlall"}</a>
{include file='ls:bottom.tpl'} {/block}

View file

@ -1,17 +1,9 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" {extends file='ls:base.tpl'}
"http://www.w3.org/TR/html4/loose.dtd"> {block name="css"}
<html> <link rel="stylesheet" type="text/css" href="{css name='recoverpassword.css'}" media="screen" title="Normal" />
<head> {include file='ls:LSsession_css.tpl'}
<meta http-equiv="content-type" content="text/html; charset=UTF-8"> {/block}
<title>LdapSaisie{if $pagetitle != ''} - {$pagetitle|escape:"htmlall"}{/if}</title> {block name="body"}
<base href="{$public_root_url}/"/>
<link rel="stylesheet" type="text/css" href="{css name='recoverpassword.css'}" media="screen" title="Normal" />
{include file='ls:LSsession_css.tpl'}
</head>
<body>
{include file='ls:LSdefault.tpl'}
<div class='recoverpasswordform'> <div class='recoverpasswordform'>
<img src='{img name='logo'}' alt='Logo' id='recoverpasswordform_logo' /> <img src='{img name='logo'}' alt='Logo' id='recoverpasswordform_logo' />
<div id='loading_zone'></div> <div id='loading_zone'></div>
@ -33,6 +25,4 @@
<span>{tr msg="Language"} : <img id='LSlang' src='{img name=$LSlang}' alt='{$LSlang|escape:"htmlall"}' title='{$LSlang|escape:"htmlall"}'/></span> <span>{tr msg="Language"} : <img id='LSlang' src='{img name=$LSlang}' alt='{$LSlang|escape:"htmlall"}' title='{$LSlang|escape:"htmlall"}'/></span>
<a href='' id='recoverpassword_back'>{tr msg="Back"}</a> <a href='' id='recoverpassword_back'>{tr msg="Back"}</a>
</div> </div>
{include file='ls:LSsession_js.tpl'} {/block}
</body>
</html>

View file

@ -1,4 +1,5 @@
{include file='ls:top.tpl'} {extends file='ls:base_connected.tpl'}
{block name="content"}
{if $pagetitle != ''}<h1 id='LSview_title'>{$pagetitle|escape:"htmlall"}</h1>{/if} {if $pagetitle != ''}<h1 id='LSview_title'>{$pagetitle|escape:"htmlall"}</h1>{/if}
{if $LSview_actions != ''} {if $LSview_actions != ''}
<ul class='LSview-actions'> <ul class='LSview-actions'>
@ -30,4 +31,4 @@
{include file='ls:LSrelations.tpl'} {include file='ls:LSrelations.tpl'}
{/foreach} {/foreach}
{/if} {/if}
{include file='ls:bottom.tpl'} {/block}

View file

@ -1,4 +1,5 @@
{include file='ls:top.tpl'} {extends file='ls:base_connected.tpl'}
{block name="content"}
<form action='{$searchForm.action}' method='post' class='LSview_search' id='LSsearch_form'> <form action='{$searchForm.action}' method='post' class='LSview_search' id='LSsearch_form'>
<div class='LSview_search'> <div class='LSview_search'>
@ -174,4 +175,4 @@
{/if} {/if}
</p> </p>
{/if} {/if}
{include file='ls:bottom.tpl'} {/block}