-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonstra.php
328 lines (282 loc) · 10.1 KB
/
Monstra.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
<?php defined('MONSTRA_ACCESS') or die('No direct script access.');
/**
* Monstra Engine
*
* Monstra - Content Management System.
* Site: www.mostra.org
* Copyright (C) 2012-2014 Romanenko Sergey / Awilum <[email protected]>
*
* This source file is part of the Monstra Engine. More information,
* documentation and tutorials can be found at http://monstra.org
*
* @package Monstra
*
* @author Romanenko Sergey / Awilum <[email protected]>
* @copyright 2012-2014 Romanenko Sergey / Awilum <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
class Monstra
{
/**
* An instance of the Monstra class
*
* @var core
*/
protected static $instance = null;
/**
* Common environment type constants for consistency and convenience
*/
const PRODUCTION = 1;
const STAGING = 2;
const TESTING = 3;
const DEVELOPMENT = 4;
/**
* The version of Monstra
*/
const VERSION = '2.3.1';
/**
* Monstra environment
*
* @var string
*/
public static $environment = Monstra::PRODUCTION;
/**
* Monstra environment names
*
* @var array
*/
public static $environment_names = array(
Monstra::PRODUCTION => 'production',
Monstra::STAGING => 'staging',
Monstra::TESTING => 'testing',
Monstra::DEVELOPMENT => 'development',
);
/**
* Protected clone method to enforce singleton behavior.
*
* @access protected
*/
protected function __clone()
{
// Nothing here.
}
/**
* Protected Construct
*/
protected function __construct()
{
/**
* Load core defines
*/
Monstra::loadDefines();
/**
* Compress HTML with gzip
*/
if (MONSTRA_GZIP) {
if ( ! ob_start("ob_gzhandler")) ob_start();
} else {
ob_start();
}
/**
* Send default header and set internal encoding
*/
header('Content-Type: text/html; charset=UTF-8');
function_exists('mb_language') AND mb_language('uni');
function_exists('mb_regex_encoding') AND mb_regex_encoding('UTF-8');
function_exists('mb_internal_encoding') AND mb_internal_encoding('UTF-8');
/**
* Gets the current configuration setting of magic_quotes_gpc
* and kill magic quotes
*/
if (get_magic_quotes_gpc()) {
function stripslashesGPC(&$value) { $value = stripslashes($value); }
array_walk_recursive($_GET, 'stripslashesGPC');
array_walk_recursive($_POST, 'stripslashesGPC');
array_walk_recursive($_COOKIE, 'stripslashesGPC');
array_walk_recursive($_REQUEST, 'stripslashesGPC');
}
/**
* Set Gelato Display Errors to False for Production environment.
*/
if (Monstra::$environment == Monstra::PRODUCTION) {
define('GELATO_DEVELOPMENT', false);
}
/**
* Define Monstra Folder for Gelato Logs
*/
define ('GELATO_LOGS_PATH', LOGS);
/**
* Include Gelato Library
*/
include ROOT . DS . 'libraries'. DS .'Gelato'. DS .'Gelato.php';
/**
* Map Monstra Engine Directory
*/
ClassLoader::directory(ROOT . DS . 'engine' . DS);
/**
* Map all Monstra Classes
*/
ClassLoader::mapClasses(array(
// Site Modules
'Security' => ROOT . DS .'engine'. DS .'Security.php',
'Uri' => ROOT . DS .'engine'. DS .'Uri.php',
'Site' => ROOT . DS .'engine'. DS .'Site.php',
'Alert' => ROOT . DS .'engine'. DS .'Alert.php',
// XMLDB API
'XML' => ROOT . DS .'engine'. DS .'Xmldb'. DS .'XML.php',
'DB' => ROOT . DS .'engine'. DS .'Xmldb'. DS .'DB.php',
'Table' => ROOT . DS .'engine'. DS .'Xmldb'. DS .'Table.php',
// Plugin API
'Plugin' => ROOT . DS .'engine'. DS .'Plugin'. DS .'Plugin.php',
'Frontend' => ROOT . DS .'engine'. DS .'Plugin'. DS .'Frontend.php',
'Backend' => ROOT . DS .'engine'. DS .'Plugin'. DS .'Backend.php',
'Action' => ROOT . DS .'engine'. DS .'Plugin'. DS .'Action.php',
'Filter' => ROOT . DS .'engine'. DS .'Plugin'. DS .'Filter.php',
'View' => ROOT . DS .'engine'. DS .'Plugin'. DS .'View.php',
'I18n' => ROOT . DS .'engine'. DS .'Plugin'. DS .'I18n.php',
'Stylesheet' => ROOT . DS .'engine'. DS .'Plugin'. DS .'Stylesheet.php',
'Javascript' => ROOT . DS .'engine'. DS .'Plugin'. DS .'Javascript.php',
'Navigation' => ROOT . DS .'engine'. DS .'Plugin'. DS .'Navigation.php',
// Option API
'Option' => ROOT . DS .'engine'. DS .'Option.php',
// Shortcode API
'Shortcode' => ROOT . DS .'engine'. DS .'Shortcode.php',
// Idiorm
'ORM' => ROOT . DS .'libraries'. DS . 'Idiorm'. DS .'ORM.php',
// PHPMailer
'PHPMailer' => ROOT . DS .'libraries'. DS . 'PHPMailer'. DS .'PHPMailer.php',
));
/**
* Start session
*/
Session::start();
/**
* Init Idiorm
*/
if (defined('MONSTRA_DB_DSN')) {
ORM::configure(MONSTRA_DB_DSN);
ORM::configure('username', MONSTRA_DB_USER);
ORM::configure('password', MONSTRA_DB_PASSWORD);
ORM::configure('driver_options', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
}
/**
* Auto cleanup if MONSTRA_DEBUG is TRUE
*/
if (Monstra::$environment == Monstra::DEVELOPMENT) {
Monstra::cleanTmp();
}
/**
* Set Cache dir
*/
Cache::configure('cache_dir', CACHE);
/**
* Init Options API module
*/
Option::init();
/**
* Set default timezone
*/
@ini_set('date.timezone', Option::get('timezone'));
if (function_exists('date_default_timezone_set')) date_default_timezone_set(Option::get('timezone')); else putenv('TZ='.Option::get('timezone'));
/**
* Sanitize URL to prevent XSS - Cross-site scripting
*/
Security::runSanitizeURL();
/**
* Load default
*/
Monstra::loadPluggable();
/**
* Init I18n
*/
I18n::init(Option::get('language'));
/**
* Init Plugins API
*/
Plugin::init();
/**
* Init Notification service
*/
Notification::init();
/**
* Init site module
*/
if ( ! BACKEND) Site::init();
}
/**
* Load Defines
*/
protected static function loadDefines()
{
$root_defines = ROOT . DS . 'boot' . DS . 'defines.php';
$environment_defines = ROOT . DS . 'boot' . DS . Monstra::$environment_names[Monstra::$environment] . DS . 'defines.php';
$monstra_defines = ROOT . DS . 'engine' . DS . 'boot' . DS . 'defines.php';
if (file_exists($root_defines)) {
include $root_defines;
} elseif (file_exists($environment_defines)) {
include $environment_defines;
} elseif (file_exists($monstra_defines)) {
include $monstra_defines;
} else {
throw new RuntimeException("The defines file does not exist.");
}
}
/**
* Load Pluggable
*/
protected static function loadPluggable()
{
$root_pluggable = ROOT . DS . 'boot';
$environment_pluggable = ROOT . DS . 'boot' . DS . Monstra::$environment_names[Monstra::$environment];
$monstra_pluggable = ROOT . DS . 'engine' . DS . 'boot';
if (file_exists($root_pluggable . DS . 'filters.php')) {
include $root_pluggable . DS . 'filters.php';
} elseif (file_exists($environment_pluggable . DS . 'filters.php')) {
include $environment_pluggable . DS . 'filters.php';
} elseif (file_exists($monstra_pluggable . DS . 'filters.php')) {
include $monstra_pluggable . DS . 'filters.php';
} else {
throw new RuntimeException("The pluggable filters.php file does not exist.");
}
if (file_exists($root_pluggable . DS . 'actions.php')) {
include $root_pluggable . DS . 'actions.php';
} elseif (file_exists($environment_pluggable . DS . 'actions.php')) {
include $environment_pluggable . DS . 'actions.php';
} elseif (file_exists($monstra_pluggable . DS . 'actions.php')) {
include $monstra_pluggable . DS . 'actions.php';
} else {
throw new RuntimeException("The pluggable actions.php file does not exist.");
}
if (file_exists($root_pluggable . DS . 'shortcodes.php')) {
include $root_pluggable . DS . 'shortcodes.php';
} elseif (file_exists($environment_pluggable . DS . 'shortcodes.php')) {
include $environment_pluggable . DS . 'shortcodes.php';
} elseif (file_exists($monstra_pluggable . DS . 'shortcodes.php')) {
include $monstra_pluggable . DS . 'shortcodes.php';
} else {
throw new RuntimeException("The pluggable shortcodes.php file does not exist.");
}
}
/**
* Clean Monstra TMP folder.
*/
public static function cleanTmp()
{
// Cleanup minify
if (count($files = File::scan(MINIFY, array('css', 'js', 'php'))) > 0) foreach ($files as $file) File::delete(MINIFY . DS . $file);
// Cleanup cache
if (count($namespaces = Dir::scan(CACHE)) > 0) foreach ($namespaces as $namespace) Dir::delete(CACHE . DS . $namespace);
}
/**
* Initialize Monstra Engine
*
* @return Monstra
*/
public static function init()
{
if ( ! isset(self::$instance)) self::$instance = new Monstra();
return self::$instance;
}
}