Elgg  Version 1.9
pagehandler.php
Go to the documentation of this file.
1 <?php
34 function elgg_register_page_handler($identifier, $function) {
35  return _elgg_services()->router->registerPageHandler($identifier, $function);
36 }
37 
48 function elgg_unregister_page_handler($identifier) {
49  _elgg_services()->router->unregisterPageHandler($identifier);
50 }
51 
58 function elgg_gatekeeper() {
59  if (!elgg_is_logged_in()) {
60  _elgg_services()->session->set('last_forward_from', current_page_url());
61  system_message(elgg_echo('loggedinrequired'));
62  forward('/login', 'login');
63  }
64 }
65 
73 function gatekeeper() {
75 }
76 
85 
86  if (!elgg_is_admin_logged_in()) {
87  _elgg_services()->session->set('last_forward_from', current_page_url());
88  register_error(elgg_echo('adminrequired'));
89  forward('', 'admin');
90  }
91 }
92 
100 function admin_gatekeeper() {
102 }
103 
117 function elgg_group_gatekeeper($forward = true, $group_guid = null) {
118  if (null === $group_guid) {
119  $group_guid = elgg_get_page_owner_guid();
120  }
121 
122  if (!$group_guid) {
123  return true;
124  }
125 
126  // this handles non-groups and invisible groups
127  $visibility = Elgg_GroupItemVisibility::factory($group_guid);
128 
129  if (!$visibility->shouldHideItems) {
130  return true;
131  }
132  if ($forward) {
133  // only forward to group if user can see it
134  $group = get_entity($group_guid);
135  $forward_url = $group ? $group->getURL() : '';
136 
137  if (!elgg_is_logged_in()) {
138  _elgg_services()->session->set('last_forward_from', current_page_url());
139  $forward_reason = 'login';
140  } else {
141  $forward_reason = 'member';
142  }
143 
144  $msg_keys = array(
145  'non_member' => 'membershiprequired',
146  'logged_out' => 'loggedinrequired',
147  'no_access' => 'noaccess',
148  );
149  register_error(elgg_echo($msg_keys[$visibility->reasonHidden]));
150  forward($forward_url, $forward_reason);
151  }
152 
153  return false;
154 }
155 
168 function group_gatekeeper($forward = true, $page_owner_guid = null) {
170 }
171 
185 function elgg_entity_gatekeeper($guid, $type = null, $subtype = null) {
187  if (!$entity) {
188  if (!elgg_entity_exists($guid)) {
189  // entity doesn't exist
190  forward('', '404');
191  } elseif (!elgg_is_logged_in()) {
192  // entity requires at least a logged in user
193  elgg_gatekeeper();
194  } else {
195  // user is logged in but still does not have access to it
196  register_error(elgg_echo('limited_access'));
197  forward();
198  }
199  }
200 
201  if ($type) {
203  // entity is of wrong type/subtype
204  forward('', '404');
205  }
206  }
207 }
208 
215 
216  if (elgg_is_logged_in()) {
217  forward('activity');
218  }
219 
220  $title = elgg_echo('content:latest');
222  if (!$content) {
223  $content = elgg_echo('river:none');
224  }
225 
226  $login_box = elgg_view('core/account/login_box');
227 
228  $params = array(
229  'title' => $title,
230  'content' => $content,
231  'sidebar' => $login_box
232  );
233  $body = elgg_view_layout('one_sidebar', $params);
234  echo elgg_view_page(null, $body);
235  return true;
236 }
237 
252  if (elgg_view_exists("errors/$type")) {
253  $title = elgg_echo("error:$type:title");
254  if ($title == "error:$type:title") {
255  // use default if there is no title for this error type
256  $title = elgg_echo("error:default:title");
257  }
258 
259  $content = elgg_view("errors/$type", $params);
260  } else {
261  $title = elgg_echo("error:default:title");
262  $content = elgg_view("errors/default", $params);
263  }
264 
265  $httpCodes = array(
266  '400' => 'Bad Request',
267  '401' => 'Unauthorized',
268  '403' => 'Forbidden',
269  '404' => 'Not Found',
270  '407' => 'Proxy Authentication Required',
271  '500' => 'Internal Server Error',
272  '503' => 'Service Unavailable',
273  );
274 
275  if (isset($httpCodes[$type])) {
276  header("HTTP/1.1 $type {$httpCodes[$type]}");
277  }
278 
279  $body = elgg_view_layout('error', array(
280  'title' => $title,
281  'content' => $content,
282  ));
283  echo elgg_view_page($title, $body, 'error');
284  exit;
285 }
286 
294  elgg_register_page_handler('', 'elgg_front_page_handler');
295  // Registered at 600 so that plugins can register at the default 500 and get to run first
296  elgg_register_plugin_hook_handler('forward', '404', 'elgg_error_page_handler', 600);
297 }
298 
299 elgg_register_event_handler('init', 'system', '_elgg_page_handler_init');
elgg_list_river(array $options=array())
List river items.
Definition: river.php:490
_elgg_page_handler_init()
Initializes the page handler/routing system.
elgg_is_logged_in()
Returns whether or not the user is currently logged in.
Definition: sessions.php:56
elgg_is_admin_logged_in()
Returns whether or not the viewer is currently logged in and an admin user.
Definition: sessions.php:65
current_page_url()
Returns the current page&#39;s complete URL.
Definition: input.php:106
elgg_group_gatekeeper($forward=true, $group_guid=null)
May the current user access item(s) on this page? If the page owner is a group, membership, visibility, and logged in status are taken into account.
elgg_view_exists($view, $viewtype= '', $recurse=true)
Returns whether the specified view exists.
Definition: views.php:318
admin_gatekeeper()
Alias of elgg_admin_gatekeeper()
elgg_entity_exists($guid)
Does an entity exist?
Definition: entities.php:673
$guid
Removes an admin notice.
exit
Definition: reorder.php:12
elgg forward
Meant to mimic the php forward() function by simply redirecting the user to another page...
Definition: elgglib.js:419
elgg_entity_gatekeeper($guid, $type=null, $subtype=null)
Can the viewer see this entity?
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
Definition: elgglib.php:853
$title
Definition: save.php:24
$params
Definition: login.php:72
static factory($container_guid, $use_cache=true)
Determine visibility of items within a container for the current user.
elgg_error_page_handler($hook, $type, $result, $params)
Serve an error page.
group_gatekeeper($forward=true, $page_owner_guid=null)
May the current user access item(s) on this page? If the page owner is a group, membership, visibility, and logged in status are taken into account.
elgg_gatekeeper()
Used at the top of a page to mark it as logged in users only.
Definition: pagehandler.php:58
elgg_instanceof($entity, $type=null, $subtype=null, $class=null)
Checks if $entity is an ElggEntity and optionally for type and subtype.
Definition: entities.php:1886
elgg_echo($message_key, $args=array(), $language="")
Given a message key, returns an appropriately translated full-text string.
Definition: languages.php:21
_elgg_services()
Definition: autoloader.php:14
$forward
Definition: delete.php:35
elgg echo
Translates a string.
Definition: languages.js:43
elgg_register_page_handler($identifier, $function)
Registers a page handler for a particular identifier.
Definition: pagehandler.php:34
$type
Definition: add.php:8
elgg_view($view, $vars=array(), $bypass=false, $ignored=false, $viewtype= '')
Return a parsed view.
Definition: views.php:354
elgg_view_layout($layout_name, $vars=array())
Displays a layout with optional parameters.
Definition: views.php:617
elgg system_message
Wrapper function for system_messages.
Definition: elgglib.js:374
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
Definition: elgglib.php:669
elgg_unregister_page_handler($identifier)
Unregister a page handler for an identifier.
Definition: pagehandler.php:48
elgg_admin_gatekeeper()
Used at the top of a page to mark it as admin only.
Definition: pagehandler.php:83
elgg register_error
Wrapper function for system_messages.
Definition: elgglib.js:383
$forward_url
Definition: login.php:73
$content
Set robots.txt action.
Definition: set_robots.php:6
elgg_view_page($title, $body, $page_shell= 'default', $vars=array())
Assembles and outputs a full page.
Definition: views.php:437
$login_box
Definition: login.php:15
$page_owner_guid
Definition: add.php:9
clearfix elgg elgg elgg elgg page header
Definition: admin.php:127
$entity
Definition: delete.php:10
$subtype
Definition: river.php:10
elgg_get_page_owner_guid($guid=0)
Gets the guid of the entity that owns the current page.
Definition: pageowner.php:18
gatekeeper()
Alias of elgg_gatekeeper()
Definition: pagehandler.php:73
elgg_front_page_handler()
Front page handler.
get_entity($guid)
Loads and returns an entity object from a guid.
Definition: entities.php:604