Elgg  Version 2.3
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  // return guid of page owner entity
39  // Note: core registers default_page_owner_handler() to handle this hook.
40  $guid = (int)elgg_trigger_plugin_hook('page_owner', 'system', null, 0);
41 
42  if ($guid) {
44  }
45 
46  return $guid;
47 }
48 
58  if (!$guid) {
59  return false;
60  }
61 
62  return get_entity($guid);
63 }
64 
74 }
75 
101 function default_page_owner_handler($hook, $entity_type, $returnvalue, $params) {
102 
103  if ($returnvalue) {
104  return $returnvalue;
105  }
106 
107  $ia = elgg_set_ignore_access(true);
108 
109  $username = get_input("username");
110  if ($username) {
111  // @todo using a username of group:<guid> is deprecated
112  if (substr_count($username, 'group:')) {
113  preg_match('/group\:([0-9]+)/i', $username, $matches);
114  $guid = $matches[1];
115  if ($entity = get_entity($guid)) {
117  return $entity->getGUID();
118  }
119  }
120 
123  return $user->getGUID();
124  }
125  }
126 
127  $owner = get_input("owner_guid");
128  if ($owner) {
129  if ($user = get_entity($owner)) {
131  return $user->getGUID();
132  }
133  }
134 
135  // @todo feels hacky
136  $segments = _elgg_services()->request->getUrlSegments();
137  if (isset($segments[1]) && isset($segments[2])) {
138  switch ($segments[1]) {
139  case 'owner':
140  case 'friends':
141  $user = get_user_by_username($segments[2]);
142  if ($user) {
144  return $user->getGUID();
145  }
146  break;
147  case 'view':
148  case 'edit':
149  $entity = get_entity($segments[2]);
150  if ($entity) {
152  return $entity->getContainerGUID();
153  }
154  break;
155  case 'add':
156  case 'group':
157  $entity = get_entity($segments[2]);
158  if ($entity) {
160  return $entity->getGUID();
161  }
162  break;
163  }
164  }
165 
167 }
168 
193  return _elgg_services()->context->set($context);
194 }
195 
204 function elgg_get_context() {
205  return _elgg_services()->context->peek();
206 }
207 
216  _elgg_services()->context->push($context);
217 }
218 
225 function elgg_pop_context() {
226  return _elgg_services()->context->pop();
227 }
228 
242  return _elgg_services()->context->contains($context);
243 }
244 
252  return _elgg_services()->context->toArray();
253 }
254 
262 function elgg_set_context_stack(array $stack) {
263  _elgg_services()->context->fromArray($stack);
264 }
265 
273 function _elgg_set_initial_context(\Elgg\Http\Request $request) {
274  // don't do this for *_handler.php, etc.
275  if (basename($request->server->get('SCRIPT_FILENAME')) === 'index.php') {
276  $context = $request->getFirstUrlSegment();
277  if (!$context) {
278  $context = 'main';
279  }
280 
281  _elgg_services()->context->set($context);
282  }
283 }
284 
291 function page_owner_boot() {
292  elgg_register_plugin_hook_handler('page_owner', 'system', 'default_page_owner_handler');
293 
295 }
296 
297 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
298  $events->registerHandler('boot', 'system', 'page_owner_boot');
299 };
Elgg HTTP request.
Definition: Request.php:12
$context
Definition: add.php:11
$username
Definition: delete.php:22
page_owner_boot()
Initializes the page owner functions.
Definition: pageowner.php:291
$guid
Removes an admin notice.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Definition: elgglib.php:740
elgg_set_context_stack(array $stack)
Set the entire context stack.
Definition: pageowner.php:262
elgg_set_page_owner_guid($guid)
Set the guid of the entity that owns this page.
Definition: pageowner.php:72
get_user_by_username($username)
Get user by username.
Definition: users.php:98
$params
Definition: login.php:72
Save menu items.
$owner
Definition: crop.php:8
elgg_set_ignore_access($ignore=true)
Set if Elgg&#39;s access system should be ignored.
Definition: access.php:43
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
elgg_set_context($context)
Sets the page context.
Definition: pageowner.php:192
$user
Definition: ban.php:13
elgg_pop_context()
Removes and returns the top context string from the stack.
Definition: pageowner.php:225
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: pageowner.php:241
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:826
elgg_get_context()
Get the current context.
Definition: pageowner.php:204
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:56
_elgg_services(\Elgg\Di\ServiceProvider $services=null)
Get the global service provider.
Definition: autoloader.php:17
elgg_push_context($context)
Push a context onto the top of the stack.
Definition: pageowner.php:215
default_page_owner_handler($hook, $entity_type, $returnvalue, $params)
Sets the page owner based on request.
Definition: pageowner.php:101
$entity
Definition: delete.php:7
$page_owner_guid
Definition: add.php:9
elgg_get_context_stack()
Get the entire context stack (e.g.
Definition: pageowner.php:251
http free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:5
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:204
_elgg_set_initial_context(\Elgg\Http\Request $request)
Set an initial context if using index.php front controller.
Definition: pageowner.php:273