<?php
//验证权限
function permission($mod,$item){
global $_S;
if($_S['uid']==1){
return true;
}
if(!$_S['member']['manage'][$mod][$item]){
showmessage('不具备相关管理权限');
}
}
function getpanel(){
global $_S;
$mods=array(
'index'=>array(
'name'=>'首页',
'next'=>array()
),
'functions'=>array(
'name'=>'功能',
'load'=>true,
'next'=>array()
),
'channel'=>array(
'name'=>'聚合',
'next'=>array(
'portal'=>array('id'=>'portal','name'=>'移动端频道'),
'topic'=>array('id'=>'topic','name'=>'PC专题'),
'keyword'=>array('id'=>'keyword','name'=>'关键词'),
'collection'=>array('id'=>'collection','name'=>'内容合集'),
)
),
'content'=>array(
'name' =>'内容',
'next'=>array(
'manage'=>array('id'=>'manage','name'=>'已发布'),
'examine'=>array('id'=>'examine','name'=>'待审核'),
'bin'=>array('id'=>'bin','name'=>'回收站'),
'search'=>array('id'=>'search','name'=>'搜索文稿','load'=>true),
)
),
'member'=>array(
'name'=>'用户',
'next'=>array(
'fans'=>array('id'=>'fans','name'=>'粉丝列表'),
'customer'=>array('id'=>'customer','name'=>'会员列表'),
'team'=>array('id'=>'team','name'=>'团队成员'),
'special'=>array('id'=>'special','name'=>'特殊用户'),
'examine'=>array('id'=>'examine','name'=>'审核用户','load'=>true),
'search'=>array('id'=>'search','name'=>'搜索用户','load'=>true),
'extend'=>array('id'=>'extend','name'=>'扩展字段'),
)
),
'service'=>array(
'name'=>'客服',
'load'=>true,
'next'=>array(
'official-account'=>array('id'=>'official-account','name'=>'公众号信息'),
'contact'=>array('id'=>'contact','name'=>'联系我们'),
'call-center'=>array('id'=>'call-center','name'=>'客服号'),
)
),
'operate'=>array(
'name'=>'运营',
'next'=>array(
'count'=>array('id'=>'count','name'=>'访客详情'),
'wxnotice'=>array('id'=>'wxnotice','name'=>'微信模版消息','load'=>true),
'sub'=>array('id'=>'sub','name'=>'粉丝订阅','load'=>true),
'sms'=>array('id'=>'sms','name'=>'短信通知','load'=>true),
'feedback'=>array('id'=>'feedback','name'=>'反馈和举报'),
'notice'=>array('id'=>'notice','name'=>'公告'),
)
),
'plugin'=>array(
'name'=>'应用',
'next'=>array(
'index'=>array('id'=>'index','name'=>'应用管理'),
'store'=>array('id'=>'store','name'=>'应用商店'),
)
),
'ui'=>array(
'name'=>'界面UI',
'load'=>true,
'next'=>array(
'nav'=>array('id'=>'nav','name'=>'手机版导航'),
'column'=>array('id'=>'column','name'=>'PC版导航'),
'css'=>array('id'=>'css','name'=>'自定义CSS'),
'color'=>array('id'=>'color','name'=>'自定义配色'),
'icons'=>array('id'=>'icons','name'=>'Icon图标库'),
/*
'smile'=>array('id'=>'smile','name'=>'表情库'),
*/
'tpl'=>array('id'=>'tpl','name'=>'模版开发'),
)
),
'set' =>array(
'name'=>'配置',
'load'=>true,
'next'=>array(
'basic'=>array('id'=>'basic','name'=>'基本信息'),
'reg'=>array('id'=>'reg','name'=>'注册控制'),
'wallet'=>array('id'=>'wallet','name'=>'用户钱包'),
'reward'=>array('id'=>'reward','name'=>'积分规则'),
'1'=>array('id'=>'blank','name'=>''),
'wechat'=>array('id'=>'wechat','name'=>'微信接口'),
'sms'=>array('id'=>'sms','name'=>'短信接口'),
'cloud'=>array('id'=>'cloud','name'=>'云存储'),
'map'=>array('id'=>'map','name'=>'地图接口'),
'2'=>array('id'=>'blank','name'=>''),
'system'=>array('id'=>'system','name'=>'系统配置'),
'poster'=>array('id'=>'poster','name'=>'海报图设置'),
'wss'=>array('id'=>'wss','name'=>'WebScoket'),
'sensitive'=>array('id'=>'sensitive','name'=>'敏感词'),
)
),
/*
'block'=>array(
'name'=>'区块链',
'load'=>true,
'next'=>array(
array('id'=>'1','name'=>'应用场景'),
array('id'=>'2','name'=>'如何实现'),
array('id'=>'3','name'=>'白皮书'),
array('id'=>'4','name'=>'招揽大才'),
array('id'=>'5','name'=>'进度查询'),
)
),
*/
'skin'=>array(
'name'=>'偏好',
'load'=>true,
'next'=>array()
),
/*
'partnership'=>array(
'name'=>'合作',
'load'=>true,
'next'=>array(
array('id'=>'1','name'=>'建立合作'),
array('id'=>'2','name'=>'授权合作'),
array('id'=>'3','name'=>'前端设计师'),
array('id'=>'4','name'=>'PHP开发者'),
array('id'=>'5','name'=>'我推广的站点'),
)
),
*/
);
if($_S['uid']==1){
return $mods;
}else{
unset($mods['set']);
//聚合
if(!$_S['member']['manage']['channel']['portal']){
unset($mods['channel']['next']['portal']);
}
if(!$_S['member']['manage']['channel']['topic']){
unset($mods['channel']['next']['topic']);
}
if(!$_S['member']['manage']['channel']['keyword']){
unset($mods['channel']['next']['keyword']);
}
if(!$_S['member']['manage']['channel']['collection']){
unset($mods['channel']['next']['collection']);
}
if(count($mods['channel']['next'])==0){
unset($mods['channel']);
}
//用户
if(!$_S['member']['manage']['user']['fans']){
unset($mods['member']['next']['fans']);
}
if(!$_S['member']['manage']['user']['customer']){
unset($mods['member']['next']['customer']);
}
if(!$_S['member']['manage']['user']['special']){
unset($mods['member']['next']['special']);
}
if(!$_S['member']['manage']['user']['team']){
unset($mods['member']['next']['team']);
}
if(!$_S['member']['manage']['user']['field']){
unset($mods['member']['next']['extend']);
}
if(!$_S['member']['manage']['user']['fans'] && !$_S['member']['manage']['user']['customer'] && !$_S['member']['manage']['user']['special']){
unset($mods['member']['next']['search']);
}
if(count($mods['member']['next'])==0){
unset($mods['member']);
}
//客服
if(!$_S['member']['manage']['operate']['service']){
unset($mods['service']);
}
//运营
if(!$_S['member']['manage']['operate']['count']){
unset($mods['service']['next']['count']);
}
if(!$_S['member']['manage']['operate']['notice']){
unset($mods['service']['next']['notice']);
}
if(!$_S['member']['manage']['operate']['feedback']){
unset($mods['service']['next']['feedback']);
}
//ui
foreach($mods['ui']['next'] as $id=>$next){
if(!$_S['member']['manage']['ui'][$id]){
unset($mods['ui']['next'][$next['id']]);
}
}
if(count($mods['ui']['next'])==0){
unset($mods['ui']);
}
}
return $mods;
}
//获取icon文件时间
function geticontime($path){
if($path){
$info = explode('.',basename($path));
return '于 '.smsdate(intval($info[0]/1000),'Y-m-d H:i:s').' 上传';
}
return false;
}
function setcolor(){
$content =":root{\n";
$query = D::q("SELECT * FROM ".D::t('colors'));
while($value = D::fetch($query)) {
$content .='--'.$value['id'].':'.$value['var'].";\n";
}
$content .='}';
writefile(ROOT.'./cache/color.css', $content, 'css', 'w', 0);
}
//操作记录
function logs($type,$title,$content){
global $_S;
if($type && $title && $content){
$log = array(
'uid'=> $_S['uid'],
'type' => $type,
'title' => $title,
'content' => $content,
'dateline' => $_S['time'],
);
D::insert('logs',$log);
D::q('UPDATE '.D::t('members_account').' SET `logs`=`logs`+ 1 WHERE `uid`=\''.$_S['uid'].'\'');
}
}
function exportarray($array, $method) {
$tmp = $array;
if($method) {
foreach($array as $k => $v) {
if(is_array($v)) {
$tmp[$k] = exportarray($v, 1);
} else {
$uv = unserialize($v);
if($uv && is_array($uv)) {
$tmp['__'.$k] = exportarray($uv, 1);
unset($tmp[$k]);
} else {
$tmp[$k] = $v;
}
}
}
} else {
foreach($array as $k => $v) {
if(is_array($v)) {
if(substr($k, 0, 2) == '__') {
$tmp[substr($k, 2)] = serialize(exportarray($v, 0));
unset($tmp[$k]);
} else {
$tmp[$k] = exportarray($v, 0);
}
} else {
$tmp[$k] = $v;
}
}
}
return $tmp;
}
function downloadpatch($patch, $targetDirectory='temporary') {
// 获取文件名
$fileName = basename($patch);
// 设置文件的保存路径
if(!is_dir(ROOT.'./data/'.$targetDirectory)) {
showmessage('服务器中“./data/'.$targetDirectory.'"文件夹不存在"');
}
$targetPath = ROOT.'./data/'.$targetDirectory.'/' . $fileName;
// 尝试使用 cURL 下载文件
if (function_exists('curl_init')) {
$ch = curl_init($patch);
curl_setopt($ch, CURLOP_TIMEOUT,60);
$fp = fopen($targetPath, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
$result = curl_exec($ch);
if ($result === false) {
showmessage('Failed to download file using cURL: ' . curl_error($ch));
}
curl_close($ch);
fclose($fp);
} else {
// 如果 cURL 不可用,使用 file_get_contents 下载文件
$fileContent = file_get_contents($patch);
if ($fileContent === false) {
showmessage('Failed to download file using file_get_contents');
}
$result = file_put_contents($targetPath, $fileContent);
if ($result === false) {
showmessage('Failed to save file to target directory');
}
}
// 检查文件是否下载成功
if (file_exists($targetPath)) {
return $fileName;
} else {
return false;
}
}
//解压zip文件
function unzipFile($zipFile) {
// 检查 ZipArchive 类是否存在
if (!class_exists('ZipArchive')) {
showmessage('服务器不支持ZipArchive');
}
// 参数验证和路径安全性检查
if (!file_exists($zipFile) || !is_readable($zipFile)) {
showmessage($zipFile.'不存在或不可读');
}
try {
$zip = new ZipArchive;
if ($zip->open($zipFile) !== TRUE) {
showmessage('无法打开zip文件');
}
$content = $zip->getFromName('info.xml');
if(!$content){
showmessage('压缩包中缺少info.xml,无法提取文件');
}
$originalEncoding = mb_detect_encoding($content);
if(!$originalEncoding){
showmessage('无法检测到内容的编码');
}
//$content = mb_convert_encoding($content, 'UTF-8', 'ASCII');
require_once ROOT.'./core/xml.php';
$info = xml2array($content);
if(!$info['type']){
showmessage('info.xml文件缺少运行文件参数');
}
// 确保目标目录存在,且可写
if ($info['target'] && !is_dir(ROOT.$info['target'])) {
if(!mkdir(ROOT.$info['target'], 0755, true) && !is_writable(ROOT.$info['target'])) {
showmessage('无法创建或写入目标目录');
}
}
if(!$zip->extractTo(ROOT.$info['target'])) {
showmessage('无法提取zip文件');
}
$numFiles = $zip->numFiles;
for ($i = 0; $i < $numFiles; $i++) {
$filelist[] = $zip->statIndex($i);
}
$zip->close();
unlink($zipFile);
return array('info'=>$info,'files'=>$filelist);
} catch (Exception $e) {
showmessage($e->getMessage());
}
}
function exportdata($name, $filename, $data,$type='portal',$target='') {
global $_S;
require_once ROOT.'./core/xml.php';
$root = array(
'name' => $name,
'type' => $type,
'target' => $target,
'site' => $_S['setting']['siteurl'],
'time' => smsdate($_S['time'], 'Y-m-d H:i'),
'data' => exportarray($data, 1)
);
$filename = str_replace(array('!', ' '), array('', '_'), $name).'_'.$filename.'.xml';
$export = array2xml($root, 1);
ob_end_clean();
Sheader('Expires: Mon, 26 Jul 2000 05:00:00 GMT');
Sheader('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
Sheader('Cache-Control: no-cache, must-revalidate');
Sheader('Pragma: no-cache');
Sheader('Content-Encoding: none');
Sheader('Content-Length: '.strlen($export));
Sheader('Content-Disposition: attachment; filename='.$filename);
Sheader('Content-Type: text/xml;charset=utf-8');
echo $export;
define('FOOTERDISABLED' , 1);
exit();
}
function getDateFromRange($startdate, $enddate){
$days = ($enddate-$startdate)/86400;
$date = array();
for($i=0; $i<$days; $i++){
$timestamp = $startdate+(86400*$i);
$date[smsdate($timestamp,'ymd')] = array('date'=>smsdate($timestamp,'m-d'),'star'=>$timestamp,'end'=>$timestamp+86400);
}
return $date;
}
function wxbutton($getname,$gettype,$getvalue){
foreach($getname as $k=>$name){
$name = security($name,4);
$type = in_array($gettype[$k],array('view','click','miniprogram')) ? $gettype[$k] : 'view';
if($name){
$value = security($getvalue[$k]);
if($type=='view'){
if($name){
$button_item = array('name'=>$name,'type'=>$type,'url'=>$value);
}
}elseif($type=='miniprogram'){
list($url,$appid,$pagepath) = explode(',',$value);
if(checkurl($url) && $appid && $pagepath){
$button_item = array('name'=>$name,'type'=>$type,'url'=>$url,'appid'=>$appid,'pagepath'=>$pagepath);
}
}else{
if($value){
$button_item = array('name'=>$name,'type'=>$type,'key'=>$value);
}
}
}
if($button_item){
$buttons[] = $button_item;
unset($button_item);
}
}
return $buttons;
}
function farmatwxvalue($item){
if($item['type']=='view'){
echo $item['url'];
}elseif($item['type']=='miniprogram'){
echo $item['url'].','.$item['appid'].','.$item['pagepath'];
}else{
echo $item['key'];
}
}
function runquery($sql) {
global $_S, $db;
if(!isset($sql) || empty($sql)) return;
$sql = str_replace("\r", "\n", str_replace(' '.TABLEPRE, ' '.$_S['db']['pre'], $sql));
$sql = str_replace("\r", "\n", str_replace(' `'.TABLEPRE, ' `'.$_S['db']['pre'], $sql));
$ret = array();
$num = 0;
foreach(explode(";\n", trim($sql)) as $query) {
$ret[$num] = '';
$queries = explode("\n", trim($query));
foreach($queries as $query) {
$ret[$num] .= (isset($query[0]) && $query[0] == '#') || (isset($query[1]) && isset($query[1]) && $query[0].$query[1] == '--') ? '' : $query;
}
$num++;
}
unset($sql);
foreach($ret as $query) {
$query = trim($query);
if($query) {
if(substr($query, 0, 12) == 'CREATE TABLE') {
$name = preg_replace("/CREATE TABLE IF NOT EXISTS `([a-z0-9_]+)` .*/is", "\\1", $query);
D::q(createtable($query));
} else {
D::q($query);
}
}
}
return true;
}
function createtable($sql) {
$type = strtoupper(preg_replace("/^\s*CREATE TABLE\s+.+\s+\(.+?\).*(ENGINE|TYPE)\s*=\s*([a-z]+?).*$/isU", "\\2", $sql));
$type = in_array($type, array('MYISAM', 'HEAP', 'MEMORY')) ? $type : 'MYISAM';
return preg_replace("/^\s*(CREATE TABLE\s+.+\s+\(.+?\)).*$/isU", "\\1", $sql)." ENGINE=$type DEFAULT CHARSET=utf8" ;
}
?>