Elgg  Version 1.11
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 
159 function access_show_hidden_entities($show_hidden) {
161  $current_value = $ENTITY_SHOW_HIDDEN_OVERRIDE;
162  $ENTITY_SHOW_HIDDEN_OVERRIDE = $show_hidden;
163  return $current_value;
164 }
165 
175 }
176 
216 function _elgg_get_access_where_sql(array $options = array()) {
217  return _elgg_services()->accessCollections->getWhereSql($options);
218 }
219 
239 function has_access_to_entity($entity, $user = null) {
240  return _elgg_services()->accessCollections->hasAccessToEntity($entity, $user);
241 }
242 
269 function get_write_access_array($user_guid = 0, $site_guid = 0, $flush = false, array $input_params = array()) {
270  return _elgg_services()->accessCollections->getWriteAccessArray($user_guid, $site_guid, $flush, $input_params);
271 }
272 
288  return _elgg_services()->accessCollections->canEdit($collection_id, $user_guid);
289 }
290 
310 function create_access_collection($name, $owner_guid = 0, $site_guid = 0) {
311  return _elgg_services()->accessCollections->create($name, $owner_guid, $site_guid);
312 }
313 
331  return _elgg_services()->accessCollections->update($collection_id, $members);
332 }
333 
344  return _elgg_services()->accessCollections->delete($collection_id);
345 }
346 
360  return _elgg_services()->accessCollections->get($collection_id);
361 }
362 
376  return _elgg_services()->accessCollections->addUser($user_guid, $collection_id);
377 }
378 
392  return _elgg_services()->accessCollections->removeUser($user_guid, $collection_id);
393 }
394 
405 function get_user_access_collections($owner_guid, $site_guid = 0) {
406  return _elgg_services()->accessCollections->getEntityCollections($owner_guid, $site_guid);
407 }
408 
418 function get_members_of_access_collection($collection, $idonly = false) {
419  return _elgg_services()->accessCollections->getMembers($collection, $idonly);
420 }
421 
434 function elgg_get_entities_from_access_id(array $options = array()) {
435  // restrict the resultset to access collection provided
436  if (!isset($options['access_id'])) {
437  return false;
438  }
439 
440  // @todo add support for an array of collection_ids
441  $where = "e.access_id = '{$options['access_id']}'";
442  if (isset($options['wheres'])) {
443  if (is_array($options['wheres'])) {
444  $options['wheres'][] = $where;
445  } else {
446  $options['wheres'] = array($options['wheres'], $where);
447  }
448  } else {
449  $options['wheres'] = array($where);
450  }
451 
452  // return entities with the desired options
453  return _elgg_services()->entityTable->getEntities($options);
454 }
455 
466 function elgg_list_entities_from_access_id(array $options = array()) {
467  return elgg_list_entities($options, 'elgg_get_entities_from_access_id');
468 }
469 
486 function get_readable_access_level($entity_access_id) {
487  return _elgg_services()->accessCollections->getReadableAccessLevel($entity_access_id);
488 }
489 
506  if (!$user_guid || $user_guid <= 0) {
507  $is_admin = false;
508  } else {
509  $is_admin = elgg_is_admin_user($user_guid);
510  }
511 
512  return ($is_admin || _elgg_services()->session->getIgnoreAccess());
513 }
514 
524 
533 function access_init() {
535  $init_finished = true;
536 }
537 
559  $user = elgg_extract('user', $params);
560  if ($user) {
561  $user_guid = $user->guid;
562  } else {
563  $user_guid = _elgg_services()->session->getLoggedInUserGuid();
564  }
565 
566  // don't do this so ignore access still works with no one logged in
567  //if (!$user instanceof \ElggUser) {
568  // return false;
569  //}
570 
571  // check for admin
573  return true;
574  }
575 
576  // check access overrides
578  return true;
579  }
580 
581  // consult other hooks
582  return null;
583 }
584 
596 function access_test($hook, $type, $value, $params) {
597  global $CONFIG;
598  $value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessCollectionsTest.php';
599  $value[] = $CONFIG->path . 'engine/tests/ElggCoreAccessSQLTest.php';
600  return $value;
601 }
602 
603 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
604  // Tell the access functions the system has booted, plugins are loaded,
605  // and the user is logged in so it can start caching
606  $events->registerHandler('ready', 'system', 'access_init');
607 
608  // For overrided permissions
609  $hooks->registerHandler('permissions_check', 'all', 'elgg_override_permissions');
610  $hooks->registerHandler('container_permissions_check', 'all', 'elgg_override_permissions');
611 
612  $hooks->registerHandler('unit_test', 'system', 'access_test');
613 };
foreach($keys as $key=> $default_value) $entity
Definition: access.php:48
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:343
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:533
$members
$value
Definition: longtext.php:26
elgg_list_entities_from_access_id(array $options=array())
Lists entities from an access collection.
Definition: access.php:466
$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:1246
get_access_collection($collection_id)
Get a specified access collection.
Definition: access.php:359
update_access_collection($collection_id, $members)
Updates the membership in an access collection.
Definition: access.php:330
access_test($hook, $type, $value, $params)
Runs unit tests for the access library.
Definition: access.php:596
remove_user_from_access_collection($user_guid, $collection_id)
Removes a user from an access collection.
Definition: access.php:391
elgg_get_ignore_access()
Get current ignore access setting.
Definition: access.php:54
$options
Definition: index.php:14
$params
Definition: access.php:33
$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:405
$init_finished
A flag to set if Elgg&#39;s access initialization is finished.
Definition: access.php:523
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:505
get_members_of_access_collection($collection, $idonly=false)
Get all of members of an access collection.
Definition: access.php:418
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:375
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:269
_elgg_services()
Definition: autoloader.php:14
$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
$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:486
access_get_show_hidden_status()
Return current status of showing disabled entities.
Definition: access.php:172
$collection_id
Definition: delete.php:9
elgg_list_entities(array $options=array(), $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
Definition: entities.php:586
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
Definition: access.php:159
elgg_get_entities_from_access_id(array $options=array())
Return entities based upon access id.
Definition: access.php:434
has_access_to_entity($entity, $user=null)
Can a user access an entity.
Definition: access.php:239
can_edit_access_collection($collection_id, $user_guid=null)
Can the user change this access collection?
Definition: access.php:287
$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:216
create_access_collection($name, $owner_guid=0, $site_guid=0)
Creates a new access collection.
Definition: access.php:310
elgg_override_permissions($hook, $type, $value, $params)
Overrides the access system if appropriate.
Definition: access.php:558