Elgg  Version 1.11
pageowner.php
Go to the documentation of this file.
1 <?php
19  static $page_owner_guid;
20 
21  if ($guid === false || $guid === null) {
22  $page_owner_guid = 0;
23  return $page_owner_guid;
24  }
25 
26  if ($guid) {
27  $page_owner_guid = (int)$guid;
28  }
29 
30  if (isset($page_owner_guid)) {
31  return $page_owner_guid;
32  }
33 
34  // return guid of page owner entity
35  $guid = (int)elgg_trigger_plugin_hook('page_owner', 'system', null, 0);
36 
37  if ($guid) {
39  }
40 
41  return $guid;
42 }
43 
55  if ($guid > 0) {
59 
60  return $owner;
61  }
62 
63  return false;
64 }
65 
75 }
76 
102 function default_page_owner_handler($hook, $entity_type, $returnvalue, $params) {
103 
104  if ($returnvalue) {
105  return $returnvalue;
106  }
107 
108  $ia = elgg_set_ignore_access(true);
109 
110  $username = get_input("username");
111  if ($username) {
112  // @todo using a username of group:<guid> is deprecated
113  if (substr_count($username, 'group:')) {
114  preg_match('/group\:([0-9]+)/i', $username, $matches);
115  $guid = $matches[1];
116  if ($entity = get_entity($guid)) {
118  return $entity->getGUID();
119  }
120  }
121 
124  return $user->getGUID();
125  }
126  }
127 
128  $owner = get_input("owner_guid");
129  if ($owner) {
130  if ($user = get_entity($owner)) {
132  return $user->getGUID();
133  }
134  }
135 
136  // ignore root and query
137  $uri = current_page_url();
138  $path = str_replace(elgg_get_site_url(), '', $uri);
139  $path = trim($path, "/");
140  if (strpos($path, "?")) {
141  $path = substr($path, 0, strpos($path, "?"));
142  }
143 
144  // @todo feels hacky
145  $segments = explode('/', $path);
146  if (isset($segments[1]) && isset($segments[2])) {
147  switch ($segments[1]) {
148  case 'owner':
149  case 'friends':
150  $user = get_user_by_username($segments[2]);
151  if ($user) {
153  return $user->getGUID();
154  }
155  break;
156  case 'view':
157  case 'edit':
158  $entity = get_entity($segments[2]);
159  if ($entity) {
161  return $entity->getContainerGUID();
162  }
163  break;
164  case 'add':
165  case 'group':
166  $entity = get_entity($segments[2]);
167  if ($entity) {
169  return $entity->getGUID();
170  }
171  break;
172  }
173  }
174 
176 }
177 
202  return _elgg_services()->context->set($context);
203 }
204 
213 function elgg_get_context() {
214  return _elgg_services()->context->peek();
215 }
216 
225  _elgg_services()->context->push($context);
226 }
227 
234 function elgg_pop_context() {
235  return _elgg_services()->context->pop();
236 }
237 
251  return _elgg_services()->context->contains($context);
252 }
253 
261  return _elgg_services()->context->toArray();
262 }
263 
271 function elgg_set_context_stack(array $stack) {
272  _elgg_services()->context->fromArray($stack);
273 }
274 
283 function page_owner_boot() {
284 
285  elgg_register_plugin_hook_handler('page_owner', 'system', 'default_page_owner_handler');
286 
287  // Bootstrap the context stack by setting its first entry to the handler.
288  // This is the first segment of the URL and the handler is set by the rewrite rules.
289  // @todo this does not work for actions
290 
291  $request = _elgg_services()->request;
292 
293  // don't do this for *_handler.php, etc.
294  if (basename($request->server->get('SCRIPT_FILENAME')) === 'index.php') {
295  $context = $request->getFirstUrlSegment();
296  if (!$context) {
297  $context = 'main';
298  }
299 
301  }
302 }
303 
304 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
305  $events->registerHandler('boot', 'system', 'page_owner_boot');
306 };
$context
Definition: add.php:11
get_input($variable, $default=null, $filter_result=true)
Get some input from variables passed submitted through GET or POST.
Definition: input.php:27
$username
Definition: delete.php:22
page_owner_boot()
Initializes the page owner functions.
Definition: pageowner.php:283
current_page_url()
Returns the current page&#39;s complete URL.
Definition: input.php:65
$ia
Definition: upgrade.php:26
$guid
Removes an admin notice.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Definition: elgglib.php:703
elgg_set_context_stack(array $stack)
Set the entire context stack.
Definition: pageowner.php:271
elgg_set_page_owner_guid($guid)
Set the guid of the entity that owns this page.
Definition: pageowner.php:73
get_user_by_username($username)
Get user by username.
Definition: users.php:98
$params
Definition: login.php:72
$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
_elgg_services()
Definition: autoloader.php:14
elgg_set_context($context)
Sets the page context.
Definition: pageowner.php:201
$user
Definition: ban.php:13
elgg_pop_context()
Removes and returns the top context string from the stack.
Definition: pageowner.php:234
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: pageowner.php:250
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:775
elgg_get_context()
Get the current context.
Definition: pageowner.php:213
elgg_get_site_url($site_guid=0)
Get the URL for the current (or specified) site.
elgg_get_page_owner_entity()
Gets the owner entity for the current page.
Definition: pageowner.php:53
elgg_push_context($context)
Push a context onto the top of the stack.
Definition: pageowner.php:224
default_page_owner_handler($hook, $entity_type, $returnvalue, $params)
Sets the page owner based on request.
Definition: pageowner.php:102
$page_owner_guid
Definition: add.php:9
elgg_get_context_stack()
Get the entire context stack (e.g.
Definition: pageowner.php:260
$entity
Definition: delete.php:10
$request
$path
Definition: invalid.php:17
elgg_get_page_owner_guid($guid=0)
Gets the guid of the entity that owns the current page.
Definition: pageowner.php:18
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:382