Source for file _functions_users.php
Documentation is available at _functions_users.php
* b2evolution - {@link http://b2evolution.net/}
* Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
* @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
* @author This file built upon code from original b2 - http://cafelog.com/
if( !defined('DB_USER') ) die( 'Please, do not access this page directly.' );
require_once dirname(__FILE__
).
'/_functions_groups.php';
require_once dirname(__FILE__
).
'/_class_user.php';
* Verify if user is logged in
* checking login & pass in the database
function veriflog( $login_required =
false )
global $cookie_user, $cookie_pass, $cookie_expires, $cookie_path, $cookie_domain, $error, $core_dirout;
global $user_login, $user_pass_md5, $userdata, $user_ID, $user_nickname, $user_email, $user_url;
// Reset all global variables in case some tricky stuff is trying to set them otherwise:
// Warning: unset() prevent from setting a new global value later in the func !!! :((
// Check if user is trying to login right now:
if( isset
($_POST['log'] ) && isset
($_POST['pwd'] ))
{ // Trying to log in with a POST
unset
($_POST['pwd']); // password is hashed from now on
elseif( isset
($_GET['log'] ) && isset
($_GET['pwd'] ))
{ // Trying to log in with a GET
unset
($_GET['pwd']); // password is hashed from now on
* ---------------------------------------------------------
* User is trying to login right now
* ---------------------------------------------------------
// echo 'Trying to log in right now...';
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " .
gmdate("D, d M Y H:i:s") .
" GMT");
header("Cache-Control: no-cache, must-revalidate");
// Check login and password
if( !( $login_ok =
user_pass_ok( $user_login, $user_pass_md5, true ) ) )
// echo 'login failed!!';
return '<strong>'.
T_('ERROR').
':</strong> '.
T_('wrong login/password.');
//echo $user_login, $pass_is_md5, $user_pass, $cookie_domain;
if( !setcookie( $cookie_user, $log, $cookie_expires, $cookie_path, $cookie_domain ) )
printf( T_('setcookie %s failed!').
'<br />', $cookie_user );
if( !setcookie( $cookie_pass, $user_pass_md5, $cookie_expires, $cookie_path, $cookie_domain) )
printf( T_('setcookie %s failed!').
'<br />', $cookie_pass );
elseif( isset
($_COOKIE[$cookie_user]) && isset
($_COOKIE[$cookie_pass]) )
* ---------------------------------------------------------
* User was not trying to log in, but he already was logged in: check validity
* ---------------------------------------------------------
// echo 'Was already logged in...';
// echo 'pass=', $user_pass_md5;
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " .
gmdate("D, d M Y H:i:s") .
" GMT");
header("Cache-Control: no-cache, must-revalidate");
return '<strong>'.
T_('ERROR').
':</strong> '.
T_('login/password no longer valid.');
return 0; // Wrong login but we don't care.
* ---------------------------------------------------------
* User was not logged in at all
* ---------------------------------------------------------
// echo ' NOT logged in...';
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: " .
gmdate("D, d M Y H:i:s") .
" GMT");
header("Cache-Control: no-cache, must-revalidate");
return T_('You must log in!');
return 0; // Not logged in but we don't care
* Login info is OK, we set the global variables:
$current_User =
new User( $userdata ); // COPY!
//echo $current_User->disp('login');
$user_ID =
$userdata['ID'];
$user_nickname =
$userdata['user_nickname'];
$user_email =
$userdata['user_email'];
$user_url =
$userdata['user_url'];
global $cookie_user, $cookie_pass, $cookie_expired, $cookie_path, $cookie_domain;
global $user_login, $user_pass_md5, $userdata, $user_ID, $user_nickname, $user_email, $user_url;
// Reset all global variables
// Note: unset is bugguy on globals
setcookie( 'cafeloguser', '', $cookie_expired, $cookie_path, $cookie_domain); // OLD
setcookie( $cookie_user, '', $cookie_expired, $cookie_path, $cookie_domain);
setcookie( 'cafelogpass', '', $cookie_expired, $cookie_path, $cookie_domain); // OLD
setcookie( $cookie_pass, '', $cookie_expired, $cookie_path, $cookie_domain);
global $user_ID, $generating_static;
if( isset
($generating_static) &&
$generating_static )
{ // When generating static page, we should always consider we are not logged in.
return (!empty($user_ID));
function user_pass_ok( $user_login, $user_pass, $pass_is_md5 =
false )
// echo 'got data for: ', $userdata['user_login'];
if( !$pass_is_md5 ) $user_pass =
md5( $user_pass );
// echo 'pass: ', $user_pass, '/', $userdata['user_pass'];
return ($user_pass ==
$userdata['user_pass']);
* @return array DB row on success, false if login does not exist
global $DB, $tableusers, $cache_userdata, $use_cache;
if( (empty($cache_userdata[$user_login])) OR (!$use_cache) )
WHERE user_login = '".
$DB->escape($user_login).
"'";
$myrow =
$DB->get_row( $sql, ARRAY_A );
$cache_userdata[$user_login] =
$myrow;
$myrow =
$cache_userdata[$user_login];
global $DB, $tableusers, $cache_userdata;
if( empty($cache_userdata[$userid] ) )
{ // We do a progressive cache load beacuse there can be many many users!
if( $myrow =
$DB->get_row( $sql, ARRAY_A ) )
$cache_userdata[ $myrow['ID'] ] =
$myrow;
if( ! isset
( $cache_userdata[$userid] ) )
die('Requested user '.
$userid.
' does not exist!');
return $cache_userdata[$userid];
return $DB->get_var( "SELECT count(*)
WHERE post_author = $userid" );
if( empty( $this_userdata ) )
{ // We want the current user
$this_userdata =
& $userdata;
$output =
$this_userdata['ID'];
$output =
$this_userdata['user_'.
$show];
$output =
$this_userdata['user_login'];
function user_info( $show =
'', $format =
'raw', $display =
true )
* Template tag; Provide a link to login
function user_login_link( $before =
'', $after =
'', $link_text =
'', $link_title =
'#' )
global $htsrv_url, $edited_Blog, $generating_static;
if( $link_text ==
'' ) $link_text =
T_('Login...');
if( $link_title ==
'#' ) $link_title =
T_('Login if you have an account...');
if( !isset
($generating_static) ||
$generating_static ==
false )
{ // We are not generating a static page here:
elseif( isset
($edited_Blog) )
{ // We are generating a static page
$redirect =
'?redirect_to='.
$edited_Blog->get('dynurl');
{ // We are in a weird situation
echo
'<a href="', $htsrv_url, '/login.php'.
$redirect.
'" title="', $link_title, '">';
* Template tag; Provide a link to new user registration
function user_register_link( $before =
'', $after =
'', $link_text =
'', $link_title =
'#' )
global $htsrv_url, $Settings, $edited_Blog, $generating_static;
if( is_logged_in() ||
!$Settings->get('newusers_canregister'))
{ // There's no need to provide this link if already logged in or if we won't let him register
if( $link_text ==
'' ) $link_text =
T_('Register...');
if( $link_title ==
'#' ) $link_title =
T_('Register to open an account...');
if( !isset
($generating_static) ||
$generating_static ==
false )
{ // We are not generating a static page here:
elseif( isset
($edited_Blog) )
{ // We are generating a static page
$redirect =
'?redirect_to='.
$edited_Blog->get('dynurl');
{ // We are in a weird situation
echo
'<a href="', $htsrv_url, '/register.php'.
$redirect.
'" title="', $link_title, '">';
* Template tag; Provide a link to logout
function user_logout_link( $before =
'', $after =
'', $link_text =
'', $link_title =
'#' )
global $htsrv_url, $user_login, $blog;
if( $link_text ==
'' ) $link_text =
T_('Logout (%s)');
if( $link_title ==
'#' ) $link_title =
T_('Logout from your account');
echo
'<a href="', $htsrv_url, '/login.php?action=logout&redirect_to='.
urlencode( regenerate_url() ), '" title="', $link_title, '">';
printf( $link_text, $user_login );
* Template tag; Provide a link to the backoffice
function user_admin_link( $before =
'', $after =
'', $page =
'b2edit.php', $link_text =
'', $link_title =
'#' )
global $admin_url, $blog, $current_User;
if( $current_User->get('level') ==
0 )
{ // If user is NOT active:
if( $link_text ==
'' ) $link_text =
T_('Admin');
if( $link_title ==
'#' ) $link_title =
T_('Go to the back-office');
// add the blog param to $page if it is not already in there
echo
'<a href="', $admin_url, '/', $page, '" title="', $link_title, '">';
* Template tag; Provide a link to user profile
function user_profile_link( $before =
'', $after =
'', $link_text =
'', $link_title =
'#' )
global $user_login, $pagenow, $Blog;
if( $link_text ==
'' ) $link_text =
T_('Profile (%s)');
if( $link_title ==
'#' ) $link_title =
T_('Edit your profile');
.
'" title="', $link_title, '">';
printf( $link_text, $user_login );
* Display "User profile" title if it has been requested
* {@internal profile_title(-) }}
* @param string Prefix to be displayed if something is going to be displayed
* @param mixed Output format, see {@link format_to_output()} or false to
* return value instead of displaying it
$info =
$prefix.
T_('User profile');