Просмотр файла index.php

Размер файла: 3.82Kb
<?php
/**
 * Ant0ha's project
 *
 * @package
 * @author Anton Pisarenko <[email protected]>
 * @copyright Copyright (c) 2006 - 2010, Anton Pisarenko
 * @license http://ant0ha.ru/license.txt
 * @link http://ant0ha.ru
 */

$mtime = explode(" ", microtime());
$start_time = $mtime[1] + $mtime[0];

defined('ROOT') or define('ROOT', str_replace('\\', '/', realpath(dirname (__FILE__))) .'/');
define('IN_SYSTEM', TRUE);

# Подключаем главные функции ядра
include_once(ROOT .'kernel/general_functions.php');
# Конфигурация php
include_once(ROOT .'kernel/ini_set.php');

session_name('sid');
session_start();

# Конфигурация системы
if(file_exists(ROOT .'data_files/config.php')) {
	include_once ROOT .'data_files/config.php';
}
else {
	header("Location: ./install/index.php");
	exit;
}

# Легкий XSS clean =)
$_GET = array_map('htmlspecialchars', $_GET);

# Конфигурация кэширования
$cache_config = file_get_contents(ROOT .'data_files/cache_config.dat');

# Определяем используется ли кэш для данного сегмента
$using_cache = FALSE;
if(!empty($cache_config) && empty($_GET['from_id'])) {
	$key_for_cache = (isset($_GET['segment1']) ? $_GET['segment1'] : '') .'#'. (isset($_GET['segment2']) ? $_GET['segment2'] : '') .'#'. (isset($_GET['segment3']) ? $_GET['segment3'] : '');
	foreach(explode(PHP_EOL, $cache_config) AS $value) {
		if(strpos($value, $key_for_cache) === 0) {
			$using_cache = TRUE;
			$ex = explode('#', $value);
			$cache_ttl = intval($ex[3]);
			break;
		}
	}
}

if($using_cache) {
	$cache_key = $_SERVER["HTTP_HOST"] . ':' . $_SERVER['REQUEST_URI'];
	a_import('libraries/file_cache');
	$file_cache = new File_Cache(ROOT .'cache/file_cache');
	$html_page = $file_cache->get($cache_key, $cache_ttl);
}

if(!$using_cache OR !$html_page) {
	# Включаем буферизацию
	if($using_cache) ob_start();

	# Подключаем MySQL класс
	a_import('libraries/mysql');
	$db = new MySQL();
	$db->debugging = TRUE;
	$db->connect();
	$db->charset('utf8');

	# Загрузка конфигурации системы
	$CONFIG = array();
	$result = $db->query("SELECT * FROM #__config");
	while($item = $db->fetch_array($result)) $CONFIG[$item['module']][$item['key']] = $item['value'];
	define('MAIN_MENU', $CONFIG['system']['main_menu']);
	define('EXT', $CONFIG['system']['ext']);
	define('DEFAULT_MODULE', $CONFIG['system']['default_module']);

	# Показ ошибок
	if($CONFIG['system']['display_errors']) ini_set('display_errors', 'On');
	else ini_set('display_errors', 'Off');

	# Мини роутинг
	a_import('libraries/route');
	$route = new Route;

	# Загрузка основного хелпера основного модуля
	a_import('modules/main/helpers/main');
	# Загрузка хелпера модулей
	a_import('modules/modules/helpers/modules');

	# Подключаем и инициализируем контроллер
	a_import('libraries/controller');
	$controller = a_load_class(ROUTE_CONTROLLER_PATH, 'controller');

	# Выполняем метод контроллера
	if(!empty($route->action)) {
		$action_method = 'action_'. $route->action;
		if(method_exists($controller, $action_method)) {
			$controller->$action_method();
		}
		else a_error('Страница не найдена!');
	}
	else {
		if(method_exists($controller, 'action_index')) {
			$controller->action_index();
		}
		else a_error('Страница не найдена!');
	}

	$db->close();

	if($using_cache) {
		# сохраняем страницу в переменную
		$html_page = ob_get_flush();
		# и отправляем содержимое переменной в кеш
		$file_cache->set($cache_key, $html_page);
	}
}
else print $html_page;

if($CONFIG['system']['profiler'] == 'on') a_profiler($start_time);

?>