aboutsummaryrefslogtreecommitdiff
path: root/engine/lib/users.php
diff options
context:
space:
mode:
Diffstat (limited to 'engine/lib/users.php')
-rw-r--r--engine/lib/users.php551
1 files changed, 374 insertions, 177 deletions
diff --git a/engine/lib/users.php b/engine/lib/users.php
index 3a15e9397..e980ee6f8 100644
--- a/engine/lib/users.php
+++ b/engine/lib/users.php
@@ -3,8 +3,8 @@
* Elgg users
* Functions to manage multiple or single users in an Elgg install
*
- * @package Elgg
- * @subpackage Core
+ * @package Elgg.Core
+ * @subpackage DataModel.User
*/
/// Map a username to a cached GUID
@@ -16,7 +16,9 @@ $CODE_TO_GUID_MAP_CACHE = array();
/**
* Return the user specific details of a user by a row.
*
- * @param int $guid
+ * @param int $guid The ElggUser guid
+ *
+ * @return mixed
*/
function get_user_entity_as_row($guid) {
global $CONFIG;
@@ -29,10 +31,16 @@ function get_user_entity_as_row($guid) {
* Create or update the extras table for a given user.
* Call create_entity first.
*
- * @param int $guid
- * @param string $name
- * @param string $description
- * @param string $url
+ * @param int $guid The user's GUID
+ * @param string $name The user's display name
+ * @param string $username The username
+ * @param string $password The password
+ * @param string $salt A salt for the password
+ * @param string $email The user's email address
+ * @param string $language The user's default language
+ * @param string $code A code
+ *
+ * @return bool
*/
function create_user_entity($guid, $name, $username, $password, $salt, $email, $language, $code) {
global $CONFIG;
@@ -50,12 +58,18 @@ function create_user_entity($guid, $name, $username, $password, $salt, $email, $
if ($row) {
// Exists and you have access to it
- if ($exists = get_data_row("SELECT guid from {$CONFIG->dbprefix}users_entity where guid = {$guid}")) {
- $result = update_data("UPDATE {$CONFIG->dbprefix}users_entity set name='$name', username='$username', password='$password', salt='$salt', email='$email', language='$language', code='$code', last_action = ". time() ." where guid = {$guid}");
+ $query = "SELECT guid from {$CONFIG->dbprefix}users_entity where guid = {$guid}";
+ if ($exists = get_data_row($query)) {
+ $query = "UPDATE {$CONFIG->dbprefix}users_entity
+ set name='$name', username='$username', password='$password', salt='$salt',
+ email='$email', language='$language', code='$code', last_action = "
+ . time() . " where guid = {$guid}";
+
+ $result = update_data($query);
if ($result != false) {
// Update succeeded, continue
$entity = get_entity($guid);
- if (trigger_elgg_event('update',$entity->type,$entity)) {
+ if (trigger_elgg_event('update', $entity->type, $entity)) {
return $guid;
} else {
$entity->delete();
@@ -63,10 +77,14 @@ function create_user_entity($guid, $name, $username, $password, $salt, $email, $
}
} else {
// Update failed, attempt an insert.
- $result = insert_data("INSERT into {$CONFIG->dbprefix}users_entity (guid, name, username, password, salt, email, language, code) values ($guid, '$name', '$username', '$password', '$salt', '$email', '$language', '$code')");
- if ($result!==false) {
+ $query = "INSERT into {$CONFIG->dbprefix}users_entity
+ (guid, name, username, password, salt, email, language, code)
+ values ($guid, '$name', '$username', '$password', '$salt', '$email', '$language', '$code')";
+
+ $result = insert_data($query);
+ if ($result !== false) {
$entity = get_entity($guid);
- if (trigger_elgg_event('create',$entity->type,$entity)) {
+ if (trigger_elgg_event('create', $entity->type, $entity)) {
return $guid;
} else {
$entity->delete(); //delete_entity($guid);
@@ -82,15 +100,20 @@ function create_user_entity($guid, $name, $username, $password, $salt, $email, $
* Disables all of a user's entities
*
* @param int $owner_guid The owner GUID
- * @return true|false Depending on success
+ *
+ * @return bool Depending on success
*/
function disable_user_entities($owner_guid) {
global $CONFIG;
$owner_guid = (int) $owner_guid;
if ($entity = get_entity($owner_guid)) {
- if (trigger_elgg_event('disable',$entity->type,$entity)) {
+ if (trigger_elgg_event('disable', $entity->type, $entity)) {
if ($entity->canEdit()) {
- $res = update_data("UPDATE {$CONFIG->dbprefix}entities set enabled='no' where owner_guid={$owner_guid} or container_guid = {$owner_guid}");
+ $query = "UPDATE {$CONFIG->dbprefix}entities
+ set enabled='no' where owner_guid={$owner_guid}
+ or container_guid = {$owner_guid}";
+
+ $res = update_data($query);
return $res;
}
}
@@ -102,8 +125,10 @@ function disable_user_entities($owner_guid) {
/**
* Ban a user
*
- * @param int $user_guid The user guid
- * @param string $reason A reason
+ * @param int $user_guid The user guid
+ * @param string $reason A reason
+ *
+ * @return bool
*/
function ban_user($user_guid, $reason = "") {
global $CONFIG;
@@ -117,7 +142,7 @@ function ban_user($user_guid, $reason = "") {
if (trigger_elgg_event('ban', 'user', $user)) {
// Add reason
if ($reason) {
- create_metadata($user_guid, 'ban_reason', $reason,'', 0, ACCESS_PUBLIC);
+ create_metadata($user_guid, 'ban_reason', $reason, '', 0, ACCESS_PUBLIC);
}
// clear "remember me" cookie code so user cannot login in using it
@@ -135,7 +160,8 @@ function ban_user($user_guid, $reason = "") {
}
// Set ban flag
- return update_data("UPDATE {$CONFIG->dbprefix}users_entity set banned='yes' where guid=$user_guid");
+ $query = "UPDATE {$CONFIG->dbprefix}users_entity set banned='yes' where guid=$user_guid";
+ return update_data($query);
}
return FALSE;
@@ -148,6 +174,8 @@ function ban_user($user_guid, $reason = "") {
* Unban a user.
*
* @param int $user_guid Unban a user.
+ *
+ * @return bool
*/
function unban_user($user_guid) {
global $CONFIG;
@@ -158,7 +186,7 @@ function unban_user($user_guid) {
if (($user) && ($user->canEdit()) && ($user instanceof ElggUser)) {
if (trigger_elgg_event('unban', 'user', $user)) {
- create_metadata($user_guid, 'ban_reason', '','', 0, ACCESS_PUBLIC);
+ create_metadata($user_guid, 'ban_reason', '', '', 0, ACCESS_PUBLIC);
// invalidate memcache for this user
static $newentity_cache;
@@ -170,7 +198,9 @@ function unban_user($user_guid) {
$newentity_cache->delete($user_guid);
}
- return update_data("UPDATE {$CONFIG->dbprefix}users_entity set banned='no' where guid=$user_guid");
+
+ $query = "UPDATE {$CONFIG->dbprefix}users_entity set banned='no' where guid=$user_guid";
+ return update_data($query);
}
return FALSE;
@@ -182,7 +212,8 @@ function unban_user($user_guid) {
/**
* Makes user $guid an admin.
*
- * @param int $guid
+ * @param int $user_guid User guid
+ *
* @return bool
*/
function make_user_admin($user_guid) {
@@ -217,7 +248,8 @@ function make_user_admin($user_guid) {
/**
* Removes user $guid's admin flag.
*
- * @param int $guid
+ * @param int $user_guid User GUID
+ *
* @return bool
*/
function remove_user_admin($user_guid) {
@@ -253,8 +285,12 @@ function remove_user_admin($user_guid) {
* THIS FUNCTION IS DEPRECATED.
*
* Delete a user's extra data.
+ *
* @todo remove
- * @param int $guid
+ *
+ * @param int $guid User GUID
+ *
+ * @return 1
*/
function delete_user_entity($guid) {
system_message(sprintf(elgg_echo('deprecatedfunction'), 'delete_user_entity'));
@@ -266,8 +302,9 @@ function delete_user_entity($guid) {
* Get the sites this user is part of
*
* @param int $user_guid The user's GUID
- * @param int $limit Number of results to return
- * @param int $offset Any indexing offset
+ * @param int $limit Number of results to return
+ * @param int $offset Any indexing offset
+ *
* @return false|array On success, an array of ElggSites
*/
function get_user_sites($user_guid, $limit = 10, $offset = 0) {
@@ -288,9 +325,10 @@ function get_user_sites($user_guid, $limit = 10, $offset = 0) {
/**
* Adds a user to another user's friends list.
*
- * @param int $user_guid The GUID of the friending user
+ * @param int $user_guid The GUID of the friending user
* @param int $friend_guid The GUID of the user to friend
- * @return true|false Depending on success
+ *
+ * @return bool Depending on success
*/
function user_add_friend($user_guid, $friend_guid) {
$user_guid = (int) $user_guid;
@@ -313,9 +351,10 @@ function user_add_friend($user_guid, $friend_guid) {
/**
* Removes a user from another user's friends list.
*
- * @param int $user_guid The GUID of the friending user
+ * @param int $user_guid The GUID of the friending user
* @param int $friend_guid The GUID of the user on the friends list
- * @return true|false Depending on success
+ *
+ * @return bool Depending on success
*/
function user_remove_friend($user_guid, $friend_guid) {
global $CONFIG;
@@ -337,9 +376,10 @@ function user_remove_friend($user_guid, $friend_guid) {
/**
* Determines whether or not a user is another user's friend.
*
- * @param int $user_guid The GUID of the user
+ * @param int $user_guid The GUID of the user
* @param int $friend_guid The GUID of the friend
- * @return true|false
+ *
+ * @return bool
*/
function user_is_friend($user_guid, $friend_guid) {
return check_entity_relationship($user_guid, "friend", $friend_guid);
@@ -348,13 +388,16 @@ function user_is_friend($user_guid, $friend_guid) {
/**
* Obtains a given user's friends
*
- * @param int $user_guid The user's GUID
- * @param string $subtype The subtype of users, if any
- * @param int $limit Number of results to return (default 10)
- * @param int $offset Indexing offset, if any
+ * @param int $user_guid The user's GUID
+ * @param string $subtype The subtype of users, if any
+ * @param int $limit Number of results to return (default 10)
+ * @param int $offset Indexing offset, if any
+ *
* @return false|array Either an array of ElggUsers or false, depending on success
*/
-function get_user_friends($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10, $offset = 0) {
+function get_user_friends($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10,
+$offset = 0) {
+
return elgg_get_entities_from_relationship(array(
'relationship' => 'friend',
'relationship_guid' => $user_guid,
@@ -368,13 +411,16 @@ function get_user_friends($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit
/**
* Obtains the people who have made a given user a friend
*
- * @param int $user_guid The user's GUID
- * @param string $subtype The subtype of users, if any
- * @param int $limit Number of results to return (default 10)
- * @param int $offset Indexing offset, if any
+ * @param int $user_guid The user's GUID
+ * @param string $subtype The subtype of users, if any
+ * @param int $limit Number of results to return (default 10)
+ * @param int $offset Indexing offset, if any
+ *
* @return false|array Either an array of ElggUsers or false, depending on success
*/
-function get_user_friends_of($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10, $offset = 0) {
+function get_user_friends_of($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10,
+$offset = 0) {
+
return elgg_get_entities_from_relationship(array(
'relationship' => 'friend',
'relationship_guid' => $user_guid,
@@ -389,15 +435,18 @@ function get_user_friends_of($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $li
/**
* Obtains a list of objects owned by a user
*
- * @param int $user_guid The GUID of the owning user
- * @param string $subtype Optionally, the subtype of objects
- * @param int $limit The number of results to return (default 10)
- * @param int $offset Indexing offset, if any
- * @param int $timelower The earliest time the entity can have been created. Default: all
- * @param int $timeupper The latest time the entity can have been created. Default: all
+ * @param int $user_guid The GUID of the owning user
+ * @param string $subtype Optionally, the subtype of objects
+ * @param int $limit The number of results to return (default 10)
+ * @param int $offset Indexing offset, if any
+ * @param int $timelower The earliest time the entity can have been created. Default: all
+ * @param int $timeupper The latest time the entity can have been created. Default: all
+ *
* @return false|array An array of ElggObjects or false, depending on success
*/
-function get_user_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10, $offset = 0, $timelower = 0, $timeupper = 0) {
+function get_user_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10,
+$offset = 0, $timelower = 0, $timeupper = 0) {
+
$ntt = elgg_get_entities(array(
'type' => 'object',
'subtype' => $subtype,
@@ -414,13 +463,16 @@ function get_user_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit
/**
* Counts the objects (optionally of a particular subtype) owned by a user
*
- * @param int $user_guid The GUID of the owning user
- * @param string $subtype Optionally, the subtype of objects
- * @param int $timelower The earliest time the entity can have been created. Default: all
- * @param int $timeupper The latest time the entity can have been created. Default: all
+ * @param int $user_guid The GUID of the owning user
+ * @param string $subtype Optionally, the subtype of objects
+ * @param int $timelower The earliest time the entity can have been created. Default: all
+ * @param int $timeupper The latest time the entity can have been created. Default: all
+ *
* @return int The number of objects the user owns (of this subtype)
*/
-function count_user_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $timelower = 0, $timeupper = 0) {
+function count_user_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $timelower = 0,
+$timeupper = 0) {
+
$total = elgg_get_entities(array(
'type' => 'object',
'subtype' => $subtype,
@@ -438,40 +490,47 @@ function count_user_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $tim
*
* @see elgg_view_entity_list
*
- * @param int $user_guid The GUID of the user
- * @param string $subtype The object subtype
- * @param int $limit The number of entities to display on a page
- * @param true|false $fullview Whether or not to display the full view (default: true)
- * @param true|false $viewtypetoggle Whether or not to allow gallery view (default: true)
- * @param true|false $pagination Whether to display pagination (default: true)
- * @param int $timelower The earliest time the entity can have been created. Default: all
- * @param int $timeupper The latest time the entity can have been created. Default: all
+ * @param int $user_guid The GUID of the user
+ * @param string $subtype The object subtype
+ * @param int $limit The number of entities to display on a page
+ * @param bool $fullview Whether or not to display the full view (default: true)
+ * @param bool $viewtypetoggle Whether or not to allow gallery view (default: true)
+ * @param bool $pagination Whether to display pagination (default: true)
+ * @param int $timelower The earliest time the entity can have been created. Default: all
+ * @param int $timeupper The latest time the entity can have been created. Default: all
+ *
* @return string The list in a form suitable to display
*/
-function list_user_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10, $fullview = true, $viewtypetoggle = true, $pagination = true, $timelower = 0, $timeupper = 0) {
+function list_user_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10,
+$fullview = true, $viewtypetoggle = true, $pagination = true, $timelower = 0, $timeupper = 0) {
+
$offset = (int) get_input('offset');
$limit = (int) $limit;
- $count = (int) count_user_objects($user_guid, $subtype,$timelower,$timeupper);
+ $count = (int) count_user_objects($user_guid, $subtype, $timelower, $timeupper);
$entities = get_user_objects($user_guid, $subtype, $limit, $offset, $timelower, $timeupper);
- return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $pagination);
+ return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle,
+ $pagination);
}
/**
* Obtains a list of objects owned by a user's friends
*
- * @param int $user_guid The GUID of the user to get the friends of
- * @param string $subtype Optionally, the subtype of objects
- * @param int $limit The number of results to return (default 10)
- * @param int $offset Indexing offset, if any
- * @param int $timelower The earliest time the entity can have been created. Default: all
- * @param int $timeupper The latest time the entity can have been created. Default: all
+ * @param int $user_guid The GUID of the user to get the friends of
+ * @param string $subtype Optionally, the subtype of objects
+ * @param int $limit The number of results to return (default 10)
+ * @param int $offset Indexing offset, if any
+ * @param int $timelower The earliest time the entity can have been created. Default: all
+ * @param int $timeupper The latest time the entity can have been created. Default: all
+ *
* @return false|array An array of ElggObjects or false, depending on success
*/
-function get_user_friends_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10, $offset = 0, $timelower = 0, $timeupper = 0) {
+function get_user_friends_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $limit = 10,
+$offset = 0, $timelower = 0, $timeupper = 0) {
+
if ($friends = get_user_friends($user_guid, "", 999999, 0)) {
$friendguids = array();
- foreach($friends as $friend) {
+ foreach ($friends as $friend) {
$friendguids[] = $friend->getGUID();
}
return elgg_get_entities(array(
@@ -491,16 +550,19 @@ function get_user_friends_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE
/**
* Counts the number of objects owned by a user's friends
*
- * @param int $user_guid The GUID of the user to get the friends of
- * @param string $subtype Optionally, the subtype of objects
- * @param int $timelower The earliest time the entity can have been created. Default: all
- * @param int $timeupper The latest time the entity can have been created. Default: all
+ * @param int $user_guid The GUID of the user to get the friends of
+ * @param string $subtype Optionally, the subtype of objects
+ * @param int $timelower The earliest time the entity can have been created. Default: all
+ * @param int $timeupper The latest time the entity can have been created. Default: all
+ *
* @return int The number of objects
*/
-function count_user_friends_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE, $timelower = 0, $timeupper = 0) {
+function count_user_friends_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VALUE,
+$timelower = 0, $timeupper = 0) {
+
if ($friends = get_user_friends($user_guid, "", 999999, 0)) {
$friendguids = array();
- foreach($friends as $friend) {
+ foreach ($friends as $friend) {
$friendguids[] = $friend->getGUID();
}
return elgg_get_entities(array(
@@ -521,44 +583,55 @@ function count_user_friends_objects($user_guid, $subtype = ELGG_ENTITIES_ANY_VAL
*
* @see elgg_view_entity_list
*
- * @param int $user_guid The GUID of the user
- * @param string $subtype The object subtype
- * @param int $limit The number of entities to display on a page
- * @param true|false $fullview Whether or not to display the full view (default: true)
- * @param true|false $viewtypetoggle Whether or not to allow you to flip to gallery mode (default: true)
- * @param true|false $pagination Whether to display pagination (default: true)
- * @param int $timelower The earliest time the entity can have been created. Default: all
- * @param int $timeupper The latest time the entity can have been created. Default: all
+ * @param int $user_guid The GUID of the user
+ * @param string $subtype The object subtype
+ * @param int $limit The number of entities to display on a page
+ * @param bool $fullview Whether or not to display the full view (default: true)
+ * @param bool $viewtypetoggle Whether or not to allow you to flip to gallery mode (default: true)
+ * @param bool $pagination Whether to display pagination (default: true)
+ * @param int $timelower The earliest time the entity can have been created. Default: all
+ * @param int $timeupper The latest time the entity can have been created. Default: all
+ *
* @return string The list in a form suitable to display
*/
-function list_user_friends_objects($user_guid, $subtype = "", $limit = 10, $fullview = true, $viewtypetoggle = true, $pagination = true, $timelower = 0, $timeupper = 0) {
+function list_user_friends_objects($user_guid, $subtype = "", $limit = 10, $fullview = true,
+$viewtypetoggle = true, $pagination = true, $timelower = 0, $timeupper = 0) {
+
$offset = (int) get_input('offset');
$limit = (int) $limit;
$count = (int) count_user_friends_objects($user_guid, $subtype, $timelower, $timeupper);
- $entities = get_user_friends_objects($user_guid, $subtype, $limit, $offset, $timelower, $timeupper);
- return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview, $viewtypetoggle, $pagination);
+ $entities = get_user_friends_objects($user_guid, $subtype, $limit, $offset,
+ $timelower, $timeupper);
+
+ return elgg_view_entity_list($entities, $count, $offset, $limit, $fullview,
+ $viewtypetoggle, $pagination);
}
/**
* Get user objects by an array of metadata
*
- * @param int $user_guid The GUID of the owning user
- * @param string $subtype Optionally, the subtype of objects
- * @paran array $metadata An array of metadata
- * @param int $limit The number of results to return (default 10)
- * @param int $offset Indexing offset, if any
+ * @param int $user_guid The GUID of the owning user
+ * @param string $subtype Optionally, the subtype of objects
+ * @param array $metadata An array of metadata
+ * @param int $limit The number of results to return (default 10)
+ * @param int $offset Indexing offset, if any
+ *
* @return false|array An array of ElggObjects or false, depending on success
*/
-function get_user_objects_by_metadata($user_guid, $subtype = "", $metadata = array(), $limit = 0, $offset = 0) {
- return get_entities_from_metadata_multi($metadata,"object",$subtype,$user_guid,$limit,$offset);
+function get_user_objects_by_metadata($user_guid, $subtype = "", $metadata = array(),
+$limit = 0, $offset = 0) {
+ return get_entities_from_metadata_multi($metadata, "object", $subtype, $user_guid,
+ $limit, $offset);
}
/**
* Get a user object from a GUID.
*
* This function returns an ElggUser from a given GUID.
+ *
* @param int $guid The GUID
+ *
* @return ElggUser|false
*/
function get_user($guid) {
@@ -568,7 +641,6 @@ function get_user($guid) {
}
if ((!empty($result)) && (!($result instanceof ElggUser))) {
- //throw new InvalidClassException(sprintf(elgg_echo('InvalidClassException:NotValidElggStar'), $guid, 'ElggUser'));
return false;
}
@@ -583,6 +655,7 @@ function get_user($guid) {
* Get user by username
*
* @param string $username The user's username
+ *
* @return ElggUser|false Depending on success
*/
function get_user_by_username($username) {
@@ -592,11 +665,16 @@ function get_user_by_username($username) {
$access = get_access_sql_suffix('e');
// Caching
- if ( (isset($USERNAME_TO_GUID_MAP_CACHE[$username])) && (retrieve_cached_entity($USERNAME_TO_GUID_MAP_CACHE[$username])) ) {
+ if ((isset($USERNAME_TO_GUID_MAP_CACHE[$username]))
+ && (retrieve_cached_entity($USERNAME_TO_GUID_MAP_CACHE[$username]))) {
return retrieve_cached_entity($USERNAME_TO_GUID_MAP_CACHE[$username]);
}
- $row = get_data_row("SELECT e.* from {$CONFIG->dbprefix}users_entity u join {$CONFIG->dbprefix}entities e on e.guid=u.guid where u.username='$username' and $access ");
+ $query = "SELECT e.* from {$CONFIG->dbprefix}users_entity u
+ join {$CONFIG->dbprefix}entities e on e.guid=u.guid
+ where u.username='$username' and $access ";
+
+ $row = get_data_row($query);
if ($row) {
$USERNAME_TO_GUID_MAP_CACHE[$username] = $row->guid;
return new ElggUser($row);
@@ -609,6 +687,7 @@ function get_user_by_username($username) {
* Get user by session code
*
* @param string $code The session code
+ *
* @return ElggUser|false Depending on success
*/
function get_user_by_code($code) {
@@ -619,11 +698,17 @@ function get_user_by_code($code) {
$access = get_access_sql_suffix('e');
// Caching
- if ( (isset($CODE_TO_GUID_MAP_CACHE[$code])) && (retrieve_cached_entity($CODE_TO_GUID_MAP_CACHE[$code])) ) {
+ if ((isset($CODE_TO_GUID_MAP_CACHE[$code]))
+ && (retrieve_cached_entity($CODE_TO_GUID_MAP_CACHE[$code]))) {
+
return retrieve_cached_entity($CODE_TO_GUID_MAP_CACHE[$code]);
}
- $row = get_data_row("SELECT e.* from {$CONFIG->dbprefix}users_entity u join {$CONFIG->dbprefix}entities e on e.guid=u.guid where u.code='$code' and $access");
+ $query = "SELECT e.* from {$CONFIG->dbprefix}users_entity u
+ join {$CONFIG->dbprefix}entities e on e.guid=u.guid
+ where u.code='$code' and $access";
+
+ $row = get_data_row($query);
if ($row) {
$CODE_TO_GUID_MAP_CACHE[$code] = $row->guid;
return new ElggUser($row);
@@ -636,6 +721,7 @@ function get_user_by_code($code) {
* Get an array of users from their
*
* @param string $email Email address.
+ *
* @return Array of users
*/
function get_user_by_email($email) {
@@ -645,7 +731,9 @@ function get_user_by_email($email) {
$access = get_access_sql_suffix('e');
- $query = "SELECT e.* from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}users_entity u on e.guid=u.guid where email='$email' and $access";
+ $query = "SELECT e.* from {$CONFIG->dbprefix}entities e
+ join {$CONFIG->dbprefix}users_entity u on e.guid=u.guid
+ where email='$email' and $access";
return get_data($query, 'entity_row_to_elggstar');
}
@@ -653,11 +741,13 @@ function get_user_by_email($email) {
/**
* Searches for a user based on a complete or partial name or username.
*
- * @param string $criteria The partial or full name or username.
- * @param int $limit Limit of the search.
- * @param int $offset Offset.
- * @param string $order_by The order.
- * @param boolean $count Whether to return the count of results or just the results.
+ * @param string $criteria The partial or full name or username.
+ * @param int $limit Limit of the search.
+ * @param int $offset Offset.
+ * @param string $order_by The order.
+ * @param boolean $count Whether to return the count of results or just the results.
+ *
+ * @return mixed
* @deprecated 1.7
*/
function search_for_user($criteria, $limit = 10, $offset = 0, $order_by = "", $count = false) {
@@ -680,13 +770,14 @@ function search_for_user($criteria, $limit = 10, $offset = 0, $order_by = "", $c
} else {
$query = "SELECT e.* ";
}
- $query .= "from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}users_entity u on e.guid=u.guid where ";
- // $query .= " match(u.name,u.username) against ('$criteria') ";
+ $query .= "from {$CONFIG->dbprefix}entities e
+ join {$CONFIG->dbprefix}users_entity u on e.guid=u.guid where ";
+
$query .= "(u.name like \"%{$criteria}%\" or u.username like \"%{$criteria}%\")";
$query .= " and $access";
if (!$count) {
- $query .= " order by $order_by limit $offset, $limit"; // Add order and limit
+ $query .= " order by $order_by limit $offset, $limit";
return get_data($query, "entity_row_to_elggstar");
} else {
if ($count = get_data_row($query)) {
@@ -701,9 +792,11 @@ function search_for_user($criteria, $limit = 10, $offset = 0, $order_by = "", $c
*
* @see elgg_view_entity_list
*
- * @param string $tag Search criteria
- * @param int $limit The number of entities to display on a page
+ * @param string $tag Search criteria
+ * @param int $limit The number of entities to display on a page
+ *
* @return string The list in a form suitable to display
+ *
* @deprecated 1.7
*/
function list_user_search($tag, $limit = 10) {
@@ -721,8 +814,10 @@ function list_user_search($tag, $limit = 10) {
* $seconds seconds.
*
* @param int $seconds Number of seconds (default 600 = 10min)
- * @param int $limit Limit, default 10.
- * @param int $offset Offset, defualt 0.
+ * @param int $limit Limit, default 10.
+ * @param int $offset Offset, defualt 0.
+ *
+ * @return mixed
*/
function find_active_users($seconds = 600, $limit = 10, $offset = 0) {
global $CONFIG;
@@ -735,7 +830,10 @@ function find_active_users($seconds = 600, $limit = 10, $offset = 0) {
$access = get_access_sql_suffix("e");
- $query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e join {$CONFIG->dbprefix}users_entity u on e.guid = u.guid where u.last_action >= {$time} and $access order by u.last_action desc limit {$offset},{$limit}";
+ $query = "SELECT distinct e.* from {$CONFIG->dbprefix}entities e
+ join {$CONFIG->dbprefix}users_entity u on e.guid = u.guid
+ where u.last_action >= {$time} and $access
+ order by u.last_action desc limit {$offset}, {$limit}";
return get_data($query, "entity_row_to_elggstar");
}
@@ -743,7 +841,9 @@ function find_active_users($seconds = 600, $limit = 10, $offset = 0) {
/**
* Generate and send a password request email to a given user's registered email address.
*
- * @param int $user_guid
+ * @param int $user_guid User GUID
+ *
+ * @return bool
*/
function send_new_password_request($user_guid) {
global $CONFIG;
@@ -754,7 +854,7 @@ function send_new_password_request($user_guid) {
if ($user) {
// generate code
$code = generate_random_cleartext_password();
- //create_metadata($user_guid, 'conf_code', $code,'', 0, ACCESS_PRIVATE);
+ //create_metadata($user_guid, 'conf_code', $code, '', 0, ACCESS_PRIVATE);
set_private_setting($user_guid, 'passwd_conf_code', $code);
// generate link
@@ -763,7 +863,8 @@ function send_new_password_request($user_guid) {
// generate email
$email = sprintf(elgg_echo('email:resetreq:body'), $user->name, $_SERVER['REMOTE_ADDR'], $link);
- return notify_user($user->guid, $CONFIG->site->guid, elgg_echo('email:resetreq:subject'), $email, NULL, 'email');
+ return notify_user($user->guid, $CONFIG->site->guid,
+ elgg_echo('email:resetreq:subject'), $email, NULL, 'email');
}
return false;
@@ -774,8 +875,10 @@ function send_new_password_request($user_guid) {
*
* This can only be called from execute_new_password_request().
*
- * @param int $user_guid The user.
- * @param string $password password text (which will then be converted into a hash and stored)
+ * @param int $user_guid The user.
+ * @param string $password Text (which will then be converted into a hash and stored)
+ *
+ * @return bool
*/
function force_user_password_reset($user_guid, $password) {
global $CONFIG;
@@ -789,7 +892,9 @@ function force_user_password_reset($user_guid, $password) {
$hash = generate_user_password($user, $password);
- return update_data("UPDATE {$CONFIG->dbprefix}users_entity set password='$hash', salt='$salt' where guid=$user_guid");
+ $query = "UPDATE {$CONFIG->dbprefix}users_entity
+ set password='$hash', salt='$salt' where guid=$user_guid";
+ return update_data($query);
}
}
@@ -799,8 +904,10 @@ function force_user_password_reset($user_guid, $password) {
/**
* Validate and execute a password reset for a user.
*
- * @param int $user_guid The user id
+ * @param int $user_guid The user id
* @param string $conf_code Confirmation code as sent in the request email.
+ *
+ * @return mixed
*/
function execute_new_password_request($user_guid, $conf_code) {
global $CONFIG;
@@ -818,7 +925,8 @@ function execute_new_password_request($user_guid, $conf_code) {
$email = sprintf(elgg_echo('email:resetpassword:body'), $user->name, $password);
- return notify_user($user->guid, $CONFIG->site->guid, elgg_echo('email:resetpassword:subject'), $email, NULL, 'email');
+ return notify_user($user->guid, $CONFIG->site->guid,
+ elgg_echo('email:resetpassword:subject'), $email, NULL, 'email');
}
}
@@ -828,8 +936,9 @@ function execute_new_password_request($user_guid, $conf_code) {
/**
* Handles pages for password reset requests.
*
- * @param unknown_type $page
- * @return unknown_type
+ * @param array $page Pages array
+ *
+ * @return void
*/
function elgg_user_resetpassword_page_handler($page) {
global $CONFIG;
@@ -873,9 +982,11 @@ function elgg_user_resetpassword_page_handler($page) {
}
/**
- * Simple function that will generate a random clear text password suitable for feeding into generate_user_password().
+ * Simple function that will generate a random clear text password
+ * suitable for feeding into generate_user_password().
*
* @see generate_user_password
+ *
* @return string
*/
function generate_random_cleartext_password() {
@@ -885,10 +996,10 @@ function generate_random_cleartext_password() {
/**
* Generate a password for a user, currently uses MD5.
*
- * Later may introduce salting etc.
+ * @param ElggUser $user The user this is being generated for.
+ * @param string $password Password in clear text
*
- * @param ElggUser $user The user this is being generated for.
- * @param string $password Password in clear text
+ * @return string
*/
function generate_user_password(ElggUser $user, $password) {
return md5($password . $user->salt);
@@ -899,7 +1010,9 @@ function generate_user_password(ElggUser $user, $password) {
*
* This should only permit chars that are valid on the file system as well.
*
- * @param string $username
+ * @param string $username Username
+ *
+ * @return bool
* @throws RegistrationException on invalid
*/
function validate_username($username) {
@@ -915,14 +1028,13 @@ function validate_username($username) {
}
// Blacklist for bad characters (partially nicked from mediawiki)
-
$blacklist = '/[' .
- '\x{0080}-\x{009f}' . # iso-8859-1 control chars
- '\x{00a0}' . # non-breaking space
- '\x{2000}-\x{200f}' . # various whitespace
- '\x{2028}-\x{202f}' . # breaks and control chars
- '\x{3000}' . # ideographic space
- '\x{e000}-\x{f8ff}' . # private use
+ '\x{0080}-\x{009f}' . // iso-8859-1 control chars
+ '\x{00a0}' . // non-breaking space
+ '\x{2000}-\x{200f}' . // various whitespace
+ '\x{2028}-\x{202f}' . // breaks and control chars
+ '\x{3000}' . // ideographic space
+ '\x{e000}-\x{f8ff}' . // private use
']/u';
if (
@@ -934,20 +1046,25 @@ function validate_username($username) {
// Belts and braces
// @todo Tidy into main unicode
$blacklist2 = '\'/\\"*& ?#%^(){}[]~?<>;|¬`@-+=';
- for ($n=0; $n < strlen($blacklist2); $n++) {
- if (strpos($username, $blacklist2[$n])!==false) {
- throw new RegistrationException(sprintf(elgg_echo('registration:invalidchars'), $blacklist2[$n], $blacklist2));
+
+ for ($n = 0; $n < strlen($blacklist2); $n++) {
+ if (strpos($username, $blacklist2[$n]) !== false) {
+ $msg = sprintf(elgg_echo('registration:invalidchars'), $blacklist2[$n], $blacklist2);
+ throw new RegistrationException($msg);
}
}
$result = true;
- return trigger_plugin_hook('registeruser:validate:username', 'all', array('username' => $username), $result);
+ return trigger_plugin_hook('registeruser:validate:username', 'all',
+ array('username' => $username), $result);
}
/**
* Simple validation of a password.
*
- * @param string $password
+ * @param string $password Clear text password
+ *
+ * @return bool
* @throws RegistrationException on invalid
*/
function validate_password($password) {
@@ -958,13 +1075,15 @@ function validate_password($password) {
}
$result = true;
- return trigger_plugin_hook('registeruser:validate:password', 'all', array('password' => $password), $result);
+ return trigger_plugin_hook('registeruser:validate:password', 'all',
+ array('password' => $password), $result);
}
/**
* Simple validation of a email.
*
- * @param string $address
+ * @param string $address Email address
+ *
* @throws RegistrationException on invalid
* @return bool
*/
@@ -975,21 +1094,27 @@ function validate_email_address($address) {
// Got here, so lets try a hook (defaulting to ok)
$result = true;
- return trigger_plugin_hook('registeruser:validate:email', 'all', array('email' => $address), $result);
+ return trigger_plugin_hook('registeruser:validate:email', 'all',
+ array('email' => $address), $result);
}
/**
* Registers a user, returning false if the username already exists
*
- * @param string $username The username of the new user
- * @param string $password The password
- * @param string $name The user's display name
- * @param string $email Their email address
- * @param bool $allow_multiple_emails Allow the same email address to be registered multiple times?
- * @param int $friend_guid Optionally, GUID of a user this user will friend once fully registered
+ * @param string $username The username of the new user
+ * @param string $password The password
+ * @param string $name The user's display name
+ * @param string $email Their email address
+ * @param bool $allow_multiple_emails Allow the same email address to be
+ * registered multiple times?
+ * @param int $friend_guid GUID of a user to friend once fully registered
+ * @param string $invitecode An invite code from a friend
+ *
* @return int|false The new user's GUID; false on failure
*/
-function register_user($username, $password, $name, $email, $allow_multiple_emails = false, $friend_guid = 0, $invitecode = '') {
+function register_user($username, $password, $name, $email,
+$allow_multiple_emails = false, $friend_guid = 0, $invitecode = '') {
+
// Load the configuration
global $CONFIG;
@@ -1084,6 +1209,7 @@ function register_user($username, $password, $name, $email, $allow_multiple_emai
* Generates a unique invite code for a user
*
* @param string $username The username of the user sending the invitation
+ *
* @return string Invite code
*/
function generate_invite_code($username) {
@@ -1094,24 +1220,32 @@ function generate_invite_code($username) {
/**
* Adds collection submenu items
*
+ * @return void
*/
function collections_submenu_items() {
global $CONFIG;
$user = get_loggedin_user();
- add_submenu_item(elgg_echo('friends:collections'), $CONFIG->wwwroot . "pg/collections/" . $user->username);
+
+ add_submenu_item(elgg_echo('friends:collections'),
+ $CONFIG->wwwroot . "pg/collections/" . $user->username);
+
add_submenu_item(elgg_echo('friends:collections:add'), $CONFIG->wwwroot . "pg/collections/add");
}
/**
* Page handler for friends
*
+ * @param array $page_elements Page elements
+ *
+ * @return void
*/
function friends_page_handler($page_elements) {
if (isset($page_elements[0]) && $user = get_user_by_username($page_elements[0])) {
set_page_owner($user->getGUID());
}
if (get_loggedin_userid() == page_owner()) {
- // collections_submenu_items(); disabled for now as we no longer use friends collections (replaced by shared access)
+ // disabled for now as we no longer use friends collections (replaced by shared access)
+ // collections_submenu_items();
}
require_once(dirname(dirname(dirname(__FILE__))) . "/pages/friends/index.php");
}
@@ -1119,13 +1253,17 @@ function friends_page_handler($page_elements) {
/**
* Page handler for friends of
*
+ * @param array $page_elements Page elements
+ *
+ * @return void
*/
function friends_of_page_handler($page_elements) {
if (isset($page_elements[0]) && $user = get_user_by_username($page_elements[0])) {
set_page_owner($user->getGUID());
}
if (get_loggedin_userid() == page_owner()) {
- // collections_submenu_items(); disabled for now as we no longer use friends collections (replaced by shared access)
+ // disabled for now as we no longer use friends collections (replaced by shared access)
+ // collections_submenu_items();
}
require_once(dirname(dirname(dirname(__FILE__))) . "/pages/friends/of.php");
}
@@ -1133,6 +1271,9 @@ function friends_of_page_handler($page_elements) {
/**
* Page handler for friends collections
*
+ * @param array $page_elements Page elements
+ *
+ * @return void
*/
function collections_page_handler($page_elements) {
if (isset($page_elements[0])) {
@@ -1154,6 +1295,10 @@ function collections_page_handler($page_elements) {
/**
* Page handler for dashboard
+ *
+ * @param array $page_elements Page elements
+ *
+ * @return void
*/
function dashboard_page_handler($page_elements) {
require_once(dirname(dirname(dirname(__FILE__))) . "/pages/dashboard/index.php");
@@ -1162,6 +1307,10 @@ function dashboard_page_handler($page_elements) {
/**
* Page handler for registration
+ *
+ * @param array $page_elements Page elements
+ *
+ * @return void
*/
function registration_page_handler($page_elements) {
require_once(dirname(dirname(dirname(__FILE__))) . "/pages/account/register.php");
@@ -1172,6 +1321,9 @@ function registration_page_handler($page_elements) {
*
* This is a fallback for non-JS users who click on the
* dropdown login link.
+ *
+ * @return void
+ * @todo finish
*/
function elgg_user_login_page_handler() {
$content = elgg_view_layout('one_column', elgg_view('account/forms/login'));
@@ -1187,34 +1339,46 @@ function elgg_user_login_page_handler() {
* Sets the last action time of the given user to right now.
*
* @param int $user_guid The user GUID
+ *
+ * @return void
*/
function set_last_action($user_guid) {
$user_guid = (int) $user_guid;
global $CONFIG;
$time = time();
- execute_delayed_write_query("UPDATE {$CONFIG->dbprefix}users_entity set prev_last_action = last_action, last_action = {$time} where guid = {$user_guid}");
+ $query = "UPDATE {$CONFIG->dbprefix}users_entity
+ set prev_last_action = last_action,
+ last_action = {$time} where guid = {$user_guid}";
+
+ execute_delayed_write_query($query);
}
/**
* Sets the last logon time of the given user to right now.
*
* @param int $user_guid The user GUID
+ *
+ * @return boid
*/
function set_last_login($user_guid) {
$user_guid = (int) $user_guid;
global $CONFIG;
$time = time();
- execute_delayed_write_query("UPDATE {$CONFIG->dbprefix}users_entity set prev_last_login = last_login, last_login = {$time} where guid = {$user_guid}");
+ $query = "UPDATE {$CONFIG->dbprefix}users_entity
+ set prev_last_login = last_login, last_login = {$time} where guid = {$user_guid}";
+
+ execute_delayed_write_query($query);
}
/**
* Creates a relationship between this site and the user.
*
- * @param $event
- * @param $object_type
- * @param $object
+ * @param string $event create
+ * @param string $object_type user
+ * @param ElggUser $object User object
+ *
* @return bool
*/
function user_create_hook_add_site_relationship($event, $object_type, $object) {
@@ -1226,23 +1390,32 @@ function user_create_hook_add_site_relationship($event, $object_type, $object) {
/**
* Sets up user-related menu items
*
+ * @return void
*/
function users_pagesetup() {
// Load config
global $CONFIG;
//add submenu options
- if (get_context() == "friends" || get_context() == "friendsof") { // || get_context() == "collections") { - disabled as we no longer use collections
- add_submenu_item(elgg_echo('friends'),$CONFIG->wwwroot."pg/friends/" . page_owner_entity()->username);
- add_submenu_item(elgg_echo('friends:of'),$CONFIG->wwwroot."pg/friendsof/" . page_owner_entity()->username);
- if(is_plugin_enabled('members'))
+ if (get_context() == "friends" || get_context() == "friendsof") {
+ // || get_context() == "collections") { - disabled as we no longer use collections
+
+ add_submenu_item(elgg_echo('friends'), $CONFIG->wwwroot . "pg/friends/"
+ . page_owner_entity()->username);
+
+ add_submenu_item(elgg_echo('friends:of'), $CONFIG->wwwroot . "pg/friendsof/"
+ . page_owner_entity()->username);
+
+ if (is_plugin_enabled('members')) {
add_submenu_item(elgg_echo('members:browse'), $CONFIG->wwwroot . "mod/members/index.php");
+ }
}
}
/**
* Users initialisation function, which establishes the page handler
*
+ * @return void
*/
function users_init() {
// Load config
@@ -1253,7 +1426,8 @@ function users_init() {
/*
if ( isloggedin() && is_plugin_enabled('profile') ) {
$user = get_loggedin_user();
- add_menu(elgg_echo('friends'), $CONFIG->wwwroot . "pg/friends/" . $user->username, array(), 'core:friends');
+ add_menu(elgg_echo('friends'), $CONFIG->wwwroot .
+ "pg/friends/" . $user->username, array(), 'core:friends');
}
*/
@@ -1299,16 +1473,24 @@ function users_init() {
//register_action("user/language");
// Register the user type
- register_entity_type('user','');
+ register_entity_type('user', '');
- register_plugin_hook('usersettings:save','user','users_settings_save');
+ register_plugin_hook('usersettings:save', 'user', 'users_settings_save');
register_elgg_event_handler('create', 'user', 'user_create_hook_add_site_relationship');
}
/**
* Returns a formatted list of users suitable for injecting into search.
+ *
* @deprecated 1.7
+ *
+ * @param string $hook Hook name
+ * @param string $user User?
+ * @param mixed $returnvalue Previous hook's return value
+ * @param mixed $tag Tag to search against
+ *
+ * @return void
*/
function search_list_users_by_name($hook, $user, $returnvalue, $tag) {
elgg_deprecated_notice('search_list_users_by_name() was deprecated by new search', 1.7);
@@ -1318,20 +1500,29 @@ function search_list_users_by_name($hook, $user, $returnvalue, $tag) {
$object = get_input('object');
if (!get_input('offset') && (empty($object) || $object == 'user')) {
- if ($users = search_for_user($tag,$threshold)) {
- $countusers = search_for_user($tag,0,0,"",true);
+ if ($users = search_for_user($tag, $threshold)) {
+ $countusers = search_for_user($tag, 0, 0, "", true);
- $return = elgg_view('user/search/startblurb',array('count' => $countusers, 'tag' => $tag));
- foreach($users as $user) {
+ $return = elgg_view('user/search/startblurb', array('count' => $countusers, 'tag' => $tag));
+ foreach ($users as $user) {
$return .= elgg_view_entity($user);
}
- $return .= elgg_view('user/search/finishblurb',array('count' => $countusers, 'threshold' => $threshold, 'tag' => $tag));
+
+ $vars = array('count' => $countusers, 'threshold' => $threshold, 'tag' => $tag);
+ $return .= elgg_view('user/search/finishblurb', $vars);
return $return;
}
}
}
+/**
+ * Saves user settings by directly including actions.
+ *
+ * @todo this is dirty.
+ *
+ * @return void
+ */
function users_settings_save() {
global $CONFIG;
include($CONFIG->path . "actions/user/name.php");
@@ -1343,6 +1534,13 @@ function users_settings_save() {
/**
* Runs unit tests for ElggObject
+ *
+ * @param sting $hook unit_test
+ * @param string $type system
+ * @param mixed $value Array of tests
+ * @param mixed $params Params
+ *
+ * @return array
*/
function users_test($hook, $type, $value, $params) {
global $CONFIG;
@@ -1350,7 +1548,6 @@ function users_test($hook, $type, $value, $params) {
return $value;
}
-//register actions *************************************************************
-register_elgg_event_handler('init','system','users_init',0);
-register_elgg_event_handler('pagesetup','system','users_pagesetup',0);
+register_elgg_event_handler('init', 'system', 'users_init', 0);
+register_elgg_event_handler('pagesetup', 'system', 'users_pagesetup', 0);
register_plugin_hook('unit_test', 'system', 'users_test'); \ No newline at end of file