LEPTON CMS 7.2.0
feel free to keep it strictly simple...
Loading...
Searching...
No Matches
initialize.php
Go to the documentation of this file.
1<?php
2
19// include secure.php to protect this file and the whole CMS!
20if(!defined("SEC_FILE")){define("SEC_FILE",'/framework/secure.php' );}
21if (defined('LEPTON_PATH')) {
22 include LEPTON_PATH.SEC_FILE;
23} else {
24 $oneback = "../";
25 $root = $oneback;
26 $level = 1;
27 while (($level < 10) && (!file_exists($root.SEC_FILE))) {
28 $root .= $oneback;
29 $level += 1;
30 }
31 if (file_exists($root.SEC_FILE)) {
32 include $root.SEC_FILE;
33 } else {
34 trigger_error(sprintf("[ <b>%s</b> ] Can't include secure.php!", $_SERVER['SCRIPT_NAME']), E_USER_ERROR);
35 }
36}
37// end include secure file
38
39if (!function_exists("lepton_autoloader"))
40{
41 require_once __DIR__."/functions/function.lepton_autoloader.php";
42 spl_autoload_register("lepton_autoloader", true);
43}
44
45// load constants
46LEPTON_handle::include_files("/framework/constants.php");
47
48// Get an instance from class database
50
51LEPTON_handle::register("get_leptoken");
52
53
54// set error-reporting
55if (is_numeric(ER_LEVEL))
56{
57 error_reporting( ER_LEVEL );
58 if (ER_LEVEL != 0)
59 {
60 ini_set('display_errors', 1);
61 }
62}
63
64// Start a session
65if (!defined('SESSION_STARTED'))
66{
67 // set name of session cookie
68 session_name(APP_NAME . 'sessionid');
69
70 //$cookie_settings = session_get_cookie_params();
71 $cookie_settings = LEPTON_session::get_cookie_defaults();
72
73 // create the session
74 session_start();
75
76 // Initialize the session cookie with the defaults
77 LEPTON_session::set_cookie( session_name(), session_id(), $cookie_settings );
78
79 unset($cookie_settings);
80
81 // create constant so this part is not running again
82 define( 'SESSION_STARTED', true );
83
84 // save in session
85 $_SESSION['LSH'] = password_hash( LEPTON_GUID, PASSWORD_DEFAULT);
86}
87
88
89// Update the session cookie to the defaults
90if (true === isset($_COOKIE[APP_NAME.'sessionid']))
91{
92 LEPTON_session::set_cookie( session_name(), $_COOKIE[ APP_NAME . 'sessionid' ], [] );
93}
94
95if (defined('ENABLED_ASP') && !isset($_SESSION['SESSION_STARTED']))
96{
97 $_SESSION[ 'SESSION_STARTED' ] = time();
98}
99
100// logout if not properly initialized
101if (!defined("LEPTON_INSTALL_PROCESS"))
102{
103
104 if ((!isset($_SESSION['LSH'])) || (!password_verify(LEPTON_GUID, $_SESSION['LSH'])))
105 {
106 $_SESSION = [];
107 LEPTON_session::set_cookie( session_name(), "", array( "expires"=> time() - 1 ) );
108 session_destroy();
109 header('Location: '.ADMIN_URL.'/login/index.php');
110 die();
111 }
112}
113
114// Get users language
115if (isset($_GET['lang']) && ($_GET['lang'] != '') && (!is_numeric($_GET['lang'])) && (strlen($_GET['lang']) == 2))
116{
117 // needed for frontend and easymultilanguage function without being logged in
118 $iTempPageId = $page_id ?? ((defined("PAGE_ID") ? PAGE_ID : 0));
119
120 if (0 != $iTempPageId)
121 {
122 $sTempLang = $database->get_one("SELECT `language` FROM `".TABLE_PREFIX."pages` WHERE `page_id` = ".$iTempPageId);
123 if (NULL != $sTempLang)
124 {
125 define( 'LANGUAGE', $sTempLang );
126 }
127 else
128 {
129 // more or less a theoretical case
130 define('LANGUAGE', DEFAULT_LANGUAGE);
131 }
132 }
133 else
134 { // needed for FE being logged in
135 if (isset($_SESSION['USER_ID']))
136 {
137 $sTempLang = $database->get_one("SELECT `language` FROM `".TABLE_PREFIX."users` WHERE `user_id`=" . $_SESSION['USER_ID']);
138 if (NULL != $sTempLang)
139 {
140 define('LANGUAGE', $sTempLang);
141 }
142 else
143 {
144 define('LANGUAGE', strtoupper($_GET['lang']));
145 }
146 }
147 else
148 {
149 define('LANGUAGE', strtoupper($_GET['lang']));
150 }
151 }
152
153 $_SESSION['LANGUAGE'] = LANGUAGE;
154}
155else
156{ // this part is for backend only
157 if (isset($_SESSION['LANGUAGE']) && ($_SESSION['LANGUAGE'] != ''))
158 {
159 $iTempPageId = $page_id ?? ((defined("PAGE_ID") ? PAGE_ID : 0));
160
161 if (0 != $iTempPageId)
162 {
163 $sTempLang = $database->get_one("SELECT `language` FROM `" . TABLE_PREFIX . "pages` WHERE `page_id`=" . $iTempPageId);
164 if (NULL != $sTempLang)
165 {
166 define('LANGUAGE', $sTempLang);
167 }
168 else
169 {
170 // more or less a theoretical case
171 define('LANGUAGE', $_SESSION['LANGUAGE']);
172 }
173 }
174 else
175 {
176 if (isset($_SESSION['USER_ID']))
177 {
178 $sTempLang = $database->get_one("SELECT `language` FROM `" . TABLE_PREFIX . "users` WHERE `user_id`='" . $_SESSION['USER_ID'] . "'");
179 if (NULL != $sTempLang)
180 {
181 define('LANGUAGE', $sTempLang);
182 } else {
183 define('LANGUAGE', $_SESSION['LANGUAGE']);
184 }
185 }
186 else
187 {
188 define('LANGUAGE', $_SESSION['LANGUAGE']);
189 }
190 }
191 }
192 else
193 {
194 define('LANGUAGE', DEFAULT_LANGUAGE);
195 }
196}
197
198
199// Load Language file
200if (!file_exists(LEPTON_PATH.'/languages/'.LANGUAGE.'.php'))
201{
202 exit('Error loading language file '.LANGUAGE.', please check configuration');
203}
204else
205{
206 $aLanguageFile = [
207 LANGUAGE.'_add.php',
208 LANGUAGE.'_custom.php',
209 LANGUAGE.'.php'
210 ];
211
212 foreach ($aLanguageFile as $sFile)
213 {
214 $sLanguagePath = LEPTON_PATH.'/languages/';
215 if (file_exists($sLanguagePath.$sFile))
216 {
217 require_once $sLanguagePath.$sFile;
218 break;
219 }
220 }
221}
222
static getInstance(array &$settings=[])
static include_files(array|string $file_names=[], bool $interrupt=true)
static get_cookie_defaults()
static set_cookie(string $name, string|int $value, array $options=[], bool $mustExists=false, bool $mergeDefault=true)
$database
$root
$level