feature:2538 Make a unified messages management

use only $page['infos'] and $page['errors'] vars and and necessary template to all main pages

git-svn-id: http://piwigo.org/svn/trunk@12764 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
mistic100 2011-12-18 21:46:24 +00:00
parent f500499530
commit ca230a6f53
25 changed files with 83 additions and 186 deletions

View file

@ -31,15 +31,13 @@ include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
check_status(ACCESS_FREE); check_status(ACCESS_FREE);
//-------------------------------------------------------------- identification //-------------------------------------------------------------- identification
$errors = array();
$redirect_to = ''; $redirect_to = '';
if ( !empty($_GET['redirect']) ) if ( !empty($_GET['redirect']) )
{ {
$redirect_to = urldecode($_GET['redirect']); $redirect_to = urldecode($_GET['redirect']);
if ( is_a_guest() ) if ( is_a_guest() )
{ {
array_push($errors, l10n('You are not authorized to access the requested page')); array_push($page['errors'], l10n('You are not authorized to access the requested page'));
} }
} }
@ -48,7 +46,7 @@ if (isset($_POST['login']))
if (!isset($_COOKIE[session_name()])) if (!isset($_COOKIE[session_name()]))
{ {
array_push( array_push(
$errors, $page['errors'],
l10n('Cookies are blocked or not supported by your browser. You must enable cookies to connect.') l10n('Cookies are blocked or not supported by your browser. You must enable cookies to connect.')
); );
} }
@ -68,7 +66,7 @@ if (isset($_POST['login']))
} }
else else
{ {
array_push( $errors, l10n('Invalid password!') ); array_push($page['errors'], l10n('Invalid password!') );
} }
} }
} }
@ -96,12 +94,6 @@ if ($conf['allow_user_registration'])
$template->assign('U_REGISTER', get_root_url().'register.php' ); $template->assign('U_REGISTER', get_root_url().'register.php' );
} }
//-------------------------------------------------------------- errors display
if ( sizeof( $errors ) != 0 )
{
$template->assign('errors', $errors);
}
// include menubar // include menubar
$themeconf = $template->get_template_vars('themeconf'); $themeconf = $template->get_template_vars('themeconf');
if (!isset($themeconf['hide_menu_on']) OR !in_array('theIdentificationPage', $themeconf['hide_menu_on'])) if (!isset($themeconf['hide_menu_on']) OR !in_array('theIdentificationPage', $themeconf['hide_menu_on']))

View file

@ -63,7 +63,10 @@ if ( !empty($_SERVER["PATH_INFO"]) )
// rewriting of language and otherarray values via URI params // rewriting of language and otherarray values via URI params
// //
$conf = array(); $conf = array();
$page = array(); $page = array(
'infos' => array(),
'errors' => array(),
);
$user = array(); $user = array();
$lang = array(); $lang = array();
$header_msgs = array(); $header_msgs = array();

View file

@ -98,6 +98,22 @@ if ( isset( $refresh ) and intval($refresh) >= 0
)); ));
} }
// messages
foreach (array('errors','infos') as $mode)
{
if (isset($_SESSION['page_'.$mode]))
{
$page[$mode] = array_merge($page[$mode], $_SESSION['page_'.$mode]);
unset($_SESSION['page_'.$mode]);
}
if (count($page[$mode]) != 0)
{
$template->assign($mode, $page[$mode]);
}
}
trigger_action('loc_end_page_header'); trigger_action('loc_end_page_header');
header('Content-Type: text/html; charset='.get_pwg_charset()); header('Content-Type: text/html; charset='.get_pwg_charset());

View file

@ -53,28 +53,23 @@ if ( $page['show_comments'] and isset( $_POST['content'] ) )
include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php'); include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
$comment_action = insert_user_comment($comm, @$_POST['key'], $infos ); $comment_action = insert_user_comment($comm, @$_POST['key'], $page['infos']);
switch ($comment_action) switch ($comment_action)
{ {
case 'moderate': case 'moderate':
array_push( $infos, l10n('An administrator must authorize your comment before it is visible.') ); array_push($page['infos'], l10n('An administrator must authorize your comment before it is visible.') );
case 'validate': case 'validate':
array_push( $infos, l10n('Your comment has been registered')); array_push($page['infos'], l10n('Your comment has been registered'));
break; break;
case 'reject': case 'reject':
set_status_header(403); set_status_header(403);
array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules') ); array_push($page['errors'], l10n('Your comment has NOT been registered because it did not pass the validation rules') );
break; break;
default: default:
trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING); trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
} }
$template->assign(
($comment_action=='reject') ? 'errors' : 'infos',
$infos
);
// allow plugins to notify what's going on // allow plugins to notify what's going on
trigger_action( 'user_comment_insertion', trigger_action( 'user_comment_insertion',
array_merge($comm, array('action'=>$comment_action) ) array_merge($comm, array('action'=>$comment_action) )

15
nbm.php
View file

@ -37,13 +37,9 @@ trigger_action('loading_lang');
load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR, array('no_fallback'=>true, 'local'=>true) ); load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR, array('no_fallback'=>true, 'local'=>true) );
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// | Main | // | Main |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
$page['errors'] = array();
$page['infos'] = array();
if (isset($_GET['subscribe']) if (isset($_GET['subscribe'])
and preg_match('/^[A-Za-z0-9]{16}$/', $_GET['subscribe'])) and preg_match('/^[A-Za-z0-9]{16}$/', $_GET['subscribe']))
{ {
@ -68,16 +64,7 @@ $page['body_id'] = 'theNBMPage';
$template->set_filenames(array('nbm'=>'nbm.tpl')); $template->set_filenames(array('nbm'=>'nbm.tpl'));
// +-----------------------------------------------------------------------+
// | errors & infos |
// +-----------------------------------------------------------------------+
$template->assign(
array(
'errors' => $page['errors'],
'infos' => $page['infos'],
)
);
// include menubar // include menubar
$themeconf = $template->get_template_vars('themeconf'); $themeconf = $template->get_template_vars('themeconf');
if (!isset($themeconf['hide_menu_on']) OR !in_array('theNBMPage', $themeconf['hide_menu_on'])) if (!isset($themeconf['hide_menu_on']) OR !in_array('theNBMPage', $themeconf['hide_menu_on']))

View file

@ -240,10 +240,6 @@ function reset_password()
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
// | Process form | // | Process form |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
$page['errors'] = array();
$page['infos'] = array();
if (isset($_POST['submit'])) if (isset($_POST['submit']))
{ {
check_pwg_token(); check_pwg_token();
@ -345,12 +341,6 @@ $template->assign(
) )
); );
// +-----------------------------------------------------------------------+
// | infos & errors display |
// +-----------------------------------------------------------------------+
$template->assign('errors', $page['errors']);
$template->assign('infos', $page['infos']);
// include menubar // include menubar
$themeconf = $template->get_template_vars('themeconf'); $themeconf = $template->get_template_vars('themeconf');

View file

@ -189,8 +189,6 @@ function default_picture_content($content, $element_info)
// | initialization | // | initialization |
// +-----------------------------------------------------------------------+ // +-----------------------------------------------------------------------+
$infos = array();
// caching first_rank, last_rank, current_rank in the displayed // caching first_rank, last_rank, current_rank in the displayed
// section. This should also help in readability. // section. This should also help in readability.
$page['first_rank'] = 0; $page['first_rank'] = 0;
@ -338,22 +336,17 @@ UPDATE '.USER_CACHE_CATEGORIES_TABLE.'
switch ($comment_action) switch ($comment_action)
{ {
case 'moderate': case 'moderate':
array_push($infos, l10n('An administrator must authorize your comment before it is visible.')); array_push($page['infos'], l10n('An administrator must authorize your comment before it is visible.'));
case 'validate': case 'validate':
array_push($infos, l10n('Your comment has been registered')); array_push($page['infos'], l10n('Your comment has been registered'));
break; break;
case 'reject': case 'reject':
set_status_header(403); set_status_header(403);
array_push($infos, l10n('Your comment has NOT been registered because it did not pass the validation rules')); array_push($page['errors'], l10n('Your comment has NOT been registered because it did not pass the validation rules'));
break; break;
default: default:
trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING); trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
} }
$template->assign(
($comment_action=='reject') ? 'errors' : 'infos',
$infos
);
unset($_POST['content']); unset($_POST['content']);
break; break;

View file

@ -64,7 +64,7 @@ SELECT '.implode(',', $fields).'
$userdata = array_merge($userdata, $default_user); $userdata = array_merge($userdata, $default_user);
} }
save_profile_from_post($userdata, $errors); save_profile_from_post($userdata, $page['errors']);
$title= l10n('Your Gallery Customization'); $title= l10n('Your Gallery Customization');
$page['body_id'] = 'theProfilePage'; $page['body_id'] = 'theProfilePage';
@ -75,13 +75,6 @@ SELECT '.implode(',', $fields).'
make_index_url(), // for redirect make_index_url(), // for redirect
$userdata ); $userdata );
// +-----------------------------------------------------------------------+
// | errors display |
// +-----------------------------------------------------------------------+
if (count($errors) != 0)
{
$template->assign('errors', $errors);
}
// include menubar // include menubar
$themeconf = $template->get_template_vars('themeconf'); $themeconf = $template->get_template_vars('themeconf');

View file

@ -37,28 +37,27 @@ if (!$conf['allow_user_registration'])
page_forbidden('User registration closed'); page_forbidden('User registration closed');
} }
$errors = array();
if (isset($_POST['submit'])) if (isset($_POST['submit']))
{ {
if (!verify_ephemeral_key(@$_POST['key'])) if (!verify_ephemeral_key(@$_POST['key']))
{ {
set_status_header(403); set_status_header(403);
array_push($errors, 'Invalid/expired form key'); array_push($page['errors'], 'Invalid/expired form key');
} }
if ($_POST['password'] != $_POST['password_conf']) if ($_POST['password'] != $_POST['password_conf'])
{ {
array_push($errors, l10n('please enter your password again')); array_push($page['errors'], l10n('please enter your password again'));
} }
$errors = $page['errors'] =
register_user($_POST['login'], register_user($_POST['login'],
$_POST['password'], $_POST['password'],
$_POST['mail_address'], $_POST['mail_address'],
true, true,
$errors); $page['errors']);
if (count($errors) == 0) if (count($page['errors']) == 0)
{ {
$user_id = get_userid($_POST['login']); $user_id = get_userid($_POST['login']);
log_user($user_id, false); log_user($user_id, false);
@ -91,12 +90,6 @@ $template->assign(array(
'obligatory_user_mail_address' => $conf['obligatory_user_mail_address'], 'obligatory_user_mail_address' => $conf['obligatory_user_mail_address'],
)); ));
//-------------------------------------------------------------- errors display
if (count($errors) != 0)
{
$template->assign('errors', $errors);
}
// include menubar // include menubar
$themeconf = $template->get_template_vars('themeconf'); $themeconf = $template->get_template_vars('themeconf');
if (!isset($themeconf['hide_menu_on']) OR !in_array('theRegisterPage', $themeconf['hide_menu_on'])) if (!isset($themeconf['hide_menu_on']) OR !in_array('theRegisterPage', $themeconf['hide_menu_on']))

View file

@ -31,7 +31,6 @@ include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
check_status(ACCESS_GUEST); check_status(ACCESS_GUEST);
//------------------------------------------------------------------ form check //------------------------------------------------------------------ form check
$errors = array();
$search = array(); $search = array();
if (isset($_POST['submit'])) if (isset($_POST['submit']))
{ {
@ -148,11 +147,11 @@ INSERT INTO '.SEARCH_TABLE.'
} }
else else
{ {
array_push($errors, l10n('Empty query. No criteria has been entered.')); array_push($page['errors'], l10n('Empty query. No criteria has been entered.'));
} }
} }
//----------------------------------------------------------------- redirection //----------------------------------------------------------------- redirection
if (isset($_POST['submit']) and count($errors) == 0) if (isset($_POST['submit']) and count($page['errors']) == 0)
{ {
redirect( redirect(
make_index_url( make_index_url(
@ -222,11 +221,6 @@ SELECT id,name,global_rank,uppercats
;'; ;';
display_select_cat_wrapper($query, array(), 'category_options', false); display_select_cat_wrapper($query, array(), 'category_options', false);
//-------------------------------------------------------------- errors display
if (sizeof($errors) != 0)
{
$template->assign('errors', $errors);
}
// include menubar // include menubar
$themeconf = $template->get_template_vars('themeconf'); $themeconf = $template->get_template_vars('themeconf');

View file

@ -249,19 +249,15 @@
.infos { .infos {
color:#f70; color:#f70;
border:0; border:0;
background-color: transparent; background:transparent url(icon/infos.png) no-repeat center right;
margin-left:125px; margin-left:40px;
padding:5px 0px 0pt 10pt;
min-height: 48px;
text-align:left; text-align:left;
} }
.errors { .errors {
color:#f33; color:#f33;
border:0; border:0;
background: transparent url(icon/errors.png) no-repeat scroll right top; background:transparent url(icon/errors.png) no-repeat center right;
margin-left:125px; margin-left:40px;
padding:5px 0px 0pt 10pt;
min-height: 48px;
text-align:left; text-align:left;
font-weight:bold; font-weight:bold;
} }

View file

@ -8,6 +8,9 @@
</ul> </ul>
<h2>{'About'|@translate}</h2> <h2>{'About'|@translate}</h2>
</div> </div>
{include file='infos_errors.tpl'}
<div id="piwigoAbout"> <div id="piwigoAbout">
{$ABOUT_MESSAGE} {$ABOUT_MESSAGE}
{if isset($THEME_ABOUT) } {if isset($THEME_ABOUT) }

View file

@ -10,6 +10,8 @@
<h2>{'User comments'|@translate}</h2> <h2>{'User comments'|@translate}</h2>
</div> </div>
{include file='infos_errors.tpl'}
<form class="filter" action="{$F_ACTION}" method="get"> <form class="filter" action="{$F_ACTION}" method="get">
<fieldset> <fieldset>

View file

@ -10,15 +10,7 @@
<h2>{'Identification'|@translate}</h2> <h2>{'Identification'|@translate}</h2>
</div> </div>
{if isset($errors) } {include file='infos_errors.tpl'}
<div class="errors">
<ul>
{foreach from=$errors item=error}
<li>{$error}</li>
{/foreach}
</ul>
</div>
{/if}
<form action="{$F_LOGIN_ACTION}" method="post" name="login_form" class="properties"> <form action="{$F_LOGIN_ACTION}" method="post" name="login_form" class="properties">
<fieldset> <fieldset>

View file

@ -79,6 +79,8 @@
</div>{* <!-- titrePage --> *} </div>{* <!-- titrePage --> *}
{include file='infos_errors.tpl'}
{if !empty($PLUGIN_INDEX_CONTENT_BEGIN)}{$PLUGIN_INDEX_CONTENT_BEGIN}{/if} {if !empty($PLUGIN_INDEX_CONTENT_BEGIN)}{$PLUGIN_INDEX_CONTENT_BEGIN}{/if}
{if !empty($category_search_results)} {if !empty($category_search_results)}

View file

@ -0,0 +1,19 @@
{if isset($errors) }
<div class="errors">
<ul>
{foreach from=$errors item=error}
<li>{$error}</li>
{/foreach}
</ul>
</div>
{/if}
{if not empty($infos)}
<div class="infos">
<ul>
{foreach from=$infos item=info}
<li>{$info}</li>
{/foreach}
</ul>
</div>
{/if}

View file

@ -9,24 +9,6 @@
<h2>{'Notification'|@translate}</h2> <h2>{'Notification'|@translate}</h2>
</div> </div>
{if not empty($errors)} {include file='infos_errors.tpl'}
<div class="errors">
<ul>
{foreach from=$errors item=error}
<li>{$error}</li>
{/foreach}
</ul>
</div>
{/if}
{if not empty($infos)}
<div class="infos">
<ul>
{foreach from=$infos item=info}
<li>{$info}</li>
{/foreach}
</ul>
</div>
{/if}
</div> </div>

View file

@ -14,6 +14,8 @@
</ul> </ul>
<h2>{'Notification'|@translate}</h2> <h2>{'Notification'|@translate}</h2>
</div> </div>
{include file='infos_errors.tpl'}
<div class="notification"> <div class="notification">
<p>{'The RSS notification feed provides notification on news from this website : new photos, updated albums, new comments. Use a RSS feed reader.'|@translate}</p> <p>{'The RSS notification feed provides notification on news from this website : new photos, updated albums, new comments. Use a RSS feed reader.'|@translate}</p>

View file

@ -12,25 +12,7 @@
<h2>{$title}</h2> <h2>{$title}</h2>
</div> </div>
{if count($errors)} {include file='infos_errors.tpl'}
<div class="errors">
<ul>
{foreach from=$errors item=error}
<li>{$error}</li>
{/foreach}
</ul>
</div>
{/if}
{if count($infos)}
<div class="infos">
<ul>
{foreach from=$infos item=info}
<li>{$info}</li>
{/foreach}
</ul>
</div>
{/if}
{if $action ne 'none'} {if $action ne 'none'}
<form id="lostPassword" action="{$form_action}?action={$action}{if isset($key)}&amp;key={$key}{/if}" method="post"> <form id="lostPassword" action="{$form_action}?action={$action}{if isset($key)}&amp;key={$key}{/if}" method="post">

View file

@ -7,24 +7,7 @@
<div id="content" class="pictureContent"> <div id="content" class="pictureContent">
{/if} {/if}
{if isset($errors)} {include file='infos_errors.tpl'}
<div class="errors">
<ul>
{foreach from=$errors item=error}
<li>{$error}</li>
{/foreach}
</ul>
</div>
{/if}
{if isset($infos)}
<div class="infos">
<ul>
{foreach from=$infos item=info}
<li>{$info}</li>
{/foreach}
</ul>
</div>
{/if}
{if !empty($PLUGIN_PICTURE_BEFORE)}{$PLUGIN_PICTURE_BEFORE}{/if} {if !empty($PLUGIN_PICTURE_BEFORE)}{$PLUGIN_PICTURE_BEFORE}{/if}

View file

@ -1,16 +1,6 @@
{if isset($MENUBAR)}{$MENUBAR}{/if} {if isset($MENUBAR)}{$MENUBAR}{/if}
<div id="content" class="content"> <div id="content" class="content">
{if isset($errors)}
<div class="errors">
<ul>
{foreach from=$errors item=error}
<li>{$error}</li>
{/foreach}
</ul>
</div>
{/if}
<div class="titrePage"> <div class="titrePage">
<ul class="categoryActions"> <ul class="categoryActions">
<li><a href="{$U_HOME}" title="{'Home'|@translate}" class="pwg-state-default pwg-button"> <li><a href="{$U_HOME}" title="{'Home'|@translate}" class="pwg-state-default pwg-button">
@ -20,5 +10,7 @@
<h2>{'Profile'|@translate}</h2> <h2>{'Profile'|@translate}</h2>
</div> </div>
{include file='infos_errors.tpl'}
{$PROFILE_CONTENT} {$PROFILE_CONTENT}
</div> <!-- content --> </div> <!-- content -->

View file

@ -12,15 +12,7 @@
<h2>{'Registration'|@translate}</h2> <h2>{'Registration'|@translate}</h2>
</div> </div>
{if isset($errors)} {include file='infos_errors.tpl'}
<div class="errors">
<ul>
{foreach from=$errors item=error}
<li>{$error}</li>
{/foreach}
</ul>
</div>
{/if}
<form method="post" action="{$F_ACTION}" class="properties" name="register_form"> <form method="post" action="{$F_ACTION}" class="properties" name="register_form">
<fieldset> <fieldset>

View file

@ -30,15 +30,7 @@
<h2>{'Search'|@translate}</h2> <h2>{'Search'|@translate}</h2>
</div> </div>
{if isset($errors) } {include file='infos_errors.tpl'}
<div class="errors">
<ul>
{foreach from=$errors item=error}
<li>{$error}</li>
{/foreach}
</ul>
</div>
{/if}
<form class="filter" method="post" name="search" action="{$F_SEARCH_ACTION}"> <form class="filter" method="post" name="search" action="{$F_SEARCH_ACTION}">
<fieldset> <fieldset>

View file

@ -20,6 +20,8 @@
<h2>{'Tags'|@translate}</h2> <h2>{'Tags'|@translate}</h2>
</div> </div>
{include file='infos_errors.tpl'}
{if isset($tags)} {if isset($tags)}
{if $display_mode == 'cloud'} {if $display_mode == 'cloud'}
<div id="fullTagCloud"> <div id="fullTagCloud">

View file

@ -734,14 +734,14 @@ INPUT[type="radio"], INPUT[type="checkbox"] {
font-weight: bold; font-weight: bold;
margin: 5px; margin: 5px;
border: 1px solid red; border: 1px solid red;
background: #ffe1e1 url(icon/errors.png) no-repeat top right; background: #ffe1e1 url(icon/errors.png) no-repeat center right;
padding: 10px 50px 10px 10px; padding: 10px 50px 10px 10px;
} }
/* Informations box */ /* Informations box */
.infos { .infos {
color: #002000; color: #002000;
background: #98fb98 url(icon/infos.png) no-repeat top right; background: #98fb98 url(icon/infos.png) no-repeat center right;
margin: 5px; margin: 5px;
padding: 10px 50px 10px 10px; padding: 10px 50px 10px 10px;
} }