197 lines
6.7 KiB
PHP
197 lines
6.7 KiB
PHP
<?php
|
||
|
||
/*
|
||
* 核心方法
|
||
* 应用支持php5.4+
|
||
*/
|
||
|
||
trait appcmp {
|
||
|
||
# 应用文件名
|
||
public $m_name = M_NAME;
|
||
# 应用数据库名简写
|
||
public $k_name;
|
||
# 数据库简写名
|
||
public $tname;
|
||
# 模板路径
|
||
public $appshow = '';
|
||
#是否要执行析构方法
|
||
public $destruct = true;
|
||
|
||
protected function show($file, $data)
|
||
{
|
||
global $_M, $_YW;
|
||
$view =load::sys_class('engine','new');
|
||
require_once $view->dodisplay($file, $data);
|
||
}
|
||
|
||
protected function check_auth() {
|
||
global $_M, $_YW;
|
||
self::cmp_a();
|
||
$exetime = time();
|
||
$bool = false;
|
||
//解密后的数组
|
||
$cache = json_decode(authcode($_YW['c']['ac_cache'],'DECODE',md5($_M['config']['met_weburl'])),true);
|
||
//查看本地是否存在禁止更新锁
|
||
if(file_exists(PATH_APP_FILE."config/update.lock")) $cache['update'] = 1;
|
||
//需要对比数据
|
||
if( $cache['time'] > $exetime || ($cache['time'] > $cache['exetime'] && $cache['time'] < $exetime) ){
|
||
$check = json_decode(authcode($cache['check'],'DECODE', md5(self::parse_url($_M['config']['met_weburl']).md5($this->m_name.$_YW['app']['addtime']))),true);
|
||
$state = $check['state'] && $check['app']['v_m_name'] == $this->m_name?true:false;
|
||
if($state){
|
||
if($check['vatime']['minute'] > 0){
|
||
//对有效时间计算
|
||
$time = date('Y-m-d H:i:s',$check['vatime']['stime']);
|
||
$endtime = strtotime("{$time} +{$check['vatime']['minute']} minute");
|
||
if($endtime <= $exetime ) $state = false;
|
||
}
|
||
//最终结果判断
|
||
$bool = $state && !empty($cache['wechat']) && !empty($cache['update'])?true:false;
|
||
}
|
||
}
|
||
if(!$bool) turnover($_M['url']['own_name'].'c=index&a=doindex&check=1','No prompt');
|
||
}
|
||
|
||
# 加载方法
|
||
public function loadp($str = '') {
|
||
global $_M, $_YW;
|
||
$arr = explode(",",$str);
|
||
foreach ($arr as $val) {
|
||
self::$val();
|
||
}
|
||
}
|
||
|
||
# 批量加载
|
||
public function cmp_load() {
|
||
global $_M, $_YW;
|
||
self::loadp('cmp_k,cmp_c,cmp_t');
|
||
}
|
||
|
||
# 获取完整数据库
|
||
public function cmp_k() {
|
||
global $_M, $_YW;
|
||
//全局
|
||
$globaltablename = ['cloud_config'];
|
||
//应用独有表名
|
||
$tablename = file_get_contents(PATH_ALL_APP.$this->m_name.'/config/table');
|
||
$this->k_name = array_diff(stringto_array($tablename,','),$globaltablename);
|
||
foreach ($this->k_name as $val) {
|
||
$_YW['k'][$val] = $_M['table'][$this->m_name . '_' . $val];
|
||
}
|
||
foreach ($globaltablename as $val) {
|
||
$_YW['k'][$val] = $_M['table'][$val];
|
||
}
|
||
}
|
||
|
||
# 配置信息
|
||
public function cmp_c($lang = '') {
|
||
global $_M, $_YW;
|
||
$_YW['n'] = $this->m_name;
|
||
if (empty($lang)) $lang = $_M['lang'];
|
||
$result = DB::query("select name,value from {$_M['table']['cloud_config']} where m_name = '{$this->m_name}' AND (lang = '{$lang}' OR lang = 'cloud') ");
|
||
while ($val = DB::fetch_array($result)) {
|
||
$_YW['c'][$val['name']] = $val['value'];
|
||
}
|
||
if(class_exists('admin') || class_exists('app')) self::check_auth();
|
||
}
|
||
|
||
# 应用信息
|
||
public function cmp_a() {
|
||
global $_M, $_YW;
|
||
$_YW['app'] = DB::get_one("SELECT * FROM {$_M['table']['applist']} WHERE m_name='{$this->m_name}' ");
|
||
}
|
||
|
||
# 栏目信息
|
||
public function cmp_ac() {
|
||
global $_M, $_YW;
|
||
$_YW['app']['column'] = DB::get_one("SELECT * FROM {$_M['table']['column']} WHERE module='{$_YW['app']['no']}' AND lang='{$_M['lang']}' ");
|
||
}
|
||
|
||
# 语言文字
|
||
public function cmp_t() {
|
||
global $_M, $_YW;
|
||
$file = PATH_APP_FILE . 'lang/' . $_M['lang'] . '.php';
|
||
if (!file_exists($file)) {
|
||
$file = PATH_APP_FILE . 'lang/cn.php';
|
||
}
|
||
if (file_exists($file)) require_once($file);
|
||
}
|
||
|
||
# 单条配置语句入库
|
||
public function addconsql($name, $val = '',$lang) {
|
||
global $_M, $_YW;
|
||
if (empty($lang)) $lang = $_M['lang'];
|
||
DB::query("INSERT INTO {$_M['table']['cloud_config']} (name,lang,m_name,value) VALUES ('{$name}','{$lang}','{$this->m_name}','{$val}') ON DUPLICATE KEY UPDATE value='{$val}' ");
|
||
}
|
||
|
||
# 信息JQ弹出并刷新当前页面
|
||
public function scriptgo($info) {
|
||
global $_M;
|
||
$this->destruct = false;
|
||
echo "<script>alert('{$info}');history.go(-1);</script>";
|
||
exit(0);
|
||
}
|
||
|
||
//表简称
|
||
public function tname() {
|
||
global $_M, $_YW;
|
||
return substr($_M['form']['a'],2);
|
||
}
|
||
|
||
//时间格式化
|
||
public function data_time($time) {
|
||
global $_M,$_YW;
|
||
return $time?date('Y-m-d H:i:s', $time):'';
|
||
}
|
||
|
||
//字符截取
|
||
public function sub_str($str) {
|
||
global $_M,$_YW;
|
||
return strlen($str) > 0?substr($str,0, 8).'...':'';
|
||
}
|
||
|
||
/*
|
||
* 把数组转成JSON,用于ajax返回,可以用于普通json请求返回,也可以用于跨域的ajax的jsonp格式的数据请求返回。
|
||
* @param array $back 输出字符串或数组
|
||
* @param string $callback ajax的回调函数的名称
|
||
*/
|
||
public function jsoncallback($back, $callback = 'callback') {
|
||
global $_M;
|
||
header('Content-type: application/x-javascript');
|
||
$callback = $_M['form'][$callback];
|
||
$json = json_encode($back,JSON_UNESCAPED_UNICODE);
|
||
echo $callback?$callback . '(' . $json . ')':$json;
|
||
}
|
||
|
||
# 分析网址
|
||
public function parse_url($url,$type = 'host') {
|
||
global $_M;
|
||
$url = url_standard($url);
|
||
$array = parse_url($url);
|
||
return $type == 'arr'?$array:$array[$type];
|
||
}
|
||
|
||
//URL参数处理,防止URL拼接错误
|
||
public function http_build_query($url,$arr) {
|
||
global $_M, $_YW;
|
||
if(!in_array(substr($url,-1), ['&','?'])) $url .= '&';
|
||
return $url.http_build_query($arr);
|
||
}
|
||
|
||
//前端CSS合并
|
||
public function merge_css($addcss = '') {
|
||
global $_M, $_YW;
|
||
$cssfile = PATH_APP_FILE.'public/css/webcss.css';
|
||
if(!file_exists($cssfile)) return false;
|
||
$css = file_get_contents($cssfile);
|
||
//自定义新增CSS文件
|
||
$diycss = PATH_APP_FILE.'public/css/diycss.css';
|
||
if(file_exists($diycss)) $css .= PHP_EOL.file_get_contents($diycss);
|
||
//通过后台新增的CSS
|
||
if(empty($addcss)) $addcss = $_YW['c']['diycss'];
|
||
return file_put_contents(PATH_APP_FILE.'web/templates/met/css/metinfo.css', $css.PHP_EOL.$addcss);
|
||
}
|
||
|
||
|
||
}
|