Resolved issue 0000697: with generic user a author name is necessary to comment picture.

+ Change way to determinate if user is a guest (use functions like is_admin)


git-svn-id: http://piwigo.org/svn/trunk@2029 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rub
2007-06-05 22:01:15 +00:00
parent a42b553c48
commit 182fb00f8f
16 changed files with 72 additions and 47 deletions

View File

@@ -91,7 +91,7 @@ SELECT user_id,
else
{
$image_only = true;
if (!$user['is_the_guest'])
if (!is_a_guest())
{// auto session was created - so switch to guest
$user = build_user( $conf['guest_id'], true );
}

View File

@@ -40,7 +40,7 @@ $redirect_to = '';
if ( !empty($_GET['redirect']) )
{
$redirect_to = urldecode($_GET['redirect']);
if ( $user['is_the_guest'] )
if ( is_a_guest() )
{
array_push($errors, l10n('access_forbiden'));
}

View File

@@ -4,7 +4,6 @@
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $Id$
// | last update : $Date$
// | last modifier : $Author$
@@ -165,7 +164,7 @@ trigger_action('loading_lang');
// only now we can set the localized username of the guest user (and not in
// include/user.inc.php)
if ($user['is_the_guest'])
if (is_a_guest())
{
$user['username'] = $lang['guest'];
}

View File

@@ -173,7 +173,7 @@ $conf['show_version'] = true;
// $conf['links'] = array(
// 'http://phpwebgallery.net' => array('label' => 'PWG website', 'new_window' => false, 'eval_visible' => 'return true;'),
// 'http://forum.phpwebgallery.net' => array('label' => 'For ADMIN', 'new_window' => true, 'eval_visible' => 'return is_admin();'),
// 'http://phpwebgallery.net/doc' => array('label' => 'For Guest', 'new_window' => true, 'eval_visible' => 'return $user[\'is_the_guest\'];'),
// 'http://phpwebgallery.net/doc' => array('label' => 'For Guest', 'new_window' => true, 'eval_visible' => 'return is_a_guest();'),
// 'http://download.gna.org/phpwebgallery/' =>
// array('label' => 'PopUp', 'new_window' => true,
// 'nw_name' => 'PopUp', 'nw_features' => 'width=800,height=450,location=no,status=no,toolbar=no,scrollbars=no,menubar=no'),
@@ -213,7 +213,7 @@ $conf['links'] = array();
// '' condition is equivalent to 'return true;'
// $conf['random_index_redirect'] = array(
// PHPWG_ROOT_PATH.'index.php?/best_rated' => 'return true;',
// PHPWG_ROOT_PATH.'index.php?/recent_pics' => 'return $user[\'is_the_guest\'];',
// PHPWG_ROOT_PATH.'index.php?/recent_pics' => 'return is_a_guest();',
// PHPWG_ROOT_PATH.'random.php' => '',
// PHPWG_ROOT_PATH.'index.php?/categories' => '',
// );

View File

@@ -423,7 +423,7 @@ function pwg_log($image_id = null, $image_type = null)
{
$do_log = false;
}
if ($user['is_the_guest'] and !$conf['history_guest'])
if (is_a_guest() and !$conf['history_guest'])
{
$do_log = false;
}

View File

@@ -58,7 +58,7 @@ function user_comment_check($action, $comment)
return $action;
// we do here only BASIC spam check (plugins can do more)
if ( !$user['is_the_guest'] )
if ( !is_a_guest() )
return $action;
$link_count = preg_match_all( '/https?:\/\//',
@@ -118,7 +118,8 @@ function insert_user_comment( &$comm, $key, &$infos )
$comment_action='moderate'; //one of validate, moderate, reject
}
if ( $user['is_the_guest'] )
// display author field if the user status is guest or generic
if (!is_classic_user())
{
if ( empty($comm['author']) )
{

View File

@@ -574,7 +574,7 @@ function access_denied()
get_root_url().'identification.php?redirect='
.urlencode(urlencode($_SERVER['REQUEST_URI']));
if ( isset($user['is_the_guest']) and !$user['is_the_guest'] )
if ( isset($user) and !is_a_guest() )
{
echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
echo '<a href="'.get_root_url().'identification.php">'.$lang['identification'].'</a>&nbsp;';

View File

@@ -146,8 +146,6 @@ function build_user( $user_id, $use_cache )
global $conf;
$user['id'] = $user_id;
$user = array_merge( $user, getuserdata($user_id, $use_cache) );
$user['is_the_guest'] = ($user['id'] == $conf['guest_id']);
$user['is_the_default'] = ($user['id'] == $conf['default_user_id']);
// calculation of the number of picture to display per page
$user['nb_image_page'] = $user['nb_image_line'] * $user['nb_line_page'];
@@ -1015,11 +1013,11 @@ function log_user($user_id, $remember_me)
{
$cookie = array('id' => (int)$user_id, 'key' => $key);
setcookie($conf['remember_me_name'],
serialize($cookie),
time()+$conf['remember_me_length'],
cookie_path()
);
}
serialize($cookie),
time()+$conf['remember_me_length'],
cookie_path()
);
}
}
else
{ // make sure we clean any remember me ...
@@ -1090,13 +1088,12 @@ SELECT '.$conf['user_fields']['id'].' AS id,
}
/*
* Return access_type definition of uuser
* Test does with user status
* @return bool
* Return user status used in this library
* @return string
*/
function get_access_type_status($user_status='')
function get_user_status($user_status)
{
global $user, $conf;
global $user;
if (empty($user_status))
{
@@ -1110,8 +1107,19 @@ function get_access_type_status($user_status='')
$user_status = '';
}
}
return $user_status;
}
switch ($user_status)
/*
* Return access_type definition of uuser
* Test does with user status
* @return bool
*/
function get_access_type_status($user_status='')
{
global $conf;
switch (get_user_status($user_status))
{
case 'guest':
{
@@ -1173,7 +1181,25 @@ function check_status($access_type, $user_status = '')
}
/*
* Return if user is an administrator
* Return if user is only a guest
* @return bool
*/
function is_a_guest($user_status = '')
{
return get_user_status($user_status) == 'guest';
}
/*
* Return if user is, at least, a classic user
* @return bool
*/
function is_classic_user($user_status = '')
{
return is_autorize_status(ACCESS_CLASSIC, $user_status);
}
/*
* Return if user is, at least, an administrator
* @return bool
*/
function is_admin($user_status = '')

View File

@@ -163,7 +163,7 @@ if ('tags' == $page['section'])
}
//---------------------------------------------------------- special categories
// favorites categories
if ( !$user['is_the_guest'] )
if ( !is_a_guest() )
{
$template->assign_block_vars('username', array());
@@ -242,7 +242,7 @@ $template->assign_block_vars(
);
//--------------------------------------------------------------------- summary
if ($user['is_the_guest'])
if (is_a_guest())
{
$template->assign_block_vars('login', array());

View File

@@ -4,8 +4,7 @@
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $RCSfile$
// | file : $Id$
// | last update : $Date$
// | last modifier : $Author$
// | revision : $Revision$
@@ -38,7 +37,7 @@ $template->assign_vars(
//--------------------------------------------------------------------- contact
if (!$user['is_the_guest'])
if (!is_a_guest())
{
$template->assign_block_vars(
'contact',

View File

@@ -43,7 +43,7 @@ foreach ($related_categories as $category)
if ( $page['show_comments'] and isset( $_POST['content'] ) )
{
if ( $user['is_the_guest'] and !$conf['comments_forall'] )
if ( is_a_guest() and !$conf['comments_forall'] )
{
die ('Session expired');
}
@@ -61,9 +61,9 @@ if ( $page['show_comments'] and isset( $_POST['content'] ) )
switch ($comment_action)
{
case 'moderate':
array_push( $infos, $lang['comment_to_validate'] );
array_push( $infos, l10n('comment_to_validate') );
case 'validate':
array_push( $infos, $lang['comment_added']);
array_push( $infos, l10n('comment_added'));
break;
case 'reject':
set_status_header(403);
@@ -137,7 +137,7 @@ SELECT id,author,date,image_id,content
'comments.comment',
array(
'COMMENT_AUTHOR' => empty($row['author'])
? $lang['guest']
? l10n('guest')
: $row['author'],
'COMMENT_DATE' => format_date(
@@ -168,8 +168,8 @@ SELECT id,author,date,image_id,content
}
}
if (!$user['is_the_guest']
or ($user['is_the_guest'] and $conf['comments_forall']))
if (!is_a_guest()
or (is_a_guest() and $conf['comments_forall']))
{
include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
$key = get_comment_post_key($page['image_id']);
@@ -183,8 +183,9 @@ SELECT id,author,date,image_id,content
'KEY' => $key,
'CONTENT' => $content
));
// display author field if the user is not logged in
if ($user['is_the_guest'])
// display author field if the user status is guest or generic
if (!is_classic_user())
{
$template->assign_block_vars(
'comments.add_comment.author_field', array()

View File

@@ -702,8 +702,8 @@ SELECT id, date, author, content
$comment_post_data = null;
if ($is_commentable and
(!$user['is_the_guest']
or ($user['is_the_guest'] and $conf['comments_forall'] )
(!is_a_guest()
or (is_a_guest() and $conf['comments_forall'] )
)
)
{
@@ -884,7 +884,7 @@ function ws_session_login($params, &$service)
function ws_session_logout($params, &$service)
{
global $user, $conf;
if (!$user['is_the_guest'])
if (!is_a_guest())
{
$_SESSION = array();
session_unset();
@@ -902,7 +902,7 @@ function ws_session_getStatus($params, &$service)
{
global $user, $lang_info;
$res = array();
$res['username'] = $user['is_the_guest'] ? 'guest' : $user['username'];
$res['username'] = is_a_guest() ? 'guest' : $user['username'];
foreach ( array('status', 'template', 'theme', 'language') as $k )
{
$res[$k] = $user[$k];

View File

@@ -4,7 +4,6 @@
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | branch : BSF (Best So Far)
// | file : $Id$
// | last update : $Date$
// | last modifier : $Author$
@@ -53,7 +52,7 @@ pwg_query($query);
$feed_url=PHPWG_ROOT_PATH.'feed.php';
if ($user['is_the_guest'])
if (is_a_guest())
{
$feed_image_only_url=$feed_url;
$feed_url .= '?feed='.$page['feed'];

View File

@@ -578,7 +578,7 @@ if (is_admin())
}
// favorite manipulation
if (!$user['is_the_guest'])
if (!is_a_guest())
{
// verify if the picture is already in the favorite of the user
$query = '

View File

@@ -206,7 +206,7 @@ function save_profile_from_post(&$userdata, &$errors)
function load_profile_in_template($url_action, $url_redirect, $userdata)
{
global $template;
global $template, $conf;
$template->set_filename('profile_content', 'profile_content.tpl');
@@ -293,7 +293,7 @@ function load_profile_in_template($url_action, $url_redirect, $userdata)
));
}
if (!($userdata['is_the_guest'] or $userdata['is_the_default']))
if (!(in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']))))
{
$template->assign_block_vars('not_special_user', array());
if ( !defined('IN_ADMIN') )

2
ws.php
View File

@@ -80,7 +80,7 @@ function ws_addDefaultMethods( $arr )
$service->addMethod('pwg.images.addComment', 'ws_images_addComment',
array(
'image_id' => array(),
'author' => array( 'default' => $user['is_the_guest']? 'guest':$user['username']),
'author' => array( 'default' => is_a_guest()? 'guest':$user['username']),
'content' => array(),
'key' => array(),
),