ossn.lib.admin.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  * Initialize the admin library
13  *
14  * @return void
15  */
16 function ossn_admin() {
17  ossn_register_admin_sidemenu('admin/sidemenu', 'admin:components', ossn_site_url('administrator/components'), ossn_print('admin:sidemenu:components'));
18  ossn_register_admin_sidemenu('admin/sidemenu', 'admin:install', ossn_site_url('administrator/com_installer'), ossn_print('admin:sidemenu:components'));
19 
20  ossn_register_admin_sidemenu('admin/sidemenu', 'admin:themes', ossn_site_url('administrator/themes'), ossn_print('admin:sidemenu:themes'));
21  ossn_register_admin_sidemenu('admin/sidemenu', 'admin:install', ossn_site_url('administrator/theme_installer'), ossn_print('admin:sidemenu:themes'));
22 
23  ossn_register_admin_sidemenu('admin/sidemenu', 'admin:basic', ossn_site_url('administrator/settings/basic'), ossn_print('admin:sidemenu:settings'));
24  ossn_register_admin_sidemenu('admin/sidemenu', 'admin:cache', ossn_site_url('administrator/cache'), ossn_print('admin:sidemenu:settings'));
25  //ossn_register_admin_sidemenu('admin/sidemenu', 'admin:mode', ossn_site_url('administrator/theme_installer'), ossn_print('admin:sidemenu:settings'));
26 
27  ossn_register_admin_sidemenu('admin/sidemenu', 'admin:users', ossn_site_url('administrator/users'), ossn_print('admin:sidemenu:usermanager'));
28  ossn_register_admin_sidemenu('admin/sidemenu', 'admin:add:user', ossn_site_url('administrator/adduser'), ossn_print('admin:sidemenu:usermanager'));
29  ossn_register_admin_sidemenu('admin/sidemenu', 'admin:users:unvalidated', ossn_site_url('administrator/unvalidated_users'), ossn_print('admin:sidemenu:usermanager'));
30 
31 
32  ossn_register_menu_link('home', 'admin:dashboard', ossn_site_url('administrator'), 'topbar_admin');
33 
34  ossn_register_menu_link('configure', 'Configure', '#', 'topbar_admin');
35  ossn_register_menu_link('help', 'admin:help', 'http://community.opensource-socialnetwork.org', 'topbar_admin');
36  ossn_register_menu_link('support', 'admin:support', 'http://community.opensource-socialnetwork.org', 'topbar_admin');
37 
38  ossn_register_menu_link('viewsite', 'admin:view:site', ossn_site_url(), 'topbar_admin');
39 
40  ossn_register_action('admin/login', ossn_route()->actions . 'administrator/login.php');
41  ossn_register_action('admin/logout', ossn_route()->actions . 'administrator/logout.php');
42 
43  if(ossn_isAdminLoggedin()) {
44  ossn_register_site_settings_page('account', 'pages/account');
45 
46  ossn_register_action('component/enable', ossn_route()->actions . 'administrator/component/enable.php');
47  ossn_register_action('component/disable', ossn_route()->actions . 'administrator/component/disable.php');
48  ossn_register_action('component/delete', ossn_route()->actions . 'administrator/component/delete.php');
49 
50  ossn_register_action('theme/enable', ossn_route()->actions . 'administrator/theme/enable.php');
51  ossn_register_action('theme/delete', ossn_route()->actions . 'administrator/theme/delete.php');
52 
53  ossn_register_action('admin/add/user', ossn_route()->actions . 'administrator/user/add.php');
54  ossn_register_action('admin/edit/user', ossn_route()->actions . 'administrator/user/edit.php');
55  ossn_register_action('admin/delete/user', ossn_route()->actions . 'administrator/user/delete.php');
56  ossn_register_action('admin/validate/user', ossn_route()->actions . 'administrator/user/validate.php');
57 
58  ossn_register_action('admin/com_install', ossn_route()->actions . 'administrator/component/com_install.php');
59  ossn_register_action('admin/theme_install', ossn_route()->actions . 'administrator/theme/theme_install.php');
60 
61  ossn_register_action('admin/settings/save/basic', ossn_route()->actions . 'administrator/settings/save/basic.php');
62  ossn_register_action('admin/cache/create', ossn_route()->actions . 'administrator/cache/create.php');
63  ossn_register_action('admin/cache/flush', ossn_route()->actions . 'administrator/cache/flush.php');
64 
65  }
66 
67  /*
68  * Register login and backend pages
69  */
70  if (ossn_isAdminLoggedin()) {
71  ossn_register_page('administrator', 'ossn_administrator_pagehandler');
72  ossn_register_site_settings_page('basic', 'settings/admin/basic_settings');
73  } else {
74  ossn_register_page('administrator', 'ossn_administrator_login_pagehandler');
75  }
76 }
77 
78 /**
79  * Register sidebar menu
80  *
81  * @params string $name The name of the menu
82  * @params string $text Link text
83  * @params string $link Full url
84  * @params string $section Menu section
85  * @params string $for sidebar name
86  *
87  * @return void
88  */
89 function ossn_register_admin_sidemenu($name, $text, $link, $section, $for = 'admin/sidemenu') {
90  ossn_register_menu_item($for, array(
91  'name' => $name,
92  'text' => $text,
93  'href' => $link,
94  'parent' => $section,
95  ));
96 }
97 
98 /**
99  * Register component panel page
100  *
101  * @param string $component Component Id
102  * $page Page url
103  * @param string $page
104  *
105  * @return void
106  */
107 function ossn_register_com_panel($component, $page) {
108  global $Ossn;
109  $Ossn->com_panel[$component] = $page;
110 }
111 
112 /**
113  * Get registered component panel pages
114  *
115  * @return array
116  */
118  global $Ossn;
119  if (!isset($Ossn->com_panel)) {
120  return false;
121  }
122  foreach ($Ossn->com_panel as $key => $name) {
123  $registered[] = $key;
124  }
125  return $registered;
126 }
127 
128 /**
129  * Register settings/<page>
130  *
131  * @param string $name <page> path
132  * $page page contents file
133  * @param string $page
134  *
135  * @return void
136  */
138  global $Ossn;
139  $Ossn->adminSettingsPage[$name] = $page;
140 }
141 
142 /**
143  * View registered settings pages
144  *
145  * @return array
146  */
148  global $Ossn;
149  if (!isset($Ossn->adminSettingsPage)) {
150  return false;
151  }
152  foreach ($Ossn->adminSettingsPage as $key => $name) {
153  $registered[] = $key;
154  }
155  return $registered;
156 }
157 
158 /**
159  * View admin sidebar menu
160  *
161  * @return html
162  */
164  global $Ossn;
165  $params['menu'] = $Ossn->menu['admin/sidemenu'];
166  $active_theme = ossn_site_settings('theme');
167  return ossn_plugin_view("menus/admin_sidemenu", $params);
168 }
169 
170 
171 /**
172  * Register a page handler for administrator;
173  * @pages:
174  * administrator,
175  * administrator/dasbhoard,
176  * administrator/component,
177  * administrator/components,
178  * administrator/com_installer,
179  * administrator/theme_installer,
180  * administrator/settings/<page>,
181  * administrator/cache,
182  * administrator/users,
183  * administrator/edituser
184  *
185  * @return boolean|null
186  */
188  $page = $pages[0];
189  if (empty($page)) {
190  $page = 'dashboard';
191  }
192 
193  switch ($page) {
194  case 'dashboard':
195  $title = ossn_print('admin:dashboard');
196  $contents['contents'] = ossn_plugin_view('pages/administrator/contents/dashboard');
197  $contents['title'] = $title;
198  $content = ossn_set_page_layout('administrator/administrator', $contents);
199  echo ossn_view_page($title, $content, 'administrator');
200  break;
201  case 'component':
202  global $Ossn;
203  if (isset($pages[1]) && in_array($pages[1], ossn_registered_com_panel())) {
204  $com['com'] = OssnComponents::getCom($pages[1]);
205  $com['settings'] = ossn_components()->getComSettings($pages[1]);
206  $title = $com['com']->name;
207  $contents['contents'] = ossn_plugin_view("settings/administrator/{$pages[1]}/{$Ossn->com_panel[$pages[1]]}", $com);
208  $contents['title'] = $title;
209  $content = ossn_set_page_layout('administrator/administrator', $contents);
210  echo ossn_view_page($title, $content, 'administrator');
211  }
212  break;
213  case 'components':
214  $title = ossn_print('admin:components');
215  $contents['contents'] = ossn_plugin_view("pages/administrator/contents/components");
216  $contents['title'] = $title;
217  $content = ossn_set_page_layout('administrator/administrator', $contents);
218  echo ossn_view_page($title, $content, 'administrator');
219  break;
220  case 'themes':
221  $title = ossn_print('admin:themes');
222  $contents['contents'] = ossn_plugin_view("pages/administrator/contents/themes");
223  $contents['title'] = $title;
224  $content = ossn_set_page_layout('administrator/administrator', $contents);
225  echo ossn_view_page($title, $content, 'administrator');
226  break;
227  case 'com_installer':
228  $title = ossn_print('admin:com:installer');
229  $contents['contents'] = ossn_plugin_view("pages/administrator/contents/com_installer");
230  $contents['title'] = $title;
231  $content = ossn_set_page_layout('administrator/administrator', $contents);
232  echo ossn_view_page($title, $content, 'administrator');
233  break;
234  case 'theme_installer':
235  $title = ossn_print('admin:theme:installer');
236  $contents['contents'] = ossn_plugin_view("pages/administrator/contents/theme_installer");
237  $contents['title'] = $title;
238  $content = ossn_set_page_layout('administrator/administrator', $contents);
239  echo ossn_view_page($title, $content, 'administrator');
240  break;
241  case 'settings':
242  global $Ossn;
243  if (isset($pages[1]) && in_array($pages[1], ossn_registered_settings_pages())) {
244  $title = ossn_print("{$pages[1]}:settings");
245  //file should be in plugins/views/default/settings/<file> $arsalanshah
246  $contents['contents'] = ossn_plugin_view($Ossn->adminSettingsPage[$pages[1]]);
247  $contents['title'] = $title;
248  $content = ossn_set_page_layout('administrator/administrator', $contents);
249  echo ossn_view_page($title, $content, 'administrator');
250  }
251  break;
252  case 'cache':
253  $title = ossn_print('admin:cache:settings');
254  $contents['contents'] = ossn_plugin_view("pages/administrator/contents/cache");
255  $contents['title'] = $title;
256  $content = ossn_set_page_layout('administrator/administrator', $contents);
257  echo ossn_view_page($title, $content, 'administrator');
258  break;
259  case 'adduser':
260  $title = ossn_print('admin:add:user');
261  $contents['contents'] = ossn_plugin_view("pages/administrator/contents/adduser");
262  $contents['title'] = $title;
263  $content = ossn_set_page_layout('administrator/administrator', $contents);
264  echo ossn_view_page($title, $content, 'administrator');
265  break;
266  case 'users':
267  $title = ossn_print('admin:user:list');
268  $contents['contents'] = ossn_plugin_view("pages/administrator/contents/users/list");
269  $contents['title'] = $title;
270  $content = ossn_set_page_layout('administrator/administrator', $contents);
271  echo ossn_view_page($title, $content, 'administrator');
272  break;
273  case 'unvalidated_users':
274  $title = ossn_print('admin:users:unvalidated');
275  $contents['contents'] = ossn_plugin_view("pages/administrator/contents/users/unvalidated");
276  $contents['title'] = $title;
277  $content = ossn_set_page_layout('administrator/administrator', $contents);
278  echo ossn_view_page($title, $content, 'administrator');
279  break;
280  case 'edituser':
281  if (isset($pages[1])) {
282  $user['user'] = ossn_user_by_username($pages[1]);
283  }
284  $title = ossn_print('admin:edit:user');
285  $contents['contents'] = ossn_plugin_view("pages/administrator/contents/user/edit", $user);
286  $contents['title'] = $title;
287  $content = ossn_set_page_layout('administrator/administrator', $contents);
288  echo ossn_view_page($title, $content, 'administrator');
289  break;
290  case 'version':
291  header('Content-Type: application/json');
292  $version = array(
293  'version' => ossn_check_update()
294  );
295  echo json_encode($version);
296  break;
297  default:
298  ossn_error_page();
299  break;
300 
301  }
302 }
303 /**
304  * Register a page handler for administrator login;
305  * @pages:
306  * administrator/login,
307  * @return mixeddata
308  */
310  $page = $pages[0];
311  if (empty($page)) {
312  $page = 'login';
313  }
314  $logout = input('logout');
315  if($logout == 'true'){
316  ossn_trigger_message(ossn_print('logged:out'));
317  redirect('administrator');
318  }
319  switch ($page) {
320  case 'login':
321  $title = ossn_print('admin:login');
322  $contents['contents'] = ossn_plugin_view("pages/administrator/contents/login");
323  $contents['title'] = $title;
324  $content = ossn_set_page_layout('administrator/login', $contents);
325  echo ossn_view_page($title, $content, 'administrator');
326  break;
327  default:
328  ossn_error_page();
329  break;
330 
331  }
332 }
333 ossn_register_callback('ossn', 'init', 'ossn_admin');