forked from emoncms/emoncms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
96 lines (77 loc) · 2.46 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/*
All Emoncms code is released under the GNU Affero General Public License.
See COPYRIGHT.txt and LICENSE.txt.
---------------------------------------------------------------------
Emoncms - open source energy visualisation
Part of the OpenEnergyMonitor project:
http://openenergymonitor.org
*/
// Load emoncms framework core
require("core.php");
// Process user settings
require "process_settings.php";
require("locale.php");
$path = get_application_path();
// Database connect
require("db.php");
switch(db_connect()) {
case 4: db_schema_setup(load_db_schema()); break;
}
// Session control
require("Modules/user/user_model.php");
if (get('apikey'))
$session = user_apikey_session($_GET['apikey']);
else
$session = emon_session_start();
set_emoncms_lang($session['userid']);
// 1) Get route
$route = decode_route(get('q'));
if (get('embed')==1) $embed = 1; else $embed = 0;
// If no route specified use defaults
if (!$route['controller'] && !$route['action'])
{
// Non authenticated defaults
if (!$session['read'])
{
$route['controller'] = $default_controller;
$route['action'] = $default_action;
}
else // Authenticated defaults
{
$route['controller'] = $default_controller_auth;
$route['action'] = $default_action_auth;
}
}
// Route calls for api through to input
if ($route['controller'] == "api") $route['controller'] = "input";
if ($route['controller'] == "input" && $route['action'] == "post") $route['format'] = "json";
// 2) Load the main page controller
$output = controller($route['controller']);
// If no controller of this name - then try username
if (!$output['content'] && $public_profile_enabled)
{
$userid = get_user_id($route['controller']);
if ($userid) {
$route['subaction'] = $route['action'];
$session['userid'] = $userid;
$session['username'] = $route['controller'];
$session['read'] = 1;
$session['profile'] = 1;
$route['action'] = $public_profile_action;
$output = controller($public_profile_controller);
}
}
// Output theming
if ($route['format']=='json')
{
echo $output['message'].$output['content'];
}
if ($route['format']=='html')
{
$menu_left = load_menu();
$output['mainmenu'] = theme("menu_view.php", array());
if ($embed == 0) print theme("theme.php", $output);
if ($embed == 1) print theme("embed.php", $output);
}
?>