LEPTON CMS 7.0.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
72 // Transform from lifetime to expire option in cookie
73 if ($cookie_settings["lifetime"] <= 0)
74 {
75 $cookie_settings[ "lifetime" ] = 3 * 3600;
76 }
77 $cookie_settings[ "expires" ] = time() + (int) $cookie_settings[ "lifetime" ];
78 unset($cookie_settings["lifetime"]);
79
80 // Initialize the session cookie with the defaults
81 LEPTON_session::set_cookie( session_name(), "", $cookie_settings );
82
83 unset($cookie_settings);
84
85 // create the session
86 session_start();
87
88 // create constant so this part is not running again
89 define( 'SESSION_STARTED', true );
90
91 // save in session
92 $_SESSION['LSH'] = password_hash( LEPTON_GUID, PASSWORD_DEFAULT);
93}
94
95
96// Update the session cookie to the defaults
97if( true === isset($_COOKIE[ APP_NAME . 'sessionid' ]))
98{
99 LEPTON_session::set_cookie( session_name(), $_COOKIE[ APP_NAME . 'sessionid' ], [] );
100}
101
102if (defined('ENABLED_ASP') && !isset($_SESSION['session_started']))
103{
104 $_SESSION[ 'session_started' ] = time();
105}
106
107// logout if not properly initialized
108if (!defined("LEPTON_INSTALL_PROCESS"))
109{
110 if ((!isset($_SESSION['LSH'])) || (!password_verify(LEPTON_GUID, $_SESSION['LSH'])))
111 {
112 $_SESSION = [];
113 LEPTON_session::set_cookie( session_name(), "", array( "expires"=> time() - 1 ) );
114 session_destroy();
115 header('Location: ' . ADMIN_URL . '/login/index.php');
116 die();
117 }
118}
119
120// Get users language
121if (isset($_SESSION['LANGUAGE']) && ($_SESSION['LANGUAGE'] != ''))
122{
123 $iTempPageId = $page_id ?? ((defined("PAGE_ID") ? PAGE_ID : 0));
124
125 if (0 != $iTempPageId)
126 {
127 $sTempLang = $database->get_one("SELECT `language` FROM `" . TABLE_PREFIX . "pages` WHERE `page_id`=" . $iTempPageId);
128 if (NULL != $sTempLang)
129 {
130 define('LANGUAGE', $sTempLang);
131 }
132 else
133 {
134 // more or less a theoretical case
135 define('LANGUAGE', $_SESSION['LANGUAGE']);
136 }
137 }
138 else
139 {
140 if (isset($_SESSION['USER_ID']))
141 {
142 $sTempLang = $database->get_one("SELECT `language` FROM `" . TABLE_PREFIX . "users` WHERE `user_id`='" . $_SESSION['USER_ID'] . "'");
143 if (NULL != $sTempLang)
144 {
145 define('LANGUAGE', $sTempLang);
146 } else {
147 define('LANGUAGE', $_SESSION['LANGUAGE']);
148 }
149 }
150 else
151 {
152 define('LANGUAGE', $_SESSION['LANGUAGE']);
153 }
154 }
155}
156else
157{
158 define('LANGUAGE', DEFAULT_LANGUAGE);
159}
160
161
162// Load Language file
163if (!file_exists(LEPTON_PATH . '/languages/' . LANGUAGE . '.php'))
164{
165 exit('Error loading language file ' . LANGUAGE . ', please check configuration');
166}
167else
168{
169 require_once (file_exists(LEPTON_PATH . '/languages/' . LANGUAGE . '_custom.php'))
170 ? LEPTON_PATH . '/languages/' . LANGUAGE . '_custom.php'
171 : LEPTON_PATH . '/languages/' . LANGUAGE . '.php'
172 ;
173}
174
static getInstance(array &$settings=[])
static include_files(array|string $file_names=[], bool $interrupt=true)
static set_cookie( $name, $value, $options=array(), $mustExists=false, $mergeDefault=true)
$database
$root
$level