Elgg  Version 2.3
access.php
Go to the documentation of this file.
1 <?php
19 // bail if set to a unusable value
20 if (isset($vars['options_values'])) {
21  if (!is_array($vars['options_values']) || empty($vars['options_values'])) {
22  return;
23  }
24 }
25 
26 $entity_allows_comments = elgg_extract('entity_allows_comments', $vars, true);
27 unset($vars['entity_allows_comments']);
28 
29 $vars['class'] = elgg_extract_class($vars, 'elgg-input-access');
30 
31 // this will be passed to plugin hooks ['access:collections:write', 'user'] and ['default', 'access']
32 $params = array();
33 
34 $keys = array(
35  'entity' => null,
36  'entity_type' => null,
37  'entity_subtype' => null,
38  'container_guid' => null,
39  'purpose' => 'read',
40 );
41 foreach ($keys as $key => $default_value) {
42  $params[$key] = elgg_extract($key, $vars, $default_value);
43  unset($vars[$key]);
44 }
45 
46 /* @var ElggEntity $entity */
47 $entity = $params['entity'];
48 
49 if ($entity) {
50  $params['value'] = $entity->access_id;
51  $params['entity_type'] = $entity->type;
52  $params['entity_subtype'] = $entity->getSubtype();
53  $params['container_guid'] = $entity->container_guid;
54 
55  if ($entity_allows_comments && ($entity->access_id != ACCESS_PUBLIC)) {
56  $vars['data-comment-count'] = (int) $entity->countComments();
57  $vars['data-original-value'] = $entity->access_id;
58  }
59 }
60 
62 if (!$params['container_guid'] && $container) {
63  $params['container_guid'] = $container->guid;
64 }
65 
66 // don't call get_default_access() unless we need it
67 if (!isset($vars['value']) || $vars['value'] == ACCESS_DEFAULT) {
68  if ($entity) {
69  $vars['value'] = $entity->access_id;
70  } else if (empty($vars['options_values']) || !is_array($vars['options_values'])) {
71  $vars['value'] = get_default_access(null, $params);
72  } else {
73  $options_values_ids = array_keys($vars['options_values']);
74  $vars['value'] = $options_values_ids[0];
75  }
76 }
77 
78 $params['value'] = $vars['value'];
79 
80 // don't call get_write_access_array() unless we need it
81 if (!isset($vars['options_values'])) {
82  $vars['options_values'] = get_write_access_array(0, 0, false, $params);
83 }
84 
85 if (!isset($vars['disabled'])) {
86  $vars['disabled'] = false;
87 }
88 
89 // if access is set to a value not present in the available options, add the option
90 if (!isset($vars['options_values'][$vars['value']])) {
91  $acl = get_access_collection($vars['value']);
92  $display = $acl ? $acl->name : elgg_echo('access:missing_name');
93  $vars['options_values'][$vars['value']] = $display;
94 }
95 
96 // should we tell users that public/logged-in access levels will be ignored?
97 if (($container instanceof ElggGroup)
98  && $container->getContentAccessMode() === ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY
99  && !elgg_in_context('group-edit')
100  && !($entity instanceof ElggGroup)) {
101  $show_override_notice = true;
102 } else {
103  $show_override_notice = false;
104 }
105 
106 if ($show_override_notice) {
107  $vars['data-group-acl'] = $container->group_acl;
108 }
109 echo elgg_view('input/select', $vars);
110 if ($show_override_notice) {
111  echo elgg_format_element('p', ['class' => 'elgg-text-help'], elgg_echo('access:overridenotice'));
112 }
foreach($keys as $key=> $default_value) $entity
Definition: access.php:47
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
if(isset($vars['options_values'])) $entity_allows_comments
Elgg access level input Displays a dropdown input field.
Definition: access.php:26
get_access_collection($collection_id)
Get a specified access collection.
Definition: access.php:357
elgg_extract_class(array $array, $existing=[])
Extract class names from an array with key "class", optionally merging into a preexisting set...
Definition: elgglib.php:1396
$keys
Definition: access.php:34
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:208
$params
Definition: access.php:32
if($entity) $container
Definition: access.php:61
get_default_access(ElggUser $user=null, array $input_params=array())
Gets the default access permission.
Definition: access.php:118
$key
Definition: summary.php:34
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
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: pageowner.php:241
elgg echo
Translates a string.
Definition: languages.js:48
elgg_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:336
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:56
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
const CONTENT_ACCESS_MODE_MEMBERS_ONLY
Definition: ElggGroup.php:16
$vars['class']
Definition: access.php:29
const ACCESS_PUBLIC
Definition: elgglib.php:2084
const ACCESS_DEFAULT
Definition: elgglib.php:2081