Draft v1
This commit is contained in:
133
LE/core.php
Normal file
133
LE/core.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/******************
|
||||
* LE Core *
|
||||
*****************/
|
||||
|
||||
|
||||
/*core functions*/
|
||||
function arr_v($arr,$field,$default=false)
|
||||
{
|
||||
return isset($arr[$field]) ? $arr[$field] : $default;
|
||||
}
|
||||
|
||||
function echo_arr(&$arr) {
|
||||
if (ISWEB) echo '<pre>';
|
||||
print_r($arr);
|
||||
if (ISWEB) echo '</pre>';
|
||||
}
|
||||
|
||||
|
||||
/*core class*/
|
||||
class LE
|
||||
{
|
||||
public static $DB,$TPL,$CACHE,$QUERY_DATA_TYPE;
|
||||
|
||||
|
||||
public static function DEF ($constant_name,$val=false)
|
||||
{
|
||||
if (!defined($constant_name)) define($constant_name, $val);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*date prepare class*/
|
||||
//prepare class
|
||||
class PRE {
|
||||
public static $MASK = ['D' => '0-9', 'R' => 'а-яё', 'L' => 'a-z', 'S' => '\s'];
|
||||
public static $SH_MASK = [
|
||||
'UP' => MB_CASE_UPPER,
|
||||
'DOWN' => MB_CASE_LOWER,
|
||||
'U1' => MB_CASE_TITLE];
|
||||
|
||||
|
||||
public static function SQL($s)
|
||||
{
|
||||
if (method_exists(LE::$DB, 'prepare')) return LE::$DB->prepare($s);
|
||||
return addslashes($s);
|
||||
}
|
||||
public static function DOWN($s)
|
||||
{
|
||||
return mb_convert_case($s, MB_CASE_LOWER);
|
||||
}
|
||||
public static function UP($s)
|
||||
{
|
||||
return mb_convert_case($s, MB_CASE_UPPER);
|
||||
}
|
||||
|
||||
|
||||
public static function SHIFT($s, $t)
|
||||
{
|
||||
if (isset(PRE::$SH_MASK[$t])) {
|
||||
return mb_convert_case($s, PRE::$SH_MASK[$t]);
|
||||
|
||||
}
|
||||
exit('shift err mask');
|
||||
}
|
||||
|
||||
public static function f2int($n,int $m):int
|
||||
{
|
||||
if (empty($n)) return 0;
|
||||
$n=(float)$n;
|
||||
|
||||
$n*=pow(10,$m+1);
|
||||
return (int) Ceil(round($n)/10);
|
||||
}
|
||||
public static function F($s, $t) {
|
||||
$preg = strtr(preg_quote(trim($t), '!'), PRE::$MASK);
|
||||
return preg_replace('![^' . $preg . ']!iu', '', $s);
|
||||
}
|
||||
|
||||
public static function UP1($s) {
|
||||
$s = PRE::SHIFT(trim($s),'DOWN');
|
||||
$w = preg_split('/\s+/', $s);
|
||||
|
||||
if (isset($w[0]))
|
||||
{
|
||||
$w[0] = PRE::SHIFT($w[0],'U1');
|
||||
return implode(' ',$w);
|
||||
}
|
||||
return $s;
|
||||
|
||||
}
|
||||
|
||||
public static function INT($i):int {return (int)PRE::NUM($i);}
|
||||
public static function NUM($i) {return preg_replace('![^0-9]!', '', $i);}
|
||||
public static function DEC($i):float {
|
||||
$i= preg_replace('/[^\-0-9,.]/u', '', $i);
|
||||
return (float)preg_replace('!([\-]?[0-9]+)[,.]?([0-9]+)?!', '$1.$2', $i);
|
||||
}
|
||||
public static function MONEY_OUT($i) {return money_format('%n', $i);}
|
||||
//удаляет двойные пробелы и табы
|
||||
public static function DSP($i)
|
||||
{
|
||||
return preg_replace('/\s{1,}/u', " ", $i);
|
||||
}
|
||||
public static function PLAIN_FORMAT($str,$one_str=0)
|
||||
{
|
||||
$str = PRE::DSP($str);
|
||||
if ($one_str) $str = preg_replace('!([\n]*)!simu', '', $str);
|
||||
$str = preg_replace('![\s]*([,.])!simu', '$1', $str);
|
||||
$str = trim($str);
|
||||
return $str;
|
||||
}
|
||||
//подрезает строку по разрешенному лимиту
|
||||
public static function CROP($s,$l=0){return (($l>0)?mb_substr($s,0,$l):$s);}
|
||||
}
|
||||
|
||||
|
||||
/**приведение в алфавит $a числа $int */
|
||||
function int2alphabet(array $a,int $int):string
|
||||
{
|
||||
$cnt = count($a); //емкость алфавита
|
||||
$out="";
|
||||
while ($int>=$cnt)
|
||||
{
|
||||
$out = ($a[($int % $cnt)]).$out;
|
||||
$int = intdiv($int, $cnt);
|
||||
}
|
||||
|
||||
return $a[$int].$out;
|
||||
}
|
||||
5
LE/core_fuctions.md
Normal file
5
LE/core_fuctions.md
Normal file
@@ -0,0 +1,5 @@
|
||||
# Описание базовых
|
||||
>jjj
|
||||
>kkk
|
||||
>
|
||||
|
||||
5
LE/db_init.php
Normal file
5
LE/db_init.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
if (SYSCONF::$USE_MYSQL)
|
||||
LE::$DB = new LE_MYSQL(SYSCONF::$DB);
|
||||
|
||||
//+++add sqlite
|
||||
11
LE/deprecated.php
Normal file
11
LE/deprecated.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
if (! function_exists("array_key_last")) {
|
||||
function array_key_last($array) {
|
||||
if (!is_array($array) || empty($array)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return array_keys($array)[count($array)-1];
|
||||
}
|
||||
}
|
||||
14
LE/load_mod.php
Normal file
14
LE/load_mod.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
$le_mod_loader = new LE_MOD_LOAD();
|
||||
LE::$QUERY_DATA_TYPE = LE_REQUEST::TYPE_DETECT();
|
||||
|
||||
//init space
|
||||
if ($le_mod_loader->init_path!==false)
|
||||
include $le_mod_loader->init_path;
|
||||
//load mod
|
||||
if ($le_mod_loader->mod_path!==false)
|
||||
include $le_mod_loader->mod_path;
|
||||
//not found
|
||||
if ($le_mod_loader->mod_path==false)
|
||||
include $le_mod_loader->select_path('main','__404.php');
|
||||
|
||||
19
LE/session.php
Normal file
19
LE/session.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
ini_set('session.gc_maxlifetime', SYSCONF::$SESS_TIME);
|
||||
ini_set('session.cookie_lifetime', SYSCONF::$SESS_TIME);
|
||||
ini_set('session.save_path', SYSCONF::$SESS_DIR);
|
||||
|
||||
if (!is_dir(SYSCONF::$SESS_DIR)) mkdir(SYSCONF::$SESS_DIR,0700,true);
|
||||
|
||||
session_start();
|
||||
|
||||
//при первом входе знать откуда пришел человек
|
||||
if (!isset($_SESSION['ref']) && isset($_SERVER["HTTP_REFERER"]))
|
||||
$_SESSION['ref'] = $_SERVER["HTTP_REFERER"];
|
||||
|
||||
//каждые 3 минуты делаем обновление времени жизни сессии
|
||||
$_exp = time()+SYSCONF::$SESS_TIME;
|
||||
if (!isset($_SESSION['_exp']))
|
||||
$_SESSION['_exp'] = $_exp;
|
||||
elseif (($_exp-$_SESSION['_exp'])>180)
|
||||
setcookie ("PHPSESSID", session_id() , ($_SESSION['_exp']=$_exp) ,'/');
|
||||
6
LE/sys_autoload.php
Normal file
6
LE/sys_autoload.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
/* LE Framework autoload core classes */
|
||||
spl_autoload_register(function ($class_name)
|
||||
{
|
||||
if (is_file(CORE_CLSDIR.$class_name.".php")) include CORE_CLSDIR.$class_name.".php";
|
||||
});
|
||||
38
LE/sys_conf.php
Normal file
38
LE/sys_conf.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
if(!defined("I")) die('err c001');
|
||||
|
||||
if(setlocale(LC_ALL, 'ru_RU.UTF-8','Russian_Russia.65001')===false)
|
||||
exit('!!!not find UTF-8 LOCALE');
|
||||
if(setlocale(LC_NUMERIC, 'en_US.UTF-8', 'C.UTF-8','C')===false)
|
||||
exit('!!!not find C NUMERIC LOCALE');
|
||||
|
||||
mb_internal_encoding("UTF-8");
|
||||
date_default_timezone_set('UTC');
|
||||
|
||||
LE::DEF('NO_CACHE'); //по-умолчанию кеширование включено
|
||||
|
||||
|
||||
class SYSCONF
|
||||
{
|
||||
public static $DEFAULT_MODSPACE = "main";
|
||||
public static $DEFAULT_MODULE = ['main' => 'welcome','admin'=>'dashboard'];
|
||||
public static $MOD_ALIASES;
|
||||
public static $USE_MYSQL = TRUE;
|
||||
public static $USE_TPL = TRUE;
|
||||
public static $ADMIN_MAIL = '';
|
||||
public static $ROBOT_MAIL = '';
|
||||
public static $DISP_TIME = FALSE;
|
||||
public static $DB = ['host'=>'localhost','user'=>'','pass'=>'','db_name' =>''];
|
||||
|
||||
public static $SPACE_LIST=['admin|cabinet'=>'admin','main'=>'main'];
|
||||
public static $SESS_DIR;
|
||||
public static $SESS_TIME=120960;
|
||||
public static $MPV;
|
||||
public static $DR_N="LE CMS";
|
||||
public static $CACH_DIR;
|
||||
}
|
||||
|
||||
SYSCONF::$SESS_DIR = APPDIR.'sessions'.DS;
|
||||
SYSCONF::$CACH_DIR = APPDIR.'cache'.DS;
|
||||
|
||||
if (is_file(APPDIR.'app_conf.php')) include APPDIR.'app_conf.php';
|
||||
Reference in New Issue
Block a user