框架升级及修复升级后的bug

This commit is contained in:
Dev
2026-10-16 18:13:09 +08:00
parent dafb0c96c0
commit 2d342bcbd7
537 changed files with 49836 additions and 40933 deletions
@@ -0,0 +1,21 @@
<?php
namespace think\addons;
use think\Exception;
/**
* 插件异常处理类
* @package think\addons
*/
class AddonException extends Exception
{
public function __construct($message, $code = 0, $data = '')
{
$this->message = $message;
$this->code = $code;
$this->data = $data;
}
}
@@ -0,0 +1,220 @@
<?php
// +----------------------------------------------------------------------
// | thinkphp5 Addons [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.zzstudio.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Byron Sampson <xiaobo.sun@qq.com>
// +----------------------------------------------------------------------
namespace think\addons;
use app\common\library\Auth;
use think\Config;
use think\Hook;
use think\Lang;
use think\Loader;
use think\Request;
use think\Validate;
/**
* 插件基类控制器
* @package think\addons
*/
class Controller extends \think\Controller
{
// 当前插件操作
protected $addon = null;
protected $controller = null;
protected $action = null;
// 当前template
protected $template;
/**
* 无需登录的方法,同时也就不需要鉴权了
* @var array
*/
protected $noNeedLogin = ['*'];
/**
* 无需鉴权的方法,但需要登录
* @var array
*/
protected $noNeedRight = ['*'];
/**
* 权限Auth
* @var Auth
*/
protected $auth = null;
/**
* 布局模板
* @var string
*/
protected $layout = null;
/**
* 架构函数
* @param Request $request Request对象
* @access public
*/
public function __construct(?Request $request = null)
{
if (is_null($request)) {
$request = Request::instance();
}
// 生成request对象
$this->request = $request;
//移除HTML标签
$this->request->filter('trim,strip_tags,htmlspecialchars');
// 是否自动转换控制器和操作名
$convert = Config::get('url_convert');
$filter = $convert ? 'strtolower' : 'trim';
// 处理路由参数
$param = $this->request->param();
$dispatch = $this->request->dispatch();
$var = isset($dispatch['var']) ? $dispatch['var'] : [];
$var = array_merge($param, $var);
if (isset($dispatch['method']) && substr($dispatch['method'][0], 0, 7) == "\\addons") {
$arr = explode("\\", $dispatch['method'][0]);
$addon = strtolower($arr[2]);
$controller = strtolower(end($arr));
$action = $dispatch['method'][1];
} else {
$addon = isset($var['addon']) ? $var['addon'] : '';
$controller = isset($var['controller']) ? $var['controller'] : '';
$action = isset($var['action']) ? $var['action'] : '';
}
$this->addon = $addon ? call_user_func($filter, $addon) : '';
$this->controller = $controller ? call_user_func($filter, $controller) : 'index';
$this->action = $action ? call_user_func($filter, $action) : 'index';
// 重置配置
Config::set('template.view_path', ADDON_PATH . $this->addon . DS . 'view' . DS);
// 父类的调用必须放在设置模板路径之后
parent::__construct($this->request);
}
protected function _initialize()
{
// 检测IP是否允许
if (function_exists("check_ip_allowed")) {
check_ip_allowed();
}
// 渲染配置到视图中
$config = get_addon_config($this->addon);
$this->view->assign("config", $config);
$lang = $this->request->langset();
$lang = preg_match("/^([a-zA-Z\-_]{2,10})\$/i", $lang) ? $lang : 'zh-cn';
// 加载系统语言包
Lang::load([
ADDON_PATH . $this->addon . DS . 'lang' . DS . $lang . EXT,
]);
// 设置替换字符串
$cdnurl = Config::get('site.cdnurl');
$this->view->replace('__ADDON__', $cdnurl . "/assets/addons/" . $this->addon);
$this->auth = Auth::instance();
// token
$token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token')));
$path = 'addons/' . $this->addon . '/' . str_replace('.', '/', $this->controller) . '/' . $this->action;
// 设置当前请求的URI
$this->auth->setRequestUri($path);
// 检测是否需要验证登录
if (!$this->auth->match($this->noNeedLogin)) {
//初始化
$this->auth->init($token);
//检测是否登录
if (!$this->auth->isLogin()) {
$this->error(__('Please login first'), 'index/user/login');
}
// 判断是否需要验证权限
if (!$this->auth->match($this->noNeedRight)) {
// 判断控制器和方法判断是否有对应权限
if (!$this->auth->check($path)) {
$this->error(__('You have no permission'));
}
}
} else {
// 如果有传递token才验证是否登录状态
if ($token) {
$this->auth->init($token);
}
}
// 如果有使用模板布局
if ($this->layout) {
$this->view->engine->layout('layout/' . $this->layout);
}
$this->view->assign('user', $this->auth->getUser());
$site = Config::get("site");
$upload = \app\common\model\Config::upload();
// 上传信息配置后
Hook::listen("upload_config_init", $upload);
Config::set('upload', array_merge(Config::get('upload'), $upload));
// 加载当前控制器语言包
$this->assign('site', $site);
}
/**
* 加载模板输出
* @access protected
* @param string $template 模板文件名
* @param array $vars 模板输出变量
* @param array $replace 模板替换
* @param array $config 模板参数
* @return mixed
*/
protected function fetch($template = '', $vars = [], $replace = [], $config = [])
{
$controller = Loader::parseName($this->controller);
if ('think' == strtolower(Config::get('template.type')) && $controller && 0 !== strpos($template, '/')) {
$depr = Config::get('template.view_depr');
$template = str_replace(['/', ':'], $depr, $template);
if ('' == $template) {
// 如果模板文件名为空 按照默认规则定位
$template = str_replace('.', DS, $controller) . $depr . $this->action;
} elseif (false === strpos($template, $depr)) {
$template = str_replace('.', DS, $controller) . $depr . $template;
}
}
return parent::fetch($template, $vars, $replace, $config);
}
/**
* 刷新Token
*/
protected function token()
{
$token = $this->request->param('__token__');
//验证Token
if (!Validate::make()->check(['__token__' => $token], ['__token__' => 'require|token'])) {
$this->error(__('Token verification error'), '', ['__token__' => $this->request->token()]);
}
//刷新Token
$this->request->token();
}
}
@@ -0,0 +1,94 @@
<?php
// +----------------------------------------------------------------------
// | thinkphp5 Addons [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.zzstudio.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Byron Sampson <xiaobo.sun@qq.com>
// +----------------------------------------------------------------------
namespace think\addons;
use think\Config;
use think\exception\HttpException;
use think\exception\HttpResponseException;
use think\Hook;
use think\Loader;
use think\Request;
use think\Response;
/**
* 插件执行默认控制器
* @package think\addons
*/
class Route
{
/**
* 插件执行
*/
public function execute($addon = null, $controller = null, $action = null)
{
$request = Request::instance();
// 是否自动转换控制器和操作名
$convert = Config::get('url_convert');
$filter = $convert ? 'strtolower' : 'trim';
$addon = $addon ? trim(call_user_func($filter, $addon)) : '';
$controller = $controller ? trim(call_user_func($filter, $controller)) : 'index';
$action = $action ? trim(call_user_func($filter, $action)) : 'index';
Hook::listen('addon_begin', $request);
if (!empty($addon) && !empty($controller) && !empty($action)) {
$info = get_addon_info($addon);
if (!$info) {
throw new HttpException(404, __('addon %s not found', $addon));
}
if (!$info['state']) {
throw new HttpException(500, __('addon %s is disabled', $addon));
}
$dispatch = $request->dispatch();
if (isset($dispatch['var']) && $dispatch['var']) {
$request->route(array_diff_key($dispatch['var'], array_flip(['addon', 'controller', 'action'])));
}
// 设置当前请求的控制器、操作
$request->controller($controller)->action($action);
// 监听addon_module_init
Hook::listen('addon_module_init', $request);
// 兼容旧版本行为,即将移除,不建议使用
Hook::listen('addons_init', $request);
$class = get_addon_class($addon, 'controller', $controller);
if (!$class) {
throw new HttpException(404, __('addon controller %s not found', Loader::parseName($controller, 1)));
}
$instance = new $class($request);
$vars = [];
if (is_callable([$instance, $action])) {
// 执行操作方法
$call = [$instance, $action];
} elseif (is_callable([$instance, '_empty'])) {
// 空操作
$call = [$instance, '_empty'];
$vars = [$action];
} else {
// 操作不存在
throw new HttpException(404, __('addon action %s not found', get_class($instance) . '->' . $action . '()'));
}
Hook::listen('addon_action_begin', $call);
return call_user_func_array($call, $vars);
} else {
abort(500, lang('addon can not be empty'));
}
}
}
File diff suppressed because it is too large Load Diff