meraproject/module/engine.php

141 lines
3.9 KiB
PHP
Raw Permalink Normal View History

<?
$start_engine = microtime(true);
include_once(dirname(__FILE__).'/../vendor/autoload.php');
/*
// Показывать ли все ошибки
error_reporting(E_ALL);
ini_set('display_errors',true);
/*/
ini_set('display_errors','Off');
/**/
if($_SERVER['HTTP_HOST']=='site1.module.bz'){
/*
// Показывать ли все ошибки
error_reporting(E_ALL);
ini_set('display_errors',true);
/*/
ini_set('display_errors','Off');
/**/
}
/**
* Функция для автоматической загрузки классов
* @param $x string Название класса
*/
function CMSBuilderAutoload($x){
$folder = dirname(__FILE__).'/';
if (substr($x,strlen($x)-1,1)=="\\") $x = substr($x,0,strlen($x)-1);
$aaa = explode("\\",$x);
$count = count($aaa);
$aa = [];
foreach ($aaa as $k=>$v){
$isLast = $k==$count-1;
if($isLast) {
$aa[] = $v;
} else {
$aa[] = strtolower($v);
}
}
$paths = [];
$isController = $aa[0]=='controller';
$isTheme = ($aa[0]=='themes' || ($isController and $aa[1]=='themes')) ;
if($isTheme) $folder .= '../';
if($isController) {
array_shift($aa);
array_pop($aa);
$paths[] = $folder.implode("/",$aa)."/controller.php";
} else {
$ss = array_pop($aa);
$paths[] = $folder . implode('/', $aa) . "/" . $ss . ".php";
$paths[] = $folder . strtolower(str_replace('\\','/',$x)). "/model.php";
}
foreach ($paths as $p) {
if(include_once($p)) {
break;
}
}
}
spl_autoload_register ( 'CMSBuilderAutoload' );
include_once(dirname(__FILE__).'/../config.php');
include_once(dirname(__FILE__).'/core/core/connect.php');
ob_start(); // echo ob_get_clean(); - происходит в Core::end();
// Инициализируем основные функции.
Core::init();
if($_GET['api']==1) {
if(in_array($_SERVER['HTTP_HOST'],[
'alsor.in',
'app.taskcrm.in',
'achi.in',
'localhost',
//'contact.in',
'compare.in',
//'changeblog.in',
'fixgardencrm.in',
'fnews.in',
'geek.in',
'minicourse.in',
'merakom.in',
'merabase.in',
//'module.in',
'msto.in',
'roots3.in',
'rootscrm.in',
'module.in',
'vhl.in',
//'timer.in',
'mquest.in',
'merakomis.in',
'photo.in',
'127.0.0.2',
'ref.bur-indeetc.ru',
'sarkko.in',
// public
])){
//header('Access-Control-Allow-Origin: http://localhost');
header('Access-Control-Allow-Origin: *');
//header('Access-Control-Allow-Origin: http://localhost');
header('Access-Control-Allow-Methods: *');
//header('Access-Control-Allow-Headers: cache-control, Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers');
//header('Access-Control-Allow-Headers: expires,pragma,Cache-Control, Access-Control-Allow-Headers, Origin,Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers');
header('Access-Control-Allow-Headers: *');
header('Cache-Control: no-store');
//header('Cache-Control: max-age=0');
}
if(in_array($_SERVER['HTTP_HOST'],[
'gigapolis.world',
'visuella.ru',
'127.0.0.2',
])){
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: *');
header('Access-Control-Allow-Headers: *');
header('Cache-Control: no-store');
}
$a = 'controller\\' . str_replace('.', '\\', $_REQUEST['module']) . '\Api';
$func = $_REQUEST['action'];
try {
$s = new $a();
$s->$func($_REQUEST);
} catch (Exception $e) {
}
Core::end();
exit;
}
//echo '<h1>'.var_dump('END',microtime(true)-$start_engine);