forked from BlackCatDevelopment/BlackCatCMS
/
index.php
121 lines (106 loc) · 4.43 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
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
<?php
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*
* @author Website Baker Project, LEPTON Project, Black Cat Development
* @copyright 2004-2010, Website Baker Project
* @copyright 2011-2012, LEPTON Project
* @copyright 2013, Black Cat Development
* @link http://www.blackcat-cms.org
* @license http://www.gnu.org/licenses/gpl.html
* @category CAT_Core
* @package CAT_Core
*
*/
$starttime = array_sum(explode(" ",microtime()));
// error configuration for production environment
ini_set('display_startup_errors', 'off');
ini_set('display_errors', 'off');
ini_set('html_errors', 'off');
ini_set('docref_root', 0);
ini_set('docref_ext', 0);
ini_set('error_reporting', '-1');
ini_set('log_errors_max_len', 0);
// Include config file
$config_file = dirname(__FILE__).'/config.php';
if(file_exists($config_file))
{
require_once($config_file);
if(defined('CAT_ENVIRONMENT') && CAT_ENVIRONMENT == 'development')
{
ini_set('display_startup_errors', 'on');
ini_set('display_errors', 'on');
ini_set('html_errors', 'on');
ini_set('error_reporting', E_ALL & E_STRICT);
ini_set('log_errors_max_len', 1024);
}
}
else
{
/**
* File isn't there, so we try to run the installer
*/
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['SCRIPT_NAME']), '/\\');
$file = 'install/index.php';
$target_url = 'http://'.$host.$uri.'/'.$file;
header('Location: '.$target_url);
exit(); // make sure that the code below will not be executed
}
require dirname(__FILE__).'/framework/CAT/ExceptionHandler.php';
// register exception/error handlers
set_exception_handler(array("CAT_ExceptionHandler", "exceptionHandler"));
set_error_handler(array("CAT_ExceptionHandler", "errorHandler"));
register_shutdown_function(array("CAT_ExceptionHandler", "shutdownHandler"));
global $wb, $admin;
// -----------------------------------------------------------------------------
// Create new frontend object; this is for backward compatibility only!
include CAT_PATH.'/framework/class.frontend.php';
$wb = new frontend();
// keep SM2 quiet
$wb->extra_where_sql = "visibility != 'none' AND visibility != 'hidden' AND visibility != 'deleted'";
// some modules may use $wb->page_id
if(isset($page_id))
$wb->page_id=$page_id;
include CAT_PATH.'/framework/frontend.functions.php';
// -----------------------------------------------------------------------------
// get page to show
$page_id = CAT_Helper_Page::selectPage() or die();
// this will show the Intro- or Default-Page if no PAGE_ID is available
$page = CAT_Page::getInstance($page_id);
// -----------------------------------------------------------------------------
// keep SM2 happy
$wb->page = CAT_Helper_Page::properties($page_id);
$wb->default_link = CAT_Helper_Page::properties($page_id,'link');
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// needed at least for droplets
$admin =& $wb;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// clean up log files (older than 24 hours and size 0)
$files = CAT_Helper_Directory::findFiles('log_\d{4}-\d{2}-\d{2}\.txt',CAT_PATH.'/temp');
if(count($files))
foreach($files as $f)
if(filemtime($f)<(time()-24*60*60)&&filesize($f)==0)
unlink($f);
$files = CAT_Helper_Directory::findFiles('log_\d{4}-\d{2}-\d{2}\.txt',CAT_PATH.'/temp/logs');
if(count($files))
foreach($files as $f)
if(filemtime($f)<(time()-24*60*60)&&filesize($f)==0)
unlink($f);
// -----------------------------------------------------------------------------
// hand over to page handler
$page->show();
exit();