Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mistic100 committed Dec 18, 2011
1 parent f500499 commit ca230a6
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 186 deletions.
14 changes: 3 additions & 11 deletions identification.php
Expand Up @@ -31,15 +31,13 @@
check_status(ACCESS_FREE);

//-------------------------------------------------------------- identification
$errors = array();

$redirect_to = '';
if ( !empty($_GET['redirect']) )
{
$redirect_to = urldecode($_GET['redirect']);
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'));
}
}

Expand All @@ -48,7 +46,7 @@
if (!isset($_COOKIE[session_name()]))
{
array_push(
$errors,
$page['errors'],
l10n('Cookies are blocked or not supported by your browser. You must enable cookies to connect.')
);
}
Expand All @@ -68,7 +66,7 @@
}
else
{
array_push( $errors, l10n('Invalid password!') );
array_push($page['errors'], l10n('Invalid password!') );
}
}
}
Expand Down Expand Up @@ -96,12 +94,6 @@
$template->assign('U_REGISTER', get_root_url().'register.php' );
}

//-------------------------------------------------------------- errors display
if ( sizeof( $errors ) != 0 )
{
$template->assign('errors', $errors);
}

// include menubar
$themeconf = $template->get_template_vars('themeconf');
if (!isset($themeconf['hide_menu_on']) OR !in_array('theIdentificationPage', $themeconf['hide_menu_on']))
Expand Down
5 changes: 4 additions & 1 deletion include/common.inc.php
Expand Up @@ -63,7 +63,10 @@ function sanitize_mysql_kv(&$v, $k)
// rewriting of language and otherarray values via URI params
//
$conf = array();
$page = array();
$page = array(
'infos' => array(),
'errors' => array(),
);
$user = array();
$lang = array();
$header_msgs = array();
Expand Down
16 changes: 16 additions & 0 deletions include/page_header.php
Expand Up @@ -98,6 +98,22 @@
));
}


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

header('Content-Type: text/html; charset='.get_pwg_charset());
Expand Down
13 changes: 4 additions & 9 deletions include/picture_comment.inc.php
Expand Up @@ -53,28 +53,23 @@

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)
{
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':
array_push( $infos, l10n('Your comment has been registered'));
array_push($page['infos'], l10n('Your comment has been registered'));
break;
case 'reject':
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;
default:
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
trigger_action( 'user_comment_insertion',
array_merge($comm, array('action'=>$comment_action) )
Expand Down
15 changes: 1 addition & 14 deletions nbm.php
Expand Up @@ -37,13 +37,9 @@
load_language('lang', PHPWG_ROOT_PATH.PWG_LOCAL_DIR, array('no_fallback'=>true, 'local'=>true) );



// +-----------------------------------------------------------------------+
// | Main |
// +-----------------------------------------------------------------------+
$page['errors'] = array();
$page['infos'] = array();

if (isset($_GET['subscribe'])
and preg_match('/^[A-Za-z0-9]{16}$/', $_GET['subscribe']))
{
Expand All @@ -68,16 +64,7 @@

$template->set_filenames(array('nbm'=>'nbm.tpl'));

// +-----------------------------------------------------------------------+
// | errors & infos |
// +-----------------------------------------------------------------------+
$template->assign(
array(
'errors' => $page['errors'],
'infos' => $page['infos'],
)
);


// include menubar
$themeconf = $template->get_template_vars('themeconf');
if (!isset($themeconf['hide_menu_on']) OR !in_array('theNBMPage', $themeconf['hide_menu_on']))
Expand Down
10 changes: 0 additions & 10 deletions password.php
Expand Up @@ -240,10 +240,6 @@ function reset_password()
// +-----------------------------------------------------------------------+
// | Process form |
// +-----------------------------------------------------------------------+

$page['errors'] = array();
$page['infos'] = array();

if (isset($_POST['submit']))
{
check_pwg_token();
Expand Down Expand Up @@ -345,12 +341,6 @@ function reset_password()
)
);

// +-----------------------------------------------------------------------+
// | infos & errors display |
// +-----------------------------------------------------------------------+

$template->assign('errors', $page['errors']);
$template->assign('infos', $page['infos']);

// include menubar
$themeconf = $template->get_template_vars('themeconf');
Expand Down
13 changes: 3 additions & 10 deletions picture.php
Expand Up @@ -189,8 +189,6 @@ function default_picture_content($content, $element_info)
// | initialization |
// +-----------------------------------------------------------------------+

$infos = array();

// caching first_rank, last_rank, current_rank in the displayed
// section. This should also help in readability.
$page['first_rank'] = 0;
Expand Down Expand Up @@ -338,22 +336,17 @@ function default_picture_content($content, $element_info)
switch ($comment_action)
{
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':
array_push($infos, l10n('Your comment has been registered'));
array_push($page['infos'], l10n('Your comment has been registered'));
break;
case 'reject':
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;
default:
trigger_error('Invalid comment action '.$comment_action, E_USER_WARNING);
}

$template->assign(
($comment_action=='reject') ? 'errors' : 'infos',
$infos
);

unset($_POST['content']);
break;
Expand Down
9 changes: 1 addition & 8 deletions profile.php
Expand Up @@ -64,7 +64,7 @@
$userdata = array_merge($userdata, $default_user);
}

save_profile_from_post($userdata, $errors);
save_profile_from_post($userdata, $page['errors']);

$title= l10n('Your Gallery Customization');
$page['body_id'] = 'theProfilePage';
Expand All @@ -75,13 +75,6 @@
make_index_url(), // for redirect
$userdata );

// +-----------------------------------------------------------------------+
// | errors display |
// +-----------------------------------------------------------------------+
if (count($errors) != 0)
{
$template->assign('errors', $errors);
}

// include menubar
$themeconf = $template->get_template_vars('themeconf');
Expand Down
17 changes: 5 additions & 12 deletions register.php
Expand Up @@ -37,28 +37,27 @@
page_forbidden('User registration closed');
}

$errors = array();
if (isset($_POST['submit']))
{
if (!verify_ephemeral_key(@$_POST['key']))
{
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'])
{
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'],
$_POST['password'],
$_POST['mail_address'],
true,
$errors);
$page['errors']);

if (count($errors) == 0)
if (count($page['errors']) == 0)
{
$user_id = get_userid($_POST['login']);
log_user($user_id, false);
Expand Down Expand Up @@ -91,12 +90,6 @@
'obligatory_user_mail_address' => $conf['obligatory_user_mail_address'],
));

//-------------------------------------------------------------- errors display
if (count($errors) != 0)
{
$template->assign('errors', $errors);
}

// include menubar
$themeconf = $template->get_template_vars('themeconf');
if (!isset($themeconf['hide_menu_on']) OR !in_array('theRegisterPage', $themeconf['hide_menu_on']))
Expand Down
10 changes: 2 additions & 8 deletions search.php
Expand Up @@ -31,7 +31,6 @@
check_status(ACCESS_GUEST);

//------------------------------------------------------------------ form check
$errors = array();
$search = array();
if (isset($_POST['submit']))
{
Expand Down Expand Up @@ -148,11 +147,11 @@
}
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
if (isset($_POST['submit']) and count($errors) == 0)
if (isset($_POST['submit']) and count($page['errors']) == 0)
{
redirect(
make_index_url(
Expand Down Expand Up @@ -222,11 +221,6 @@
;';
display_select_cat_wrapper($query, array(), 'category_options', false);

//-------------------------------------------------------------- errors display
if (sizeof($errors) != 0)
{
$template->assign('errors', $errors);
}

// include menubar
$themeconf = $template->get_template_vars('themeconf');
Expand Down
12 changes: 4 additions & 8 deletions themes/Sylvia/theme.css
Expand Up @@ -249,19 +249,15 @@
.infos {
color:#f70;
border:0;
background-color: transparent;
margin-left:125px;
padding:5px 0px 0pt 10pt;
min-height: 48px;
background:transparent url(icon/infos.png) no-repeat center right;
margin-left:40px;
text-align:left;
}
.errors {
color:#f33;
border:0;
background: transparent url(icon/errors.png) no-repeat scroll right top;
margin-left:125px;
padding:5px 0px 0pt 10pt;
min-height: 48px;
background:transparent url(icon/errors.png) no-repeat center right;
margin-left:40px;
text-align:left;
font-weight:bold;
}
Expand Down
3 changes: 3 additions & 0 deletions themes/default/template/about.tpl
Expand Up @@ -8,6 +8,9 @@
</ul>
<h2>{'About'|@translate}</h2>
</div>

{include file='infos_errors.tpl'}

<div id="piwigoAbout">
{$ABOUT_MESSAGE}
{if isset($THEME_ABOUT) }
Expand Down
2 changes: 2 additions & 0 deletions themes/default/template/comments.tpl
Expand Up @@ -10,6 +10,8 @@
<h2>{'User comments'|@translate}</h2>
</div>

{include file='infos_errors.tpl'}

<form class="filter" action="{$F_ACTION}" method="get">

<fieldset>
Expand Down
10 changes: 1 addition & 9 deletions themes/default/template/identification.tpl
Expand Up @@ -10,15 +10,7 @@
<h2>{'Identification'|@translate}</h2>
</div>

{if isset($errors) }
<div class="errors">
<ul>
{foreach from=$errors item=error}
<li>{$error}</li>
{/foreach}
</ul>
</div>
{/if}
{include file='infos_errors.tpl'}

<form action="{$F_LOGIN_ACTION}" method="post" name="login_form" class="properties">
<fieldset>
Expand Down
2 changes: 2 additions & 0 deletions themes/default/template/index.tpl
Expand Up @@ -79,6 +79,8 @@

</div>{* <!-- titrePage --> *}

{include file='infos_errors.tpl'}

{if !empty($PLUGIN_INDEX_CONTENT_BEGIN)}{$PLUGIN_INDEX_CONTENT_BEGIN}{/if}

{if !empty($category_search_results)}
Expand Down

0 comments on commit ca230a6

Please sign in to comment.