Vergleich inc/datahandlers/user.php - 1.8.5 - 1.8.7

  Keine Änderungen   Hinzugefügt   Modifiziert   Entfernt
Zeile 61Zeile 61
	 * @var array
*/
public $return_values = array();

	 * @var array
*/
public $return_values = array();

 

/**
* @var array
*/
var $delete_uids = array();

/**
* @var int
*/
var $deleted_users = 0;


/**
* Verifies if a username is valid or invalid.
*


/**
* Verifies if a username is valid or invalid.
*

	 * @param boolean True when valid, false when invalid.

	 * @return boolean True when valid, false when invalid.

	 */
function verify_username()
{

	 */
function verify_username()
{

Zeile 73Zeile 83

$username = &$this->data['username'];
require_once MYBB_ROOT.'inc/functions_user.php';


$username = &$this->data['username'];
require_once MYBB_ROOT.'inc/functions_user.php';





		// Fix bad characters
$username = trim_blank_chrs($username);
$username = str_replace(array(unichr(160), unichr(173), unichr(0xCA), dec_to_utf8(8238), dec_to_utf8(8237), dec_to_utf8(8203)), array(" ", "-", "", "", "", ""), $username);

		// Fix bad characters
$username = trim_blank_chrs($username);
$username = str_replace(array(unichr(160), unichr(173), unichr(0xCA), dec_to_utf8(8238), dec_to_utf8(8237), dec_to_utf8(8203)), array(" ", "-", "", "", "", ""), $username);

Zeile 83Zeile 93

// Check if the username is not empty.
if($username == '')


// Check if the username is not empty.
if($username == '')

		{

		{

			$this->set_error('missing_username');
return false;
}

			$this->set_error('missing_username');
return false;
}

Zeile 115Zeile 125
	/**
* Verifies if a usertitle is valid or invalid.
*

	/**
* Verifies if a usertitle is valid or invalid.
*

	 * @param boolean True when valid, false when invalid.

	 * @return boolean True when valid, false when invalid.

	 */
function verify_usertitle()
{

	 */
function verify_usertitle()
{

Zeile 164Zeile 174
	* @return boolean True when valid, false when invalid.
*/
function verify_password()

	* @return boolean True when valid, false when invalid.
*/
function verify_password()

	{

	{

		global $mybb;

$user = &$this->data;

		global $mybb;

$user = &$this->data;

Zeile 204Zeile 214

// MD5 the password
$user['md5password'] = md5($user['password']);


// MD5 the password
$user['md5password'] = md5($user['password']);





		// Generate our salt
$user['salt'] = generate_salt();

		// Generate our salt
$user['salt'] = generate_salt();





		// Combine the password and salt
$user['saltedpw'] = salt_password($user['md5password'], $user['salt']);


		// Combine the password and salt
$user['saltedpw'] = salt_password($user['md5password'], $user['salt']);


Zeile 224Zeile 234
	*/
function verify_usergroup()
{

	*/
function verify_usergroup()
{

		$user = &$this->data;

 
		return true;
}
/**

		return true;
}
/**

Zeile 462Zeile 471

/**
* Verifies if the thread count field is filled in correctly.


/**
* Verifies if the thread count field is filled in correctly.

	*
* @return boolean True when valid, false when invalid.
*/

	*
* @return boolean True when valid, false when invalid.
*/

	function verify_threadnum()
{
$user = &$this->data;

	function verify_threadnum()
{
$user = &$this->data;

Zeile 491Zeile 500
		$profile_fields = &$this->data['profile_fields'];

// Loop through profile fields checking if they exist or not and are filled in.

		$profile_fields = &$this->data['profile_fields'];

// Loop through profile fields checking if they exist or not and are filled in.

		$userfields = array();
$comma = '';

 

// Fetch all profile fields first.
$pfcache = $cache->read('profilefields');


// Fetch all profile fields first.
$pfcache = $cache->read('profilefields');

Zeile 519Zeile 526
				}

$profilefield['type'] = htmlspecialchars_uni($profilefield['type']);

				}

$profilefield['type'] = htmlspecialchars_uni($profilefield['type']);

 
				$profilefield['name'] = htmlspecialchars_uni($profilefield['name']);

				$thing = explode("\n", $profilefield['type'], "2");
$type = trim($thing[0]);
$field = "fid{$profilefield['fid']}";

				$thing = explode("\n", $profilefield['type'], "2");
$type = trim($thing[0]);
$field = "fid{$profilefield['fid']}";

Zeile 850Zeile 858
	}

/**

	}

/**

	 * Verifies if a langage is valid for this user or not.

	 * Verifies if a language is valid for this user or not.

	 *
* @return boolean True when valid, false when invalid.
*/

	 *
* @return boolean True when valid, false when invalid.
*/

Zeile 864Zeile 872
		if($language != '' && !$lang->language_exists($language))
{
$this->set_error("invalid_language");

		if($language != '' && !$lang->language_exists($language))
{
$this->set_error("invalid_language");

			return false;
}
return true;
}


























			return false;
}
return true;
}

/**
* Verifies if a style is valid for this user or not.
*
* @return boolean True when valid, false when invalid.
*/
function verify_style()
{
global $lang;

$user = &$this->data;

if($user['style'])
{
$theme = get_theme($user['style']);

if(empty($theme) || !is_member($theme['allowedgroups'], $user) && $theme['allowedgroups'] != 'all')
{
$this->set_error('invalid_style');
return false;
}
}

return true;
}


/**
* Verifies if this is coming from a spam bot or not


/**
* Verifies if this is coming from a spam bot or not

Zeile 875Zeile 908
	 * @return boolean True when valid, false when invalid.
*/
function verify_checkfields()

	 * @return boolean True when valid, false when invalid.
*/
function verify_checkfields()

	{
$user = &$this->data;

	{
$user = &$this->data;


// An invalid language has been specified?
if($user['regcheck1'] !== "" || $user['regcheck2'] !== "true")


// An invalid language has been specified?
if($user['regcheck1'] !== "" || $user['regcheck2'] !== "true")

Zeile 885Zeile 918
			return false;
}
return true;

			return false;
}
return true;

	}






















	}

/**
* Verifies if the user timezone is valid.
* If the timezone is invalid, the board default is used.
*
* @return boolean True when timezone was valid, false otherwise
*/
function verify_timezone()
{
$user = &$this->data;

$timezones = get_supported_timezones();

if(!array_key_exists($user['timezone'], $timezones))
{
$user['timezone'] = $mybb->settings['timezoneoffset'];
return false;
}

return true;
}


/**
* Validate all user assets.


/**
* Validate all user assets.

Zeile 895Zeile 949
	function validate_user()
{
global $mybb, $plugins;

	function validate_user()
{
global $mybb, $plugins;





		$user = &$this->data;

		$user = &$this->data;





		// First, grab the old user details if this user exists
if(!empty($user['uid']))
{
$old_user = get_user($user['uid']);

		// First, grab the old user details if this user exists
if(!empty($user['uid']))
{
$old_user = get_user($user['uid']);

		}


		}


		if($this->method == "insert" || array_key_exists('username', $user))
{
// If the username is the same - no need to verify

		if($this->method == "insert" || array_key_exists('username', $user))
{
// If the username is the same - no need to verify

Zeile 938Zeile 992
			$this->verify_website();
}
if($this->method == "insert" || array_key_exists('icq', $user))

			$this->verify_website();
}
if($this->method == "insert" || array_key_exists('icq', $user))

		{

		{

			$this->verify_icq();
}
if($this->method == "insert" || (isset($user['birthday']) && is_array($user['birthday'])))

			$this->verify_icq();
}
if($this->method == "insert" || (isset($user['birthday']) && is_array($user['birthday'])))

Zeile 950Zeile 1004
			$this->verify_postnum();
}
if($this->method == "insert" || array_key_exists('threadnum', $user))

			$this->verify_postnum();
}
if($this->method == "insert" || array_key_exists('threadnum', $user))

		{

		{

			$this->verify_threadnum();
}
if($this->method == "insert" || array_key_exists('profile_fields', $user))
{
$this->verify_profile_fields();

			$this->verify_threadnum();
}
if($this->method == "insert" || array_key_exists('profile_fields', $user))
{
$this->verify_profile_fields();

		}

		}

		if($this->method == "insert" || array_key_exists('referrer', $user))
{
$this->verify_referrer();

		if($this->method == "insert" || array_key_exists('referrer', $user))
{
$this->verify_referrer();

Zeile 968Zeile 1022
		if($this->method == "insert" || array_key_exists('regdate', $user))
{
$this->verify_regdate();

		if($this->method == "insert" || array_key_exists('regdate', $user))
{
$this->verify_regdate();

		}

		}

		if($this->method == "insert" || array_key_exists('lastvisit', $user))
{
$this->verify_lastvisit();
}
if($this->method == "insert" || array_key_exists('lastactive', $user))

		if($this->method == "insert" || array_key_exists('lastvisit', $user))
{
$this->verify_lastvisit();
}
if($this->method == "insert" || array_key_exists('lastactive', $user))

		{

		{

			$this->verify_lastactive();
}
if($this->method == "insert" || array_key_exists('away', $user))

			$this->verify_lastactive();
}
if($this->method == "insert" || array_key_exists('away', $user))

Zeile 985Zeile 1039
		{
$this->verify_language();
}

		{
$this->verify_language();
}

		if($this->method == "insert" && array_key_exists('regcheck1', $user) && array_key_exists('regcheck2', $user))





		if($this->method == "insert" || array_key_exists('timezone', $user))
{
$this->verify_timezone();
}
if($this->method == "insert" && array_key_exists('regcheck1', $user) && array_key_exists('regcheck2', $user))

		{
$this->verify_checkfields();
}
if(array_key_exists('birthdayprivacy', $user))
{
$this->verify_birthday_privacy();

		{
$this->verify_checkfields();
}
if(array_key_exists('birthdayprivacy', $user))
{
$this->verify_birthday_privacy();

		}





		}
if($this->method == "insert" || array_key_exists('style', $user))
{
$this->verify_style();
}


$plugins->run_hooks("datahandler_user_validate", $this);


$plugins->run_hooks("datahandler_user_validate", $this);





		// We are done validating, return.
$this->set_validated(true);
if(count($this->get_errors()) > 0)

		// We are done validating, return.
$this->set_validated(true);
if(count($this->get_errors()) > 0)

		{

		{

			return false;

			return false;

		}

		}

		else
{
return true;

		else
{
return true;

Zeile 1010Zeile 1072

/**
* Inserts a user into the database.


/**
* Inserts a user into the database.

 
	*
* @return array

	*/
function insert_user()
{

	*/
function insert_user()
{

Zeile 1175Zeile 1239

/**
* Updates a user in the database.


/**
* Updates a user in the database.

 
	*
* @return bool

	*/
function update_user()
{

	*/
function update_user()
{

Zeile 1186Zeile 1252
			die("The user needs to be validated before inserting it into the DB.");
}
if(count($this->get_errors()) > 0)

			die("The user needs to be validated before inserting it into the DB.");
}
if(count($this->get_errors()) > 0)

		{

		{

			die("The user is not valid.");
}

			die("The user is not valid.");
}





		$user = &$this->data;
$user['uid'] = (int)$user['uid'];
$this->uid = $user['uid'];

		$user = &$this->data;
$user['uid'] = (int)$user['uid'];
$this->uid = $user['uid'];

Zeile 1198Zeile 1264
		if(isset($user['username']))
{
$this->user_update_data['username'] = $db->escape_string($user['username']);

		if(isset($user['username']))
{
$this->user_update_data['username'] = $db->escape_string($user['username']);

		}

		}

		if(isset($user['saltedpw']))
{
$this->user_update_data['password'] = $user['saltedpw'];

		if(isset($user['saltedpw']))
{
$this->user_update_data['password'] = $user['saltedpw'];

Zeile 1221Zeile 1287
		{
$this->user_update_data['avatar'] = $db->escape_string($user['avatar']);
$this->user_update_data['avatartype'] = $db->escape_string($user['avatartype']);

		{
$this->user_update_data['avatar'] = $db->escape_string($user['avatar']);
$this->user_update_data['avatartype'] = $db->escape_string($user['avatartype']);

		}

		}

		if(isset($user['usergroup']))

		if(isset($user['usergroup']))

		{

		{

			$this->user_update_data['usergroup'] = (int)$user['usergroup'];
}
if(isset($user['additionalgroups']))

			$this->user_update_data['usergroup'] = (int)$user['usergroup'];
}
if(isset($user['additionalgroups']))

		{

		{

			$this->user_update_data['additionalgroups'] = $db->escape_string($user['additionalgroups']);
}
if(isset($user['displaygroup']))
{
$this->user_update_data['displaygroup'] = (int)$user['displaygroup'];

			$this->user_update_data['additionalgroups'] = $db->escape_string($user['additionalgroups']);
}
if(isset($user['displaygroup']))
{
$this->user_update_data['displaygroup'] = (int)$user['displaygroup'];

		}

		}

		if(isset($user['usertitle']))
{
$this->user_update_data['usertitle'] = $db->escape_string($user['usertitle']);

		if(isset($user['usertitle']))
{
$this->user_update_data['usertitle'] = $db->escape_string($user['usertitle']);

Zeile 1267Zeile 1333
			$this->user_update_data['aim'] = $db->escape_string($user['aim']);
}
if(isset($user['yahoo']))

			$this->user_update_data['aim'] = $db->escape_string($user['aim']);
}
if(isset($user['yahoo']))

		{

		{

			$this->user_update_data['yahoo'] = $db->escape_string($user['yahoo']);
}
if(isset($user['skype']))

			$this->user_update_data['yahoo'] = $db->escape_string($user['yahoo']);
}
if(isset($user['skype']))

Zeile 1414Zeile 1480
			{
// User was latest to register, update stats
update_stats(array("numusers" => "+0"));

			{
// User was latest to register, update stats
update_stats(array("numusers" => "+0"));

			}
}


			}
}


		return true;
}

/**
* Provides a method to completely delete a user.
*

		return true;
}

/**
* Provides a method to completely delete a user.
*

	 * @param array Array of user information
* @param integer Whether if delete threads/posts or not
* @return boolean True when successful, false if fails

	 * @param array $delete_uids Array of user information
* @param integer $prunecontent Whether if delete threads/posts or not
* @return array

	 */
function delete_user($delete_uids, $prunecontent=0)
{

	 */
function delete_user($delete_uids, $prunecontent=0)
{

Zeile 1451Zeile 1517
		$plugins->run_hooks('datahandler_user_delete_start', $this);

$this->delete_uids = implode(',', $this->delete_uids);

		$plugins->run_hooks('datahandler_user_delete_start', $this);

$this->delete_uids = implode(',', $this->delete_uids);

		
$this->delete_content();












if(empty($this->delete_uids))
{
$this->deleted_users = 0;
$this->return_values = array(
"deleted_users" => $this->deleted_users
);

return $this->return_values;
}

$this->delete_content();


// Delete the user
$query = $db->delete_query('users', "uid IN({$this->delete_uids})");
$this->deleted_users = $db->affected_rows($query);


// Delete the user
$query = $db->delete_query('users', "uid IN({$this->delete_uids})");
$this->deleted_users = $db->affected_rows($query);





		// Are we removing the posts/threads of a user?
if((int)$prunecontent == 1)
{
$this->delete_posts();

		// Are we removing the posts/threads of a user?
if((int)$prunecontent == 1)
{
$this->delete_posts();

		}


			$db->delete_query('announcements', "uid IN({$this->delete_uids})");
}

		else
{
// We're just updating the UID

		else
{
// We're just updating the UID

 
			$db->update_query('pollvotes', array('uid' => 0), "uid IN({$this->delete_uids})");

			$db->update_query('posts', array('uid' => 0), "uid IN({$this->delete_uids})");
$db->update_query('threads', array('uid' => 0), "uid IN({$this->delete_uids})");

			$db->update_query('posts', array('uid' => 0), "uid IN({$this->delete_uids})");
$db->update_query('threads', array('uid' => 0), "uid IN({$this->delete_uids})");

 
			$db->update_query('attachments', array('uid' => 0), "uid IN({$this->delete_uids})");
$db->update_query('announcements', array('uid' => 0), "uid IN({$this->delete_uids})");

		}

		}

 

$db->update_query('privatemessages', array('fromid' => 0), "fromid IN({$this->delete_uids})");
$db->update_query('users', array('referrer' => 0), "referrer IN({$this->delete_uids})");


// Update thread ratings
$query = $db->query("


// Update thread ratings
$query = $db->query("

Zeile 1491Zeile 1574
		// Update forums & threads if user is the lastposter
$db->update_query('forums', array('lastposteruid' => 0), "lastposteruid IN({$this->delete_uids})");
$db->update_query('threads', array('lastposteruid' => 0), "lastposteruid IN({$this->delete_uids})");

		// Update forums & threads if user is the lastposter
$db->update_query('forums', array('lastposteruid' => 0), "lastposteruid IN({$this->delete_uids})");
$db->update_query('threads', array('lastposteruid' => 0), "lastposteruid IN({$this->delete_uids})");


$cache->update_banned();
$cache->update_moderators();

 

// Update forum stats
update_stats(array('numusers' => '-'.$this->deleted_users));


// Update forum stats
update_stats(array('numusers' => '-'.$this->deleted_users));

Zeile 1501Zeile 1581
		$this->return_values = array(
"deleted_users" => $this->deleted_users
);

		$this->return_values = array(
"deleted_users" => $this->deleted_users
);

		
// Update reports cache







$plugins->run_hooks("datahandler_user_delete_end", $this);

// Update cache
$cache->update_banned();
$cache->update_moderators();
$cache->update_forumsdisplay();

		$cache->update_reportedcontent();

		$cache->update_reportedcontent();



 
		$cache->update_awaitingactivation();

		$cache->update_awaitingactivation();


$plugins->run_hooks("datahandler_user_delete_end", $this);






		return $this->return_values;

		return $this->return_values;

	}

/**
* Provides a method to delete users' content
*
* @param array Array of user ids, false if they're already set (eg when using the delete_user function)
*/

	}

/**
* Provides a method to delete users' content
*
* @param array|bool $delete_uids Array of user ids, false if they're already set (eg when using the delete_user function)
*/

	function delete_content($delete_uids=false)
{

	function delete_content($delete_uids=false)
{

		global $db, $plugins;


		global $db, $plugins, $mybb;


		if($delete_uids != false)
{
$this->delete_uids = array_map('intval', (array)$delete_uids);


		if($delete_uids != false)
{
$this->delete_uids = array_map('intval', (array)$delete_uids);


			foreach($this->delete_uids as $key => $uid)
{
if(!$uid || is_super_admin($uid) || $uid == $mybb->user['uid'])
{
// Remove super admins
unset($this->delete_uids[$key]);
}
}

$this->delete_uids = implode(',', $this->delete_uids);
}

$plugins->run_hooks('datahandler_user_delete_content', $this);

$db->delete_query('userfields', "ufid IN({$this->delete_uids})");






			foreach($this->delete_uids as $key => $uid)
{
if(!$uid || is_super_admin($uid) || $uid == $mybb->user['uid'])
{
// Remove super admins
unset($this->delete_uids[$key]);
}
}

$this->delete_uids = implode(',', $this->delete_uids);
}

$plugins->run_hooks('datahandler_user_delete_content', $this);

if(empty($this->delete_uids))
{
return;
}

$db->delete_query('userfields', "ufid IN({$this->delete_uids})");

		$db->delete_query('privatemessages', "uid IN({$this->delete_uids})");
$db->delete_query('events', "uid IN({$this->delete_uids})");
$db->delete_query('moderators', "id IN({$this->delete_uids}) AND isgroup = 0");

		$db->delete_query('privatemessages', "uid IN({$this->delete_uids})");
$db->delete_query('events', "uid IN({$this->delete_uids})");
$db->delete_query('moderators', "id IN({$this->delete_uids}) AND isgroup = 0");

Zeile 1569Zeile 1656
		$db->update_query('reportedcontent', array('uid' => 0), "uid IN({$this->delete_uids})");

// Remove any of the user(s) uploaded avatars

		$db->update_query('reportedcontent', array('uid' => 0), "uid IN({$this->delete_uids})");

// Remove any of the user(s) uploaded avatars

		$query = $db->simple_select('users', 'avatar', "uid IN({$this->delete_uids}) AND avatartype='upload'");
while($avatar = $db->fetch_field($query, 'avatar'))

		require_once MYBB_ROOT.'inc/functions_upload.php';
foreach(explode(',', $this->delete_uids) as $uid)

		{

		{

			$avatar = substr($avatar, 2, -20);
@unlink(MYBB_ROOT.$avatar);

			remove_avatars($uid);


		}

		}



 
	}

	}





	/**
* Provides a method to delete an users posts and threads
*

	/**
* Provides a method to delete an users posts and threads
*

	 * @param array Array of user ids, false if they're already set (eg when using the delete_user function)

	 * @param array|bool $delete_uids Array of user ids, false if they're already set (eg when using the delete_user function)

	 */
function delete_posts($delete_uids=false)

	 */
function delete_posts($delete_uids=false)

	{
global $db, $plugins;

if($delete_uids != false)
{
$this->delete_uids = array_map('intval', (array)$delete_uids);


	{
global $db, $plugins, $mybb;

if($delete_uids != false)
{
$this->delete_uids = array_map('intval', (array)$delete_uids);


			foreach($this->delete_uids as $key => $uid)
{
if(!$uid || is_super_admin($uid) || $uid == $mybb->user['uid'])

			foreach($this->delete_uids as $key => $uid)
{
if(!$uid || is_super_admin($uid) || $uid == $mybb->user['uid'])

Zeile 1601Zeile 1686
			}

$this->delete_uids = implode(',', $this->delete_uids);

			}

$this->delete_uids = implode(',', $this->delete_uids);

		}


		}


		require_once MYBB_ROOT.'inc/class_moderation.php';
$moderation = new Moderation();

$plugins->run_hooks('datahandler_user_delete_posts', $this);

		require_once MYBB_ROOT.'inc/class_moderation.php';
$moderation = new Moderation();

$plugins->run_hooks('datahandler_user_delete_posts', $this);

 

if(empty($this->delete_uids))
{
return;
}


// Threads
$query = $db->simple_select('threads', 'tid', "uid IN({$this->delete_uids})");


// Threads
$query = $db->simple_select('threads', 'tid', "uid IN({$this->delete_uids})");

Zeile 1616Zeile 1706
		}

// Posts

		}

// Posts

		$pids = array();

 
		$query = $db->simple_select('posts', 'pid', "uid IN({$this->delete_uids})");
while($pid = $db->fetch_field($query, 'pid'))
{
$moderation->delete_post($pid);

		$query = $db->simple_select('posts', 'pid', "uid IN({$this->delete_uids})");
while($pid = $db->fetch_field($query, 'pid'))
{
$moderation->delete_post($pid);

			$pids[] = (int)$pid;

 
		}

		}


// Delete Reports made to users's posts/threads
if(!empty($pids))
{
$db->delete_query('reportedcontent', "type='posts' AND id IN(".implode(',', $pids).")");
}
}

	}








/**
* Provides a method to clear an users profile
*


/**
* Provides a method to clear an users profile
*

	 * @param array Array of user ids, false if they're already set (eg when using the delete_user function)
* @param int The new usergroup if the users should be moved (additional usergroups are always removed)

	 * @param array|bool $delete_uids Array of user ids, false if they're already set (eg when using the delete_user function)
* @param int $gid The new usergroup if the users should be moved (additional usergroups are always removed)

	 */
function clear_profile($delete_uids=false, $gid=0)
{

	 */
function clear_profile($delete_uids=false, $gid=0)
{

		global $db, $plugins;

		global $db, $plugins, $mybb;


// delete_uids isn't a nice name, but it's used as the functions above use the same
if($delete_uids != false)


// delete_uids isn't a nice name, but it's used as the functions above use the same
if($delete_uids != false)

		{

		{

			$this->delete_uids = array_map('intval', (array)$delete_uids);

foreach($this->delete_uids as $key => $uid)

			$this->delete_uids = array_map('intval', (array)$delete_uids);

foreach($this->delete_uids as $key => $uid)

Zeile 1685Zeile 1767
		}

$plugins->run_hooks('datahandler_user_clear_profile', $this);

		}

$plugins->run_hooks('datahandler_user_clear_profile', $this);

 

if(empty($this->delete_uids))
{
return;
}


$db->update_query("users", $update, "uid IN({$this->delete_uids})");
$db->delete_query('userfields', "ufid IN({$this->delete_uids})");


$db->update_query("users", $update, "uid IN({$this->delete_uids})");
$db->delete_query('userfields', "ufid IN({$this->delete_uids})");

 

// Remove any of the user(s) uploaded avatars
require_once MYBB_ROOT.'inc/functions_upload.php';
foreach(explode(',', $this->delete_uids) as $uid)
{
remove_avatars($uid);
}

	}
}

	}
}