Elgg  Version 2.3
access.php
Go to the documentation of this file.
1 <?php
43 function elgg_set_ignore_access($ignore = true) {
44  return _elgg_services()->session->setIgnoreAccess($ignore);
45 }
46 
55  return _elgg_services()->session->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 
118 function get_default_access(ElggUser $user = null, array $input_params = array()) {
119  global $CONFIG;
120 
121  // site default access
122  $default_access = $CONFIG->default_access;
123 
124  // user default access if enabled
125  if ($CONFIG->allow_user_default_access) {
126  $user = $user ? $user : _elgg_services()->session->getLoggedInUser();
127  if ($user) {
128  $user_access = $user->getPrivateSetting('elgg_default_access');
129  if ($user_access !== null) {
130  $default_access = $user_access;
131  }
132  }
133  }
134 
135  $params = array(
136  'user' => $user,
137  'default_access' => $default_access,
138  'input_params' => $input_params,
139  );
140  return _elgg_services()->hooks->trigger('default', 'access', $params, $default_access);
141 }
142 
151 
158 function access_show_hidden_entities($show_hidden) {
160  $current_value = $ENTITY_SHOW_HIDDEN_OVERRIDE;
161  $ENTITY_SHOW_HIDDEN_OVERRIDE = $show_hidden;
162  return $current_value;
163 }
164 
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 
267 function get_write_access_array($user_guid = 0, $site_guid = 0, $flush = false, array $input_params = array()) {
268  return _elgg_services()->accessCollections->getWriteAccessArray($user_guid, $site_guid, $flush, $input_params);
269 }
270 
286  return _elgg_services()->accessCollections->canEdit($collection_id, $user_guid);
287 }
288 
308 function create_access_collection($name, $owner_guid = 0, $site_guid = 0) {
309  return _elgg_services()->accessCollections->create($name, $owner_guid, $site_guid);
310 }
311 
329  return _elgg_services()->accessCollections->update($collection_id, $members);
330 }
331 
342  return _elgg_services()->accessCollections->delete($collection_id);
343 }
344 
358  return _elgg_services()->accessCollections->get($collection_id);
359 }
360 
374  return _elgg_services()->accessCollections->addUser($user_guid, $collection_id);
375 }
376 
390  return _elgg_services()->accessCollections->removeUser($user_guid, $collection_id);
391 }
392 
403 function get_user_access_collections($owner_guid, $site_guid = 0) {
404  return _elgg_services()->accessCollections->getEntityCollections($owner_guid, $site_guid);
405 }
406 
416 function get_members_of_access_collection($collection_id, $guids_only = false) {
417  return _elgg_services()->accessCollections->getMembers($collection_id, $guids_only);
418 }
419 
432 function elgg_get_entities_from_access_id(array $options = array()) {
433  // restrict the resultset to access collection provided
434  if (!isset($options['access_id'])) {
435  return false;
436  }
437 
438  // @todo add support for an array of collection_ids
439  $where = "e.access_id = '{$options['access_id']}'";
440  if (isset($options['wheres'])) {
441  if (is_array($options['wheres'])) {
442  $options['wheres'][] = $where;
443  } else {
444  $options['wheres'] = array($options['wheres'], $where);
445  }
446  } else {
447  $options['wheres'] = array($where);
448  }
449 
450  // return entities with the desired options
451  return _elgg_services()->entityTable->getEntities($options);
452 }
453 
464 function elgg_list_entities_from_access_id(array $options = array()) {
465  return elgg_list_entities($options, 'elgg_get_entities_from_access_id');
466 }
467 
484 function get_readable_access_level($entity_access_id) {
485  return _elgg_services()->accessCollections->getReadableAccessLevel($entity_access_id);
486 }
487 
504  if (!$user_guid || $user_guid <= 0) {
505  $is_admin = false;
506  } else {
507  $is_admin = elgg_is_admin_user($user_guid);
508  }
509 
510  return ($is_admin || _elgg_services()->session->getIgnoreAccess());
511 }
512 
522 
531 function access_init() {
533  $init_finished = true;
534 }
535 
557  $user = elgg_extract('user', $params);
558  if ($user) {
559  $user_guid = $user->guid;
560  } else {
561  $user_guid = _elgg_services()->session->getLoggedInUserGuid();
562  }
563 
564  // don't do this so ignore access still works with no one logged in
565  //if (!$user instanceof \ElggUser) {
566  // return false;
567  //}
568 
569  // check for admin
571  return true;
572  }
573 
574  // check access overrides
576  return true;
577  }
578 
579  // consult other hooks
580  return null;
581 }
582 
594 function access_test($hook, $type, $value, $params) {
595  global $CONFIG;
596  $value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessCollectionsTest.php';
597  $value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessSQLTest.php';
598  return $value;
599 }
600 
601 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
602  // Tell the access functions the system has booted, plugins are loaded,
603  // and the user is logged in so it can start caching
604  $events->registerHandler('ready', 'system', 'access_init');
605 
606  // For overrided permissions
607  $hooks->registerHandler('permissions_check', 'all', 'elgg_override_permissions', 600);
608  $hooks->registerHandler('container_permissions_check', 'all', 'elgg_override_permissions', 600);
609 
610  $hooks->registerHandler('unit_test', 'system', 'access_test');
611 };
foreach($keys as $key=> $default_value) $entity
Definition: access.php:47
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:341
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:531
$members
$value
Definition: longtext.php:42
elgg_list_entities_from_access_id(array $options=array())
Lists entities from an access collection.
Definition: access.php:464
get_access_collection($collection_id)
Get a specified access collection.
Definition: access.php:357
get_members_of_access_collection($collection_id, $guids_only=false)
Get all of members of an access collection.
Definition: access.php:416
update_access_collection($collection_id, $members)
Updates the membership in an access collection.
Definition: access.php:328
access_test($hook, $type, $value, $params)
Runs unit tests for the access library.
Definition: access.php:594
remove_user_from_access_collection($user_guid, $collection_id)
Removes a user from an access collection.
Definition: access.php:389
$options
Elgg admin footer.
Definition: footer.php:6
elgg_get_ignore_access()
Get current ignore access setting.
Definition: access.php:54
$params
Definition: access.php:32
$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:403
$init_finished
A flag to set if Elgg&#39;s access initialization is finished.
Definition: access.php:521
get_default_access(ElggUser $user=null, array $input_params=array())
Gets the default access permission.
Definition: access.php:118
elgg_check_access_overrides($user_guid=0)
Decides if the access system should be ignored for a user.
Definition: access.php:503
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:373
elgg_is_admin_user($user_guid)
Check if the given user has full access.
Definition: sessions.php:74
get_write_access_array($user_guid=0, $site_guid=0, $flush=false, array $input_params=array())
Returns an array of access permissions that the user is allowed to save content with.
Definition: access.php:267
$ENTITY_SHOW_HIDDEN_OVERRIDE
Allow disabled entities and metadata to be returned by getter functions.
Definition: access.php:150
global $CONFIG
$user
Definition: ban.php:13
elgg global
Pointer to the global context.
Definition: elgglib.js:12
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:484
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
access_get_show_hidden_status()
Return current status of showing disabled entities.
Definition: access.php:170
$collection_id
Definition: delete.php:9
elgg_extract($key, $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
Definition: elgglib.php:1375
elgg_list_entities(array $options=array(), $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
Definition: entities.php:393
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
Definition: access.php:158
elgg_get_entities_from_access_id(array $options=array())
Return entities based upon access id.
Definition: access.php:432
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:285
$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
if(!$user instanceof ElggUser) $default_access
create_access_collection($name, $owner_guid=0, $site_guid=0)
Creates a new access collection.
Definition: access.php:308
elgg_override_permissions($hook, $type, $value, $params)
Overrides the access system if appropriate.
Definition: access.php:556
if(!$display_name) $type
Definition: delete.php:27