Elgg  Version 3.0
pageowner.php
Go to the documentation of this file.
1 <?php
11 
23  static $page_owner_guid;
24 
25  if ($guid === false || $guid === null) {
26  $page_owner_guid = 0;
27  return $page_owner_guid;
28  }
29 
30  if ($guid) {
31  $page_owner_guid = (int) $guid;
32  }
33 
34  if (isset($page_owner_guid)) {
35  return $page_owner_guid;
36  }
37 
38  $route = _elgg_services()->request->getRoute();
39  if ($route instanceof Route) {
40  $page_owner = $route->resolvePageOwner();
41  if ($page_owner) {
43  return $page_owner_guid;
44  }
45  }
46 
47  // return guid of page owner entity
48  // Note: core registers default_page_owner_handler() to handle this hook.
49  $guid = (int) elgg_trigger_plugin_hook('page_owner', 'system', null, 0);
50 
51  if ($guid) {
53  }
54 
55  return $guid;
56 }
57 
67  if (!$guid) {
68  return false;
69  }
70 
71  return get_entity($guid);
72 }
73 
83 }
84 
110 function default_page_owner_handler($hook, $entity_type, $returnvalue, $params) {
111 
112  if ($returnvalue) {
113  return $returnvalue;
114  }
115 
116  $ia = elgg_set_ignore_access(true);
117 
118  $username = get_input("username");
121  return $user->getGUID();
122  }
123 
124  $owner = get_input("owner_guid");
125  if ($owner) {
126  if ($user = get_entity($owner)) {
128  return $user->getGUID();
129  }
130  }
131 
132  // @todo feels hacky
133  $segments = _elgg_services()->request->getUrlSegments();
134  if (isset($segments[1]) && isset($segments[2])) {
135  switch ($segments[1]) {
136  case 'owner':
137  case 'friends':
138  $user = get_user_by_username($segments[2]);
139  if ($user) {
141  return $user->getGUID();
142  }
143  break;
144  case 'view':
145  case 'edit':
146  $entity = get_entity($segments[2]);
147  if ($entity) {
149  return $entity->getContainerGUID();
150  }
151  break;
152  case 'add':
153  case 'group':
154  $entity = get_entity($segments[2]);
155  if ($entity) {
157  return $entity->getGUID();
158  }
159  break;
160  }
161  }
162 
164 }
165 
190  return _elgg_services()->request->getContextStack()->set($context);
191 }
192 
201 function elgg_get_context() {
202  return _elgg_services()->request->getContextStack()->peek();
203 }
204 
213  _elgg_services()->request->getContextStack()->push($context);
214 }
215 
222 function elgg_pop_context() {
223  return _elgg_services()->request->getContextStack()->pop();
224 }
225 
239  return _elgg_services()->request->getContextStack()->contains($context);
240 }
241 
249  return _elgg_services()->request->getContextStack()->toArray();
250 }
251 
259 function elgg_set_context_stack(array $stack) {
260  _elgg_services()->request->getContextStack()->fromArray($stack);
261 }
262 
270  elgg_register_plugin_hook_handler('page_owner', 'system', 'default_page_owner_handler');
271 }
272 
276 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
277  $events->registerHandler('init', 'system', '_elgg_pageowner_init');
278 };
$context
Definition: add.php:8
$username
Definition: delete.php:23
$params
Saves global plugin settings.
Definition: save.php:13
Events service.
$guid
Removes an admin notice.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Definition: elgglib.php:634
elgg_set_context_stack(array $stack)
Set the entire context stack.
Definition: pageowner.php:259
elgg_set_page_owner_guid($guid)
Set the guid of the entity that owns this page.
Definition: pageowner.php:81
get_user_by_username($username)
Get user by username.
Definition: users.php:61
Route Wrapper.
Definition: Route.php:8
Base class for events and hooks.
$entity
Definition: reset.php:8
$owner
Definition: crop.php:7
elgg_set_ignore_access($ignore=true)
Set if Elgg&#39;s access system should be ignored.
Definition: access.php:52
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
_elgg_pageowner_init()
Set up default page owner default.
Definition: pageowner.php:269
elgg_set_context($context)
Sets the page context.
Definition: pageowner.php:189
$user
Definition: ban.php:7
elgg_pop_context()
Removes and returns the top context string from the stack.
Definition: pageowner.php:222
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: pageowner.php:238
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:720
elgg_get_context()
Get the current context.
Definition: pageowner.php:201
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:65
$page_owner
Definition: add.php:15
elgg_push_context($context)
Push a context onto the top of the stack.
Definition: pageowner.php:212
default_page_owner_handler($hook, $entity_type, $returnvalue, $params)
Sets the page owner based on request.
Definition: pageowner.php:110
_elgg_services()
Get the global service provider.
Definition: elgglib.php:1292
$page_owner_guid
Elgg widget add action.
Definition: add.php:6
elgg_get_context_stack()
Get the entire context stack (e.g.
Definition: pageowner.php:248
elgg_get_page_owner_guid($guid=0)
Gets the guid of the entity that owns the current page.
Definition: pageowner.php:22
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:87