添加网站文件

This commit is contained in:
2025-12-22 13:59:40 +08:00
commit 117aaf83d1
19468 changed files with 2111999 additions and 0 deletions

View File

@@ -0,0 +1,148 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\response;
use think\Exception;
use think\Response;
class Download extends Response
{
protected $expire = 360;
protected $name;
protected $mimeType;
protected $isContent = false;
protected $openinBrowser = false;
/**
* 处理数据
* @access protected
* @param mixed $data 要处理的数据
* @return mixed
* @throws \Exception
*/
protected function output($data)
{
if (!$this->isContent && !is_file($data)) {
throw new Exception('file not exists:' . $data);
}
ob_end_clean();
if (!empty($this->name)) {
$name = $this->name;
} else {
$name = !$this->isContent ? pathinfo($data, PATHINFO_BASENAME) : '';
}
if ($this->isContent) {
$mimeType = $this->mimeType;
$size = strlen($data);
} else {
$mimeType = $this->getMimeType($data);
$size = filesize($data);
}
$this->header['Pragma'] = 'public';
$this->header['Content-Type'] = $mimeType ?: 'application/octet-stream';
$this->header['Cache-control'] = 'max-age=' . $this->expire;
$this->header['Content-Disposition'] = $this->openinBrowser ? 'inline' : 'attachment; filename="' . $name . '"';
$this->header['Content-Length'] = $size;
$this->header['Content-Transfer-Encoding'] = 'binary';
$this->header['Expires'] = gmdate("D, d M Y H:i:s", time() + $this->expire) . ' GMT';
$this->lastModified(gmdate('D, d M Y H:i:s', time()) . ' GMT');
$data = $this->isContent ? $data : file_get_contents($data);
return $data;
}
/**
* 设置是否为内容 必须配合mimeType方法使用
* @access public
* @param bool $content
* @return $this
*/
public function isContent($content = true)
{
$this->isContent = $content;
return $this;
}
/**
* 设置有效期
* @access public
* @param integer $expire 有效期
* @return $this
*/
public function expire($expire)
{
$this->expire = $expire;
return $this;
}
/**
* 设置文件类型
* @access public
* @param string $filename 文件名
* @return $this
*/
public function mimeType($mimeType)
{
$this->mimeType = $mimeType;
return $this;
}
/**
* 获取文件类型信息
* @access public
* @param string $filename 文件名
* @return string
*/
protected function getMimeType($filename)
{
if (!empty($this->mimeType)) {
return $this->mimeType;
}
$finfo = finfo_open(FILEINFO_MIME_TYPE);
return finfo_file($finfo, $filename);
}
/**
* 设置下载文件的显示名称
* @access public
* @param string $filename 文件名
* @param bool $extension 后缀自动识别
* @return $this
*/
public function name($filename, $extension = true)
{
$this->name = $filename;
if ($extension && false === strpos($filename, '.')) {
$this->name .= '.' . pathinfo($this->data, PATHINFO_EXTENSION);
}
return $this;
}
/**
* 设置是否在浏览器中显示文件
* @access public
* @param bool $openinBrowser 是否在浏览器中显示文件
* @return $this
*/
public function openinBrowser($openinBrowser) {
$this->openinBrowser = $openinBrowser;
return $this;
}
}

View File

@@ -0,0 +1,51 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\response;
use think\Response;
class Json extends Response
{
// 输出参数
protected $options = [
'json_encode_param' => JSON_UNESCAPED_UNICODE,
];
protected $contentType = 'application/json';
/**
* 处理数据
* @access protected
* @param mixed $data 要处理的数据
* @return mixed
* @throws \Exception
*/
protected function output($data)
{
try {
// 返回JSON数据格式到客户端 包含状态信息
$data = json_encode($data, $this->options['json_encode_param']);
if (false === $data) {
throw new \InvalidArgumentException(json_last_error_msg());
}
return $data;
} catch (\Exception $e) {
if ($e->getPrevious()) {
throw $e->getPrevious();
}
throw $e;
}
}
}

View File

@@ -0,0 +1,58 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\response;
use think\Response;
class Jsonp extends Response
{
// 输出参数
protected $options = [
'var_jsonp_handler' => 'callback',
'default_jsonp_handler' => 'jsonpReturn',
'json_encode_param' => JSON_UNESCAPED_UNICODE,
];
protected $contentType = 'application/javascript';
/**
* 处理数据
* @access protected
* @param mixed $data 要处理的数据
* @return mixed
* @throws \Exception
*/
protected function output($data)
{
try {
// 返回JSON数据格式到客户端 包含状态信息 [当url_common_param为false时是无法获取到$_GET的数据的故使用Request来获取<xiaobo.sun@qq.com>]
$var_jsonp_handler = $this->app['request']->param($this->options['var_jsonp_handler'], "");
$handler = !empty($var_jsonp_handler) ? $var_jsonp_handler : $this->options['default_jsonp_handler'];
$data = json_encode($data, $this->options['json_encode_param']);
if (false === $data) {
throw new \InvalidArgumentException(json_last_error_msg());
}
$data = $handler . '(' . $data . ');';
return $data;
} catch (\Exception $e) {
if ($e->getPrevious()) {
throw $e->getPrevious();
}
throw $e;
}
}
}

View File

@@ -0,0 +1,32 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\response;
use think\Response;
class Jump extends Response
{
protected $contentType = 'text/html';
/**
* 处理数据
* @access protected
* @param mixed $data 要处理的数据
* @return mixed
* @throws \Exception
*/
protected function output($data)
{
$data = $this->app['view']->fetch($this->options['jump_template'], $data);
return $data;
}
}

View File

@@ -0,0 +1,119 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\response;
use think\Response;
class Redirect extends Response
{
protected $options = [];
// URL参数
protected $params = [];
public function __construct($data = '', $code = 302, array $header = [], array $options = [])
{
parent::__construct($data, $code, $header, $options);
$this->cacheControl('no-cache,must-revalidate');
}
/**
* 处理数据
* @access protected
* @param mixed $data 要处理的数据
* @return mixed
*/
protected function output($data)
{
$this->header['Location'] = $this->getTargetUrl();
return;
}
/**
* 重定向传值通过Session
* @access protected
* @param string|array $name 变量名或者数组
* @param mixed $value 值
* @return $this
*/
public function with($name, $value = null)
{
$session = $this->app['session'];
if (is_array($name)) {
foreach ($name as $key => $val) {
$session->flash($key, $val);
}
} else {
$session->flash($name, $value);
}
return $this;
}
/**
* 获取跳转地址
* @access public
* @return string
*/
public function getTargetUrl()
{
if (strpos($this->data, '://') || (0 === strpos($this->data, '/') && empty($this->params))) {
return $this->data;
} else {
return $this->app['url']->build($this->data, $this->params);
}
}
public function params($params = [])
{
$this->params = $params;
return $this;
}
/**
* 记住当前url后跳转
* @access public
* @param string $url 指定记住的url
* @return $this
*/
public function remember($url = null)
{
$this->app['session']->set('redirect_url', $url ?: $this->app['request']->url());
return $this;
}
/**
* 跳转到上次记住的url
* @access public
* @param string $url 闪存数据不存在时的跳转地址
* @return $this
*/
public function restore($url = null)
{
$session = $this->app['session'];
if ($session->has('redirect_url')) {
$this->data = $session->get('redirect_url');
$session->delete('redirect_url');
} elseif ($url) {
$this->data = $url;
}
return $this;
}
}

View File

@@ -0,0 +1,119 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\response;
use think\Response;
class View extends Response
{
// 输出参数
protected $options = [];
protected $vars = [];
protected $config = [];
protected $filter;
protected $contentType = 'text/html';
/**
* 是否内容渲染
* @var bool
*/
protected $isContent = false;
/**
* 处理数据
* @access protected
* @param mixed $data 要处理的数据
* @return mixed
*/
protected function output($data)
{
// 渲染模板输出
return $this->app['view']
->filter($this->filter)
->fetch($data, $this->vars, $this->config, $this->isContent);
}
/**
* 设置是否为内容渲染
* @access public
* @param bool $content
* @return $this
*/
public function isContent($content = true)
{
$this->isContent = $content;
return $this;
}
/**
* 获取视图变量
* @access public
* @param string $name 模板变量
* @return mixed
*/
public function getVars($name = null)
{
if (is_null($name)) {
return $this->vars;
} else {
return isset($this->vars[$name]) ? $this->vars[$name] : null;
}
}
/**
* 模板变量赋值
* @access public
* @param mixed $name 变量名
* @param mixed $value 变量值
* @return $this
*/
public function assign($name, $value = '')
{
if (is_array($name)) {
$this->vars = array_merge($this->vars, $name);
} else {
$this->vars[$name] = $value;
}
return $this;
}
public function config($config)
{
$this->config = $config;
return $this;
}
/**
* 视图内容过滤
* @access public
* @param callable $filter
* @return $this
*/
public function filter($filter)
{
$this->filter = $filter;
return $this;
}
/**
* 检查模板是否存在
* @access private
* @param string|array $name 参数名
* @return bool
*/
public function exists($name)
{
return $this->app['view']->exists($name);
}
}

View File

@@ -0,0 +1,116 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace think\response;
use think\Collection;
use think\Model;
use think\Response;
class Xml extends Response
{
// 输出参数
protected $options = [
// 根节点名
'root_node' => 'think',
// 根节点属性
'root_attr' => '',
//数字索引的子节点名
'item_node' => 'item',
// 数字索引子节点key转换的属性名
'item_key' => 'id',
// 数据编码
'encoding' => 'utf-8',
];
protected $contentType = 'text/xml';
/**
* 处理数据
* @access protected
* @param mixed $data 要处理的数据
* @return mixed
*/
protected function output($data)
{
if (is_string($data)) {
if (0 !== strpos($data, '<?xml')) {
$encoding = $this->options['encoding'];
$xml = "<?xml version=\"1.0\" encoding=\"{$encoding}\"?>";
$data = $xml . $data;
}
return $data;
}
// XML数据转换
return $this->xmlEncode($data, $this->options['root_node'], $this->options['item_node'], $this->options['root_attr'], $this->options['item_key'], $this->options['encoding']);
}
/**
* XML编码
* @access protected
* @param mixed $data 数据
* @param string $root 根节点名
* @param string $item 数字索引的子节点名
* @param string $attr 根节点属性
* @param string $id 数字索引子节点key转换的属性名
* @param string $encoding 数据编码
* @return string
*/
protected function xmlEncode($data, $root, $item, $attr, $id, $encoding)
{
if (is_array($attr)) {
$array = [];
foreach ($attr as $key => $value) {
$array[] = "{$key}=\"{$value}\"";
}
$attr = implode(' ', $array);
}
$attr = trim($attr);
$attr = empty($attr) ? '' : " {$attr}";
$xml = "<?xml version=\"1.0\" encoding=\"{$encoding}\"?>";
$xml .= "<{$root}{$attr}>";
$xml .= $this->dataToXml($data, $item, $id);
$xml .= "</{$root}>";
return $xml;
}
/**
* 数据XML编码
* @access protected
* @param mixed $data 数据
* @param string $item 数字索引时的节点名称
* @param string $id 数字索引key转换为的属性名
* @return string
*/
protected function dataToXml($data, $item, $id)
{
$xml = $attr = '';
if ($data instanceof Collection || $data instanceof Model) {
$data = $data->toArray();
}
foreach ($data as $key => $val) {
if (is_numeric($key)) {
$id && $attr = " {$id}=\"{$key}\"";
$key = $item;
}
$xml .= "<{$key}{$attr}>";
$xml .= (is_array($val) || is_object($val)) ? $this->dataToXml($val, $item, $id) : $val;
$xml .= "</{$key}>";
}
return $xml;
}
}