Elgg  Version 1.12
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 
53  if (!$guid) {
54  return false;
55  }
56 
57  return get_entity($guid);
58 }
59 
69 }
70 
96 function default_page_owner_handler($hook, $entity_type, $returnvalue, $params) {
97 
98  if ($returnvalue) {
99  return $returnvalue;
100  }
101 
102  $ia = elgg_set_ignore_access(true);
103 
104  $username = get_input("username");
105  if ($username) {
106  // @todo using a username of group:<guid> is deprecated
107  if (substr_count($username, 'group:')) {
108  preg_match('/group\:([0-9]+)/i', $username, $matches);
109  $guid = $matches[1];
110  if ($entity = get_entity($guid)) {
112  return $entity->getGUID();
113  }
114  }
115 
118  return $user->getGUID();
119  }
120  }
121 
122  $owner = get_input("owner_guid");
123  if ($owner) {
124  if ($user = get_entity($owner)) {
126  return $user->getGUID();
127  }
128  }
129 
130  // ignore root and query
131  $uri = current_page_url();
132  $path = str_replace(elgg_get_site_url(), '', $uri);
133  $path = trim($path, "/");
134  if (strpos($path, "?")) {
135  $path = substr($path, 0, strpos($path, "?"));
136  }
137 
138  // @todo feels hacky
139  $segments = explode('/', $path);
140  if (isset($segments[1]) && isset($segments[2])) {
141  switch ($segments[1]) {
142  case 'owner':
143  case 'friends':
144  $user = get_user_by_username($segments[2]);
145  if ($user) {
147  return $user->getGUID();
148  }
149  break;
150  case 'view':
151  case 'edit':
152  $entity = get_entity($segments[2]);
153  if ($entity) {
155  return $entity->getContainerGUID();
156  }
157  break;
158  case 'add':
159  case 'group':
160  $entity = get_entity($segments[2]);
161  if ($entity) {
163  return $entity->getGUID();
164  }
165  break;
166  }
167  }
168 
170 }
171 
196  return _elgg_services()->context->set($context);
197 }
198 
207 function elgg_get_context() {
208  return _elgg_services()->context->peek();
209 }
210 
219  _elgg_services()->context->push($context);
220 }
221 
228 function elgg_pop_context() {
229  return _elgg_services()->context->pop();
230 }
231 
245  return _elgg_services()->context->contains($context);
246 }
247 
255  return _elgg_services()->context->toArray();
256 }
257 
265 function elgg_set_context_stack(array $stack) {
266  _elgg_services()->context->fromArray($stack);
267 }
268 
277 function page_owner_boot() {
278 
279  elgg_register_plugin_hook_handler('page_owner', 'system', 'default_page_owner_handler');
280 
281  // Bootstrap the context stack by setting its first entry to the handler.
282  // This is the first segment of the URL and the handler is set by the rewrite rules.
283  // @todo this does not work for actions
284 
285  $request = _elgg_services()->request;
286 
287  // don't do this for *_handler.php, etc.
288  if (basename($request->server->get('SCRIPT_FILENAME')) === 'index.php') {
289  $context = $request->getFirstUrlSegment();
290  if (!$context) {
291  $context = 'main';
292  }
293 
295  }
296 }
297 
298 return function(\Elgg\EventsService $events, \Elgg\HooksRegistrationService $hooks) {
299  $events->registerHandler('boot', 'system', 'page_owner_boot');
300 };
$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:277
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:717
elgg_set_context_stack(array $stack)
Set the entire context stack.
Definition: pageowner.php:265
elgg_set_page_owner_guid($guid)
Set the guid of the entity that owns this page.
Definition: pageowner.php:67
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:195
$user
Definition: ban.php:13
elgg_pop_context()
Removes and returns the top context string from the stack.
Definition: pageowner.php:228
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: pageowner.php:244
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Definition: elgglib.php:790
elgg_get_context()
Get the current context.
Definition: pageowner.php:207
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:51
elgg_push_context($context)
Push a context onto the top of the stack.
Definition: pageowner.php:218
default_page_owner_handler($hook, $entity_type, $returnvalue, $params)
Sets the page owner based on request.
Definition: pageowner.php:96
$page_owner_guid
Definition: add.php:9
elgg_get_context_stack()
Get the entire context stack (e.g.
Definition: pageowner.php:254
$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