开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
捐赠
捐赠前请先登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
1 Star 1 Fork 0

楚羽幽/小白插件

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
main
分支 (1)
标签 (5)
main
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
main
分支 (1)
标签 (5)
main
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
main
分支 (1)
标签 (5)
main
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
plugins
/
src
/
utils
/
helpers.php
plugins
/
src
/
utils
/
helpers.php
helpers.php 7.34 KB
一键复制 编辑 原始数据 按行查看 历史
楚羽幽 提交于 2023年10月09日 18:11 +08:00 . 解决静态资源访问速度,增加zip打包
<?php
declare(strict_types=1);
use think\helper\{
Str, Arr
};
if (!function_exists('getPluginName')) {
/**
* 获取当前请求的插件名称
* @return string|null
* @author 贵州猿创科技有限公司
* @copyright 贵州猿创科技有限公司
* @email 416716328@qq.com
*/
function getPluginName()
{
$request = request();
$pathInfo = $request->pathinfo();
// 检测字符串中是否带有app/字符串
if (strpos($pathInfo, 'app/') === false) {
return '';
}
$response = explode('/',$pathInfo);
if (count($response) < 2) {
return '';
}
return isset($response[1]) ? $response[1] : '';
}
}
if (!function_exists('getPluginConfig')) {
/**
* 获取插件配置
* @param mixed $name
* @param mixed $default
* @return array
* @author John
*/
function getPluginConfig($name,$default = null)
{
$pluginName = getPluginName();
if (empty($pluginName)) {
return $default;
}
$pluginPath = getPluginPath($pluginName, '');
if (empty($pluginPath)) {
return $default;
}
$configPath = "{$pluginPath}/config";
// 加载配置
\think\facade\Config::load("{$configPath}/{$name}.php",$name);
// 读取配置
$config = config($name,$default);
return $config;
}
}
if (!function_exists('getPluginPath')) {
/**
* 获取插件路径
* @param mixed $name
* @param mixed $default
* @return mixed
* @author John
*/
function getPluginPath($name,$default = null)
{
$app = app();
$rootPath = $app->getRootPath();
$pluginPath = "{$rootPath}plugin/{$name}/";
if (!is_dir($pluginPath)) {
return $default;
}
return $pluginPath;
}
}
if (!function_exists('getPluginInfo')) {
/**
* 获取插件信息
* @param mixed $name
* @param mixed $default
* @return mixed
* @author 贵州猿创科技有限公司
* @copyright 贵州猿创科技有限公司
* @email 416716328@qq.com
*/
function getPluginInfo($name,$default = null)
{
$pluginPath = getPluginPath($name);
if (empty($pluginPath)) {
return $default;
}
$infoFile = "{$pluginPath}/info.json";
if (!is_file($infoFile)) {
return $default;
}
$info = file_get_contents($infoFile);
$info = json_decode($info,true);
return $info;
}
}
if (!function_exists('getPluginControl')) {
/**
* 获取插件类的类命名空间
* @param mixed $name
* @param mixed $class
* @param mixed $suffix
* @return string
* @author John
*/
function getPluginControl($pluginName, $class = null,$suffix = '')
{
$name = trim($pluginName);
// 处理多级控制器情况
if (!is_null($class) && strpos($class, '/')) {
$class = explode('/', $class);
$class[count($class) - 1] = Str::studly(end($class));
$class = implode('\\', $class);
} else {
$class = Str::studly(is_null($class) ? $name : $class);
$class = "controller\\{$class}";
}
$namespace = "\\plugin\\{$name}\\app\\{$class}{$suffix}";
return $namespace;
}
}
if (!function_exists('getBetween')) {
/**
* 截取指定两个字符之间内容
* @param mixed $input
* @param mixed $start
* @param mixed $end
* @return string
* @author John
*/
function getBetween($input, $start, $end)
{
$substr = substr($input, strlen($start) + strpos($input, $start), (strlen($input) - strpos($input, $end)) * (-1));
return $substr;
}
}
if (!function_exists('getAssetsCheck')) {
/**
* 检测是否存在静态资源并处理
* @param support\Request $request
* @return bool|think\Response
* @author 贵州猿创科技有限公司
* @copyright 贵州猿创科技有限公司
* @email 416716328@qq.com
*/
function getAssetsCheck(\think\Request $request)
{
$staticSuffix = config('plugins.static_suffix');
if (!is_array($staticSuffix)) {
throw new Exception("配置项plugins.static_suffix必须为数组");
}
if (empty($staticSuffix)) {
throw new Exception("配置项plugins.static_suffix不能为空");
}
# 检测是否资源文件
$extension = pathinfo($request->pathinfo(), PATHINFO_EXTENSION);
if (in_array($extension, $staticSuffix)) {
$mimeContentTypes = [
'xml' => 'application/xml,text/xml,application/x-xml',
'json' => 'application/json,text/x-json,application/jsonrequest,text/json',
'js' => 'text/javascript,application/javascript,application/x-javascript',
'css' => 'text/css',
'rss' => 'application/rss+xml',
'yaml' => 'application/x-yaml,text/yaml',
'atom' => 'application/atom+xml',
'pdf' => 'application/pdf',
'text' => 'text/plain',
'image' => 'image/png,image/jpg,image/jpeg,image/pjpeg,image/gif,image/webp,image/*',
'csv' => 'text/csv',
'html' => 'text/html,application/xhtml+xml,*/*',
'vue' => 'application/octet-stream',
'svg' => 'image/svg+xml',
];
# 检测文件媒体类型
$mimeContentType = 'text/plain';
if (isset($mimeContentTypes[$extension])) {
$mimeContentType = $mimeContentTypes[$extension];
}
# 检测是否框架GZ资源
$file = public_path().$request->pathinfo();
if (file_exists($file)) {
$content = file_get_contents($file);
return response()->code(200)->contentType($mimeContentType)->content($content);
}
# 检测是否插件资源
$pluginRoute = explode('/',$request->pathinfo());
if (isset($pluginRoute[1])) {
$plugin = $pluginRoute[1];
unset($pluginRoute[0]);
unset($pluginRoute[1]);
$pluginRoute = implode('/', $pluginRoute);
$file = root_path()."plugin/{$plugin}/public/{$pluginRoute}";
if (file_exists($file)) {
$content = file_get_contents($file);
return response()->code(200)->contentType($mimeContentType)->content($content);
}
}
# 文件资源不存在则找官方库
$file = root_path()."view/{$request->pathinfo()}.gz";
if (file_exists($file)) {
$content = file_get_contents($file);
return response()->code(200)->header([
'Content-Type' => $mimeContentType,
'Content-Encoding' => 'gzip'
])->content($content);
}
# 普通文件
$file = root_path()."view/{$request->pathinfo()}";
if (file_exists($file)) {
$content = file_get_contents($file);
return response()->code(200)->contentType($mimeContentType)->content($content);
}
}
return false;
}
}
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

使用该插件可在TP6和TP8中直接以Webman的应用插件形势做开发
暂无标签
Apache-2.0
使用 Apache-2.0 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
PHP
1
https://gitee.com/xbcode888/plugins.git
git@gitee.com:xbcode888/plugins.git
xbcode888
plugins
小白插件
main
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /