<?php
namespace ticky;
class app {
public static $namespace;
public static $config = [];
public static function run() {
self::$config = config::get('app');
self::$namespace = '\\' . self::$config['app_namespace'];
self::_init_lang();
self::_init_env();
route::dispatch();
}
private static function _init_lang() {
$langset = strtolower(config::get('lang', 'default_lang'));
Lang::load([
TICKY_PATH . DS . 'lang' . DS . $langset . ".php",
APP_PATH . DS . 'lang' . DS . $langset . ".php",
APP_PATH . DS . 'common' . DS . 'lang' . DS . $langset . ".php",
]);
}
private static function _init_env() {
register_shutdown_function(array('ticky\debug', 'fatalerror'));
set_error_handler(array('ticky\debug', 'catcher'));
set_exception_handler(array('ticky\debug', 'exception'));
date_default_timezone_set(self::$config['default_timezone']);
header("Content-type: text/html; charset=" . self::$config['default_charset']);
header('X-Powered-By:TickyPHP V' . TICKY_VERSION);
defined('CHARSET') or define('CHARSET', self::$config['default_charset']);
if (function_exists('ini_get')) {
$memorylimit = @ini_get('memory_limit');
if ($memorylimit && return_bytes($memorylimit) < 33554432 && function_exists('ini_set')) {
ini_set('memory_limit', '128m');
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) {
$_GET = array_merge($_GET, $_POST);
}
global $_G;
$_G = array(
'uid' => 0,
'username' => '',
'adminid' => 0,
'groupid' => 0,
'config' => self::$config,
'setting' => array(),
'cookie' => array(),
'cache' => array(),
'session' => array(),
'PHP_FILE' => rtrim($_SERVER['SCRIPT_NAME'], '/'),
'ROOT_PATH' => dirname(TICKY_PATH) . DS,
'TICKY_PATH' => dirname(dirname(__FILE__)) . DS,
'TICKY_LIB' => TICKY_PATH . 'library' . DS,
'TICKY_CONFIG' => TICKY_PATH . 'config' . DS,
'APP_PATH' => ROOT_PATH . 'application' . DS,
'HTTP_HOST' => $_SERVER['HTTP_HOST'],
'SERVER_PORT' => isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://',
'SITE_PATH' => str_replace('index.php', '', PHP_FILE),
'SITE_URL' => SERVER_PORT . HTTP_HOST . SITE_PATH,
'IS_CGI' => (0 === strpos(PHP_SAPI, 'cgi') || false !== strpos(PHP_SAPI, 'fcgi')) ? 1 : 0
);
$_G['basefilename'] = basename(PHP_FILE);
}
public static function showmsg($msg, $gourl, $limittime) {
$gourl = empty($gourl) ? HTTP_REFERER : $gourl;
$stop = $gourl != 'stop' ? false : true;
include(TICKY_PATH . DS . 'tpl' . DS . 'message.tpl');
}
public static function fatalerror($msg, $detailed = '', $type = 1) {
if (ob_get_length() !== false)
@ob_end_clean();
include(TICKY_PATH . DS . 'tpl' . DS . 'error.tpl');
exit();
}
public static function halt($msg) {
if (ob_get_length() !== false)
@ob_end_clean();
header('HTTP/1.1 404 Not Found');
header('Status:404 Not Found');
include(TICKY_PATH . DS . 'tpl' . DS . 'halt.tpl');
exit();
}
}