ossn.lib.actions.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Open Source Social Network
4  *
5  * @package (Informatikon.com).ossn
6  * @author OSSN Core Team <[email protected]>
7  * @copyright 2014 iNFORMATIKON TECHNOLOGIES
8  * @license General Public Licence http://www.opensource-socialnetwork.org/licence
9  * @link http://www.opensource-socialnetwork.org/licence
10  */
11 
12 /**
13  * Registers an action.
14  *
15  * @param string $action The name of the action
16  * @param string $filename The filename where this action is located.
17  *
18  * @return void
19  */
20 function ossn_register_action($action, $file) {
21  global $Ossn;
22  $Ossn->action[$action] = $file;
23 }
24 
25 /**
26  * Unregister action
27  *
28  * @param string $action The name of the action
29  *
30  * @return void
31  */
32 function ossn_unregister_action($action) {
33  global $Ossn;
34  unset($Ossn->action[$action]);
35 }
36 
37 /**
38  * Load action.
39  *
40  * @param string $action The name of the action
41  *
42  * @return void
43  */
44 function ossn_action($action) {
45  global $Ossn;
46  if (isset($Ossn->action) && array_key_exists($action, $Ossn->action)
47  ) {
48  if (is_file($Ossn->action[$action])) {
49  $params['action'] = $action;
50  ossn_trigger_callback('action', 'load', $params);
51  include_once($Ossn->action[$action]);
52  if(ossn_is_xhr()){
53  header('Content-Type: application/json');
54  $vars = array();
55  if(isset($_SESSION['ossn_messages']['success'])
56  && !empty($_SESSION['ossn_messages']['success'])){
57  $vars['success'] = $_SESSION['ossn_messages']['success'];
58  }
59  //danger = error bootstrap
60  if(isset($_SESSION['ossn_messages']['danger'])
61  && !empty($_SESSION['ossn_messages']['danger'])){
62  $vars['error'] = $_SESSION['ossn_messages']['danger'];
63  }
64  if(isset($Ossn->redirect) && !empty($Ossn->redirect)){
65  $vars['redirect'] = $Ossn->redirect;
66  }
67  if(isset($Ossn->ajaxData) && !empty($Ossn->ajaxData)){
68  $vars['data'] = $Ossn->ajaxData;
69  }
70  unset($_SESSION['ossn_messages']);
71  if(!empty($vars)){
72  echo json_encode($vars);
73  }
74  }
75  }
76  } else {
78  }
79 }