summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
authorlsces <lester@lsces.co.uk>2025-08-29 13:16:19 +0100
committerlsces <lester@lsces.co.uk>2025-08-29 13:16:19 +0100
commit03f2de05ae293d5c34a6828d3d8c62e0de8938e2 (patch)
treeddbc544b6533c7e6ca3be04a498f876ccdaaf5d8 /includes
parentf2904d3ad14d45461d36237dba33f62b66aafe5a (diff)
downloadusers-03f2de05ae293d5c34a6828d3d8c62e0de8938e2.tar.gz
users-03f2de05ae293d5c34a6828d3d8c62e0de8938e2.tar.bz2
users-03f2de05ae293d5c34a6828d3d8c62e0de8938e2.zip
Classes updated to PHP8.4 and namespace
Diffstat (limited to 'includes')
-rwxr-xr-x[-rw-r--r--]includes/classes/BaseAuth.php51
-rwxr-xr-x[-rw-r--r--]includes/classes/BitHybridAuthManager.php65
-rwxr-xr-x[-rw-r--r--]includes/classes/BitPermUser.php611
-rwxr-xr-x[-rw-r--r--]includes/classes/BitUser.php553
-rwxr-xr-x[-rw-r--r--]includes/classes/RolePermUser.php445
-rwxr-xr-x[-rw-r--r--]includes/classes/RoleUser.php1105
6 files changed, 1456 insertions, 1374 deletions
diff --git a/includes/classes/BaseAuth.php b/includes/classes/BaseAuth.php
index 3d07920..dfea52e 100644..100755
--- a/includes/classes/BaseAuth.php
+++ b/includes/classes/BaseAuth.php
@@ -5,6 +5,8 @@
* @package users
*/
+namespace Bitweaver\Users;
+
/**
* Class that manages the base autentication method
*
@@ -16,9 +18,9 @@ class BaseAuth {
public $mConfig;
public $mInfo;
public $mCfg;
- public $mErrors =array();
+ public $mErrors =[];
- function __construct($pAuthId) {
+ public function __construct($pAuthId) {
global $gBitSystem;
$this->mCfg = BaseAuth::getAuthMethod($pAuthId);
$this->mCfg['auth_id'] = $pAuthId;
@@ -26,14 +28,14 @@ class BaseAuth {
$var_id = substr($op_id,strrpos($op_id,"_")+1);
$var = $gBitSystem->getConfig($op_id, $op['default']);
if ($op['type']=="checkbox") {
- $var = ($var== "y");
+ $var = $var== "y";
}
$this->mConfig[$var_id]=$var;
}
}
public static function &getAuthMethods() {
- static $authMethod = array();
+ static $authMethod = [];
static $scaned = false;
if (!$scaned) {
$scaned = true;
@@ -60,11 +62,11 @@ class BaseAuth {
if( is_dir( $authDir ) && $authScan = scandir( $authDir ) ) {
foreach( $authScan as $plugDir ) {
if( $plugDir != 'CVS' && substr($plugDir,0,1)!='.' && is_dir( $authDir.$plugDir ) ) {
- BaseAuth::register( $plugDir,array(
- 'name' => strtoupper( $plugDir ).' Auth',
- 'file' => $authDir.$plugDir.'/auth.php',
- 'class' => ucfirst( $plugDir ).'Auth',
- ) );
+ BaseAuth::register( $plugDir, [
+ 'name' => strtoupper( $plugDir ) . ' Auth',
+ 'file' => $authDir . $plugDir . '/auth.php',
+ 'class' => '\\Bitweaver\\Users\\' . ucfirst( $plugDir ) . 'Auth',
+ ] );
}
}
}
@@ -101,7 +103,7 @@ class BaseAuth {
public static function authError($str) {
$warning = '<div class="error">'.$str.'</div>';
- print( $warning );
+ print $warning;
}
public static function getAuthMethodCount() {
@@ -110,38 +112,38 @@ class BaseAuth {
return count($methods);
}
- function validate($user,$pass,$challenge,$response) {
+ public function validate($user,$pass,$challenge,$response) {
if (!$this->isSupported()) return false;
$this->mLogin = $user;
$this->mInfo['login']=$user;
$this->mInfo['password']=$pass;
}
- function getUserData() {
+ public function getUserData() {
return $this->mInfo;
}
- function isSupported() {
+ public function isSupported() {
$this->mErrors[] = "BaseAuth is not an authentcation method";
return false;
}
- function createUser(&$userattr) {
+ public function createUser(&$userattr) {
$this->mErrors[] = "BaseAuth is not an authentcation method";
return false;
}
- function getSettings() {
- return array();
+ public function getSettings() {
+ return [];
}
- function canManageAuth() {
+ public function canManageAuth() {
$this->mErrors[] = "BaseAuth is not an authentcation method";
return false;
}
- function getRegistrationFields() {
- return array();
+ public function getRegistrationFields() {
+ return [];
}
public static function isActive($package) {
@@ -175,7 +177,7 @@ class BaseAuth {
} elseif (!empty($pAuthMixed)) {
$authPlugin=BaseAuth::getAuthMethod( $pAuthMixed );
if (file_exists( $authPlugin['file'] )) {
- require_once( $authPlugin['file'] );
+// require_once $authPlugin['file'];
$cl = $authPlugin['class'];
$instance = new $cl();
if( $instance->isSupported() ) {
@@ -188,7 +190,7 @@ class BaseAuth {
public static function getConfig() {
global $gBitSystem;
- $authSettings = array();
+ $authSettings = [];
foreach( BaseAuth::getAuthMethods() as $meth_name => $method ) {
$instance = BaseAuth::init($meth_name) ;
if ($instance) {
@@ -211,7 +213,7 @@ class BaseAuth {
}
}
if (!empty($_REQUEST["loginprefs"])) {
- $used =array();
+ $used =[];
for ($i=0,$j=0;$i<count($authSettings['avail']);$i++,$j++) {
$gBitSystem->storeConfig( "users_auth_method_$i",null, USERS_PKG_NAME );
if (empty($_REQUEST["users_auth_method_$i"])) {
@@ -238,8 +240,7 @@ class BaseAuth {
if (($gBitSystem->getConfig('users_allow_register','y')=='y')&&!$canManageAuth) {
$authSettings['err']['bit_reg']="Registration is enabled but there are no Auth Methods that support this, Registration won't work!";
}
- $method['active']=BaseAuth::isActive($meth_name);
+ $method['active']=BaseAuth::isActive($authSettings['avail'][$meth_name] ?? 'BitAuth');
return $authSettings;
}
-}
-?>
+} \ No newline at end of file
diff --git a/includes/classes/BitHybridAuthManager.php b/includes/classes/BitHybridAuthManager.php
index 61bdfc5..fc9d853 100644..100755
--- a/includes/classes/BitHybridAuthManager.php
+++ b/includes/classes/BitHybridAuthManager.php
@@ -7,15 +7,16 @@
* Copyright (c) 2017 bitweaver.org
*/
-require_once( USERS_PKG_PATH.'hauth/Hybrid/Auth.php' );
+namespace Bitweaver\Users;
+require_once USERS_PKG_PATH.'hauth/Hybrid/Auth.php';
if( file_exists( EXTERNAL_LIBS_PATH.'facebook/src/Facebook/autoload.php' ) ) {
- require_once( EXTERNAL_LIBS_PATH.'facebook/src/Facebook/autoload.php' );
+ require_once EXTERNAL_LIBS_PATH.'facebook/src/Facebook/autoload.php';
}
-class BitHybridAuthManager extends BitSingleton {
+class BitHybridAuthManager extends \Bitweaver\BitSingleton {
- private $mEnabledProviders = array();
+ private $mEnabledProviders = [];
/**
* Constructor
@@ -39,13 +40,13 @@ class BitHybridAuthManager extends BitSingleton {
/**
* Returns:
- * - FALSE: Authentication Failed
- * - TRUE: Authentication was connected to pUser
+ * - false: Authentication Failed
+ * - true: Authentication was connected to pUser
* - INT: users_users.user_id of auth'ed profile
* - Object: Hybrid_User_Profile of validated profile, but no local user_id was found to match the profile
**/
public function authenticate( $pProvider, &$pUser ) {
- $ret = FALSE;
+ $ret = false;
if( $this->isProviderEnabled( $pProvider ) ) {
$hybridAuth = $this->getHybridAuth();
$authedProvider = $hybridAuth->authenticate( $pProvider );
@@ -60,7 +61,7 @@ class BitHybridAuthManager extends BitSingleton {
if( !empty( $userId ) ) {
$pUser->mUserId = $userId;
if( $pUser->load() ) {
- $pUser->loadPermissions( TRUE );
+ $pUser->loadPermissions( true );
$pUser->setUserSession();
$pUser->clearFromCache();
$ret = $userId;
@@ -87,7 +88,7 @@ class BitHybridAuthManager extends BitSingleton {
}
public function storeUserProfile( $pUserId, $pProvider, $pIdentifier, $pAuthProfile ) {
- if( BitBase::verifyId( $pUserId ) && !empty( $pProvider ) && !empty( $pIdentifier ) ) {
+ if( \Bitweaver\BitBase::verifyId( $pUserId ) && !empty( $pProvider ) && !empty( $pIdentifier ) ) {
$this->StartTrans();
$query = "DELETE FROM `".BIT_DB_PREFIX."users_auth_map` WHERE `user_id`=? AND `provider`=?";
$result = $this->mDb->query( $query, array( $pUserId, $pProvider ) );
@@ -106,7 +107,7 @@ class BitHybridAuthManager extends BitSingleton {
}
private function cacheUserProfile( $pProvider, $pProfile ) {
- $ret = FALSE;
+ $ret = false;
global $gBitSystem;
if( $gBitSystem::isCacheActive() ) {
$cacheKey = $this->getProfileCacheKey( $pProvider, $pProfile->identifier );
@@ -115,18 +116,18 @@ class BitHybridAuthManager extends BitSingleton {
return $ret;
}
- public function getAuthData( $pProvider, $pUserId=NULL ) {
- $ret = array();
+ public function getAuthData( $pProvider, $pUserId=null ) {
+ $ret = [];
try {
if( empty( $pUserId ) ) {
global $gBitUser;
$pUserId = $gBitUser->mUserId;
}
if( $ret = $this->mDb->getRow( "SELECT * FROM `".BIT_DB_PREFIX."users_auth_map` WHERE `user_id`=? AND `provider`=?", array( $pUserId, $pProvider ) ) ) {
- $ret['profile_hash'] = json_decode( $ret['profile_json'], TRUE );
+ $ret['profile_hash'] = json_decode( $ret['profile_json'], true );
}
- } catch( Exception $e ) {
- bit_error_log( $e->GetMessage() );
+ } catch( \Exception $e ) {
+ \Bitweaver\bit_error_log( $e->GetMessage() );
}
return $ret;
}
@@ -135,7 +136,7 @@ class BitHybridAuthManager extends BitSingleton {
$config = array(
// "base_url" the url that point to HybridAuth Endpoint (where the index.php and config.php are found)
"base_url" => USERS_PKG_URI.'hauth/',
- "debug_mode" => TRUE,
+ "debug_mode" => true,
"debug_file" => sys_get_temp_dir().'/hybridauth_log',
);
@@ -150,7 +151,7 @@ class BitHybridAuthManager extends BitSingleton {
}
}
}
- return new Hybrid_Auth( $config );
+ return new \Hybrid_Auth( $config );
}
public function isProviderEnabled( $pProvider ) {
@@ -184,7 +185,7 @@ class BitHybridAuthManager extends BitSingleton {
}
private function getProviderIcon( $pProvider ) {
- $ret = 'fa-user';
+ $ret = 'icon-user';
$allProviders = $this->getAllProviders();
if( !empty( $allProviders[$pProvider]['icon'] ) ) {
$ret = $allProviders[$pProvider]['icon'];
@@ -201,7 +202,7 @@ class BitHybridAuthManager extends BitSingleton {
$allProviders = $this->getAllProviders();
foreach( $allProviders as $providerKey=>$providerHash ) {
if( $this->getConfig( $this->getEnabledConfigKey( $providerHash['provider'] ) ) ) {
- $active = TRUE;
+ $active = true;
foreach( array_keys( $providerHash['keys'] ) as $providerConfig ) {
$configValue = $this->getProviderConfig( $providerKey, $providerConfig );
$active &= !empty( $configValue );
@@ -216,7 +217,7 @@ class BitHybridAuthManager extends BitSingleton {
}
public function scanProviders() {
- $ret = array();
+ $ret = [];
if( $providerFiles = array_diff(scandir( $this->getProviderPath() ), array('..', '.')) ) {
foreach( $providerFiles as $providerFile ) {
require_once $this->getProviderFile( $provider );
@@ -227,18 +228,18 @@ class BitHybridAuthManager extends BitSingleton {
public function getAllProviders() {
return array (
- 'google' => array( 'provider' => 'Google', 'icon' => ' fab fa-google', 'image' => USERS_PKG_URL.'hauth/images/google.png', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
- 'amazon' => array( 'provider' => 'Amazon', 'icon' => ' fab fa-amazon', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
- 'aol' => array( 'provider' => 'AOL', 'icon' => ' fa fa-user', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
- 'facebook' => array( 'provider' => 'Facebook', 'icon' => ' fab fa-facebook', 'keys' => array( 'id'=>'', 'secret'=> '' ), 'options' => array( 'scope'=>'Comma separated list of requested permissions. Default are: email, user_about_me, user_birthday, user_hometown, user_location, user_website, publish_actions, read_custom_friendlists' ) ),
- 'foursquare' => array( 'provider' => 'Foursquare', 'icon' => ' fab fa-foursquare', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
- 'instagram' => array( 'provider' => 'Instagram', 'icon' => ' fab fa-instagram', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
- 'linkedin' => array( 'provider' => 'LinkedIn', 'icon' => ' fab fa-linkedin', 'keys' => array( 'key'=>'', 'secret'=> '' ) ),
- 'live' => array( 'provider' => 'Live', 'icon' => ' fab fa-windows', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
- 'openid' => array( 'provider' => 'OpenID', 'icon' => ' fab fa-openid', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
- 'paypal' => array( 'provider' => 'Paypal', 'icon' => ' fab fa-paypal', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
- 'twitter' => array( 'provider' => 'Twitter', 'icon' => ' fab fa-twitter', 'keys' => array( 'key'=>'', 'secret'=> '' ) ),
- 'yahoo' => array( 'provider' => 'Yahoo', 'icon' => ' fab fa-yahoo', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
+ 'google' => array( 'provider' => 'Google', 'icon' => 'icon-google-plus-sign', 'image' => USERS_PKG_URL.'hauth/images/google.png', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
+ 'amazon' => array( 'provider' => 'Amazon', 'icon' => 'icon-user', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
+ 'aol' => array( 'provider' => 'AOL', 'icon' => 'icon-user', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
+ 'facebook' => array( 'provider' => 'Facebook', 'icon' => 'icon-facebook-sign', 'keys' => array( 'id'=>'', 'secret'=> '' ), 'options' => array( 'scope'=>'Comma separated list of requested permissions. Default are: email, user_about_me, user_birthday, user_hometown, user_location, user_website, publish_actions, read_custom_friendlists' ) ),
+ 'foursquare' => array( 'provider' => 'Foursquare', 'icon' => 'icon-foursquare', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
+ 'instagram' => array( 'provider' => 'Instagram', 'icon' => 'icon-instagram', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
+ 'linkedin' => array( 'provider' => 'LinkedIn', 'icon' => 'icon-linkedin', 'keys' => array( 'key'=>'', 'secret'=> '' ) ),
+ 'live' => array( 'provider' => 'Live', 'icon' => 'icon-windows', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
+ 'openid' => array( 'provider' => 'OpenID', 'icon' => 'icon-user', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
+ 'paypal' => array( 'provider' => 'Paypal', 'icon' => 'icon-user', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
+ 'twitter' => array( 'provider' => 'Twitter', 'icon' => 'icon-twitter', 'keys' => array( 'key'=>'', 'secret'=> '' ) ),
+ 'yahoo' => array( 'provider' => 'Yahoo', 'icon' => 'icon-user', 'keys' => array( 'id'=>'', 'secret'=> '' ) ),
);
}
diff --git a/includes/classes/BitPermUser.php b/includes/classes/BitPermUser.php
index d713db1..12a8fbe 100644..100755
--- a/includes/classes/BitPermUser.php
+++ b/includes/classes/BitPermUser.php
@@ -18,7 +18,9 @@
/**
* required setup
*/
-require_once( USERS_PKG_CLASS_PATH.'BitUser.php' );
+namespace Bitweaver\Users;
+
+use Bitweaver\KernelTools;
/**
* Class that holds all information for a given user
@@ -40,7 +42,7 @@ class BitPermUser extends BitUser {
* @access public
* @return void
*/
- function __construct( $pUserId=NULL, $pContentId=NULL ) {
+ function __construct( $pUserId=null, $pContentId=null ) {
parent::__construct( $pUserId, $pContentId );
// Permission setup
@@ -63,11 +65,11 @@ class BitPermUser extends BitUser {
*
* @param numeric $pUserId User ID of the user you want to hijack
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function assumeUser( $pUserId ) {
global $gBitUser;
- $ret = FALSE;
+ $ret = false;
// make double sure the current logged in user has permission, check for p_users_admin, not admin, as that is all you need for assuming another user.
// this enables creating of a non technical site adminstrators group, eg customer support representatives.
@@ -75,10 +77,10 @@ class BitPermUser extends BitUser {
$assumeUser = new BitPermUser( $pUserId );
$assumeUser->loadPermissions();
if( $assumeUser->isAdmin() ) {
- $this->mErrors['assume_user'] = tra( "User administrators cannot be assumed." );
+ $this->mErrors['assume_user'] = KernelTools::tra( "User administrators cannot be assumed." );
} else {
$this->mDb->query( "UPDATE `".BIT_DB_PREFIX."users_cnxn` SET `user_id`=?, `assume_user_id`=? WHERE `cookie`=?", array( $pUserId, $gBitUser->mUserId, $_COOKIE[$this->getSiteCookieName()] ) );
- $ret = TRUE;
+ $ret = true;
}
}
@@ -88,20 +90,19 @@ class BitPermUser extends BitUser {
/**
* load
*
- * @param boolean $pFull Load all permissions
+ * @param bool $pFull Load all permissions
* @param string $pUserName User login name
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function load( $pFull=FALSE, $pUserName=NULL ) {
- if( BitUser::load( $pFull, $pUserName ) ) {
- if( $pFull ) {
+ public function load( ...$extraParams ): bool {
+ if( BitUser::load( $extraParams[0], $extraParams[1] ) ) {
+ if( !empty($extraParams[0]) && $extraParams[0] ) {
unset( $this->mPerms );
$this->loadGroups();
$this->loadPermissions();
}
}
- return( $this->mUserId != NULL );
+ return $this->mUserId != null;
}
/**
@@ -110,11 +111,12 @@ class BitPermUser extends BitUser {
* @access public
* @return void
*/
- function sanitizeUserInfo() {
- if( !empty( $this->mInfo )) {
+ function sanitizeUserInfo()
+ {
+ if (!empty( $this->mInfo )) {
$unsanitary = array( 'provpass', 'hash', 'challenge', 'user_password' );
- foreach( array_keys( $this->mInfo ) as $key ) {
- if( in_array( $key, $unsanitary )) {
+ foreach ( array_keys( $this->mInfo ) as $key ) {
+ if (in_array( $key, $unsanitary )) {
unset( $this->mInfo[$key] );
}
}
@@ -125,36 +127,36 @@ class BitPermUser extends BitUser {
* store
*
* @param array $pParamHash
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function store( &$pParamHash ) {
+ public function store( array &$pParamHash ) : bool
+ {
global $gBitSystem;
// keep track of newUser before calling base class
$newUser = !$this->isRegistered();
$this->StartTrans();
- if( BitUser::store( $pParamHash ) && $newUser ) {
+ if (BitUser::store( $pParamHash ) && $newUser) {
$defaultGroups = $this->getDefaultGroup();
$this->addUserToGroup( $this->mUserId, $defaultGroups );
- if( $gBitSystem->isFeatureActive( 'users_eponymous_groups' ) ) {
+ if ($gBitSystem->isFeatureActive( 'users_eponymous_groups' )) {
// Create a group just for this user, for permissions assignment.
$groupParams = array(
'user_id' => $this->mUserId,
'name' => $pParamHash['user_store']['login'],
- 'desc' => "Personal group for ".( !empty( $pParamHash['user_store']['real_name'] ) ? $pParamHash['user_store']['real_name'] : $pParamHash['user_store']['login'] )
+ 'desc' => "Personal group for " . ( !empty( $pParamHash['user_store']['real_name'] ) ? $pParamHash['user_store']['real_name'] : $pParamHash['user_store']['login'] )
);
- if( $this->storeGroup( $groupParams ) ) {
+ if ($this->storeGroup( $groupParams )) {
$this->addUserToGroup( $this->mUserId, $groupParams['group_id'] );
}
}
- $this->load( TRUE );
+ $this->load( true );
// store any uploaded images, this can stuff mErrors, so we want to do this as the very last thing.
- $pParamHash['upload']['thumbnail'] = FALSE; // i don't think this does anything - perhaps replace it by setting thumbnail_sizes
+ $pParamHash['upload']['thumbnail'] = false; // i don't think this does anything - perhaps replace it by setting thumbnail_sizes
$this->storeImages( $pParamHash );
}
$this->CompleteTrans();
- return( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
@@ -163,74 +165,77 @@ class BitPermUser extends BitUser {
* @param string $pGroupName
* @param numeric $pUserId
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function groupExists( $pGroupName, $pUserId = ROOT_USER_ID ) {
- static $sGroups = array();
- if( !isset( $sGroups[$pUserId][$pGroupName] ) ) {
+ function groupExists( $pGroupName, $pUserId = ROOT_USER_ID )
+ {
+ static $sGroups = [];
+ if (!isset( $sGroups[$pUserId][$pGroupName] )) {
$bindVars = array( $pGroupName );
$whereSql = '';
- if( $pUserId != '*' ) {
+ if ($pUserId != '*') {
$whereSql = 'AND `user_id`=?';
$bindVars[] = $pUserId;
}
$query = "
SELECT ug.`group_name`, ug.`group_id`, ug.`user_id`
- FROM `".BIT_DB_PREFIX."users_groups` ug
+ FROM `" . BIT_DB_PREFIX . "users_groups` ug
WHERE `group_name`=? $whereSql";
- if( $result = $this->mDb->getAssoc( $query, $bindVars ) ) {
- if( empty( $sGroups[$pUserId] ) ) {
- $sGroups[$pUserId] = array();
+ if ($result = $this->mDb->getAssoc( $query, $bindVars )) {
+ if (empty( $sGroups[$pUserId] )) {
+ $sGroups[$pUserId] = [];
}
$sGroups[$pUserId][$pGroupName] = $result[$pGroupName];
- } else {
- $sGroups[$pUserId][$pGroupName]['group_id'] = NULL;
+ }
+ else {
+ $sGroups[$pUserId][$pGroupName]['group_id'] = null;
}
}
- return( $sGroups[$pUserId][$pGroupName]['group_id'] );
+ return $sGroups[$pUserId][$pGroupName]['group_id'];
}
/**
* removes user and associated private data
*
* @access public
- * @return always FALSE???
- * TODO: fix return
+ * @return bool
*/
- function expunge( $pExpungeContent=NULL) {
+ public function expunge() : bool
+ {
global $gBitSystem, $gBitUser;
$this->clearFromCache();
- if( $this->isValid() ) {
+ if ($this->isValid()) {
$this->StartTrans();
- if( $this->mUserId == $gBitUser->mUserId ) {
+ if ($this->mUserId == $gBitUser->mUserId) {
$this->mDb->RollbackTrans();
- $gBitSystem->fatalError( tra( 'You cannot delete yourself' ) );
- } elseif( $this->mUserId != ANONYMOUS_USER_ID ) {
+ $gBitSystem->fatalError( KernelTools::tra( 'You cannot delete yourself' ) );
+ }
+ elseif ($this->mUserId != ANONYMOUS_USER_ID) {
$userTables = array(
'users_groups_map',
);
- foreach( $userTables as $table ) {
- $query = "DELETE FROM `".BIT_DB_PREFIX.$table."` WHERE `user_id` = ?";
+ foreach ( $userTables as $table ) {
+ $query = "DELETE FROM `" . BIT_DB_PREFIX . $table . "` WHERE `user_id` = ?";
$result = $this->mDb->query( $query, array( $this->mUserId ) );
}
- if( parent::expunge( $pExpungeContent ) ) {
+ if ( parent::expunge() ) {
$this->CompleteTrans();
- return TRUE;
- } else {
+ return true;
+ }
+ else {
$this->mDb->RollbackTrans();
}
- } else {
+ }
+ else {
$this->mDb->RollbackTrans();
- $gBitSystem->fatalError( tra( 'The anonymous user cannot be deleted' ) );
+ $gBitSystem->fatalError( KernelTools::tra( 'The anonymous user cannot be deleted' ) );
}
}
- return FALSE;
+ return true;
}
-
-
// =-=-=-=-=-=-=-=-=-=-=-= Group Functions =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/**
* loadGroups load groups into $this->mGroups
@@ -239,9 +244,10 @@ class BitPermUser extends BitUser {
* @access public
* @return void
*/
- function loadGroups( $pForceRefresh = FALSE ) {
- if( $this->isValid() ) {
- $this->mGroups = $this->getGroups( NULL, $pForceRefresh );
+ public function loadGroups( $pForceRefresh = false )
+ {
+ if ($this->isValid()) {
+ $this->mGroups = $this->getGroups( null, $pForceRefresh );
}
}
@@ -250,21 +256,24 @@ class BitPermUser extends BitUser {
*
* @param mixed $pGroupMixed Group ID or Group Name (deprecated)
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function isInGroup( $pGroupMixed ) {
- $ret = FALSE;
- if( $this->isAdmin() ) {
- $ret = TRUE;
- } if( $this->isValid() ) {
- if( empty( $this->mGroups ) ) {
+ public function isInGroup( $pGroupMixed )
+ {
+ $ret = false;
+ if ($this->isAdmin()) {
+ $ret = true;
+ }
+ if ($this->isValid()) {
+ if (empty( $this->mGroups )) {
$this->loadGroups();
}
- if( preg_match( '/A-Za-z/', $pGroupMixed ) ) {
+ if (preg_match( '/A-Za-z/', $pGroupMixed )) {
// Old style group name passed in
deprecated( "Please use the Group ID instead of the Group name." );
$ret = in_array( $pGroupMixed, $this->mGroups );
- } else {
+ }
+ else {
$ret = isset( $this->mGroups[$pGroupMixed] );
}
}
@@ -278,38 +287,42 @@ class BitPermUser extends BitUser {
* @access public
* @return array of groups
*/
- function getAllGroups( &$pListHash ) {
- if( empty( $pListHash['sort_mode'] ) || $pListHash['sort_mode'] == 'name_asc' ) {
+ function getAllGroups( &$pListHash )
+ {
+ if (empty( $pListHash['sort_mode'] ) || $pListHash['sort_mode'] == 'name_asc') {
$pListHash['sort_mode'] = 'group_name_asc';
}
LibertyContent::prepGetList( $pListHash );
$sortMode = $this->mDb->convertSortmode( $pListHash['sort_mode'] );
- if( !empty( $pListHash['find_groups'] ) ) {
+ if (!empty( $pListHash['find_groups'] )) {
$mid = " AND UPPER(`group_name`) like ?";
- $bindvars[] = "%".strtoupper( $pListHash['find_groups'] )."%";
- } elseif( !empty( $pListHash['find'] ) ) {
+ $bindvars[] = "%" . strtoupper( $pListHash['find_groups'] ) . "%";
+ }
+ elseif (!empty( $pListHash['find'] )) {
$mid = " AND UPPER(`group_name`) like ?";
- $bindvars[] = "%".strtoupper( $pListHash['find'] )."%";
- } else {
+ $bindvars[] = "%" . strtoupper( $pListHash['find'] ) . "%";
+ }
+ else {
$mid = '';
- $bindvars = array();
+ $bindvars = [];
}
- if( !empty( $pListHash['hide_root_groups'] )) {
- $mid .= ' AND `user_id` <> '.ROOT_USER_ID;
- } elseif( !empty( $pListHash['only_root_groups'] )) {
- $mid .= ' AND `user_id` = '.ROOT_USER_ID;
+ if (!empty( $pListHash['hide_root_groups'] )) {
+ $mid .= ' AND `user_id` <> ' . ROOT_USER_ID;
+ }
+ elseif (!empty( $pListHash['only_root_groups'] )) {
+ $mid .= ' AND `user_id` = ' . ROOT_USER_ID;
}
- if( !empty( $pListHash['user_id'] ) ){
+ if (!empty( $pListHash['user_id'] )) {
$mid .= ' AND `user_id` = ? ';
$bindvars[] = $pListHash['user_id'];
}
- if( !empty( $pListHash['is_public'] ) ) {
+ if (!empty( $pListHash['is_public'] )) {
$mid .= ' AND `is_public` = ?';
$bindvars[] = $pListHash['is_public'];
}
- if( !empty( $pListHash['visible'] ) && !$this->isAdmin() ){
+ if (!empty( $pListHash['visible'] ) && !$this->isAdmin()) {
global $gBitUser;
$mid .= ' AND `user_id` = ? OR `is_public` = ? ';
$bindvars[] = $gBitUser->mUserId;
@@ -317,22 +330,22 @@ class BitPermUser extends BitUser {
}
- $mid = preg_replace('/^ AND */',' WHERE ', $mid);
+ $mid = preg_replace( '/^ AND */', ' WHERE ', $mid );
$query = "
SELECT `user_id`, `group_id`, `group_name` , `group_desc`, `group_home`, `is_default`, `is_public`
- FROM `".BIT_DB_PREFIX."users_groups` $mid
+ FROM `" . BIT_DB_PREFIX . "users_groups` $mid
ORDER BY $sortMode";
- $ret = array();
- if( $rs = $this->mDb->query( $query, $bindvars ) ) {
- while( $row = $rs->fetchRow() ) {
+ $ret = [];
+ if ($rs = $this->mDb->query( $query, $bindvars )) {
+ while ( $row = $rs->fetchRow() ) {
$groupId = $row['group_id'];
$ret[$groupId] = $row;
- $ret[$groupId]['perms'] = $this->getGroupPermissions( array( 'group_id' => $groupId ));
+ $ret[$groupId]['perms'] = $this->getGroupPermissions( array( 'group_id' => $groupId ) );
}
}
- $pListHash['cant'] = $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."users_groups` $mid", $bindvars );
+ $pListHash['cant'] = $this->mDb->getOne( "SELECT COUNT(*) FROM `" . BIT_DB_PREFIX . "users_groups` $mid", $bindvars );
return $ret;
}
@@ -344,16 +357,17 @@ class BitPermUser extends BitUser {
* @access public
* @return array of groups a user belongs to
*/
- function getAllUserGroups( $pUserId = NULL ) {
- if( empty( $pUserId ) ) {
+ function getAllUserGroups( $pUserId = null )
+ {
+ if (empty( $pUserId )) {
$pUserId = $this->mUserId;
}
$sql = "
- SELECT ug.`group_id` AS `hash_key`, ug.* FROM `".BIT_DB_PREFIX."users_groups` ug
+ SELECT ug.`group_id` AS `hash_key`, ug.* FROM `" . BIT_DB_PREFIX . "users_groups` ug
WHERE `user_id`=?
ORDER BY ug.`group_name` ASC";
- return $this->mDb->getAssoc( $sql, array( $pUserId ));
+ return $this->mDb->getAssoc( $sql, array( $pUserId ) );
}
/**
@@ -361,18 +375,19 @@ class BitPermUser extends BitUser {
*
* @param numeric $pGroupId
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
- function expungeGroup( $pGroupId ) {
+ function expungeGroup( $pGroupId )
+ {
// we cannot remove the anonymous group
- if( $pGroupId != ANONYMOUS_GROUP_ID ) {
- $query = "DELETE FROM `".BIT_DB_PREFIX."users_groups_map` WHERE `group_id` = ?";
- $result = $this->mDb->query( $query, array( $pGroupId ));
- $query = "DELETE FROM `".BIT_DB_PREFIX."users_group_permissions` WHERE `group_id` = ?";
- $result = $this->mDb->query( $query, array( $pGroupId ));
- $query = "DELETE FROM `".BIT_DB_PREFIX."users_groups` WHERE `group_id` = ?";
- $result = $this->mDb->query( $query, array( $pGroupId ));
- return TRUE;
+ if ($pGroupId != ANONYMOUS_GROUP_ID) {
+ $query = "DELETE FROM `" . BIT_DB_PREFIX . "users_groups_map` WHERE `group_id` = ?";
+ $result = $this->mDb->query( $query, array( $pGroupId ) );
+ $query = "DELETE FROM `" . BIT_DB_PREFIX . "users_group_permissions` WHERE `group_id` = ?";
+ $result = $this->mDb->query( $query, array( $pGroupId ) );
+ $query = "DELETE FROM `" . BIT_DB_PREFIX . "users_groups` WHERE `group_id` = ?";
+ $result = $this->mDb->query( $query, array( $pGroupId ) );
+ return true;
}
}
@@ -383,14 +398,15 @@ class BitPermUser extends BitUser {
* @access public
* @return Default Group ID if one is set
*/
- function getDefaultGroup( $pGroupId = NULL ) {
- $bindvars = FALSE;
+ function getDefaultGroup( $pGroupId = null )
+ {
+ $bindvars = false;
$whereSql = '';
- if( @BitBase::verifyId( $pGroupId )) {
+ if (\Bitweaver\BitBase::verifyId( $pGroupId )) {
$whereSql = "AND `group_id`=? ";
$bindvars = array( $pGroupId );
}
- return( $this->mDb->getAssoc( "SELECT `group_id`, `group_name` FROM `".BIT_DB_PREFIX."users_groups` WHERE `is_default` = 'y' $whereSql ", $bindvars ) );
+ return $this->mDb->getAssoc( "SELECT `group_id`, `group_name` FROM `" . BIT_DB_PREFIX . "users_groups` WHERE `is_default` = 'y' $whereSql ", $bindvars );
}
/**
@@ -400,16 +416,16 @@ class BitPermUser extends BitUser {
* @access public
* @return list of users who are in the group id
*/
- function getGroupUsers( $pGroupId ) {
- $ret = array();
- if( @BitBase::verifyId( $pGroupId )) {
+ function getGroupUsers( $pGroupId )
+ {
+ $ret = [];
+ if (\Bitweaver\BitBase::verifyId( $pGroupId )) {
$query = "
- SELECT uu.`user_id` AS hash_key, uu.`login`, uu.`real_name`, uu.`user_id`, uu.`email`, uu.`registration_date`, uu.`last_login`
- FROM `".BIT_DB_PREFIX."users_users` uu
- INNER JOIN `".BIT_DB_PREFIX."users_groups_map` ug ON (uu.`user_id`=ug.`user_id`)
- WHERE `group_id`=?
- ORDER BY uu.`registration_date`";
- $ret = $this->mDb->getAssoc( $query, array( $pGroupId ));
+ SELECT uu.`user_id` AS hash_key, uu.`login`, uu.`real_name`, uu.`user_id`
+ FROM `" . BIT_DB_PREFIX . "users_users` uu
+ INNER JOIN `" . BIT_DB_PREFIX . "users_groups_map` ug ON (uu.`user_id`=ug.`user_id`)
+ WHERE `group_id`=?";
+ $ret = $this->mDb->getAssoc( $query, array( $pGroupId ) );
}
return $ret;
}
@@ -419,13 +435,14 @@ class BitPermUser extends BitUser {
*
* @param array $pGroupId
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function getGroupHome( $pGroupId ) {
- $ret = FALSE;
- if( @BitBase::verifyId( $pGroupId )) {
- $query = "SELECT `group_home` FROM `".BIT_DB_PREFIX."users_groups` WHERE `group_id`=?";
- $ret = $this->mDb->getOne( $query,array( $pGroupId ) );
+ function getGroupHome( $pGroupId )
+ {
+ $ret = false;
+ if (\Bitweaver\BitBase::verifyId( $pGroupId )) {
+ $query = "SELECT `group_home` FROM `" . BIT_DB_PREFIX . "users_groups` WHERE `group_id`=?";
+ $ret = $this->mDb->getOne( $query, array( $pGroupId ) );
}
return $ret;
}
@@ -433,16 +450,18 @@ class BitPermUser extends BitUser {
/**
* storeUserDefaultGroup
*
- * @param array $pUserId
- * @param array $pGroupId
+ * @param integer $pUserId
+ * @param integer $pGroupId
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
- function storeUserDefaultGroup( $pUserId, $pGroupId ) {
- if( @BitBase::verifyId( $pUserId ) && @BitBase::verifyId( $pGroupId )) {
- $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `default_group_id` = ? WHERE `user_id` = ?";
- return $this->mDb->query( $query, array( $pGroupId, $pUserId ));
+ function storeUserDefaultGroup( $pUserId, $pGroupId )
+ {
+ if (\Bitweaver\BitBase::verifyId( $pUserId ) && \Bitweaver\BitBase::verifyId( $pGroupId )) {
+ $query = "UPDATE `" . BIT_DB_PREFIX . "users_users` SET `default_group_id` = ? WHERE `user_id` = ?";
+ return $this->mDb->query( $query, [ $pGroupId, $pUserId ] );
}
+ return false;
}
/**
@@ -452,12 +471,13 @@ class BitPermUser extends BitUser {
* @access public
* @return void
*/
- function batchAssignUsersToGroup( $pGroupId ) {
- if( @BitBase::verifyId( $pGroupId )) {
+ function batchAssignUsersToGroup( $pGroupId )
+ {
+ if (\Bitweaver\BitBase::verifyId( $pGroupId )) {
$users = $this->getGroupUsers( $pGroupId );
- $result = $this->mDb->getCol( "SELECT uu.`user_id` FROM `".BIT_DB_PREFIX."users_users` uu" );
- foreach( $result as $userId ) {
- if( empty( $users[$userId] ) && $userId != ANONYMOUS_USER_ID ) {
+ $result = $this->mDb->getCol( "SELECT uu.`user_id` FROM `" . BIT_DB_PREFIX . "users_users` uu" );
+ foreach ( $result as $userId ) {
+ if (empty( $users[$userId] ) && $userId != ANONYMOUS_USER_ID) {
$this->addUserToGroup( $userId, $pGroupId );
}
}
@@ -469,12 +489,13 @@ class BitPermUser extends BitUser {
*
* @param array $pGroupId
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function batchSetUserDefaultGroup( $pGroupId ) {
- if( @BitBase::verifyId( $pGroupId )) {
- $users = $this->getGroupUsers($pGroupId);
- foreach( array_keys( $users ) as $userId ) {
+ function batchSetUserDefaultGroup( $pGroupId )
+ {
+ if (\Bitweaver\BitBase::verifyId( $pGroupId )) {
+ $users = $this->getGroupUsers( $pGroupId );
+ foreach ( array_keys( $users ) as $userId ) {
$this->storeUserDefaultGroup( $userId, $pGroupId );
}
}
@@ -487,19 +508,20 @@ class BitPermUser extends BitUser {
* @access public
* @return group information
*/
- function getGroupInfo( $pGroupId ) {
- if( @BitBase::verifyId( $pGroupId )) {
- $sql = "SELECT * FROM `".BIT_DB_PREFIX."users_groups` WHERE `group_id` = ?";
- $ret = $this->mDb->getRow( $sql, array( $pGroupId ));
+ function getGroupInfo( $pGroupId )
+ {
+ if (\Bitweaver\BitBase::verifyId( $pGroupId )) {
+ $sql = "SELECT * FROM `" . BIT_DB_PREFIX . "users_groups` WHERE `group_id` = ?";
+ $ret = $this->mDb->getRow( $sql, array( $pGroupId ) );
$listHash = array(
- 'group_id' => $pGroupId,
+ 'group_id' => $pGroupId,
'sort_mode' => 'up.perm_name_asc',
);
$ret["perms"] = $this->getGroupPermissions( $listHash );
- $sql = "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."users_groups_map` WHERE `group_id` = ?";
- $ret['num_members'] = $this->mDb->getOne( $sql, array( $pGroupId ));
+ $sql = "SELECT COUNT(*) FROM `" . BIT_DB_PREFIX . "users_groups_map` WHERE `group_id` = ?";
+ $ret['num_members'] = $this->mDb->getOne( $sql, array( $pGroupId ) );
return $ret;
}
@@ -511,23 +533,25 @@ class BitPermUser extends BitUser {
* @param numeric $pUserId User ID
* @param mixed $pGroupMixed A single group ID or an array of group IDs
* @access public
- * @return Either an ADO RecordSet (success) or FALSE (failure).
+ * @return Either an ADO RecordSet (success) or false (failure).
*/
- function addUserToGroup( $pUserId, $pGroupMixed ) {
- $result = FALSE;
- if( @BitBase::verifyId( $pUserId ) && !empty( $pGroupMixed )) {
- $result = TRUE;
- $addGroups = array();
- if( is_array( $pGroupMixed ) ) {
+ function addUserToGroup( $pUserId, $pGroupMixed )
+ {
+ $result = false;
+ if (\Bitweaver\BitBase::verifyId( $pUserId ) && !empty( $pGroupMixed )) {
+ $result = true;
+ $addGroups = [];
+ if (is_array( $pGroupMixed )) {
$addGroups = array_keys( $pGroupMixed );
- } elseif( @BitBase::verifyId($pGroupMixed) ) {
+ }
+ elseif (\Bitweaver\BitBase::verifyId( $pGroupMixed )) {
$addGroups = array( $pGroupMixed );
}
$currentUserGroups = $this->getGroups( $pUserId );
- foreach( $addGroups AS $groupId ) {
- if( !$this->mDb->getOne( "SELECT group_id FROM `".BIT_DB_PREFIX."users_groups_map` WHERE `user_id` = ? AND `group_id` = ?", array( $pUserId, $groupId ) ) ) {
- $query = "INSERT INTO `".BIT_DB_PREFIX."users_groups_map` (`user_id`,`group_id`) VALUES(?,?)";
- $result = $this->mDb->query( $query, array( $pUserId, $groupId ));
+ foreach ( $addGroups as $groupId ) {
+ if (!$this->mDb->getOne( "SELECT group_id FROM `" . BIT_DB_PREFIX . "users_groups_map` WHERE `user_id` = ? AND `group_id` = ?", array( $pUserId, $groupId ) )) {
+ $query = "INSERT INTO `" . BIT_DB_PREFIX . "users_groups_map` (`user_id`,`group_id`) VALUES(?,?)";
+ $result = $this->mDb->query( $query, array( $pUserId, $groupId ) );
}
}
}
@@ -538,19 +562,20 @@ class BitPermUser extends BitUser {
/**
* removeUserFromGroup
*
- * @param array $pUserId
- * @param array $pGroupId
+ * @param integer $pUserId
+ * @param integer $pGroupId
* @access public
* @return void
*/
- function removeUserFromGroup( $pUserId, $pGroupId ) {
- if( @BitBase::verifyId( $pUserId ) && @BitBase::verifyId( $pGroupId )) {
- $query = "DELETE FROM `".BIT_DB_PREFIX."users_groups_map` WHERE `user_id` = ? AND `group_id` = ?";
- $result = $this->mDb->query( $query, array( $pUserId, $pGroupId ));
+ function removeUserFromGroup( $pUserId, $pGroupId )
+ {
+ if (\Bitweaver\BitBase::verifyId( $pUserId ) && \Bitweaver\BitBase::verifyId( $pGroupId )) {
+ $query = "DELETE FROM `" . BIT_DB_PREFIX . "users_groups_map` WHERE `user_id` = ? AND `group_id` = ?";
+ $result = $this->mDb->query( $query, [ $pUserId, $pGroupId ] );
$default = $this->getDefaultGroup();
- if( $pGroupId == key( $default )) {
- $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `default_group_id` = NULL WHERE `user_id` = ?";
- $this->mDb->query( $query, array( $pUserId ));
+ if ($pGroupId == key( $default )) {
+ $query = "UPDATE `" . BIT_DB_PREFIX . "users_users` SET `default_group_id` = null WHERE `user_id` = ?";
+ $this->mDb->query( $query, [ $pUserId ] );
}
}
$this->clearFromCache();
@@ -561,29 +586,32 @@ class BitPermUser extends BitUser {
*
* @param array $pParamHash
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function verifyGroup( &$pParamHash ) {
- if( !empty($pParamHash['group_id'] )) {
- if( @$this->verifyId( $pParamHash['group_id'] )) {
+ function verifyGroup( &$pParamHash )
+ {
+ if (!empty( $pParamHash['group_id'] )) {
+ if (@$this->verifyId( $pParamHash['group_id'] )) {
$pParamHash['group_store']['group_id'] = $pParamHash['group_id'];
- } else {
+ }
+ else {
$this->mErrors['groups'] = 'Unknown Group';
}
}
- if( !empty( $pParamHash["name"] )) {
+ if (!empty( $pParamHash["name"] )) {
$pParamHash['group_store']['group_name'] = substr( $pParamHash["name"], 0, 30 );
}
- if( !empty( $pParamHash["desc"] )) {
- $pParamHash['group_store']['group_desc'] = substr( $pParamHash["desc"], 0, 255 );;
+ if (!empty( $pParamHash["desc"] )) {
+ $pParamHash['group_store']['group_desc'] = substr( $pParamHash["desc"], 0, 255 );
+ ;
}
- $pParamHash['group_store']['group_home'] = !empty( $pParamHash["home"] ) ? $pParamHash["home"] : '';
- $pParamHash['group_store']['is_default'] = !empty( $pParamHash["is_default"] ) ? $pParamHash["is_default"] : NULL;
- $pParamHash['group_store']['user_id'] = @$this->verifyId( $pParamHash["user_id"] ) ? $pParamHash["user_id"] : $this->mUserId;
- $pParamHash['group_store']['is_public'] = !empty( $pParamHash['is_public'] ) ? $pParamHash['is_public'] : NULL;
+ $pParamHash['group_store']['group_home'] = !empty( $pParamHash["home"] ) ? $pParamHash["home"] : '';
+ $pParamHash['group_store']['is_default'] = !empty( $pParamHash["is_default"] ) ? $pParamHash["is_default"] : null;
+ $pParamHash['group_store']['user_id'] = @$this->verifyId( $pParamHash["user_id"] ) ? $pParamHash["user_id"] : $this->mUserId;
+ $pParamHash['group_store']['is_public'] = !empty( $pParamHash['is_public'] ) ? $pParamHash['is_public'] : null;
$pParamHash['group_store']['after_registration_page'] = !empty( $pParamHash['after_registration_page'] ) ? $pParamHash['after_registration_page'] : '';
- return( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
@@ -591,34 +619,37 @@ class BitPermUser extends BitUser {
*
* @param array $pParamHash
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function storeGroup( &$pParamHash ) {
- global $gBitSystem;
- if ($this->verifyGroup( $pParamHash)) {
+ function storeGroup( &$pParamHash )
+ {
+ global $gBitSystem, $gBitUser;
+ if ($this->verifyGroup( $pParamHash )) {
$this->StartTrans();
- if( empty( $pParamHash['group_id'] ) ) {
+ if (empty( $pParamHash['group_id'] )) {
$pParamHash['group_id'] = $this->mDb->GenID( 'users_groups_id_seq' );
$pParamHash['group_store']['group_id'] = $pParamHash['group_id'];
- $result = $this->mDb->associateInsert( BIT_DB_PREFIX.'users_groups', $pParamHash['group_store'] );
- } else {
- $sql = "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."users_groups` WHERE `group_id` = ?";
- $groupExists = $this->mDb->getOne($sql, array($pParamHash['group_id']));
+ $result = $this->mDb->associateInsert( BIT_DB_PREFIX . 'users_groups', $pParamHash['group_store'] );
+ }
+ else {
+ $sql = "SELECT COUNT(*) FROM `" . BIT_DB_PREFIX . "users_groups` WHERE `group_id` = ?";
+ $groupExists = $this->mDb->getOne( $sql, array( $pParamHash['group_id'] ) );
if ($groupExists) {
- $result = $this->mDb->associateUpdate( BIT_DB_PREFIX.'users_groups', $pParamHash['group_store'], array( "group_id" => $pParamHash['group_id'] ) );
- } else {
+ $result = $this->mDb->associateUpdate( BIT_DB_PREFIX . 'users_groups', $pParamHash['group_store'], array( "group_id" => $pParamHash['group_id'] ) );
+ }
+ else {
// A group_id was specified but that group does not exist yet
$pParamHash['group_store']['group_id'] = $pParamHash['group_id'];
- $result = $this->mDb->associateInsert(BIT_DB_PREFIX.'users_groups', $pParamHash['group_store']);
+ $result = $this->mDb->associateInsert( BIT_DB_PREFIX . 'users_groups', $pParamHash['group_store'] );
}
}
- if( isset( $_REQUEST['batch_set_default'] ) and $_REQUEST['batch_set_default'] == 'on' ) {
+ if (isset( $_REQUEST['batch_set_default'] ) and $_REQUEST['batch_set_default'] == 'on') {
$gBitUser->batchSetUserDefaultGroup( $pParamHash['group_id'] );
}
$this->CompleteTrans();
}
- return ( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
@@ -629,11 +660,12 @@ class BitPermUser extends BitUser {
* @access public
* @return array of group data
*/
- public static function getGroupNameFromId( $pGroupId ) {
+ public static function getGroupNameFromId( $pGroupId )
+ {
$ret = '';
- if( static::verifyId( $pGroupId ) ) {
+ if (static::verifyId( $pGroupId )) {
global $gBitDb;
- $ret = $gBitDb->getOne( "SELECT `group_name` FROM `".BIT_DB_PREFIX."users_groups` WHERE `group_id`=?", array( $pGroupId ) );
+ $ret = $gBitDb->getOne( "SELECT `group_name` FROM `" . BIT_DB_PREFIX . "users_groups` WHERE `group_id`=?", array( $pGroupId ) );
}
return $ret;
}
@@ -646,22 +678,24 @@ class BitPermUser extends BitUser {
* @access public
* @return array of group data
*/
- function getGroupUserData( $pGroupId, $pColumns ) {
- $ret = array();
- if( @$this->verifyId( $pGroupId ) && !empty( $pColumns ) ) {
- if( is_array( $pColumns ) ) {
+ function getGroupUserData( $pGroupId, $pColumns )
+ {
+ $ret = [];
+ if (@$this->verifyId( $pGroupId ) && !empty( $pColumns )) {
+ if (is_array( $pColumns )) {
$col = implode( $pColumns, ',' );
$exec = 'getAssoc';
- } else {
- $col = '`'.$pColumns.'`';
+ }
+ else {
+ $col = '`' . $pColumns . '`';
$exec = 'getArray';
}
$query = "
SELECT $col
- FROM `".BIT_DB_PREFIX."users_users` uu
- INNER JOIN `".BIT_DB_PREFIX."users_groups_map` ugm ON (uu.`user_id`=ugm.`user_id`)
+ FROM `" . BIT_DB_PREFIX . "users_users` uu
+ INNER JOIN `" . BIT_DB_PREFIX . "users_groups_map` ugm ON (uu.`user_id`=ugm.`user_id`)
WHERE ugm.`group_id` = ?";
- $ret = $this->mDb->$exec( $query, array( $pGroupId ));
+ $ret = $this->mDb->$exec( $query, array( $pGroupId ) );
}
return $ret;
}
@@ -671,28 +705,29 @@ class BitPermUser extends BitUser {
* loadPermissions
*
* @access public
- * @return TRUE on success, FALSE if no perms were loaded
+ * @return bool true on success, false if no perms were loaded
*/
- function loadPermissions( $pForceReload=FALSE ) {
- if( $this->isValid() && (empty( $this->mPerms ) || $pForceReload) ) {
- $this->mPerms = array();
+ function loadPermissions( $pForceReload = false )
+ {
+ if ($this->isValid() && ( empty( $this->mPerms ) || $pForceReload )) {
+ $this->mPerms = [];
// the double up.`perm_name` is intentional - the first is for hash key, the second is for hash value
$query = "
SELECT up.`perm_name` AS `hash_key`, up.`perm_name`, up.`perm_desc`, up.`perm_level`, up.`package`
- FROM `".BIT_DB_PREFIX."users_permissions` up
- INNER JOIN `".BIT_DB_PREFIX."users_group_permissions` ugp ON ( ugp.`perm_name`=up.`perm_name` )
- INNER JOIN `".BIT_DB_PREFIX."users_groups` ug ON ( ug.`group_id`=ugp.`group_id` )
- LEFT OUTER JOIN `".BIT_DB_PREFIX."users_groups_map` ugm ON ( ugm.`group_id`=ugp.`group_id` AND ugm.`user_id` = ? )
- WHERE ug.`group_id`= ".ANONYMOUS_GROUP_ID." OR ugm.`group_id`=ug.`group_id`";
- $this->mPerms = $this->mDb->getAssoc( $query, array( $this->mUserId ));
+ FROM `" . BIT_DB_PREFIX . "users_permissions` up
+ INNER JOIN `" . BIT_DB_PREFIX . "users_group_permissions` ugp ON ( ugp.`perm_name`=up.`perm_name` )
+ INNER JOIN `" . BIT_DB_PREFIX . "users_groups` ug ON ( ug.`group_id`=ugp.`group_id` )
+ LEFT OUTER JOIN `" . BIT_DB_PREFIX . "users_groups_map` ugm ON ( ugm.`group_id`=ugp.`group_id` AND ugm.`user_id` = ? )
+ WHERE ug.`group_id`= " . ANONYMOUS_GROUP_ID . " OR ugm.`group_id`=ug.`group_id`";
+ $this->mPerms = $this->mDb->getAssoc( $query, array( $this->mUserId ) );
// Add in override permissions
- if( !empty( $this->mPermsOverride ) ) {
- foreach( $this->mPermsOverride as $key => $val ) {
+ if (!empty( $this->mPermsOverride )) {
+ foreach ( $this->mPermsOverride as $key => $val ) {
$this->mPerms[$key] = $val;
}
}
}
- return( !empty( $this->mPerms ) );
+ return !empty( $this->mPerms );
}
/**
@@ -701,13 +736,14 @@ class BitPermUser extends BitUser {
* @access public
* @return array of permissions that have not been assigned to any group yet
*/
- function getUnassignedPerms() {
+ function getUnassignedPerms()
+ {
$query = "SELECT up.`perm_name` AS `hash_key`, up.*
- FROM `".BIT_DB_PREFIX."users_permissions` up
- LEFT OUTER JOIN `".BIT_DB_PREFIX."users_group_permissions` ugp ON( up.`perm_name` = ugp.`perm_name` )
- WHERE ugp.`group_id` IS NULL AND up.`perm_name` <> ?
+ FROM `" . BIT_DB_PREFIX . "users_permissions` up
+ LEFT OUTER JOIN `" . BIT_DB_PREFIX . "users_group_permissions` ugp ON( up.`perm_name` = ugp.`perm_name` )
+ WHERE ugp.`group_id` IS null AND up.`perm_name` <> ?
ORDER BY `package`, up.`perm_name` ASC";
- return( $this->mDb->getAssoc( $query, array( '' )));
+ return $this->mDb->getAssoc( $query, array( '' ) );
}
/**
@@ -715,11 +751,12 @@ class BitPermUser extends BitUser {
*
* @param array $pCheckTicket
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function isAdmin() {
+ function isAdmin()
+ {
// we can't use hasPermission here since it turn into an endless loop
- return( !empty( $this->mPerms['p_admin'] ));
+ return !empty( $this->mPerms['p_admin'] );
}
/**
@@ -727,30 +764,34 @@ class BitPermUser extends BitUser {
*
* @param array $pPerm Perm name
* @access public
- * @return TRUE if the user has a permission, FALSE if they don't
+ * @return bool true if the user has a permission, false if they don't
*/
- function hasPermission( $pPerm ) {
- $ret = FALSE;
- if( $this->isAdmin() ) {
- $ret = TRUE;
- } elseif( $this->isValid() ) {
+ function hasPermission( $pPerm )
+ {
+ $ret = false;
+ if ($this->isAdmin()) {
+ $ret = true;
+ }
+ elseif ($this->isValid()) {
$ret = isset( $this->mPerms[$pPerm] );
}
- return ( $ret );
+ return $ret;
}
/**
* verifyPermission check if a user has a given permission and if not
* it will display the error template and die()
* @param $pPermission value of a given permission
- * @return none
+ * @return void
* @access public
*/
- function verifyPermission( $pPermission, $pMsg = NULL ) {
+ function verifyPermission( $pPermission, $pMsg = null )
+ {
global $gBitSmarty, $gBitSystem, ${$pPermission};
- if( empty( $pPermission ) || $this->hasPermission( $pPermission ) ) {
- return TRUE;
- } else {
+ if (empty( $pPermission ) || $this->hasPermission( $pPermission )) {
+ return;
+ }
+ else {
$gBitSystem->fatalPermission( $pPermission, $pMsg );
}
}
@@ -763,56 +804,55 @@ class BitPermUser extends BitUser {
* @param string $find search for a particular permission
* @param array $pSortMode sort mode of return hash
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return array true on success, false on failure
*/
- function getGroupPermissions( $pParamHash = NULL ) {
+ public function getGroupPermissions( $pParamHash = null )
+ {
global $gBitSystem;
- $ret = $bindVars = array();
+ $ret = $bindVars = [];
$whereSql = $selectSql = $fromSql = '';
- if( !empty( $pParamHash['sort_mode'] )) {
- $sortMode = $this->mDb->convertSortmode( $pParamHash['sort_mode'] );
- } else {
- $sortMode = 'up.`package`, up.`perm_name` ASC';
- }
+ $sortMode = ( !empty( $pParamHash['sort_mode'] ) ) ? $this->mDb->convertSortmode( $pParamHash['sort_mode'] ) : 'up.`package`, up.`perm_name` ASC';
- if( !empty( $pParamHash['package'] )) {
+ if (!empty( $pParamHash['package'] )) {
$whereSql = ' WHERE `package`= ? ';
$bindVars[] = $pParamHash['package'];
}
- if( @BitBase::verifyId( $pParamHash['group_id'] )) {
+ if (\Bitweaver\BitBase::verifyId( $pParamHash['group_id'] )) {
$selectSql = ', ugp.`perm_value` AS `hasPerm` ';
- $fromSql = ' INNER JOIN `'.BIT_DB_PREFIX.'users_group_permissions` ugp ON ( ugp.`perm_name`=up.`perm_name` ) ';
- if( $whereSql ) {
+ $fromSql = ' INNER JOIN `' . BIT_DB_PREFIX . 'users_group_permissions` ugp ON ( ugp.`perm_name`=up.`perm_name` ) ';
+ if ($whereSql) {
$whereSql .= " AND ugp.`group_id`=?";
- } else {
+ }
+ else {
$whereSql .= " WHERE ugp.`group_id`=?";
}
$bindVars[] = $pParamHash['group_id'];
}
- if( !empty( $pParamHash['find'] )) {
- if( $whereSql ) {
+ if (!empty( $pParamHash['find'] )) {
+ if ($whereSql) {
$whereSql .= " AND `perm_name` like ?";
- } else {
+ }
+ else {
$whereSql .= " WHERE `perm_name` like ?";
}
- $bindVars[] = '%'.$pParamHash['find'].'%';
+ $bindVars[] = '%' . $pParamHash['find'] . '%';
}
// the double up.`perm_name` is intentional - the first is for hash key, the second is for hash value
$query = "
SELECT up.`perm_name` AS `hash_key`, up.`perm_name`, up.`perm_desc`, up.`perm_level`, up.`package` $selectSql
- FROM `".BIT_DB_PREFIX."users_permissions` up $fromSql $whereSql
+ FROM `" . BIT_DB_PREFIX . "users_permissions` up $fromSql $whereSql
ORDER BY $sortMode";
$perms = $this->mDb->getAssoc( $query, $bindVars );
// weed out permissions of inactive packages
- $ret = array();
- foreach( $perms as $key => $perm ) {
- if( $gBitSystem->isPackageActive( $perm['package'] )) {
+ $ret = [];
+ foreach ( $perms as $key => $perm ) {
+ if ($gBitSystem->isPackageActive( $perm['package'] )) {
$ret[$key] = $perm;
}
}
@@ -829,17 +869,18 @@ class BitPermUser extends BitUser {
* @access public
* @return void
*/
- function assignLevelPermissions( $pGroupId, $pLevel, $pPackage = NULL) {
- if( @BitBase::verifyId( $pGroupId ) && !empty( $pLevel )) {
+ function assignLevelPermissions( $pGroupId, $pLevel, $pPackage = null )
+ {
+ if (\Bitweaver\BitBase::verifyId( $pGroupId ) && !empty( $pLevel )) {
$bindvars = array( $pLevel );
$whereSql = '';
- if( !empty( $pPackage ) ) {
+ if (!empty( $pPackage )) {
$whereSql = ' AND `package`=?';
array_push( $bindvars, $pPackage );
}
- $query = "SELECT `perm_name` FROM `".BIT_DB_PREFIX."users_permissions` WHERE `perm_level` = ? $whereSql";
- if( $result = $this->mDb->query( $query, $bindvars ) ) {
- while( $row = $result->fetchRow() ) {
+ $query = "SELECT `perm_name` FROM `" . BIT_DB_PREFIX . "users_permissions` WHERE `perm_level` = ? $whereSql";
+ if ($result = $this->mDb->query( $query, $bindvars )) {
+ while ( $row = $result->fetchRow() ) {
$this->assignPermissionToGroup( $row['perm_name'], $pGroupId );
}
}
@@ -852,8 +893,9 @@ class BitPermUser extends BitUser {
* @access public
* @return array of packages
*/
- function getPermissionPackages() {
- return( $this->mDb->getCol( "SELECT DISTINCT(`package`) FROM `".BIT_DB_PREFIX."users_permissions` ORDER BY `package`" ) );
+ function getPermissionPackages()
+ {
+ return $this->mDb->getCol( "SELECT DISTINCT(`package`) FROM `" . BIT_DB_PREFIX . "users_permissions` ORDER BY `package`" );
}
/**
@@ -862,15 +904,15 @@ class BitPermUser extends BitUser {
* @param array $perm
* @param array $pGroupId
* @access public
- * @return TRUE on success
+ * @return bool true on success
*/
function assignPermissionToGroup( $pPerm, $pGroupId ) {
- if( @BitBase::verifyId( $pGroupId ) && !empty( $pPerm )) {
+ if( \Bitweaver\BitBase::verifyId( $pGroupId ) && !empty( $pPerm )) {
$query = "DELETE FROM `".BIT_DB_PREFIX."users_group_permissions` WHERE `group_id` = ? AND `perm_name` = ?";
$result = $this->mDb->query( $query, array( $pGroupId, $pPerm ));
$query = "INSERT INTO `".BIT_DB_PREFIX."users_group_permissions`(`group_id`, `perm_name`) VALUES(?, ?)";
$result = $this->mDb->query( $query, array( $pGroupId, $pPerm ));
- return TRUE;
+ return true;
}
}
@@ -880,13 +922,13 @@ class BitPermUser extends BitUser {
* @param string $pPerm Perm name
* @param numeric $pGroupId Group ID
* @access public
- * @return TRUE on success
+ * @return bool true on success
*/
function removePermissionFromGroup( $pPerm, $pGroupId ) {
- if( @BitBase::verifyId( $pGroupId ) && !empty( $pPerm )) {
+ if( \Bitweaver\BitBase::verifyId( $pGroupId ) && !empty( $pPerm )) {
$query = "DELETE FROM `".BIT_DB_PREFIX."users_group_permissions` WHERE `perm_name` = ? AND `group_id` = ?";
$result = $this->mDb->query($query, array($pPerm, $pGroupId));
- return TRUE;
+ return true;
}
}
@@ -894,11 +936,11 @@ class BitPermUser extends BitUser {
* storeRegistrationChoice
*
* @param mixed $pGroupMixed A single group ID or an array of group IDs
- * @param array $pValue Value you wish to store - use NULL to delete a value
+ * @param array $pValue Value you wish to store - use null to delete a value
* @access public
- * @return ADO record set on success, FALSE on failure
+ * @return ADO record set on success, false on failure
*/
- function storeRegistrationChoice( $pGroupMixed, $pValue = NULL ) {
+ function storeRegistrationChoice( $pGroupMixed, $pValue = null ) {
if( !empty( $pGroupMixed )) {
$this->clearFromCache();
$bindVars[] = $pValue;
@@ -917,14 +959,14 @@ class BitPermUser extends BitUser {
/**
* Grant a single permission to a given value
*/
- function setPermissionOverride( $pPerm, $pValue = NULL ) {
+ function setPermissionOverride( $pPerm, $pValue = null ) {
if( $this->isAdmin() ) {
- $this->mPerms[$pPerm] = TRUE;
- $this->mPermsOverride[$pPerm] = TRUE;
+ $this->mPerms[$pPerm] = true;
+ $this->mPermsOverride[$pPerm] = true;
} elseif( $this->isValid() ) {
- if( $pValue == 'y' || $pValue == TRUE ) {
- $this->mPermsOverride[$pPerm] = TRUE;
- $this->mPerms[$pPerm] = TRUE;
+ if( $pValue == 'y' || $pValue == true ) {
+ $this->mPermsOverride[$pPerm] = true;
+ $this->mPerms[$pPerm] = true;
} else {
unset( $this->mPermsOverride[$pPerm] );
unset( $this->mPerms[$pPerm] );
@@ -934,4 +976,3 @@ class BitPermUser extends BitUser {
}
/* vim: :set fdm=marker : */
-?>
diff --git a/includes/classes/BitUser.php b/includes/classes/BitUser.php
index 366e3e7..4a1f7f3 100644..100755
--- a/includes/classes/BitUser.php
+++ b/includes/classes/BitUser.php
@@ -16,8 +16,9 @@
/**
* required setup
*/
-require_once( LIBERTY_PKG_CLASS_PATH.'LibertyMime.php' );
-require_once( USERS_PKG_INCLUDE_PATH.'users_lib.php' );
+namespace Bitweaver\Users;
+use Bitweaver\BitMailer;
+use Bitweaver\KernelTools;
define( 'AVATAR_TYPE_CENTRALIZED', 'c' );
define( 'AVATAR_TYPE_USER_DB', 'u' );
@@ -42,21 +43,23 @@ define( "ACCOUNT_DISABLED", -6 );
* @package users
* @subpackage BitUser
*/
-class BitUser extends LibertyMime {
+#[\AllowDynamicProperties]
+class BitUser extends \Bitweaver\Liberty\LibertyMime {
public $mUserId;
public $mUsername;
public $mGroups;
public $mTicket;
public $mAuth;
+ public $pExpungeContent = false;
/**
* Constructor - will automatically load all relevant data if passed a user string
*
* @access public
* @author Christian Fowler <spider@viovio.com>
- * @return returnString
+ * @return void
*/
- function __construct( $pUserId=NULL, $pContentId=NULL ) {
+ function __construct( $pUserId=null, $pContentId=null ) {
parent::__construct();
$this->mContentTypeGuid = BITUSER_CONTENT_TYPE_GUID;
$this->registerContentType(
@@ -70,7 +73,7 @@ class BitUser extends LibertyMime {
'maintainer_url' => 'http://www.bitweaver.org'
)
);
- $this->mUserId = ( @$this->verifyId( $pUserId ) ? $pUserId : NULL);
+ $this->mUserId = ( @$this->verifyId( $pUserId ) ? $pUserId : null);
$this->mContentId = $pContentId;
}
@@ -94,7 +97,7 @@ class BitUser extends LibertyMime {
/**
* Determines if a user object is cacheable. Out of paranoia, admin's are never cached.
- * @return boolean if object can be cached
+ * @return bool if object can be cached
*/
public function isCacheableObject() {
global $gBitSystem;
@@ -105,7 +108,7 @@ class BitUser extends LibertyMime {
* Validate inbound sort_mode parameter
* @return array of fields which are valid sorts
*/
- public static function getSortModeFields() {
+ public static function getSortModeFields(): array {
$fields = parent::getSortModeFields();
$fields[] = 'map_position';
return $fields;
@@ -114,29 +117,28 @@ class BitUser extends LibertyMime {
/**
* load - loads all settings & preferences for this user
*
- * @param boolean $pFull Load additional user data like
- * @param string $pUserName User login name
- * @access public
+ * - bool $pFull Load additional user data like
+ * - string $pUserName User login name
* @author Chrstian Fowler <spider@steelsun.com>
- * @return returnString
+ * @return bool true if valid object
*/
- function load( $pFull=TRUE, $pUserName=NULL ) {
+ public function load( ...$extraParams ): bool {
global $gBitSystem;
- $this->mInfo = NULL;
+ $this->mInfo = null;
if( isset( $this->mUserId ) ) {
$whereSql = "WHERE uu.`user_id`=?";
$bindVars = array( $this->mUserId );
} elseif( isset( $this->mContentId ) ) {
$whereSql = "WHERE uu.`content_id`=?";
$bindVars = array( $this->mContentId );
- } elseif( !empty( $pUserName ) ) {
+ } elseif( !empty( $extraParams[1] ) ) {
$whereSql = "WHERE uu.`login`=?";
- $bindVars = array( $pUserName );
+ $bindVars = array( $extraParams[1] );
}
if( isset( $whereSql ) ) {
$fullSelect = '';
$fullJoin = '';
- if( $pFull ) {
+ if( !empty($extraParams[0]) && $extraParams[0] ) {
$fullSelect = ' , lc.* ';
$fullJoin = " LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( uu.`content_id`=lc.`content_id` )";
$this->getServicesSql( 'content_load_sql_function', $fullSelect, $fullJoin, $whereSql, $bindVars );
@@ -164,8 +166,8 @@ class BitUser extends LibertyMime {
$this->mInfo['user_id'] = $this->mInfo['uu_user_id'];
$this->mInfo['is_registered'] = $this->isRegistered();
foreach( array( 'portrait', 'avatar', 'logo' ) as $img ) {
- $this->mInfo[$img.'_path'] = $this->getSourceFile( array( 'user_id'=>$this->getField( 'user_id' ), 'package'=>liberty_mime_get_storage_sub_dir_name( array( 'mime_type' => $this->getField( $img.'_mime_type' ), 'name' => $this->getField( $img.'_file_name' ) ) ), 'file_name' => basename( $this->mInfo[$img.'_file_name'] ?? '' ), 'sub_dir' => $this->getField( $img.'_attachment_id' ), 'mime_type' => $this->getField( $img.'_mime_type' ) ) );
- $this->mInfo[$img.'_url'] = liberty_fetch_thumbnail_url( array( 'source_file'=>$this->mInfo[$img.'_path'], 'size' => 'small', 'mime_image' => FALSE ));
+ $this->mInfo[$img.'_path'] = $this->getSourceFile( array( 'user_id'=>$this->getField( 'user_id' ), 'package'=>\Bitweaver\Liberty\liberty_mime_get_storage_sub_dir_name( array( 'mime_type' => $this->getField( $img.'_mime_type' ), 'name' => $this->getField( $img.'_file_name' ) ) ), 'file_name' => basename( $this->mInfo[$img.'_file_name'] ?? '' ), 'sub_dir' => $this->getField( $img.'_attachment_id' ), 'mime_type' => $this->getField( $img.'_mime_type' ) ) );
+ $this->mInfo[$img.'_url'] = \Bitweaver\Liberty\liberty_fetch_thumbnail_url( [ 'source_file'=>$this->mInfo[$img.'_path'], 'size' => 'small', 'mime_image' => false ]);
}
// break the real name into first and last name using the last space as the beginning of the last name
@@ -187,12 +189,12 @@ class BitUser extends LibertyMime {
$this->loadPreferences();
// Load attachments
- LibertyMime::load();
+ \Bitweaver\Liberty\LibertyMime::load();
if( $this->getPreference( 'users_country' ) ) {
$this->setPreference( 'flag', $this->getPreference( 'users_country' ) );
$this->setPreference( 'users_country', str_replace( '_', ' ', $this->getPreference( 'users_country' ) ) );
}
- if( $pFull ) {
+ if( !empty($extraParams[0]) && $extraParams[0] ) {
$this->mInfo['real_name'] = trim( $this->mInfo['real_name'] );
$this->mInfo['display_name'] = (
( !empty( $this->mInfo['real_name'] ) ? $this->mInfo['real_name'] :
@@ -202,11 +204,11 @@ class BitUser extends LibertyMime {
);
//print("displayName: ".$this->mInfo['display_name']);
$this->defaults();
- $this->mInfo['publicEmail'] = scramble_email( $this->mInfo['email'], ( $this->getPreference( 'users_email_display' ) ? $this->getPreference( 'users_email_display' ) : NULL ) );
+ $this->mInfo['publicEmail'] = scramble_email( $this->mInfo['email'], ( $this->getPreference( 'users_email_display' ) ? $this->getPreference( 'users_email_display' ) : null ) );
}
$this->mTicket = substr( md5( session_id() . $this->mUserId ), 0, 20 );
} else {
- $this->mUserId = NULL;
+ $this->mUserId = null;
}
}
if( !$gBitSystem->isFeatureActive( 'i18n_browser_languages' ) ) {
@@ -220,7 +222,7 @@ class BitUser extends LibertyMime {
$gBitLanguage->mLanguage = $_SESSION['bitlanguage'];
}
}
- return( $this->isValid() );
+ return $this->isValid();
}
/**
@@ -259,13 +261,12 @@ class BitUser extends LibertyMime {
* verify store hash
*
* @param array $pParamHash Data to be verified
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function verify( &$pParamHash ) {
+ public function verify( array &$pParamHash ): bool {
global $gBitSystem;
- trim_array( $pParamHash );
+ KernelTools::trim_array( $pParamHash );
// DO NOT REMOVE - to allow specific setting of the user_id during the first store.
// used by ROOT_USER_ID or ANONYMOUS_USER_ID during install.
@@ -281,7 +282,7 @@ class BitUser extends LibertyMime {
if( $this->userExists( array( 'login' => $pParamHash['login'] ) ) ) {
$this->mErrors['login'] = 'The username "'.$pParamHash['login'].'" is already in use';
} elseif( preg_match( '/[^A-Za-z0-9_.-]/', $pParamHash["login"] ) ) {
- $this->mErrors['login'] = tra( "Your username can only contain numbers, characters, underscores and hyphens." );
+ $this->mErrors['login'] = KernelTools::tra( "Your username can only contain numbers, characters, underscores and hyphens." );
} else {
// LOWER CASE all logins
$pParamHash['login'] = strtolower( $pParamHash['login'] );
@@ -315,7 +316,7 @@ class BitUser extends LibertyMime {
// choose a login based on the username in the email
if( empty($pParamHash['email']) ){
// obviously if they didnt enter an email address we cant help them out
- $this->mErrors['email'] = tra( 'You must enter your email address' );
+ $this->mErrors['email'] = KernelTools::tra( 'You must enter your email address' );
}else{
$loginBase = preg_replace( '/[^A-Za-z0-9_]/', '', substr( $pParamHash['email'], 0, strpos( $pParamHash['email'], '@' ) ) );
$login = $loginBase;
@@ -335,14 +336,14 @@ class BitUser extends LibertyMime {
if( !empty( $pParamHash['email'] ) && empty($this->mErrors['email']) ) {
$pParamHash['user_store']['email'] = substr( $pParamHash['email'], 0, 200 ) ;
}elseif( empty($pParamHash['email']) ){
- $this->mErrors['email'] = tra( 'You must enter your email address' );
+ $this->mErrors['email'] = KernelTools::tra( 'You must enter your email address' );
}
if( $gBitSystem->isFeatureActive( 'users_validate_user' ) ) {
- $pParamHash['user_store']['provpass'] = md5(BitSystem::genPass());
+ $pParamHash['user_store']['provpass'] = md5(\Bitweaver\BitSystem::genPass());
$pParamHash['pass_due'] = 0;
} elseif( empty( $pParamHash['password'] ) ) {
- $this->mErrors['password'] = tra( 'Your password should be at least '.$gBitSystem->getConfig( 'users_min_pass_length', 4 ).' characters long' );
+ $this->mErrors['password'] = KernelTools::tra( 'Your password should be at least '.$gBitSystem->getConfig( 'users_min_pass_length', 4 ).' characters long' );
}
} elseif( $this->isValid() ) {
// Prevent losing user info on save
@@ -353,7 +354,7 @@ class BitUser extends LibertyMime {
if( isset( $pParamHash['password'] ) ) {
if( isset( $pParamHash["password2"] ) && $pParamHash["password"] != $pParamHash["password2"] ) {
- $passwordErrors['password2'] = tra("The passwords didn't match");
+ $passwordErrors['password2'] = KernelTools::tra("The passwords didn't match");
}
if( ( !$this->isValid() || isset( $pParamHash['password'] ) ) && $error = $this->verifyPasswordFormat( $pParamHash['password'] ) ) {
$passwordErrors['password'] = $error;
@@ -380,8 +381,6 @@ class BitUser extends LibertyMime {
}
}
- $pParamHash['user_store']['registration_ip'] = $_SERVER['REMOTE_ADDR'];
-
// if we have an error we get them all by checking parent classes for additional errors
if( count( $this->mErrors ) > 0 ){
parent::verify( $pParamHash );
@@ -424,17 +423,15 @@ class BitUser extends LibertyMime {
}
}
- if( $gBitSystem->isFeatureActive( 'users_register_cfturnstile' ) && (empty( $pParamHash['novalidation'] ) || $pParamHash['novalidation'] != 'yes') ) {
- require_once( USERS_PKG_CLASS_PATH.'CloudflareTurnstile.php' );
- $cfTurnstile = new CloudflareTurnstileValidator( $gBitSystem->getConfig( 'users_register_cfturnstile_secret_key' ) );
- if( !empty( $pParamHash['cf-turnstile-response'] ) ) {
- $result = $cfTurnstile->validate( $pParamHash['cf-turnstile-response'], $_SERVER['REMOTE_ADDR'] );
- if ($result['success']) {
- } else {
- $this->mErrors['cfturnstile'] = "Cloudflare Verification failed: " . implode(', ', $result['error_codes']);
+ if( $gBitSystem->isFeatureActive( 'users_register_smcaptcha' ) && (empty( $pParamHash['novalidation'] ) || $pParamHash['novalidation'] != 'yes') ) {
+ require_once( USERS_PKG_INCLUDE_PATH.'solvemedialib.php' );
+ if( !empty( $pParamHash['adcopy_challenge'] ) && !empty( $pParamHash['adcopy_response'] ) ) {
+ $solvemediaResponse = solvemedia_check_answer($gBitSystem->getConfig( 'users_register_smcaptcha_v_key' ), $_SERVER["REMOTE_ADDR"], $pParamHash["adcopy_challenge"], $pParamHash["adcopy_response"], $gBitSystem->getConfig( 'users_register_smcaptcha_h_key' ) );
+ if( !$solvemediaResponse->is_valid ) {
+ $this->mErrors['smcaptcha'] = $solvemediaResponse->error;
}
} else {
- $this->mErrors['smcaptcha'] = 'No Cloudflare Response';
+ $this->mErrors['smcaptcha'] = 'Wrong Answer';
}
}
@@ -459,7 +456,7 @@ class BitUser extends LibertyMime {
$this->mErrors['passcode'] = 'Wrong passcode! You need to know the passcode to register at this site';
}
}
- return ( count($this->mErrors) == 0 );
+ return count($this->mErrors) == 0;
}
/**
@@ -468,23 +465,23 @@ class BitUser extends LibertyMime {
* @param array $pPassword
* @param array $pPassword2
* @access public
- * @return FALSE on success, Error string on failure
+ * @return false on success, Error string on failure
*/
- function verifyPasswordFormat( $pPassword, $pPassword2=NULL ) {
+ function verifyPasswordFormat( $pPassword, $pPassword2=null ) {
global $gBitSystem;
$minPassword = $gBitSystem->getConfig( 'users_min_pass_length', 4 );
if( strlen( $pPassword ) < $minPassword ) {
- return ( tra( 'Your password should be at least '.$minPassword.' characters long' ));
+ return ( KernelTools::tra( 'Your password should be at least '.$minPassword.' characters long' ));
}
if( !empty( $pPassword2 ) && $pPassword != $pPassword2 ) {
- return( tra( 'The passwords do not match' ));
+ return( KernelTools::tra( 'The passwords do not match' ));
}
if( $gBitSystem->isFeatureActive( 'users_pass_chr_num' ) && ( !preg_match_all( "/[0-9]+/",$pPassword,$foo ) || !preg_match_all( "/[A-Za-z]+/",$pPassword,$foo ))) {
- return ( tra( 'Password must contain both letters and numbers' ));
+ return ( KernelTools::tra( 'Password must contain both letters and numbers' ));
}
- return FALSE;
+ return false;
}
/**
@@ -492,7 +489,7 @@ class BitUser extends LibertyMime {
*
* @param array $pConnect
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function getSmtpResponse( &$pConnect ) {
$out = "";
@@ -510,7 +507,7 @@ class BitUser extends LibertyMime {
* verifyEmail
*
* @param array $pEmail
- * @return TRUE on success, FALSE on failure, or -1 if verifyMX had a connection failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure, or -1 if verifyMX had a connection failure - mErrors will contain reason for failure
*/
public function verifyEmail( $pEmail , &$pErrors ) {
global $gBitSystem;
@@ -524,7 +521,7 @@ class BitUser extends LibertyMime {
} elseif( !validate_email_syntax( $pEmail ) ) {
$pErrors['email'] = 'The email address '.$pEmail.' is invalid.';
} elseif( $gBitSystem->isFeatureActive( 'users_validate_email' ) ) {
- $mxErrors;
+ $mxErrors = [];
$ret = $this->verifyMX( $pEmail, $mxErrors ) ;
if ($ret === false) {
bit_error_log('INVALID EMAIL : '.$pEmail.' by '. $_SERVER['REMOTE_ADDR'] .' for '. $mxErrors['email']);
@@ -543,7 +540,7 @@ class BitUser extends LibertyMime {
* verifyAnonEmail
*
* @param array $pEmail
- * @return TRUE on success, FALSE on failure, or -1 if verifyMX had a connection failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure, or -1 if verifyMX had a connection failure - mErrors will contain reason for failure
*/
public static function verifyAnonEmail( $pEmail , &$pErrors ) {
global $gBitSystem;
@@ -568,7 +565,7 @@ class BitUser extends LibertyMime {
* @param array $pEmail
* @param array $pValidate
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function verifyMX( $pEmail, &$pErrors ) {
@@ -580,13 +577,13 @@ class BitUser extends LibertyMime {
if( validate_email_syntax( $pEmail ) ){
list ( $Username, $domain ) = preg_split ("/@/",$pEmail);
//checkdnsrr will check to see if there are any MX records for the domain
- if( !is_windows() and checkdnsrr ( $domain, "MX" ) ) {
- bitdebug( "Confirmation : MX record for {$domain} exists." );
+ if( !\KernelTools::is_windows() and checkdnsrr ( $domain, "MX" ) ) {
+ \Bitweaver\bitdebug( "Confirmation : MX record for {$domain} exists." );
- $MXWeights = array();
+ $MXWeights = [];
getmxrr ( $domain, $MXHost, $MXWeights );
- $hosts = array();
+ $hosts = [];
//create an array that combines the MXWeights with their associated hosts
for( $i = 0; $i < count( $MXHost ); $i++ ) {
@@ -685,13 +682,13 @@ class BitUser extends LibertyMime {
*
* @access public
* @author Christian Fowler<spider@viovio.com>
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
- function register( &$pParamHash, $pNotifyRegistrant=TRUE ) {
+ function register( &$pParamHash, $pNotifyRegistrant=true ) {
global $notificationlib, $gBitSmarty, $gBitSystem;
- $ret = FALSE;
+ $ret = false;
if( !empty( $_FILES['user_portrait_file'] ) && empty( $_FILES['user_avatar_file'] ) ) {
- $pParamHash['user_auto_avatar'] = TRUE;
+ $pParamHash['user_auto_avatar'] = true;
}
if( $this->verify( $pParamHash )) {
for( $i = 0; $i < BaseAuth::getAuthMethodCount(); $i++ ) {
@@ -702,7 +699,7 @@ class BitUser extends LibertyMime {
break;
} else {
$this->mErrors = array_merge( $this->mErrors, $instance->mErrors );
- return FALSE;
+ return false;
}
}
}
@@ -712,9 +709,9 @@ class BitUser extends LibertyMime {
}
$this->mLogs['register'] = 'New user registered.';
- $ret = TRUE;
+ $ret = true;
- $this->load( FALSE, $pParamHash['login'] );
+ $this->load( false, $pParamHash['login'] );
require_once( KERNEL_PKG_INCLUDE_PATH.'notification_lib.php' );
$notificationlib->post_new_user_event( $pParamHash['login'] );
@@ -749,12 +746,12 @@ class BitUser extends LibertyMime {
$machine = httpPrefix().$foo1;
// Send the mail
- $gBitSmarty->assign( 'msg',tra( 'You will receive an email with information to login for the first time into this site' ));
+ $gBitSmarty->assign( 'msg',KernelTools::tra( 'You will receive an email with information to login for the first time into this site' ));
$gBitSmarty->assign( 'mail_machine',$machine );
$gBitSmarty->assign( 'mailUserId',$this->mUserId );
$gBitSmarty->assign( 'mailProvPass',$apass );
$mail_data = $gBitSmarty->fetch( 'bitpackage:users/user_validation_mail.tpl' );
- mail( $pParamHash["email"], $siteName.' - '.tra( 'Your registration information' ), $mail_data, "From: ".$gBitSystem->getConfig('site_sender_email')."\nContent-type: text/plain;charset=utf-8\n" );
+ mail( $pParamHash["email"], $siteName.' - '.KernelTools::tra( 'Your registration information' ), $mail_data, "From: ".$gBitSystem->getConfig('site_sender_email')."\nContent-type: text/plain;charset=utf-8\n" );
$gBitSmarty->assign( 'showmsg', 'y' );
$this->mLogs['confirm'] = 'Validation email sent.';
@@ -763,7 +760,7 @@ class BitUser extends LibertyMime {
$gBitSmarty->assign( 'mailPassword',$pParamHash['password'] );
$gBitSmarty->assign( 'mailEmail',$pParamHash['email'] );
$mail_data = $gBitSmarty->fetch( 'bitpackage:users/welcome_mail.tpl' );
- mail( $pParamHash["email"], tra( 'Welcome to' ).' '.$siteName, $mail_data, "From: ".$gBitSystem->getConfig( 'site_sender_email' )."\nContent-type: text/plain;charset=utf-8\n" );
+ mail( $pParamHash["email"], KernelTools::tra( 'Welcome to' ).' '.$siteName, $mail_data, "From: ".$gBitSystem->getConfig( 'site_sender_email' )."\nContent-type: text/plain;charset=utf-8\n" );
$this->mLogs['welcome'] = 'Welcome email sent.';
}
@@ -779,17 +776,17 @@ class BitUser extends LibertyMime {
*
* @param array $pCaptcha
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
- function verifyCaptcha( $pCaptcha = NULL ) {
- if( $this->hasPermission( 'p_users_bypass_captcha' ) || ( !empty( $_SESSION['captcha_verified'] ) && $_SESSION['captcha_verified'] === TRUE ) ) {
- return TRUE;
+ function verifyCaptcha( $pCaptcha = null ) {
+ if( $this->hasPermission( 'p_users_bypass_captcha' ) || ( !empty( $_SESSION['captcha_verified'] ) && $_SESSION['captcha_verified'] === true ) ) {
+ return true;
} else {
if( empty( $pCaptcha ) || empty( $_SESSION['captcha'] ) || $_SESSION['captcha'] != md5( $pCaptcha ) ) {
- return FALSE;
+ return false;
} else {
- $_SESSION['captcha_verified'] = TRUE;
- return TRUE;
+ $_SESSION['captcha_verified'] = true;
+ return true;
}
}
}
@@ -799,10 +796,9 @@ class BitUser extends LibertyMime {
* store
*
* @param array $pParamHash
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function store( &$pParamHash ) {
+ public function store( array &$pParamHash): bool {
if( $this->verify( $pParamHash ) ) {
$this->StartTrans();
$pParamHash['content_type_guid'] = BITUSER_CONTENT_TYPE_GUID;
@@ -823,8 +819,8 @@ class BitUser extends LibertyMime {
// Prevent liberty from assuming ANONYMOUS_USER_ID while storing
$pParamHash['user_id'] = $this->mUserId;
// Don't let LA snarf these now so we can do extra things.
- $pParamHash['_files_override'] = array();
- if( LibertyMime::store( $pParamHash ) ) {
+ $pParamHash['_files_override'] = [];
+ if( \Bitweaver\LibertyMime::store( $pParamHash ) ) {
if( empty( $this->mInfo['content_id'] ) || ($pParamHash['content_id'] != $this->mInfo['content_id']) ) {
$query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `content_id`=? WHERE `user_id`=?";
@@ -835,7 +831,7 @@ class BitUser extends LibertyMime {
$this->CompleteTrans();
- $this->load( TRUE );
+ $this->load( true );
}
return( count( $this->mErrors ) == 0 );
}
@@ -845,13 +841,13 @@ class BitUser extends LibertyMime {
* This is a admin specific function
*
* @param $pParamHash an array with user data
- * @return TRUE if import succeed
+ * @return bool true if import succeed
**/
function importUser( &$pParamHash ) {
global $gBitUser;
if( ! $gBitUser->hasPermission( 'p_users_admin' ) ) {
- return FALSE;
+ return false;
}
if( $this->verifyUserImport( $pParamHash ) ) {
$this->StartTrans();
@@ -893,7 +889,7 @@ class BitUser extends LibertyMime {
// store any uploaded images
$this->storeImages( $pParamHash );
- $this->load( TRUE );
+ $this->load( true );
}
return( count( $this->mErrors ) == 0 );
}
@@ -904,19 +900,17 @@ class BitUser extends LibertyMime {
* This is a admin specific function
*
* @param $pParamHash an array with user data
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
**/
function verifyUserImport( &$pParamHash ) {
global $gBitSystem, $gBitUser;
if( ! $gBitUser->hasPermission( 'p_users_admin' ) ) {
- return FALSE;
+ return false;
}
trim_array( $pParamHash );
- $pParamHash['user_store']['registration_ip'] = $_SERVER['REMOTE_ADDR'];
-
// perhaps someone is importing users and *knows* what they are doing
if( $this->verifyIdParameter( $pParamHash, 'user_id' ) ) {
// only import user_id if it doesn't exist or overwrite is set.
@@ -938,7 +932,7 @@ class BitUser extends LibertyMime {
$this->mErrors['login'] = 'The username "'.$pParamHash['login'].'" is already in use';
}
} elseif( preg_match( '/[^A-Za-z0-9_.-]/', $pParamHash["login"] ) ) {
- $this->mErrors['login'] = tra( "Your username can only contain numbers, characters, underscores and hyphens." );
+ $this->mErrors['login'] = KernelTools::tra( "Your username can only contain numbers, characters, underscores and hyphens." );
}
if( !isset($this->mErrors['login']) ) {
@@ -977,7 +971,7 @@ class BitUser extends LibertyMime {
$this->mErrors['email'] = 'The email address "'.$pParamHash['email'].'" has an invalid syntax.';
}
} else {
- $this->mErrors['email'] = tra( 'You must enter your email address' );
+ $this->mErrors['email'] = KernelTools::tra( 'You must enter your email address' );
}
// check some new user requirements
@@ -993,7 +987,7 @@ class BitUser extends LibertyMime {
if( !empty($pParamHash['hash'] ) ) {
unset( $pParamHash['password'] );
if( strlen( $pParamHash['hash'] ) <> 32 ) {
- $this->mErrors['password'] = tra( 'When importing a MD5 password hash it needto have a length of 32 bytes.' );
+ $this->mErrors['password'] = KernelTools::tra( 'When importing a MD5 password hash it needto have a length of 32 bytes.' );
}
} else {
if( !empty( $_REQUEST['admin_verify_user'] ) ) {
@@ -1048,9 +1042,9 @@ class BitUser extends LibertyMime {
* expunge removes user and associated private data
*
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool
*/
- function expunge( $pExpungeContent = NULL ) {
+ public function expunge(): bool {
global $gBitSystem;
$this->invokeServices( 'users_expunge_check_function' );
if( !empty( $this->mErrors['expunge_check'] ) ) {
@@ -1058,8 +1052,8 @@ class BitUser extends LibertyMime {
} else {
$this->StartTrans();
- if( !empty( $pExpungeContent ) ) {
- if( $pExpungeContent == 'all' ) {
+ if( !empty( $this->pExpungeContent ) ) {
+ if( $this->pExpungeContent == 'all' ) {
if( $userContent = $this->mDb->getAssoc( "SELECT content_id, content_type_guid FROM `".BIT_DB_PREFIX."liberty_content` WHERE `user_id`=? AND `content_type_guid` != 'bituser'", array( $this->mUserId ) ) ) {
foreach( $userContent as $contentId=>$contentTypeGuid ) {
if( $delContent = static::getLibertyObject( $contentId, $contentTypeGuid ) ) {
@@ -1095,10 +1089,10 @@ class BitUser extends LibertyMime {
$this->CompleteTrans();
$this->clearFromCache();
- return TRUE;
+ return true;
} else {
$this->mDb->RollbackTrans();
- $gBitSystem->fatalError( tra( 'The anonymous user cannot be deleted' ) );
+ $gBitSystem->fatalError( KernelTools::tra( 'The anonymous user cannot be deleted' ) );
}
}
return count( $this->mErrors ) === 0;
@@ -1110,7 +1104,7 @@ class BitUser extends LibertyMime {
*
* @param array $pSessionId
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
protected function updateSession( $pSessionId ) {
global $gLightWeightScan;
@@ -1164,12 +1158,12 @@ class BitUser extends LibertyMime {
* @access public
* @return count of sessions
*/
- function countSessions( $pActive = FALSE ) {
+ function countSessions( $pActive = false ) {
$query = "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."users_cnxn`";
if( $pActive ) {
- $query .=" WHERE `cookie` IS NOT NULL";
+ $query .=" WHERE `cookie` IS NOT null";
}
- return $this->mDb->getOne( $query,array() );
+ return $this->mDb->getOne( $query,[] );
}
/**
@@ -1182,15 +1176,15 @@ class BitUser extends LibertyMime {
// This must come first
$this->clearFromCache();
- $this->sendSessionCookie( FALSE );
+ $this->sendSessionCookie( false );
session_destroy();
- $this->mUserId = NULL;
+ $this->mUserId = null;
// ensure Guest default page is loaded if required
$this->mInfo['default_group_id'] = -1;
}
- protected function sendSessionCookie( $pCookie=TRUE ) {
+ protected function sendSessionCookie( $pCookie=true ) {
global $gBitSystem;
$siteCookie = static::getSiteCookieName();
@@ -1198,12 +1192,12 @@ class BitUser extends LibertyMime {
$cookiePath = BIT_ROOT_URL;
$cookieDomain = '';
- if( $pCookie === TRUE ) {
+ if( $pCookie === true ) {
$pCookie = session_id();
- } elseif( $pCookie==FALSE ) {
+ } elseif( $pCookie==false ) {
$pCookie = ''; // unset the cookie, eg logout
if( !empty( $_COOKIE[$siteCookie] ) ) {
- $this->mDb->query( "UPDATE `".BIT_DB_PREFIX."users_cnxn` SET `cookie`=NULL WHERE `cookie`=?", array( $_COOKIE[$siteCookie] ) );
+ $this->mDb->query( "UPDATE `".BIT_DB_PREFIX."users_cnxn` SET `cookie`=null WHERE `cookie`=?", array( $_COOKIE[$siteCookie] ) );
unset( $_COOKIE[$siteCookie] );
}
}
@@ -1234,16 +1228,16 @@ class BitUser extends LibertyMime {
* @param array $pFatalOnError
* @param array $pForceCheck
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function verifyTicket( $pFatalOnError=TRUE, $pForceCheck=TRUE ) {
+ function verifyTicket( $pFatalOnError=true, $pForceCheck=true ) {
global $gBitSystem, $gBitUser;
- $ret = FALSE;
- if( $pForceCheck == TRUE || !empty( $_REQUEST['tk'] ) ) {
+ $ret = false;
+ if( $pForceCheck == true || !empty( $_REQUEST['tk'] ) ) {
if( empty( $_REQUEST['tk'] ) || (!($ret = $_REQUEST['tk'] == $this->mTicket ) && $pFatalOnError) ) {
$userString = $gBitUser->isRegistered() ? "\nUSER ID: ".$gBitUser->mUserId.' ( '.$gBitUser->getField( 'email' ).' ) ' : '';
- error_log( tra( "Security Violation" )."$userString ".$_SERVER['REMOTE_ADDR']."\nURI: $_SERVER[REQUEST_URI] \n".(!empty( $_SERVER['HTTP_REFERER'] ) ? "REFERER: $_SERVER[HTTP_REFERER]\n" : ""));
- $gBitSystem->fatalError( tra( "Security Violation" ));
+ error_log( KernelTools::tra( "Security Violation" )."$userString ".$_SERVER['REMOTE_ADDR']."\nURI: $_SERVER[REQUEST_URI] \nREFERER: $_SERVER[HTTP_REFERER] " );
+ $gBitSystem->fatalError( KernelTools::tra( "Security Violation" ));
}
}
return $ret;
@@ -1255,15 +1249,15 @@ class BitUser extends LibertyMime {
* ban sets the user account status to -201 suspended
*
* @access public
- * @return TRUE on success, Display error message on failure
+ * @return bool true on success, Display error message on failure
*/
function ban(){
global $gBitSystem;
if( $this->mUserId == ANONYMOUS_USER_ID || $this->mUserId == ROOT_USER_ID || $this->isAdmin()) {
- $gBitSystem->fatalError( tra( 'You cannot ban the user' )." ".$this->mInfo['login'] );
+ $gBitSystem->fatalError( KernelTools::tra( 'You cannot ban the user' )." ".$this->mInfo['login'] );
} else {
$this->storeStatus( -201 );
- return TRUE;
+ return true;
}
}
@@ -1271,12 +1265,12 @@ class BitUser extends LibertyMime {
* ban unban the user
*
* @access public
- * @return TRUE on success
+ * @return bool true on success
*/
function unban(){
global $gBitSystem;
$this->storeStatus( 50 );
- return TRUE;
+ return true;
}
// }}}
@@ -1287,7 +1281,7 @@ class BitUser extends LibertyMime {
* @access public
* @return password
*/
- public static function genPass( $pLength=NULL ) {
+ public static function genPass( $pLength=null ) {
global $gBitSystem;
$vocales = "AaEeIiOoUu13580";
$consonantes = "BbCcDdFfGgHhJjKkLlMmNnPpQqRrSsTtVvWwXxYyZz24679";
@@ -1312,7 +1306,7 @@ class BitUser extends LibertyMime {
* @return md5 string
*/
function generateChallenge() {
- return( md5( BitSystem::genPass() ));
+ return( md5( \Bitweaver\BitSystem::genPass() ));
}
/**
@@ -1325,7 +1319,7 @@ class BitUser extends LibertyMime {
* @access public
* @return URL the user should be sent to after login
*/
- function login( $pLogin, $pPassword, $pChallenge=NULL, $pResponse=NULL ) {
+ function login( $pLogin, $pPassword, $pChallenge=null, $pResponse=null ) {
global $gBitSystem;
$isvalid = false;
@@ -1349,7 +1343,7 @@ class BitUser extends LibertyMime {
// User is valid and not due to change pass..
$this->mUserId = $userInfo['user_id'];
$this->load();
- $this->loadPermissions( TRUE );
+ $this->loadPermissions( true );
$url = $this->getPostLoginUrl();
@@ -1364,9 +1358,9 @@ class BitUser extends LibertyMime {
$url = USERS_PKG_URL.'remind_password.php?remind=y&required=y&username='.$pLogin;
}else{
$this->mUserId = ANONYMOUS_USER_ID;
- $this->mInfo = array();
+ $this->mInfo = [];
$this->clearFromCache();
- $this->mErrors['login'] = tra( 'Invalid username or password' );
+ $this->mErrors['login'] = KernelTools::tra( 'Invalid username or password' );
$url = USERS_PKG_URL.'signin.php?error=' . urlencode( $this->mErrors['login'] );
}
}
@@ -1402,7 +1396,7 @@ class BitUser extends LibertyMime {
// set post-login url
// if group home is set for this user we get that
// default to general post-login
- // @see BitSystem::getIndexPage
+ // @see \Bitweaver\BitSystem::getIndexPage
$indexType = 'my_page';
// getGroupHome is BitPermUser method
if( method_exists( $this, 'getGroupHome' ) &&
@@ -1432,13 +1426,13 @@ class BitUser extends LibertyMime {
* @param array $pChallenge
* @param array $pResponse
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
* @todo rewrite this mess. this is horrible stuff. - xing - Thursday Oct 16, 2008 09:47:20 CEST
*/
function validate( $pUser, $pPass, $pChallenge, $pResponse ) {
global $gBitSystem;
// these will help us keep tabs of what is going on
- $authValid = $authPresent = FALSE;
+ $authValid = $authPresent = false;
$createAuth = ( $gBitSystem->getConfig( "users_create_user_auth", "n" ) == "y" );
for( $i = 0; $i < BaseAuth::getAuthMethodCount(); $i++ ) {
@@ -1448,14 +1442,14 @@ class BitUser extends LibertyMime {
switch( $result ) {
case USER_VALID:
unset($this->mErrors['login']);
- $authPresent = TRUE;
- $authValid = TRUE;
+ $authPresent = true;
+ $authValid = true;
break;
case PASSWORD_INCORRECT:
// this mErrors assignment is CRUCIAL so that bit auth fails properly. DO NOT FUCK WITH THIS unless you know what you are doing and have checked with me first. XOXOX - spiderr
// This might have broken other auth, but at this point, bw auth was TOTALLY busted. If you need to fix, please come find me.
$this->mErrors['login'] = 'Password incorrect';
- $authPresent = TRUE;
+ $authPresent = true;
break;
case USER_NOT_FOUND:
break;
@@ -1482,7 +1476,7 @@ class BitUser extends LibertyMime {
$userInfo = $this->getUserInfo( array( 'login' => $pUser ));
$this->mUserId = $userInfo['user_id'];
$this->store( $authUserInfo );
- $this->mErrors = array();
+ $this->mErrors = [];
} else {
$authUserInfo = array(
@@ -1492,15 +1486,15 @@ class BitUser extends LibertyMime {
'email' => $instance->mInfo['email']
);
// TODO somehow, mUserId gets set to -1 at this point - no idea how
- // set to NULL to prevent overwriting Guest user - wolff_borg
- $this->mUserId = NULL;
+ // set to null to prevent overwriting Guest user - wolff_borg
+ $this->mUserId = null;
$this->store( $authUserInfo );
}
if( $createAuth && $i > 0 ) {
// if the user was logged into this system and we should progate users down other auth methods
for( $j = $i; $i >= 0; $j-- ) {
- $probMethodName = $gBitSystem->getConfig( "users_auth_method_$j", $default );
+ $probMethodName = $gBitSystem->getConfig( "users_auth_method_$j", $default ?? false );
if( !empty( $probMethodName )) {
$probInstance = BaseAuth::init( $probMethodName );
if( $probInstance && $probInstance->canManageAuth() ) {
@@ -1543,15 +1537,15 @@ class BitUser extends LibertyMime {
*
* @param array $pUserId
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function updateLastLogin( $pUserId ) {
- $ret = FALSE;
+ $ret = false;
if( @$this->verifyId( $pUserId ) ) {
global $gBitSystem;
$query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `last_login` = `current_login`, `current_login` = ? WHERE `user_id` = ?";
$result = $this->mDb->query( $query, array( $gBitSystem->getUTCTime(), $pUserId ));
- $ret = TRUE;
+ $ret = true;
}
return $ret;
}
@@ -1568,7 +1562,7 @@ class BitUser extends LibertyMime {
global $gBitSystem;
$query = "
SELECT `user_id`, `provpass`, `user_password`, `login`, `email` FROM `".BIT_DB_PREFIX."users_users`
- WHERE `user_id`=? AND `provpass`=? AND ( `provpass_expires` IS NULL OR `provpass_expires` > ?)";
+ WHERE `user_id`=? AND `provpass`=? AND ( `provpass_expires` IS null OR `provpass_expires` > ?)";
return( $this->mDb->getRow( $query, array( (int)$pUserId, $pProvpass, $gBitSystem->getUTCTime() )));
}
@@ -1578,13 +1572,13 @@ class BitUser extends LibertyMime {
* @param array $pUserId
* @param array $pEmail
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function changeUserEmail( $pUserId, $pEmail ) {
if( !validate_email_syntax( $pEmail ) ) {
- $this->mErrors['bad_mail'] = tra( "The email address provided does not have recognised valid syntax." );
+ $this->mErrors['bad_mail'] = KernelTools::tra( "The email address provided does not have recognised valid syntax." );
} elseif( $this->userExists( array( 'email' => $pEmail ))) {
- $this->mErrors['duplicate_mail'] = tra( "The email address you selected already exists." );
+ $this->mErrors['duplicate_mail'] = KernelTools::tra( "The email address you selected already exists." );
} else {
$query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `email`=? WHERE `user_id`=?";
$result = $this->mDb->query( $query, array( $pEmail, $pUserId ) );
@@ -1605,7 +1599,7 @@ class BitUser extends LibertyMime {
* @return user_id that can be used to point to users homepage
*/
function lookupHomepage( $iHomepage ) {
- $ret = NULL;
+ $ret = null;
if( @$this->verifyId( $iHomepage )) {
// iHomepage is the user_id for the user...
$key = 'user_id';
@@ -1628,18 +1622,17 @@ class BitUser extends LibertyMime {
/**
* getUserPreference
*
- * @param array $pPrefName
- * @param array $pPrefDefault
- * @param array $pUserId
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @param string $pPrefName
+ * @param string $pPrefDefault
+ * @param int $pUserId
+ * @return string|null
*/
- static function getUserPreference( $pPrefName, $pPrefDefault, $pUserId ) {
+ public static function getUserPreference( string $pPrefName, string $pPrefDefault, int $pUserId ) {
// Alternate to LibertyContent::getPreference when all you have is a user_id and a pref_name, and you need a value...
global $gBitDb;
- $ret = NULL;
+ $ret = null;
- if( BitBase::verifyId( $pUserId ) ) {
+ if( \Bitweaver\BitBase::verifyId( $pUserId ) ) {
$query = "
SELECT lcp.`pref_value` FROM `".BIT_DB_PREFIX."liberty_content_prefs` lcp INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON (lcp.`content_id`=uu.`content_id`)
WHERE uu.`user_id` = ? AND lcp.`pref_name` = ?";
@@ -1655,11 +1648,11 @@ class BitUser extends LibertyMime {
*
* @param array $pUserMixed hash key can be any column in users_users table e.g.: 'login', 'user_id', 'email', 'content_id'
* @access public
- * @return user info on success, NULL on failure
+ * @return user info on success, null on failure
*/
public static function getUserInfo( $pUserMixed ) {
global $gBitDb;
- $ret = NULL;
+ $ret = null;
if( is_array( $pUserMixed ) ) {
if( $val = current( $pUserMixed ) ) {
$key = $gBitDb->sanitizeColumnString( key( $pUserMixed ) );
@@ -1689,14 +1682,14 @@ class BitUser extends LibertyMime {
/**
* isUserPublic Determine if an arbitrary user can be viewed by non-permissioned users.
*
- * @param array $pUserId user_id of user to query visibility, if NULL will use this object
+ * @param array $pUserId user_id of user to query visibility, if null will use this object
* @access public
- * @return boolean if user is publically visible
+ * @return bool if user is publically visible
*/
- function isUserPrivate( $pUserId=NULL ) {
- $infoPref = NULL;
- if( BitBase::verifyId( $pUserId ) ) {
- $infoPref = BitUser::getUserPreference( 'users_information', NULL, $pUserId );
+ function isUserPrivate( $pUserId=null ) {
+ $infoPref = null;
+ if( \Bitweaver\BitBase::verifyId( $pUserId ) ) {
+ $infoPref = BitUser::getUserPreference( 'users_information', null, $pUserId );
} elseif( isset( $this ) && $this->isValid() ) {
$infoPref = $this->getPreference( 'users_information' );
}
@@ -1720,21 +1713,21 @@ class BitUser extends LibertyMime {
* isPasswordDue work out if a user has to change their password
*
* @access public
- * @return TRUE when the password is due, FALSE if it isn't, NULL when no due time is set
- * @note NULL password due means *no* expiration
+ * @return bool true when the password is due, false if it isn't, null when no due time is set
+ * @note null password due means *no* expiration
*/
- function isPasswordDue( $pUserId = NULL ) {
+ function isPasswordDue( $pUserId = null ) {
global $gBitSystem;
- $ret = FALSE;
+ $ret = false;
if( empty( $pUserId) && $this->isRegistered() ) {
$pUserId = $this->mUserId;
}
if( !empty( $pUserId ) ){
- // get user_id to avoid NULL and zero confusion
+ // get user_id to avoid null and zero confusion
$query = "
SELECT `user_id`, `pass_due`
FROM `".BIT_DB_PREFIX."users_users`
- WHERE `pass_due` IS NOT NULL AND `user_id`=? ";
+ WHERE `pass_due` IS NOT null AND `user_id`=? ";
$due = $this->mDb->getRow( $query, array( $pUserId ) );
if( @$this->verifyId( $due['user_id'] ) && !empty( $due['pass_due'] ) ) {
$ret = $due['pass_due'] <= $gBitSystem->getUTCTime();
@@ -1749,7 +1742,7 @@ class BitUser extends LibertyMime {
* @param array $pLogin
* @param array $pPass
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function createTempPassword( $pLogin, $pPass ) {
global $gBitSystem;
@@ -1760,7 +1753,7 @@ class BitUser extends LibertyMime {
}
if( !empty( $pLogin )) {
- $pass = BitSystem::genPass();
+ $pass = \Bitweaver\BitSystem::genPass();
$provpass = md5( $pass );
$loginCol = strpos( $pLogin, '@' ) ? 'email' : 'login';
@@ -1779,29 +1772,29 @@ class BitUser extends LibertyMime {
* @param array $pPass
* @param array $pLogin
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function storePassword( $pPass, $pLogin=NULL ) {
+ function storePassword( $pPass, $pLogin=null ) {
global $gBitSystem;
- $ret = FALSE;
+ $ret = false;
if( empty( $pLogin ) ) {
$pLogin = $this->getField( 'email' );
}
if( !empty( $pLogin )) {
- $ret = TRUE;
+ $ret = true;
$hash = md5( $pPass );
// if renew password config is set then set - otherwise set null to respect no pass due
- $passDue = NULL;
+ $passDue = null;
if( $gBitSystem->getConfig('users_pass_due') ) {
$now = $gBitSystem->getUTCTime();;
// renew password according to config value
$passDue = $now + ( 60 * 60 * 24 * $gBitSystem->getConfig( 'users_pass_due' ));
}
- $pPass = NULL;
+ $pPass = null;
$loginCol = strpos( $pLogin, '@' ) ? 'email' : 'login';
- $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `provpass`= NULL, `provpass_expires` = NULL,`hash`=? ,`user_password`=? ,`pass_due`=? WHERE `".$loginCol."`=?";
+ $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `provpass`= null, `provpass_expires` = null,`hash`=? ,`user_password`=? ,`pass_due`=? WHERE `".$loginCol."`=?";
$result = $this->mDb->query( $query, array( $hash, $pPass, $passDue, $pLogin ));
}
return $ret;
@@ -1815,7 +1808,7 @@ class BitUser extends LibertyMime {
* @return array of users and what they have been up to
*/
function getUserActivity( &$pListHash ) {
- $bindVars = array();
+ $bindVars = [];
if( empty( $pListHash['sort_mode'] ) ) {
$pListHash['sort_mode'] = 'last_get_desc';
}
@@ -1827,13 +1820,13 @@ class BitUser extends LibertyMime {
$bindVars[] = time() - $pListHash['last_get'];
}
- if( @BitBase::verifyId( $pListHash['user_id'] ) ) {
+ if( \Bitweaver\BitBase::verifyId( $pListHash['user_id'] ?? 0 ) ) {
$whereSql .= ' AND uc.`user_id` = ? ';
$bindVars[] = $pListHash['user_id'];
}
if( !empty( $pListHash['ip'] ) ) {
- $ips = explode( ',', $pListHash['ip'] );
+ $ips = mb_split( ',', $pListHash['ip'] );
$ipList = '';
do {
$ip = array_pop( $ips );
@@ -1846,7 +1839,7 @@ class BitUser extends LibertyMime {
}
if( !empty( $pListHash['online'] ) ) {
- $whereSql .= ' AND uc.`cookie` IS NOT NULL ';
+ $whereSql .= ' AND uc.`cookie` IS NOT null ';
}
$query = "
@@ -1854,10 +1847,10 @@ class BitUser extends LibertyMime {
FROM `".BIT_DB_PREFIX."users_users` uu
INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (uu.`content_id` = lc.`content_id`)
LEFT JOIN `".BIT_DB_PREFIX."users_cnxn` uc ON (uc.`user_id` = uu.`user_id`)
- WHERE uu.`user_id` IS NOT NULL $whereSql
+ WHERE uu.`user_id` IS NOT null $whereSql
ORDER BY ".$this->mDb->convertSortmode( $pListHash['sort_mode'] );
$result = $this->mDb->query( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] );
- $ret = array();
+ $ret = [];
while( $res = $result->fetchRow() ) {
$res['users_information'] = $this->getPreference( 'users_information', 'public', $res['content_id'] );
$ret[] = $res;
@@ -1868,7 +1861,7 @@ class BitUser extends LibertyMime {
FROM `".BIT_DB_PREFIX."users_users` uu
INNER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (uu.`content_id` = lc.`content_id`)
LEFT JOIN `".BIT_DB_PREFIX."users_cnxn` uc ON (uc.`user_id` = uu.`user_id`)
- WHERE uc.`user_id` IS NOT NULL $whereSql";
+ WHERE uc.`user_id` IS NOT null $whereSql";
$pListHash['cant'] = $this->mDb->GetOne( $countSql, $bindVars );
$this->postGetList( $pListHash );
return $ret;
@@ -1879,10 +1872,10 @@ class BitUser extends LibertyMime {
*
* @param array $pLogin
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function getUserDomain( $pLogin ) {
- $ret = array();
+ $ret = [];
if( $pLogin == $this->getField( 'login' ) && $this->getPreference( 'domain_style' ) ) {
$ret = $this->mInfo;
$ret['style'] = $this->getPreference( 'domain_style' );
@@ -1902,10 +1895,10 @@ class BitUser extends LibertyMime {
*
* @param array $pContentId
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function getDomain( $pContentId ) {
- $ret = array();
+ $ret = [];
if( $this->verifyId( $pContentId ) ) {
$ret['content_id'] = $pContentId;
$ret['style'] = $this->mDb->getOne( "SELECT `pref_value` FROM `".BIT_DB_PREFIX."liberty_content_prefs` WHERE `content_id`=? AND `pref_name`=?", array( $pContentId, 'domain_style' ));
@@ -1917,7 +1910,7 @@ class BitUser extends LibertyMime {
* canCustomizeTheme check if a user can customise their theme
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function canCustomizeTheme() {
global $gBitSystem;
@@ -1928,7 +1921,7 @@ class BitUser extends LibertyMime {
* canCustomizeLayout check if a user can customise their layout
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function canCustomizeLayout() {
global $gBitSystem;
@@ -1944,9 +1937,9 @@ class BitUser extends LibertyMime {
* @param string $pSize
* @param array $pInfoHash
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function getThumbnailUrl( $pSize = 'small', $pInfoHash = NULL, $pSecondaryId = NULL, $pDefault=TRUE ) {
+ function getThumbnailUrl( string $pSize = 'small', ?array $pInfoHash = null, ?int $pSecondaryId = null, ?int $pDefault = null ): string|null {
$ret = '';
if( $pInfoHash ) {
// do some stuff if we are passed a hash-o-crap, not implemented currently
@@ -1965,7 +1958,7 @@ class BitUser extends LibertyMime {
* @param array $pParamHash array of options
* @param boolean $pParamHash['user_auto_avatar'] automatically create avatar from portrait
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function storeImages( $pParamHash ) {
if( isset( $_FILES['user_portrait_file'] ) && is_uploaded_file( $_FILES['user_portrait_file']['tmp_name'] ) && $_FILES['user_portrait_file']['size'] > 0 ) {
@@ -2002,9 +1995,9 @@ class BitUser extends LibertyMime {
* @param array $pStorageHash
* @param array $pGenerateAvatar
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function storePortrait( &$pStorageHash, $pGenerateAvatar = FALSE ) {
+ function storePortrait( &$pStorageHash, $pGenerateAvatar = false ) {
if( $this->isValid() && count( $pStorageHash )) {
// make a copy before the uploaded file disappears
if( $pGenerateAvatar ) {
@@ -2028,7 +2021,7 @@ class BitUser extends LibertyMime {
*
* @param array $pStorageHash
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function storeAvatar( &$pStorageHash ) {
return( $this->storeUserImage( $pStorageHash, 'avatar' ));
@@ -2039,7 +2032,7 @@ class BitUser extends LibertyMime {
*
* @param array $pStorageHash
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function storeLogo( &$pStorageHash ) {
return( $this->storeUserImage( $pStorageHash, 'logo' ));
@@ -2051,21 +2044,21 @@ class BitUser extends LibertyMime {
* @param array $pStorageHash
* @param string $pType
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function storeUserImage( &$pStorageHash, $pType = 'portrait' ) {
if( $this->isValid() && count( $pStorageHash ) ) {
// don't do the content thing
- $pStorageHash['skip_content_store'] = TRUE;
+ $pStorageHash['skip_content_store'] = true;
// setup the hash for central storage functions
- $pStorageHash['no_perm_check'] = TRUE;
+ $pStorageHash['no_perm_check'] = true;
$pStorageHash['_files_override'][$pType] = $pStorageHash['upload'];
$pStorageHash['_files_override'][$pType]['max_width'] = constant( strtoupper( $pType )."_MAX_DIM" );
$pStorageHash['_files_override'][$pType]['max_height'] = constant( strtoupper( $pType )."_MAX_DIM" );
- $pStorageHash['_files_override'][$pType]['attachment_id'] = !empty( $this->mInfo["{$pType}_attachment_id"] ) ? $this->mInfo["{$pType}_attachment_id"] : NULL;
+ $pStorageHash['_files_override'][$pType]['attachment_id'] = !empty( $this->mInfo["{$pType}_attachment_id"] ) ? $this->mInfo["{$pType}_attachment_id"] : null;
$pStorageHash['_files_override'][$pType]['user_id'] = $this->mUserId;
- if( LibertyMime::store( $pStorageHash )) {
+ if( \Bitweaver\LibertyMime::store( $pStorageHash )) {
$file = $pStorageHash['upload_store']['files'][$pType];
if( empty( $this->mInfo["{$pType}_attachment_id"] ) || $this->mInfo["{$pType}_attachment_id"] != $file['attachment_id'] ) {
$query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `{$pType}_attachment_id` = ? WHERE `user_id`=?";
@@ -2083,14 +2076,14 @@ class BitUser extends LibertyMime {
/**
* purgeImage
*
- * @param array $pType
+ * @param string $pType
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function purgeImage( $pType ) {
if( $this->isValid() && @$this->verifyId( $this->mInfo[$pType.'_attachment_id'] ) ) {
$this->StartTrans();
- $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `".$pType."_attachment_id` = NULL WHERE `user_id`=?";
+ $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `".$pType."_attachment_id` = null WHERE `user_id`=?";
$result = $this->mDb->query( $query, array( $this->mUserId ) );
if( $this->expungeAttachment( $this->getField( $pType.'_attachment_id' ) ) ) {
unset( $this->mInfo[$pType.'_file_name'] );
@@ -2098,7 +2091,7 @@ class BitUser extends LibertyMime {
unset( $this->mInfo[$pType.'_url'] );
}
$this->CompleteTrans();
- return TRUE;
+ return true;
}
}
@@ -2106,7 +2099,7 @@ class BitUser extends LibertyMime {
* purgePortrait
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function purgePortrait() {
return $this->purgeImage( 'portrait' );
@@ -2117,7 +2110,7 @@ class BitUser extends LibertyMime {
* purgeAvatar
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function purgeAvatar() {
return $this->purgeImage( 'avatar' );
@@ -2128,7 +2121,7 @@ class BitUser extends LibertyMime {
* purgeLogo
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function purgeLogo() {
return $this->purgeImage( 'logo' );
@@ -2146,7 +2139,7 @@ class BitUser extends LibertyMime {
* @param array $pTitle
* @param array $pUrl
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function storeWatch( $pEvent, $pObject, $pType, $pTitle, $pUrl ) {
global $userlib;
@@ -2156,7 +2149,7 @@ class BitUser extends LibertyMime {
$this->mDb->query($query,array( $this->mUserId, $pEvent, $pObject ) );
$query = "INSERT INTO `".BIT_DB_PREFIX."users_watches`(`user_id` ,`event` ,`object` , `email`, `hash`, `watch_type`, `title`, `url`) VALUES(?,?,?,?,?,?,?,?)";
$this->mDb->query( $query, array( $this->mUserId, $pEvent, $pObject, $this->mInfo['email'], $hash, $pType, $pTitle, $pUrl ) );
- return TRUE;
+ return true;
}
}
@@ -2165,10 +2158,10 @@ class BitUser extends LibertyMime {
*
* @param string $pEvent
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function getWatches( $pEvent = '' ) {
- $ret = NULL;
+ $ret = null;
if( $this->isValid() ) {
$mid = '';
$bindvars=array( $this->mUserId );
@@ -2179,7 +2172,7 @@ class BitUser extends LibertyMime {
$query = "select * from `".BIT_DB_PREFIX."users_watches` where `user_id`=? $mid";
$result = $this->mDb->query($query,$bindvars);
- $ret = array();
+ $ret = [];
while ($res = $result->fetchRow()) {
$ret[] = $res;
@@ -2194,10 +2187,10 @@ class BitUser extends LibertyMime {
* @param array $pEvent
* @param array $object
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function getEventWatches( $pEvent, $pObject ) {
- $ret = NULL;
+ $ret = null;
if( $this->isValid() ) {
$query = "SELECT * FROM `".BIT_DB_PREFIX."users_watches` WHERE `user_id`=? AND `event`=? AND `object`=?";
$result = $this->mDb->query($query,array( $this->mUserId, $pEvent, $pObject ) );
@@ -2214,10 +2207,10 @@ class BitUser extends LibertyMime {
* @param array $pEvent
* @param array $pObject
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function get_event_watches( $pEvent, $pObject ) {
- $ret = array();
+ $ret = [];
$query = "select * from `".BIT_DB_PREFIX."users_watches` tw INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON ( tw.`user_id`=uu.`user_id` ) where `event`=? and `object`=?";
$result = $this->mDb->query( $query,array( $pEvent,$pObject ));
@@ -2238,7 +2231,7 @@ class BitUser extends LibertyMime {
*
* @param array $pParamHash
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function remove_user_watch_by_hash( $pParamHash ) {
$query = "DELETE FROM `".BIT_DB_PREFIX."users_watches` WHERE `hash`=?";
@@ -2251,7 +2244,7 @@ class BitUser extends LibertyMime {
* @param array $pEvent
* @param array $pObject
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function expungeWatch( $pEvent, $pObject ) {
if( $this->isValid() ) {
@@ -2264,12 +2257,12 @@ class BitUser extends LibertyMime {
* get_watches_events
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function get_watches_events() {
$query = "select distinct `event` from `".BIT_DB_PREFIX."users_watches`";
- $result = $this->mDb->query($query,array());
- $ret = array();
+ $result = $this->mDb->query($query,[]);
+ $ret = [];
while ($res = $result->fetchRow()) {
$ret[] = $res['event'];
}
@@ -2296,33 +2289,33 @@ class BitUser extends LibertyMime {
*
* @param array $pContentId
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function storeFavorite( $pContentId ) {
- $ret = FALSE;
+ $ret = false;
if( $this->isValid() && $this->verifyId( $pContentId )) {
if( !$this->hasFavorite( $pContentId ) ){
$this->mDb->query( "INSERT INTO `".BIT_DB_PREFIX."users_favorites_map` ( `user_id`, `favorite_content_id` ) VALUES (?,?)", array( $this->mUserId, $pContentId ) );
}
- $ret = TRUE;
+ $ret = true;
}
return( $ret );
}
function expungeFavorite( $pContentId ) {
- $ret = FALSE;
+ $ret = false;
if( $this->isValid() && $this->verifyId( $pContentId ) ) {
$this->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."users_favorites_map` WHERE `user_id`=? AND `favorite_content_id`=?", array( $this->mUserId, $pContentId ) );
- $ret = TRUE;
+ $ret = true;
}
return( $ret );
}
function hasFavorite( $pContentId ) {
- $ret = FALSE;
+ $ret = false;
$rslt = $this->mDb->getOne( "SELECT `favorite_content_id` FROM `".BIT_DB_PREFIX."users_favorites_map` WHERE `user_id`=? AND `favorite_content_id`=?", array( $this->mUserId, $pContentId ) );
if( !is_null( $rslt ) ){
- $ret = TRUE;
+ $ret = true;
}
return $ret;
}
@@ -2334,10 +2327,10 @@ class BitUser extends LibertyMime {
* @return Array of content data
*/
function getFavorites(){
- $ret = NULL;
+ $ret = null;
if( $this->isRegistered() ){
$listHash['join_sql'] = " INNER JOIN `".BIT_DB_PREFIX."users_favorites_map` ufm ON (ufm.favorite_content_id=lc.content_id AND ufm.user_id=".$this->mUserId.") ";
- $listHash['user_favs'] = TRUE;
+ $listHash['user_favs'] = true;
$listHash['order_table'] = 'ufm.';
$listHash['sort_mode'] = 'map_position_desc';
$ret = $this->getContentList( $listHash );
@@ -2353,7 +2346,7 @@ class BitUser extends LibertyMime {
* @return user id of currently loaded user
*/
function getUserId() {
- return( $this->isValid() ? $this->mUserId : ANONYMOUS_USER_ID );
+ return $this->isValid() ? $this->mUserId : ANONYMOUS_USER_ID;
}
/**
@@ -2392,8 +2385,8 @@ class BitUser extends LibertyMime {
* @access public
* @return get a link to the the users homepage
*/
- public static function getDisplayLinkFromHash( &$pParamHash, $pLinkText=NULL, $pAnchor=NULL ) {
- return BitUser::getDisplayNameFromHash( $pParamHash, TRUE );
+ public static function getDisplayLinkFromHash( &$pParamHash, $pLinkText=null, $pAnchor=null ) {
+ return BitUser::getDisplayNameFromHash( $pParamHash, true );
}
/**
@@ -2401,20 +2394,20 @@ class BitUser extends LibertyMime {
*
* @param array $pParamHash
* @access public
- * @return get the users display name
+ * @return string get the users display name
*/
- public static function getTitleFromHash( &$pParamHash, $pDefault=TRUE ) {
+ public static function getTitleFromHash( &$pParamHash, $pDefault=true ) {
return BitUser::getDisplayNameFromHash( $pParamHash );
}
/**
* Get user information for a particular user
*
- * @param pUseLink return the information in the form of a url that links to the users information page
- * @param pParamHash todo - need explanation on how to use this...
- * @return display name or link to user information page
+ * @param array pParamHash todo - need explanation on how to use this...
+ * @param bool pUseLink return the information in the form of a url that links to the users information page
+ * @return string display name or link to user information page
**/
- public static function getDisplayNameFromHash( $pParamHash, $pUseLink=FALSE ) {
+ public static function getDisplayNameFromHash( $pParamHash, $pUseLink=false ) {
global $gBitSystem, $gBitUser;
if( !empty( $pParamHash )) {
if( !empty( $pParamHash['real_name'] ) && $gBitSystem->getConfig( 'users_display_name', 'real_name' ) == 'real_name' ) {
@@ -2425,18 +2418,30 @@ class BitUser extends LibertyMime {
$displayName = $pParamHash['login'];
} elseif( !empty( $pParamHash['email'] )) {
$displayName = substr( $pParamHash['email'], 0, strpos( $pParamHash['email'], '@' ));
- } elseif( !empty( $pParamHash['user_id'] ) ) {
+ } else {
$displayName = $pParamHash['user_id'];
+ }
+
+ if( !empty( $pParamHash['user'] )) {
+ $iHomepage = $pParamHash['user'];
+ } elseif( !empty( $pParamHash['login'] )) {
+ // user of 'login' is deprecated and eventually should go away!
+ $iHomepage = $pParamHash['login'];
+ } elseif( \Bitweaver\BitBase::verifyId( $pParamHash['user_id'] )) {
+ $iHomepage = $pParamHash['user_id'];
+ } elseif( !empty( $pParamHash['email'] )) {
+ $iHomepage = $pParamHash['email'];
} else {
- $displayName = 'No Name';
+ // this won't work right now, we need to alter userslib::interpret_home() to interpret a real name
+ $iHomepage = $pParamHash['real_name'];
}
if( empty( $pParamHash['users_information'] ) && !empty( $pParamHash['login'] ) ) {
- $pParamHash['users_information'] = $gBitSystem->mDb->getOne( "SELECT pref_value FROM liberty_content_prefs lcp INNER JOIN users_users uu ON (lcp.content_id=uu.content_id) WHERE uu.login=? AND pref_name='users_information'", array( $pParamHash['login'] ), 1, NULL, 86400 );
+ $pParamHash['users_information'] = $gBitSystem->mDb->getOne( "SELECT pref_value FROM liberty_content_prefs lcp INNER JOIN users_users uu ON (lcp.content_id=uu.content_id) WHERE uu.login=? AND pref_name='users_information'", array( $pParamHash['login'] ), 1, null, 86400 );
}
if( $pUseLink && ($gBitUser->hasPermission( 'p_users_view_user_homepage' ) || $pParamHash['users_information'] == 'public') ) {
- $ret = '<a class="username" title="'.( !empty( $pParamHash['link_title'] ) ? $pParamHash['link_title'] : tra( 'Profile for' ).' '.htmlspecialchars( $displayName ))
+ $ret = '<a class="username" title="'.( !empty( $pParamHash['link_title'] ) ? $pParamHash['link_title'] : KernelTools::tra( 'Profile for' ).' '.htmlspecialchars( $displayName ))
.'" href="'.BitUser::getDisplayUrlFromHash( $pParamHash ).'">'
. htmlspecialchars( isset( $pParamHash['link_label'] ) ? $pParamHash['link_label'] : $displayName )
.'</a>';
@@ -2444,7 +2449,7 @@ class BitUser extends LibertyMime {
$ret = htmlspecialchars( $displayName );
}
} else {
- $ret = tra( "Anonymous" );
+ $ret = KernelTools::tra( "Anonymous" );
}
return $ret;
@@ -2457,7 +2462,7 @@ class BitUser extends LibertyMime {
* @param pParamHash todo - need explanation on how to use this...
* @return display name or link to user information page
**/
- function getDisplayName( $pUseLink=FALSE ) {
+ function getDisplayName( $pUseLink=false ) {
return static::getDisplayNameFromHash( $this->mInfo, $pUseLink );
}
@@ -2475,7 +2480,7 @@ class BitUser extends LibertyMime {
* getSelectionList get a list of users that can be used in dropdown lists in forms to choose from
*
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function getSelectionList() {
$query = "
@@ -2483,7 +2488,7 @@ class BitUser extends LibertyMime {
FROM `".BIT_DB_PREFIX."users_users` uu
ORDER BY uu.`login`";
$result = $this->mDb->query( $query );
- $ret = array();
+ $ret = [];
while( $res = $result->fetchRow()) {
$ret[$res['user_id']] = $res['login'].(( !empty( $res['real_name'] ) && $res['real_name'] != $res['login'] ) ? ' - '.$res['real_name'] : '' );
}
@@ -2508,7 +2513,7 @@ class BitUser extends LibertyMime {
$selectSql = $joinSql = $whereSql = '';
$bindVars = array( 'bituser' );
-// $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $pParamHash );
+ $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, null, $pParamHash );
// limit search to users with a specific language
if( !empty( $pParamHash['lang_code'] ) ) {
@@ -2519,13 +2524,13 @@ class BitUser extends LibertyMime {
if( !$gBitUser->hasPermission( 'p_users_admin' ) ) {
$joinSql .= " LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_prefs` lcp2 ON ( lcp2.`content_id`=uu.`content_id` AND lcp2.`pref_name`='users_information' )";
- $whereSql .= " AND (lcp2.`pref_value` IS NULL OR lcp2.`pref_value`='public')";
+ $whereSql .= " AND (lcp2.`pref_value` IS null OR lcp2.`pref_value`='public')";
}
// limit search to users with a specific IP
if( !empty( $pParamHash['ip'] ) ) {
$joinSql .= " LEFT OUTER JOIN `".BIT_DB_PREFIX."users_cnxn` uc ON ( uu.`user_id`=uc.`user_id`) ";
- $ips = explode( ',', $pParamHash['ip'] );
+ $ips = mb_split( ',', $pParamHash['ip'] );
$ipList = '';
do {
$ip = array_pop( $ips );
@@ -2558,7 +2563,7 @@ class BitUser extends LibertyMime {
$selectSql .= ", sru.`referer_url`";
if( !empty( $pParamHash['referer'] ) ) {
if( $pParamHash['referer'] == 'none' ) {
- $whereSql .= " AND `referer_url` IS NULL";
+ $whereSql .= " AND `referer_url` IS null";
} else {
$whereSql .= " AND `referer_url` LIKE ?";
$bindVars[] = '%'.strtolower( $pParamHash['find'] ).'%';
@@ -2578,7 +2583,7 @@ class BitUser extends LibertyMime {
WHERE lc.`content_type_guid` = ? $whereSql ORDER BY ".$this->mDb->convertSortmode( $pParamHash['sort_mode'] );
$result = $this->mDb->query( $query, $bindVars, $pParamHash['max_records'], $pParamHash['offset'] );
- $ret = array();
+ $ret = [];
while( $res = $result->fetchRow() ) {
// Used for pulling out dead/empty/spam accounts
if( isset( $pParamHash['max_content_count'] ) && is_numeric( $pParamHash['max_content_count'] ) ) {
@@ -2604,7 +2609,7 @@ class BitUser extends LibertyMime {
if( !empty( $res['avatar_file_name'] )) {
$res['avatar_url'] = $this->getSourceUrl( array( 'attachment_id'=>$res['avatar_attachment_id'], 'mime_type'=>$res['avatar_mime_type'], 'file_name'=>$res['avatar_file_name'] ) );
$res['thumbnail_url'] = liberty_fetch_thumbnail_url( array(
- 'source_file' => $this->getSourceFile( array( 'sub_dir'=>$res['avatar_attachment_id'], 'user_id' => $res['user_id'], 'file_name'=>$res['avatar_file_name'], 'mime_type'=>$res['avatar_mime_type'], 'package'=>liberty_mime_get_storage_sub_dir_name( array( 'mime_type'=>$res['avatar_mime_type'], 'name'=>$res['avatar_file_name'] ) ) ) ),
+ 'source_file' => $this->getSourceFile( array( 'sub_dir'=>$res['avatar_attachment_id'], 'user_id' => $res['user_id'], 'file_name'=>$res['avatar_file_name'], 'mime_type'=>$res['avatar_mime_type'], 'package'=>\Bitweaver\Liberty\liberty_mime_get_storage_sub_dir_name( array( 'mime_type'=>$res['avatar_mime_type'], 'name'=>$res['avatar_file_name'] ) ) ) ),
'file_name' => $res['avatar_url'],
// TODO: Make this a preference
'size' => 'avatar'
@@ -2613,7 +2618,7 @@ class BitUser extends LibertyMime {
$res["groups"] = $this->getGroups( $res['user_id'] );
$ret[$res['user_id']] = $res;
}
- $retval = array();
+ $retval = [];
$query = "
SELECT COUNT(*) FROM `".BIT_DB_PREFIX."users_users` uu
@@ -2632,9 +2637,9 @@ class BitUser extends LibertyMime {
* @param array $pUserId
* @param array $pForceRefresh
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function getGroups( $pUserId=NULL, $pForceRefresh = FALSE ) {
+ function getGroups( $pUserId=null, $pForceRefresh = false ) {
$pUserId = !empty( $pUserId ) ? $pUserId : $this->mUserId;
if( !isset( $this->cUserGroups[$pUserId] ) || $pForceRefresh ) {
$query = "
@@ -2644,7 +2649,7 @@ class BitUser extends LibertyMime {
$ret = $this->mDb->getAssoc( $query, array(( int )$pUserId ));
if( $ret ) {
foreach( array_keys( $ret ) as $groupId ) {
- $res = array();
+ $res = [];
foreach( $res as $key=>$val) {
$ret[$key] = array( 'group_name' => $val );
}
@@ -2662,7 +2667,7 @@ class BitUser extends LibertyMime {
* isValid
*
* @access public
- * @return TRUE if user is loaded
+ * @return bool true if user is loaded
*/
function isValid() {
return ( $this->verifyId( $this->mUserId ) );
@@ -2672,17 +2677,17 @@ class BitUser extends LibertyMime {
* isAdmin "PURE VIRTUAL BASE FUNCTION";
*
* @access public
- * @return FALSE
+ * @return false
*/
function isAdmin() {
- return FALSE;
+ return false;
}
/**
* isRegistered
*
* @access public
- * @return TRUE if user is registered, FALSE otherwise
+ * @return bool true if user is registered, false otherwise
*/
function isRegistered() {
return ( $this->mUserId > ANONYMOUS_USER_ID );
@@ -2692,14 +2697,14 @@ class BitUser extends LibertyMime {
* verifyRegistered
*
* @access public
- * @return TRUE if user is registered, otherwise a login dialog is displayed
+ * @return bool true if user is registered, otherwise a login dialog is displayed
*/
function verifyRegistered( $pMsg = "" ) {
global $gBitSystem;
if( !$this->isRegistered() ) {
$gBitSystem->fatalPermission( "", $pMsg );
}
- return TRUE;
+ return true;
}
/**
@@ -2707,10 +2712,10 @@ class BitUser extends LibertyMime {
*
* @param array $pUserMixed
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function userExists( $pUserMixed ) {
- $ret = FALSE;
+ $ret = false;
if ( is_array( $pUserMixed ) ) {
if( $cur = current( $pUserMixed ) ) {
if( is_numeric( $cur ) ) {
@@ -2733,7 +2738,7 @@ class BitUser extends LibertyMime {
*/
function exportHash() {
global $gBitSystem;
- $ret = array();
+ $ret = [];
if( $this->isValid() ) {
$ret = parent::exportHash();
@@ -2775,7 +2780,7 @@ class BitUser extends LibertyMime {
$pReturn['user_id'] = $pInput['user_id'];
}
}
- if( @BitBase::verifyId( $pInput['group_id'] ) ) {
+ if( \Bitweaver\BitBase::verifyId( $pInput['group_id'] ) ) {
$pReturn['group_id'] = $pInput['group_id'];
}
return;
@@ -2793,15 +2798,15 @@ class BitUser extends LibertyMime {
function get_user_content_count( $pUserId ) {
global $gBitDb;
- if( BitBase::verifyId( $pUserId ) ) {
+ if( \Bitweaver\BitBase::verifyId( $pUserId ) ) {
return $gBitDb->getOne( "SELECT COUNT(`content_id`) FROM `".BIT_DB_PREFIX."liberty_content` lc WHERE lc.`content_type_guid`!='bituser' AND lc.`user_id`=?", array( $pUserId ) );
}
}
// {{{ ==================== Services ====================
-function users_favs_content_list_sql( $pObject, $pParamHash=NULL ){
- $ret = array();
+function users_favs_content_list_sql( $pObject, $pParamHash=null ){
+ $ret = [];
if( is_object( $pObject ) && !empty( $pParamHash['user_favs'] ) ){
// $ret['select_sql'] = "";
$ret['join_sql'] = " INNER JOIN `".BIT_DB_PREFIX."users_favorites_map` ufm ON ( ufm.`favorite_content_id`=lc.`content_id` )";
@@ -2811,9 +2816,9 @@ function users_favs_content_list_sql( $pObject, $pParamHash=NULL ){
return $ret;
}
-function users_collection_sql( &$pObject, $pParamHash=NULL ){
- $ret = array();
- if( !empty( $pParamHash['group_id'] ) and BitBase::verifyId( $pParamHash['group_id'] ) ){
+function users_collection_sql( &$pObject, $pParamHash=null ){
+ $ret = [];
+ if( !empty( $pParamHash['group_id'] ) and \Bitweaver\BitBase::verifyId( $pParamHash['group_id'] ) ){
// $ret['select_sql'] = "";
$ret['join_sql'] = " INNER JOIN `".BIT_DB_PREFIX."users_groups_map` ugm ON (ugm.`user_id`=uu.`user_id`)";
$ret['where_sql'] = ' AND ugm.`group_id` = ? ';
diff --git a/includes/classes/RolePermUser.php b/includes/classes/RolePermUser.php
index efa9ba6..3aca5d0 100644..100755
--- a/includes/classes/RolePermUser.php
+++ b/includes/classes/RolePermUser.php
@@ -18,7 +18,10 @@
/**
* required setup
*/
-require_once( USERS_PKG_CLASS_PATH.'RoleUser.php' );
+namespace Bitweaver\Users;
+use Bitweaver\BitBase;
+use Bitweaver\KernelTools;
+use Bitweaver\Liberty\LibertyContent;
/**
* Class that holds all information for a given user
@@ -28,9 +31,12 @@ require_once( USERS_PKG_CLASS_PATH.'RoleUser.php' );
* @package users
* @subpackage RolePermUser
*/
-class RolePermUser extends BitUser {
+#[\AllowDynamicProperties]
+class RolePermUser extends RoleUser {
public $mPerms;
+ public $mGroups;
+ public $mPermsOverride;
/**
* RolePermUser Initialise class
@@ -40,7 +46,7 @@ class RolePermUser extends BitUser {
* @access public
* @return void
*/
- function __construct( $pUserId=NULL, $pContentId=NULL ) {
+ function __construct( $pUserId=null, $pContentId=null ) {
parent::__construct( $pUserId, $pContentId );
// Permission setup
@@ -48,7 +54,7 @@ class RolePermUser extends BitUser {
}
public function __sleep() {
- return array_merge( parent::__sleep(), array( 'mPerms' ) );
+ return array_merge( parent::__sleep(), [ 'mPerms' ] );
}
public function __wakeup() {
@@ -63,11 +69,11 @@ class RolePermUser extends BitUser {
*
* @param numeric $pUserId User ID of the user you want to hijack
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function assumeUser( $pUserId ) {
global $gBitUser;
- $ret = FALSE;
+ $ret = false;
// make double sure the current logged in user has permission, check for p_users_admin, not admin, as that is all you need for assuming another user.
// this enables creating of a non technical site adminstrators role, eg customer support representatives.
@@ -75,10 +81,10 @@ class RolePermUser extends BitUser {
$assumeUser = new RolePermUser( $pUserId );
$assumeUser->loadPermissions();
if( $assumeUser->isAdmin() ) {
- $this->mErrors['assume_user'] = tra( "User administrators cannot be assumed." );
+ $this->mErrors['assume_user'] = KernelTools::tra( "User administrators cannot be assumed." );
} else {
- $this->mDb->query( "UPDATE `".BIT_DB_PREFIX."users_cnxn` SET `user_id`=?, `assume_user_id`=? WHERE `cookie`=?", array( $pUserId, $gBitUser->mUserId, $_COOKIE[$this->getSiteCookieName()] ) );
- $ret = TRUE;
+ $this->mDb->query( "UPDATE `".BIT_DB_PREFIX."users_cnxn` SET `user_id`=?, `assume_user_id`=? WHERE `cookie`=?", [ $pUserId, $gBitUser->mUserId, $_COOKIE[$this->getSiteCookieName()] ] );
+ $ret = true;
}
}
@@ -88,20 +94,19 @@ class RolePermUser extends BitUser {
/**
* load
*
- * @param boolean $pFull Load all permissions
- * @param string $pUserName User login name
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * - bool $pFull Load all permissions
+ * - string $pUserName User login name
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function load( $pFull=FALSE, $pUserName=NULL ) {
- if( BitUser::load( $pFull, $pUserName ) ) {
- if( $pFull ) {
+ public function load( ...$extraParams ): bool {
+ if( RoleUser::load( ...$extraParams ) ) {
+ if( !empty($extraParams[0]) && $extraParams[0] ) {
unset( $this->mPerms );
$this->loadRoles();
$this->loadPermissions();
}
}
- return( $this->mUserId != NULL );
+ return $this->mUserId != null;
}
/**
@@ -112,7 +117,7 @@ class RolePermUser extends BitUser {
*/
function sanitizeUserInfo() {
if( !empty( $this->mInfo )) {
- $unsanitary = array( 'provpass', 'hash', 'challenge', 'user_password' );
+ $unsanitary = [ 'provpass', 'hash', 'challenge', 'user_password' ];
foreach( array_keys( $this->mInfo ) as $key ) {
if( in_array( $key, $unsanitary )) {
unset( $this->mInfo[$key] );
@@ -125,36 +130,35 @@ class RolePermUser extends BitUser {
* store
*
* @param array $pParamHash
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function store( &$pParamHash ) {
+ public function store( array &$pParamHash): bool {
global $gBitSystem;
// keep track of newUser before calling base class
$newUser = !$this->isRegistered();
$this->StartTrans();
- if( BitUser::store( $pParamHash ) && $newUser ) {
+ if( RoleUser::store( $pParamHash ) && $newUser ) {
$defaultRoles = $this->getDefaultRole();
$this->addUserToRole( $this->mUserId, $defaultRoles );
if( $gBitSystem->isFeatureActive( 'users_eponymous_roles' ) ) {
// Create a role just for this user, for permissions assignment.
- $roleParams = array(
+ $roleParams = [
'user_id' => $this->mUserId,
'name' => $pParamHash['user_store']['login'],
'desc' => "Personal role for ".( !empty( $pParamHash['user_store']['real_name'] ) ? $pParamHash['user_store']['real_name'] : $pParamHash['user_store']['login'] )
- );
+ ];
if( $this->storeRole( $roleParams ) ) {
$this->addUserToRole( $this->mUserId, $roleParams['role_id'] );
}
}
- $this->load( TRUE );
+ $this->load( true );
// store any uploaded images, this can stuff mErrors, so we want to do this as the very last thing.
- $pParamHash['upload']['thumbnail'] = FALSE; // i don't think this does anything - perhaps replace it by setting thumbnail_sizes
+ $pParamHash['upload']['thumbnail'] = false; // i don't think this does anything - perhaps replace it by setting thumbnail_sizes
$this->storeImages( $pParamHash );
}
$this->CompleteTrans();
- return( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
@@ -163,12 +167,12 @@ class RolePermUser extends BitUser {
* @param string $pRoleName
* @param numeric $pUserId
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function roleExists( $pRoleName, $pUserId = ROOT_USER_ID ) {
- static $sRoles = array();
+ static $sRoles = [];
if( !isset( $sRoles[$pUserId][$pRoleName] ) ) {
- $bindVars = array( $pRoleName );
+ $bindVars = [ $pRoleName ];
$whereSql = '';
if( $pUserId != '*' ) {
$whereSql = 'AND `user_id`=?';
@@ -180,56 +184,55 @@ class RolePermUser extends BitUser {
WHERE `role_name`=? $whereSql";
if( $result = $this->mDb->getAssoc( $query, $bindVars ) ) {
if( empty( $sRoles[$pUserId] ) ) {
- $sRoles[$pUserId] = array();
+ $sRoles[$pUserId] = [];
}
$sRoles[$pUserId][$pRoleName] = $result[$pRoleName];
} else {
- $sRoles[$pUserId][$pRoleName]['role_id'] = NULL;
+ $sRoles[$pUserId][$pRoleName]['role_id'] = null;
}
}
- return( $sRoles[$pUserId][$pRoleName]['role_id'] );
+ return $sRoles[$pUserId][$pRoleName]['role_id'];
}
/**
* removes user and associated private data
*
* @access public
- * @return always FALSE???
- * TODO: fix return
+ * @return bool always true - some expunge overrides may retrun false
*/
- function expunge( $pExpungeContent=NULL) {
+ public function expunge(): bool {
global $gBitSystem, $gBitUser;
$this->clearFromCache();
if( $this->isValid() ) {
$this->StartTrans();
if( $this->mUserId == $gBitUser->mUserId ) {
$this->mDb->RollbackTrans();
- $gBitSystem->fatalError( tra( 'You cannot delete yourself' ) );
+ $gBitSystem->fatalError( KernelTools::tra( 'You cannot delete yourself' ) );
} elseif( $this->mUserId != ANONYMOUS_USER_ID ) {
- $userTables = array(
+ $userTables = [
'users_roles_map',
- );
+ ];
foreach( $userTables as $table ) {
$query = "DELETE FROM `".BIT_DB_PREFIX.$table."` WHERE `user_id` = ?";
- $result = $this->mDb->query( $query, array( $this->mUserId ) );
+ $result = $this->mDb->query( $query, [ $this->mUserId ] );
}
- if( parent::expunge( $pExpungeContent ) ) {
+ if( parent::expunge() ) {
$this->CompleteTrans();
- return TRUE;
} else {
$this->mDb->RollbackTrans();
}
} else {
$this->mDb->RollbackTrans();
- $gBitSystem->fatalError( tra( 'The anonymous user cannot be deleted' ) );
+ $gBitSystem->fatalError( KernelTools::tra( 'The anonymous user cannot be deleted' ) );
}
}
- return FALSE;
+ return true;
}
-
+ public function isInGroup( $pGroupMixed ) { return false; }
+ public function groupExists( $pGroupMixed ) { return false; }
// =-=-=-=-=-=-=-=-=-=-=-= Role Functions =-=-=-=-=-=-=-=-=-=-=-=-=-=-=
/**
@@ -239,9 +242,9 @@ class RolePermUser extends BitUser {
* @access public
* @return void
*/
- function loadRoles( $pForceRefresh = FALSE ) {
+ function loadRoles( $pForceRefresh = false ) {
if( $this->isValid() ) {
- $this->mRoles = $this->getRoles( NULL, $pForceRefresh );
+ $this->mRoles = $this->getRoles( 0, $pForceRefresh );
}
}
@@ -250,23 +253,19 @@ class RolePermUser extends BitUser {
*
* @param mixed $pRoleMixed Role ID or Role Name (deprecated)
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function isInRole( $pRoleMixed ) {
- $ret = FALSE;
+ $ret = false;
if( $this->isAdmin() ) {
- $ret = TRUE;
+ $ret = true;
} if( $this->isValid() ) {
if( empty( $this->mRoles ) ) {
$this->loadRoles();
}
- if( preg_match( '/A-Za-z/', $pRoleMixed ) ) {
- // Old style role name passed in
- deprecated( "Please use the Role ID instead of the Role name." );
- $ret = in_array( $pRoleMixed, $this->mRoles );
- } else {
- $ret = isset( $this->mRoles[$pRoleMixed] );
- }
+ $ret = preg_match( '/A-Za-z/', $pRoleMixed )
+ ? in_array( $pRoleMixed, $this->mRoles )
+ : isset( $this->mRoles[$pRoleMixed] );
}
return $ret;
}
@@ -278,7 +277,7 @@ class RolePermUser extends BitUser {
* @access public
* @return array of roles
*/
- function getAllRoles( &$pListHash ) {
+ public function getAllRoles( &$pListHash ) {
if( empty( $pListHash['sort_mode'] ) || $pListHash['sort_mode'] == 'name_asc' ) {
$pListHash['sort_mode'] = 'role_name_asc';
}
@@ -292,7 +291,7 @@ class RolePermUser extends BitUser {
$bindvars[] = "%".strtoupper( $pListHash['find'] )."%";
} else {
$mid = '';
- $bindvars = array();
+ $bindvars = [];
}
if( !empty( $pListHash['hide_root_roles'] )) {
@@ -323,12 +322,12 @@ class RolePermUser extends BitUser {
SELECT `user_id`, `role_id`, `role_name` , `role_desc`, `role_home`, `is_default`, `is_public`
FROM `".BIT_DB_PREFIX."users_roles` $mid
ORDER BY $sortMode";
- $ret = array();
+ $ret = [];
if( $rs = $this->mDb->query( $query, $bindvars ) ) {
while( $row = $rs->fetchRow() ) {
$roleId = $row['role_id'];
$ret[$roleId] = $row;
- $ret[$roleId]['perms'] = $this->getRolePermissions( array( 'role_id' => $roleId ));
+ $ret[$roleId]['perms'] = $this->getRolePermissions( [ 'role_id' => $roleId ]);
}
}
@@ -344,7 +343,7 @@ class RolePermUser extends BitUser {
* @access public
* @return array of roles a user belongs to
*/
- function getAllUserRoles( $pUserId = NULL ) {
+ function getAllUserRoles( $pUserId = null ) {
if( empty( $pUserId ) ) {
$pUserId = $this->mUserId;
}
@@ -353,62 +352,69 @@ class RolePermUser extends BitUser {
SELECT ur.`role_id` AS `hash_key`, ur.* FROM `".BIT_DB_PREFIX."users_roles` ur
WHERE `user_id`=?
ORDER BY ur.`role_name` ASC";
- return $this->mDb->getAssoc( $sql, array( $pUserId ));
+ return $this->mDb->getAssoc( $sql, [ $pUserId ] );
+ }
+
+ public function getAllGroups( &$pListHash ) {
+ return [];
}
+ function getAllUserGroups( $pUserId = null ) {
+ return [];
+ }
/**
* expungeRole remove a role
*
* @param numeric $pRoleId
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function expungeRole( $pRoleId ) {
// we cannot remove the anonymous role
if( $pRoleId != ANONYMOUS_TEAM_ID ) {
$query = "DELETE FROM `".BIT_DB_PREFIX."users_roles_map` WHERE `role_id` = ?";
- $result = $this->mDb->query( $query, array( $pRoleId ));
+ $result = $this->mDb->query( $query, [ $pRoleId ] );
$query = "DELETE FROM `".BIT_DB_PREFIX."users_role_permissions` WHERE `role_id` = ?";
- $result = $this->mDb->query( $query, array( $pRoleId ));
+ $result = $this->mDb->query( $query, [ $pRoleId ] );
$query = "DELETE FROM `".BIT_DB_PREFIX."users_roles` WHERE `role_id` = ?";
- $result = $this->mDb->query( $query, array( $pRoleId ));
- return TRUE;
+ $result = $this->mDb->query( $query, [ $pRoleId ] );
+ return true;
}
+ return false;
}
/**
* getDefaultRole get the default role of a given user
*
* @param array $pRoleId pass in a Role ID to make conditional function
- * @access public
- * @return Default Role ID if one is set
+ * @return array Default Role ID if one is set
*/
- function getDefaultRole( $pRoleId = NULL ) {
- $bindvars = FALSE;
+ public static function getDefaultRole( $pRoleId = null ) {
+ global $gBitDb;
+ $bindvars = [];
$whereSql = '';
- if( @BitBase::verifyId( $pRoleId )) {
+ if( BitBase::verifyId( $pRoleId )) {
$whereSql = "AND `role_id`=? ";
- $bindvars = array( $pRoleId );
+ $bindvars = [ $pRoleId ];
}
- return( $this->mDb->getAssoc( "SELECT `role_id`, `role_name` FROM `".BIT_DB_PREFIX."users_roles` WHERE `is_default` = 'y' $whereSql ", $bindvars ) );
+ return $gBitDb->getAssoc( "SELECT `role_id`, `role_name` FROM `".BIT_DB_PREFIX."users_roles` WHERE `is_default` = 'y' $whereSql ", $bindvars );
}
/**
* getRoleUsers Get a list of users who share a given role id
*
- * @param array $pRoleId
- * @access public
- * @return list of users who are in the role id
+ * @param int $pRoleId
+ * @return array list of users who are in the role id
*/
- function getRoleUsers( $pRoleId ) {
- $ret = array();
- if( @BitBase::verifyId( $pRoleId )) {
+ public function getRoleUsers( $pRoleId ) {
+ $ret = [];
+ if( BitBase::verifyId( $pRoleId )) {
$query = "
SELECT uu.`user_id` AS hash_key, uu.`login`, uu.`real_name`, uu.`user_id`
FROM `".BIT_DB_PREFIX."users_users` uu
INNER JOIN `".BIT_DB_PREFIX."users_roles_map` ur ON (uu.`user_id`=ur.`user_id`)
WHERE `role_id`=?";
- $ret = $this->mDb->getAssoc( $query, array( $pRoleId ));
+ $ret = $this->mDb->getAssoc( $query, [ $pRoleId ]);
}
return $ret;
}
@@ -416,15 +422,18 @@ class RolePermUser extends BitUser {
/**
* getHomeRole get the URL where a user of that role should be sent
*
- * @param array $pRoleId
+ * @param int $pRoleId
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function getHomeRole( $pRoleId ) {
- $ret = FALSE;
- if( @BitBase::verifyId( $pRoleId )) {
+ public function getGroupHome( $pRoleId ) {
+ return $this->getRoleHome( $pRoleId );
+ }
+ public function getRoleHome( $pRoleId ) {
+ $ret = false;
+ if( BitBase::verifyId( $pRoleId )) {
$query = "SELECT `role_home` FROM `".BIT_DB_PREFIX."users_roles` WHERE `role_id`=?";
- $ret = $this->mDb->getOne( $query,array( $pRoleId ) );
+ $ret = $this->mDb->getOne( $query,[ $pRoleId ] );
}
return $ret;
}
@@ -432,27 +441,28 @@ class RolePermUser extends BitUser {
/**
* storeUserDefaultRole
*
- * @param array $pUserId
- * @param array $pRoleId
+ * @param int $pUserId
+ * @param int $pRoleId
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function storeUserDefaultRole( $pUserId, $pRoleId ) {
- if( @BitBase::verifyId( $pUserId ) && @BitBase::verifyId( $pRoleId )) {
+ if( BitBase::verifyId( $pUserId ) && BitBase::verifyId( $pRoleId )) {
$query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `default_role_id` = ? WHERE `user_id` = ?";
- return $this->mDb->query( $query, array( $pRoleId, $pUserId ));
+ return $this->mDb->query( $query, [ $pRoleId, $pUserId ] );
}
+ return false;
}
/**
* batchAssignUsersToRole assign all users to a given role
*
- * @param array $pRoleId
+ * @param int $pRoleId
* @access public
* @return void
*/
function batchAssignUsersToRole( $pRoleId ) {
- if( @BitBase::verifyId( $pRoleId )) {
+ if( BitBase::verifyId( $pRoleId )) {
$users = $this->getRoleUsers( $pRoleId );
$result = $this->mDb->getCol( "SELECT uu.`user_id` FROM `".BIT_DB_PREFIX."users_users` uu" );
foreach( $result as $userId ) {
@@ -466,12 +476,11 @@ class RolePermUser extends BitUser {
/**
* batchSetUserDefaultRole
*
- * @param array $pRoleId
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @param int $pRoleId
+ * @return void
*/
- function batchSetUserDefaultRole( $pRoleId ) {
- if( @BitBase::verifyId( $pRoleId )) {
+ public function batchSetUserDefaultRole( $pRoleId ) {
+ if( BitBase::verifyId( $pRoleId )) {
$users = $this->getRoleUsers($pRoleId);
foreach( array_keys( $users ) as $userId ) {
$this->storeUserDefaultRole( $userId, $pRoleId );
@@ -482,82 +491,81 @@ class RolePermUser extends BitUser {
/**
* getRoleInfo
*
- * @param array $pRoleId
- * @access public
- * @return role information
+ * @param int $pRoleId
+ * @return array role information
*/
- function getRoleInfo( $pRoleId ) {
- if( @BitBase::verifyId( $pRoleId )) {
+ public function getRoleInfo( $pRoleId ) {
+ $ret = [];
+ if( BitBase::verifyId( $pRoleId )) {
$sql = "SELECT * FROM `".BIT_DB_PREFIX."users_roles` WHERE `role_id` = ?";
- $ret = $this->mDb->getRow( $sql, array( $pRoleId ));
+ $ret = $this->mDb->getRow( $sql, [ $pRoleId ] );
- $listHash = array(
+ $listHash = [
'role_id' => $pRoleId,
'sort_mode' => 'up.perm_name_asc',
- );
+ ];
$ret["perms"] = $this->getRolePermissions( $listHash );
$sql = "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."users_roles_map` WHERE `role_id` = ?";
- $ret['num_members'] = $this->mDb->getOne( $sql, array( $pRoleId ));
-
- return $ret;
+ $ret['num_members'] = $this->mDb->getOne( $sql, [ $pRoleId ] );
}
+ return $ret;
}
/**
* addUserToRole Adds user pUserId to role(s) pRoleMixed.
*
- * @param numeric $pUserId User ID
+ * @param int $pUserId User ID
* @param mixed $pRoleMixed A single role ID or an array of role IDs
- * @access public
- * @return Either an ADO RecordSet (success) or FALSE (failure).
+ * @return array|bool Either an ADO RecordSet (success) or false (failure).
*/
- function addUserToRole( $pUserId, $pRoleMixed ) {
- $result = FALSE;
- if( @BitBase::verifyId( $pUserId ) && !empty( $pRoleMixed )) {
- $result = TRUE;
- $addRoles = array();
+ public static function addUserToRole( ?int $pUserId, array|int $pRoleMixed ): array|bool {
+ global $gBitUser;
+ $result = false;
+ if( BitBase::verifyId( $pUserId ) && !empty( $pRoleMixed )) {
+ $result = true;
+ $addRoles = [];
if( is_array( $pRoleMixed ) ) {
$addRoles = array_keys( $pRoleMixed );
- } elseif( @BitBase::verifyId($pRoleMixed) ) {
- $addRoles = array( $pRoleMixed );
+ } elseif(BitBase::verifyId($pRoleMixed) ) {
+ $addRoles = [ $pRoleMixed ];
}
- $currentUserRoles = $this->getRoles( $pUserId );
+ $currentUserRoles = $gBitUser->getRoles( $pUserId );
foreach( $addRoles AS $roleId ) {
- $isInRole = FALSE;
+ $isInRole = false;
if( $currentUserRoles ) {
foreach( $currentUserRoles as $curRoleId => $curRoleInfo ) {
if( $curRoleId == $roleId ) {
- $isInRole = TRUE;
+ $isInRole = true;
}
}
}
if( !$isInRole ) {
$query = "INSERT INTO `".BIT_DB_PREFIX."users_roles_map` (`user_id`,`role_id`) VALUES(?,?)";
- $result = $this->mDb->query( $query, array( $pUserId, $roleId ));
+ $result = $gBitUser->mDb->query( $query, [ $pUserId, $roleId ] );
}
}
}
- $this->clearFromCache();
+ $gBitUser->clearFromCache();
return $result;
}
/**
* removeUserFromRole
*
- * @param array $pUserId
- * @param array $pRoleId
+ * @param int $pUserId
+ * @param int $pRoleId
* @access public
* @return void
*/
function removeUserFromRole( $pUserId, $pRoleId ) {
- if( @BitBase::verifyId( $pUserId ) && @BitBase::verifyId( $pRoleId )) {
+ if( BitBase::verifyId( $pUserId ) && BitBase::verifyId( $pRoleId )) {
$query = "DELETE FROM `".BIT_DB_PREFIX."users_roles_map` WHERE `user_id` = ? AND `role_id` = ?";
- $result = $this->mDb->query( $query, array( $pUserId, $pRoleId ));
+ $result = $this->mDb->query( $query, [ $pUserId, $pRoleId ] );
$default = $this->getDefaultRole();
if( $pRoleId == key( $default )) {
- $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `default_role_id` = NULL WHERE `user_id` = ?";
- $this->mDb->query( $query, array( $pUserId ));
+ $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `default_role_id` = null WHERE `user_id` = ?";
+ $this->mDb->query( $query, [ $pUserId ] );
}
}
$this->clearFromCache();
@@ -568,7 +576,7 @@ class RolePermUser extends BitUser {
*
* @param array $pParamHash
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function verifyRole( &$pParamHash ) {
if( !empty($pParamHash['role_id'] )) {
@@ -586,11 +594,11 @@ class RolePermUser extends BitUser {
$pParamHash['role_store']['role_desc'] = substr( $pParamHash["desc"], 0, 255 );;
}
$pParamHash['role_store']['role_home'] = !empty( $pParamHash["home"] ) ? $pParamHash["home"] : '';
- $pParamHash['role_store']['is_default'] = !empty( $pParamHash["is_default"] ) ? $pParamHash["is_default"] : NULL;
+ $pParamHash['role_store']['is_default'] = !empty( $pParamHash["is_default"] ) ? $pParamHash["is_default"] : null;
$pParamHash['role_store']['user_id'] = @$this->verifyId( $pParamHash["user_id"] ) ? $pParamHash["user_id"] : $this->mUserId;
- $pParamHash['role_store']['is_public'] = !empty( $pParamHash['is_public'] ) ? $pParamHash['is_public'] : NULL;
+ $pParamHash['role_store']['is_public'] = !empty( $pParamHash['is_public'] ) ? $pParamHash['is_public'] : null;
$pParamHash['role_store']['after_registration_page'] = !empty( $pParamHash['after_registration_page'] ) ? $pParamHash['after_registration_page'] : '';
- return( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
@@ -598,10 +606,10 @@ class RolePermUser extends BitUser {
*
* @param array $pParamHash
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function storeRole( &$pParamHash ) {
- global $gBitSystem;
+ global $gBitSystem, $gBitUser;
if ($this->verifyRole( $pParamHash)) {
$this->StartTrans();
if( empty( $pParamHash['role_id'] ) ) {
@@ -610,9 +618,9 @@ class RolePermUser extends BitUser {
$result = $this->mDb->associateInsert( BIT_DB_PREFIX.'users_roles', $pParamHash['role_store'] );
} else {
$sql = "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."users_roles` WHERE `role_id` = ?";
- $roleExists = $this->mDb->getOne($sql, array($pParamHash['role_id']));
+ $roleExists = $this->mDb->getOne($sql, [ $pParamHash['role_id'] ] );
if ($roleExists) {
- $result = $this->mDb->associateUpdate( BIT_DB_PREFIX.'users_roles', $pParamHash['role_store'], array( "role_id" => $pParamHash['role_id'] ) );
+ $result = $this->mDb->associateUpdate( BIT_DB_PREFIX.'users_roles', $pParamHash['role_store'], [ "role_id" => $pParamHash['role_id'] ] );
} else {
// A role_id was specified but that role does not exist yet
$pParamHash['role_store']['role_id'] = $pParamHash['role_id'];
@@ -625,7 +633,7 @@ class RolePermUser extends BitUser {
}
$this->CompleteTrans();
}
- return ( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
@@ -634,13 +642,13 @@ class RolePermUser extends BitUser {
* @param array $pRoleId
* @param array $pColumns
* @access public
- * @return array of group data
+ * @return string of role name
*/
- public static function getRoleNameFromId( $pRoleId ) {
+ public static function getRoleNameFromId( $pRoleId ): string {
$ret = '';
if( static::verifyId( $pRoleId ) ) {
global $gBitDb;
- $ret = $gBitDb->getOne( "SELECT `role_name` FROM `".BIT_DB_PREFIX."users_roles` WHERE `role_id`=?", array( $pRoleId ) );
+ $ret = $gBitDb->getOne( "SELECT `role_name` FROM `".BIT_DB_PREFIX."users_roles` WHERE `role_id`=?", [ $pRoleId ] );
}
return $ret;
}
@@ -650,14 +658,13 @@ class RolePermUser extends BitUser {
*
* @param array $pRoleId
* @param array $pColumns
- * @access public
* @return array of role data
*/
- function getRoleUserData( $pRoleId, $pColumns ) {
- $ret = array();
+ public function getRoleUserData( $pRoleId, $pColumns ) {
+ $ret = [];
if( @$this->verifyId( $pRoleId ) && !empty( $pColumns ) ) {
if( is_array( $pColumns ) ) {
- $col = implode( $pColumns, ',' );
+ $col = implode( ',', $pColumns );
$exec = 'getAssoc';
} else {
$col = '`'.$pColumns.'`';
@@ -668,7 +675,7 @@ class RolePermUser extends BitUser {
FROM `".BIT_DB_PREFIX."users_users` uu
INNER JOIN `".BIT_DB_PREFIX."users_roles_map` urm ON (uu.`user_id`=urm.`user_id`)
WHERE urm.`role_id` = ?";
- $ret = $this->mDb->$exec( $query, array( $pRoleId ));
+ $ret = $this->mDb->$exec( $query, [ $pRoleId ]);
}
return $ret;
}
@@ -677,12 +684,11 @@ class RolePermUser extends BitUser {
/**
* loadPermissions
*
- * @access public
- * @return TRUE on success, FALSE if no perms were loaded
+ * @return bool true on success, false if no perms were loaded
*/
- function loadPermissions( $pForceReload=FALSE ) {
+ public function loadPermissions( $pForceReload=false ) {
if( $this->isValid() && (empty( $this->mPerms ) || $pForceReload) ) {
- $this->mPerms = array();
+ $this->mPerms = [];
// the double up.`perm_name` is intentional - the first is for hash key, the second is for hash value
$query = "
SELECT up.`perm_name` AS `hash_key`, up.`perm_name`, up.`perm_desc`, up.`perm_level`, up.`package`
@@ -691,7 +697,7 @@ class RolePermUser extends BitUser {
INNER JOIN `".BIT_DB_PREFIX."users_roles` ur ON ( ur.`role_id`=urp.`role_id` )
LEFT OUTER JOIN `".BIT_DB_PREFIX."users_roles_map` urm ON ( urm.`role_id`=urp.`role_id` AND urm.`user_id` = ? )
WHERE ur.`role_id`= ".ANONYMOUS_TEAM_ID." OR urm.`role_id`=ur.`role_id`";
- $this->mPerms = $this->mDb->getAssoc( $query, array( $this->mUserId ));
+ $this->mPerms = $this->mDb->getAssoc( $query, [ $this->mUserId ] );
// Add in override permissions
if( !empty( $this->mPermsOverride ) ) {
foreach( $this->mPermsOverride as $key => $val ) {
@@ -699,69 +705,53 @@ class RolePermUser extends BitUser {
}
}
}
- return( count( $this->mPerms ) );
+ return count( $this->mPerms );
}
/**
* getUnassignedPerms
*
- * @access public
* @return array of permissions that have not been assigned to any role yet
*/
- function getUnassignedPerms() {
+ public function getUnassignedPerms() {
$query = "SELECT up.`perm_name` AS `hash_key`, up.*
FROM `".BIT_DB_PREFIX."users_permissions` up
LEFT OUTER JOIN `".BIT_DB_PREFIX."users_role_permissions` urp ON( up.`perm_name` = urp.`perm_name` )
- WHERE urp.`role_id` IS NULL AND up.`perm_name` <> ?
+ WHERE urp.`role_id` IS null AND up.`perm_name` <> ?
ORDER BY `package`, up.`perm_name` ASC";
- return( $this->mDb->getAssoc( $query, array( '' )));
+ return $this->mDb->getAssoc( $query, [ '' ] );
}
/**
* isAdmin
*
* @param array $pCheckTicket
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function isAdmin() {
+ public function isAdmin() {
// we can't use hasPermission here since it turn into an endless loop
- return( !empty( $this->mPerms['p_admin'] ));
- }
-
- /**
- * hasPermission check to see if a user has a given permission
- *
- * @param array $pPerm Perm name
- * @access public
- * @return TRUE if the user has a permission, FALSE if they don't
- */
- function hasPermission( $pPerm ) {
- $ret = FALSE;
- if( $this->isAdmin() ) {
- $ret = TRUE;
- } elseif( $this->isValid() ) {
- $ret = isset( $this->mPerms[$pPerm] );
- }
- return ( $ret );
+ return !empty( $this->mPerms['p_admin'] );
}
/**
* verifyPermission check if a user has a given permission and if not
* it will display the error template and die()
* @param $pPermission value of a given permission
- * @return none
- * @access public
+ * @return void
*/
- function verifyPermission( $pPermission, $pMsg = NULL ) {
+ public function verifyPermission( $pPermission, $pMsg = null ) {
global $gBitSmarty, $gBitSystem, ${$pPermission};
if( empty( $pPermission ) || $this->hasPermission( $pPermission ) ) {
- return TRUE;
+ return;
} else {
$gBitSystem->fatalPermission( $pPermission, $pMsg );
}
}
+ public function getGroupPermissions( $pParamHash = null ) {
+ $this->getRolePermissions( $pParamHash );
+ }
+
/**
* getRolePermissions
*
@@ -769,26 +759,23 @@ class RolePermUser extends BitUser {
* @param string $pPackage permissions to give role, if unset, all permissions are returned
* @param string $find search for a particular permission
* @param array $pSortMode sort mode of return hash
- * @access public
- * @return TRUE on success, FALSE on failure
+ * @return array
*/
- function getRolePermissions( $pParamHash = NULL ) {
+ public function getRolePermissions( $pParamHash = null ) {
global $gBitSystem;
- $ret = $bindVars = array();
+ $ret = $bindVars = [];
$whereSql = $selectSql = $fromSql = '';
- if( !empty( $pParamHash['sort_mode'] )) {
- $sortMode = $this->mDb->convertSortmode( $pParamHash['sort_mode'] );
- } else {
- $sortMode = 'up.`package`, up.`perm_name` ASC';
- }
+ $sortMode = !empty( $pParamHash['sort_mode'] )
+ ? $this->mDb->convertSortmode( $pParamHash['sort_mode'] )
+ : 'up.`package`, up.`perm_name` ASC';
if( !empty( $pParamHash['package'] )) {
$whereSql = ' WHERE `package`= ? ';
$bindVars[] = $pParamHash['package'];
}
- if( @BitBase::verifyId( $pParamHash['role_id'] )) {
+ if( BitBase::verifyId( $pParamHash['role_id'] ?? 0 ) ) {
$selectSql = ', urp.`perm_value` AS `hasPerm` ';
$fromSql = ' INNER JOIN `'.BIT_DB_PREFIX.'users_role_permissions` urp ON ( urp.`perm_name`=up.`perm_name` ) ';
if( $whereSql ) {
@@ -817,7 +804,7 @@ class RolePermUser extends BitUser {
$perms = $this->mDb->getAssoc( $query, $bindVars );
// weed out permissions of inactive packages
- $ret = array();
+ $ret = [];
foreach( $perms as $key => $perm ) {
if( $gBitSystem->isPackageActive( $perm['package'] )) {
$ret[$key] = $perm;
@@ -830,15 +817,14 @@ class RolePermUser extends BitUser {
/**
* assignLevelPermissions Assign the permissions of a given level to a given role
*
- * @param array $pRoleId Role we want to assign permissions to
- * @param array $pLevel permission level we wish to assign from
- * @param array $pPackage limit set of permissions to a given package
- * @access public
+ * @param int $pRoleId Role we want to assign permissions to
+ * @param string $pLevel permission level we wish to assign from
+ * @param string $pPackage limit set of permissions to a given package
* @return void
*/
- function assignLevelPermissions( $pRoleId, $pLevel, $pPackage = NULL) {
- if( @BitBase::verifyId( $pRoleId ) && !empty( $pLevel )) {
- $bindvars = array( $pLevel );
+ public function assignLevelPermissions( $pRoleId, $pLevel, $pPackage = '') {
+ if( BitBase::verifyId( $pRoleId ) && !empty( $pLevel )) {
+ $bindvars = [ $pLevel ];
$whereSql = '';
if( !empty( $pPackage ) ) {
$whereSql = ' AND `package`=?';
@@ -860,24 +846,22 @@ class RolePermUser extends BitUser {
* @return array of packages
*/
function getPermissionPackages() {
- return( $this->mDb->getCol( "SELECT DISTINCT(`package`) FROM `".BIT_DB_PREFIX."users_permissions` ORDER BY `package`" ) );
+ return $this->mDb->getCol( "SELECT DISTINCT(`package`) FROM `".BIT_DB_PREFIX."users_permissions` ORDER BY `package`" );
}
/**
* assignPermissionToRole
*
- * @param array $perm
- * @param array $pRoleId
- * @access public
- * @return TRUE on success
+ * @param string $perm
+ * @param int $pRoleId
+ * @return void
*/
- function assignPermissionToRole( $pPerm, $pRoleId ) {
- if( @BitBase::verifyId( $pRoleId ) && !empty( $pPerm )) {
+ public function assignPermissionToRole( $pPerm, $pRoleId ) {
+ if( BitBase::verifyId( $pRoleId ) && !empty( $pPerm )) {
$query = "DELETE FROM `".BIT_DB_PREFIX."users_role_permissions` WHERE `role_id` = ? AND `perm_name` = ?";
- $result = $this->mDb->query( $query, array( $pRoleId, $pPerm ));
+ $result = $this->mDb->query( $query, [ $pRoleId, $pPerm ] );
$query = "INSERT INTO `".BIT_DB_PREFIX."users_role_permissions`(`role_id`, `perm_name`) VALUES(?, ?)";
- $result = $this->mDb->query( $query, array( $pRoleId, $pPerm ));
- return TRUE;
+ $result = $this->mDb->query( $query, [ $pRoleId, $pPerm ] );
}
}
@@ -885,15 +869,13 @@ class RolePermUser extends BitUser {
* removePermissionFromRole
*
* @param string $pPerm Perm name
- * @param numeric $pRoleId Role ID
- * @access public
- * @return TRUE on success
+ * @param int $pRoleId Role ID
+ * @return void
*/
- function removePermissionFromRole( $pPerm, $pRoleId ) {
- if( @BitBase::verifyId( $pRoleId ) && !empty( $pPerm )) {
+ public function removePermissionFromRole( $pPerm, $pRoleId ) {
+ if( BitBase::verifyId( $pRoleId ) && !empty( $pPerm )) {
$query = "DELETE FROM `".BIT_DB_PREFIX."users_role_permissions` WHERE `perm_name` = ? AND `role_id` = ?";
- $result = $this->mDb->query($query, array($pPerm, $pRoleId));
- return TRUE;
+ $result = $this->mDb->query($query, [$pPerm, $pRoleId ] );
}
}
@@ -901,11 +883,10 @@ class RolePermUser extends BitUser {
* storeRegistrationChoice
*
* @param mixed $pRoleMixed A single role ID or an array of role IDs
- * @param array $pValue Value you wish to store - use NULL to delete a value
- * @access public
- * @return ADO record set on success, FALSE on failure
+ * @param string $pValue Value you wish to store - use null to delete a value
+ * @return array|null ADO record set on success, false on failure
*/
- function storeRegistrationChoice( $pRoleMixed, $pValue = NULL ) {
+ public function storeRegistrationChoice( $pRoleMixed, $pValue = null ) {
if( !empty( $pRoleMixed )) {
$bindVars[] = $pValue;
if( is_array( $pRoleMixed )) {
@@ -918,26 +899,24 @@ class RolePermUser extends BitUser {
$query = "UPDATE `".BIT_DB_PREFIX."users_roles` SET `is_public`= ? where `role_id` IN ($mid)";
return $this->mDb->query( $query, $bindVars );
}
+ return null;
}
/**
* Grant a single permission to a given value
*/
- function setPermissionOverride( $pPerm, $pValue = NULL ) {
+ public function setPermissionOverride( $pPerm, $pValue = null ) {
if( $this->isAdmin() ) {
- $this->mPerms[$pPerm] = TRUE;
- $this->mPermsOverride[$pPerm] = TRUE;
+ $this->mPerms[$pPerm] = true;
+ $this->mPermsOverride[$pPerm] = true;
} elseif( $this->isValid() ) {
- if( $pValue == 'y' || $pValue == TRUE ) {
- $this->mPermsOverride[$pPerm] = TRUE;
- $this->mPerms[$pPerm] = TRUE;
+ if( $pValue == 'y' || $pValue == true ) {
+ $this->mPermsOverride[$pPerm] = true;
+ $this->mPerms[$pPerm] = true;
} else {
unset( $this->mPermsOverride[$pPerm] );
unset( $this->mPerms[$pPerm] );
}
}
}
-}
-
-/* vim: :set fdm=marker : */
-?>
+} \ No newline at end of file
diff --git a/includes/classes/RoleUser.php b/includes/classes/RoleUser.php
index d4efc66..b1c53a2 100644..100755
--- a/includes/classes/RoleUser.php
+++ b/includes/classes/RoleUser.php
@@ -16,8 +16,16 @@
/**
* required setup
*/
-require_once( LIBERTY_PKG_CLASS_PATH.'LibertyMime.php' );
-require_once( USERS_PKG_INCLUDE_PATH.'includes/users_lib.php' );
+namespace Bitweaver\Users;
+use Bitweaver\BitBase;
+use Bitweaver\BitSystem;
+use Bitweaver\DateTime;
+use Bitweaver\Liberty\LibertyBase;
+use Bitweaver\Liberty\LibertyContent;
+use Bitweaver\KernelTools;
+
+require_once LIBERTY_PKG_INCLUDE_PATH.'liberty_lib.php';
+require_once USERS_PKG_INCLUDE_PATH.'users_lib.php';
define( 'AVATAR_TYPE_CENTRALIZED', 'c' );
define( 'AVATAR_TYPE_USER_DB', 'u' );
@@ -42,40 +50,43 @@ define( "ACCOUNT_DISABLED", -6 );
* @package users
* @subpackage BitUser
*/
-class BitUser extends LibertyMime {
+class RoleUser extends \Bitweaver\Liberty\LibertyMime {
public $mUserId;
public $mUsername;
public $mRoles;
public $mTicket;
public $mAuth;
+ public $cUserRoles;
+ public $pExpungeContent = 'none';
/**
* Constructor - will automatically load all relevant data if passed a user string
*
* @access public
* @author Christian Fowler <spider@viovio.com>
- * @return returnString
+ * @return // returnString
*/
- function __construct( $pUserId=NULL, $pContentId=NULL ) {
+ public function __construct( $pUserId=null, $pContentId=null ) {
parent::__construct();
$this->mContentTypeGuid = BITUSER_CONTENT_TYPE_GUID;
$this->registerContentType(
- BITUSER_CONTENT_TYPE_GUID, array(
+ BITUSER_CONTENT_TYPE_GUID, [
'content_type_guid' => BITUSER_CONTENT_TYPE_GUID,
'content_name' => 'User Information',
'content_name_plural' => 'User Information',
- 'handler_class' => 'BitUser',
+ 'handler_class' => 'RoleUser',
'handler_package' => 'users',
'handler_file' => 'RoleUser.php',
- 'maintainer_url' => 'http://www.bitweaver.org'
- )
+ 'maintainer_url' => 'http://www.bitweaver.org',
+ ]
);
- $this->mUserId = ( @$this->verifyId( $pUserId ) ? $pUserId : NULL);
+ $this->mUserId = @$this->verifyId( $pUserId ) ? $pUserId : null;
$this->mContentId = $pContentId;
+ $this->pExpungeContent = 'none';
}
public function __sleep() {
- return array_merge( parent::__sleep(), array( 'mUserId', 'mUsername', 'mRoles', 'mTicket', 'mAuth' ) );
+ return array_merge( parent::__sleep(), [ 'mUserId', 'mUsername', 'mRoles', 'mTicket', 'mAuth' ] );
}
public function getCacheKey() {
@@ -94,7 +105,7 @@ class BitUser extends LibertyMime {
/**
* Determines if a user object is cacheable. Out of paranoia, admin's are never cached.
- * @return boolean if object can be cached
+ * @return bool if object can be cached
*/
public function isCacheableObject() {
global $gBitSystem;
@@ -105,7 +116,7 @@ class BitUser extends LibertyMime {
* Validate inbound sort_mode parameter
* @return array of fields which are valid sorts
*/
- public static function getSortModeFields() {
+ public static function getSortModeFields(): array {
$fields = parent::getSortModeFields();
$fields[] = 'map_position';
return $fields;
@@ -114,29 +125,29 @@ class BitUser extends LibertyMime {
/**
* load - loads all settings & preferences for this user
*
- * @param boolean $pFull Load additional user data like
- * @param string $pUserName User login name
+ * - boolean $pFull Load additional user data like
+ * - string $pUserName User login name
* @access public
* @author Chrstian Fowler <spider@steelsun.com>
- * @return returnString
+ * @return bool returnString
*/
- function load( $pFull=TRUE, $pUserName=NULL ) {
+ public function load( ...$extraParams ): bool {
global $gBitSystem;
- $this->mInfo = NULL;
+ $this->mInfo = null;
if( isset( $this->mUserId ) ) {
$whereSql = "WHERE uu.`user_id`=?";
- $bindVars = array( $this->mUserId );
+ $bindVars = [ $this->mUserId ];
} elseif( isset( $this->mContentId ) ) {
$whereSql = "WHERE uu.`content_id`=?";
- $bindVars = array( $this->mContentId );
- } elseif( !empty( $pUserName ) ) {
+ $bindVars = [ $this->mContentId ];
+ } elseif( !empty( $extraParams[1] ) ) {
$whereSql = "WHERE uu.`login`=?";
- $bindVars = array( $pUserName );
+ $bindVars = [ $extraParams[1] ];
}
if( isset( $whereSql ) ) {
$fullSelect = '';
$fullJoin = '';
- if( $pFull ) {
+ if( !empty( $extraParams[0] ) && $extraParams[0] ) {
$fullSelect = ' , lc.* ';
$fullJoin = " LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON ( uu.`content_id`=lc.`content_id` )";
$this->getServicesSql( 'content_load_sql_function', $fullSelect, $fullJoin, $whereSql, $bindVars );
@@ -163,9 +174,19 @@ class BitUser extends LibertyMime {
$this->mInfo['valid'] = @$this->verifyId( $this->mInfo['uu_user_id'] );
$this->mInfo['user_id'] = $this->mInfo['uu_user_id'];
$this->mInfo['is_registered'] = $this->isRegistered();
- foreach( array( 'portrait', 'avatar', 'logo' ) as $img ) {
- $this->mInfo[$img.'_path'] = $this->getSourceFile( array( 'user_id'=>$this->getField( 'user_id' ), 'package'=>liberty_mime_get_storage_sub_dir_name( array( 'mime_type' => $this->getField( $img.'_mime_type' ), 'name' => $this->getField( $img.'_file_name' ) ) ), 'file_name' => basename( $this->mInfo[$img.'_file_name'] ), 'sub_dir' => $this->getField( $img.'_attachment_id' ), 'mime_type' => $this->getField( $img.'_mime_type' ) ) );
- $this->mInfo[$img.'_url'] = liberty_fetch_thumbnail_url( array( 'source_file'=>$this->mInfo[$img.'_path'], 'size' => 'small', 'mime_image' => FALSE ));
+ foreach( [ 'portrait', 'avatar', 'logo' ] as $img ) {
+ $this->mInfo[$img.'_path'] = $this->getSourceFile( [
+ 'user_id'=>$this->getField( 'user_id' ),
+ 'package'=>\Bitweaver\Liberty\liberty_mime_get_storage_sub_dir_name([
+ 'mime_type' => $this->getField( $img.'_mime_type' ),
+ 'name' => $this->getField( $img.'_file_name' ) ] ),
+ 'file_name' => basename( $this->mInfo[$img.'_file_name'] ?? '' ),
+ 'sub_dir' => $this->getField( $img.'_attachment_id' ),
+ 'mime_type' => $this->getField( $img.'_mime_type' ) ] );
+ $this->mInfo[$img.'_url'] = \Bitweaver\Liberty\liberty_fetch_thumbnail_url( [
+ 'source_file'=>$this->mInfo[$img.'_path'],
+ 'size' => 'small',
+ 'mime_image' => false ] );
}
// break the real name into first and last name using the last space as the beginning of the last name
@@ -187,26 +208,24 @@ class BitUser extends LibertyMime {
$this->loadPreferences();
// Load attachments
- LibertyMime::load();
+ \Bitweaver\Liberty\LibertyMime::load();
if( $this->getPreference( 'users_country' ) ) {
$this->setPreference( 'flag', $this->getPreference( 'users_country' ) );
$this->setPreference( 'users_country', str_replace( '_', ' ', $this->getPreference( 'users_country' ) ) );
}
- if( $pFull ) {
+ if( !empty($extraParams[0]) && $extraParams[0] ) {
$this->mInfo['real_name'] = trim( $this->mInfo['real_name'] );
- $this->mInfo['display_name'] = (
- ( !empty( $this->mInfo['real_name'] ) ? $this->mInfo['real_name'] :
+ $this->mInfo['display_name'] = !empty( $this->mInfo['real_name'] ) ? $this->mInfo['real_name'] :
( !empty( $this->mUsername) ? $this->mUsername :
( !empty( $this->mInfo['email'] ) ? substr( $this->mInfo['email'], 0, strpos( $this->mInfo['email'],'@' )) :
- $this->mUserId )))
- );
+ $this->mUserId ));
//print("displayName: ".$this->mInfo['display_name']);
$this->defaults();
- $this->mInfo['publicEmail'] = scramble_email( $this->mInfo['email'], ( $this->getPreference( 'users_email_display' ) ? $this->getPreference( 'users_email_display' ) : NULL ) );
+ $this->mInfo['publicEmail'] = scramble_email( $this->mInfo['email'], $this->getPreference( 'users_email_display' ) ? $this->getPreference( 'users_email_display' ) : null );
}
$this->mTicket = substr( md5( session_id() . $this->mUserId ), 0, 20 );
} else {
- $this->mUserId = NULL;
+ $this->mUserId = null;
}
}
if( !$gBitSystem->isFeatureActive( 'i18n_browser_languages' ) ) {
@@ -220,7 +239,7 @@ class BitUser extends LibertyMime {
$gBitLanguage->mLanguage = $_SESSION['bitlanguage'];
}
}
- return( $this->isValid() );
+ return $this->isValid();
}
/**
@@ -229,7 +248,7 @@ class BitUser extends LibertyMime {
* @access public
* @return void
*/
- function defaults() {
+ public function defaults(): void {
global $gBitSystem, $gBitThemes, $gBitLanguage;
if( !$this->getPreference( 'users_information' ) ) {
$this->setPreference( 'users_information', 'public' );
@@ -260,25 +279,25 @@ class BitUser extends LibertyMime {
*
* @param array $pParamHash Data to be verified
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function verify( &$pParamHash ) {
+ public function verify( array &$pParamHash ): bool {
global $gBitSystem;
- trim_array( $pParamHash );
+ KernelTools::trim_array( $pParamHash );
// DO NOT REMOVE - to allow specific setting of the user_id during the first store.
// used by ROOT_USER_ID or ANONYMOUS_USER_ID during install.
- if( @$this->verifyId( $pParamHash['user_id'] ) ) {
+ if( @$this->verifyId( $pParamHash['user_id'] ?? '' ) ) {
$pParamHash['user_store']['user_id'] = $pParamHash['user_id'];
}
// require login
if( !empty( $pParamHash['login'] ) && $pParamHash['login'] != $this->getField( 'login' ) ) {
$pParamHash['login'] = strip_tags($pParamHash['login']);
- if( $this->userExists( array( 'login' => $pParamHash['login'] ) ) ) {
+ if( $this->userExists( [ 'login' => $pParamHash['login'] ] ) ) {
$this->mErrors['login'] = 'The username "'.$pParamHash['login'].'" is already in use';
} elseif( preg_match( '/[^A-Za-z0-9_.-]/', $pParamHash["login"] ) ) {
- $this->mErrors['login'] = tra( "Your username can only contain numbers, characters, underscores and hyphens." );
+ $this->mErrors['login'] = KernelTools::tra( "Your username can only contain numbers, characters, underscores and hyphens." );
} else {
// LOWER CASE all logins
$pParamHash['login'] = strtolower( $pParamHash['login'] );
@@ -303,7 +322,7 @@ class BitUser extends LibertyMime {
// LOWER CASE all emails
$pParamHash['email'] = strtolower( $pParamHash['email'] );
if( $emailResult = $this->verifyEmail( $pParamHash['email'] , $this->mErrors) ) {
- $pParamHash['verified_email'] = ($emailResult === true);
+ $pParamHash['verified_email'] = $emailResult === true;
}
}
// check some new user requirements
@@ -312,12 +331,12 @@ class BitUser extends LibertyMime {
// choose a login based on the username in the email
if( empty($pParamHash['email']) ){
// obviously if they didnt enter an email address we cant help them out
- $this->mErrors['email'] = tra( 'You must enter your email address' );
+ $this->mErrors['email'] = KernelTools::tra( 'You must enter your email address' );
}else{
$loginBase = preg_replace( '/[^A-Za-z0-9_]/', '', substr( $pParamHash['email'], 0, strpos( $pParamHash['email'], '@' ) ) );
$login = $loginBase;
do {
- if( $loginTaken = $this->userExists( array( 'login' => $login ) ) ) {
+ if( $loginTaken = $this->userExists( [ 'login' => $login ] ) ) {
$login = $loginBase.rand(100,999);
}
} while( $loginTaken );
@@ -332,14 +351,14 @@ class BitUser extends LibertyMime {
if( !empty( $pParamHash['email'] ) && empty($this->mErrors['email']) ) {
$pParamHash['user_store']['email'] = substr( $pParamHash['email'], 0, 200 ) ;
}elseif( empty($pParamHash['email']) ){
- $this->mErrors['email'] = tra( 'You must enter your email address' );
+ $this->mErrors['email'] = KernelTools::tra( 'You must enter your email address' );
}
if( $gBitSystem->isFeatureActive( 'users_validate_user' ) ) {
$pParamHash['user_store']['provpass'] = md5(BitSystem::genPass());
$pParamHash['pass_due'] = 0;
} elseif( empty( $pParamHash['password'] ) ) {
- $this->mErrors['password'] = tra( 'Your password should be at least '.$gBitSystem->getConfig( 'users_min_pass_length', 4 ).' characters long' );
+ $this->mErrors['password'] = KernelTools::tra( 'Your password should be at least '.$gBitSystem->getConfig( 'users_min_pass_length', 4 ).' characters long' );
}
} elseif( $this->isValid() ) {
// Prevent losing user info on save
@@ -350,7 +369,7 @@ class BitUser extends LibertyMime {
if( isset( $pParamHash['password'] ) ) {
if( isset( $pParamHash["password2"] ) && $pParamHash["password"] != $pParamHash["password2"] ) {
- $passwordErrors['password2'] = tra("The passwords didn't match");
+ $passwordErrors['password2'] = KernelTools::tra("The passwords didn't match");
}
if( ( !$this->isValid() || isset( $pParamHash['password'] ) ) && $error = $this->verifyPasswordFormat( $pParamHash['password'] ) ) {
$passwordErrors['password'] = $error;
@@ -366,10 +385,10 @@ class BitUser extends LibertyMime {
// if no pass_due and no user_pass_due value user will never have to update the password
if( empty( $pParamHash['pass_due'] ) && $gBitSystem->getConfig('users_pass_due') ) {
// renew password according to config value
- $pParamHash['user_store']['pass_due'] = $now + (60 * 60 * 24 * $gBitSystem->getConfig('users_pass_due') );
+ $pParamHash['user_store']['pass_due'] = $now + 60 * 60 * 24 * $gBitSystem->getConfig('users_pass_due');
} elseif( !empty( $pParamHash['pass_due'] ) ) {
// renew password only next half year ;)
- $pParamHash['user_store']['pass_due'] = $now + (60 * 60 * 24 * $pParamHash['pass_due']);
+ $pParamHash['user_store']['pass_due'] = $now + 60 * 60 * 24 * $pParamHash['pass_due'];
}
if( $gBitSystem->isFeatureActive( 'users_clear_passwords' ) || !empty( $pParamHash['user_store']['provpass'] ) ) {
$pParamHash['user_store']['user_password'] = $pParamHash['password'];
@@ -382,7 +401,7 @@ class BitUser extends LibertyMime {
parent::verify( $pParamHash );
}
- return ( count($this->mErrors) == 0 );
+ return count($this->mErrors) == 0;
}
/**
@@ -403,7 +422,7 @@ class BitUser extends LibertyMime {
}
if( $gBitSystem->isFeatureActive( 'users_register_recaptcha' ) && (empty( $pParamHash['novalidation'] ) || $pParamHash['novalidation'] != 'yes') ) {
- require_once( USERS_PKG_INCLUDE_PATH.'recaptchalib.php' );
+ require_once USERS_PKG_INCLUDE_PATH.'recaptchalib.php';
if( !empty( $pParamHash["recaptcha_challenge_field"] ) && !empty( $pParamHash["recaptcha_response_field"] ) ) {
$resp = recaptcha_check_answer ( $gBitSystem->getConfig( 'users_register_recaptcha_secret_key' ), $_SERVER["REMOTE_ADDR"], $pParamHash["recaptcha_challenge_field"], $pParamHash["recaptcha_response_field"] );
if( !$resp->is_valid ) {
@@ -414,29 +433,29 @@ class BitUser extends LibertyMime {
}
}
- if( $gBitSystem->isFeatureActive( 'users_register_cfcaptcha' ) && (empty( $pParamHash['novalidation'] ) || $pParamHash['novalidation'] != 'yes') ) {
- require_once( USERS_PKG_INCLUDE_PATH.'solvemedialib.php' );
+ if( $gBitSystem->isFeatureActive( 'users_register_smcaptcha' ) && (empty( $pParamHash['novalidation'] ) || $pParamHash['novalidation'] != 'yes') ) {
+ require_once USERS_PKG_INCLUDE_PATH.'solvemedialib.php';
if( !empty( $pParamHash['adcopy_challenge'] ) && !empty( $pParamHash['adcopy_response'] ) ) {
$solvemediaResponse = solvemedia_check_answer($gBitSystem->getConfig( 'users_register_smcaptcha_v_key' ), $_SERVER["REMOTE_ADDR"], $pParamHash["adcopy_challenge"], $pParamHash["adcopy_response"], $gBitSystem->getConfig( 'users_register_smcaptcha_h_key' ) );
if( !$solvemediaResponse->is_valid ) {
- $this->mErrors['cfcaptcha'] = $solvemediaResponse->error;
+ $this->mErrors['smcaptcha'] = $solvemediaResponse->error;
}
} else {
- $this->mErrors['cfcaptcha'] = 'Wrong Answer';
+ $this->mErrors['smcaptcha'] = 'Wrong Answer';
}
}
- return ( count($this->mErrors) == 0 );
+ return count($this->mErrors) == 0;
}
/**
* preRegisterVerify
*
* A collection of values to verify before a user can register
- * Separated from BitUser::verify so that import verification can
+ * Separated from RoleUser::verify so that import verification can
* be processed with less rigor than user submitted requests
*/
- function preRegisterVerify( &$pParamHash ) {
+ function preRegisterVerify( $pParamHash ) {
global $gBitSystem;
$this->answerCaptcha( $pParamHash );
@@ -447,42 +466,42 @@ class BitUser extends LibertyMime {
$this->mErrors['passcode'] = 'Wrong passcode! You need to know the passcode to register at this site';
}
}
- return ( count($this->mErrors) == 0 );
+ return count($this->mErrors) == 0;
}
/**
* verifyPasswordFormat
*
- * @param array $pPassword
- * @param array $pPassword2
+ * @param string $pPassword
+ * @param string $pPassword2
* @access public
- * @return FALSE on success, Error string on failure
+ * @return string|bool false on success, Error string on failure
*/
- function verifyPasswordFormat( $pPassword, $pPassword2=NULL ) {
+ function verifyPasswordFormat( $pPassword, $pPassword2=null ) {
global $gBitSystem;
$minPassword = $gBitSystem->getConfig( 'users_min_pass_length', 4 );
if( strlen( $pPassword ) < $minPassword ) {
- return ( tra( 'Your password should be at least '.$minPassword.' characters long' ));
+ return KernelTools::tra( 'Your password should be at least '.$minPassword.' characters long' );
}
if( !empty( $pPassword2 ) && $pPassword != $pPassword2 ) {
- return( tra( 'The passwords do not match' ));
+ return KernelTools::tra( 'The passwords do not match' );
}
if( $gBitSystem->isFeatureActive( 'users_pass_chr_num' ) && ( !preg_match_all( "/[0-9]+/",$pPassword,$foo ) || !preg_match_all( "/[A-Za-z]+/",$pPassword,$foo ))) {
- return ( tra( 'Password must contain both letters and numbers' ));
+ return KernelTools::tra( 'Password must contain both letters and numbers' );
}
- return FALSE;
+ return false;
}
/**
* getSmtpResponse
*
- * @param array $pConnect
+ * @param resource $pConnect
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return string on success, false on failure - mErrors will contain reason for failure
*/
- function getSmtpResponse( &$pConnect ) {
+ function getSmtpResponse( $pConnect ): string {
$out = "";
while( 1 ) {
$work = fgets( $pConnect, 1024 );
@@ -497,31 +516,31 @@ class BitUser extends LibertyMime {
/**
* verifyEmail
*
- * @param array $pEmail
- * @return TRUE on success, FALSE on failure, or -1 if verifyMX had a connection failure - mErrors will contain reason for failure
+ * @param string $pEmail
+ * @return bool true on success, false on failure, or -1 if verifyMX had a connection failure - mErrors will contain reason for failure
*/
public function verifyEmail( $pEmail , &$pErrors ) {
global $gBitSystem;
// check for existing user first, so root@localhost doesn't get attempted to re-register
- if( !empty( $this ) && is_object( $this ) && $this->userExists( array( 'email' => $pEmail ) ) ) {
+ if( !empty( $this ) && is_object( $this ) && $this->userExists( [ 'email' => $pEmail ] ) ) {
$pErrors['email'] = 'The email address "'.$pEmail.'" has already been registered.';
// during install we have some <user>@localhost as email address. we won't cause problems on those
} elseif( $pEmail == 'root@localhost' || $pEmail == 'guest@localhost' ) {
// nothing to do
- } elseif( !validate_email_syntax( $pEmail ) ) {
+ } elseif( !KernelTools::validate_email_syntax( $pEmail ) ) {
$pErrors['email'] = 'The email address "'.$pEmail.'" is invalid.';
} elseif( $gBitSystem->isFeatureActive( 'users_validate_email' ) ) {
- $mxErrors;
+ $mxErrors = [];
$ret = $this->verifyMX( $pEmail, $mxErrors ) ;
if ($ret === false) {
- bit_error_log('INVALID EMAIL : '.$pEmail.' by '. $_SERVER['REMOTE_ADDR'] .' for '. $mxErrors['email']);
+ \Bitweaver\bit_error_log('INVALID EMAIL : '.$pEmail.' by '. $_SERVER['REMOTE_ADDR'] .' for '. $mxErrors['email']);
$pErrors = array_merge( $pErrors, $mxErrors );
}
}
if( !isset( $ret ) ) {
- $ret = ( count( $pErrors ) == 0 ) ;
+ $ret = count( $pErrors ) == 0;
}
return $ret;
@@ -531,7 +550,7 @@ class BitUser extends LibertyMime {
* verifyAnonEmail
*
* @param array $pEmail
- * @return TRUE on success, FALSE on failure, or -1 if verifyMX had a connection failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure, or -1 if verifyMX had a connection failure - mErrors will contain reason for failure
*/
public static function verifyAnonEmail( $pEmail , &$pErrors ) {
global $gBitSystem;
@@ -539,12 +558,12 @@ class BitUser extends LibertyMime {
// check for existing user first, so root@localhost doesn't get attempted to re-register
if( $pEmail == 'root@localhost' || $pEmail == 'guest@localhost' ) {
// nothing to do
- } elseif( !validate_email_syntax( $pEmail ) ) {
+ } elseif( !KernelTools::validate_email_syntax( $pEmail ) ) {
$pErrors['email'] = 'The email address "'.$pEmail.'" is invalid.';
}
if( !isset( $ret ) ) {
- $ret = ( count( $pErrors ) == 0 ) ;
+ $ret = count( $pErrors ) == 0 ;
}
return $ret;
@@ -553,10 +572,10 @@ class BitUser extends LibertyMime {
/**
* verifyMX
*
- * @param array $pEmail
- * @param array $pValidate
+ * @param string $pEmail
+ * @param bool $pValidate
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function verifyMX( $pEmail, &$pErrors ) {
@@ -565,16 +584,16 @@ class BitUser extends LibertyMime {
$HTTP_HOST=$_SERVER['SERVER_NAME'];
$ret = false;
- if( validate_email_syntax( $pEmail ) ){
+ if( KernelTools::validate_email_syntax( $pEmail ) ){
list ( $Username, $domain ) = preg_split ("/@/",$pEmail);
//checkdnsrr will check to see if there are any MX records for the domain
- if( !is_windows() and checkdnsrr ( $domain, "MX" ) ) {
- bitdebug( "Confirmation : MX record for {$domain} exists." );
+ if( !KernelTools::is_windows() and checkdnsrr ( $domain, "MX" ) ) {
+ \Bitweaver\bitdebug( "Confirmation : MX record for {$domain} exists." );
- $MXWeights = array();
+ $MXWeights = [];
getmxrr ( $domain, $MXHost, $MXWeights );
- $hosts = array();
+ $hosts = [];
//create an array that combines the MXWeights with their associated hosts
for( $i = 0; $i < count( $MXHost ); $i++ ) {
@@ -592,7 +611,7 @@ class BitUser extends LibertyMime {
// Success in fsockopen
if( $Connect ) {
- bitdebug( "Connection succeeded to {$host} SMTP." );
+ \Bitweaver\bitdebug( "Connection succeeded to {$host} SMTP." );
stream_set_timeout( $Connect, 30 );
@@ -604,31 +623,31 @@ class BitUser extends LibertyMime {
if( $gBitSystem->hasValidSenderEmail() ) {
$senderEmail = $gBitSystem->getConfig( 'site_sender_email' );
fputs( $Connect, "HELO $HTTP_HOST\r\n" );
- bitdebug( "Run : HELO $HTTP_HOST" );
+ \Bitweaver\bitdebug( "Run : HELO $HTTP_HOST" );
// Receive server's answering cord.
$out = $this->getSmtpResponse( $Connect );
// Inform sender's address to server.
fputs ( $Connect, "MAIL FROM: <{$senderEmail}>\r\n" );
- bitdebug( "Run : MAIL FROM: &lt;{$senderEmail}&gt;" );
+ \Bitweaver\bitdebug( "Run : MAIL FROM: &lt;{$senderEmail}&gt;" );
// Receive server's answering cord.
$from = $this->getSmtpResponse( $Connect );
// Inform listener's address to server.
fputs ( $Connect, "RCPT TO: <{$pEmail}>\r\n" );
- bitdebug( "Run : RCPT TO: &lt;{$pEmail}&gt;" );
+ \Bitweaver\bitdebug( "Run : RCPT TO: &lt;{$pEmail}&gt;" );
// Receive server's answering cord.
$to = $this->getSmtpResponse( $Connect );
// Finish connection.
fputs( $Connect, "QUIT\r\n" );
- bitdebug( "Run : QUIT" );
+ \Bitweaver\bitdebug( "Run : QUIT" );
fclose( $Connect );
//Checks if we received a 250 OK from the server. If we did not, the server is telling us that this address is not a valid mailbox.
if( !preg_match ( "/^250/", $from ) || ( !preg_match ( "/^250/", $to ) && !preg_match( "/Please use your ISP relay/", $to ))) {
$pErrors['email'] = $pEmail." is not recognized by the mail server. Try double checking the address for typos." ;
- bit_error_log("INVALID EMAIL : ".$pEmail." SMTP FROM : ".$from." SMTP TO: ".$to);
+ \Bitweaver\bit_error_log("INVALID EMAIL : ".$pEmail." SMTP FROM : ".$from." SMTP TO: ".$to);
$ret = false;
break; //break out of foreach and fall through to the end of function
}else{
@@ -638,11 +657,11 @@ class BitUser extends LibertyMime {
}
} elseif( preg_match ( "/^420/", $out ) ) {
// Yahoo has a bad, bad habit of issuing 420's
- bit_error_log("UNKNOWN EMAIL : ".$pEmail." SMTP response: ".$out);
+ \Bitweaver\bit_error_log("UNKNOWN EMAIL : ".$pEmail." SMTP response: ".$out);
$ret = true;
} else {
$pErrors['email'] = 'Connection rejected by MX server';
- bit_error_log("INVALID EMAIL : ".$pEmail." SMTP response: ".$out);
+ \Bitweaver\bit_error_log("INVALID EMAIL : ".$pEmail." SMTP response: ".$out);
$ret = false;
}
} else {
@@ -673,13 +692,13 @@ class BitUser extends LibertyMime {
*
* @access public
* @author Christian Fowler<spider@viovio.com>
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
- function register( &$pParamHash, $pNotifyRegistrant=TRUE ) {
+ public function register( &$pParamHash, $pNotifyRegistrant=true ): bool {
global $notificationlib, $gBitSmarty, $gBitSystem;
- $ret = FALSE;
+ $ret = false;
if( !empty( $_FILES['user_portrait_file'] ) && empty( $_FILES['user_avatar_file'] ) ) {
- $pParamHash['user_auto_avatar'] = TRUE;
+ $pParamHash['user_auto_avatar'] = true;
}
if( $this->verify( $pParamHash )) {
for( $i = 0; $i < BaseAuth::getAuthMethodCount(); $i++ ) {
@@ -690,7 +709,7 @@ class BitUser extends LibertyMime {
break;
} else {
$this->mErrors = array_merge( $this->mErrors, $instance->mErrors );
- return FALSE;
+ return false;
}
}
}
@@ -700,11 +719,11 @@ class BitUser extends LibertyMime {
}
$this->mLogs['register'] = 'New user registered.';
- $ret = TRUE;
+ $ret = true;
- $this->load( FALSE, $pParamHash['login'] );
+ $this->load( false, $pParamHash['login'] );
- require_once( KERNEL_PKG_INCLUDE_PATH.'notification_lib.php' );
+ require_once KERNEL_PKG_INCLUDE_PATH.'notification_lib.php';
$notificationlib->post_new_user_event( $pParamHash['login'] );
// set local time zone as default when registering
@@ -734,15 +753,15 @@ class BitUser extends LibertyMime {
$apass = $pParamHash['user_store']['provpass'];
$foo = parse_url( $_SERVER["REQUEST_URI"] );
$foo1 = str_replace( "register", "confirm", $foo["path"] );
- $machine = httpPrefix().$foo1;
+ $machine = KernelTools::httpPrefix().$foo1;
// Send the mail
- $gBitSmarty->assign( 'msg',tra( 'You will receive an email with information to login for the first time into this site' ));
+ $gBitSmarty->assign( 'msg',KernelTools::tra( 'You will receive an email with information to login for the first time into this site' ));
$gBitSmarty->assign( 'mail_machine',$machine );
$gBitSmarty->assign( 'mailUserId',$this->mUserId );
$gBitSmarty->assign( 'mailProvPass',$apass );
$mail_data = $gBitSmarty->fetch( 'bitpackage:users/user_validation_mail.tpl' );
- mail( $pParamHash["email"], $siteName.' - '.tra( 'Your registration information' ), $mail_data, "From: ".$gBitSystem->getConfig('site_sender_email')."\nContent-type: text/plain;charset=utf-8\n" );
+ mail( $pParamHash["email"], $siteName.' - '.KernelTools::tra( 'Your registration information' ), $mail_data, "From: ".$gBitSystem->getConfig('site_sender_email')."\nContent-type: text/plain;charset=utf-8\n" );
$gBitSmarty->assign( 'showmsg', 'y' );
$this->mLogs['confirm'] = 'Validation email sent.';
@@ -751,7 +770,7 @@ class BitUser extends LibertyMime {
$gBitSmarty->assign( 'mailPassword',$pParamHash['password'] );
$gBitSmarty->assign( 'mailEmail',$pParamHash['email'] );
$mail_data = $gBitSmarty->fetch( 'bitpackage:users/welcome_mail.tpl' );
- mail( $pParamHash["email"], tra( 'Welcome to' ).' '.$siteName, $mail_data, "From: ".$gBitSystem->getConfig( 'site_sender_email' )."\nContent-type: text/plain;charset=utf-8\n" );
+ mail( $pParamHash["email"], KernelTools::tra( 'Welcome to' ).' '.$siteName, $mail_data, "From: ".$gBitSystem->getConfig( 'site_sender_email' )."\nContent-type: text/plain;charset=utf-8\n" );
$this->mLogs['welcome'] = 'Welcome email sent.';
}
@@ -759,25 +778,25 @@ class BitUser extends LibertyMime {
$logHash['action_log']['title'] = $pParamHash['login'];
$this->storeActionLog( $logHash );
}
- return( $ret );
+ return $ret;
}
/**
* verifyCaptcha
*
- * @param array $pCaptcha
+ * @param string $pCaptcha
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
- function verifyCaptcha( $pCaptcha = NULL ) {
- if( $this->hasPermission( 'p_users_bypass_captcha' ) || ( !empty( $_SESSION['captcha_verified'] ) && $_SESSION['captcha_verified'] === TRUE ) ) {
- return TRUE;
+ public function verifyCaptcha( $pCaptcha = null ) {
+ if( $this->hasPermission( 'p_users_bypass_captcha' ) || ( !empty( $_SESSION['captcha_verified'] ) && $_SESSION['captcha_verified'] === true ) ) {
+ return true;
} else {
if( empty( $pCaptcha ) || empty( $_SESSION['captcha'] ) || $_SESSION['captcha'] != md5( $pCaptcha ) ) {
- return FALSE;
+ return false;
} else {
- $_SESSION['captcha_verified'] = TRUE;
- return TRUE;
+ $_SESSION['captcha_verified'] = true;
+ return true;
}
}
}
@@ -787,10 +806,9 @@ class BitUser extends LibertyMime {
* store
*
* @param array $pParamHash
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function store( &$pParamHash ) {
+ public function store( array &$pParamHash): bool {
if( $this->verify( $pParamHash ) ) {
$this->StartTrans();
$pParamHash['content_type_guid'] = BITUSER_CONTENT_TYPE_GUID;
@@ -811,21 +829,21 @@ class BitUser extends LibertyMime {
// Prevent liberty from assuming ANONYMOUS_USER_ID while storing
$pParamHash['user_id'] = $this->mUserId;
// Don't let LA snarf these now so we can do extra things.
- $pParamHash['_files_override'] = array();
- if( LibertyMime::store( $pParamHash ) ) {
+ $pParamHash['_files_override'] = [];
+ if( \Bitweaver\Liberty\LibertyMime::store( $pParamHash ) ) {
if( empty( $this->mInfo['content_id'] ) || ($pParamHash['content_id'] != $this->mInfo['content_id']) ) {
$query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `content_id`=? WHERE `user_id`=?";
- $result = $this->mDb->query( $query, array( $pParamHash['content_id'], $this->mUserId ) );
+ $result = $this->mDb->query( $query, [ $pParamHash['content_id'], $this->mUserId ] );
$this->mInfo['content_id'] = $pParamHash['content_id'];
}
}
$this->CompleteTrans();
- $this->load( TRUE );
+ $this->load( true );
}
- return( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
@@ -833,13 +851,13 @@ class BitUser extends LibertyMime {
* This is a admin specific function
*
* @param $pParamHash an array with user data
- * @return TRUE if import succeed
+ * @return bool true if import succeed
**/
function importUser( &$pParamHash ) {
global $gBitUser;
if( ! $gBitUser->hasPermission( 'p_users_admin' ) ) {
- return FALSE;
+ return false;
}
if( $this->verifyUserImport( $pParamHash ) ) {
$this->StartTrans();
@@ -871,7 +889,7 @@ class BitUser extends LibertyMime {
if( LibertyContent::store( $pParamHash )) {
if( empty( $this->mInfo['content_id'] ) || $pParamHash['content_id'] != $this->mInfo['content_id'] ) {
$query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `content_id`=? WHERE `user_id`=?";
- $result = $this->mDb->query( $query, array( $pParamHash['content_id'], $this->mUserId ) );
+ $result = $this->mDb->query( $query, [ $pParamHash['content_id'], $this->mUserId ] );
$this->mInfo['content_id'] = $pParamHash['content_id'];
}
}
@@ -881,9 +899,9 @@ class BitUser extends LibertyMime {
// store any uploaded images
$this->storeImages( $pParamHash );
- $this->load( TRUE );
+ $this->load( true );
}
- return( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
@@ -892,28 +910,28 @@ class BitUser extends LibertyMime {
* This is a admin specific function
*
* @param $pParamHash an array with user data
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
**/
function verifyUserImport( &$pParamHash ) {
global $gBitSystem, $gBitUser;
if( ! $gBitUser->hasPermission( 'p_users_admin' ) ) {
- return FALSE;
+ return false;
}
- trim_array( $pParamHash );
+ KernelTools::trim_array( $pParamHash );
// perhaps someone is importing users and *knows* what they are doing
if( @$this->verifyId( $pParamHash['user_id'] ) ) {
// only import user_id if it doesn't exist or overwrite is set.
- if( !$this->userExists( array( 'user_id' => $pParamHash['user_id'] ) ) || !empty( $_REQUEST['overwrite'] ) ) {
+ if( !$this->userExists( [ 'user_id' => $pParamHash['user_id'] ] ) || !empty( $_REQUEST['overwrite'] ) ) {
$pParamHash['user_store']['user_id'] = $pParamHash['user_id'];
} else {
unset( $pParamHash['user_id'] );
}
}
if( !empty( $pParamHash['login'] ) ) {
- $ret = $this->userExists( array( 'login' => $pParamHash['login'] ) );
+ $ret = $this->userExists( [ 'login' => $pParamHash['login'] ] );
if( !empty( $ret ) ) {
// On batch import admin can overwrite existing user, so don't error if set
// however, prevent overwrite of a mix of user records
@@ -924,7 +942,7 @@ class BitUser extends LibertyMime {
$this->mErrors['login'] = 'The username "'.$pParamHash['login'].'" is already in use';
}
} elseif( preg_match( '/[^A-Za-z0-9_.-]/', $pParamHash["login"] ) ) {
- $this->mErrors['login'] = tra( "Your username can only contain numbers, characters, underscores and hyphens." );
+ $this->mErrors['login'] = KernelTools::tra( "Your username can only contain numbers, characters, underscores and hyphens." );
}
if( !isset($this->mErrors['login']) ) {
@@ -941,8 +959,8 @@ class BitUser extends LibertyMime {
if( !empty( $pParamHash['email'] ) ) {
// LOWER CASE all emails admin_verify_email
$pParamHash['email'] = strtolower( $pParamHash['email'] );
- if( validate_email_syntax( $pParamHash['email'] ) ) {
- $ret = $this->userExists( array( 'email' => $pParamHash['email'] ) );
+ if( KernelTools::validate_email_syntax( $pParamHash['email'] ) ) {
+ $ret = $this->userExists( [ 'email' => $pParamHash['email'] ] );
if( !empty($ret) ) {
if( !empty( $_REQUEST['overwrite'] ) && (!isset($pParamHash['user_store']['user_id']) || $pParamHash['user_store']['user_id'] == $ret ) ) {
$pParamHash['user_id'] = $ret;
@@ -952,7 +970,7 @@ class BitUser extends LibertyMime {
}
}
if( !empty( $_REQUEST['admin_verify_email'] ) ) {
- if( !$this->verifyMX( $pParamHash['email'] ) ) {
+ if( !$this->verifyMX( (string) $pParamHash['email'], $mxErrors ) ) {
$this->mErrors['email'] = 'Cannot find a valid mail server';
}
}
@@ -963,13 +981,13 @@ class BitUser extends LibertyMime {
$this->mErrors['email'] = 'The email address "'.$pParamHash['email'].'" has an invalid syntax.';
}
} else {
- $this->mErrors['email'] = tra( 'You must enter your email address' );
+ $this->mErrors['email'] = KernelTools::tra( 'You must enter your email address' );
}
// check some new user requirements
if( !$this->isRegistered() ) {
if( isset($pParamHash['user_store']['user_id']) && !empty( $_REQUEST['overwrite'] ) ) {
- $this->mUserId = $this->userExists( array( 'user_id' => $pParamHash['user_store']['user_id'] ) );
+ $this->mUserId = $this->userExists( [ 'user_id' => $pParamHash['user_store']['user_id'] ] );
}
if( empty( $pParamHash['registration_date'] ) ) {
$pParamHash['registration_date'] = date( "U" );
@@ -979,9 +997,9 @@ class BitUser extends LibertyMime {
if( !empty($pParamHash['hash'] ) ) {
unset( $pParamHash['password'] );
if($gBitSystem->isFeatureActive( 'users_clear_passwords' ) ) {
- $this->mErrors['password'] = tra( 'You cannot import a password hash when setting to stor password in plan text is set.' );
+ $this->mErrors['password'] = KernelTools::tra( 'You cannot import a password hash when setting to stor password in plan text is set.' );
} elseif( strlen( $pParamHash['hash'] ) <> 32 ) {
- $this->mErrors['password'] = tra( 'When importing a MD5 password hash it needto have a length of 32 bytes.' );
+ $this->mErrors['password'] = KernelTools::tra( 'When importing a MD5 password hash it needto have a length of 32 bytes.' );
}
} else {
if( !empty( $_REQUEST['admin_verify_user'] ) ) {
@@ -1012,43 +1030,39 @@ class BitUser extends LibertyMime {
$pParamHash['user_store']['hash'] = md5( $pParamHash['password'] );
$now = $gBitSystem->getUTCTime();
if( !isset( $pParamHash['pass_due'] ) && $gBitSystem->getConfig('users_pass_due') ) {
- $pParamHash['user_store']['pass_due'] = $now + (60 * 60 * 24 * $gBitSystem->getConfig('users_pass_due') );
+ $pParamHash['user_store']['pass_due'] = $now + 60 * 60 * 24 * $gBitSystem->getConfig('users_pass_due');
} elseif( isset( $pParamHash['pass_due'] ) ) {
// renew password only next half year ;)
- $pParamHash['user_store']['pass_due'] = $now + (60 * 60 * 24 * $pParamHash['pass_due']);
+ $pParamHash['user_store']['pass_due'] = $now + 60 * 60 * 24 * $pParamHash['pass_due'];
}
- if( $gBitSystem->isFeatureActive( 'users_clear_passwords' ) ) {
- $pParamHash['user_store']['user_password'] = $pParamHash['password'];
- } else {
- $pParamHash['user_store']['user_password'] = '';
+ $pParamHash['user_store']['user_password'] = ($gBitSystem->isFeatureActive( 'users_clear_passwords' )) ? $pParamHash['password'] : '';
+ if ( !empty( $pParamHash['hash'] )) $pParamHash['user_store']['hash'] = $pParamHash['hash'];
+ $now = $gBitSystem->getUTCTime();
+ if( !isset( $pParamHash['pass_due'] ) && $gBitSystem->getConfig( 'users_pass_due' )) {
+ $pParamHash['user_store']['pass_due'] = $now + 60 * 60 * 24 * $gBitSystem->getConfig( 'users_pass_due' );
+ } elseif( isset( $pParamHash['pass_due'] ) ) {
+ // renew password only next half year ;)
+ $pParamHash['user_store']['pass_due'] = $now + 60 * 60 * 24 * $pParamHash['pass_due'];
}
}
- } elseif( !empty( $pParamHash['hash'] )) {
- $pParamHash['user_store']['hash'] = $pParamHash['hash'];
- $now = $gBitSystem->getUTCTime();
- if( !isset( $pParamHash['pass_due'] ) && $gBitSystem->getConfig( 'users_pass_due' )) {
- $pParamHash['user_store']['pass_due'] = $now + ( 60 * 60 * 24 * $gBitSystem->getConfig( 'users_pass_due' ));
- } elseif( isset( $pParamHash['pass_due'] ) ) {
- // renew password only next half year ;)
- $pParamHash['user_store']['pass_due'] = $now + ( 60 * 60 * 24 * $pParamHash['pass_due'] );
- }
}
- return ( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
* expunge removes user and associated private data
*
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool
+ * $this->$pExpungeContent no longer passed in function for compatability with base expunge
*/
- function expunge( $pExpungeContent = NULL ) {
+ public function expunge(): bool {
global $gBitSystem;
$this->StartTrans();
- if( !empty( $pExpungeContent ) ) {
- if( $pExpungeContent == 'all' ) {
- if( $userContent = $this->mDb->getAssoc( "SELECT content_id, content_type_guid FROM `".BIT_DB_PREFIX."liberty_content` WHERE `user_id`=? AND `content_type_guid` != 'bituser'", array( $this->mUserId ) ) ) {
+ if( $this->pExpungeContent != 'none' ) {
+ if( $this->pExpungeContent == 'all' ) {
+ if( $userContent = $this->mDb->getAssoc( "SELECT content_id, content_type_guid FROM `".BIT_DB_PREFIX."liberty_content` WHERE `user_id`=? AND `content_type_guid` != 'bituser'", [ $this->mUserId ] ) ) {
foreach( $userContent as $contentId=>$contentTypeGuid ) {
if( $delContent = LibertyBase::getLibertyObject( $contentId, $contentTypeGuid ) ) {
$delContent->expunge();
@@ -1063,15 +1077,15 @@ class BitUser extends LibertyMime {
$this->purgeImage( 'portrait' );
$this->purgeImage( 'logo' );
$this->invokeServices( 'users_expunge_function' );
- $userTables = array(
+ $userTables = [
'users_cnxn',
'users_watches',
'users_favorites_map',
'users_users',
- );
+ ];
foreach( $userTables as $table ) {
$query = "DELETE FROM `".BIT_DB_PREFIX.$table."` WHERE `user_id` = ?";
- $result = $this->mDb->query( $query, array( $this->mUserId ) );
+ $result = $this->mDb->query( $query, [ $this->mUserId ] );
}
parent::expunge();
@@ -1080,20 +1094,20 @@ class BitUser extends LibertyMime {
$this->mLogs['user_del'] = 'User deleted';
$this->storeActionLog( $logHash );
$this->CompleteTrans();
- return TRUE;
} else {
$this->mDb->RollbackTrans();
- $gBitSystem->fatalError( tra( 'The anonymous user cannot be deleted' ) );
+ $gBitSystem->fatalError( KernelTools::tra( 'The anonymous user cannot be deleted' ) );
}
+ return true;
}
// {{{ ==================== Sessions and logging in and out methods ====================
/**
* updateSession
*
- * @param array $pSessionId
+ * @param string $pSessionId
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function updateSession( $pSessionId ) {
global $gLightWeightScan;
@@ -1103,7 +1117,7 @@ class BitUser extends LibertyMime {
$update['current_view'] = $_SERVER['SCRIPT_NAME'];
if( empty( $gLightWeightScan ) ) {
- $row = $this->mDb->getRow( "SELECT `last_get`, `connect_time`, `get_count`, `user_agent`, `current_view` FROM `".BIT_DB_PREFIX."users_cnxn` WHERE `cookie`=? ", array( $pSessionId ) );
+ $row = $this->mDb->getRow( "SELECT `last_get`, `connect_time`, `get_count`, `user_agent`, `current_view` FROM `".BIT_DB_PREFIX."users_cnxn` WHERE `cookie`=? ", [ $pSessionId ] );
if( $gBitUser->isRegistered() ) {
$update['user_id'] = $gBitUser->mUserId;
}
@@ -1115,7 +1129,7 @@ class BitUser extends LibertyMime {
$update['user_agent'] = (string)substr( $_SERVER['HTTP_USER_AGENT'], 0, 128 );
}
$update['get_count'] = $row['get_count'] + 1;
- $ret = $this->mDb->associateUpdate( BIT_DB_PREFIX.'users_cnxn', $update, array( 'cookie' => $pSessionId ) );
+ $ret = $this->mDb->associateUpdate( BIT_DB_PREFIX.'users_cnxn', $update, [ 'cookie' => $pSessionId ] );
} else {
if( $this->isRegistered() ) {
$update['user_id'] = $this->mUserId;
@@ -1132,9 +1146,9 @@ class BitUser extends LibertyMime {
// This needs moving to an event that is known to happen
if( date( 'H' ) == '03' && date( 'i' ) > 0 && date( 'i' ) < 2 ) {
// Default to 30 days history
- $oldy = $update['last_get'] - ($gBitSystem->getConfig( 'users_cnxn_history_days', 30 ) * 24 * 60 * 60);
+ $oldy = $update['last_get'] - $gBitSystem->getConfig( 'users_cnxn_history_days', 30 ) * 24 * 60 * 60;
$query = "DELETE from `".BIT_DB_PREFIX."users_cnxn` where `connect_time` < ?";
- $result = $this->mDb->query($query, array($oldy));
+ $result = $this->mDb->query($query, [ $oldy ]);
}
}
return true;
@@ -1145,14 +1159,14 @@ class BitUser extends LibertyMime {
*
* @param array $pActive
* @access public
- * @return count of sessions
+ * @return int count of sessions
*/
- function countSessions( $pActive = FALSE ) {
+ function countSessions( $pActive = false ) {
$query = "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."users_cnxn`";
if( $pActive ) {
- $query .=" WHERE `cookie` IS NOT NULL";
+ $query .=" WHERE `cookie` IS NOT null";
}
- return $this->mDb->getOne( $query,array() );
+ return $this->mDb->getOne( $query,[] );
}
/**
@@ -1161,32 +1175,32 @@ class BitUser extends LibertyMime {
* @access public
* @return void
*/
- function logout() {
+ public function logout() {
// This must come first
$this->clearFromCache();
- $this->sendSessionCookie( FALSE );
+ $this->sendSessionCookie( false );
session_destroy();
- $this->mUserId = NULL;
+ $this->mUserId = null;
// ensure Guest default page is loaded if required
$this->mInfo['default_role_id'] = -1;
}
- function sendSessionCookie( $pCookie=TRUE ) {
+ public function sendSessionCookie( $pCookie=true ) {
global $gBitSystem;
$siteCookie = static::getSiteCookieName();
$cookieTime = 0;
$cookiePath = BIT_ROOT_URL;
- $cookieDomain = '';
+ $cookieDomain = parse_url(BIT_ROOT_URL, PHP_URL_HOST);
- if( $pCookie === TRUE ) {
+ if( $pCookie === true ) {
$pCookie = session_id();
- } elseif( $pCookie==FALSE ) {
+ } elseif( $pCookie==false ) {
$pCookie = ''; // unset the cookie, eg logout
if( !empty( $_COOKIE[$siteCookie] ) ) {
- $this->mDb->query( "UPDATE `".BIT_DB_PREFIX."users_cnxn` SET `cookie`=NULL WHERE `cookie`=?", array( $_COOKIE[$siteCookie] ) );
+ $this->mDb->query( "UPDATE `".BIT_DB_PREFIX."users_cnxn` SET `cookie`=null WHERE `cookie`=?", [ $_COOKIE[$siteCookie] ] );
unset( $_COOKIE[$siteCookie] );
}
}
@@ -1196,10 +1210,17 @@ class BitUser extends LibertyMime {
if( $gBitSystem->isFeatureActive( 'users_remember_me' ) && isset( $_REQUEST['rme'] ) && $_REQUEST['rme'] == 'on' ) {
$cookieTime = (int)( time() + (int)$gBitSystem->getConfig( 'users_remember_time', 86400 ));
$cookiePath = $gBitSystem->getConfig( 'cookie_path', $cookiePath );
- $cookieDomain = $gBitSystem->getConfig( 'cookie_domain', $cookieDomain );
+ $cookieDomain = $gBitSystem->getConfig( 'cookie_domain', $cookieDomain, parse_url(BIT_ROOT_URL, PHP_URL_HOST) );
}
}
- setcookie( $siteCookie, $pCookie, $cookieTime , $cookiePath, $cookieDomain );
+ setcookie( $siteCookie, $pCookie, [
+ 'expires' => $cookieTime,
+ 'path' => $cookiePath,
+ 'domain' => $cookieDomain,
+ 'secure' => true,
+ 'httponly' => true,
+ 'samesite' => 'Strict'
+ ] );
$_COOKIE[$siteCookie] = $pCookie;
}
@@ -1207,7 +1228,7 @@ class BitUser extends LibertyMime {
global $gBitSystem;
$cookie_site = strtolower( preg_replace( "/[^a-zA-Z0-9]/", "", $gBitSystem->getConfig( 'site_title', 'bitweaver' )));
- return( 'bit-user-'.$cookie_site );
+ return 'bit-user-'.$cookie_site;
}
/**
@@ -1216,49 +1237,72 @@ class BitUser extends LibertyMime {
* @param array $pFatalOnError
* @param array $pForceCheck
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function verifyTicket( $pFatalOnError=TRUE, $pForceCheck=TRUE ) {
+ public function verifyTicket( $pFatalOnError=true, $pForceCheck=true ) {
global $gBitSystem, $gBitUser;
- $ret = FALSE;
- if( $pForceCheck == TRUE || !empty( $_REQUEST['tk'] ) ) {
+ $ret = false;
+ if( $pForceCheck == true || !empty( $_REQUEST['tk'] ) ) {
if( empty( $_REQUEST['tk'] ) || (!($ret = $_REQUEST['tk'] == $this->mTicket ) && $pFatalOnError) ) {
$userString = $gBitUser->isRegistered() ? "\nUSER ID: ".$gBitUser->mUserId.' ( '.$gBitUser->getField( 'email' ).' ) ' : '';
- error_log( tra( "Security Violation" )."$userString ".$_SERVER['REMOTE_ADDR']."\nURI: $_SERVER[REQUEST_URI] \nREFERER: $_SERVER[HTTP_REFERER] " );
- $gBitSystem->fatalError( tra( "Security Violation" ));
+ error_log( KernelTools::tra( "Security Violation" )."$userString ".$_SERVER['REMOTE_ADDR']."\nURI: $_SERVER[REQUEST_URI] \nREFERER: $_SERVER[HTTP_REFERER] " );
+ $gBitSystem->fatalError( KernelTools::tra( "Security Violation" ));
}
}
return $ret;
}
// }}}
+ public function getPostLoginUrl() {
+ global $gBitSystem;
+ $url = BIT_ROOT_URL;
+ if( $this->isRegistered() ) {
+ // set post-login url
+ // if group home is set for this user we get that
+ // default to general post-login
+ // @see \Bitweaver\BitSystem::getIndexPage
+ $indexType = 'my_page';
+ // getGroupHome is BitPermUser method
+ if( method_exists( $this, 'getGroupHome' ) &&
+ (( @$this->verifyId( $this->mInfo['default_group_id'] ) && ( $group_home = $this->getGroupHome( $this->mInfo['default_group_id'] ) ) ) ||
+ ( $gBitSystem->getConfig( 'default_home_group' ) && ( $group_home = $this->getGroupHome( $gBitSystem->getConfig( 'default_home_group' ) ) ) )) ){
+ $indexType = 'group_home';
+ }
+
+ $url = isset($_SESSION['loginfrom']) ? $_SESSION['loginfrom'] : $gBitSystem->getIndexPage( $indexType );
+ unset( $_SESSION['loginfrom'] );
+ }
+ return $url;
+ }
+
// {{{ ==================== Banning ====================
/**
* ban sets the user account status to -201 suspended
*
* @access public
- * @return TRUE on success, Display error message on failure
+ * @return bool true on success, Display error message on failure
*/
- function ban(){
+ public function ban(){
global $gBitSystem;
if( $this->mUserId == ANONYMOUS_USER_ID || $this->mUserId == ROOT_USER_ID || $this->isAdmin()) {
- $gBitSystem->fatalError( tra( 'You cannot ban the user' )." ".$this->mInfo['login'] );
+ $gBitSystem->fatalError( KernelTools::tra( 'You cannot ban the user' )." ".$this->mInfo['login'] );
} else {
$this->storeStatus( -201 );
- return TRUE;
+ return true;
}
+ return false;
}
/**
* ban unban the user
*
* @access public
- * @return TRUE on success
+ * @return bool true on success
*/
- function unban(){
+ public function unban(){
global $gBitSystem;
$this->storeStatus( 50 );
- return TRUE;
+ return true;
}
// }}}
@@ -1267,9 +1311,9 @@ class BitUser extends LibertyMime {
*
* @param array $pLength Length of final password
* @access public
- * @return password
+ * @return string password
*/
- function genPass( $pLength=NULL ) {
+ public function genPass( $pLength=null ) {
global $gBitSystem;
$vocales = "AaEeIiOoUu13580";
$consonantes = "BbCcDdFfGgHhJjKkLlMmNnPpQqRrSsTtVvWwXxYyZz24679";
@@ -1279,9 +1323,9 @@ class BitUser extends LibertyMime {
}
for( $i = 0; $i < $pLength; $i++ ) {
if( $i % 2 ) {
- $ret .= $vocales{rand( 0, strlen( $vocales ) - 1 )};
+ $ret .= $vocales[rand( 0, strlen( $vocales ) - 1 )];
} else {
- $ret .= $consonantes{rand( 0, strlen( $consonantes ) - 1 )};
+ $ret .= $consonantes[rand( 0, strlen( $consonantes ) - 1 )];
}
}
return $ret;
@@ -1291,23 +1335,23 @@ class BitUser extends LibertyMime {
* generateChallenge
*
* @access public
- * @return md5 string
+ * @return string md5
*/
- function generateChallenge() {
- return( md5( BitSystem::genPass() ));
+ public function generateChallenge() {
+ return md5( BitSystem::genPass() );
}
/**
* login
*
- * @param array $pLogin
- * @param array $pPassword
- * @param array $pChallenge
- * @param array $pResponse
+ * @param int $pLogin
+ * @param string $pPassword
+ * @param string $pChallenge
+ * @param string $pResponse
* @access public
- * @return URL the user should be sent to after login
+ * @return string URL the user should be sent to after login
*/
- function login( $pLogin, $pPassword, $pChallenge=NULL, $pResponse=NULL ) {
+ public function login( $pLogin, $pPassword, $pChallenge=null, $pResponse=null ) {
global $gBitSystem;
$isvalid = false;
@@ -1316,7 +1360,7 @@ class BitUser extends LibertyMime {
$this->StartTrans();
// Verify user is valid
if( $this->validate( $pLogin, $pPassword, $pChallenge, $pResponse )) {
- $userInfo = $this->getUserInfo( array( $loginCol => $pLogin ));
+ $userInfo = $this->getUserInfo( [ $loginCol => $pLogin ]);
// If the password is valid but it is due then force the user to change the password by
// sending the user to the new password change screen without letting him use
@@ -1331,21 +1375,21 @@ class BitUser extends LibertyMime {
// User is valid and not due to change pass..
$this->mUserId = $userInfo['user_id'];
$this->load();
- $this->loadPermissions( TRUE );
+ $this->loadPermissions( true );
// set post-login url
// if role home is set for this user we get that
// default to general post-login
- // @see BitSystem::getIndexPage
+ // @see \Bitweaver\BitSystem::getIndexPage
$indexType = 'my_page';
// getHomeRole is RolePermUser method
if( method_exists( $this, 'getHomeRole' ) &&
(( @$this->verifyId( $this->mInfo['default_role_id'] ) && ( $role_home = $this->getHomeRole( $this->mInfo['default_role_id'] ) ) ) ||
- ( $gBitSystem->getConfig( 'default_home_role' ) && ( $role_home = $this->getHomeRole( $gBitSystem->getConfig( 'default_home_role' ) ) ) )) ){
+ ( $gBitSystem->getConfig( 'default_home_role' ) && ( $role_home = $this->getRoleHome( $gBitSystem->getConfig( 'default_home_role' ) ) ) )) ){
$indexType = 'role_home';
}
- $url = isset($_SESSION['loginfrom']) ? $_SESSION['loginfrom'] : $gBitSystem->getIndexPage( $indexType );
+ $url = $_SESSION['loginfrom'] ?? $gBitSystem->getIndexPage( $indexType );
unset( $_SESSION['loginfrom'] );
$sessionId = session_id();
@@ -1355,14 +1399,14 @@ class BitUser extends LibertyMime {
} else {
// before we give up lets see if the user exists and if the password is expired
$query = "select `email`, `user_id`, `user_password` from `".BIT_DB_PREFIX."users_users` where " . $this->mDb->convertBinary(). " $loginCol = ?";
- $result = $this->mDb->getRow( $query, array( $pLogin ) );
+ $result = $this->mDb->getRow( $query, [ $pLogin ] );
if( !empty( $result['user_id'] ) && $this->isPasswordDue( $result['user_id'] ) ) {
// user needs email password reset so send it and let them know
$url = USERS_PKG_URL.'remind_password.php?remind=y&required=y&username='.$pLogin;
}else{
$this->mUserId = ANONYMOUS_USER_ID;
unset( $this->mInfo );
- $this->mErrors['login'] = tra( 'Invalid username or password' );
+ $this->mErrors['login'] = KernelTools::tra( 'Invalid username or password' );
$url = USERS_PKG_URL.'signin.php?error=' . urlencode( $this->mErrors['login'] );
}
}
@@ -1388,25 +1432,25 @@ class BitUser extends LibertyMime {
$url = $prefix.$url;
}
}
- return( $url );
+ return $url;
}
/**
* validate
*
- * @param array $pUser
- * @param array $pPass
- * @param array $pChallenge
- * @param array $pResponse
+ * @param int $pUser
+ * @param string $pPass
+ * @param string $pChallenge
+ * @param string $pResponse
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
* @todo rewrite this mess. this is horrible stuff. - xing - Thursday Oct 16, 2008 09:47:20 CEST
*/
- function validate( $pUser, $pPass, $pChallenge, $pResponse ) {
+ public function validate( $pUser, $pPass, $pChallenge, $pResponse ) {
global $gBitSystem;
// these will help us keep tabs of what is going on
- $authValid = $authPresent = FALSE;
- $createAuth = ( $gBitSystem->getConfig( "users_create_user_auth", "n" ) == "y" );
+ $authValid = $authPresent = false;
+ $createAuth = $gBitSystem->getConfig( "users_create_user_auth", "n" ) == "y";
for( $i = 0; $i < BaseAuth::getAuthMethodCount(); $i++ ) {
$instance = BaseAuth::init( $i );
@@ -1415,14 +1459,14 @@ class BitUser extends LibertyMime {
switch( $result ) {
case USER_VALID:
unset($this->mErrors['login']);
- $authPresent = TRUE;
- $authValid = TRUE;
+ $authPresent = true;
+ $authValid = true;
break;
case PASSWORD_INCORRECT:
// this mErrors assignment is CRUCIAL so that bit auth fails properly. DO NOT FUCK WITH THIS unless you know what you are doing and have checked with me first. XOXOX - spiderr
// This might have broken other auth, but at this point, bw auth was TOTALLY busted. If you need to fix, please come find me.
$this->mErrors['login'] = 'Password incorrect';
- $authPresent = TRUE;
+ $authPresent = true;
break;
case USER_NOT_FOUND:
break;
@@ -1438,36 +1482,36 @@ class BitUser extends LibertyMime {
$this->mUserId = $instance->mInfo['user_id'];
//Is the user already in the database:
- } elseif( $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."users_users` WHERE `login` = ?", array( $instance->mLogin )) > 0 ) {
+ } elseif ( $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."users_users` WHERE `login` = ?", [ $instance->mLogin ]) > 0 ) {
// Update Details
- $authUserInfo = array(
+ $authUserInfo = [
'login' => $instance->mInfo['login'],
'password' => $instance->mInfo['password'],
'real_name' => $instance->mInfo['real_name'],
- 'email' => $instance->mInfo['email']
- );
- $userInfo = $this->getUserInfo( array( 'login' => $pUser ));
+ 'email' => $instance->mInfo['email'],
+ ];
+ $userInfo = $this->getUserInfo( [ 'login' => $pUser ]);
$this->mUserId = $userInfo['user_id'];
$this->store( $authUserInfo );
- $this->mErrors = array();
+ $this->mErrors = [];
} else {
- $authUserInfo = array(
+ $authUserInfo = [
'login' => $instance->mInfo['login'],
'password' => $instance->mInfo['password'],
'real_name' => $instance->mInfo['real_name'],
- 'email' => $instance->mInfo['email']
- );
+ 'email' => $instance->mInfo['email'],
+ ];
// TODO somehow, mUserId gets set to -1 at this point - no idea how
- // set to NULL to prevent overwriting Guest user - wolff_borg
- $this->mUserId = NULL;
+ // set to null to prevent overwriting Guest user - wolff_borg
+ $this->mUserId = null;
$this->store( $authUserInfo );
}
if( $createAuth && $i > 0 ) {
// if the user was logged into this system and we should progate users down other auth methods
for( $j = $i; $i >= 0; $j-- ) {
- $probMethodName = $gBitSystem->getConfig( "users_auth_method_$j", $default );
+ $probMethodName = $gBitSystem->getConfig( "users_auth_method_$j", $default ?? true );
if( !empty( $probMethodName )) {
$probInstance = BaseAuth::init( $probMethodName );
if( $probInstance && $probInstance->canManageAuth() ) {
@@ -1497,12 +1541,12 @@ class BitUser extends LibertyMime {
if( $this->mUserId != ANONYMOUS_USER_ID ) {
$this->load();
//on first time login we run the users registation service
- if( $this->mInfo['last_login'] == NULL ) {
+ if( empty($this->mInfo['last_login']) ) {
$this->invokeServices( 'users_register_function' );
}
$this->updateLastLogin( $this->mUserId );
}
- return( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
@@ -1510,15 +1554,15 @@ class BitUser extends LibertyMime {
*
* @param array $pUserId
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function updateLastLogin( $pUserId ) {
- $ret = FALSE;
- if( @$this->verifyId( $pUserId ) ) {
- global $gBitSystem;
+ public static function updateLastLogin( $pUserId ) {
+ global $gBitSystem, $gBitDb;
+ $ret = false;
+ if( $gBitSystem->verifyId( $pUserId ) ) {
$query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `last_login` = `current_login`, `current_login` = ? WHERE `user_id` = ?";
- $result = $this->mDb->query( $query, array( $gBitSystem->getUTCTime(), $pUserId ));
- $ret = TRUE;
+ $result = $gBitDb->query( $query, [ $gBitSystem->getUTCTime(), $pUserId ]);
+ $ret = true;
}
return $ret;
}
@@ -1526,58 +1570,58 @@ class BitUser extends LibertyMime {
/**
* confirmRegistration
*
- * @param array $pUserId
- * @param array $pProvpass
+ * @param integer $pUserId
+ * @param string $pProvpass
* @access public
- * @return registered user, empty array on failure
+ * @return array registered user, empty array on failure
*/
- function confirmRegistration( $pUserId, $pProvpass ) {
+ public function confirmRegistration( $pUserId, $pProvpass ) {
global $gBitSystem;
$query = "
SELECT `user_id`, `provpass`, `user_password`, `login`, `email` FROM `".BIT_DB_PREFIX."users_users`
- WHERE `user_id`=? AND `provpass`=? AND ( `provpass_expires` IS NULL OR `provpass_expires` > ?)";
- return( $this->mDb->getRow( $query, array( $pUserId, $pProvpass, $gBitSystem->getUTCTime() )));
+ WHERE `user_id`=? AND `provpass`=? AND ( `provpass_expires` IS null OR `provpass_expires` > ?)";
+ return $this->mDb->getRow( $query, [ $pUserId, $pProvpass, $gBitSystem->getUTCTime() ]);
}
/**
* changeUserEmail
*
- * @param array $pUserId
- * @param array $pEmail
+ * @param integer $pUserId
+ * @param string $pEmail
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function changeUserEmail( $pUserId, $pEmail ) {
- if( !validate_email_syntax( $pEmail ) ) {
- $this->mErrors['bad_mail'] = tra( "The email address provided does not have recognised valid syntax." );
- } elseif( $this->userExists( array( 'email' => $pEmail ))) {
- $this->mErrors['duplicate_mail'] = tra( "The email address you selected already exists." );
+ public function changeUserEmail( $pUserId, $pEmail ) {
+ if( !KernelTools::validate_email_syntax( $pEmail ) ) {
+ $this->mErrors['bad_mail'] = KernelTools::tra( "The email address provided does not have recognised valid syntax." );
+ } elseif( $this->userExists( [ 'email' => $pEmail ])) {
+ $this->mErrors['duplicate_mail'] = KernelTools::tra( "The email address you selected already exists." );
} else {
$query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `email`=? WHERE `user_id`=?";
- $result = $this->mDb->query( $query, array( $pEmail, $pUserId ) );
+ $result = $this->mDb->query( $query, [ $pEmail, $pUserId ] );
$query = "UPDATE `".BIT_DB_PREFIX."users_watches` SET `email`=? WHERE `user_id`=?";
- $result = $this->mDb->query( $query, array( $pEmail, $pUserId ) );
+ $result = $this->mDb->query( $query, [ $pEmail, $pUserId ] );
// update value in hash
$this->mInfo['email'] = $pEmail;
}
- return( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
* lookupHomepage
*
- * @param array $iHomepage
+ * @param string $iHomepage
* @access public
- * @return user_id that can be used to point to users homepage
+ * @return int user_id that can be used to point to users homepage
*/
- function lookupHomepage( $iHomepage ) {
- $ret = NULL;
+ public function lookupHomepage( $iHomepage ) {
+ $ret = null;
if( @$this->verifyId( $iHomepage )) {
// iHomepage is the user_id for the user...
$key = 'user_id';
// force to proper integer to get things like "007." to properly query
- $iHomepage = (integer)$iHomepage;
+ $iHomepage = (integer) $iHomepage;
} elseif( substr( $iHomepage, 0, 7 ) == 'mailto:' ) {
// iHomepage is the email address of the user...
$key = 'email';
@@ -1585,7 +1629,7 @@ class BitUser extends LibertyMime {
// iHomepage is the 'login' of the user...
$key = 'login';
}
- $tmpUser = $this->getUserInfo( array( $key => $iHomepage ));
+ $tmpUser = $this->getUserInfo( [ $key => $iHomepage ]);
if( @$this->verifyId( $tmpUser['user_id'] )) {
$ret = $tmpUser['user_id'];
}
@@ -1595,22 +1639,21 @@ class BitUser extends LibertyMime {
/**
* getUserPreference
*
- * @param array $pPrefName
- * @param array $pPrefDefault
- * @param array $pUserId
- * @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @param string $pPrefName
+ * @param string $pPrefDefault
+ * @param int $pUserId
+ * @return string|null
*/
- static function getUserPreference( $pPrefName, $pPrefDefault, $pUserId ) {
+ public static function getUserPreference( string $pPrefName, string $pPrefDefault, int $pUserId ) {
// Alternate to LibertyContent::getPreference when all you have is a user_id and a pref_name, and you need a value...
global $gBitDb;
- $ret = NULL;
+ $ret = null;
if( BitBase::verifyId( $pUserId ) ) {
$query = "
SELECT lcp.`pref_value` FROM `".BIT_DB_PREFIX."liberty_content_prefs` lcp INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON (lcp.`content_id`=uu.`content_id`)
WHERE uu.`user_id` = ? AND lcp.`pref_name` = ?";
- if( !$ret = $gBitDb->getOne( $query, array( $pUserId, $pPrefName ))) {
+ if( !$ret = $gBitDb->getOne( $query, [ $pUserId, $pPrefName ])) {
$ret = $pPrefDefault;
}
}
@@ -1622,10 +1665,10 @@ class BitUser extends LibertyMime {
*
* @param array $pUserMixed hash key can be any column in users_users table e.g.: 'login', 'user_id', 'email', 'content_id'
* @access public
- * @return user info on success, NULL on failure
+ * @return array user info on success, null on failure
*/
- function getUserInfo( $pUserMixed ) {
- $ret = NULL;
+ public function getUserInfo( $pUserMixed ) {
+ $ret = null;
if( is_array( $pUserMixed ) ) {
if( $val = current( $pUserMixed ) ) {
$key = $this->mDb->sanitizeColumnString( key( $pUserMixed ) );
@@ -1638,14 +1681,14 @@ class BitUser extends LibertyMime {
}
} elseif( is_numeric( $val ) ) {
$col = " uu.`".$key."` ";
- $val = $val;
+// $val = $val;
} else {
$col = "UPPER( uu.`".$key."` ) ";
$val = strtoupper( $val );
}
if( !empty( $col ) ) {
$query = "SELECT uu.* FROM `".BIT_DB_PREFIX."users_users` uu LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content` lc ON (lc.`content_id`=uu.`content_id`) WHERE $col = ?";
- $ret = $this->mDb->getRow( $query, array( $val ), 600 );
+ $ret = $this->mDb->getRow( $query, [ $val ], 600 );
}
}
}
@@ -1653,16 +1696,32 @@ class BitUser extends LibertyMime {
}
/**
+ * hasPermission check to see if a user has a given permission
+ *
+ * @param string $pPerm Perm name
+ * @return bool true if the user has a permission, false if they don't
+ */
+ public function hasPermission( $pPerm ) {
+ $ret = false;
+ if( $this->isAdmin() ) {
+ $ret = true;
+ } elseif( $this->isValid() ) {
+ $ret = isset( $this->mPerms[$pPerm] );
+ }
+ return $ret;
+ }
+
+ /**
* isUserPublic Determine if an arbitrary user can be viewed by non-permissioned users.
*
- * @param array $pUserId user_id of user to query visibility, if NULL will use this object
+ * @param int $pUserId user_id of user to query visibility, if null will use this object
* @access public
- * @return boolean if user is publically visible
+ * @return bool if user is publically visible
*/
- function isUserPrivate( $pUserId=NULL ) {
- $infoPref = NULL;
+ public function isUserPrivate( $pUserId=0 ) {
+ $infoPref = null;
if( BitBase::verifyId( $pUserId ) ) {
- $infoPref = BitUser::getUserPreference( 'users_information', NULL, $pUserId );
+ $infoPref = RoleUser::getUserPreference( 'users_information', null, $pUserId );
} elseif( isset( $this ) && $this->isValid() ) {
$infoPref = $this->getPreference( 'users_information' );
}
@@ -1675,34 +1734,34 @@ class BitUser extends LibertyMime {
*
* @param array $pHash
* @access public
- * @return user info
+ * @return array user info
*/
- function getUserIdFromCookieHash( $pHash ) {
+ public function getUserIdFromCookieHash( $pHash ) {
$query = "SELECT `user_id` FROM `".BIT_DB_PREFIX."users_cnxn` WHERE `cookie` = ?";
- return $this->mDb->getOne( $query, array( $pHash ));
+ return $this->mDb->getOne( $query, [ $pHash ]);
}
/**
* isPasswordDue work out if a user has to change their password
*
* @access public
- * @return TRUE when the password is due, FALSE if it isn't, NULL when no due time is set
- * @note NULL password due means *no* expiration
+ * @return bool true when the password is due, false if it isn't, null when no due time is set
+ * @note null password due means *no* expiration
*/
- function isPasswordDue( $pUserId = NULL ) {
+ public function isPasswordDue( $pUserId = null ) {
global $gBitSystem;
- $ret = FALSE;
+ $ret = false;
if( empty( $pUserId) && $this->isRegistered() ) {
$pUserId = $this->mUserId;
}
if( !empty( $pUserId ) ){
- // get user_id to avoid NULL and zero confusion
+ // get user_id to avoid null and zero confusion
$query = "
SELECT `user_id`, `pass_due`
FROM `".BIT_DB_PREFIX."users_users`
- WHERE `pass_due` IS NOT NULL AND `user_id`=? ";
- $due = $this->mDb->getRow( $query, array( $pUserId ) );
- if( @$this->verifyId( $due['user_id'] ) && !empty( $due['pass_due'] ) ) {
+ WHERE `pass_due` IS NOT null AND `user_id`=? ";
+ $due = $this->mDb->getRow( $query, [ $pUserId ] );
+ if( !empty( $due['user_id'] ) && @$this->verifyId( $due['user_id'] ) && !empty( $due['pass_due'] ) ) {
$ret = $due['pass_due'] <= $gBitSystem->getUTCTime();
}
}
@@ -1712,14 +1771,14 @@ class BitUser extends LibertyMime {
/**
* createTempPassword
*
- * @param array $pLogin
- * @param array $pPass
+ * @param string $pLogin
+ * @param string $pPass
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return array of temporary passwords
*/
function createTempPassword( $pLogin, $pPass ) {
global $gBitSystem;
- $ret = array( '', '' );
+ $ret = [ '', '' ];
if( empty( $pLogin ) ) {
$pLogin = $this->getField( 'email' );
@@ -1731,10 +1790,10 @@ class BitUser extends LibertyMime {
$loginCol = strpos( $pLogin, '@' ) ? 'email' : 'login';
#temp passwords good for 3 days -- prob should be an config option
- $passDue = $gBitSystem->getUTCTime() + ( 60 * 60 * 24 * 3 );
+ $passDue = $gBitSystem->getUTCTime() + 60 * 60 * 24 * 3;
$query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `provpass` = ?, `provpass_expires` = ? WHERE `".$loginCol."` = ?";
- $result = $this->mDb->query( $query, array( $provpass, $passDue, $pLogin ));
- $ret = array( $pass, $provpass );
+ $result = $this->mDb->query( $query, [ $provpass, $passDue, $pLogin ]);
+ $ret = [ $pass, $provpass ];
}
return $ret;
}
@@ -1742,35 +1801,35 @@ class BitUser extends LibertyMime {
/**
* storePassword
*
- * @param array $pPass
- * @param array $pLogin
+ * @param string $pPass
+ * @param string $pLogin
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function storePassword( $pPass, $pLogin=NULL ) {
+ function storePassword( $pPass, $pLogin=null ) {
global $gBitSystem;
- $ret = FALSE;
+ $ret = false;
if( empty( $pLogin ) ) {
$pLogin = $this->getField( 'email' );
}
if( !empty( $pLogin )) {
- $ret = TRUE;
+ $ret = true;
$hash = md5( $pPass );
// if renew password config is set then set - otherwise set null to respect no pass due
- $passDue = NULL;
+ $passDue = null;
if( $gBitSystem->getConfig('users_pass_due') ) {
$now = $gBitSystem->getUTCTime();;
// renew password according to config value
- $passDue = $now + ( 60 * 60 * 24 * $gBitSystem->getConfig( 'users_pass_due' ));
+ $passDue = $now + 60 * 60 * 24 * $gBitSystem->getConfig( 'users_pass_due' );
}
if( !$gBitSystem->isFeatureActive( 'users_clear_passwords' )) {
- $pPass = NULL;
+ $pPass = null;
}
$loginCol = strpos( $pLogin, '@' ) ? 'email' : 'login';
- $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `provpass`= NULL, `provpass_expires` = NULL,`hash`=? ,`user_password`=? ,`pass_due`=? WHERE `".$loginCol."`=?";
- $result = $this->mDb->query( $query, array( $hash, $pPass, $passDue, $pLogin ));
+ $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `provpass`= null, `provpass_expires` = null,`hash`=? ,`user_password`=? ,`pass_due`=? WHERE `".$loginCol."`=?";
+ $this->mDb->query( $query, [ $hash, $pPass, $passDue, $pLogin ]);
}
return $ret;
}
@@ -1783,7 +1842,7 @@ class BitUser extends LibertyMime {
* @return array of users and what they have been up to
*/
function getUserActivity( &$pListHash ) {
- $bindVars = array();
+ $bindVars = [];
if( empty( $pListHash['sort_mode'] ) ) {
$pListHash['sort_mode'] = 'last_get_desc';
}
@@ -1795,13 +1854,13 @@ class BitUser extends LibertyMime {
$bindVars[] = time() - $pListHash['last_get'];
}
- if( @BitBase::verifyId( $pListHash['user_id'] ) ) {
+ if( BitBase::verifyId( $pListHash['user_id'] ?? 0 ) ) {
$whereSql .= ' AND uc.`user_id` = ? ';
$bindVars[] = $pListHash['user_id'];
}
if( !empty( $pListHash['ip'] ) ) {
- $ips = split( ',', $pListHash['ip'] );
+ $ips = mb_split( ',', $pListHash['ip'] );
$whereSql .= ' AND ( ';
do {
$ip = array_pop( $ips );
@@ -1815,19 +1874,19 @@ class BitUser extends LibertyMime {
}
if( !empty( $pListHash['online'] ) ) {
- $whereSql .= ' AND uc.`cookie` IS NOT NULL ';
+ $whereSql .= ' AND uc.`cookie` IS NOT null ';
}
$query = "
SELECT DISTINCT uc.`user_id`, `login`, `real_name`, `connect_time`, `ip`, `user_agent`, `last_get`, uu.`content_id`
FROM `".BIT_DB_PREFIX."users_cnxn` uc
INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON (uc.`user_id` = uu.`user_id`)
- WHERE uc.`user_id` IS NOT NULL $whereSql
+ WHERE uc.`user_id` IS NOT null $whereSql
ORDER BY ".$this->mDb->convertSortmode( $pListHash['sort_mode'] );
$result = $this->mDb->query( $query, $bindVars, $pListHash['max_records'], $pListHash['offset'] );
- $ret = array();
+ $ret = [];
while( $res = $result->fetchRow() ) {
- $res['users_information'] = $this->getPreference( 'users_information', 'public', $res['content_id'] );
+ $res['users_information'] = $this->getPreference( 'users_information', 'public' );
$ret[] = $res;
}
@@ -1835,7 +1894,7 @@ class BitUser extends LibertyMime {
SELECT COUNT( uc.`user_id` )
FROM `".BIT_DB_PREFIX."users_cnxn` uc
INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON (uc.`user_id` = uu.`user_id`)
- WHERE uc.`user_id` IS NOT NULL $whereSql";
+ WHERE uc.`user_id` IS NOT null $whereSql";
$pListHash['cant'] = $this->mDb->GetOne( $countSql, $bindVars );
$this->postGetList( $pListHash );
return $ret;
@@ -1846,10 +1905,10 @@ class BitUser extends LibertyMime {
*
* @param array $pLogin
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function getUserDomain( $pLogin ) {
- $ret = array();
+ $ret = [];
if( $pLogin == $this->getField( 'login' ) && $this->getPreference( 'domain_style' ) ) {
$ret = $this->mInfo;
$ret['style'] = $this->getPreference( 'domain_style' );
@@ -1859,47 +1918,47 @@ class BitUser extends LibertyMime {
FROM `".BIT_DB_PREFIX."users_users` uu
INNER JOIN `".BIT_DB_PREFIX."liberty_content_prefs` lcp ON( uu.`content_id` = lcp.`content_id` )
WHERE uu.`login` = ? AND lcp.`pref_name` = ?";
- $ret = $this->mDb->getRow( $sql, array( $pLogin, 'domain_style' ) );
+ $ret = $this->mDb->getRow( $sql, [ $pLogin, 'domain_style' ] );
}
- return( $ret );
+ return $ret;
}
/**
* getDomain
*
- * @param array $pContentId
+ * @param integer $pContentId
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return array
*/
function getDomain( $pContentId ) {
- $ret = array();
+ $ret = [];
if( $this->verifyId( $pContentId ) ) {
$ret['content_id'] = $pContentId;
- $ret['style'] = $this->mDb->getOne( "SELECT `pref_value` FROM `".BIT_DB_PREFIX."liberty_content_prefs` WHERE `content_id`=? AND `pref_name`=?", array( $pContentId, 'domain_style' ));
+ $ret['style'] = $this->mDb->getOne( "SELECT `pref_value` FROM `".BIT_DB_PREFIX."liberty_content_prefs` WHERE `content_id`=? AND `pref_name`=?", [ $pContentId, 'domain_style' ]);
}
- return( $ret );
+ return $ret;
}
/**
* canCustomizeTheme check if a user can customise their theme
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
- function canCustomizeTheme() {
+ public function canCustomizeTheme() {
global $gBitSystem;
- return( $this->hasPermission( 'p_tidbits_custom_home_theme' ) || $gBitSystem->getConfig( 'users_themes' ) == 'y' || $gBitSystem->getConfig( 'users_themes' ) == 'h' || $gBitSystem->getConfig( 'users_themes' ) == 'u' );
+ return $this->hasPermission( 'p_tidbits_custom_home_theme' ) || $gBitSystem->getConfig( 'users_themes' ) == 'y' || $gBitSystem->getConfig( 'users_themes' ) == 'h' || $gBitSystem->getConfig( 'users_themes' ) == 'u';
}
/**
* canCustomizeLayout check if a user can customise their layout
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
- function canCustomizeLayout() {
+ public function canCustomizeLayout() {
global $gBitSystem;
- return( $this->hasPermission( 'p_tidbits_custom_home_layout' ) || $gBitSystem->getConfig( 'users_layouts' ) == 'y' || $gBitSystem->getConfig( 'users_layouts' ) == 'h' || $gBitSystem->getConfig( 'users_layouts' ) == 'u' );
+ return $this->hasPermission( 'p_tidbits_custom_home_layout' ) || $gBitSystem->getConfig( 'users_layouts' ) == 'y' || $gBitSystem->getConfig( 'users_layouts' ) == 'h' || $gBitSystem->getConfig( 'users_layouts' ) == 'u';
}
@@ -1911,9 +1970,9 @@ class BitUser extends LibertyMime {
* @param string $pSize
* @param array $pInfoHash
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function getThumbnailUrl( $pSize = 'small', $pInfoHash = NULL, $pSecondaryId = NULL, $pDefault=TRUE ) {
+ function getThumbnailUrl( string $pSize = 'small', ?array $pInfoHash = null, ?int $pSecondaryId = null, ?int $pDefault = null ): string|null {
$ret = '';
if( $pInfoHash ) {
// do some stuff if we are passed a hash-o-crap, not implemented currently
@@ -1932,7 +1991,7 @@ class BitUser extends LibertyMime {
* @param array $pParamHash array of options
* @param boolean $pParamHash['user_auto_avatar'] automatically create avatar from portrait
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return void
*/
function storeImages( $pParamHash ) {
if( isset( $_FILES['user_portrait_file'] ) && is_uploaded_file( $_FILES['user_portrait_file']['tmp_name'] ) && $_FILES['user_portrait_file']['size'] > 0 ) {
@@ -1967,11 +2026,11 @@ class BitUser extends LibertyMime {
* storePortrait
*
* @param array $pStorageHash
- * @param array $pGenerateAvatar
+ * @param bool $pGenerateAvatar
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
- function storePortrait( &$pStorageHash, $pGenerateAvatar = FALSE ) {
+ function storePortrait( &$pStorageHash, $pGenerateAvatar = false ) {
if( $this->isValid() && count( $pStorageHash )) {
// make a copy before the uploaded file disappears
if( $pGenerateAvatar ) {
@@ -1987,7 +2046,7 @@ class BitUser extends LibertyMime {
}
}
- return( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
@@ -1995,10 +2054,10 @@ class BitUser extends LibertyMime {
*
* @param array $pStorageHash
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function storeAvatar( &$pStorageHash ) {
- return( $this->storeUserImage( $pStorageHash, 'avatar' ));
+ return $this->storeUserImage( $pStorageHash, 'avatar' );
}
/**
@@ -2006,10 +2065,10 @@ class BitUser extends LibertyMime {
*
* @param array $pStorageHash
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function storeLogo( &$pStorageHash ) {
- return( $this->storeUserImage( $pStorageHash, 'logo' ));
+ return $this->storeUserImage( $pStorageHash, 'logo' );
}
/**
@@ -2018,25 +2077,25 @@ class BitUser extends LibertyMime {
* @param array $pStorageHash
* @param string $pType
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function storeUserImage( &$pStorageHash, $pType = 'portrait' ) {
if( $this->isValid() && count( $pStorageHash ) ) {
// don't do the content thing
- $pStorageHash['skip_content_store'] = TRUE;
+ $pStorageHash['skip_content_store'] = true;
// setup the hash for central storage functions
- $pStorageHash['no_perm_check'] = TRUE;
+ $pStorageHash['no_perm_check'] = true;
$pStorageHash['_files_override'][$pType] = $pStorageHash['upload'];
$pStorageHash['_files_override'][$pType]['max_width'] = constant( strtoupper( $pType )."_MAX_DIM" );
$pStorageHash['_files_override'][$pType]['max_height'] = constant( strtoupper( $pType )."_MAX_DIM" );
- $pStorageHash['_files_override'][$pType]['attachment_id'] = !empty( $this->mInfo["{$pType}_attachment_id"] ) ? $this->mInfo["{$pType}_attachment_id"] : NULL;
+ $pStorageHash['_files_override'][$pType]['attachment_id'] = !empty( $this->mInfo["{$pType}_attachment_id"] ) ? $this->mInfo["{$pType}_attachment_id"] : null;
$pStorageHash['_files_override'][$pType]['user_id'] = $this->mUserId;
- if( LibertyMime::store( $pStorageHash )) {
+ if( \Bitweaver\Liberty\LibertyMime::store( $pStorageHash )) {
$file = $pStorageHash['upload_store']['files'][$pType];
if( empty( $this->mInfo["{$pType}_attachment_id"] ) || $this->mInfo["{$pType}_attachment_id"] != $file['attachment_id'] ) {
$query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `{$pType}_attachment_id` = ? WHERE `user_id`=?";
- $result = $this->mDb->query( $query, array( $file['attachment_id'], $this->mUserId ) );
+ $result = $this->mDb->query( $query, [ $file['attachment_id'], $this->mUserId ] );
$this->mInfo["{$pType}_attachment_id"] = $file['attachment_id'];
$pStorageHash["{$pType}_file_name"] = $file['upload']['dest_branch'];
}
@@ -2044,36 +2103,37 @@ class BitUser extends LibertyMime {
$this->mErrors["{$pType}_file"] = 'File '.$pStorageHash['upload_store']['files'][$pType]['name'].' could not be stored.';
}
}
- return( count( $this->mErrors ) == 0 );
+ return count( $this->mErrors ) == 0;
}
/**
* purgeImage
*
- * @param array $pType
+ * @param string $pType
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return bool true on success, false on failure - mErrors will contain reason for failure
*/
function purgeImage( $pType ) {
if( $this->isValid() && @$this->verifyId( $this->mInfo[$pType.'_attachment_id'] ) ) {
$this->StartTrans();
- $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `".$pType."_attachment_id` = NULL WHERE `user_id`=?";
- $result = $this->mDb->query( $query, array( $this->mUserId ) );
+ $query = "UPDATE `".BIT_DB_PREFIX."users_users` SET `".$pType."_attachment_id` = null WHERE `user_id`=?";
+ $result = $this->mDb->query( $query, [ $this->mUserId ] );
if( $this->expungeAttachment( $this->getField( $pType.'_attachment_id' ) ) ) {
unset( $this->mInfo[$pType.'_file_name'] );
unset( $this->mInfo[$pType.'_attachment_id'] );
unset( $this->mInfo[$pType.'_url'] );
}
$this->CompleteTrans();
- return TRUE;
+ return true;
}
+ return false;
}
/**
* purgePortrait
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function purgePortrait() {
return $this->purgeImage( 'portrait' );
@@ -2084,7 +2144,7 @@ class BitUser extends LibertyMime {
* purgeAvatar
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function purgeAvatar() {
return $this->purgeImage( 'avatar' );
@@ -2095,7 +2155,7 @@ class BitUser extends LibertyMime {
* purgeLogo
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
function purgeLogo() {
return $this->purgeImage( 'logo' );
@@ -2107,24 +2167,25 @@ class BitUser extends LibertyMime {
/**
* storeWatch
*
- * @param array $pEvent
- * @param array $pObject
- * @param array $pType
- * @param array $pTitle
- * @param array $pUrl
+ * @param string $pEvent
+ * @param string $pObject
+ * @param string $pType
+ * @param string $pTitle
+ * @param string $pUrl
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
- function storeWatch( $pEvent, $pObject, $pType, $pTitle, $pUrl ) {
+ public function storeWatch( $pEvent, $pObject, $pType, $pTitle, $pUrl ) {
global $userlib;
if( $this->isValid() ) {
$hash = md5( uniqid( '.' ));
$query = "DELETE FROM `".BIT_DB_PREFIX."users_watches` WHERE `user_id`=? AND `event`=? AND `object`=?";
- $this->mDb->query($query,array( $this->mUserId, $pEvent, $pObject ) );
+ $this->mDb->query( $query, [ $this->mUserId, $pEvent, $pObject ] );
$query = "INSERT INTO `".BIT_DB_PREFIX."users_watches`(`user_id` ,`event` ,`object` , `email`, `hash`, `watch_type`, `title`, `url`) VALUES(?,?,?,?,?,?,?,?)";
- $this->mDb->query( $query, array( $this->mUserId, $pEvent, $pObject, $this->mInfo['email'], $hash, $pType, $pTitle, $pUrl ) );
- return TRUE;
+ $this->mDb->query( $query, [ $this->mUserId, $pEvent, $pObject, $this->mInfo['email'], $hash, $pType, $pTitle, $pUrl ] );
+ return true;
}
+ return false;
}
/**
@@ -2132,13 +2193,13 @@ class BitUser extends LibertyMime {
*
* @param string $pEvent
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return array|null true on success, false on failure
*/
function getWatches( $pEvent = '' ) {
- $ret = NULL;
+ $ret = null;
if( $this->isValid() ) {
$mid = '';
- $bindvars=array( $this->mUserId );
+ $bindvars= [ $this->mUserId ];
if ($pEvent) {
$mid = " and `event`=? ";
$bindvars[]=$pEvent;
@@ -2146,7 +2207,7 @@ class BitUser extends LibertyMime {
$query = "select * from `".BIT_DB_PREFIX."users_watches` where `user_id`=? $mid";
$result = $this->mDb->query($query,$bindvars);
- $ret = array();
+ $ret = [];
while ($res = $result->fetchRow()) {
$ret[] = $res;
@@ -2158,16 +2219,16 @@ class BitUser extends LibertyMime {
/**
* getEventWatches
*
- * @param array $pEvent
- * @param array $object
+ * @param string $pEvent
+ * @param string $object
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return array
*/
function getEventWatches( $pEvent, $pObject ) {
- $ret = NULL;
+ $ret = [];
if( $this->isValid() ) {
$query = "SELECT * FROM `".BIT_DB_PREFIX."users_watches` WHERE `user_id`=? AND `event`=? AND `object`=?";
- $result = $this->mDb->query($query,array( $this->mUserId, $pEvent, $pObject ) );
+ $result = $this->mDb->query($query, [ $this->mUserId, $pEvent, $pObject ] );
if ( $result->numRows() ) {
$ret = $result->fetchRow();
}
@@ -2178,13 +2239,13 @@ class BitUser extends LibertyMime {
/**
* get_event_watches
*
- * @param array $pEvent
- * @param array $pObject
+ * @param string $pEvent
+ * @param string $pObject
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return array
*/
- function get_event_watches( $pEvent, $pObject ) {
- $ret = array();
+ public function get_event_watches( $pEvent, $pObject ) {
+ $ret = [];
$query = "select * from `".BIT_DB_PREFIX."users_watches` tw INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON ( tw.`user_id`=uu.`user_id` ) where `event`=? and `object`=?";
$result = $this->mDb->query( $query,array( $pEvent,$pObject ));
@@ -2205,25 +2266,25 @@ class BitUser extends LibertyMime {
*
* @param array $pHash
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
- function remove_user_watch_by_hash( $pHash ) {
+ public function remove_user_watch_by_hash( $pHash ) {
$query = "DELETE FROM `".BIT_DB_PREFIX."users_watches` WHERE `hash`=?";
- $this->mDb->query( $query,array( $pHash ));
+ return $this->mDb->query( $query, [ $pHash ]);
}
/**
* expungeWatch
*
- * @param array $pEvent
- * @param array $pObject
+ * @param string $pEvent
+ * @param string $pObject
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return void
*/
- function expungeWatch( $pEvent, $pObject ) {
+ public function expungeWatch( $pEvent, $pObject ) {
if( $this->isValid() ) {
$query = "DELETE FROM `".BIT_DB_PREFIX."users_watches` WHERE `user_id`=? AND `event`=? AND `object`=?";
- $this->mDb->query( $query, array( $this->mUserId, $pEvent, $pObject ));
+ $this->mDb->query( $query, [ $this->mUserId, $pEvent, $pObject ]);
}
}
@@ -2231,12 +2292,12 @@ class BitUser extends LibertyMime {
* get_watches_events
*
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return array|bool true on success, false on failure
*/
- function get_watches_events() {
+ public function get_watches_events() {
$query = "select distinct `event` from `".BIT_DB_PREFIX."users_watches`";
- $result = $this->mDb->query($query,array());
- $ret = array();
+ $result = $this->mDb->query($query,[]);
+ $ret = [];
while ($res = $result->fetchRow()) {
$ret[] = $res['event'];
}
@@ -2249,11 +2310,11 @@ class BitUser extends LibertyMime {
*
* @param array $pListHash
* @access public
- * @return list of attachments
+ * @return array list of attachments
*/
- function getUserAttachments( &$pListHash ) {
+ public function getUserAttachments( &$pListHash ) {
$pListHash['user_id'] = $this->mUserId;
- $mime = new LibertyMime();
+ $mime = new \Bitweaver\Liberty\LibertyMime();
return $mime->getAttachmentList( $pListHash );
}
@@ -2263,33 +2324,33 @@ class BitUser extends LibertyMime {
*
* @param array $pContentId
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
*/
- function storeFavorite( $pContentId ) {
- $ret = FALSE;
+ public function storeFavorite( $pContentId ) {
+ $ret = false;
if( $this->isValid() && $this->verifyId( $pContentId )) {
if( !$this->hasFavorite( $pContentId ) ){
- $this->mDb->query( "INSERT INTO `".BIT_DB_PREFIX."users_favorites_map` ( `user_id`, `favorite_content_id` ) VALUES (?,?)", array( $this->mUserId, $pContentId ) );
+ $this->mDb->query( "INSERT INTO `".BIT_DB_PREFIX."users_favorites_map` ( `user_id`, `favorite_content_id` ) VALUES (?,?)", [ $this->mUserId, $pContentId ] );
}
- $ret = TRUE;
+ $ret = true;
}
- return( $ret );
+ return $ret;
}
- function expungeFavorite( $pContentId ) {
- $ret = FALSE;
+ public function expungeFavorite( $pContentId ) {
+ $ret = false;
if( $this->isValid() && $this->verifyId( $pContentId ) ) {
- $this->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."users_favorites_map` WHERE `user_id`=? AND `favorite_content_id`=?", array( $this->mUserId, $pContentId ) );
- $ret = TRUE;
+ $this->mDb->query( "DELETE FROM `".BIT_DB_PREFIX."users_favorites_map` WHERE `user_id`=? AND `favorite_content_id`=?", [ $this->mUserId, $pContentId ] );
+ $ret = true;
}
- return( $ret );
+ return $ret;
}
function hasFavorite( $pContentId ) {
- $ret = FALSE;
- $rslt = $this->mDb->getOne( "SELECT `favorite_content_id` FROM `".BIT_DB_PREFIX."users_favorites_map` WHERE `user_id`=? AND `favorite_content_id`=?", array( $this->mUserId, $pContentId ) );
- if( !is_null( $rslt ) ){
- $ret = TRUE;
+ $ret = false;
+ $rslt = $this->mDb->getOne( "SELECT `favorite_content_id` FROM `".BIT_DB_PREFIX."users_favorites_map` WHERE `user_id`=? AND `favorite_content_id`=?", [ $this->mUserId, $pContentId ] );
+ if($rslt !== null ){
+ $ret = true;
}
return $ret;
}
@@ -2298,12 +2359,12 @@ class BitUser extends LibertyMime {
* getFavorites
*
* @see LibertyContent::getContentList
- * @return Array of content data
+ * @return array of content data
*/
function getFavorites(){
- $ret = NULL;
+ $ret = null;
if( $this->isRegistered() ){
- $listHash['user_favs'] = TRUE;
+ $listHash['user_favs'] = true;
$listHash['order_table'] = 'ufm.';
$listHash['sort_mode'] = 'map_position_desc';
$ret = $this->getContentList( $listHash );
@@ -2316,10 +2377,10 @@ class BitUser extends LibertyMime {
* getUserId
*
* @access public
- * @return user id of currently loaded user
+ * @return int user id of currently loaded user
*/
function getUserId() {
- return( $this->isValid() ? $this->mUserId : ANONYMOUS_USER_ID );
+ return $this->isValid() ? $this->mUserId : ANONYMOUS_USER_ID;
}
/**
@@ -2328,7 +2389,7 @@ class BitUser extends LibertyMime {
* @param array $pUserName
* @param array $pParamHash
* @access public
- * @return URL to users homepage
+ * @return string URL to users homepage
*/
public static function getDisplayUrlFromHash( &$pParamHash ) {
if( function_exists( 'override_user_url' ) ) {
@@ -2341,10 +2402,10 @@ class BitUser extends LibertyMime {
if ($gBitSystem->isFeatureActive( 'pretty_urls' )
|| $gBitSystem->isFeatureActive( 'pretty_urls_extended' ) ) {
$ret = USERS_PKG_URL . $rewrite_tag;
- $ret .= urlencode( $pParamHash['login'] );
+ $ret .= urlencode( $pParamHash['login'] ?? '' );
} else {
$ret = USERS_PKG_URL . 'index.php?home=';
- $ret .= urlencode( $pParamHash['login'] );
+ $ret .= urlencode( $pParamHash['login'] ?? '' );
}
}
return $ret;
@@ -2356,10 +2417,10 @@ class BitUser extends LibertyMime {
* @param array $pUserName
* @param array $pDisplayHash
* @access public
- * @return get a link to the the users homepage
+ * @return string get a link to the the users homepage
*/
- public function getDisplayLink( $pParamHash, $pLinkText=NULL, $pAnchor=NULL ) {
- return BitUser::getDisplayNameFromHash( $pParamHash, TRUE );
+ public function getDisplayLink( $pParamHash, $pLinkText=null, $pAnchor=null ) {
+ return RoleUser::getDisplayNameFromHash( $pParamHash, true );
}
/**
@@ -2367,20 +2428,20 @@ class BitUser extends LibertyMime {
*
* @param array $pHash
* @access public
- * @return get the users display name
+ * @return string get the users display name
*/
- public static function getTitleFromHash( &$pHash, $pDefault=TRUE ) {
- return BitUser::getDisplayNameFromHash( $pHash, FALSE );
+ public static function getTitleFromHash( &$pHash, $pDefault=true ) {
+ return RoleUser::getDisplayNameFromHash( $pHash, false );
}
/**
* Get user information for a particular user
*
- * @param pUseLink return the information in the form of a url that links to the users information page
- * @param pHash todo - need explanation on how to use this...
- * @return display name or link to user information page
+ * @param array pHash todo - need explanation on how to use this...
+ * @param bool pUseLink return the information in the form of a url that links to the users information page
+ * @return string display name or link to user information page
**/
- public static function getDisplayNameFromHash( $pUseLink=FALSE, $pHash ) {
+ public static function getDisplayNameFromHash( array $pHash, $pUseLink=false ): string {
global $gBitSystem, $gBitUser;
if( !empty( $pHash )) {
if( !empty( $pHash['real_name'] ) && $gBitSystem->getConfig( 'users_display_name', 'real_name' ) == 'real_name' ) {
@@ -2410,19 +2471,19 @@ class BitUser extends LibertyMime {
}
if( empty( $pHash['users_information'] ) && !empty( $pHash['login'] ) ) {
- $pHash['users_information'] = $gBitSystem->mDb->getOne( "SELECT pref_value FROM liberty_content_prefs lcp INNER JOIN users_users uu ON (lcp.content_id=uu.content_id) WHERE uu.login=? AND pref_name='users_information'", array( $pHash['login'] ), 1, NULL, 86400 );
+ $pHash['users_information'] = $gBitSystem->mDb->getOne( "SELECT pref_value FROM liberty_content_prefs lcp INNER JOIN users_users uu ON (lcp.content_id=uu.content_id) WHERE uu.login=? AND pref_name='users_information'", [ $pHash['login'] ], 1, null, 86400 );
}
if( $pUseLink && $gBitUser->hasPermission( 'p_users_view_user_homepage' ) && (empty( $pHash['users_information'] ) || $pHash['users_information'] == 'public') ) {
- $ret = '<a class="username" title="'.( !empty( $pHash['link_title'] ) ? $pHash['link_title'] : tra( 'Profile for' ).' '.htmlspecialchars( $displayName ))
- .'" href="'.BitUser::getDisplayUrlFromHash( $pHash ).'">'
- . htmlspecialchars( isset( $pHash['link_label'] ) ? $pHash['link_label'] : $displayName )
+ $ret = '<a class="username" title="'.( !empty( $pHash['link_title'] ) ? $pHash['link_title'] : KernelTools::tra( 'Profile for' ).' '.htmlspecialchars( $displayName ))
+ .'" href="'.RoleUser::getDisplayUrlFromHash( $pHash ).'">'
+ . htmlspecialchars( isset( $pHash['link_label'] ) ? $pHash['link_label'] : ( isset($displayName) ? $displayName : 'not set' ) )
.'</a>';
} else {
$ret = htmlspecialchars( $displayName );
}
} else {
- $ret = tra( "Anonymous" );
+ $ret = KernelTools::tra( "Anonymous" );
}
return $ret;
@@ -2431,12 +2492,12 @@ class BitUser extends LibertyMime {
/**
* Get user information for a particular user
*
- * @param pUseLink return the information in the form of a url that links to the users information page
- * @param pHash todo - need explanation on how to use this...
- * @return display name or link to user information page
+ * @param bool pUseLink return the information in the form of a url that links to the users information page
+ * @param array pHash todo - need explanation on how to use this...
+ * @return string display name or link to user information page
**/
- function getDisplayName( $pUseLink=FALSE, $pHash=NULL ) {
- $ret = NULL;
+ public function getDisplayName( $pUseLink=false, $pHash=null ) {
+ $ret = null;
if( empty( $pHash ) && !empty( $this ) && !empty( $this->mInfo )) {
$pHash = &$this->mInfo;
}
@@ -2447,9 +2508,9 @@ class BitUser extends LibertyMime {
* getRenderFile Returns include file that will
*
* @access public
- * @return the fully specified path to file to be included
+ * @return string the fully specified path to file to be included
*/
- function getRenderFile() {
+ public function getRenderFile() {
return USERS_PKG_INCLUDE_PATH.'display_bituser_inc.php';
}
@@ -2457,15 +2518,15 @@ class BitUser extends LibertyMime {
* getSelectionList get a list of users that can be used in dropdown lists in forms to choose from
*
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return array|bool true on success, false on failure - mErrors will contain reason for failure
*/
- function getSelectionList() {
+ public function getSelectionList() {
$query = "
SELECT uu.`user_id`, uu.`login`, uu.`real_name`
FROM `".BIT_DB_PREFIX."users_users` uu
ORDER BY uu.`login`";
$result = $this->mDb->query( $query );
- $ret = array();
+ $ret = [];
while( $res = $result->fetchRow()) {
$ret[$res['user_id']] = $res['login'].(( !empty( $res['real_name'] ) && $res['real_name'] != $res['login'] ) ? ' - '.$res['real_name'] : '' );
}
@@ -2480,7 +2541,7 @@ class BitUser extends LibertyMime {
* @access public
* @return array of users
*/
- function getList( &$pParamHash ) {
+ public function getList( &$pParamHash ) {
global $gBitSystem, $gBitUser;
if( empty( $pParamHash['sort_mode'] )) {
$pParamHash['sort_mode'] = 'registration_date_desc';
@@ -2489,8 +2550,8 @@ class BitUser extends LibertyMime {
LibertyContent::prepGetList( $pParamHash );
$selectSql = $joinSql = $whereSql = '';
- $bindVars = array( 'bituser' );
- $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $pParamHash );
+ $bindVars = [ 'bituser' ];
+ $this->getServicesSql( 'content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, null, $pParamHash );
// limit search to users with a specific language
if( !empty( $pParamHash['lang_code'] ) ) {
@@ -2501,7 +2562,7 @@ class BitUser extends LibertyMime {
if( !$gBitUser->hasPermission( 'p_users_admin' ) ) {
$joinSql .= " LEFT OUTER JOIN `".BIT_DB_PREFIX."liberty_content_prefs` lcp2 ON ( lcp2.`content_id`=uu.`content_id` AND lcp2.`pref_name`='users_information' )";
- $whereSql .= " AND (lcp2.`pref_value` IS NULL OR lcp2.`pref_value`='public')";
+ $whereSql .= " AND (lcp2.`pref_value` IS null OR lcp2.`pref_value`='public')";
}
// limit search to users with a specific IP
@@ -2545,7 +2606,7 @@ class BitUser extends LibertyMime {
$selectSql .= ", sru.`referer_url`";
if( !empty( $pParamHash['referer'] ) ) {
if( $pParamHash['referer'] == 'none' ) {
- $whereSql .= " AND `referer_url` IS NULL";
+ $whereSql .= " AND `referer_url` IS null";
} else {
$whereSql .= " AND `referer_url` LIKE ?";
$bindVars[] = '%'.strtolower( $pParamHash['find'] ).'%';
@@ -2565,11 +2626,11 @@ class BitUser extends LibertyMime {
WHERE lc.`content_type_guid` = ? $whereSql ORDER BY ".$this->mDb->convertSortmode( $pParamHash['sort_mode'] );
$result = $this->mDb->query( $query, $bindVars, $pParamHash['max_records'], $pParamHash['offset'] );
- $ret = array();
+ $ret = [];
while( $res = $result->fetchRow() ) {
// Used for pulling out dead/empty/spam accounts
if( isset( $pParamHash['max_content_count'] ) && is_numeric( $pParamHash['max_content_count'] ) ) {
- $contentCount = $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."liberty_content` lc INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON ( lc.`user_id`=uu.`user_id` ) WHERE uu.`user_id`=? AND `content_type_guid` != 'bituser'", array( $res['user_id'] ) );
+ $contentCount = $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."liberty_content` lc INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON ( lc.`user_id`=uu.`user_id` ) WHERE uu.`user_id`=? AND `content_type_guid` != 'bituser'", [ $res['user_id'] ] );
if( $contentCount > $pParamHash['max_content_count'] ) {
continue;
}
@@ -2577,7 +2638,7 @@ class BitUser extends LibertyMime {
// Used for pulling out non-idle accounts or pigs
if( isset( $pParamHash['min_content_count'] ) && is_numeric( $pParamHash['min_content_count'] ) ) {
- $contentCount = $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."liberty_content` lc INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON ( lc.`user_id`=uu.`user_id` ) WHERE uu.`user_id`=? AND `content_type_guid` != 'bituser'", array( $res['user_id'] ) );
+ $contentCount = $this->mDb->getOne( "SELECT COUNT(*) FROM `".BIT_DB_PREFIX."liberty_content` lc INNER JOIN `".BIT_DB_PREFIX."users_users` uu ON ( lc.`user_id`=uu.`user_id` ) WHERE uu.`user_id`=? AND `content_type_guid` != 'bituser'", [ $res['user_id'] ] );
if( $contentCount < $pParamHash['min_content_count'] ) {
continue;
}
@@ -2585,22 +2646,22 @@ class BitUser extends LibertyMime {
if( !empty( $res['referer_url'] )) {
if ( $gBitSystem->isPackageActive('stats') ) {
- $res['short_referer_url'] = stats_referer_display_short($res['referer_url']);
+ $res['short_referer_url'] = \Bitweaver\Stats\stats_referer_display_short($res['referer_url']);
}
}
if( !empty( $res['avatar_file_name'] )) {
- $res['avatar_url'] = $this->getSourceUrl( array( 'attachment_id'=>$res['avatar_attachment_id'], 'mime_type'=>$res['avatar_mime_type'], 'file_name'=>$res['avatar_file_name'] ) );
- $res['thumbnail_url'] = liberty_fetch_thumbnail_url( array(
- 'source_file' => $this->getSourceFile( array( 'sub_dir'=>$res['avatar_attachment_id'], 'user_id' => $res['user_id'], 'file_name'=>$res['avatar_file_name'], 'mime_type'=>$res['avatar_mime_type'], 'package'=>liberty_mime_get_storage_sub_dir_name( array( 'mime_type'=>$res['avatar_mime_type'], 'name'=>$res['avatar_file_name'] ) ) ) ),
- 'file_name' => $res['avatar_url'],
+ $res['avatar_url'] = $this->getSourceUrl( [ 'attachment_id' => $res['avatar_attachment_id'], 'mime_type' => $res['avatar_mime_type'], 'file_name' => $res['avatar_file_name'] ] );
+ $res['thumbnail_url'] = \Bitweaver\Liberty\liberty_fetch_thumbnail_url( [
+ 'source_file' => $this->getSourceFile( [ 'sub_dir' => $res['avatar_attachment_id'], 'user_id' => $res['user_id'], 'file_name' => $res['avatar_file_name'], 'mime_type' => $res['avatar_mime_type'], 'package' => \Bitweaver\Liberty\liberty_mime_get_storage_sub_dir_name( [ 'mime_type' => $res['avatar_mime_type'], 'name' => $res['avatar_file_name'] ] ) ] ),
+ 'file_name' => $res['avatar_url'],
// TODO: Make this a preference
- 'size' => 'avatar'
- ));
+ 'size' => 'avatar',
+ ]);
}
$res["roles"] = $this->getRoles( $res['user_id'] );
$ret[$res['user_id']] = $res;
}
- $retval = array();
+ $retval = [];
$query = "
SELECT COUNT(*) FROM `".BIT_DB_PREFIX."users_users` uu
@@ -2616,24 +2677,24 @@ class BitUser extends LibertyMime {
/**
* getRoles
*
- * @param array $pUserId
- * @param array $pForceRefresh
+ * @param int $pUserId
+ * @param bool $pForceRefresh
* @access public
- * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
+ * @return int|array|bool false on failure - mErrors will contain reason for failure
*/
- function getRoles( $pUserId=NULL, $pForceRefresh = FALSE ) {
+ public function getRoles( int $pUserId = 0, bool $pForceRefresh = false ) {
$pUserId = !empty( $pUserId ) ? $pUserId : $this->mUserId;
if( !isset( $this->cUserRoles[$pUserId] ) || $pForceRefresh ) {
$query = "
SELECT ur.`role_id`, ur.`role_name`, ur.`user_id` as role_owner_user_id
FROM `".BIT_DB_PREFIX."users_roles_map` urm INNER JOIN `".BIT_DB_PREFIX."users_roles` ur ON (ur.`role_id`=urm.`role_id`)
WHERE urm.`user_id`=? OR urm.`role_id`=".ANONYMOUS_TEAM_ID;
- $ret = $this->mDb->getAssoc( $query, array(( int )$pUserId ));
+ $ret = $this->mDb->getAssoc( $query, [ (int) $pUserId ]);
if( $ret ) {
foreach( array_keys( $ret ) as $roleId ) {
- $res = array();
+ $res = [];
foreach( $res as $key=>$val) {
- $ret[$key] = array( 'role_name' => $val );
+ $ret[$key] = [ 'role_name' => $val ];
}
}
}
@@ -2649,44 +2710,44 @@ class BitUser extends LibertyMime {
* isValid
*
* @access public
- * @return TRUE if user is loaded
+ * @return bool true if user is loaded
*/
- function isValid() {
- return ( $this->verifyId( $this->mUserId ) );
+ public function isValid() {
+ return $this->verifyId( $this->mUserId );
}
/**
* isAdmin "PURE VIRTUAL BASE FUNCTION";
*
* @access public
- * @return FALSE
+ * @return false
*/
- function isAdmin() {
- return FALSE;
+ public function isAdmin() {
+ return false;
}
/**
* isRegistered
*
* @access public
- * @return TRUE if user is registered, FALSE otherwise
+ * @return bool true if user is registered, false otherwise
*/
- function isRegistered() {
- return ( $this->mUserId > ANONYMOUS_USER_ID );
+ public function isRegistered() {
+ return $this->mUserId > ANONYMOUS_USER_ID;
}
/**
* verifyRegistered
*
* @access public
- * @return TRUE if user is registered, otherwise a login dialog is displayed
+ * @return bool true if user is registered, otherwise a login dialog is displayed
*/
- function verifyRegistered( $pMsg = "" ) {
+ public function verifyRegistered( $pMsg = "" ) {
global $gBitSystem;
if( !$this->isRegistered() ) {
$gBitSystem->fatalPermission( "", $pMsg );
}
- return TRUE;
+ return true;
}
/**
@@ -2694,19 +2755,16 @@ class BitUser extends LibertyMime {
*
* @param array $pUserMixed
* @access public
- * @return TRUE on success, FALSE on failure
+ * @return bool true on success, false on failure
+ * TODO Tidy check query!
*/
- function userExists( $pUserMixed ) {
- $ret = FALSE;
+ public function userExists( $pUserMixed ) {
+ $ret = false;
if ( is_array( $pUserMixed ) ) {
if( $cur = current( $pUserMixed ) ) {
- if( is_numeric( $cur ) ) {
- $conditionSql = " `".key( $pUserMixed )."` ";
- } else {
- $conditionSql = " UPPER(`".key( $pUserMixed )."`)";
- }
- $query = "SELECT `user_id` FROM `".BIT_DB_PREFIX."users_users` WHERE $conditionSql = ?";
- $ret = $this->mDb->getOne( $query, array( strtoupper( $cur ) ) );
+ $conditionSql = (is_numeric( $cur )) ? " `".key( $pUserMixed )."` " : " UPPER(`".key( $pUserMixed )."`)";
+ $query = "SELECT user_id FROM `".BIT_DB_PREFIX."users`".$conditionSql;
+ $ret = $this->mDb->getOne( $query, [ strtoupper( $cur ) ] );
}
}
return $ret;
@@ -2716,21 +2774,21 @@ class BitUser extends LibertyMime {
* Create an export hash from the data
*
* @access public
- * @return export data
+ * @return array export data
*/
- function exportHash() {
+ public function exportHash() {
global $gBitSystem;
- $ret = array();
+ $ret = [];
if( $this->isValid() ) {
- $ret = array(
+ $ret = [
'user_id' => $this->mUserId,
'content_id' => $this->mContentId,
'real_name' => $this->getField( 'real_name' ),
'email' => $this->getField( 'email' ),
'uri' => $this->getDisplayUri(),
- 'registration_date' => date( DateTime::W3C, $this->getField('registration_date') ),
- 'last_login' => date( DateTime::W3C, $this->getField('last_login') ),
- );
+ 'registration_date' => date( \DateTime::W3C, $this->getField('registration_date') ),
+ 'last_login' => date( \DateTime::W3C, $this->getField('last_login') ),
+ ];
$ret['content_count'] = get_user_content_count( $this->mUserId );
if( $gBitSystem->isPackageActive( 'stats' ) ) {
$ret['referer'] = $this->mDb->getOne( "SELECT sru.`referer_url` FROM `".BIT_DB_PREFIX."stats_referer_urls` sru INNER JOIN `".BIT_DB_PREFIX."stats_referer_users_map` srum ON (srum.`referer_url_id`=sru.`referer_url_id`) WHERE `user_id`=?", $this->mUserId );
@@ -2758,7 +2816,7 @@ class BitUser extends LibertyMime {
$pReturn['user_id'] = $pInput['user_id'];
}
}
- if( @BitBase::verifyId( $pInput['role_id'] ) ) {
+ if( BitBase::verifyId( $pInput['role_id'] ?? 0 ) ) {
$pReturn['role_id'] = $pInput['role_id'];
}
return;
@@ -2777,25 +2835,25 @@ class BitUser extends LibertyMime {
function get_user_content_count( $pUserId ) {
global $gBitDb;
if( BitBase::verifyId( $pUserId ) ) {
- return $gBitDb->getOne( "SELECT COUNT(`content_id`) FROM `".BIT_DB_PREFIX."liberty_content` lc WHERE lc.`content_type_guid`!='bituser' AND lc.`user_id`=?", array( $pUserId ) );
+ return $gBitDb->getOne( "SELECT COUNT(`content_id`) FROM `".BIT_DB_PREFIX."liberty_content` lc WHERE lc.`content_type_guid`!='bituser' AND lc.`user_id`=?", [ $pUserId ] );
}
}
// {{{ ==================== Services ====================
-function users_favs_content_list_sql( &$pObject, $pParamHash=NULL ){
- $ret = array();
+function users_favs_content_list_sql( $pObject, $pParamHash=null ){
+ $ret = [];
if( !empty( $pParamHash['user_favs'] ) ){
// $ret['select_sql'] = "";
$ret['join_sql'] = " INNER JOIN `".BIT_DB_PREFIX."users_favorites_map` ufm ON ( ufm.`favorite_content_id`=lc.`content_id` )";
$ret['where_sql'] = " AND ufm.`user_id` = ?";
- $ret['bind_vars'][] = $pObject->mUserId;
+ $ret['bind_vars'][] = !empty($pObject->mUserId) ? $pObject->mUserId : 0;
}
return $ret;
}
-function users_collection_sql( &$pObject, $pParamHash=NULL ){
- $ret = array();
+function users_collection_sql( $pObject, $pParamHash=null ){
+ $ret = [];
if( !empty( $pParamHash['role_id'] ) and BitBase::verifyId( $pParamHash['role_id'] ) ){
// $ret['select_sql'] = "";
$ret['join_sql'] = " INNER JOIN `".BIT_DB_PREFIX."users_roles_map` urm ON (ugm.`user_id`=uu.`user_id`)";
@@ -2804,6 +2862,3 @@ function users_collection_sql( &$pObject, $pParamHash=NULL ){
}
return $ret;
}
-// }}}
-
-/* vim: :set fdm=marker : */