Elgg  Version 2.2
 All Classes Namespaces Files Functions Variables Pages
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'] = (array) elgg_extract('class', $vars, []);
30 $vars['class'][] = 'elgg-input-access';
31 
32 // this will be passed to plugin hooks ['access:collections:write', 'user'] and ['default', 'access']
33 $params = array();
34 
35 $keys = array(
36  'entity' => null,
37  'entity_type' => null,
38  'entity_subtype' => null,
39  'container_guid' => null,
40  'purpose' => 'read',
41 );
42 foreach ($keys as $key => $default_value) {
43  $params[$key] = elgg_extract($key, $vars, $default_value);
44  unset($vars[$key]);
45 }
46 
47 /* @var ElggEntity $entity */
48 $entity = $params['entity'];
49 
50 if ($entity) {
51  $params['value'] = $entity->access_id;
52  $params['entity_type'] = $entity->type;
53  $params['entity_subtype'] = $entity->getSubtype();
54  $params['container_guid'] = $entity->container_guid;
55 
56  if ($entity_allows_comments && ($entity->access_id != ACCESS_PUBLIC)) {
57  $vars['data-comment-count'] = (int) $entity->countComments();
58  $vars['data-original-value'] = $entity->access_id;
59  }
60 }
61 
63 if (!$params['container_guid'] && $container) {
64  $params['container_guid'] = $container->guid;
65 }
66 
67 // don't call get_default_access() unless we need it
68 if (!isset($vars['value']) || $vars['value'] == ACCESS_DEFAULT) {
69  if ($entity) {
70  $vars['value'] = $entity->access_id;
71  } else if (empty($vars['options_values']) || !is_array($vars['options_values'])) {
72  $vars['value'] = get_default_access(null, $params);
73  } else {
74  $options_values_ids = array_keys($vars['options_values']);
75  $vars['value'] = $options_values_ids[0];
76  }
77 }
78 
79 $params['value'] = $vars['value'];
80 
81 // don't call get_write_access_array() unless we need it
82 if (!isset($vars['options_values'])) {
83  $vars['options_values'] = get_write_access_array(0, 0, false, $params);
84 }
85 
86 if (!isset($vars['disabled'])) {
87  $vars['disabled'] = false;
88 }
89 
90 // if access is set to a value not present in the available options, add the option
91 if (!isset($vars['options_values'][$vars['value']])) {
92  $acl = get_access_collection($vars['value']);
93  $display = $acl ? $acl->name : elgg_echo('access:missing_name');
94  $vars['options_values'][$vars['value']] = $display;
95 }
96 
97 // should we tell users that public/logged-in access levels will be ignored?
98 if (($container instanceof ElggGroup)
99  && $container->getContentAccessMode() === ElggGroup::CONTENT_ACCESS_MODE_MEMBERS_ONLY
100  && !elgg_in_context('group-edit')
101  && !($entity instanceof ElggGroup)) {
102  $show_override_notice = true;
103 } else {
104  $show_override_notice = false;
105 }
106 
107 if ($show_override_notice) {
108  $vars['data-group-acl'] = $container->group_acl;
109 }
110 echo elgg_view('input/select', $vars);
111 if ($show_override_notice) {
112  echo elgg_format_element('p', ['class' => 'elgg-text-help'], elgg_echo('access:overridenotice'));
113 }
foreach($keys as $key=> $default_value) $entity
Definition: access.php:48
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
$keys
Definition: access.php:35
elgg_format_element($tag_name, array $attributes=array(), $text= '', array $options=array())
Format an HTML element.
Definition: output.php:218
$params
Definition: access.php:33
if($entity) $container
Definition: access.php:62
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_view($view, $vars=array(), $ignore1=false, $ignore2=false, $viewtype= '')
Return a parsed view.
Definition: views.php:342
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:1310
const CONTENT_ACCESS_MODE_MEMBERS_ONLY
Definition: ElggGroup.php:16
$vars['class']
Definition: access.php:29
const ACCESS_PUBLIC
Definition: elgglib.php:1990
const ACCESS_DEFAULT
Definition: elgglib.php:1987