Elgg  Version 1.9
users.php
Go to the documentation of this file.
1 <?php
10 
17 
28 
29  $guid = (int)$guid;
30  return get_data_row("SELECT * from {$CONFIG->dbprefix}users_entity where guid=$guid");
31 }
32 
42  $owner_guid = (int) $owner_guid;
44  if (elgg_trigger_event('disable', $entity->type, $entity)) {
45  if ($entity->canEdit()) {
46  $query = "UPDATE {$CONFIG->dbprefix}entities
47  set enabled='no' where owner_guid={$owner_guid}
48  or container_guid = {$owner_guid}";
49 
50  $res = update_data($query);
51  return $res;
52  }
53  }
54  }
55 
56  return false;
57 }
58 
67 function ban_user($user_guid, $reason = "") {
69 
70  $user_guid = (int)$user_guid;
71 
73 
74  if (($user) && ($user->canEdit()) && ($user instanceof ElggUser)) {
75  if (elgg_trigger_event('ban', 'user', $user)) {
76  // Add reason
77  if ($reason) {
78  create_metadata($user_guid, 'ban_reason', $reason, '', 0, ACCESS_PUBLIC);
79  }
80 
81  // invalidate memcache for this user
82  static $newentity_cache;
83  if ((!$newentity_cache) && (is_memcache_available())) {
84  $newentity_cache = new ElggMemcache('new_entity_cache');
85  }
86 
87  if ($newentity_cache) {
88  $newentity_cache->delete($user_guid);
89  }
90 
91  // Set ban flag
92  $query = "UPDATE {$CONFIG->dbprefix}users_entity set banned='yes' where guid=$user_guid";
93  return update_data($query);
94  }
95 
96  return false;
97  }
98 
99  return false;
100 }
101 
110  global $CONFIG;
111 
112  $user_guid = (int)$user_guid;
113 
115 
116  if (($user) && ($user->canEdit()) && ($user instanceof ElggUser)) {
117  if (elgg_trigger_event('unban', 'user', $user)) {
118  create_metadata($user_guid, 'ban_reason', '', '', 0, ACCESS_PUBLIC);
119 
120  // invalidate memcache for this user
121  static $newentity_cache;
122  if ((!$newentity_cache) && (is_memcache_available())) {
123  $newentity_cache = new ElggMemcache('new_entity_cache');
124  }
125 
126  if ($newentity_cache) {
127  $newentity_cache->delete($user_guid);
128  }
129 
130 
131  $query = "UPDATE {$CONFIG->dbprefix}users_entity set banned='no' where guid=$user_guid";
132  return update_data($query);
133  }
134 
135  return false;
136  }
137 
138  return false;
139 }
140 
149  global $CONFIG;
150 
151  $user = get_entity((int)$user_guid);
152 
153  if (($user) && ($user instanceof ElggUser) && ($user->canEdit())) {
154  if (elgg_trigger_event('make_admin', 'user', $user)) {
155 
156  // invalidate memcache for this user
157  static $newentity_cache;
158  if ((!$newentity_cache) && (is_memcache_available())) {
159  $newentity_cache = new ElggMemcache('new_entity_cache');
160  }
161 
162  if ($newentity_cache) {
163  $newentity_cache->delete($user_guid);
164  }
165 
166  $r = update_data("UPDATE {$CONFIG->dbprefix}users_entity set admin='yes' where guid=$user_guid");
168  return $r;
169  }
170 
171  return false;
172  }
173 
174  return false;
175 }
176 
185  global $CONFIG;
186 
187  $user = get_entity((int)$user_guid);
188 
189  if (($user) && ($user instanceof ElggUser) && ($user->canEdit())) {
190  if (elgg_trigger_event('remove_admin', 'user', $user)) {
191 
192  // invalidate memcache for this user
193  static $newentity_cache;
194  if ((!$newentity_cache) && (is_memcache_available())) {
195  $newentity_cache = new ElggMemcache('new_entity_cache');
196  }
197 
198  if ($newentity_cache) {
199  $newentity_cache->delete($user_guid);
200  }
201 
202  $r = update_data("UPDATE {$CONFIG->dbprefix}users_entity set admin='no' where guid=$user_guid");
204  return $r;
205  }
206 
207  return false;
208  }
209 
210  return false;
211 }
212 
222 function get_user($guid) {
223  // Fixes "Exception thrown without stack frame" when db_select fails
224  if (!empty($guid)) {
226  }
227 
228  if ((!empty($result)) && (!($result instanceof ElggUser))) {
229  return false;
230  }
231 
232  if (!empty($result)) {
233  return $result;
234  }
235 
236  return false;
237 }
238 
248 
249  // Fixes #6052. Username is frequently sniffed from the path info, which,
250  // unlike $_GET, is not URL decoded. If the username was not URL encoded,
251  // this is harmless.
252  $username = rawurldecode($username);
253 
256 
257  // Caching
258  if ((isset($USERNAME_TO_GUID_MAP_CACHE[$username]))
259  && (_elgg_retrieve_cached_entity($USERNAME_TO_GUID_MAP_CACHE[$username]))) {
260  return _elgg_retrieve_cached_entity($USERNAME_TO_GUID_MAP_CACHE[$username]);
261  }
262 
263  $query = "SELECT e.* FROM {$CONFIG->dbprefix}users_entity u
264  JOIN {$CONFIG->dbprefix}entities e ON e.guid = u.guid
265  WHERE u.username = '$username' AND $access";
266 
267  $entity = get_data_row($query, 'entity_row_to_elggstar');
268  if ($entity) {
269  $USERNAME_TO_GUID_MAP_CACHE[$username] = $entity->guid;
270  } else {
271  $entity = false;
272  }
273 
274  return $entity;
275 }
276 
284 function get_user_by_code($hash) {
285  _elgg_services()->persistentLogin->getUserFromHash($hash);
286 }
287 
296  global $CONFIG;
297 
299 
301 
302  $query = "SELECT e.* FROM {$CONFIG->dbprefix}entities e
303  JOIN {$CONFIG->dbprefix}users_entity u ON e.guid = u.guid
304  WHERE email = '$email' AND $access";
305 
306  return get_data($query, 'entity_row_to_elggstar');
307 }
308 
327 function find_active_users($options = array(), $limit = 10, $offset = 0, $count = false) {
328 
329  $seconds = 600; //default value
330 
331  if (!is_array($options)) {
332  elgg_deprecated_notice("find_active_users() now accepts an \$options array", 1.9);
333  if (!$options) {
334  $options = $seconds; //assign default value
335  }
336  $options = array('seconds' => $options);
337  }
338 
339  $options = array_merge(array(
340  'seconds' => $seconds,
341  'limit' => $limit,
342  'offset' => $offset,
343  'count' => $count,
344  ), $options);
345 
346  // cast options we're sending to hook
347  foreach (array('seconds', 'limit', 'offset') as $key) {
348  $options[$key] = (int)$options[$key];
349  }
350  $options['count'] = (bool)$options['count'];
351 
352  // allow plugins to override
353  $params = array(
354  'seconds' => $options['seconds'],
355  'limit' => $options['limit'],
356  'offset' => $options['offset'],
357  'count' => $options['count'],
358  'options' => $options,
359  );
360  $data = elgg_trigger_plugin_hook('find_active_users', 'system', $params, null);
361  // check null because the handler could legitimately return falsey values.
362  if ($data !== null) {
363  return $data;
364  }
365 
366  $dbprefix = elgg_get_config('dbprefix');
367  $time = time() - $options['seconds'];
368  return elgg_get_entities(array(
369  'type' => 'user',
370  'limit' => $options['limit'],
371  'offset' => $options['offset'],
372  'count' => $options['count'],
373  'joins' => array("join {$dbprefix}users_entity u on e.guid = u.guid"),
374  'wheres' => array("u.last_action >= {$time}"),
375  'order_by' => "u.last_action desc",
376  ));
377 }
378 
387  $user_guid = (int)$user_guid;
388 
390  if ($user instanceof ElggUser) {
391  // generate code
393  $user->setPrivateSetting('passwd_conf_code', $code);
394  $user->setPrivateSetting('passwd_conf_time', time());
395 
396  // email subject
397  $subject = elgg_echo('email:changereq:subject', array(), $user->language);
398 
399  // link for changing the password
400  $link = elgg_get_site_url() . "changepassword?u=$user_guid&c=$code";
401 
402  // IP address of the current user
403  $ip_address = _elgg_services()->request->getClientIp();
404 
405  // email message body
406  $email = elgg_echo('email:changereq:body', array(
407  $user->name,
408  $ip_address,
409  $link
410  ), $user->language);
411 
412  return notify_user($user->guid, elgg_get_site_entity()->guid,
413  $subject, $email, array(), 'email');
414  }
415 
416  return false;
417 }
418 
431  if ($user instanceof ElggUser) {
433 
436  $user->password = $hash;
437  $result = (bool)$user->save();
438 
440 
441  return $result;
442  }
443 
444  return false;
445 }
446 
456 function execute_new_password_request($user_guid, $conf_code, $password = null) {
457 
458  $user_guid = (int)$user_guid;
460 
461  if ($password === null) {
463  $reset = true;
464  }
465 
466  if (!elgg_instanceof($user, 'user')) {
467  return false;
468  }
469 
470  $saved_code = $user->getPrivateSetting('passwd_conf_code');
471  $code_time = (int) $user->getPrivateSetting('passwd_conf_time');
472 
473  if (!$saved_code || $saved_code != $conf_code) {
474  return false;
475  }
476 
477  // Discard for security if it is 24h old
478  if (!$code_time || $code_time < time() - 24 * 60 * 60) {
479  return false;
480  }
481 
483  remove_private_setting($user_guid, 'passwd_conf_code');
484  remove_private_setting($user_guid, 'passwd_conf_time');
485  // clean the logins failures
487 
488  $ns = $reset ? 'resetpassword' : 'changepassword';
489 
490  notify_user($user->guid,
491  elgg_get_site_entity()->guid,
492  elgg_echo("email:$ns:subject", array(), $user->language),
493  elgg_echo("email:$ns:body", array($user->username, $password), $user->language),
494  array(),
495  'email'
496  );
497 
498  return true;
499  }
500 
501  return false;
502 }
503 
510  return _elgg_services()->crypto->getRandomString(12, ElggCrypto::CHARS_PASSWORD);
511 }
512 
520  return _elgg_services()->crypto->getRandomString(8);
521 }
522 
532  return md5($password . $user->salt);
533 }
534 
546  global $CONFIG;
547 
548  // Basic, check length
549  if (!isset($CONFIG->minusername)) {
550  $CONFIG->minusername = 4;
551  }
552 
553  if (strlen($username) < $CONFIG->minusername) {
554  $msg = elgg_echo('registration:usernametooshort', array($CONFIG->minusername));
555  throw new RegistrationException($msg);
556  }
557 
558  // username in the database has a limit of 128 characters
559  if (strlen($username) > 128) {
560  $msg = elgg_echo('registration:usernametoolong', array(128));
561  throw new RegistrationException($msg);
562  }
563 
564  // Blacklist for bad characters (partially nicked from mediawiki)
565  $blacklist = '/[' .
566  '\x{0080}-\x{009f}' . // iso-8859-1 control chars
567  '\x{00a0}' . // non-breaking space
568  '\x{2000}-\x{200f}' . // various whitespace
569  '\x{2028}-\x{202f}' . // breaks and control chars
570  '\x{3000}' . // ideographic space
571  '\x{e000}-\x{f8ff}' . // private use
572  ']/u';
573 
574  if (preg_match($blacklist, $username)) {
575  // @todo error message needs work
576  throw new RegistrationException(elgg_echo('registration:invalidchars'));
577  }
578 
579  // Belts and braces
580  // @todo Tidy into main unicode
581  $blacklist2 = '\'/\\"*& ?#%^(){}[]~?<>;|¬`@-+=';
582 
583  for ($n = 0; $n < strlen($blacklist2); $n++) {
584  if (strpos($username, $blacklist2[$n]) !== false) {
585  $msg = elgg_echo('registration:invalidchars', array($blacklist2[$n], $blacklist2));
586  $msg = htmlspecialchars($msg, ENT_QUOTES, 'UTF-8');
587  throw new RegistrationException($msg);
588  }
589  }
590 
591  $result = true;
592  return elgg_trigger_plugin_hook('registeruser:validate:username', 'all',
593  array('username' => $username), $result);
594 }
595 
604 function validate_password($password) {
605  global $CONFIG;
606 
607  if (!isset($CONFIG->min_password_length)) {
608  $CONFIG->min_password_length = 6;
609  }
610 
611  if (strlen($password) < $CONFIG->min_password_length) {
612  $msg = elgg_echo('registration:passwordtooshort', array($CONFIG->min_password_length));
613  throw new RegistrationException($msg);
614  }
615 
616  $result = true;
617  return elgg_trigger_plugin_hook('registeruser:validate:password', 'all',
618  array('password' => $password), $result);
619 }
620 
629 function validate_email_address($address) {
630  if (!is_email_address($address)) {
631  throw new RegistrationException(elgg_echo('registration:notemail'));
632  }
633 
634  // Got here, so lets try a hook (defaulting to ok)
635  $result = true;
636  return elgg_trigger_plugin_hook('registeruser:validate:email', 'all',
637  array('email' => $address), $result);
638 }
639 
653 function register_user($username, $password, $name, $email, $allow_multiple_emails = false) {
654 
655  // no need to trim password.
656  $username = trim($username);
657  $name = trim(strip_tags($name));
658  $email = trim($email);
659 
660  // A little sanity checking
661  if (empty($username)
662  || empty($password)
663  || empty($name)
664  || empty($email)) {
665  return false;
666  }
667 
668  // Make sure a user with conflicting details hasn't registered and been disabled
669  $access_status = access_get_show_hidden_status();
670  access_show_hidden_entities(true);
671 
672  if (!validate_email_address($email)) {
673  throw new RegistrationException(elgg_echo('registration:emailnotvalid'));
674  }
675 
676  if (!validate_password($password)) {
677  throw new RegistrationException(elgg_echo('registration:passwordnotvalid'));
678  }
679 
680  if (!validate_username($username)) {
681  throw new RegistrationException(elgg_echo('registration:usernamenotvalid'));
682  }
683 
684  if ($user = get_user_by_username($username)) {
685  throw new RegistrationException(elgg_echo('registration:userexists'));
686  }
687 
688  if ((!$allow_multiple_emails) && (get_user_by_email($email))) {
689  throw new RegistrationException(elgg_echo('registration:dupeemail'));
690  }
691 
692  access_show_hidden_entities($access_status);
693 
694  // Create user
695  $user = new ElggUser();
696  $user->username = $username;
697  $user->email = $email;
698  $user->name = $name;
699  $user->access_id = ACCESS_PUBLIC;
700  $user->salt = _elgg_generate_password_salt();
701  $user->password = generate_user_password($user, $password);
702  $user->owner_guid = 0; // Users aren't owned by anyone, even if they are admin created.
703  $user->container_guid = 0; // Users aren't contained by anyone, even if they are admin created.
704  $user->language = get_current_language();
705  if ($user->save() === false) {
706  return false;
707  }
708 
709  // Turn on email notifications by default
710  set_user_notification_setting($user->getGUID(), 'email', true);
711 
712  return $user->getGUID();
713 }
714 
722 function generate_invite_code($username) {
723  $secret = datalist_get('__site_secret__');
724  return md5($username . $secret);
725 }
726 
736 function elgg_set_user_validation_status($user_guid, $status, $method = '') {
737  $result1 = create_metadata($user_guid, 'validated', $status, '', 0, ACCESS_PUBLIC, false);
738  $result2 = create_metadata($user_guid, 'validated_method', $method, '', 0, ACCESS_PUBLIC, false);
739  if ($result1 && $result2) {
740  return true;
741  } else {
742  return false;
743  }
744 }
745 
753 function elgg_get_user_validation_status($user_guid) {
754  $md = elgg_get_metadata(array(
755  'guid' => $user_guid,
756  'metadata_name' => 'validated'
757  ));
758  if ($md == false) {
759  return null;
760  }
761 
762  if ($md[0]->value) {
763  return true;
764  }
765 
766  return false;
767 }
768 
778 function elgg_user_account_page_handler($page_elements, $handler) {
779 
780  $base_dir = elgg_get_root_path() . 'pages/account';
781  switch ($handler) {
782  case 'login':
783  require_once("$base_dir/login.php");
784  break;
785  case 'forgotpassword':
786  require_once("$base_dir/forgotten_password.php");
787  break;
788  case 'changepassword':
789  require_once("$base_dir/change_password.php");
790  break;
791  case 'register':
792  require_once("$base_dir/register.php");
793  break;
794  default:
795  return false;
796  }
797  return true;
798 }
799 
807 function set_last_action($user_guid) {
808  $user_guid = (int) $user_guid;
809  global $CONFIG;
810  $time = time();
811 
812  $query = "UPDATE {$CONFIG->dbprefix}users_entity
813  set prev_last_action = last_action,
814  last_action = {$time} where guid = {$user_guid}";
815 
816  execute_delayed_write_query($query);
817 }
818 
826 function set_last_login($user_guid) {
827  $user_guid = (int) $user_guid;
828  global $CONFIG;
829  $time = time();
830 
831  $query = "UPDATE {$CONFIG->dbprefix}users_entity
832  set prev_last_login = last_login, last_login = {$time} where guid = {$user_guid}";
833 
834  execute_delayed_write_query($query);
835 }
836 
847 function user_create_hook_add_site_relationship($event, $object_type, $object) {
848  add_entity_relationship($object->getGUID(), 'member_of_site', elgg_get_site_entity()->guid);
849 }
850 
861 function user_avatar_hook($hook, $entity_type, $returnvalue, $params) {
862  $user = $params['entity'];
863  $size = $params['size'];
864 
865  if (isset($user->icontime)) {
866  return "avatar/view/$user->username/$size/$user->icontime";
867  } else {
868  return "_graphics/icons/user/default{$size}.gif";
869  }
870 }
871 
876 function elgg_user_hover_menu($hook, $type, $return, $params) {
877  $user = $params['entity'];
878  /* @var ElggUser $user */
879 
880  if (elgg_is_logged_in()) {
881  if (elgg_get_logged_in_user_guid() == $user->guid) {
882  $url = "profile/$user->username/edit";
883  $item = new ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url);
884  $item->setSection('action');
885  $return[] = $item;
886 
887  $url = "avatar/edit/$user->username";
888  $item = new ElggMenuItem('avatar:edit', elgg_echo('avatar:edit'), $url);
889  $item->setSection('action');
890  $return[] = $item;
891  }
892  }
893 
894  // prevent admins from banning or deleting themselves
895  if (elgg_get_logged_in_user_guid() == $user->guid) {
896  return $return;
897  }
898 
899  if (elgg_is_admin_logged_in()) {
900  $actions = array();
901  if (!$user->isBanned()) {
902  $actions[] = 'ban';
903  } else {
904  $actions[] = 'unban';
905  }
906  $actions[] = 'delete';
907  $actions[] = 'resetpassword';
908  if (!$user->isAdmin()) {
909  $actions[] = 'makeadmin';
910  } else {
911  $actions[] = 'removeadmin';
912  }
913 
914  foreach ($actions as $action) {
915  $url = "action/admin/user/$action?guid={$user->guid}";
916  $url = elgg_add_action_tokens_to_url($url);
917  $item = new ElggMenuItem($action, elgg_echo($action), $url);
918  $item->setSection('admin');
919  $item->setLinkClass('elgg-requires-confirmation');
920 
921  $return[] = $item;
922  }
923 
924  $url = "profile/$user->username/edit";
925  $item = new ElggMenuItem('profile:edit', elgg_echo('profile:edit'), $url);
926  $item->setSection('admin');
927  $return[] = $item;
928 
929  $url = "settings/user/$user->username";
930  $item = new ElggMenuItem('settings:edit', elgg_echo('settings:edit'), $url);
931  $item->setSection('admin');
932  $return[] = $item;
933 
934  $url = "activity/owner/$user->username";
935  $item = new ElggMenuItem('activity:owner', elgg_echo('activity:owner'), $url);
936  $item->setSection('action');
937  $return[] = $item;
938  }
939 
940  return $return;
941 }
942 
954 function elgg_users_setup_entity_menu($hook, $type, $return, $params) {
955  if (elgg_in_context('widgets')) {
956  return $return;
957  }
958 
959  $entity = $params['entity'];
960  if (!elgg_instanceof($entity, 'user')) {
961  return $return;
962  }
963  /* @var ElggUser $entity */
964 
965  if ($entity->isBanned()) {
966  $banned = elgg_echo('banned');
967  $options = array(
968  'name' => 'banned',
969  'text' => "<span>$banned</span>",
970  'href' => false,
971  'priority' => 0,
972  );
973  $return = array(ElggMenuItem::factory($options));
974  } else {
975  $return = array();
976  if (isset($entity->location)) {
977  $location = htmlspecialchars($entity->location, ENT_QUOTES, 'UTF-8', false);
978  $options = array(
979  'name' => 'location',
980  'text' => "<span>$location</span>",
981  'href' => false,
982  'priority' => 150,
983  );
984  $return[] = ElggMenuItem::factory($options);
985  }
986  }
987 
988  return $return;
989 }
990 
999 function elgg_profile_fields_setup() {
1000  global $CONFIG;
1001 
1002  $profile_defaults = array (
1003  'description' => 'longtext',
1004  'briefdescription' => 'text',
1005  'location' => 'location',
1006  'interests' => 'tags',
1007  'skills' => 'tags',
1008  'contactemail' => 'email',
1009  'phone' => 'text',
1010  'mobile' => 'text',
1011  'website' => 'url',
1012  'twitter' => 'text',
1013  );
1014 
1015  $loaded_defaults = array();
1016  $fieldlist = elgg_get_config('profile_custom_fields');
1017  if ($fieldlist || $fieldlist === '0') {
1018  $fieldlistarray = explode(',', $fieldlist);
1019  foreach ($fieldlistarray as $listitem) {
1020  if ($translation = elgg_get_config("admin_defined_profile_{$listitem}")) {
1021  $type = elgg_get_config("admin_defined_profile_type_{$listitem}");
1022  $loaded_defaults["admin_defined_profile_{$listitem}"] = $type;
1023  add_translation(get_current_language(), array("profile:admin_defined_profile_{$listitem}" => $translation));
1024  }
1025  }
1026  }
1027 
1028  if (count($loaded_defaults)) {
1029  $CONFIG->profile_using_custom = true;
1030  $profile_defaults = $loaded_defaults;
1031  }
1032 
1033  $CONFIG->profile_fields = elgg_trigger_plugin_hook('profile:fields', 'profile', null, $profile_defaults);
1034 
1035  // register any tag metadata names
1036  foreach ($CONFIG->profile_fields as $name => $type) {
1037  if ($type == 'tags' || $type == 'location' || $type == 'tag') {
1038  elgg_register_tag_metadata_name($name);
1039  // register a tag name translation
1040  add_translation(get_current_language(), array("tag_names:$name" => elgg_echo("profile:$name")));
1041  }
1042  }
1043 }
1044 
1055 function elgg_avatar_page_handler($page) {
1056  global $CONFIG;
1057 
1058  $user = get_user_by_username($page[1]);
1059  if ($user) {
1060  elgg_set_page_owner_guid($user->getGUID());
1061  }
1062 
1063  if ($page[0] == 'edit') {
1064  require_once("{$CONFIG->path}pages/avatar/edit.php");
1065  return true;
1066  } else {
1067  set_input('size', $page[2]);
1068  require_once("{$CONFIG->path}pages/avatar/view.php");
1069  return true;
1070  }
1071  return false;
1072 }
1073 
1081 function elgg_profile_page_handler($page) {
1082  global $CONFIG;
1083 
1084  $user = get_user_by_username($page[0]);
1085  elgg_set_page_owner_guid($user->guid);
1086 
1087  if ($page[1] == 'edit') {
1088  require_once("{$CONFIG->path}pages/profile/edit.php");
1089  return true;
1090  }
1091  return false;
1092 }
1093 
1100 function users_pagesetup() {
1101 
1102  $owner = elgg_get_page_owner_entity();
1103  $viewer = elgg_get_logged_in_user_entity();
1104 
1105  if ($owner) {
1106  elgg_register_menu_item('page', array(
1107  'name' => 'edit_avatar',
1108  'href' => "avatar/edit/{$owner->username}",
1109  'text' => elgg_echo('avatar:edit'),
1110  'section' => '1_profile',
1111  'contexts' => array('settings'),
1112  ));
1113 
1114  elgg_register_menu_item('page', array(
1115  'name' => 'edit_profile',
1116  'href' => "profile/{$owner->username}/edit",
1117  'text' => elgg_echo('profile:edit'),
1118  'section' => '1_profile',
1119  'contexts' => array('settings'),
1120  ));
1121  }
1122 
1123  // topbar
1124  if ($viewer) {
1125  elgg_register_menu_item('topbar', array(
1126  'name' => 'profile',
1127  'href' => $viewer->getURL(),
1128  'text' => elgg_view('output/img', array(
1129  'src' => $viewer->getIconURL('topbar'),
1130  'alt' => $viewer->name,
1131  'title' => elgg_echo('profile'),
1132  'class' => 'elgg-border-plain elgg-transition',
1133  )),
1134  'priority' => 100,
1135  'link_class' => 'elgg-topbar-avatar',
1136  ));
1137 
1138  elgg_register_menu_item('topbar', array(
1139  'name' => 'usersettings',
1140  'href' => "settings/user/{$viewer->username}",
1141  'text' => elgg_view_icon('settings') . elgg_echo('settings'),
1142  'priority' => 500,
1143  'section' => 'alt',
1144  ));
1145 
1146  elgg_register_menu_item('topbar', array(
1147  'name' => 'logout',
1148  'href' => "action/logout",
1149  'text' => elgg_echo('logout'),
1150  'is_action' => true,
1151  'priority' => 1000,
1152  'section' => 'alt',
1153  ));
1154  }
1155 }
1156 
1163 function users_init() {
1164 
1165  elgg_register_page_handler('register', 'elgg_user_account_page_handler');
1166  elgg_register_page_handler('forgotpassword', 'elgg_user_account_page_handler');
1167  elgg_register_page_handler('changepassword', 'elgg_user_account_page_handler');
1168  elgg_register_page_handler('login', 'elgg_user_account_page_handler');
1169  elgg_register_page_handler('avatar', 'elgg_avatar_page_handler');
1170  elgg_register_page_handler('profile', 'elgg_profile_page_handler');
1171 
1172  elgg_register_plugin_hook_handler('register', 'menu:user_hover', 'elgg_user_hover_menu');
1173 
1174  elgg_register_action('register', '', 'public');
1175  elgg_register_action('useradd', '', 'admin');
1176  elgg_register_action('avatar/upload');
1177  elgg_register_action('avatar/crop');
1178  elgg_register_action('avatar/remove');
1179  elgg_register_action('profile/edit');
1180 
1181  elgg_register_plugin_hook_handler('entity:icon:url', 'user', 'user_avatar_hook');
1182 
1183  elgg_register_action('user/changepassword', '', 'public');
1184  elgg_register_action('user/requestnewpassword', '', 'public');
1185 
1186  // Register the user type
1187  elgg_register_entity_type('user', '');
1188 
1189  elgg_register_plugin_hook_handler('register', 'menu:entity', 'elgg_users_setup_entity_menu', 501);
1190 
1191  elgg_register_event_handler('create', 'user', 'user_create_hook_add_site_relationship');
1192 }
1193 
1205 function users_test($hook, $type, $value, $params) {
1206  global $CONFIG;
1207  $value[] = "{$CONFIG->path}engine/tests/ElggUserTest.php";
1208  return $value;
1209 }
1210 
1211 elgg_register_event_handler('init', 'system', 'users_init', 0);
1212 elgg_register_event_handler('init', 'system', 'elgg_profile_fields_setup', 10000); // Ensure this runs after other plugins
1213 elgg_register_event_handler('pagesetup', 'system', 'users_pagesetup', 0);
1214 elgg_register_plugin_hook_handler('unit_test', 'system', 'users_test');
elgg_get_config($name, $site_guid=0)
Get an Elgg configuration value.
$dbprefix
Definition: index.php:13
execute_new_password_request($user_guid, $conf_code, $password=null)
Validate and change password for a user.
Definition: users.php:456
elgg_get_site_entity($site_guid=0)
Get an ElggSite entity (default is current site)
Definition: sites.php:18
$r
$CONFIG view
The current view type.
Definition: config.php:185
send_new_password_request($user_guid)
Generate and send a password request email to a given user&#39;s registered email address.
Definition: users.php:386
get_user_by_email($email)
Get an array of users from an email address.
Definition: users.php:295
elgg widget edit
Definition: admin.php:1213
make_user_admin($user_guid)
Makes user $guid an admin.
Definition: users.php:148
$username
Definition: delete.php:22
get_data_row($query, $callback="")
Retrieve a single row from the database.
Definition: database.php:66
$subject
Definition: exceptions.php:25
_elgg_invalidate_cache_for_entity($guid)
Invalidate this class&#39;s entry in the cache.
Definition: entities.php:72
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
const CHARS_PASSWORD
Character set for temp passwords (no risk of embedded profanity/glyphs that look similar) ...
Definition: ElggCrypto.php:15
$size
Definition: view.php:10
_elgg_retrieve_cached_entity($guid)
Retrieve a entity from the cache.
Definition: entities.php:134
force_user_password_reset($user_guid, $password)
Low level function to reset a given user&#39;s password.
Definition: users.php:429
elgg form settings
Definition: admin.php:562
find_active_users($options=array(), $limit=10, $offset=0, $count=false)
Return users (or the number of them) who have been active within a recent period. ...
Definition: users.php:327
if(elgg_in_context('widget')) $offset
Definition: pagination.php:20
$data
Definition: opendd.php:13
$ia
Definition: upgrade.php:26
validate_username($username)
Simple function which ensures that a username contains only valid characters.
Definition: users.php:545
elgg menu user
Definition: admin.php:190
$guid
Removes an admin notice.
reset_login_failure_count($user_guid)
Resets the fail login count for $user_guid.
Definition: sessions.php:217
$email
Definition: register.php:15
unban_user($user_guid)
Unban a user.
Definition: users.php:109
update_data($query)
Update a row in the database.
Definition: database.php:93
$action
get_user_by_username($username)
Get user by username.
Definition: users.php:246
disable_user_entities($owner_guid)
Disables all of a user&#39;s entities.
Definition: users.php:40
$params
Definition: login.php:72
$options
Definition: index.php:14
ban_user($user_guid, $reason="")
Ban a user.
Definition: users.php:67
get_user_by_code($hash)
Get user by persistent login password.
Definition: users.php:284
$owner_guid
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an ElggEntity and optionally for type and subtype.
Definition: entities.php:1886
$limit
Definition: userpicker.php:33
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
remove_private_setting($entity_guid, $name)
Deletes a private setting for an entity.
elgg avatar
Definition: admin.php:1324
$owner
Definition: crop.php:8
$key
Definition: summary.php:34
get_user($guid)
Get a user object from a GUID.
Definition: users.php:222
get_user_entity_as_row($guid)
Return the user specific details of a user by a row.
Definition: users.php:26
elgg_set_ignore_access($ignore=true)
Set if Elgg&#39;s access system should be ignored.
Definition: access.php:43
_elgg_services()
Definition: autoloader.php:14
global $CONFIG
create_metadata($entity_guid, $name, $value, $value_type= '', $owner_guid=0, $access_id=ACCESS_PRIVATE, $allow_multiple=false)
Create a new metadata object, or update an existing one.
Definition: metadata.php:69
sanitise_string($string)
Wrapper function for alternate English spelling (.
Definition: database.php:150
$user
Definition: ban.php:13
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
Definition: entities.php:777
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
Definition: elgglib.php:925
global $USERNAME_TO_GUID_MAP_CACHE
Definition: users.php:15
$reset
elgg_deprecated_notice($msg, $dep_version, $backtrace_level=1)
Sends a notice about deprecated use of a function, view, etc.
Definition: elgglib.php:1171
elgg global
Pointer to the global context.
Definition: elgglib.js:12
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
ui datepicker td span
Definition: admin.php:610
login(ElggUser $user, $persistent=false)
Logs in a specified ElggUser.
Definition: sessions.php:305
generate_user_password(ElggUser $user, $password)
Hash a password for storage.
Definition: users.php:531
$password
Definition: login.php:25
_elgg_generate_password_salt()
Generate an 8 character Base64 URL salt for the password.
Definition: users.php:519
logout()
Log the current user out.
Definition: sessions.php:357
get_data($query, $callback="")
Retrieve rows from the database.
Definition: database.php:50
const ACCESS_PUBLIC
Definition: elgglib.php:2123
$count
Definition: tools.php:19
notify_user($to, $from, $subject, $message, array $params=array(), $methods_override="")
Notify a user via their preferences.
is_memcache_available()
Return true if memcache is available and configured.
Definition: memcache.php:16
generate_random_cleartext_password()
Generate a random 12 character clear text password.
Definition: users.php:509
$user_guid
Avatar remove action.
Definition: remove.php:6
$entity
Definition: delete.php:10
_elgg_get_access_where_sql(array $options=array())
Returns the SQL where clause for enforcing read access to data.
Definition: access.php:343
elgg_trigger_event($event, $object_type, $object=null)
Trigger an Elgg Event and attempt to run all handler callbacks registered to that event...
Definition: elgglib.php:720
remove_user_admin($user_guid)
Removes user $guid&#39;s admin flag.
Definition: users.php:184
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604
$access
Definition: save.php:15
elgg action
Definition: ajax.js:178