Elgg  Version 1.10
access.php
Go to the documentation of this file.
1 <?php
43 function elgg_set_ignore_access($ignore = true) {
44  return _elgg_services()->access->setIgnoreAccess($ignore);
45 }
46 
55  return _elgg_services()->access->getIgnoreAccess();
56 }
57 
73 function get_access_list($user_guid = 0, $site_guid = 0, $flush = false) {
74  return _elgg_services()->accessCollections->getAccessList($user_guid, $site_guid, $flush);
75 }
76 
102 function get_access_array($user_guid = 0, $site_guid = 0, $flush = false) {
103  return _elgg_services()->accessCollections->getAccessArray($user_guid, $site_guid, $flush);
104 }
105 
117 function get_default_access(\ElggUser $user = null) {
118  global $CONFIG;
119 
120  // site default access
121  $default_access = $CONFIG->default_access;
122 
123  // user default access if enabled
124  if ($CONFIG->allow_user_default_access) {
125  $user = $user ? $user : _elgg_services()->session->getLoggedInUser();
126  if ($user) {
127  $user_access = $user->getPrivateSetting('elgg_default_access');
128  if ($user_access !== null) {
129  $default_access = $user_access;
130  }
131  }
132  }
133 
134  $params = array(
135  'user' => $user,
136  'default_access' => $default_access,
137  );
138  return _elgg_services()->hooks->trigger('default', 'access', $params, $default_access);
139 }
140 
149 
157 function access_show_hidden_entities($show_hidden) {
159  $current_value = $ENTITY_SHOW_HIDDEN_OVERRIDE;
160  $ENTITY_SHOW_HIDDEN_OVERRIDE = $show_hidden;
161  return $current_value;
162 }
163 
173 }
174 
214 function _elgg_get_access_where_sql(array $options = array()) {
215  return _elgg_services()->accessCollections->getWhereSql($options);
216 }
217 
237 function has_access_to_entity($entity, $user = null) {
238  return _elgg_services()->accessCollections->hasAccessToEntity($entity, $user);
239 }
240 
266 function get_write_access_array($user_guid = 0, $site_guid = 0, $flush = false) {
267  return _elgg_services()->accessCollections->getWriteAccessArray($user_guid, $site_guid, $flush);
268 }
269 
285  return _elgg_services()->accessCollections->canEdit($collection_id, $user_guid);
286 }
287 
307 function create_access_collection($name, $owner_guid = 0, $site_guid = 0) {
308  return _elgg_services()->accessCollections->create($name, $owner_guid, $site_guid);
309 }
310 
328  return _elgg_services()->accessCollections->update($collection_id, $members);
329 }
330 
341  return _elgg_services()->accessCollections->delete($collection_id);
342 }
343 
357  return _elgg_services()->accessCollections->get($collection_id);
358 }
359 
373  return _elgg_services()->accessCollections->addUser($user_guid, $collection_id);
374 }
375 
389  return _elgg_services()->accessCollections->removeUser($user_guid, $collection_id);
390 }
391 
402 function get_user_access_collections($owner_guid, $site_guid = 0) {
403  return _elgg_services()->accessCollections->getUserCollections($owner_guid, $site_guid);
404 }
405 
415 function get_members_of_access_collection($collection, $idonly = false) {
416  return _elgg_services()->accessCollections->getMembers($collection, $idonly);
417 }
418 
431 function elgg_get_entities_from_access_id(array $options = array()) {
432  // restrict the resultset to access collection provided
433  if (!isset($options['access_id'])) {
434  return false;
435  }
436 
437  // @todo add support for an array of collection_ids
438  $where = "e.access_id = '{$options['access_id']}'";
439  if (isset($options['wheres'])) {
440  if (is_array($options['wheres'])) {
441  $options['wheres'][] = $where;
442  } else {
443  $options['wheres'] = array($options['wheres'], $where);
444  }
445  } else {
446  $options['wheres'] = array($where);
447  }
448 
449  // return entities with the desired options
450  return _elgg_services()->entityTable->getEntities($options);
451 }
452 
463 function elgg_list_entities_from_access_id(array $options = array()) {
464  return elgg_list_entities($options, 'elgg_get_entities_from_access_id');
465 }
466 
485 function get_readable_access_level($entity_access_id) {
486  $access = (int) $entity_access_id;
487 
488  $translator = _elgg_services()->translator;
489 
490  // Check if entity access id is a defined global constant
491  $access_array = array(
492  ACCESS_PRIVATE => $translator->translate("PRIVATE"),
493  ACCESS_FRIENDS => $translator->translate("access:friends:label"),
494  ACCESS_LOGGED_IN => $translator->translate("LOGGED_IN"),
495  ACCESS_PUBLIC => $translator->translate("PUBLIC"),
496  );
497 
498  if (array_key_exists($access, $access_array)) {
499  return $access_array[$access];
500  }
501 
502  // Entity access id is a custom access collection
503  // Check if the user has write access to it and can see it's label
504  $write_access_array = _elgg_services()->accessCollections->getWriteAccessArray();
505 
506  if (array_key_exists($access, $write_access_array)) {
507  return $write_access_array[$access];
508  }
509 
510  // return 'Limited' if the user does not have access to the access collection
511  return $translator->translate('access:limited:label');
512 }
513 
530  if (!$user_guid || $user_guid <= 0) {
531  $is_admin = false;
532  } else {
533  $is_admin = elgg_is_admin_user($user_guid);
534  }
535 
536  return ($is_admin || _elgg_services()->access->getIgnoreAccess());
537 }
538 
548 
557 function access_init() {
559  $init_finished = true;
560 }
561 
583  $user = elgg_extract('user', $params);
584  if ($user) {
585  $user_guid = $user->guid;
586  } else {
587  $user_guid = _elgg_services()->session->getLoggedInUserGuid();
588  }
589 
590  // don't do this so ignore access still works with no one logged in
591  //if (!$user instanceof \ElggUser) {
592  // return false;
593  //}
594 
595  // check for admin
597  return true;
598  }
599 
600  // check access overrides
602  return true;
603  }
604 
605  // consult other hooks
606  return null;
607 }
608 
620 function access_test($hook, $type, $value, $params) {
621  global $CONFIG;
622  $value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessCollectionsTest.php';
623  $value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessSQLTest.php';
624  return $value;
625 }
626 
627 // Tell the access functions the system has booted, plugins are loaded,
628 // and the user is logged in so it can start caching
629 elgg_register_event_handler('ready', 'system', 'access_init');
630 
631 // For overrided permissions
632 elgg_register_plugin_hook_handler('permissions_check', 'all', 'elgg_override_permissions');
633 elgg_register_plugin_hook_handler('container_permissions_check', 'all', 'elgg_override_permissions');
634 
635 elgg_register_plugin_hook_handler('unit_test', 'system', 'access_test');
get_access_array($user_guid=0, $site_guid=0, $flush=false)
Returns an array of access IDs a user is permitted to see.
Definition: access.php:102
delete_access_collection($collection_id)
Deletes a specified access collection and its membership.
Definition: access.php:340
if($guid==elgg_get_logged_in_user_guid()) $name
Definition: delete.php:21
access_init()
A quick and dirty way to make sure the access permissions have been correctly set up...
Definition: access.php:557
$members
$value
Definition: longtext.php:29
elgg_list_entities_from_access_id(array $options=array())
Lists entities from an access collection.
Definition: access.php:463
if(!$autoload_available) _elgg_services()
Definition: autoloader.php:20
const ACCESS_FRIENDS
Definition: elgglib.php:2049
$collection
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1349
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
Definition: elgglib.php:737
get_access_collection($collection_id)
Get a specified access collection.
Definition: access.php:356
update_access_collection($collection_id, $members)
Updates the membership in an access collection.
Definition: access.php:327
access_test($hook, $type, $value, $params)
Runs unit tests for the access library.
Definition: access.php:620
remove_user_from_access_collection($user_guid, $collection_id)
Removes a user from an access collection.
Definition: access.php:388
elgg_get_ignore_access()
Get current ignore access setting.
Definition: access.php:54
$params
Definition: login.php:72
$options
Definition: index.php:14
$owner_guid
get_user_access_collections($owner_guid, $site_guid=0)
Returns an array of database row objects of the access collections owned by $owner_guid.
Definition: access.php:402
$init_finished
A flag to set if Elgg&#39;s access initialization is finished.
Definition: access.php:547
elgg_check_access_overrides($user_guid=0)
Decides if the access system should be ignored for a user.
Definition: access.php:529
get_members_of_access_collection($collection, $idonly=false)
Get all of members of an access collection.
Definition: access.php:415
elgg_set_ignore_access($ignore=true)
Set if Elgg&#39;s access system should be ignored.
Definition: access.php:43
add_user_to_access_collection($user_guid, $collection_id)
Adds a user to an access collection.
Definition: access.php:372
elgg_is_admin_user($user_guid)
Check if the given user has full access.
Definition: sessions.php:74
$ENTITY_SHOW_HIDDEN_OVERRIDE
Allow disabled entities and metadata to be returned by getter functions.
Definition: access.php:148
global $CONFIG
$user
Definition: ban.php:13
const ACCESS_PRIVATE
Definition: elgglib.php:2046
elgg global
Pointer to the global context.
Definition: elgglib.js:12
$type
Definition: add.php:8
get_access_list($user_guid=0, $site_guid=0, $flush=false)
Return a string of access_ids for $user_guid appropriate for inserting into an SQL IN clause...
Definition: access.php:73
get_readable_access_level($entity_access_id)
Return the name of an ACCESS_* constant or an access collection, but only if the logged in user has w...
Definition: access.php:485
access_get_show_hidden_status()
Return current status of showing disabled entities.
Definition: access.php:170
$collection_id
Definition: delete.php:9
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
Definition: elgglib.php:553
elgg_list_entities(array $options=array(), $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
Definition: entities.php:585
const ACCESS_PUBLIC
Definition: elgglib.php:2048
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
Definition: access.php:157
elgg_get_entities_from_access_id(array $options=array())
Return entities based upon access id.
Definition: access.php:431
has_access_to_entity($entity, $user=null)
Can a user access an entity.
Definition: access.php:237
can_edit_access_collection($collection_id, $user_guid=null)
Can the user change this access collection?
Definition: access.php:284
const ACCESS_LOGGED_IN
Definition: elgglib.php:2047
$user_guid
Avatar remove action.
Definition: remove.php:6
_elgg_get_access_where_sql(array $options=array())
Returns the SQL where clause for enforcing read access to data.
Definition: access.php:214
get_write_access_array($user_guid=0, $site_guid=0, $flush=false)
Returns an array of access permissions that the user is allowed to save content with.
Definition: access.php:266
$access
Definition: save.php:15
create_access_collection($name, $owner_guid=0, $site_guid=0)
Creates a new access collection.
Definition: access.php:307
elgg_override_permissions($hook, $type, $value, $params)
Overrides the access system if appropriate.
Definition: access.php:582
$entity
Definition: access.php:26
get_default_access(\ElggUser $user=null)
Gets the default access permission.
Definition: access.php:117