Elgg  Version 1.10
actions.php
Go to the documentation of this file.
1 <?php
19 function _elgg_action_handler(array $segments) {
20  _elgg_services()->actions->execute(implode('/', $segments));
21 }
22 
47 function action($action, $forwarder = "") {
48  _elgg_services()->actions->execute($action, $forwarder);
49 }
50 
85 function elgg_register_action($action, $filename = "", $access = 'logged_in') {
86  return _elgg_services()->actions->register($action, $filename, $access);
87 }
88 
97  return _elgg_services()->actions->unregister($action);
98 }
99 
116 function validate_action_token($visible_errors = true, $token = null, $ts = null) {
117  return _elgg_services()->actions->validateActionToken($visible_errors, $token, $ts);
118 }
119 
135  return _elgg_services()->actions->gatekeeper($action);
136 }
137 
157  return _elgg_services()->actions->generateActionToken($timestamp);
158 }
159 
171 function init_site_secret() {
172  return _elgg_services()->siteSecret->init();
173 }
174 
184 function get_site_secret() {
185  return _elgg_services()->siteSecret->get();
186 }
187 
195  return _elgg_services()->siteSecret->getStrength();
196 }
197 
207  return _elgg_services()->actions->exists($action);
208 }
209 
216 function elgg_is_xhr() {
217  return _elgg_services()->request->isXmlHttpRequest();
218 }
219 
246 function ajax_forward_hook($hook, $type, $reason, $params) {
247  _elgg_services()->actions->ajaxForwardHook($hook, $type, $reason, $params);
248 }
249 
255 function ajax_action_hook() {
256  _elgg_services()->actions->ajaxActionHook();
257 }
258 
265 
266  if (!elgg_is_xhr()) {
267  return false;
268  }
269 
270  $ts = time();
272  $data = array(
273  '__elgg_ts' => $ts,
274  '__elgg_token' => $token,
275  'logged_in' => elgg_is_logged_in(),
276  );
277 
278  header("Content-Type: application/json");
279  echo json_encode($data);
280 
281  return true;
282 }
283 
288 function actions_init() {
289  elgg_register_page_handler('action', '_elgg_action_handler');
290  elgg_register_page_handler('refresh_token', '_elgg_csrf_token_refresh');
291 
292  elgg_register_simplecache_view('js/languages/en');
293 
294  elgg_register_plugin_hook_handler('action', 'all', 'ajax_action_hook');
295  elgg_register_plugin_hook_handler('forward', 'all', 'ajax_forward_hook');
296 }
297 
298 elgg_register_event_handler('init', 'system', 'actions_init');
elgg_is_logged_in()
Returns whether or not the user is currently logged in.
Definition: sessions.php:51
elgg_is_xhr()
Checks whether the request was requested via ajax.
Definition: actions.php:216
action($action, $forwarder="")
Perform an action.
Definition: actions.php:47
action_gatekeeper($action)
Validates the presence of action tokens.
Definition: actions.php:134
elgg_action_exists($action)
Check if an action is registered and its script exists.
Definition: actions.php:206
elgg_register_simplecache_view($view_name)
Registers a view to simple cache.
Definition: cache.php:98
$data
Definition: opendd.php:13
if(!$autoload_available) _elgg_services()
Definition: autoloader.php:20
init_site_secret()
Initialise the site secret (32 bytes: "z" to indicate format + 186-bit key in Base64 URL)...
Definition: actions.php:171
elgg_register_plugin_hook_handler($hook, $type, $callback, $priority=500)
Register a callback as a plugin hook handler.
Definition: elgglib.php:737
$timestamp
Definition: date.php:35
$action
$params
Definition: login.php:72
generate_action_token($timestamp)
Generate an action token.
Definition: actions.php:156
actions_init()
Initialize some ajaxy actions features private.
Definition: actions.php:288
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
ajax_forward_hook($hook, $type, $reason, $params)
Catch calls to forward() in ajax request and force an exit.
Definition: actions.php:246
$type
Definition: add.php:8
get_site_secret()
Returns the site secret.
Definition: actions.php:184
$token
elgg_register_event_handler($event, $object_type, $callback, $priority=500)
Register a callback as an Elgg event handler.
Definition: elgglib.php:553
_elgg_action_handler(array $segments)
Handle a request for an action.
Definition: actions.php:19
validate_action_token($visible_errors=true, $token=null, $ts=null)
Validate an action token.
Definition: actions.php:116
_elgg_get_site_secret_strength()
Get the strength of the site secret.
Definition: actions.php:194
$filename
Definition: crop.php:23
_elgg_csrf_token_refresh()
Send an updated CSRF token.
Definition: actions.php:264
clearfix elgg elgg elgg elgg page header
Definition: admin.php:127
elgg_register_action($action, $filename="", $access= 'logged_in')
Registers an action.
Definition: actions.php:85
$access
Definition: save.php:15
ajax_action_hook()
Buffer all output echo&#39;d directly in the action for inclusion in the returned JSON.
Definition: actions.php:255
elgg_unregister_action($action)
Unregisters an action.
Definition: actions.php:96