Elgg  Version 1.9
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  global $CONFIG;
203 
204  $context = trim($context);
205 
206  if (empty($context)) {
207  return false;
208  }
209 
210  $context = strtolower($context);
211 
212  array_pop($CONFIG->context);
213  array_push($CONFIG->context, $context);
214 
215  return true;
216 }
217 
226 function elgg_get_context() {
227  global $CONFIG;
228 
229  if (!$CONFIG->context) {
230  return null;
231  }
232 
233  return $CONFIG->context[count($CONFIG->context) - 1];
234 }
235 
244  global $CONFIG;
245 
246  array_push($CONFIG->context, $context);
247 }
248 
255 function elgg_pop_context() {
256  global $CONFIG;
257 
258  return array_pop($CONFIG->context);
259 }
260 
274  global $CONFIG;
275 
276  return in_array($context, $CONFIG->context);
277 }
278 
287 function page_owner_boot() {
288 
289  elgg_register_plugin_hook_handler('page_owner', 'system', 'default_page_owner_handler');
290 
291  // Bootstrap the context stack by setting its first entry to the handler.
292  // This is the first segment of the URL and the handler is set by the rewrite rules.
293  // @todo this does not work for actions
294 
295  $request = _elgg_services()->request;
296 
297  // don't do this for *_handler.php, etc.
298  if (basename($request->server->get('SCRIPT_FILENAME')) === 'index.php') {
299  $context = $request->getFirstUrlSegment();
300  if (!$context) {
301  $context = 'main';
302  }
303 
305  }
306 }
307 
308 elgg_register_event_handler('boot', 'system', 'page_owner_boot');
$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:287
current_page_url()
Returns the current page&#39;s complete URL.
Definition: input.php:106
$ia
Definition: upgrade.php:26
$guid
Removes an admin notice.
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
Definition: elgglib.php:853
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:246
$params
Definition: login.php:72
$request
$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
global $CONFIG
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:255
elgg_in_context($context)
Check if this context exists anywhere in the stack.
Definition: pageowner.php:273
elgg_trigger_plugin_hook($hook, $type, $params=null, $returnvalue=null)
Trigger a Plugin Hook and run all handler callbacks registered to that hook:type. ...
Definition: elgglib.php:925
elgg_get_context()
Get the current context.
Definition: pageowner.php:226
elgg global
Pointer to the global context.
Definition: elgglib.js:12
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_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
Definition: elgglib.php:669
elgg_push_context($context)
Push a context onto the top of the stack.
Definition: pageowner.php:243
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
$entity
Definition: delete.php:10
$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:604