Initial project files: BESCMS full source

This commit is contained in:
bes
2026-08-13 23:37:46 +08:00
parent fa6cddb540
commit 2e26f85723
2166 changed files with 396625 additions and 0 deletions
+527
View File
@@ -0,0 +1,527 @@
<?php namespace Phpcmf\Control\Api;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
// 通用接口处理
class Api extends \Phpcmf\Common {
/**
* ip地址
*/
public function ip_address() {
$value = dr_safe_replace(\Phpcmf\Service::L('input')->get('value'));
if (!$value) {
exit(dr_lang('IP地址为空'));
}
list($value, $port) = explode('-', $value);
$address = \Phpcmf\Service::L('ip')->address($value);
echo ('<a href="https://www.baidu.com/s?wd='.$value.'&action=xunruicms" target="_blank">'.dr_lang('IP归属地:%s', $address).'</a>');
if ($port) {
echo '
<br>'.dr_lang('源端口号:%s', (int)$port);
}
exit;
}
/**
* 保存浏览器定位坐标
*/
public function map_position() {
$value = dr_safe_replace(\Phpcmf\Service::L('input')->get('value'));
$cookie = \Phpcmf\Service::L('input')->get_cookie('map_position');
if ($cookie != $value) {
\Phpcmf\Service::L('input')->set_cookie('map_position', $value, 10000);
exit('ok');
}
exit('none');
}
/**
* 二维码显示
*/
public function qrcode() {
$value = urldecode(\Phpcmf\Service::L('input')->get('text'));
$thumb = urldecode(\Phpcmf\Service::L('input')->get('thumb'));
$matrixPointSize = (int)\Phpcmf\Service::L('input')->get('size');
$errorCorrectionLevel = dr_safe_replace(\Phpcmf\Service::L('input')->get('level'));
//生成二维码图片
require_once CMSPATH.'Library/Phpqrcode.php';
$file = WRITEPATH.'file/qrcode-'.md5($value.$thumb.$matrixPointSize.$errorCorrectionLevel).'-qrcode.png';
if (!IS_DEV && is_file($file)) {
$QR = imagecreatefrompng($file);
} else {
\QRcode::png($value, $file, $errorCorrectionLevel, $matrixPointSize, 3);
if (!is_file($file)) {
exit('二维码生成失败');
}
$QR = imagecreatefromstring(file_get_contents($file));
if ($thumb) {
if (stripos($thumb, 'phar://') !== false) {
exit('图片地址不规范');
} elseif (filter_var($thumb, FILTER_VALIDATE_URL) !== false || file_exists($thumb)) {
$img = getimagesize($thumb);
if (!$img) {
exit('此图片不是一张可用的图片');
}
$code = dr_catcher_data($thumb);
if (!$code) {
exit('图片参数不规范');
}
$logo = imagecreatefromstring($code);
$QR_width = imagesx($QR);//二维码图片宽度
$logo_width = imagesx($logo);//logo图片宽度
$logo_height = imagesy($logo);//logo图片高度
$logo_qr_width = $QR_width / 4;
$scale = $logo_width/$logo_qr_width;
$logo_qr_height = $logo_height/$scale;
$from_width = ($QR_width - $logo_qr_width) / 2;
//重新组合图片并调整大小
imagecopyresampled($QR, $logo, (int)$from_width, (int)$from_width, 0, 0, (int)$logo_qr_width, (int)$logo_qr_height, (int)$logo_width, (int)$logo_height);
imagepng($QR, $file);
} else {
exit('图片地址不规范');
}
}
}
// 输出图片
ob_start();
ob_clean();
header("Content-type: image/png");
$QR && imagepng($QR);
exit;
}
/**
* 搜索
*/
public function search() {
if (function_exists('dr_module_api_search')) {
dr_module_api_search();
} else {
exit('需要升级最新版的【内容建站系统】插件');
}
}
/**
* 检查关键字
*/
public function checktitle() {
if (function_exists('dr_module_checktitle')) {
dr_module_checktitle();
} else {
exit('需要升级最新版的【内容建站系统】插件');
}
}
/**
* 提取关键字
*/
public function getkeywords() {
exit(dr_get_keywords(dr_safe_replace(\Phpcmf\Service::L('input')->get('title'))));
}
/**
* 存储临时表单内容
*/
public function save_form_data() {
if (IS_POST && $this->member && $this->member['is_admin']) {
$rt = \Phpcmf\Service::L('cache')->init('file')->save(
md5(\Phpcmf\Service::L('input')->get('name')),
\Phpcmf\Service::L('input')->post('data'),
7200
);
var_dump($rt);
}
exit;
}
/**
* 删除临时表单内容
*/
public function delete_form_data() {
\Phpcmf\Service::L('cache')->init('file')->delete(md5(\Phpcmf\Service::L('input')->get('name', true)));
$this->_json(1, dr_lang('清除成功'));
exit;
}
/**
* 验证码
*/
public function captcha() {
$code = \Phpcmf\Service::L('captcha')->create(
max(0, intval($_GET['width'])), max(0, intval($_GET['height']))
);
\Phpcmf\Service::L('cache')->set_auth_data('web-captcha-'.USER_HTTP_CODE, $code, SITE_ID);
IS_DEV && log_message('debug', '图片验证码生成('.USER_HTTP_CODE.')验证码:'.$code);
exit;
}
/**
* 汉字转换拼音
*/
public function pinyin() {
$name = dr_safe_replace(\Phpcmf\Service::L('input')->get('name'));
if (!$name) {
exit('');
}
$py = \Phpcmf\Service::L('pinyin')->result($name);
if (strlen($py) > 12) {
$sx = \Phpcmf\Service::L('pinyin')->result($name, 0);
if ($sx) {
exit($sx);
}
}
exit($py);
}
/**
* 联动菜单调用
*/
public function linkage() {
$code = dr_safe_replace(\Phpcmf\Service::L('input')->get('code'));
$linkage = dr_linkage_json($code);
if (!$linkage) {
if (CI_DEBUG) {
$linkage = [
[
'value' => 0,
'label' => '请在联动菜单管理,找到【'.$code.'】,点击一键生成按钮',
'children' => [],
]
];
} else {
$linkage = [];
}
}
echo 'var linkage_'.$code.' ='.json_encode($linkage, JSON_UNESCAPED_UNICODE).';';exit;
}
/**
* 联动菜单Api
*/
public function linkage_json() {
$code = dr_safe_replace(\Phpcmf\Service::L('input')->get('code'));
if (!$code) {
$this->_json(0, dr_lang('联动菜单code参数没有值'));
}
$linkage = dr_linkage_json($code);
if (!$linkage) {
$this->_json(0, dr_lang('没有联动菜单数据'));
}
$this->_json(1, $code, $linkage);
}
/**
* 经典样式的联动菜单调用
*/
public function linkage_data() {
$code = dr_safe_replace(\Phpcmf\Service::L('input')->get('code'));
if (!$code) {
$this->_json(0, dr_lang('联动菜单code参数没有值'));
}
$pid = (int)\Phpcmf\Service::L('input')->get('pid');
$linkage = dr_linkage_list($code, $pid);
$json = [];
foreach ($linkage as $v) {
if ($v['pid'] == $pid) {
$json[] = $v;
}
}
if (!$json) {
$this->_json(0, dr_lang('没有联动菜单数据'));
}
$this->_json(1, $code, $json);
}
/**
* 经典样式的联动菜单调用
*/
public function linkage_ld() {
$pid = (int)\Phpcmf\Service::L('input')->get('parent_id');
$code = dr_safe_replace(\Phpcmf\Service::L('input')->get('code'));
$linkage = dr_linkage_list($code, $pid);
$json = [];
$html = '';
foreach ($linkage as $v) {
if ($v['pid'] == $pid) {
$json[] = [
'region_id' => $v['ii'],
'region_code' => $v['id'],
'region_name' => $v['name']
];
}
}
echo json_encode([
'data' => $json,
'html' => $html,
], JSON_UNESCAPED_UNICODE);exit;
}
/**
* Ajax调用字段属性表单
*/
public function field() {
\Phpcmf\Service::L('api')->field();
}
/**
* 动态调用模板
*/
public function template() {
$app = dr_safe_filename(\Phpcmf\Service::L('input')->get('app'));
$file = dr_safe_filename(\Phpcmf\Service::L('input')->get('name'));
$module = dr_safe_filename(\Phpcmf\Service::L('input')->get('module'));
$data = [
'app' => $app,
'file' => $file,
'module' => $module,
];
if (!$file) {
$html = 'name不能为空';
} else {
if ($module) {
$this->_module_init($module);
\Phpcmf\Service::V()->module($module);
} elseif ($app) {
\Phpcmf\Service::V()->module($app);
}
\Phpcmf\Service::V()->assign(\Phpcmf\Service::L('input')->get('', true));
ob_start();
\Phpcmf\Service::V()->display($file);
$html = ob_get_contents();
ob_clean();
$data['call_value'] = \Phpcmf\Service::V()->call_value;
}
$this->_json(1, $html, $data);
}
/**
* 内容关联字段数据读取
*/
public function related() {
$this->_json(0, dr_lang('需要安装最新版的【建站系统】插件'));
}
/**
* 会员关联字段数据读取
*/
public function members() {
$this->_json(0, dr_lang('需要安装最新版的【用户系统】插件'));
}
/**
* 退出前台账号
*/
public function loginout() {
// 注销授权登陆的会员
if ($this->session()->get('member_auth_uid')) {
\Phpcmf\Service::C()->session()->delete('member_auth_uid');
$this->_json(0, dr_lang('当前状态无法退出账号'));
}
$this->_json(1, dr_lang('您的账号已退出系统'), [
'url' => isset($_SERVER['HTTP_REFERER']) ? dr_safe_url($_SERVER['HTTP_REFERER']) : SITE_URL,
'sso' => \Phpcmf\Service::M('member')->logout(),
]);
}
/**
* 电脑和手机网站切换处理接口
*/
public function client() {
$this->_json(0, dr_lang('此功能已废弃'));
}
/**
* 发送验证码
*/
public function send_code() {
$phone = dr_safe_replace(\Phpcmf\Service::L('input')->get('id'));
if (!$phone) {
$this->_json(0, dr_lang('手机号码未填写'), ['field' => 'phone']);
} elseif (!\Phpcmf\Service::L('Form')->check_phone($phone)) {
$this->_json(0, dr_lang('手机号码格式不正确'), ['field' => 'phone']);
}
// 挂钩点 短信验证之前
\Phpcmf\Hooks::trigger('send_phone_before', $phone);
if (!defined('SYS_SMS_IMG_CODE') || SYS_SMS_IMG_CODE == 0) {
$code = dr_safe_replace(\Phpcmf\Service::L('input')->get('code'));
if (!$code) {
$this->_json(0, dr_lang('图片验证码未填写'), ['field' => 'code']);
} elseif (!\Phpcmf\Service::L('Form')->check_captcha_value($code)) {
$this->_json(0, dr_lang('图片验证码不正确'), ['field' => 'code']);
}
}
// 验证操作间隔
if (\Phpcmf\Service::L('Form')->get_mobile_code($phone)) {
$this->_json(1, dr_lang('已经发送稍后再试'));
}
$code = \Phpcmf\Service::L('Form')->get_rand_value();
$rt = \Phpcmf\Service::M('member')->sendsms_code($phone, $code);
if (!$rt['code']) {
$this->_json(0, IS_DEV ? $rt['msg'] : dr_lang('发送失败'));
}
\Phpcmf\Service::L('Form')->set_mobile_code($phone, $code);
$this->_json(1, dr_lang('验证码发送成功'));
}
/**
* 关联字段数据读取
*/
public function join() {
$user = (string)$_SERVER['HTTP_USER_AGENT'];
if (stripos($user, 'spider') !== false or strpos($user, 'bot') !== false) {
$this->goto_404_page('蜘蛛禁止抓取');
}
// 强制将模板设置为后台
\Phpcmf\Service::V()->admin();
// 登陆判断
//if (!$this->uid) {
// $this->_json(0, dr_lang('会话超时,请重新登录'));
//}
// 参数判断
$fid = intval(\Phpcmf\Service::L('input')->get('fid'));
if (!$fid) {
$this->_json(0, dr_lang('fid参数不存在'));
}
$field = \Phpcmf\Service::M()->table('field')->get($fid);
if (!$field) {
$this->_json(0, dr_lang('字段(%s)不存在', $fid));
}
$field['setting'] = dr_string2array($field['setting']);
$pagesize = $field['setting']['option']['pagesize'];
if (!$pagesize) {
$pagesize = 10;
}
// 模块缓存判断
$table = $field['setting']['option']['table'];
if (!$table) {
$this->_json(0, dr_lang('未设置关联表'));
}
$param = $data = \Phpcmf\Service::L('input')->get('', true);
$name = $field['fieldname'];
if (IS_POST) {
$ids = \Phpcmf\Service::L('input')->get_post_ids();
if (!$ids) {
$this->_json(0, dr_lang('没有选择项'));
}
$id = [];
foreach ($ids as $i) {
$id[] = (int)$i;
}
$builder = \Phpcmf\Service::M()->db->table($table);
$builder->whereIn('id', $id);
$mylist = $builder->orderBy('id DESC')->get()->getResultArray();
if (!$mylist) {
$this->_json(0, dr_lang('没有相关数据'));
}
$ids = [];
foreach ($mylist as $t) {
$ids[] = $t['id'];
}
$file = \Phpcmf\Service::V()->code2php(
file_get_contents(is_file(MYPATH.'View/api_join_field_'.$field['fieldname'].'.html') ? MYPATH.'View/api_join_field_'.$field['fieldname'].'.html' : COREPATH.'View/api_join_field.html')
);
ob_start();
require $file;
$code = ob_get_clean();
$html = explode('<!--list-->', $code);
$this->_json(1, dr_lang('操作成功'), ['ids' => $ids, 'html' => $html[1]]);
}
$where = [];
if ($data['search']) {
$data['keyword'] = dr_safe_replace(urldecode($data['keyword']));
if ($data['keyword']) {
$where[] = 'id LIKE "%'.$data['keyword'].'%"';
foreach ($field['setting']['option']['field'] as $t) {
if ($t['field']) {
$where[] = $t['field'].' LIKE "%'.$data['keyword'].'%"';
}
}
}
}
$rules = $data;
$rules['page'] = '{page}';
\Phpcmf\Service::V()->assign([
'table' => $table,
'param' => $data,
'field' => $field,
'where' => $where ? urlencode('('.implode(' OR ', $where).')') : '',
'search' => dr_form_search_hidden(['search' => 1, 'is_iframe' => 1, 'fid' => $fid]),
'urlrule' => '/index.php?s=api&c=api&m=join&'.http_build_query($rules),
'pagesize' => $pagesize,
]);
if (is_file(MYPATH.'View/api_join_'.$field['fieldname'].'.html')) {
\Phpcmf\Service::V()->display('api_join_'.$field['fieldname'].'.html');
} else {
\Phpcmf\Service::V()->display('api_join.html');
}
}
}
+19
View File
@@ -0,0 +1,19 @@
<?php namespace Phpcmf\Control\Api;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
$file = dr_get_app_dir('pay').'Controllers/Buy.php';
if (is_file($file)) {
require_once $file;
} else {
\dr_exit_msg(0, '没有安装「支付系统」插件');
}
// 交易下单
class Buy extends \Phpcmf\Controllers\Buy {
}
File diff suppressed because it is too large Load Diff
+121
View File
@@ -0,0 +1,121 @@
<?php namespace Phpcmf\Control\Api;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
// 文件操作
class File extends \Phpcmf\Common
{
// 验证权限脚本
public function _check_upload_auth($editor = 0) {
return \Phpcmf\Service::L('api')->check_upload_auth($editor);
}
/**
* 文件上传
*/
public function upload() {
\Phpcmf\Service::L('api')->upload();
}
/**
* 输入一个附件
*/
public function input_file_url() {
\Phpcmf\Service::L('api')->input_file_url();
}
/**
* 浏览文件
*/
public function input_file_list() {
\Phpcmf\Service::L('api')->input_file_list();
}
/**
* 浏览文件
*/
public function file_list() {
\Phpcmf\Service::L('api')->file_list();
}
/**
* 删除文件
*/
public function file_delete() {
$rt = \Phpcmf\Service::M('Attachment')->file_delete(
$this->member,
(int)\Phpcmf\Service::L('input')->get('id')
);
$this->_json($rt['code'], $rt['msg']);
}
/**
* 下载文件
*/
public function down() {
\Phpcmf\Service::L('api')->down();
}
/**
* 百度编辑器处理接口
*/
public function ueditor() {
require ROOTPATH.'api/ueditor/php/controller.php';exit;
}
/**
* base64图片上传
*/
public function upload_base64_image() {
\Phpcmf\Service::L('api')->upload_base64_image();
}
/**
* 图片编辑
*/
public function image_edit() {
\Phpcmf\Service::L('api')->image_edit();
}
/**
* 附件改名
*/
public function name_edit() {
\Phpcmf\Service::L('api')->name_edit();
}
/**
* 下载远程图片
*/
public function down_img_list() {
\Phpcmf\Service::L('api')->down_img_list();
}
/**
* 下载远程图片
*/
public function down_img_url() {
\Phpcmf\Service::L('api')->down_img_url();
}
/**
* 下载远程图片
*/
public function down_img() {
\Phpcmf\Service::L('api')->down_img();
}
/**
* 编辑器视频外链解析
*/
public function video() {
\Phpcmf\Service::L('api')->video_link();
}
}
+51
View File
@@ -0,0 +1,51 @@
<?php namespace Phpcmf\Control\Api;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
// 接口处理
class Home extends \Phpcmf\Common
{
public function index() {
if (IS_API === 'pay') {
// 支付接口部分
$info = pathinfo($_SERVER['PHP_SELF']);
$name = basename($info['dirname']);
$path = trim($info['dirname'], '/');
$file = str_replace('_url.php', '_api.php', $info['basename']);
$apifile = WEBPATH . $path . '/' . $file;
if (!is_file($apifile)) {
if (IS_DEV) {
exit('支付接口文件('.$apifile.')不存在');
}
exit('支付接口文件不存在');
}
// 接口配置参数
$config = $this->member_cache['payapi'][$name];
require $apifile;
} elseif (IS_API === 'cron') {
// 任务脚本
$cron = new \Phpcmf\Control\Api\Run($this);
$cron->index();
} elseif (is_file(IS_API)) {
// 自定义任意目录的api
require IS_API;
} else {
$myfile = MYPATH.'Api/'.ucfirst(IS_API).'.php';
if (!is_file($myfile)) {
if (IS_DEV) {
exit('Api接口文件('.$myfile.')不存在');
}
exit('api file is error');
}
require $myfile;
exit;
}
exit;
}
}
+104
View File
@@ -0,0 +1,104 @@
<?php namespace Phpcmf\Control\Api;
/**
* https://www.besyun.com
* BESCMS
* 本代码基于MIT开源协议,协议规定此处版权信息不可去除
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
// 模块ajax操作接口
class Module extends \Phpcmf\Common {
private $siteid;
private $dirname;
private $tablename;
public $content_model;
public function __construct() {
parent::__construct();
// 初始化模块
$this->siteid = (int)\Phpcmf\Service::L('input')->get('siteid');
!$this->siteid && $this->siteid = SITE_ID;
$this->dirname = dr_safe_filename(\Phpcmf\Service::L('input')->get('app'));
if ($this->dirname == 'MOD_DIR') {
$this->_msg(0, dr_lang('app参数存在问题'));
} elseif (!$this->dirname || !dr_is_app_dir(($this->dirname))) {
$this->_msg(0, dr_lang('模块目录[%s]不存在', $this->dirname));
exit;
}
$this->tablename = $this->siteid.'_'.$this->dirname;
$this->content_model = \Phpcmf\Service::M('Content', $this->dirname);
$this->_module_init($this->dirname, $this->siteid);
$user = (string)$_SERVER['HTTP_USER_AGENT'];
if (strpos($user, 'spider') !== false or strpos($user, 'bot') !== false) {
$this->goto_404_page('蜘蛛禁止抓取');
}
}
public function index() {
exit('module api');
}
/**
* 阅读数统计
*/
public function hits() {
$id = (int)\Phpcmf\Service::L('input')->get('id');
if (!$id) {
$this->_jsonp(0, dr_lang('阅读统计: id参数不完整'));
}
$rt = $this->content_model->update_hits($id, (int)\Phpcmf\Service::L('input')->get('qx'));
if (isset($_GET['format']) && $_GET['format'] == 'json') {
$this->_json($rt['code'], $rt['msg'], $rt['data']);
} else {
$this->_jsonp($rt['code'], $rt['msg'], $rt['data']);
}
}
/**
* 收藏模块内容
*/
public function favorite() {
if (!dr_is_app('favorite')) {
$this->_json(0, dr_lang('应用[模块内容收藏]未安装'));
}
$rt = \Phpcmf\Service::M('op', 'favorite')->run($this->tablename, $this->dirname);
$this->_json($rt['code'], $rt['msg'], $rt['data']);
}
/**
* 是否收藏模块内容
*/
public function is_favorite() {
if (!dr_is_app('favorite')) {
$this->_json(0, dr_lang('应用[模块内容收藏]未安装'));
}
$rt = \Phpcmf\Service::M('op', 'favorite')->is_favorite($this->tablename, $this->dirname);
$this->_json($rt['code'], $rt['msg'], $rt['data']);
}
/**
* 模块内容支持与反对
*/
public function digg() {
if (!dr_is_app('zan')) {
$this->_json(0, dr_lang('应用[模块内容点赞]未安装'));
}
$rt = \Phpcmf\Service::M('op', 'zan')->run($this->tablename, $this->dirname);
$this->_json($rt['code'], $rt['msg'], $rt['data']);
}
}
+45
View File
@@ -0,0 +1,45 @@
<?php namespace Phpcmf\Control\Api;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
// 快捷登录接口
class Oauth extends \Phpcmf\Common
{
/**
* 快捷登录
*/
public function index() {
$name = dr_safe_filename(\Phpcmf\Service::L('input')->get('name'));
$type = dr_safe_replace(\Phpcmf\Service::L('input')->get('type'));
$back = dr_safe_replace(\Phpcmf\Service::L('input')->get('back'));
$action = dr_safe_replace(\Phpcmf\Service::L('input')->get('action'));
// 非授权登录时必须验证登录状态
if ($type != 'login' && !$this->uid) {
$this->_msg(0, dr_lang('你还没有登录'));
} elseif (!$name) {
$this->_msg(0, dr_lang('未知接入商'));
}
// 请求参数
$appid = $this->member_cache['oauth'][$name]['id'];
$appkey = $this->member_cache['oauth'][$name]['value'];
$callback_url = OAUTH_URL.'index.php?s=api&c=oauth&m=index&action=callback&name='.$name.'&type='.$type;
if ($back) {
$callback_url.= '&back='.urlencode(dr_redirect_safe_check($back));
}
$file = FCPATH.'ThirdParty/OAuth/'.ucfirst($name).'/Run.php';
if (is_file($file)) {
require $file;
} else {
$this->_msg(0, IS_DEV ? dr_lang('没有找到接入商(%s)执行程序', $file) : dr_lang('没有找到接入商的执行程序'));
}
}
}
+20
View File
@@ -0,0 +1,20 @@
<?php namespace Phpcmf\Control\Api;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
$file = dr_get_app_dir('pay').'Controllers/Home.php';
if (is_file($file)) {
require_once $file;
} else {
\dr_exit_msg(0, '没有安装「支付系统」插件');
}
// 付款
class Pay extends \Phpcmf\Controllers\Home
{
}
+54
View File
@@ -0,0 +1,54 @@
<?php namespace Phpcmf\Control\Api;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
// 系统默认伪静态处理
class Rewrite extends \Phpcmf\Common
{
// test
public function test() {
$this->_jsonp(1, '服务器支持伪静态功能,可以自定义URL规则和解析规则了');
}
/**
* 跳转地址
*/
public function url() {
$url = urldecode(\Phpcmf\Service::L('input')->get('url'));
$arr = [ 0 => [], 1 => []];
for ($i = 1 ; $i < 10; $i ++) {
$arr[0][] = urldecode(\Phpcmf\Service::L('input')->get('p'.$i));
$arr[1][] = '$'.$i;
}
dr_redirect(dr_url_prefix(str_replace($arr[1], $arr[0], $url)), 'location', '301');
}
public function license() {
$license = \Phpcmf\Service::R(MYPATH.'Config/License.php');
if (isset($license['oem']) && $license['oem']) {
echo $license['name'].' '.$license['cms'].''.$license['type'].' V'.$this->cmf_version['version'] . ' <span style="display: none">'.$license['license'].'</span>';exit;
}
echo 'XunRuiCMS V'.$this->cmf_version['version'].'<hr>';
if (is_file(WEBPATH.'LICENSE')) {
$file = WEBPATH.'LICENSE';
} elseif (is_file(ROOTPATH.'LICENSE')) {
$file = ROOTPATH.'LICENSE';
} elseif (is_file(dirname(WEBPATH).'/LICENSE')) {
$file = dirname(WEBPATH).'/LICENSE';
} else {
exit('<font color="red">LICENSE许可证文件不存在,请遵守迅睿MIT开源协议</font>');
}
echo nl2br((string)file_get_contents($file));
exit;
}
}
+243
View File
@@ -0,0 +1,243 @@
<?php namespace Phpcmf\Control\Api;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
/**
* 运行任务接口
*/
class Run extends \Phpcmf\Common
{
/**
* 初始化
*/
public function __construct($object = NULL)
{
parent::__construct();
if ($object) {
foreach ($object as $var => $value) {
$this->$var = $value;
}
}
}
public function index() {
// 验证运行权限
if (!IS_DEV) {
if (defined('SYS_CRON_AUTH') && SYS_CRON_AUTH) {
if (is_cli()) {
// cli模式
} else {
// url模式
if (SYS_CRON_AUTH == 'cli') {
exit('限制CLI模式执行任务');
}
$ip = \Phpcmf\Service::L('input')->ip_address();
if (!$ip) {
if (CI_DEBUG) {
log_message('error', '任务执行失败:无法获取执行客户端的IP地址');
}
exit('无权限执行任务');
return;
}
if (SYS_CRON_AUTH != $ip) {
if (CI_DEBUG) {
log_message('error', '任务执行失败:后台设置的服务端ip('.SYS_CRON_AUTH.')与客户端ip'.$ip.')不一致');
}
exit('限制固定IP执行任务');
return;
}
}
}
$run_time = 0;// 上次执行的时间
if (is_file(WRITEPATH.'config/cron_run_time.php')) {
$run_time = file_get_contents(WRITEPATH.'config/cron_run_time.php');
if ($run_time && SYS_TIME - $run_time < 100) {
exit('未到任务执行时间');
}
} else {
file_put_contents(WRITEPATH.'config/cron_run_time.php', SYS_TIME);
}
$fp = fopen ( WRITEPATH.'config/cron_run_time.php' , "r" );
//加锁
if ( flock ( $fp ,LOCK_EX | LOCK_NB)) {
// 写入新的时间
file_put_contents(WRITEPATH.'config/cron_run_time.php', SYS_TIME);
} else {
fclose( $fp );
exit('任务正在执行中');
}
if (isset($_GET['is_ajax'])) {
// 后台脚本自动任务时
} else {
// 服务器自动任务时
// 自动任务锁定
if (!is_file(WRITEPATH.'config/run_lock.php')) {
file_put_contents(WRITEPATH.'config/run_lock.php', 'true');
}
}
} else {
$fp = false;
}
// 批量执行站点动作
foreach ($this->site_info as $siteid => $site) {
// 删除网站首页
if ($site['SITE_INDEX_HTML']) {
$time = (isset($site['SITE_INDEX_TIME']) && $site['SITE_INDEX_TIME'] ? $site['SITE_INDEX_TIME'] : 10) * 3600;
foreach ([
\Phpcmf\Service::L('html')->get_webpath($siteid,'site', 'index.html'),
\Phpcmf\Service::L('html')->get_webpath($siteid,'site', 'mobile/index.html'),
] as $file) {
$ft = filemtime($file);
if ($ft && SYS_TIME - $ft > $time) {
unlink($file);
}
}
}
}
// 执行队列
$i = \Phpcmf\Service::M('cron')->run_cron(intval($_GET['num']));
// 最少100秒调用本程序
//\Phpcmf\Service::L('input')->set_cookie('cron', 1, 100);
// 定义后台执行任务的时效
//\Phpcmf\Service::L('input')->set_cookie('admin_cron', 1, 600);
// 任务计划
\Phpcmf\Hooks::trigger('cron');
// 清理缓存数据
if (!is_file(WRITEPATH.'config/run_auto_cache_time.php')) {
$time = SYS_TIME;
file_put_contents(WRITEPATH.'config/run_auto_cache_time.php', $time);
} else {
$time = file_get_contents(WRITEPATH.'config/run_auto_cache_time.php');
}
// 多少天清理一次系统缓存
$day = max(3, SYS_CACHE_CRON);
if (SYS_TIME - $time > 3600 * 24 * $day) {
// 缓存清理
\Phpcmf\Service::M('cache')->update_data_cache(true);
file_put_contents(WRITEPATH.'config/run_auto_cache_time.php', SYS_TIME);
// 清理日志
$map = dr_file_map(WRITEPATH.'error/');
if ($map) {
foreach ($map as $file) {
if (strpos($file, 'log-') !== false) {
$file = WRITEPATH.'error/'.$file;
$time = filectime($file);
if ($time && SYS_TIME - $time > 3600 * 24 * 30) {
@unlink($file);
}
}
}
}
}
// 项目计划
if (is_file(MYPATH.'Config/Cron.php')) {
require MYPATH.'Config/Cron.php';
}
// 为插件单独执行计划
$local = \Phpcmf\Service::Apps();
if ($local) {
foreach ($local as $dir => $path) {
if (is_file($path.'Config/Cron.php')
&& is_file($path.'Config/App.php')
&& is_file($path.'install.lock')) {
require $path.'Config/Cron.php';
}
}
}
// 自动任务执行时间
file_put_contents(WRITEPATH.'config/run_time.php', dr_date(SYS_TIME));
if ($fp) {
flock ( $fp ,LOCK_UN);
fclose( $fp );
}
exit('任务执行成功:Run '.($i ? $i : 'Ok'));
}
/**
* 线程任务接口
*/
public function cron() {
$file = WRITEPATH.'thread/'.dr_safe_filename(\Phpcmf\Service::L('input')->get('auth')).'.auth';
if (!is_file($file)) {
//log_message('error', '线程任务auth文件不存在:'.dr_now_url());
exit('线程任务auth文件不存在'.$file);
}
$time = (int)file_get_contents($file);
unlink($file);
if (SYS_TIME - $time > 500) {
// 500秒外无效
log_message('error', '线程任务auth过期:'.dr_now_url());
exit('线程任务auth过期');
}
switch (\Phpcmf\Service::L('input')->get('action')) {
case 'oauth_down_avatar': // 快捷登录下载头像
$id = intval(\Phpcmf\Service::L('input')->get('id'));
$oauth = \Phpcmf\Service::M()->table('member_oauth')->get($id);
if (!$oauth) {
exit('oauth不存在');
} elseif (!$oauth['uid']) {
exit('oauth没有绑定账号');
}
list($cache_path) = dr_avatar_path();
$path = $cache_path.dr_avatar_dir($oauth['uid']);
$file = $path.$oauth['uid'].'.jpg';
if (is_file($file)) {
\Phpcmf\Service::M()->db->table('member_data')->where('id', $oauth['uid'])->update(['is_avatar' => 1]);
exit('头像已经存在');
}
$avatar = dr_catcher_data($oauth['avatar']);
if ($avatar) {
if (!is_dir($path)) {
dr_mkdirs($path);
}
if (file_put_contents($file, $avatar)) {
\Phpcmf\Service::M()->db->table('member_data')->where('id', $oauth['uid'])->update(['is_avatar' => 1]);
}
}
break;
case 'cron': // 队列任务
$id = intval(\Phpcmf\Service::L('input')->get('id'));
$rt = \Phpcmf\Service::M('cron')->do_cron_id($id);
if (!$rt['code']) {
log_message('debug', '任务执行失败('.$rt['msg'].'):'.$rt['data']['value']);
exit('任务执行失败('.$rt['msg'].'');
}
break;
}
exit('ok');
}
}
+115
View File
@@ -0,0 +1,115 @@
<?php namespace Phpcmf\Control\Api;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
// 同步登陆接口
class Sso extends \Phpcmf\Common {
public function index() {
switch (\Phpcmf\Service::L('input')->get('action')) {
case 'logout': // 前台退出登录
header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
\Phpcmf\Service::L('input')->set_cookie('member_uid', 0, -30000);
\Phpcmf\Service::L('input')->set_cookie('admin_login_member', 0, -30000);
\Phpcmf\Service::L('input')->set_cookie('member_cookie', 0, -30000);
break;
case 'login': // 前台同步登录
$code = dr_authcode(\Phpcmf\Service::L('input')->get('code'), 'DECODE');
if (!$code) {
$this->_jsonp(0, '解密失败');
}
list($uid, $salt) = explode('-', $code);
if (!$uid || !$salt) {
$this->_jsonp(0, '格式错误');
}
$member = \Phpcmf\Service::M()->db->table('member')->where('id', $uid)->get()->getRowArray();
if (!$member) {
$this->_jsonp(0, '账号不存在');
} elseif ($salt != $member['salt']) {
$this->_jsonp(0, '账号验证失败');
}
header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
\Phpcmf\Service::M('member')->save_cookie($member, \Phpcmf\Service::L('input')->get('remember'));
break;
case 'alogin': // 后台登录授权
$code = dr_authcode(\Phpcmf\Service::L('input')->get('code'), 'DECODE');
if (!$code) {
$this->_jsonp(0, '解密失败');
}
list($uid, $password) = explode('-', $code);
$admin = \Phpcmf\Service::L('cache')->get_data('admin_login_member');
if (!$admin) {
$this->_jsonp(0, '缓存失败');
} elseif ($password != md5($admin['id'].$admin['password'])) {
$this->_jsonp(0, '验证失败');
}
// 存储状态
header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
\Phpcmf\Service::L('input')->set_cookie('admin_login_member', $uid.'-'.$admin['id'], 3600);
$this->session()->set('admin_login_member_code', md5($uid.$admin['id'].$admin['password']));
break;
case 'slogin': // 后台登录其他站点
exit('功能废弃');
break;
}
return $this->_jsonp(1, 'ok', [], true);
}
public function login() {
if (!IS_USE_MEMBER) {
$this->_json(0, '没有安装用户系统插件');
}
require IS_USE_MEMBER.'Controllers/Login.php';
$ci = new \Phpcmf\Controllers\Login($this);
$ci->index();
}
public function sms() {
if (!IS_USE_MEMBER) {
$this->_json(0, '没有安装用户系统插件');
}
require IS_USE_MEMBER.'Controllers/Login.php';
$ci = new \Phpcmf\Controllers\Login($this);
$ci->sms();
}
public function oauth() {
if (!IS_USE_MEMBER) {
$this->_json(0, '没有安装用户系统插件');
}
require IS_USE_MEMBER.'Controllers/Login.php';
$ci = new \Phpcmf\Controllers\Login($this);
$ci->oauth();
}
public function register() {
if (!IS_USE_MEMBER) {
$this->_json(0, '没有安装用户系统插件');
}
require IS_USE_MEMBER.'Controllers/Register.php';
$ci = new \Phpcmf\Controllers\Register($this);
$ci->index();
}
}
+40
View File
@@ -0,0 +1,40 @@
<?php namespace Phpcmf\Control\Api;
/**
* https://www.besyun.com
* BESCMS
* 本文件是框架系统文件,二次开发时不可以修改本文件
**/
// 测试信息
class Test extends \Phpcmf\Common
{
// test
public function https() {
echo 'xunruicms';
}
public function index() {
$license = \Phpcmf\Service::R(MYPATH.'Config/License.php');
if (isset($license['oem']) && $license['oem']) {
echo $license['name'].' '.$license['cms'].' V'.$this->cmf_version['version'] . ' <span style="display: none">'.$license['license'].'</span>';exit;
}
echo 'XunRuiCMS V'.$this->cmf_version['version'].'<hr>';
if (is_file(WEBPATH.'LICENSE')) {
$file = WEBPATH.'LICENSE';
} elseif (is_file(ROOTPATH.'LICENSE')) {
$file = ROOTPATH.'LICENSE';
} elseif (is_file(dirname(WEBPATH).'/LICENSE')) {
$file = dirname(WEBPATH).'/LICENSE';
} else {
exit('<font color="red">LICENSE许可证文件不存在,请遵守迅睿MIT开源协议</font>');
}
echo nl2br((string)file_get_contents($file));
exit;
}
}