47 return $elgg_access->setIgnoreAccess($ignore);
108 if (($site_guid == 0) && (isset($CONFIG->site_id))) {
109 $site_guid = $CONFIG->site_id;
112 $site_guid = (int) $site_guid;
114 $hash =
$user_guid . $site_guid .
'get_access_list';
117 return $cache[$hash];
121 $access =
"(" . implode(
",", $access_array) .
")";
123 if ($init_finished) {
168 if (($site_guid == 0) && (isset($CONFIG->site_guid))) {
169 $site_guid = $CONFIG->site_guid;
173 $site_guid = (int) $site_guid;
175 $hash =
$user_guid . $site_guid .
'get_access_array';
178 $access_array = $cache[$hash];
187 $query =
"SELECT am.access_collection_id" 188 .
" FROM {$CONFIG->dbprefix}access_collection_membership am" 189 .
" LEFT JOIN {$CONFIG->dbprefix}access_collections ag ON ag.id = am.access_collection_id" 190 .
" WHERE am.user_guid = $user_guid AND (ag.site_guid = $site_guid OR ag.site_guid = 0)";
195 if (!empty($collection->access_collection_id)) {
196 $access_array[] = (int)$collection->access_collection_id;
202 $query =
"SELECT ag.id FROM {$CONFIG->dbprefix}access_collections ag ";
203 $query .=
"WHERE ag.owner_guid = $user_guid AND (ag.site_guid = $site_guid OR ag.site_guid = 0)";
208 if (!empty($collection->id)) {
209 $access_array[] = (int)$collection->id;
216 if ($ignore_access ==
true) {
221 if ($init_finished) {
222 $cache[$hash] = $access_array;
228 'site_id' => $site_guid
250 $default_access = $CONFIG->default_access;
253 if ($CONFIG->allow_user_default_access) {
256 $user_access =
$user->getPrivateSetting(
'elgg_default_access');
257 if ($user_access !== null) {
258 $default_access = $user_access;
265 'default_access' => $default_access,
289 $ENTITY_SHOW_HIDDEN_OVERRIDE = $show_hidden;
290 return $current_value;
347 'table_alias' =>
'e',
349 'use_enabled_clause' => !$ENTITY_SHOW_HIDDEN_OVERRIDE,
350 'access_column' =>
'access_id',
351 'owner_guid_column' =>
'owner_guid',
352 'guid_column' =>
'guid',
360 foreach (array(
'table_alias',
'access_column',
'owner_guid_column',
'guid_column') as
$key) {
366 $table_alias =
$options[
'table_alias'] ?
$options[
'table_alias'] .
'.' :
'';
376 $clauses[
'ors'][] =
'1 = 1';
379 $clauses[
'ors'][] =
"$table_alias{$options['access_column']} = " .
ACCESS_FRIENDS .
" 380 AND $table_alias{$options['owner_guid_column']} IN ( 381 SELECT guid_one FROM {$CONFIG->dbprefix}entity_relationships 382 WHERE relationship = 'friend' AND guid_two = {$options['user_guid']} 386 $clauses[
'ors'][] =
"$table_alias{$options['owner_guid_column']} = {$options['user_guid']}";
392 $clauses[
'ors'][] =
"$table_alias{$options['access_column']} IN {$access_list}";
395 if (
$options[
'use_enabled_clause']) {
396 $clauses[
'ands'][] =
"{$table_alias}enabled = 'yes'";
402 if (is_array($clauses[
'ors']) && $clauses[
'ors']) {
403 $clauses_str =
'(' . implode(
' OR ', $clauses[
'ors']) .
')';
406 if (is_array($clauses[
'ands']) && $clauses[
'ands']) {
408 $clauses_str .=
' AND ';
410 $clauses_str .=
'(' . implode(
' AND ', $clauses[
'ands']) .
')';
413 return "($clauses_str)";
449 $query =
"SELECT guid from {$CONFIG->dbprefix}entities e WHERE e.guid = " .
$entity->getGUID();
451 $query .=
" AND " . $access_bit;
496 if (($site_guid == 0) && (isset($CONFIG->site_id))) {
497 $site_guid = $CONFIG->site_id;
501 $site_guid = (int) $site_guid;
503 $hash =
$user_guid . $site_guid .
'get_write_access_array';
506 $access_array = $cache[$hash];
509 $access_array = array(
516 $query =
"SELECT ag.* FROM {$CONFIG->dbprefix}access_collections ag ";
517 $query .=
" WHERE (ag.site_guid = $site_guid OR ag.site_guid = 0)";
518 $query .=
" AND (ag.owner_guid = $user_guid)";
523 $access_array[$collection->id] = $collection->name;
527 if ($init_finished) {
528 $cache[$hash] = $access_array;
534 'site_id' => $site_guid
607 if (($site_guid == 0) && (isset($CONFIG->site_guid))) {
608 $site_guid = $CONFIG->site_guid;
612 $q =
"INSERT INTO {$CONFIG->dbprefix}access_collections 613 SET name = '{$name}', 614 owner_guid = {$owner_guid}, 615 site_guid = {$site_guid}";
622 'collection_id' =>
$id 657 $cur_members = (is_array($cur_members)) ? $cur_members : array();
659 $remove_members = array_diff($cur_members,
$members);
660 $add_members = array_diff(
$members, $cur_members);
664 foreach ($add_members as
$guid) {
668 foreach ($remove_members as $guid) {
695 $q =
"DELETE FROM {$CONFIG->dbprefix}access_collection_membership 696 WHERE access_collection_id = {$collection_id}";
699 $q =
"DELETE FROM {$CONFIG->dbprefix}access_collections 700 WHERE id = {$collection_id}";
722 $query =
"SELECT * FROM {$CONFIG->dbprefix}access_collections WHERE id = {$collection_id}";
725 return $get_collection;
764 $q =
"INSERT INTO {$CONFIG->dbprefix}access_collection_membership 765 SET access_collection_id = $collection_id, user_guid = $user_guid 766 ON DUPLICATE KEY UPDATE user_guid = user_guid";
806 $q =
"DELETE FROM {$CONFIG->dbprefix}access_collection_membership 807 WHERE access_collection_id = {$collection_id} 808 AND user_guid = {$user_guid}";
826 $site_guid = (int) $site_guid;
828 if (($site_guid == 0) && (isset($CONFIG->site_guid))) {
829 $site_guid = $CONFIG->site_guid;
832 $query =
"SELECT * FROM {$CONFIG->dbprefix}access_collections 833 WHERE owner_guid = {$owner_guid} 834 AND site_guid = {$site_guid} 856 $query =
"SELECT e.* FROM {$CONFIG->dbprefix}access_collection_membership m" 857 .
" JOIN {$CONFIG->dbprefix}entities e ON e.guid = m.user_guid" 858 .
" WHERE m.access_collection_id = {$collection}";
859 $collection_members =
get_data($query,
"entity_row_to_elggstar");
861 $query =
"SELECT e.guid FROM {$CONFIG->dbprefix}access_collection_membership m" 862 .
" JOIN {$CONFIG->dbprefix}entities e ON e.guid = m.user_guid" 863 .
" WHERE m.access_collection_id = {$collection}";
864 $collection_members =
get_data($query);
865 if (!$collection_members) {
868 foreach ($collection_members as
$key => $val) {
869 $collection_members[
$key] = $val->guid;
873 return $collection_members;
888 if (!isset(
$options[
'access_id'])) {
893 $where =
"e.access_id = '{$options['access_id']}'";
941 $access = (int) $entity_access_id;
944 $access_array = array(
951 if (array_key_exists(
$access, $access_array)) {
959 if (array_key_exists(
$access, $write_access_array)) {
960 return $write_access_array[
$access];
964 return elgg_echo(
'access:limited:label');
1003 static $elgg_access;
1005 if (!$elgg_access) {
1009 return $elgg_access;
1032 $init_finished =
true;
1095 $value[] = $CONFIG->path .
'engine/tests/ElggCoreAccessCollectionsTest.php';
1096 $value[] = $CONFIG->path .
'engine/tests/ElggCoreAccessSQLTest.php';
get_data_row($query, $callback="")
Retrieve a single row from the database.
get_access_array($user_guid=0, $site_guid=0, $flush=false)
Returns an array of access IDs a user is permitted to see.
delete_access_collection($collection_id)
Deletes a specified access collection and its membership.
if($guid==elgg_get_logged_in_user_guid()) $name
access_init()
A quick and dirty way to make sure the access permissions have been correctly set up...
elgg_list_entities_from_access_id(array $options=array())
Lists entities from an access collection.
$guid
Removes an admin notice.
_elgg_get_access_cache()
Return an ElggCache static variable cache for the access caches.
elgg_extract($key, array $array, $default=null, $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
delete_data($query)
Remove a row from the database.
get_access_collection($collection_id)
Get a specified access collection.
update_access_collection($collection_id, $members)
Updates the membership in an access collection.
access_test($hook, $type, $value, $params)
Runs unit tests for the access library.
remove_user_from_access_collection($user_guid, $collection_id)
Removes a user from an access collection.
sanitize_string($string)
Sanitize a string for database use.
insert_data($query)
Insert a row into the database.
elgg_get_ignore_access()
Get current ignore access setting.
get_user_access_collections($owner_guid, $site_guid=0)
Returns an array of database row objects of the access collections owned by $owner_guid.
$init_finished
A flag to set if Elgg's access initialization is finished.
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
elgg_check_access_overrides($user_guid=0)
Decides if the access system should be ignored for a user.
get_user($guid)
Get a user object from a GUID.
get_members_of_access_collection($collection, $idonly=false)
Get all of members of an access collection.
elgg_set_ignore_access($ignore=true)
Set if Elgg's access system should be ignored.
add_user_to_access_collection($user_guid, $collection_id)
Adds a user to an access collection.
elgg_is_admin_user($user_guid)
Check if the given user has full access.
$ENTITY_SHOW_HIDDEN_OVERRIDE
Allow disabled entities and metadata to be returned by getter functions.
sanitise_string($string)
Wrapper function for alternate English spelling (.
elgg_get_entities(array $options=array())
Returns an array of entities with optional filtering.
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
elgg global
Pointer to the global context.
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...
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...
access_get_show_hidden_status()
Return current status of showing disabled entities.
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
elgg_list_entities(array $options=array(), $getter= 'elgg_get_entities', $viewer= 'elgg_view_entity_list')
Returns a string of rendered entities.
get_data($query, $callback="")
Retrieve rows from the database.
access_show_hidden_entities($show_hidden)
Show or hide disabled entities.
elgg_get_entities_from_access_id(array $options=array())
Return entities based upon access id.
has_access_to_entity($entity, $user=null)
Can a user access an entity.
elgg_get_access_object()
Returns the Elgg_Access object.
can_edit_access_collection($collection_id, $user_guid=null)
Can the user change this access collection?
elgg_get_logged_in_user_entity()
Return the current logged in user, or null if no user is logged in.
get_default_access(ElggUser $user=null)
Gets the default access permission.
sanitize_int($int, $signed=true)
Sanitizes an integer for database use.
$user_guid
Avatar remove action.
_elgg_get_access_where_sql(array $options=array())
Returns the SQL where clause for enforcing read access to data.
if(!$collection_name) $id
elgg_get_logged_in_user_guid()
Return the current logged in user by guid.
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.
get_entity($guid)
Loads and returns an entity object from a guid.
create_access_collection($name, $owner_guid=0, $site_guid=0)
Creates a new access collection.
elgg_override_permissions($hook, $type, $value, $params)
Overrides the access system if appropriate.