diff --git a/README.md b/README.md index ad6d6a0f7..d8e755cd7 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,8 @@ [![PHP](https://img.shields.io/badge/PHP->=5.6-orange.svg)](http://php.net) [![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/wisp-x/lsky-pro.svg)](https://github.com/wisp-x/lsky-pro) -> 下载稳定版请点击[这里](https://github.com/wisp-x/lsky-pro/releases),发现 bug 可发送邮件至邮箱:i@wispx.cn,或提交 [issues](https://github.com/wisp-x/lsky-pro/issues),确认 bug 后我会及时修复,谢谢! +> 下载稳定版请点击[这里](https://github.com/wisp-x/lsky-pro/releases),发现 bug 可发送邮件至邮箱:i@wispx.cn,或提交 [issues](https://github.com/wisp-x/lsky-pro/issues) +> 下载速度慢的可以移步 Coding https://dev.tencent.com/u/wispx/p/lsky-pro-releases/git ![homepage.png](./public/static/app/images/demo/1.png) ![homepage.png](./public/static/app/images/demo/2.png) diff --git a/application/api/controller/Base.php b/application/api/controller/Base.php index a7345f6d1..ba2013fa1 100644 --- a/application/api/controller/Base.php +++ b/application/api/controller/Base.php @@ -35,7 +35,7 @@ public function initialize() $this->response('API is not open yet.', [], 500); } - $this->token = $this->request->header('token'); + $this->token = $this->request->header('token', $this->param('token')); $this->auth($this->token); $format = $this->param('format'); diff --git a/application/api/controller/Image.php b/application/api/controller/Image.php new file mode 100644 index 000000000..953f49e8f --- /dev/null +++ b/application/api/controller/Image.php @@ -0,0 +1,67 @@ + + * Date: 2019/10/31 + * Time: 11:10 上午 + * Link: https://github.com/wisp-x + */ + +namespace app\api\controller; + +use app\common\model\Images; +use app\index\controller\User; + +class Image extends Base +{ + private $model; + + public function initialize() + { + parent::initialize(); + $this->model = new Images(); + $this->model = $this->model->where('user_id', $this->user->id)->field(['user_id', 'folder_id'], true); + } + + public function find() + { + $id = $this->param('id'); + $image = $this->model->where(['id' => $id])->find(); + $this->response('success', $this->parseData($image)); + } + + public function items() + { + $page = $this->param('page', 1); + $rows = $this->param('rows', 20); + $images = $this->model->paginate(null, false, [ + 'page' => $page, + 'list_rows' => $rows, + ])->each(function ($item) { + $item = $this->parseData($item); + unset($item['create_time']); + return $item; + }); + $this->response('success', $images); + } + + public function delete() + { + $user = new User(); + $data = str_replace(',', ',', $this->param('id')); + if (strpos($data, ',') !== false) { + $data = explode(',', $data); + } + if ($user->deleteImages($data)) { + return $this->response('删除成功!'); + } + return $this->response('删除失败!', [], 500); + } + + private function parseData($data) + { + $data['upload_time'] = $data->getData('create_time'); + $data['upload_date'] = $data->create_time; + return $data; + } +} \ No newline at end of file diff --git a/application/common/model/Images.php b/application/common/model/Images.php index b583f13ae..5b1afa06a 100644 --- a/application/common/model/Images.php +++ b/application/common/model/Images.php @@ -16,6 +16,8 @@ class Images extends Model protected $insert = ['ip']; + protected $append = ['url']; + public function getUrlAttr($url, $data) { // 图片链接 diff --git a/application/index/controller/User.php b/application/index/controller/User.php index d0752e076..b7ca225ad 100644 --- a/application/index/controller/User.php +++ b/application/index/controller/User.php @@ -47,55 +47,53 @@ public function images($keyword = '', $folderId = 0, $limit = 60) public function deleteImages($deleteId = null) { - if ($this->request->isPost()) { - Db::startTrans(); - try { - $id = $deleteId ? $deleteId : $this->request->post('id'); - $deletes = []; // 需要删除的文件 - if (is_array($id)) { - $images = Images::all($id); - foreach ($images as &$value) { - $deletes[$value->strategy][] = $value->pathname; - $value->delete(); - unset($value); - } - } else { - $image = Images::get($id); - if (!$image) { - throw new Exception('没有找到该图片数据'); - } - $deletes[$image->strategy][] = $image->pathname; - $image->delete(); + Db::startTrans(); + try { + $id = $deleteId ? $deleteId : $this->request->post('id'); + $deletes = []; // 需要删除的文件 + if (is_array($id)) { + $images = Images::all($id); + foreach ($images as &$value) { + $deletes[$value->strategy][] = $value->pathname; + $value->delete(); + unset($value); + } + } else { + $image = Images::get($id); + if (!$image) { + throw new Exception('没有找到该图片数据'); + } + $deletes[$image->strategy][] = $image->pathname; + $image->delete(); + } + // 是否开启软删除(开启了只删除记录,不删除文件) + if (!$this->config['soft_delete']) { + $strategy = []; + // 实例化所有储存策略驱动 + $strategyAll = array_keys(Config::pull('strategy')); + foreach ($strategyAll as $value) { + // 获取储存策略驱动 + $strategy[$value] = $this->getStrategyInstance($value); } - // 是否开启软删除(开启了只删除记录,不删除文件) - if (!$this->config['soft_delete']) { - $strategy = []; - // 实例化所有储存策略驱动 - $strategyAll = array_keys(Config::pull('strategy')); - foreach ($strategyAll as $value) { - // 获取储存策略驱动 - $strategy[$value] = $this->getStrategyInstance($value); - } - foreach ($deletes as $key => $val) { - if (1 === count($val)) { - if (!$strategy[$key]->delete(isset($val[0]) ? $val[0] : null)) { - throw new Exception('删除失败'); - } - } else { - if (!$strategy[$key]->deletes($val)) { - throw new Exception('批量删除失败'); - } + foreach ($deletes as $key => $val) { + if (1 === count($val)) { + if (!$strategy[$key]->delete(isset($val[0]) ? $val[0] : null)) { + throw new Exception('删除失败'); + } + } else { + if (!$strategy[$key]->deletes($val)) { + throw new Exception('批量删除失败'); } } } - Db::commit(); - } catch (Exception $e) { - Db::rollback(); - return $deleteId ? false : $this->error($e->getMessage()); } - return $deleteId ? true : $this->success('删除成功'); + Db::commit(); + } catch (Exception $e) { + Db::rollback(); + return $deleteId ? false : $this->error($e->getMessage()); } + return $deleteId ? true : $this->success('删除成功'); } public function createFolder() diff --git a/application/index/controller/admin/System.php b/application/index/controller/admin/System.php index 88afdb301..19d2ec049 100644 --- a/application/index/controller/admin/System.php +++ b/application/index/controller/admin/System.php @@ -10,6 +10,7 @@ use app\common\model\Config; use think\Db; +use app\common\model\Images; use think\Exception; /** @@ -50,14 +51,14 @@ public function index() public function console() { - $storage = Db::name('images')->sum('size'); - $imagesCount = Db::name('images')->count(); - $suspiciousImagesCount = Db::name('images')->where('suspicious', 1)->count(); - $users_count = Db::name('users')->count(); - $today = Db::name('images')->whereTime('create_time', 'today')->count(); - $yesterday = Db::name('images')->whereTime('create_time', 'yesterday')->count(); - $month = Db::name('images')->whereTime('create_time', 'month')->count(); - $tourists = Db::name('images')->where('user_id', 0)->count(); + $storage = Images::sum('size'); + $imagesCount = Images::count(); + $suspiciousImagesCount = Images::where('suspicious', 1)->count(); + $users_count = \app\common\model\Users::count(); + $today = Images::whereTime('create_time', 'today')->count(); + $yesterday = Images::whereTime('create_time', 'yesterday')->count(); + $month = Images::whereTime('create_time', 'month')->count(); + $tourists = Images::where('user_id', 0)->count(); $this->assign([ 'storage' => format_size($storage, true), // 占用储存 diff --git a/application/index/controller/admin/Update.php b/application/index/controller/admin/Update.php index 185f0a5f3..08120c2e6 100644 --- a/application/index/controller/admin/Update.php +++ b/application/index/controller/admin/Update.php @@ -17,6 +17,7 @@ class Update extends Base { public function index() { + die; // https://dev.tencent.com/u/wispx/p/lsky-pro-releases/git/raw/master/releases/lsky-pro-1.5.4.zip echo << diff --git a/application/index/view/admin/system/console.html b/application/index/view/admin/system/console.html index 810f58529..d5b8a4423 100644 --- a/application/index/view/admin/system/console.html +++ b/application/index/view/admin/system/console.html @@ -10,7 +10,9 @@

占用储存

- {$storage[0]} {$storage[1]} + {$storage[0]} + {if $storage[0]}{$storage[1]}{else/}Kb{/if} +
diff --git a/application/index/view/auth/login.html b/application/index/view/auth/login.html index 7e323c831..6c2e5c961 100644 --- a/application/index/view/auth/login.html +++ b/application/index/view/auth/login.html @@ -3,7 +3,7 @@ {block name="title"}登录 - {$config.site_name}{/block} {block name="css"} - + {/block} {block name="main"} @@ -42,5 +42,5 @@ {/block} {block name="js"} - + {/block} \ No newline at end of file diff --git a/application/index/view/auth/register.html b/application/index/view/auth/register.html index 9993359b8..880ea46cd 100644 --- a/application/index/view/auth/register.html +++ b/application/index/view/auth/register.html @@ -3,7 +3,7 @@ {block name="title"}注册 - {$config.site_name}{/block} {block name="css"} - + {/block} {block name="main"} @@ -67,5 +67,5 @@

站点已关闭注册

{/block} {block name="js"} - + {/block} diff --git a/application/index/view/index/api.html b/application/index/view/index/api.html index 81244542f..20d8b6bda 100644 --- a/application/index/view/index/api.html +++ b/application/index/view/index/api.html @@ -227,6 +227,301 @@

响应错误示例

"time": 1544245931 }
+ +
+ 注意:以下接口均需要 Token +
+
+

3. 获取图片列表

+
+
+
+ + + + + + + + + + + + + + + + + +
功能接口
请求方式POST
URL{$domain}/api/images
+
+
+
+

请求参数

+
+ + + + + + + + + + + + + + + + + + + + + + + +
参数名称类型是否必须说明
pageString页码
rowsString每页数量, 默认 20 条
+
+

返回数据(data)说明

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
参数名称类型实例值说明
totalNumber999数据总量
per_pageString1每页数量
current_pageNumber1当前所在页码
last_pageNumber999最后一页页码
+
+

图片数据说明

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
参数名称类型实例值说明
idNumber1图片ID
strategyStringoss储存策略, (cos:腾讯云, kodo:七牛云, local:本地, oss:阿里云oss, remote:远程储存, uss:又拍云)
pathString2019/10/31图片所在路径
nameString929616303ca92.jpg图片名称
pathnameString2019/10/31/929616303ca92.jpg图片路径+名称
sizeString30405.00图片大小(字节: b)
mimeStringimage/jpeg图片 mime 类型
sha1String0143f7904f12e2a76ff2935f21a771b8adadf961图片 sha1 值
md5Stringe630c1d832f1701b0afe09cfe86a7f2b图片 md5 值
ipString192.168.0.1上传者 IP
suspiciousNumber0是否是可疑图片, (0:否, 1:是)
update_timeNumber1572491936图片上传时间
update_dateString2019-10-31 11:18:56图片上传日期
urlStringhttp://domain.com/2019/10/31/929616303ca92.jpg图片链接
+
+
+ +
+

4. 获取单张图片

+
+
+
+ + + + + + + + + + + + + + + + + +
功能接口
请求方式POST
URL{$domain}/api/image
+
+
+
+

请求参数

+
+ + + + + + + + + + + + + + + + + +
参数名称类型是否必须说明
idString图片ID
+
+

返回数据(data)与第三条相同

+
+ +
+

5. 删除图片

+
+
+
+ + + + + + + + + + + + + + + + + +
功能接口
请求方式POST
URL{$domain}/api/delete
+
+
+
+

请求参数

+
+ + + + + + + + + + + + + + + + + +
参数名称类型是否必须说明
idString图片ID, 删除多个使用逗号分隔
+
+
{/block} diff --git a/application/index/view/index/index.html b/application/index/view/index/index.html index 7fb2ce11f..1209cc3fb 100644 --- a/application/index/view/index/index.html +++ b/application/index/view/index/index.html @@ -12,6 +12,12 @@
+ {if $config.notice} +
+ + {$config.notice|raw} +
+ {/if}

Image Upload

最大可上传 {:round($config.upload_max_size / 1024 / 1024)} MB的图片,单次同时可选择 {$config.upload_single_num} 张。本站已托管 {$images_count} 张图片。

@@ -84,7 +90,7 @@
请登录后体验
}; $("#image").fileinput({ - uploadUrl: "{:url('upload/upload')}", + uploadUrl: "{:url('upload/upload')}" + '?rand=' + new Date().getTime().toString(36) + Math.random().toString(36).slice(2), language: "zh", theme: "fas", previewFileType: "image", diff --git a/composer.json b/composer.json index bdaf585bc..91ad986c3 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "upyun/sdk": "^3.3", "qcloud/cos-sdk-v5": "^1.2", "topthink/think-image": "^1.0", - "phpmailer/phpmailer": "^6.0" + "phpmailer/phpmailer": "^6.0", + "nicolab/php-ftp-client": "^1.5" }, "autoload": { "psr-4": { diff --git a/composer.lock b/composer.lock index bcce1824d..98e18132b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "f3a07db17ca2f758f19303939f3bb3d6", + "content-hash": "fb6ffef3fc6c84854a1c9c891746c6e1", "packages": [ { "name": "aliyuncs/oss-sdk-php", @@ -157,16 +157,16 @@ }, { "name": "guzzlehttp/guzzle", - "version": "6.3.3", + "version": "6.4.1", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" + "reference": "0895c932405407fd3a7368b6910c09a24d26db11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/0895c932405407fd3a7368b6910c09a24d26db11", + "reference": "0895c932405407fd3a7368b6910c09a24d26db11", "shasum": "", "mirrors": [ { @@ -176,14 +176,15 @@ ] }, "require": { + "ext-json": "*", "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.4", + "guzzlehttp/psr7": "^1.6.1", "php": ">=5.5" }, "require-dev": { "ext-curl": "*", "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", - "psr/log": "^1.0" + "psr/log": "^1.1" }, "suggest": { "psr/log": "Required for using the Log middleware" @@ -195,12 +196,12 @@ } }, "autoload": { - "files": [ - "src/functions_include.php" - ], "psr-4": { "GuzzleHttp\\": "src/" - } + }, + "files": [ + "src/functions_include.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -224,7 +225,7 @@ "rest", "web service" ], - "time": "2018-04-22T15:46:56+00:00" + "time": "2019-10-23T15:58:00+00:00" }, { "name": "guzzlehttp/promises", @@ -360,18 +361,73 @@ ], "time": "2019-07-01T23:21:34+00:00" }, + { + "name": "nicolab/php-ftp-client", + "version": "v1.5.1", + "source": { + "type": "git", + "url": "https://github.com/Nicolab/php-ftp-client.git", + "reference": "8c66e1104da1b638f5d7a9e24624a5525b459a0c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Nicolab/php-ftp-client/zipball/8c66e1104da1b638f5d7a9e24624a5525b459a0c", + "reference": "8c66e1104da1b638f5d7a9e24624a5525b459a0c", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-ftp": "*", + "php": ">=5.4" + }, + "type": "library", + "autoload": { + "psr-0": { + "FtpClient": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Tallefourtane", + "email": "dev@nicolab.net", + "homepage": "http://nicolab.net" + } + ], + "description": "A flexible FTP and SSL-FTP client for PHP. This lib provides helpers easy to use to manage the remote files.", + "homepage": "https://github.com/Nicolab/php-ftp-client", + "keywords": [ + "file", + "ftp", + "helper", + "lib", + "server", + "sftp", + "ssl", + "ssl-ftp" + ], + "time": "2019-04-23T09:22:37+00:00" + }, { "name": "phpmailer/phpmailer", - "version": "v6.0.7", + "version": "v6.1.1", "source": { "type": "git", "url": "https://github.com/PHPMailer/PHPMailer.git", - "reference": "0c41a36d4508d470e376498c1c0c527aa36a2d59" + "reference": "26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/0c41a36d4508d470e376498c1c0c527aa36a2d59", - "reference": "0c41a36d4508d470e376498c1c0c527aa36a2d59", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8", + "reference": "26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8", "shasum": "", "mirrors": [ { @@ -410,17 +466,17 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-2.1" + "LGPL-2.1-only" ], "authors": [ - { - "name": "Jim Jagielski", - "email": "jimjag@gmail.com" - }, { "name": "Marcus Bointon", "email": "phpmailer@synchromedia.co.uk" }, + { + "name": "Jim Jagielski", + "email": "jimjag@gmail.com" + }, { "name": "Andy Prevost", "email": "codeworxtech@users.sourceforge.net" @@ -430,7 +486,7 @@ } ], "description": "PHPMailer is a full-featured email creation and transfer class for PHP", - "time": "2019-02-01T15:04:28+00:00" + "time": "2019-09-27T21:33:43+00:00" }, { "name": "psr/http-message", @@ -490,16 +546,16 @@ }, { "name": "qcloud/cos-sdk-v5", - "version": "v1.3.2", + "version": "v1.3.4", "source": { "type": "git", "url": "https://github.com/tencentyun/cos-php-sdk-v5.git", - "reference": "0454f48629210749ae6316ab317548169dac9d8f" + "reference": "1b32aa422f6dffe4ea411e5095e4b0da9135551b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/0454f48629210749ae6316ab317548169dac9d8f", - "reference": "0454f48629210749ae6316ab317548169dac9d8f", + "url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/1b32aa422f6dffe4ea411e5095e4b0da9135551b", + "reference": "1b32aa422f6dffe4ea411e5095e4b0da9135551b", "shasum": "", "mirrors": [ { @@ -538,20 +594,20 @@ "php", "qcloud" ], - "time": "2019-04-25T12:23:41+00:00" + "time": "2019-09-02T12:08:44+00:00" }, { "name": "qiniu/php-sdk", - "version": "v7.2.9", + "version": "v7.2.10", "source": { "type": "git", "url": "https://github.com/qiniu/php-sdk.git", - "reference": "afe7d8715d8a688b1d8d8cdf031240d2363dad90" + "reference": "d89987163f560ebf9dfa5bb25de9bd9b1a3b2bd8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/qiniu/php-sdk/zipball/afe7d8715d8a688b1d8d8cdf031240d2363dad90", - "reference": "afe7d8715d8a688b1d8d8cdf031240d2363dad90", + "url": "https://api.github.com/repos/qiniu/php-sdk/zipball/d89987163f560ebf9dfa5bb25de9bd9b1a3b2bd8", + "reference": "d89987163f560ebf9dfa5bb25de9bd9b1a3b2bd8", "shasum": "", "mirrors": [ { @@ -595,7 +651,7 @@ "sdk", "storage" ], - "time": "2019-07-09T07:55:07+00:00" + "time": "2019-10-28T10:23:23+00:00" }, { "name": "ralouphie/getallheaders", @@ -711,16 +767,16 @@ }, { "name": "topthink/framework", - "version": "v5.1.37.1", + "version": "v5.1.38.1", "source": { "type": "git", "url": "https://github.com/top-think/framework.git", - "reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b" + "reference": "12d15c29d5d6a972fc8bfc8db005d64d4786028c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/top-think/framework/zipball/05eecd121d18d6705aaa10aa44fcdf7c14da4d0b", - "reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b", + "url": "https://api.github.com/repos/top-think/framework/zipball/12d15c29d5d6a972fc8bfc8db005d64d4786028c", + "reference": "12d15c29d5d6a972fc8bfc8db005d64d4786028c", "shasum": "", "mirrors": [ { @@ -764,7 +820,7 @@ "orm", "thinkphp" ], - "time": "2019-05-28T06:57:29+00:00" + "time": "2019-08-12T00:58:30+00:00" }, { "name": "topthink/think-captcha", @@ -906,16 +962,16 @@ }, { "name": "upyun/sdk", - "version": "3.3.0", + "version": "3.4.0", "source": { "type": "git", "url": "https://github.com/upyun/php-sdk.git", - "reference": "1a2dd5ae31047956c733aef0f764f3a527d30628" + "reference": "b4819fd941e3f19a886f8b3c5f8bffcb8279185f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/upyun/php-sdk/zipball/1a2dd5ae31047956c733aef0f764f3a527d30628", - "reference": "1a2dd5ae31047956c733aef0f764f3a527d30628", + "url": "https://api.github.com/repos/upyun/php-sdk/zipball/b4819fd941e3f19a886f8b3c5f8bffcb8279185f", + "reference": "b4819fd941e3f19a886f8b3c5f8bffcb8279185f", "shasum": "", "mirrors": [ { @@ -945,10 +1001,6 @@ "MIT" ], "authors": [ - { - "name": "totoleo", - "email": "totoleo@163.com" - }, { "name": "lfeng", "email": "bonevv@gmail.com" @@ -957,6 +1009,10 @@ "name": "lvtongda", "email": "riyao.lyu@gmail.com" }, + { + "name": "totoleo", + "email": "totoleo@163.com" + }, { "name": "sabakugaara", "email": "senellise@gmail.com" @@ -968,7 +1024,7 @@ "sdk", "upyun" ], - "time": "2017-11-12T09:17:42+00:00" + "time": "2019-04-29T09:27:51+00:00" } ], "packages-dev": [], diff --git a/config/naming.php b/config/naming.php index 874b5523c..366339a9f 100644 --- a/config/naming.php +++ b/config/naming.php @@ -8,13 +8,10 @@ // [命名规则配置文件] -$array = gettimeofday(); -$aa = ($array['sec'] * 100000 + $array['usec'] / 10) & 0x7FFFFFFF; -$logId = ((($array['sec'] * 100000 + $array['usec'] / 10) & 0x7FFFFFFF) | 0x80000000); - $time = time(); -$md5 = md5('LSKY PRO' . $logId . time()); -$uniqid = substr(md5($logId), 8, 13); +$rand = function_exists('session_create_id') ? session_create_id() : uniqid(); +$md5 = md5('LSKY PRO' . $rand . time()); +$uniqid = substr(md5($rand), 8, 13); return [ 'path' => [ diff --git a/config/strategy.php b/config/strategy.php index b448356b4..12f1f4f9f 100644 --- a/config/strategy.php +++ b/config/strategy.php @@ -29,4 +29,8 @@ 'name' => '又拍云USS', 'class' => \strategy\driver\Uss::class ], + 'remote' => [ + 'name' => '远程', + 'class' => \strategy\driver\Remote::class + ], ]; diff --git a/extend/strategy/Driver.php b/extend/strategy/Driver.php index 58b450980..222b6ee97 100644 --- a/extend/strategy/Driver.php +++ b/extend/strategy/Driver.php @@ -16,6 +16,8 @@ */ interface Driver { + public function __construct($options = []); + /** * 创建文件 * diff --git a/extend/strategy/driver/Remote.php b/extend/strategy/driver/Remote.php new file mode 100644 index 000000000..1486bd42a --- /dev/null +++ b/extend/strategy/driver/Remote.php @@ -0,0 +1,113 @@ + + * Date: 2019/10/31 + * Time: 9:39 上午 + * Link: https://github.com/wisp-x + */ + +namespace strategy\driver; + +use FtpClient\FtpException; +use strategy\Driver; + +class Remote implements Driver +{ + private $ftp; + + private $error; + + public function __construct($options = []) + { + try { + $this->ftp = new \FtpClient\FtpClient(); + $this->ftp->connect($options['remote_host']); + $this->ftp->login($options['remote_name'], $options['remote_password']); + } catch (FtpException $e) { + $this->error = $e->getMessage(); + } + } + + /** + * 创建文件 + * + * @param $pathname + * @param $file + * + * @return mixed + */ + public function create($pathname, $file) + { + try { + $dirname = dirname($pathname); + if (!$this->ftp->isDir($dirname)) { + if (!$this->ftp->mkdir($dirname, true)) { + throw new FtpException('文件夹创建失败!'); + } + } + if (!$this->ftp->put($pathname, $file, FTP_BINARY)) { + throw new FtpException('上传失败'); + } + } catch (FtpException $e) { + $this->error = $e->getMessage(); + return false; + } + + return true; + } + + /** + * 删除单个文件 + * + * @param $pathname + * + * @return mixed + */ + public function delete($pathname) + { + try { + if (!$this->ftp->remove($pathname, true)) { + throw new FtpException('删除失败'); + } + } catch (FtpException $e) { + $this->error = $e->getMessage(); + return false; + } + + return true; + } + + /** + * 删除多个文件 + * + * @param array $list 一维数组 + * + * @return mixed + */ + public function deletes(array $list) + { + try { + foreach ($list as $item) { + if (!$this->ftp->remove($item, true)) { + throw new FtpException('删除失败'); + } + } + } catch (FtpException $e) { + $this->error = $e->getMessage(); + return false; + } + + return true; + } + + /** + * 获取出错信息 + * + * @return mixed + */ + public function getError() + { + return 'Remote:' . $this->error; + } +} diff --git a/install.sql b/install.sql index eab0d43cb..0c2666abc 100644 --- a/install.sql +++ b/install.sql @@ -153,11 +153,18 @@ INSERT INTO `lsky_config` (`id`, `key`, `type`, `input_type`, `name`, `title`, ` (NULL, 'uss', 'text', 'text', 'uss_operator_name', 'OperatorName', '操作员账号', '', ''), (NULL, 'uss', 'text', 'password', 'uss_operator_pwd', 'OperatorPwd', '操作员密码', '', ''), (NULL, 'uss', 'text', 'text', 'uss_service_name', 'ServiceName', '云储存服务名称', '', ''), +(NULL, 'basics', 'textarea', 'textarea', 'notice', '系统公告', '支持html', '', ''), +(NULL, 'remote', 'text', 'text', 'remote_cdn_domain', '域名', NULL, '', ''), +(NULL, 'remote', 'select', 'text', 'remote_type', '远程储存类型', NULL, 'ftp', '{\"ftp\":\"ftp\"}'), +(NULL, 'remote', 'text', 'text', 'remote_host', '连接地址', NULL, '', ''), +(NULL, 'remote', 'text', 'text', 'remote_name', '登录账号', NULL, '', ''), +(NULL, 'remote', 'text', 'password', 'remote_password', '登录密码', NULL, '', ''), +(NULL, 'remote', 'text', 'number', 'remote_port', '连接端口', NULL, '21', ''), (NULL, 'audit', 'bool', 'checkbox', 'open_audit', '开启图片鉴黄', '接口申请地址:https://www.moderatecontent.com', '0', ''), (NULL, 'audit', 'text', 'text', 'audit_key', 'Key', NULL, '', ''), (NULL, 'audit', 'select', 'text', 'audit_index', '内容评级', '1=所有人,2=少年,3=成人', '3', '{\"1\": \"所有人\", \"2\": \"少年\", \"3\": \"成人\"}'), -(NULL, '', 'text', 'text', 'system_version', '系统版本', NULL, '1.5.4', ''); +(NULL, '', 'text', 'text', 'system_version', '系统版本', NULL, '1.5.5', ''); INSERT INTO `lsky_group` (`id`, `strategy`, `name`, `default`, `update_time`, `create_time`) VALUES (NULL, 'local', '默认组', '1', '0', '0'); diff --git a/public/2019/05/08/5cd2e24bf3a68.jpg b/public/2019/05/08/5cd2e24bf3a68.jpg deleted file mode 100644 index 9e14ccb05..000000000 Binary files a/public/2019/05/08/5cd2e24bf3a68.jpg and /dev/null differ diff --git a/public/2019/05/08/5cd2e24bf3fc2.jpg b/public/2019/05/08/5cd2e24bf3fc2.jpg deleted file mode 100644 index a846da6e1..000000000 Binary files a/public/2019/05/08/5cd2e24bf3fc2.jpg and /dev/null differ diff --git a/public/2019/05/08/5cd2e24c04746.jpg b/public/2019/05/08/5cd2e24c04746.jpg deleted file mode 100644 index d6875e8c2..000000000 Binary files a/public/2019/05/08/5cd2e24c04746.jpg and /dev/null differ diff --git a/public/2019/05/08/5cd2e24c05595.jpg b/public/2019/05/08/5cd2e24c05595.jpg deleted file mode 100644 index cd2102fe6..000000000 Binary files a/public/2019/05/08/5cd2e24c05595.jpg and /dev/null differ diff --git a/public/2019/05/08/5cd2e24c17428.jpg b/public/2019/05/08/5cd2e24c17428.jpg deleted file mode 100644 index fb7c335b6..000000000 Binary files a/public/2019/05/08/5cd2e24c17428.jpg and /dev/null differ diff --git a/public/2019/05/08/5cd2e24c67731.jpg b/public/2019/05/08/5cd2e24c67731.jpg deleted file mode 100644 index 9f0418d87..000000000 Binary files a/public/2019/05/08/5cd2e24c67731.jpg and /dev/null differ diff --git a/public/2019/05/08/5cd2e24c802a8.jpg b/public/2019/05/08/5cd2e24c802a8.jpg deleted file mode 100644 index 217148af9..000000000 Binary files a/public/2019/05/08/5cd2e24c802a8.jpg and /dev/null differ diff --git a/public/2019/05/08/5cd2e24ca1ae5.jpg b/public/2019/05/08/5cd2e24ca1ae5.jpg deleted file mode 100644 index 42fab45fd..000000000 Binary files a/public/2019/05/08/5cd2e24ca1ae5.jpg and /dev/null differ diff --git a/public/2019/05/08/5cd2e24cbe5b7.jpg b/public/2019/05/08/5cd2e24cbe5b7.jpg deleted file mode 100644 index 30e9e786e..000000000 Binary files a/public/2019/05/08/5cd2e24cbe5b7.jpg and /dev/null differ diff --git a/route/route.php b/route/route.php index b5d21b267..356726299 100644 --- a/route/route.php +++ b/route/route.php @@ -15,8 +15,11 @@ // [Api Route] Route::group('api', function () { - Route::post('token', 'api/Token/index'); - Route::post('upload', 'api/Upload/index'); + Route::any('token', 'api/Token/index'); + Route::any('upload', 'api/Upload/index'); + Route::any('image', 'api/Image/find'); + Route::any('images', 'api/Image/items'); + Route::any('delete', 'api/Image/delete'); }) ->header('Access-Control-Allow-Headers', 'Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-Requested-With, Token') ->allowCrossDomain(); diff --git a/thinkphp/helper.php b/thinkphp/helper.php index fc2ca8c85..72b9e9fde 100644 --- a/thinkphp/helper.php +++ b/thinkphp/helper.php @@ -686,7 +686,13 @@ function view($template = '', $vars = [], $code = 200, $filter = null) */ function widget($name, $data = []) { - return app()->action($name, $data, 'widget'); + $result = app()->action($name, $data, 'widget'); + + if (is_object($result)) { + $result = $result->getContent(); + } + + return $result; } } diff --git a/thinkphp/library/think/App.php b/thinkphp/library/think/App.php index 1fb9fbda2..7766555eb 100644 --- a/thinkphp/library/think/App.php +++ b/thinkphp/library/think/App.php @@ -20,7 +20,7 @@ */ class App extends Container { - const VERSION = '5.1.37 LTS'; + const VERSION = '5.1.38 LTS'; /** * 当前模块路径 diff --git a/thinkphp/library/think/Collection.php b/thinkphp/library/think/Collection.php index d58c8999b..8251fc8f1 100644 --- a/thinkphp/library/think/Collection.php +++ b/thinkphp/library/think/Collection.php @@ -353,7 +353,7 @@ public function where($field, $operator, $value = null) $result = isset($data[$field]) ? $data[$field] : null; } - switch ($operator) { + switch (strtolower($operator)) { case '===': return $result === $value; case '!==': diff --git a/thinkphp/library/think/Controller.php b/thinkphp/library/think/Controller.php index d16a1ed50..966eaaa83 100644 --- a/thinkphp/library/think/Controller.php +++ b/thinkphp/library/think/Controller.php @@ -158,7 +158,7 @@ protected function beforeAction($method, $options = []) */ protected function fetch($template = '', $vars = [], $config = []) { - return $this->view->fetch($template, $vars, $config); + return Response::create($template, 'view')->assign($vars)->config($config); } /** @@ -171,7 +171,7 @@ protected function fetch($template = '', $vars = [], $config = []) */ protected function display($content = '', $vars = [], $config = []) { - return $this->view->display($content, $vars, $config); + return Response::create($content, 'view')->assign($vars)->config($config)->isContent(true); } /** diff --git a/thinkphp/library/think/Request.php b/thinkphp/library/think/Request.php index f6529d03c..e0488e77f 100644 --- a/thinkphp/library/think/Request.php +++ b/thinkphp/library/think/Request.php @@ -682,6 +682,7 @@ public function pathinfo() // 判断URL里面是否有兼容模式参数 $pathinfo = $_GET[$this->config['var_pathinfo']]; unset($_GET[$this->config['var_pathinfo']]); + unset($this->get[$this->config['var_pathinfo']]); } elseif ($this->isCli()) { // CLI模式下 index.php module/controller/action/params/... $pathinfo = isset($_SERVER['argv'][1]) ? $_SERVER['argv'][1] : ''; @@ -702,6 +703,10 @@ public function pathinfo() } } + if (!empty($pathinfo)) { + unset($this->get[$pathinfo], $this->request[$pathinfo]); + } + $this->pathinfo = empty($pathinfo) || '/' == $pathinfo ? '' : ltrim($pathinfo, '/'); } @@ -1039,7 +1044,7 @@ public function put($name = '', $default = null, $filter = '') protected function getInputData($content) { - if (false !== strpos($this->contentType(), 'application/json') || 0 === strpos($content, '{"')) { + if ($this->isJson()) { return (array) json_decode($content, true); } elseif (strpos($content, '=')) { parse_str($content, $data); @@ -1631,6 +1636,19 @@ public function isSsl() return false; } + /** + * 当前是否JSON请求 + * @access public + * @return bool + */ + public function isJson() + { + $contentType = $this->contentType(); + $acceptType = $this->type(); + + return false !== strpos($contentType, 'json') || false !== strpos($acceptType, 'json'); + } + /** * 当前是否Ajax请求 * @access public diff --git a/thinkphp/library/think/Url.php b/thinkphp/library/think/Url.php index a339f8de2..cccabc222 100644 --- a/thinkphp/library/think/Url.php +++ b/thinkphp/library/think/Url.php @@ -130,7 +130,9 @@ public function build($url = '', $vars = '', $suffix = true, $domain = false) // 匹配路由命名标识 $url = $match[0]; - $domain = $match[1]; + if ($domain) { + $domain = $match[1]; + } if (!is_null($match[2])) { $suffix = $match[2]; diff --git a/thinkphp/library/think/View.php b/thinkphp/library/think/View.php index 17860a6ba..284dd41a1 100644 --- a/thinkphp/library/think/View.php +++ b/thinkphp/library/think/View.php @@ -160,7 +160,10 @@ public function exists($name) */ public function filter($filter) { - $this->filter = $filter; + if ($filter) { + $this->filter = $filter; + } + return $this; } diff --git a/thinkphp/library/think/db/Builder.php b/thinkphp/library/think/db/Builder.php index b742506aa..09df1a072 100644 --- a/thinkphp/library/think/db/Builder.php +++ b/thinkphp/library/think/db/Builder.php @@ -407,7 +407,7 @@ protected function parseWhereItem(Query $query, $field, $val, $rule = '', $binds $jsonType = $query->getJsonFieldType($field); $bindType = $this->connection->getFieldBindType($jsonType); } else { - $bindType = isset($binds[$field]) ? $binds[$field] : PDO::PARAM_STR; + $bindType = isset($binds[$field]) && 'LIKE' != $exp ? $binds[$field] : PDO::PARAM_STR; } if (is_scalar($value) && !in_array($exp, ['EXP', 'NOT NULL', 'NULL', 'IN', 'NOT IN', 'BETWEEN', 'NOT BETWEEN']) && strpos($exp, 'TIME') === false) { @@ -450,7 +450,7 @@ protected function parseLike(Query $query, $key, $exp, $value, $field, $bindType // 模糊匹配 if (is_array($value)) { foreach ($value as $item) { - $name = $query->bind($item, $bindType); + $name = $query->bind($item, PDO::PARAM_STR); $array[] = $key . ' ' . $exp . ' :' . $name; } @@ -604,6 +604,10 @@ protected function parseCompare(Query $query, $key, $exp, $value, $field, $bindT $value = $this->parseClosure($query, $value); } + if ('=' == $exp && is_null($value)) { + return $key . ' IS NULL'; + } + return $key . ' ' . $exp . ' ' . $value; } @@ -651,7 +655,6 @@ protected function parseIn(Query $query, $key, $exp, $value, $field, $bindType) $value = $value->getValue(); } else { $value = array_unique(is_array($value) ? $value : explode(',', $value)); - $array = []; foreach ($value as $k => $v) { @@ -659,9 +662,12 @@ protected function parseIn(Query $query, $key, $exp, $value, $field, $bindType) $array[] = ':' . $name; } - $zone = implode(',', $array); - - $value = empty($zone) ? "''" : $zone; + if (count($array) == 1) { + return $key . ('IN' == $exp ? ' = ' : ' <> ') . $array[0]; + } else { + $zone = implode(',', $array); + $value = empty($zone) ? "''" : $zone; + } } return $key . ' ' . $exp . ' (' . $value . ')'; diff --git a/thinkphp/library/think/db/Connection.php b/thinkphp/library/think/db/Connection.php index d6b3c7ed5..18b4885a6 100644 --- a/thinkphp/library/think/db/Connection.php +++ b/thinkphp/library/think/db/Connection.php @@ -1467,9 +1467,7 @@ public function getRealSql($sql, array $bind = []) $value = is_array($val) ? $val[0] : $val; $type = is_array($val) ? $val[1] : PDO::PARAM_STR; - if (self::PARAM_FLOAT == $type) { - $value = (float) $value; - } elseif (PDO::PARAM_STR == $type) { + if ((self::PARAM_FLOAT == $type || PDO::PARAM_STR == $type) && is_string($value)) { $value = '\'' . addslashes($value) . '\''; } elseif (PDO::PARAM_INT == $type && '' === $value) { $value = 0; @@ -1503,7 +1501,7 @@ protected function bindValue(array $bind = []) if (PDO::PARAM_INT == $val[1] && '' === $val[0]) { $val[0] = 0; } elseif (self::PARAM_FLOAT == $val[1]) { - $val[0] = (float) $val[0]; + $val[0] = is_string($val[0]) ? (float) $val[0] : $val[0]; $val[1] = PDO::PARAM_STR; } diff --git a/thinkphp/library/think/db/Query.php b/thinkphp/library/think/db/Query.php index 5b1785e41..4d6329099 100644 --- a/thinkphp/library/think/db/Query.php +++ b/thinkphp/library/think/db/Query.php @@ -95,14 +95,14 @@ class Query * @var array */ protected $timeRule = [ - 'today' => ['today', 'tomorrow'], - 'yesterday' => ['yesterday', 'today'], - 'week' => ['this week 00:00:00', 'next week 00:00:00'], - 'last week' => ['last week 00:00:00', 'this week 00:00:00'], - 'month' => ['first Day of this month 00:00:00', 'first Day of next month 00:00:00'], - 'last month' => ['first Day of last month 00:00:00', 'first Day of this month 00:00:00'], - 'year' => ['this year 1/1', 'next year 1/1'], - 'last year' => ['last year 1/1', 'this year 1/1'], + 'today' => ['today', 'tomorrow -1second'], + 'yesterday' => ['yesterday', 'today -1second'], + 'week' => ['this week 00:00:00', 'next week 00:00:00 -1second'], + 'last week' => ['last week 00:00:00', 'this week 00:00:00 -1second'], + 'month' => ['first Day of this month 00:00:00', 'first Day of next month 00:00:00 -1second'], + 'last month' => ['first Day of last month 00:00:00', 'first Day of this month 00:00:00 -1second'], + 'year' => ['this year 1/1', 'next year 1/1 -1second'], + 'last year' => ['last year 1/1', 'this year 1/1 -1second'], ]; /** diff --git a/thinkphp/library/think/db/builder/Mysql.php b/thinkphp/library/think/db/builder/Mysql.php index 22f33900e..c715aa34f 100644 --- a/thinkphp/library/think/db/builder/Mysql.php +++ b/thinkphp/library/think/db/builder/Mysql.php @@ -129,7 +129,7 @@ public function parseKey(Query $query, $key, $strict = false) // JSON字段支持 list($field, $name) = explode('->', $key, 2); - return 'json_extract(' . $this->parseKey($query, $field, true) . ', \'$.' . str_replace('->', '.', $name) . '\')'; + return 'json_extract(' . $this->parseKey($query, $field, true) . ', \'$' . (strpos($name, '[') === 0 ? '' : '.') . str_replace('->', '.', $name) . '\')'; } elseif (strpos($key, '.') && !preg_match('/[,\'\"\(\)`\s]/', $key)) { list($table, $key) = explode('.', $key, 2); diff --git a/thinkphp/library/think/db/connector/Mysql.php b/thinkphp/library/think/db/connector/Mysql.php index 93b8a1825..1713b99b9 100644 --- a/thinkphp/library/think/db/connector/Mysql.php +++ b/thinkphp/library/think/db/connector/Mysql.php @@ -136,7 +136,27 @@ public function getTables($dbName = '') */ protected function getExplain($sql) { - $pdo = $this->linkID->query("EXPLAIN " . $sql); + $pdo = $this->linkID->prepare("EXPLAIN " . $this->queryStr); + + foreach ($this->bind as $key => $val) { + // 占位符 + $param = is_int($key) ? $key + 1 : ':' . $key; + + if (is_array($val)) { + if (PDO::PARAM_INT == $val[1] && '' === $val[0]) { + $val[0] = 0; + } elseif (self::PARAM_FLOAT == $val[1]) { + $val[0] = is_string($val[0]) ? (float) $val[0] : $val[0]; + $val[1] = PDO::PARAM_STR; + } + + $result = $pdo->bindValue($param, $val[0], $val[1]); + } else { + $result = $pdo->bindValue($param, $val); + } + } + + $pdo->execute(); $result = $pdo->fetch(PDO::FETCH_ASSOC); $result = array_change_key_case($result); diff --git a/thinkphp/library/think/exception/ValidateException.php b/thinkphp/library/think/exception/ValidateException.php index e3f843745..81ddfe211 100644 --- a/thinkphp/library/think/exception/ValidateException.php +++ b/thinkphp/library/think/exception/ValidateException.php @@ -18,7 +18,7 @@ class ValidateException extends \RuntimeException public function __construct($error, $code = 0) { $this->error = $error; - $this->message = is_array($error) ? implode("\n\r", $error) : $error; + $this->message = is_array($error) ? implode(PHP_EOL, $error) : $error; $this->code = $code; } diff --git a/thinkphp/library/think/log/driver/File.php b/thinkphp/library/think/log/driver/File.php index c506105fd..3f6522d1a 100644 --- a/thinkphp/library/think/log/driver/File.php +++ b/thinkphp/library/think/log/driver/File.php @@ -107,7 +107,7 @@ protected function write($message, $destination, $apart = false, $append = false $info['timestamp'] = date($this->config['time_format']); foreach ($message as $type => $msg) { - $msg = is_array($msg) ? implode("\r\n", $msg) : $msg; + $msg = is_array($msg) ? implode(PHP_EOL, $msg) : $msg; if (PHP_SAPI == 'cli') { $info['msg'] = $msg; $info['type'] = $type; @@ -212,14 +212,14 @@ protected function checkLogSize($destination) protected function parseCliLog($info) { if ($this->config['json']) { - $message = json_encode($info, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\r\n"; + $message = json_encode($info, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL; } else { $now = $info['timestamp']; unset($info['timestamp']); - $message = implode("\r\n", $info); + $message = implode(PHP_EOL, $info); - $message = "[{$now}]" . $message . "\r\n"; + $message = "[{$now}]" . $message . PHP_EOL; } return $message; @@ -242,13 +242,13 @@ protected function parseLog($info) if ($this->config['json']) { $info = $requestInfo + $info; - return json_encode($info, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . "\r\n"; + return json_encode($info, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) . PHP_EOL; } - array_unshift($info, "---------------------------------------------------------------\r\n[{$info['timestamp']}] {$requestInfo['ip']} {$requestInfo['method']} {$requestInfo['host']}{$requestInfo['uri']}"); + array_unshift($info, "---------------------------------------------------------------" . PHP_EOL . "\r\n[{$info['timestamp']}] {$requestInfo['ip']} {$requestInfo['method']} {$requestInfo['host']}{$requestInfo['uri']}"); unset($info['timestamp']); - return implode("\r\n", $info) . "\r\n"; + return implode(PHP_EOL, $info) . PHP_EOL; } protected function getDebugLog(&$info, $append, $apart) diff --git a/thinkphp/library/think/model/concern/Conversion.php b/thinkphp/library/think/model/concern/Conversion.php index 922d5b0e1..28a6f9991 100644 --- a/thinkphp/library/think/model/concern/Conversion.php +++ b/thinkphp/library/think/model/concern/Conversion.php @@ -189,10 +189,12 @@ public function toArray() if (!$relation) { $relation = $this->getAttr($key); - $relation->visible($name); + if ($relation) { + $relation->visible($name); + } } - $item[$key] = $relation->append($name)->toArray(); + $item[$key] = $relation ? $relation->append($name)->toArray() : []; } elseif (strpos($name, '.')) { list($key, $attr) = explode('.', $name); // 追加关联对象属性 @@ -200,10 +202,12 @@ public function toArray() if (!$relation) { $relation = $this->getAttr($key); - $relation->visible([$attr]); + if ($relation) { + $relation->visible([$attr]); + } } - $item[$key] = $relation->append([$attr])->toArray(); + $item[$key] = $relation ? $relation->append([$attr])->toArray() : []; } else { $item[$name] = $this->getAttr($name, $item); } diff --git a/thinkphp/library/think/model/relation/BelongsTo.php b/thinkphp/library/think/model/relation/BelongsTo.php index 98d176e8f..1dea3b3b5 100644 --- a/thinkphp/library/think/model/relation/BelongsTo.php +++ b/thinkphp/library/think/model/relation/BelongsTo.php @@ -140,13 +140,17 @@ public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER' $relation = basename(str_replace('\\', '/', $this->model)); $localKey = $this->localKey; $foreignKey = $this->foreignKey; + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->whereExists(function ($query) use ($table, $model, $relation, $localKey, $foreignKey) { $query->table([$table => $relation]) ->field($relation . '.' . $localKey) - ->whereExp($model . '.' . $foreignKey, '=' . $relation . '.' . $localKey); + ->whereExp($model . '.' . $foreignKey, '=' . $relation . '.' . $localKey) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }); }); } @@ -167,12 +171,16 @@ public function hasWhere($where = [], $fields = null) $this->getQueryWhere($where, $relation); } - $fields = $this->getRelationQueryFields($fields, $model); + $fields = $this->getRelationQueryFields($fields, $model); + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->field($fields) ->join([$table => $relation], $model . '.' . $this->foreignKey . '=' . $relation . '.' . $this->localKey, $this->joinType) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) ->where($where); } diff --git a/thinkphp/library/think/model/relation/HasMany.php b/thinkphp/library/think/model/relation/HasMany.php index f97623b87..728ca1818 100644 --- a/thinkphp/library/think/model/relation/HasMany.php +++ b/thinkphp/library/think/model/relation/HasMany.php @@ -292,14 +292,18 @@ public function saveAll($dataSet, $replace = true) */ public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER') { - $table = $this->query->getTable(); - $model = basename(str_replace('\\', '/', get_class($this->parent))); - $relation = basename(str_replace('\\', '/', $this->model)); + $table = $this->query->getTable(); + $model = basename(str_replace('\\', '/', get_class($this->parent))); + $relation = basename(str_replace('\\', '/', $this->model)); + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->field($model . '.*') ->join([$table => $relation], $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey, $joinType) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) ->group($relation . '.' . $this->foreignKey) ->having('count(' . $id . ')' . $operator . $count); } @@ -321,13 +325,17 @@ public function hasWhere($where = [], $fields = null) $this->getQueryWhere($where, $relation); } - $fields = $this->getRelationQueryFields($fields, $model); + $fields = $this->getRelationQueryFields($fields, $model); + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->group($model . '.' . $this->localKey) ->field($fields) ->join([$table => $relation], $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) ->where($where); } diff --git a/thinkphp/library/think/model/relation/HasManyThrough.php b/thinkphp/library/think/model/relation/HasManyThrough.php index 7c7acaa07..c048eb911 100644 --- a/thinkphp/library/think/model/relation/HasManyThrough.php +++ b/thinkphp/library/think/model/relation/HasManyThrough.php @@ -12,7 +12,6 @@ namespace think\model\relation; use think\db\Query; -use think\Exception; use think\Loader; use think\Model; use think\model\Relation; @@ -24,6 +23,12 @@ class HasManyThrough extends Relation // 中间表模型 protected $through; + /** + * 中间主键 + * @var string + */ + protected $throughPk; + /** * 架构函数 * @access public @@ -38,9 +43,10 @@ public function __construct(Model $parent, $model, $through, $foreignKey, $throu { $this->parent = $parent; $this->model = $model; - $this->through = $through; + $this->through = (new $through)->db(); $this->foreignKey = $foreignKey; $this->throughKey = $throughKey; + $this->throughPk = $this->through->getPk(); $this->localKey = $localKey; $this->query = (new $model)->db(); } @@ -74,7 +80,28 @@ public function getRelation($subRelation = '', $closure = null) */ public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER') { - return $this->parent; + $model = App::parseName(App::classBaseName($this->parent)); + $throughTable = $this->through->getTable(); + $pk = $this->throughPk; + $throughKey = $this->throughKey; + $relation = (new $this->model)->db(); + $relationTable = $relation->getTable(); + $softDelete = $this->query->getOptions('soft_delete'); + + if ('*' != $id) { + $id = $relationTable . '.' . $relation->getPk(); + } + + return $this->parent->db() + ->alias($model) + ->field($model . '.*') + ->join($throughTable, $throughTable . '.' . $this->foreignKey . '=' . $model . '.' . $this->localKey) + ->join($relationTable, $relationTable . '.' . $throughKey . '=' . $throughTable . '.' . $this->throughPk) + ->when($softDelete, function ($query) use ($softDelete, $relationTable) { + $query->where($relationTable . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) + ->group($relationTable . '.' . $this->throughKey) + ->having('count(' . $id . ')' . $operator . $count); } /** @@ -86,45 +113,225 @@ public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER' */ public function hasWhere($where = [], $fields = null) { - throw new Exception('relation not support: hasWhere'); + $model = App::parseName(App::classBaseName($this->parent)); + $throughTable = $this->through->getTable(); + $pk = $this->throughPk; + $throughKey = $this->throughKey; + $modelTable = (new $this->model)->db()->getTable(); + + if (is_array($where)) { + $this->getQueryWhere($where, $modelTable); + } + + $fields = $this->getRelationQueryFields($fields, $model); + $softDelete = $this->query->getOptions('soft_delete'); + + return $this->parent->db() + ->alias($model) + ->join($throughTable, $throughTable . '.' . $this->foreignKey . '=' . $model . '.' . $this->localKey) + ->join($modelTable, $modelTable . '.' . $throughKey . '=' . $throughTable . '.' . $this->throughPk) + ->when($softDelete, function ($query) use ($softDelete, $modelTable) { + $query->where($modelTable . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) + ->group($modelTable . '.' . $this->throughKey) + ->where($where) + ->field($fields); } /** - * 预载入关联查询 - * @access public - * @param array $resultSet 数据集 - * @param string $relation 当前关联名 - * @param string $subRelation 子关联名 - * @param \Closure $closure 闭包 + * 预载入关联查询(数据集) + * @access protected + * @param array $resultSet 数据集 + * @param string $relation 当前关联名 + * @param array $subRelation 子关联名 + * @param Closure $closure 闭包 * @return void */ - public function eagerlyResultSet(&$resultSet, $relation, $subRelation, $closure) - {} + public function eagerlyResultSet(array &$resultSet, $relation, array $subRelation = [], $closure = null) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + + $range = []; + foreach ($resultSet as $result) { + // 获取关联外键列表 + if (isset($result->$localKey)) { + $range[] = $result->$localKey; + } + } + + if (!empty($range)) { + $this->query->removeWhereField($foreignKey); + + $data = $this->eagerlyWhere([ + [$this->foreignKey, 'in', $range], + ], $foreignKey, $relation, $subRelation, $closure); + + // 关联属性名 + $attr = App::parseName($relation); + + // 关联数据封装 + foreach ($resultSet as $result) { + $pk = $result->$localKey; + if (!isset($data[$pk])) { + $data[$pk] = []; + } + + foreach ($data[$pk] as &$relationModel) { + $relationModel->setParent(clone $result); + } + + // 设置关联属性 + $result->setRelation($attr, $this->resultSetBuild($data[$pk])); + } + } + } /** - * 预载入关联查询 返回模型对象 - * @access public - * @param Model $result 数据对象 - * @param string $relation 当前关联名 - * @param string $subRelation 子关联名 - * @param \Closure $closure 闭包 + * 预载入关联查询(数据) + * @access protected + * @param Model $result 数据对象 + * @param string $relation 当前关联名 + * @param array $subRelation 子关联名 + * @param Closure $closure 闭包 * @return void */ - public function eagerlyResult(&$result, $relation, $subRelation, $closure) - {} + public function eagerlyResult($result, $relation, array $subRelation = [], $closure = null) + { + $localKey = $this->localKey; + $foreignKey = $this->foreignKey; + $pk = $result->$localKey; + + $this->query->removeWhereField($foreignKey); + + $data = $this->eagerlyWhere([ + [$foreignKey, '=', $pk], + ], $foreignKey, $relation, $subRelation, $closure); + + // 关联数据封装 + if (!isset($data[$pk])) { + $data[$pk] = []; + } + + foreach ($data[$pk] as &$relationModel) { + $relationModel->setParent(clone $result); + } + + $result->setRelation(App::parseName($relation), $this->resultSetBuild($data[$pk])); + } + + /** + * 关联模型预查询 + * @access public + * @param array $where 关联预查询条件 + * @param string $key 关联键名 + * @param string $relation 关联名 + * @param array $subRelation 子关联 + * @param Closure $closure + * @return array + */ + protected function eagerlyWhere(array $where, $key, $relation, array $subRelation = [], $closure = null) + { + // 预载入关联查询 支持嵌套预载入 + $throughList = $this->through->where($where)->select(); + $keys = $throughList->column($this->throughPk, $this->throughPk); + + if ($closure) { + $closure($this->query); + } + + $list = $this->query->where($this->throughKey, 'in', $keys)->select(); + + // 组装模型数据 + $data = []; + $keys = $throughList->column($this->foreignKey, $this->throughPk); + + foreach ($list as $set) { + $data[$keys[$set->{$this->throughKey}]][] = $set; + } + + return $data; + } /** * 关联统计 * @access public - * @param Model $result 数据对象 - * @param \Closure $closure 闭包 - * @param string $aggregate 聚合查询方法 - * @param string $field 字段 - * @param string $name 统计字段别名 + * @param Model $result 数据对象 + * @param Closure $closure 闭包 + * @param string $aggregate 聚合查询方法 + * @param string $field 字段 + * @param string $name 统计字段别名 * @return integer */ - public function relationCount($result, $closure, $aggregate = 'count', $field = '*', &$name = '') - {} + public function relationCount($result, $closure, $aggregate = 'count', $field = '*', &$name = null) + { + $localKey = $this->localKey; + + if (!isset($result->$localKey)) { + return 0; + } + + if ($closure) { + $return = $closure($this->query); + if ($return && is_string($return)) { + $name = $return; + } + } + + $alias = App::parseName(App::classBaseName($this->model)); + $throughTable = $this->through->getTable(); + $pk = $this->throughPk; + $throughKey = $this->throughKey; + $modelTable = $this->parent->getTable(); + + if (false === strpos($field, '.')) { + $field = $alias . '.' . $field; + } + + return $this->query + ->alias($alias) + ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) + ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) + ->where($throughTable . '.' . $this->foreignKey, $result->$localKey) + ->$aggregate($field); + } + + /** + * 创建关联统计子查询 + * @access public + * @param Closure $closure 闭包 + * @param string $aggregate 聚合查询方法 + * @param string $field 字段 + * @param string $name 统计字段别名 + * @return string + */ + public function getRelationCountQuery($closure = null, $aggregate = 'count', $field = '*', &$name = null) + { + if ($closure) { + $return = $closure($this->query); + if ($return && is_string($return)) { + $name = $return; + } + } + + $alias = App::parseName(App::classBaseName($this->model)); + $throughTable = $this->through->getTable(); + $pk = $this->throughPk; + $throughKey = $this->throughKey; + $modelTable = $this->parent->getTable(); + + if (false === strpos($field, '.')) { + $field = $alias . '.' . $field; + } + + return $this->query + ->alias($alias) + ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) + ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) + ->whereExp($throughTable . '.' . $this->foreignKey, '=' . $this->parent->getTable() . '.' . $this->localKey) + ->fetchSql() + ->$aggregate($field); + } /** * 执行基础查询(仅执行一次) @@ -134,10 +341,9 @@ public function relationCount($result, $closure, $aggregate = 'count', $field = protected function baseQuery() { if (empty($this->baseQuery) && $this->parent->getData()) { - $through = $this->through; $alias = Loader::parseName(basename(str_replace('\\', '/', $this->model))); - $throughTable = $through::getTable(); - $pk = (new $through)->getPk(); + $throughTable = $this->through->getTable(); + $pk = $this->throughPk; $throughKey = $this->throughKey; $modelTable = $this->parent->getTable(); $fields = $this->getQueryFields($alias); diff --git a/thinkphp/library/think/model/relation/HasOne.php b/thinkphp/library/think/model/relation/HasOne.php index d8e3ec798..7d582a142 100644 --- a/thinkphp/library/think/model/relation/HasOne.php +++ b/thinkphp/library/think/model/relation/HasOne.php @@ -139,13 +139,17 @@ public function has($operator = '>=', $count = 1, $id = '*', $joinType = 'INNER' $relation = basename(str_replace('\\', '/', $this->model)); $localKey = $this->localKey; $foreignKey = $this->foreignKey; + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->whereExists(function ($query) use ($table, $model, $relation, $localKey, $foreignKey) { $query->table([$table => $relation]) ->field($relation . '.' . $foreignKey) - ->whereExp($model . '.' . $localKey, '=' . $relation . '.' . $foreignKey); + ->whereExp($model . '.' . $localKey, '=' . $relation . '.' . $foreignKey) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }); }); } @@ -166,12 +170,16 @@ public function hasWhere($where = [], $fields = null) $this->getQueryWhere($where, $relation); } - $fields = $this->getRelationQueryFields($fields, $model); + $fields = $this->getRelationQueryFields($fields, $model); + $softDelete = $this->query->getOptions('soft_delete'); return $this->parent->db() ->alias($model) ->field($fields) ->join([$table => $relation], $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey, $this->joinType) + ->when($softDelete, function ($query) use ($softDelete, $relation) { + $query->where($relation . strstr($softDelete[0], '.'), '=' == $softDelete[1][0] ? $softDelete[1][1] : null); + }) ->where($where); } diff --git a/thinkphp/library/think/response/View.php b/thinkphp/library/think/response/View.php index c836ccb5d..3d54c7352 100644 --- a/thinkphp/library/think/response/View.php +++ b/thinkphp/library/think/response/View.php @@ -18,9 +18,16 @@ class View extends Response // 输出参数 protected $options = []; protected $vars = []; + protected $config = []; protected $filter; protected $contentType = 'text/html'; + /** + * 是否内容渲染 + * @var bool + */ + protected $isContent = false; + /** * 处理数据 * @access protected @@ -32,7 +39,19 @@ protected function output($data) // 渲染模板输出 return $this->app['view'] ->filter($this->filter) - ->fetch($data, $this->vars); + ->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; } /** @@ -68,6 +87,12 @@ public function assign($name, $value = '') return $this; } + public function config($config) + { + $this->config = $config; + return $this; + } + /** * 视图内容过滤 * @access public diff --git a/thinkphp/library/think/route/Dispatch.php b/thinkphp/library/think/route/Dispatch.php index 93afe73b6..7323c98db 100644 --- a/thinkphp/library/think/route/Dispatch.php +++ b/thinkphp/library/think/route/Dispatch.php @@ -11,9 +11,9 @@ namespace think\route; +use think\App; use think\Container; use think\exception\ValidateException; -use think\App; use think\Request; use think\Response; @@ -181,9 +181,10 @@ protected function autoResponse($data) $response = Response::create($data, $type); } else { - $data = ob_get_clean(); - $content = false === $data ? '' : $data; - $status = '' === $content && $this->request->isAjax() ? 204 : 200; + $data = ob_get_clean(); + $content = false === $data ? '' : $data; + $status = '' === $content && $this->request->isJson() ? 204 : 200; + $response = Response::create($content, '', $status); } diff --git a/thinkphp/library/think/route/dispatch/Module.php b/thinkphp/library/think/route/dispatch/Module.php index e8842cd3a..40bd77596 100644 --- a/thinkphp/library/think/route/dispatch/Module.php +++ b/thinkphp/library/think/route/dispatch/Module.php @@ -12,7 +12,6 @@ namespace think\route\dispatch; use ReflectionMethod; -use think\Controller; use think\exception\ClassNotFoundException; use think\exception\HttpException; use think\Loader; diff --git a/update.sql b/update.sql index 82fc226e6..7bab0f75a 100644 --- a/update.sql +++ b/update.sql @@ -76,3 +76,14 @@ UPDATE `lsky_config` SET `value` = '1.5.3' WHERE `lsky_config`.`name` = 'system_ -- v1.5.4 UPDATE `lsky_config` SET `value` = '1.5.4' WHERE `lsky_config`.`name` = 'system_version'; + +-- v1.5.5 +UPDATE `lsky_config` SET `value` = '1.5.5' WHERE `lsky_config`.`name` = 'system_version'; +INSERT IGNORE INTO `lsky_config` (`id`, `key`, `type`, `input_type`, `name`, `title`, `tip`, `value`, `extend`) VALUES +(NULL, 'basics', 'textarea', 'textarea', 'notice', '系统公告', '支持html', '', ''), +(NULL, 'remote', 'text', 'text', 'remote_cdn_domain', '域名', NULL, '', ''), +(NULL, 'remote', 'select', 'text', 'remote_type', '远程储存类型', NULL, 'ftp', '{\"ftp\":\"Ftp\"}'), +(NULL, 'remote', 'text', 'text', 'remote_host', '连接地址', NULL, '', ''), +(NULL, 'remote', 'text', 'text', 'remote_name', '登录账号', NULL, '', ''), +(NULL, 'remote', 'text', 'password', 'remote_password', '登录密码', NULL, '', ''), +(NULL, 'remote', 'text', 'number', 'remote_port', '连接端口', NULL, '21', ''); diff --git a/vendor/aliyuncs/oss-sdk-php/build-phar.sh b/vendor/aliyuncs/oss-sdk-php/build-phar.sh old mode 100644 new mode 100755 diff --git a/vendor/autoload.php b/vendor/autoload.php index d224ed8ba..68e745beb 100644 --- a/vendor/autoload.php +++ b/vendor/autoload.php @@ -4,4 +4,4 @@ require_once __DIR__ . '/composer/autoload_real.php'; -return ComposerAutoloaderInit04f78adc0d26d025ab398ddde054e232::getLoader(); +return ComposerAutoloaderInitf1a511e38c2f284964a16f1eeccf1745::getLoader(); diff --git a/vendor/composer/autoload_namespaces.php b/vendor/composer/autoload_namespaces.php index 3fde43ef9..56d77c0ff 100644 --- a/vendor/composer/autoload_namespaces.php +++ b/vendor/composer/autoload_namespaces.php @@ -9,4 +9,5 @@ 'Qcloud\\Cos\\' => array($vendorDir . '/qcloud/cos-sdk-v5/src'), 'Guzzle\\Tests' => array($vendorDir . '/guzzle/guzzle/tests'), 'Guzzle' => array($vendorDir . '/guzzle/guzzle/src'), + 'FtpClient' => array($vendorDir . '/nicolab/php-ftp-client/src'), ); diff --git a/vendor/composer/autoload_real.php b/vendor/composer/autoload_real.php index f7d0a7882..acafc3893 100644 --- a/vendor/composer/autoload_real.php +++ b/vendor/composer/autoload_real.php @@ -2,7 +2,7 @@ // autoload_real.php @generated by Composer -class ComposerAutoloaderInit04f78adc0d26d025ab398ddde054e232 +class ComposerAutoloaderInitf1a511e38c2f284964a16f1eeccf1745 { private static $loader; @@ -19,15 +19,15 @@ public static function getLoader() return self::$loader; } - spl_autoload_register(array('ComposerAutoloaderInit04f78adc0d26d025ab398ddde054e232', 'loadClassLoader'), true, true); + spl_autoload_register(array('ComposerAutoloaderInitf1a511e38c2f284964a16f1eeccf1745', 'loadClassLoader'), true, true); self::$loader = $loader = new \Composer\Autoload\ClassLoader(); - spl_autoload_unregister(array('ComposerAutoloaderInit04f78adc0d26d025ab398ddde054e232', 'loadClassLoader')); + spl_autoload_unregister(array('ComposerAutoloaderInitf1a511e38c2f284964a16f1eeccf1745', 'loadClassLoader')); $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded()); if ($useStaticLoader) { require_once __DIR__ . '/autoload_static.php'; - call_user_func(\Composer\Autoload\ComposerStaticInit04f78adc0d26d025ab398ddde054e232::getInitializer($loader)); + call_user_func(\Composer\Autoload\ComposerStaticInitf1a511e38c2f284964a16f1eeccf1745::getInitializer($loader)); } else { $map = require __DIR__ . '/autoload_namespaces.php'; foreach ($map as $namespace => $path) { @@ -48,19 +48,19 @@ public static function getLoader() $loader->register(true); if ($useStaticLoader) { - $includeFiles = Composer\Autoload\ComposerStaticInit04f78adc0d26d025ab398ddde054e232::$files; + $includeFiles = Composer\Autoload\ComposerStaticInitf1a511e38c2f284964a16f1eeccf1745::$files; } else { $includeFiles = require __DIR__ . '/autoload_files.php'; } foreach ($includeFiles as $fileIdentifier => $file) { - composerRequire04f78adc0d26d025ab398ddde054e232($fileIdentifier, $file); + composerRequiref1a511e38c2f284964a16f1eeccf1745($fileIdentifier, $file); } return $loader; } } -function composerRequire04f78adc0d26d025ab398ddde054e232($fileIdentifier, $file) +function composerRequiref1a511e38c2f284964a16f1eeccf1745($fileIdentifier, $file) { if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) { require $file; diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index 4e4ef451d..43701fe08 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -4,7 +4,7 @@ namespace Composer\Autoload; -class ComposerStaticInit04f78adc0d26d025ab398ddde054e232 +class ComposerStaticInitf1a511e38c2f284964a16f1eeccf1745 { public static $files = array ( '7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php', @@ -129,14 +129,21 @@ class ComposerStaticInit04f78adc0d26d025ab398ddde054e232 0 => __DIR__ . '/..' . '/guzzle/guzzle/src', ), ), + 'F' => + array ( + 'FtpClient' => + array ( + 0 => __DIR__ . '/..' . '/nicolab/php-ftp-client/src', + ), + ), ); public static function getInitializer(ClassLoader $loader) { return \Closure::bind(function () use ($loader) { - $loader->prefixLengthsPsr4 = ComposerStaticInit04f78adc0d26d025ab398ddde054e232::$prefixLengthsPsr4; - $loader->prefixDirsPsr4 = ComposerStaticInit04f78adc0d26d025ab398ddde054e232::$prefixDirsPsr4; - $loader->prefixesPsr0 = ComposerStaticInit04f78adc0d26d025ab398ddde054e232::$prefixesPsr0; + $loader->prefixLengthsPsr4 = ComposerStaticInitf1a511e38c2f284964a16f1eeccf1745::$prefixLengthsPsr4; + $loader->prefixDirsPsr4 = ComposerStaticInitf1a511e38c2f284964a16f1eeccf1745::$prefixDirsPsr4; + $loader->prefixesPsr0 = ComposerStaticInitf1a511e38c2f284964a16f1eeccf1745::$prefixesPsr0; }, null, ClassLoader::class); } diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index 2811bb5c3..fc39cdcb8 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -154,17 +154,17 @@ }, { "name": "guzzlehttp/guzzle", - "version": "6.3.3", - "version_normalized": "6.3.3.0", + "version": "6.4.1", + "version_normalized": "6.4.1.0", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba" + "reference": "0895c932405407fd3a7368b6910c09a24d26db11" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/407b0cb880ace85c9b63c5f9551db498cb2d50ba", - "reference": "407b0cb880ace85c9b63c5f9551db498cb2d50ba", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/0895c932405407fd3a7368b6910c09a24d26db11", + "reference": "0895c932405407fd3a7368b6910c09a24d26db11", "shasum": "", "mirrors": [ { @@ -174,19 +174,20 @@ ] }, "require": { + "ext-json": "*", "guzzlehttp/promises": "^1.0", - "guzzlehttp/psr7": "^1.4", + "guzzlehttp/psr7": "^1.6.1", "php": ">=5.5" }, "require-dev": { "ext-curl": "*", "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", - "psr/log": "^1.0" + "psr/log": "^1.1" }, "suggest": { "psr/log": "Required for using the Log middleware" }, - "time": "2018-04-22T15:46:56+00:00", + "time": "2019-10-23T15:58:00+00:00", "type": "library", "extra": { "branch-alias": { @@ -195,12 +196,12 @@ }, "installation-source": "dist", "autoload": { - "files": [ - "src/functions_include.php" - ], "psr-4": { "GuzzleHttp\\": "src/" - } + }, + "files": [ + "src/functions_include.php" + ] }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -363,19 +364,76 @@ "url" ] }, + { + "name": "nicolab/php-ftp-client", + "version": "v1.5.1", + "version_normalized": "1.5.1.0", + "source": { + "type": "git", + "url": "https://github.com/Nicolab/php-ftp-client.git", + "reference": "8c66e1104da1b638f5d7a9e24624a5525b459a0c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/Nicolab/php-ftp-client/zipball/8c66e1104da1b638f5d7a9e24624a5525b459a0c", + "reference": "8c66e1104da1b638f5d7a9e24624a5525b459a0c", + "shasum": "", + "mirrors": [ + { + "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%", + "preferred": true + } + ] + }, + "require": { + "ext-ftp": "*", + "php": ">=5.4" + }, + "time": "2019-04-23T09:22:37+00:00", + "type": "library", + "installation-source": "dist", + "autoload": { + "psr-0": { + "FtpClient": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Tallefourtane", + "email": "dev@nicolab.net", + "homepage": "http://nicolab.net" + } + ], + "description": "A flexible FTP and SSL-FTP client for PHP. This lib provides helpers easy to use to manage the remote files.", + "homepage": "https://github.com/Nicolab/php-ftp-client", + "keywords": [ + "file", + "ftp", + "helper", + "lib", + "server", + "sftp", + "ssl", + "ssl-ftp" + ] + }, { "name": "phpmailer/phpmailer", - "version": "v6.0.7", - "version_normalized": "6.0.7.0", + "version": "v6.1.1", + "version_normalized": "6.1.1.0", "source": { "type": "git", "url": "https://github.com/PHPMailer/PHPMailer.git", - "reference": "0c41a36d4508d470e376498c1c0c527aa36a2d59" + "reference": "26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/0c41a36d4508d470e376498c1c0c527aa36a2d59", - "reference": "0c41a36d4508d470e376498c1c0c527aa36a2d59", + "url": "https://api.github.com/repos/PHPMailer/PHPMailer/zipball/26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8", + "reference": "26bd96350b0b2fcbf0ef4e6f0f9cf3528302a9d8", "shasum": "", "mirrors": [ { @@ -406,7 +464,7 @@ "stevenmaguire/oauth2-microsoft": "Needed for Microsoft XOAUTH2 authentication", "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)" }, - "time": "2019-02-01T15:04:28+00:00", + "time": "2019-09-27T21:33:43+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -416,17 +474,17 @@ }, "notification-url": "https://packagist.org/downloads/", "license": [ - "LGPL-2.1" + "LGPL-2.1-only" ], "authors": [ - { - "name": "Jim Jagielski", - "email": "jimjag@gmail.com" - }, { "name": "Marcus Bointon", "email": "phpmailer@synchromedia.co.uk" }, + { + "name": "Jim Jagielski", + "email": "jimjag@gmail.com" + }, { "name": "Andy Prevost", "email": "codeworxtech@users.sourceforge.net" @@ -497,17 +555,17 @@ }, { "name": "qcloud/cos-sdk-v5", - "version": "v1.3.2", - "version_normalized": "1.3.2.0", + "version": "v1.3.4", + "version_normalized": "1.3.4.0", "source": { "type": "git", "url": "https://github.com/tencentyun/cos-php-sdk-v5.git", - "reference": "0454f48629210749ae6316ab317548169dac9d8f" + "reference": "1b32aa422f6dffe4ea411e5095e4b0da9135551b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/0454f48629210749ae6316ab317548169dac9d8f", - "reference": "0454f48629210749ae6316ab317548169dac9d8f", + "url": "https://api.github.com/repos/tencentyun/cos-php-sdk-v5/zipball/1b32aa422f6dffe4ea411e5095e4b0da9135551b", + "reference": "1b32aa422f6dffe4ea411e5095e4b0da9135551b", "shasum": "", "mirrors": [ { @@ -520,7 +578,7 @@ "guzzle/guzzle": "~3.7", "php": ">=5.3.0" }, - "time": "2019-04-25T12:23:41+00:00", + "time": "2019-09-02T12:08:44+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -551,17 +609,17 @@ }, { "name": "qiniu/php-sdk", - "version": "v7.2.9", - "version_normalized": "7.2.9.0", + "version": "v7.2.10", + "version_normalized": "7.2.10.0", "source": { "type": "git", "url": "https://github.com/qiniu/php-sdk.git", - "reference": "afe7d8715d8a688b1d8d8cdf031240d2363dad90" + "reference": "d89987163f560ebf9dfa5bb25de9bd9b1a3b2bd8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/qiniu/php-sdk/zipball/afe7d8715d8a688b1d8d8cdf031240d2363dad90", - "reference": "afe7d8715d8a688b1d8d8cdf031240d2363dad90", + "url": "https://api.github.com/repos/qiniu/php-sdk/zipball/d89987163f560ebf9dfa5bb25de9bd9b1a3b2bd8", + "reference": "d89987163f560ebf9dfa5bb25de9bd9b1a3b2bd8", "shasum": "", "mirrors": [ { @@ -577,7 +635,7 @@ "phpunit/phpunit": "~4.0", "squizlabs/php_codesniffer": "~2.3" }, - "time": "2019-07-09T07:55:07+00:00", + "time": "2019-10-28T10:23:23+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -726,17 +784,17 @@ }, { "name": "topthink/framework", - "version": "v5.1.37.1", - "version_normalized": "5.1.37.1", + "version": "v5.1.38.1", + "version_normalized": "5.1.38.1", "source": { "type": "git", "url": "https://github.com/top-think/framework.git", - "reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b" + "reference": "12d15c29d5d6a972fc8bfc8db005d64d4786028c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/top-think/framework/zipball/05eecd121d18d6705aaa10aa44fcdf7c14da4d0b", - "reference": "05eecd121d18d6705aaa10aa44fcdf7c14da4d0b", + "url": "https://api.github.com/repos/top-think/framework/zipball/12d15c29d5d6a972fc8bfc8db005d64d4786028c", + "reference": "12d15c29d5d6a972fc8bfc8db005d64d4786028c", "shasum": "", "mirrors": [ { @@ -758,7 +816,7 @@ "sebastian/phpcpd": "2.*", "squizlabs/php_codesniffer": "2.*" }, - "time": "2019-05-28T06:57:29+00:00", + "time": "2019-08-12T00:58:30+00:00", "type": "think-framework", "installation-source": "dist", "notification-url": "https://packagist.org/downloads/", @@ -929,17 +987,17 @@ }, { "name": "upyun/sdk", - "version": "3.3.0", - "version_normalized": "3.3.0.0", + "version": "3.4.0", + "version_normalized": "3.4.0.0", "source": { "type": "git", "url": "https://github.com/upyun/php-sdk.git", - "reference": "1a2dd5ae31047956c733aef0f764f3a527d30628" + "reference": "b4819fd941e3f19a886f8b3c5f8bffcb8279185f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/upyun/php-sdk/zipball/1a2dd5ae31047956c733aef0f764f3a527d30628", - "reference": "1a2dd5ae31047956c733aef0f764f3a527d30628", + "url": "https://api.github.com/repos/upyun/php-sdk/zipball/b4819fd941e3f19a886f8b3c5f8bffcb8279185f", + "reference": "b4819fd941e3f19a886f8b3c5f8bffcb8279185f", "shasum": "", "mirrors": [ { @@ -958,7 +1016,7 @@ "phpdocumentor/phpdocumentor": "^2.9", "phpunit/phpunit": "~4.0" }, - "time": "2017-11-12T09:17:42+00:00", + "time": "2019-04-29T09:27:51+00:00", "type": "library", "installation-source": "dist", "autoload": { @@ -971,10 +1029,6 @@ "MIT" ], "authors": [ - { - "name": "totoleo", - "email": "totoleo@163.com" - }, { "name": "lfeng", "email": "bonevv@gmail.com" @@ -983,6 +1037,10 @@ "name": "lvtongda", "email": "riyao.lyu@gmail.com" }, + { + "name": "totoleo", + "email": "totoleo@163.com" + }, { "name": "sabakugaara", "email": "senellise@gmail.com" diff --git a/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/RedirectPluginTest.php b/vendor/guzzle/guzzle/tests/Guzzle/Tests/Http/RedirectPluginTest.php old mode 100644 new mode 100755 diff --git a/vendor/guzzlehttp/guzzle/.php_cs b/vendor/guzzlehttp/guzzle/.php_cs new file mode 100644 index 000000000..a8ace8aab --- /dev/null +++ b/vendor/guzzlehttp/guzzle/.php_cs @@ -0,0 +1,21 @@ +setRiskyAllowed(true) + ->setRules([ + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + 'declare_strict_types' => false, + 'concat_space' => ['spacing'=>'one'], + // 'ordered_imports' => true, + // 'phpdoc_align' => ['align'=>'vertical'], + // 'native_function_invocation' => true, + ]) + ->setFinder( + PhpCsFixer\Finder::create() + ->in(__DIR__.'/src') + ->name('*.php') + ) +; + +return $config; diff --git a/vendor/guzzlehttp/guzzle/CHANGELOG.md b/vendor/guzzlehttp/guzzle/CHANGELOG.md index 17badd756..65557498b 100644 --- a/vendor/guzzlehttp/guzzle/CHANGELOG.md +++ b/vendor/guzzlehttp/guzzle/CHANGELOG.md @@ -1,5 +1,22 @@ # Change Log +## 6.4.1 - 2019-10-23 + +* No `guzzle.phar` was created in 6.4.0 due expired API token. This release will fix that +* Added `parent::__construct()` to `FileCookieJar` and `SessionCookieJar` + +## 6.4.0 - 2019-10-23 + +* Improvement: Improved error messages when using curl < 7.21.2 [#2108](https://github.com/guzzle/guzzle/pull/2108) +* Fix: Test if response is readable before returning a summary in `RequestException::getResponseBodySummary()` [#2081](https://github.com/guzzle/guzzle/pull/2081) +* Fix: Add support for GUZZLE_CURL_SELECT_TIMEOUT environment variable [#2161](https://github.com/guzzle/guzzle/pull/2161) +* Improvement: Added `GuzzleHttp\Exception\InvalidArgumentException` [#2163](https://github.com/guzzle/guzzle/pull/2163) +* Improvement: Added `GuzzleHttp\_current_time()` to use `hrtime()` if that function exists. [#2242](https://github.com/guzzle/guzzle/pull/2242) +* Improvement: Added curl's `appconnect_time` in `TransferStats` [#2284](https://github.com/guzzle/guzzle/pull/2284) +* Improvement: Make GuzzleException extend Throwable wherever it's available [#2273](https://github.com/guzzle/guzzle/pull/2273) +* Fix: Prevent concurrent writes to file when saving `CookieJar` [#2335](https://github.com/guzzle/guzzle/pull/2335) +* Improvement: Update `MockHandler` so we can test transfer time [#2362](https://github.com/guzzle/guzzle/pull/2362) + ## 6.3.3 - 2018-04-22 * Fix: Default headers when decode_content is specified diff --git a/vendor/guzzlehttp/guzzle/Dockerfile b/vendor/guzzlehttp/guzzle/Dockerfile new file mode 100644 index 000000000..f6a095230 --- /dev/null +++ b/vendor/guzzlehttp/guzzle/Dockerfile @@ -0,0 +1,18 @@ +FROM composer:latest as setup + +RUN mkdir /guzzle + +WORKDIR /guzzle + +RUN set -xe \ + && composer init --name=guzzlehttp/test --description="Simple project for testing Guzzle scripts" --author="Márk Sági-Kazár " --no-interaction \ + && composer require guzzlehttp/guzzle + + +FROM php:7.3 + +RUN mkdir /guzzle + +WORKDIR /guzzle + +COPY --from=setup /guzzle /guzzle diff --git a/vendor/guzzlehttp/guzzle/README.md b/vendor/guzzlehttp/guzzle/README.md index bcd18b8e7..a5ef18aee 100644 --- a/vendor/guzzlehttp/guzzle/README.md +++ b/vendor/guzzlehttp/guzzle/README.md @@ -21,19 +21,18 @@ trivial to integrate with web services. ```php $client = new \GuzzleHttp\Client(); -$res = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle'); -echo $res->getStatusCode(); -// 200 -echo $res->getHeaderLine('content-type'); -// 'application/json; charset=utf8' -echo $res->getBody(); -// '{"id": 1420053, "name": "guzzle", ...}' - -// Send an asynchronous request. +$response = $client->request('GET', 'https://api.github.com/repos/guzzle/guzzle'); + +echo $response->getStatusCode(); # 200 +echo $response->getHeaderLine('content-type'); # 'application/json; charset=utf8' +echo $response->getBody(); # '{"id": 1420053, "name": "guzzle", ...}' + +# Send an asynchronous request. $request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org'); $promise = $client->sendAsync($request)->then(function ($response) { echo 'I completed! ' . $response->getBody(); }); + $promise->wait(); ``` @@ -57,7 +56,7 @@ curl -sS https://getcomposer.org/installer | php Next, run the Composer command to install the latest stable version of Guzzle: ```bash -php composer.phar require guzzlehttp/guzzle +composer require guzzlehttp/guzzle ``` After installing, you need to require Composer's autoloader: @@ -69,7 +68,7 @@ require 'vendor/autoload.php'; You can then later update Guzzle using composer: ```bash -composer.phar update +composer update ``` @@ -86,6 +85,6 @@ composer.phar update [guzzle-4-repo]: https://github.com/guzzle/guzzle/tree/4.x [guzzle-5-repo]: https://github.com/guzzle/guzzle/tree/5.3 [guzzle-6-repo]: https://github.com/guzzle/guzzle -[guzzle-3-docs]: http://guzzle3.readthedocs.org/en/latest/ +[guzzle-3-docs]: http://guzzle3.readthedocs.org [guzzle-5-docs]: http://guzzle.readthedocs.org/en/5.3/ [guzzle-6-docs]: http://guzzle.readthedocs.org/en/latest/ diff --git a/vendor/guzzlehttp/guzzle/composer.json b/vendor/guzzlehttp/guzzle/composer.json index 1f328e308..c55325753 100644 --- a/vendor/guzzlehttp/guzzle/composer.json +++ b/vendor/guzzlehttp/guzzle/composer.json @@ -2,7 +2,15 @@ "name": "guzzlehttp/guzzle", "type": "library", "description": "Guzzle is a PHP HTTP client library", - "keywords": ["framework", "http", "rest", "web service", "curl", "client", "HTTP client"], + "keywords": [ + "framework", + "http", + "rest", + "web service", + "curl", + "client", + "HTTP client" + ], "homepage": "http://guzzlephp.org/", "license": "MIT", "authors": [ @@ -14,31 +22,37 @@ ], "require": { "php": ">=5.5", - "guzzlehttp/psr7": "^1.4", - "guzzlehttp/promises": "^1.0" + "ext-json": "*", + "guzzlehttp/promises": "^1.0", + "guzzlehttp/psr7": "^1.6.1" }, "require-dev": { "ext-curl": "*", "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.4 || ^7.0", - "psr/log": "^1.0" + "psr/log": "^1.1" + }, + "suggest": { + "psr/log": "Required for using the Log middleware" + }, + "config": { + "sort-packages": true + }, + "extra": { + "branch-alias": { + "dev-master": "6.3-dev" + } }, "autoload": { - "files": ["src/functions_include.php"], "psr-4": { "GuzzleHttp\\": "src/" - } + }, + "files": [ + "src/functions_include.php" + ] }, "autoload-dev": { "psr-4": { "GuzzleHttp\\Tests\\": "tests/" } - }, - "suggest": { - "psr/log": "Required for using the Log middleware" - }, - "extra": { - "branch-alias": { - "dev-master": "6.3-dev" - } } } diff --git a/vendor/guzzlehttp/guzzle/phpstan.neon.dist b/vendor/guzzlehttp/guzzle/phpstan.neon.dist new file mode 100644 index 000000000..4ef4192d3 --- /dev/null +++ b/vendor/guzzlehttp/guzzle/phpstan.neon.dist @@ -0,0 +1,9 @@ +parameters: + level: 1 + paths: + - src + + ignoreErrors: + - + message: '#Function uri_template not found#' + path: %currentWorkingDirectory%/src/functions.php diff --git a/vendor/guzzlehttp/guzzle/src/Client.php b/vendor/guzzlehttp/guzzle/src/Client.php index 80417918d..0f43c71f0 100644 --- a/vendor/guzzlehttp/guzzle/src/Client.php +++ b/vendor/guzzlehttp/guzzle/src/Client.php @@ -210,7 +210,7 @@ private function configureDefaults(array $config) * * @return array */ - private function prepareDefaults($options) + private function prepareDefaults(array $options) { $defaults = $this->config; diff --git a/vendor/guzzlehttp/guzzle/src/ClientInterface.php b/vendor/guzzlehttp/guzzle/src/ClientInterface.php index 2dbcffa49..5b3708514 100644 --- a/vendor/guzzlehttp/guzzle/src/ClientInterface.php +++ b/vendor/guzzlehttp/guzzle/src/ClientInterface.php @@ -12,7 +12,7 @@ */ interface ClientInterface { - const VERSION = '6.3.3'; + const VERSION = '6.4.1'; /** * Send an HTTP request. diff --git a/vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php b/vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php index 78f2b79fe..286264261 100644 --- a/vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php +++ b/vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php @@ -120,7 +120,7 @@ public function clear($domain = null, $path = null, $name = null) } elseif (!$path) { $this->cookies = array_filter( $this->cookies, - function (SetCookie $cookie) use ($path, $domain) { + function (SetCookie $cookie) use ($domain) { return !$cookie->matchesDomain($domain); } ); diff --git a/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php b/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php index 9887c1d54..3fb8600ef 100644 --- a/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php +++ b/vendor/guzzlehttp/guzzle/src/Cookie/FileCookieJar.php @@ -23,6 +23,7 @@ class FileCookieJar extends CookieJar */ public function __construct($cookieFile, $storeSessionCookies = false) { + parent::__construct(); $this->filename = $cookieFile; $this->storeSessionCookies = $storeSessionCookies; @@ -56,7 +57,7 @@ public function save($filename) } $jsonStr = \GuzzleHttp\json_encode($json); - if (false === file_put_contents($filename, $jsonStr)) { + if (false === file_put_contents($filename, $jsonStr, LOCK_EX)) { throw new \RuntimeException("Unable to save file {$filename}"); } } diff --git a/vendor/guzzlehttp/guzzle/src/Cookie/SessionCookieJar.php b/vendor/guzzlehttp/guzzle/src/Cookie/SessionCookieJar.php index 4497bcf03..0224a2447 100644 --- a/vendor/guzzlehttp/guzzle/src/Cookie/SessionCookieJar.php +++ b/vendor/guzzlehttp/guzzle/src/Cookie/SessionCookieJar.php @@ -22,6 +22,7 @@ class SessionCookieJar extends CookieJar */ public function __construct($sessionKey, $storeSessionCookies = false) { + parent::__construct(); $this->sessionKey = $sessionKey; $this->storeSessionCookies = $storeSessionCookies; $this->load(); diff --git a/vendor/guzzlehttp/guzzle/src/Cookie/SetCookie.php b/vendor/guzzlehttp/guzzle/src/Cookie/SetCookie.php index f6993943e..3d776a70b 100644 --- a/vendor/guzzlehttp/guzzle/src/Cookie/SetCookie.php +++ b/vendor/guzzlehttp/guzzle/src/Cookie/SetCookie.php @@ -227,7 +227,7 @@ public function setExpires($timestamp) /** * Get whether or not this is a secure cookie * - * @return null|bool + * @return bool|null */ public function getSecure() { @@ -247,7 +247,7 @@ public function setSecure($secure) /** * Get whether or not this is a session cookie * - * @return null|bool + * @return bool|null */ public function getDiscard() { diff --git a/vendor/guzzlehttp/guzzle/src/Exception/ClientException.php b/vendor/guzzlehttp/guzzle/src/Exception/ClientException.php index f95c09f2b..4cfd393cc 100644 --- a/vendor/guzzlehttp/guzzle/src/Exception/ClientException.php +++ b/vendor/guzzlehttp/guzzle/src/Exception/ClientException.php @@ -4,4 +4,6 @@ /** * Exception when a client error is encountered (4xx codes) */ -class ClientException extends BadResponseException {} +class ClientException extends BadResponseException +{ +} diff --git a/vendor/guzzlehttp/guzzle/src/Exception/GuzzleException.php b/vendor/guzzlehttp/guzzle/src/Exception/GuzzleException.php index 510778f6e..27b2722b0 100644 --- a/vendor/guzzlehttp/guzzle/src/Exception/GuzzleException.php +++ b/vendor/guzzlehttp/guzzle/src/Exception/GuzzleException.php @@ -1,13 +1,23 @@ getBody(); - if (!$body->isSeekable()) { + if (!$body->isSeekable() || !$body->isReadable()) { return null; } diff --git a/vendor/guzzlehttp/guzzle/src/Exception/ServerException.php b/vendor/guzzlehttp/guzzle/src/Exception/ServerException.php index 7cdd34086..127094c14 100644 --- a/vendor/guzzlehttp/guzzle/src/Exception/ServerException.php +++ b/vendor/guzzlehttp/guzzle/src/Exception/ServerException.php @@ -4,4 +4,6 @@ /** * Exception when a server error is encountered (5xx codes) */ -class ServerException extends BadResponseException {} +class ServerException extends BadResponseException +{ +} diff --git a/vendor/guzzlehttp/guzzle/src/Exception/TooManyRedirectsException.php b/vendor/guzzlehttp/guzzle/src/Exception/TooManyRedirectsException.php index b60a9678d..fff05251d 100644 --- a/vendor/guzzlehttp/guzzle/src/Exception/TooManyRedirectsException.php +++ b/vendor/guzzlehttp/guzzle/src/Exception/TooManyRedirectsException.php @@ -1,4 +1,6 @@ handle); + $curlStats['appconnect_time'] = curl_getinfo($easy->handle, CURLINFO_APPCONNECT_TIME); $stats = new TransferStats( $easy->request, $easy->response, @@ -136,7 +140,9 @@ private static function finishError( $ctx = [ 'errno' => $easy->errno, 'error' => curl_error($easy->handle), + 'appconnect_time' => curl_getinfo($easy->handle, CURLINFO_APPCONNECT_TIME), ] + curl_getinfo($easy->handle); + $ctx[self::CURL_VERSION_STR] = curl_version()['version']; $factory->release($easy); // Retry when nothing is present or when curl failed to rewind. @@ -172,13 +178,22 @@ private static function createRejection(EasyHandle $easy, array $ctx) ) ); } - - $message = sprintf( - 'cURL error %s: %s (%s)', - $ctx['errno'], - $ctx['error'], - 'see http://curl.haxx.se/libcurl/c/libcurl-errors.html' - ); + if (version_compare($ctx[self::CURL_VERSION_STR], self::LOW_CURL_VERSION_NUMBER)) { + $message = sprintf( + 'cURL error %s: %s (%s)', + $ctx['errno'], + $ctx['error'], + 'see https://curl.haxx.se/libcurl/c/libcurl-errors.html' + ); + } else { + $message = sprintf( + 'cURL error %s: %s (%s) for %s', + $ctx['errno'], + $ctx['error'], + 'see https://curl.haxx.se/libcurl/c/libcurl-errors.html', + $easy->request->getUri() + ); + } // Create a connection exception if it was a specific error code. $error = isset($connectionErrors[$easy->errno]) diff --git a/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php b/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php index 2754d8e43..d8297623c 100644 --- a/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php +++ b/vendor/guzzlehttp/guzzle/src/Handler/CurlMultiHandler.php @@ -37,8 +37,14 @@ public function __construct(array $options = []) { $this->factory = isset($options['handle_factory']) ? $options['handle_factory'] : new CurlFactory(50); - $this->selectTimeout = isset($options['select_timeout']) - ? $options['select_timeout'] : 1; + + if (isset($options['select_timeout'])) { + $this->selectTimeout = $options['select_timeout']; + } elseif ($selectTimeout = getenv('GUZZLE_CURL_SELECT_TIMEOUT')) { + $this->selectTimeout = $selectTimeout; + } else { + $this->selectTimeout = 1; + } } public function __get($name) @@ -82,7 +88,7 @@ public function tick() { // Add any delayed handles if needed. if ($this->delays) { - $currentTime = microtime(true); + $currentTime = \GuzzleHttp\_current_time(); foreach ($this->delays as $id => $delay) { if ($currentTime >= $delay) { unset($this->delays[$id]); @@ -134,7 +140,7 @@ private function addRequest(array $entry) if (empty($easy->options['delay'])) { curl_multi_add_handle($this->_mh, $easy->handle); } else { - $this->delays[$id] = microtime(true) + ($easy->options['delay'] / 1000); + $this->delays[$id] = \GuzzleHttp\_current_time() + ($easy->options['delay'] / 1000); } } @@ -186,7 +192,7 @@ private function processMessages() private function timeToNext() { - $currentTime = microtime(true); + $currentTime = \GuzzleHttp\_current_time(); $nextTime = PHP_INT_MAX; foreach ($this->delays as $time) { if ($time < $nextTime) { diff --git a/vendor/guzzlehttp/guzzle/src/Handler/MockHandler.php b/vendor/guzzlehttp/guzzle/src/Handler/MockHandler.php index d892061c7..d5c449c1d 100644 --- a/vendor/guzzlehttp/guzzle/src/Handler/MockHandler.php +++ b/vendor/guzzlehttp/guzzle/src/Handler/MockHandler.php @@ -182,7 +182,8 @@ private function invokeStats( $reason = null ) { if (isset($options['on_stats'])) { - $stats = new TransferStats($request, $response, 0, $reason); + $transferTime = isset($options['transfer_time']) ? $options['transfer_time'] : 0; + $stats = new TransferStats($request, $response, $transferTime, $reason); call_user_func($options['on_stats'], $stats); } } diff --git a/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php b/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php index b686545ea..0dedd7da4 100644 --- a/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php +++ b/vendor/guzzlehttp/guzzle/src/Handler/StreamHandler.php @@ -33,7 +33,7 @@ public function __invoke(RequestInterface $request, array $options) usleep($options['delay'] * 1000); } - $startTime = isset($options['on_stats']) ? microtime(true) : null; + $startTime = isset($options['on_stats']) ? \GuzzleHttp\_current_time() : null; try { // Does not support the expect header. @@ -42,7 +42,7 @@ public function __invoke(RequestInterface $request, array $options) // Append a content-length header if body size is zero to match // cURL's behavior. if (0 === $request->getBody()->getSize()) { - $request = $request->withHeader('Content-Length', 0); + $request = $request->withHeader('Content-Length', '0'); } return $this->createResponse( @@ -82,7 +82,7 @@ private function invokeStats( $stats = new TransferStats( $request, $response, - microtime(true) - $startTime, + \GuzzleHttp\_current_time() - $startTime, $error, [] ); @@ -343,13 +343,25 @@ private function resolveHost(RequestInterface $request, array $options) if ('v4' === $options['force_ip_resolve']) { $records = dns_get_record($uri->getHost(), DNS_A); if (!isset($records[0]['ip'])) { - throw new ConnectException(sprintf("Could not resolve IPv4 address for host '%s'", $uri->getHost()), $request); + throw new ConnectException( + sprintf( + "Could not resolve IPv4 address for host '%s'", + $uri->getHost() + ), + $request + ); } $uri = $uri->withHost($records[0]['ip']); } elseif ('v6' === $options['force_ip_resolve']) { $records = dns_get_record($uri->getHost(), DNS_AAAA); if (!isset($records[0]['ipv6'])) { - throw new ConnectException(sprintf("Could not resolve IPv6 address for host '%s'", $uri->getHost()), $request); + throw new ConnectException( + sprintf( + "Could not resolve IPv6 address for host '%s'", + $uri->getHost() + ), + $request + ); } $uri = $uri->withHost('[' . $records[0]['ipv6'] . ']'); } diff --git a/vendor/guzzlehttp/guzzle/src/HandlerStack.php b/vendor/guzzlehttp/guzzle/src/HandlerStack.php index 24c46fd9f..f0016861e 100644 --- a/vendor/guzzlehttp/guzzle/src/HandlerStack.php +++ b/vendor/guzzlehttp/guzzle/src/HandlerStack.php @@ -206,7 +206,7 @@ public function resolve() } /** - * @param $name + * @param string $name * @return int */ private function findByName($name) @@ -223,10 +223,10 @@ private function findByName($name) /** * Splices a function into the middleware list at a specific position. * - * @param $findName - * @param $withName + * @param string $findName + * @param string $withName * @param callable $middleware - * @param $before + * @param bool $before */ private function splice($findName, $withName, callable $middleware, $before) { diff --git a/vendor/guzzlehttp/guzzle/src/Middleware.php b/vendor/guzzlehttp/guzzle/src/Middleware.php index d4ad75c94..bffc1974b 100644 --- a/vendor/guzzlehttp/guzzle/src/Middleware.php +++ b/vendor/guzzlehttp/guzzle/src/Middleware.php @@ -7,7 +7,6 @@ use GuzzleHttp\Psr7; use Psr\Http\Message\ResponseInterface; use Psr\Log\LoggerInterface; -use Psr\Log\LogLevel; /** * Functions used to create and wrap handlers with handler middleware. @@ -39,7 +38,7 @@ function ($response) use ($cookieJar, $request) { $cookieJar->extractCookies($request, $response); return $response; } - ); + ); }; }; } @@ -58,7 +57,7 @@ public static function httpErrors() return $handler($request, $options); } return $handler($request, $options)->then( - function (ResponseInterface $response) use ($request, $handler) { + function (ResponseInterface $response) use ($request) { $code = $response->getStatusCode(); if ($code < 400) { return $response; @@ -183,7 +182,7 @@ public static function retry(callable $decider, callable $delay = null) * * @return callable Returns a function that accepts the next handler. */ - public static function log(LoggerInterface $logger, MessageFormatter $formatter, $logLevel = LogLevel::INFO) + public static function log(LoggerInterface $logger, MessageFormatter $formatter, $logLevel = 'info' /* \Psr\Log\LogLevel::INFO */) { return function (callable $handler) use ($logger, $formatter, $logLevel) { return function ($request, array $options) use ($handler, $logger, $formatter, $logLevel) { diff --git a/vendor/guzzlehttp/guzzle/src/Pool.php b/vendor/guzzlehttp/guzzle/src/Pool.php index 8f1be33cd..05c854aeb 100644 --- a/vendor/guzzlehttp/guzzle/src/Pool.php +++ b/vendor/guzzlehttp/guzzle/src/Pool.php @@ -6,7 +6,7 @@ use GuzzleHttp\Promise\EachPromise; /** - * Sends and iterator of requests concurrently using a capped pool size. + * Sends an iterator of requests concurrently using a capped pool size. * * The pool will read from an iterator until it is cancelled or until the * iterator is consumed. When a request is yielded, the request is sent after diff --git a/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php b/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php index 131b77179..bff4e4e8a 100644 --- a/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php +++ b/vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php @@ -186,7 +186,7 @@ public function modifyRequest( if ($options['allow_redirects']['referer'] && $modify['uri']->getScheme() === $request->getUri()->getScheme() ) { - $uri = $request->getUri()->withUserInfo('', ''); + $uri = $request->getUri()->withUserInfo(''); $modify['set_headers']['Referer'] = (string) $uri; } else { $modify['remove_headers'][] = 'Referer'; diff --git a/vendor/guzzlehttp/guzzle/src/RequestOptions.php b/vendor/guzzlehttp/guzzle/src/RequestOptions.php index c6aacfb15..5c0fd19d3 100644 --- a/vendor/guzzlehttp/guzzle/src/RequestOptions.php +++ b/vendor/guzzlehttp/guzzle/src/RequestOptions.php @@ -22,7 +22,7 @@ final class RequestOptions * - strict: (bool, default=false) Set to true to use strict redirects * meaning redirect POST requests with POST requests vs. doing what most * browsers do which is redirect POST requests with GET requests - * - referer: (bool, default=true) Set to false to disable the Referer + * - referer: (bool, default=false) Set to true to enable the Referer * header. * - protocols: (array, default=['http', 'https']) Allowed redirect * protocols. diff --git a/vendor/guzzlehttp/guzzle/src/RetryMiddleware.php b/vendor/guzzlehttp/guzzle/src/RetryMiddleware.php index f27090fd1..7d40ecaf8 100644 --- a/vendor/guzzlehttp/guzzle/src/RetryMiddleware.php +++ b/vendor/guzzlehttp/guzzle/src/RetryMiddleware.php @@ -19,6 +19,9 @@ class RetryMiddleware /** @var callable */ private $decider; + /** @var callable */ + private $delay; + /** * @param callable $decider Function that accepts the number of retries, * a request, [response], and [exception] and @@ -42,7 +45,7 @@ public function __construct( /** * Default exponential backoff delay function. * - * @param $retries + * @param int $retries * * @return int */ diff --git a/vendor/guzzlehttp/guzzle/src/TransferStats.php b/vendor/guzzlehttp/guzzle/src/TransferStats.php index 15f717e1e..23a22a336 100644 --- a/vendor/guzzlehttp/guzzle/src/TransferStats.php +++ b/vendor/guzzlehttp/guzzle/src/TransferStats.php @@ -20,7 +20,7 @@ final class TransferStats /** * @param RequestInterface $request Request that was sent. * @param ResponseInterface $response Response received (if any) - * @param null $transferTime Total handler transfer time. + * @param float|null $transferTime Total handler transfer time. * @param mixed $handlerErrorData Handler error data. * @param array $handlerStats Handler specific stats. */ diff --git a/vendor/guzzlehttp/guzzle/src/functions.php b/vendor/guzzlehttp/guzzle/src/functions.php index a3ac450db..51d736d88 100644 --- a/vendor/guzzlehttp/guzzle/src/functions.php +++ b/vendor/guzzlehttp/guzzle/src/functions.php @@ -196,7 +196,8 @@ function default_ca_bundle() } } - throw new \RuntimeException(<<< EOT + throw new \RuntimeException( + <<< EOT No system CA bundle could be found in any of the the common system locations. PHP versions earlier than 5.6 are not properly configured to use the system's CA bundle by default. In order to verify peer certificates, you will need to @@ -294,14 +295,14 @@ function is_host_in_noproxy($host, array $noProxyArray) * @param int $options Bitmask of JSON decode options. * * @return mixed - * @throws \InvalidArgumentException if the JSON cannot be decoded. + * @throws Exception\InvalidArgumentException if the JSON cannot be decoded. * @link http://www.php.net/manual/en/function.json-decode.php */ function json_decode($json, $assoc = false, $depth = 512, $options = 0) { $data = \json_decode($json, $assoc, $depth, $options); if (JSON_ERROR_NONE !== json_last_error()) { - throw new \InvalidArgumentException( + throw new Exception\InvalidArgumentException( 'json_decode error: ' . json_last_error_msg() ); } @@ -317,17 +318,29 @@ function json_decode($json, $assoc = false, $depth = 512, $options = 0) * @param int $depth Set the maximum depth. Must be greater than zero. * * @return string - * @throws \InvalidArgumentException if the JSON cannot be encoded. + * @throws Exception\InvalidArgumentException if the JSON cannot be encoded. * @link http://www.php.net/manual/en/function.json-encode.php */ function json_encode($value, $options = 0, $depth = 512) { $json = \json_encode($value, $options, $depth); if (JSON_ERROR_NONE !== json_last_error()) { - throw new \InvalidArgumentException( + throw new Exception\InvalidArgumentException( 'json_encode error: ' . json_last_error_msg() ); } return $json; } + +/** + * Wrapper for the hrtime() or microtime() functions + * (depending on the PHP version, one of the two is used) + * + * @return float|mixed UNIX timestamp + * @internal + */ +function _current_time() +{ + return function_exists('hrtime') ? hrtime(true) / 1e9 : microtime(true); +} diff --git a/vendor/nicolab/php-ftp-client/.gitignore b/vendor/nicolab/php-ftp-client/.gitignore new file mode 100644 index 000000000..9bbd83f28 --- /dev/null +++ b/vendor/nicolab/php-ftp-client/.gitignore @@ -0,0 +1,7 @@ +/vendor +composer.phar +composer.lock +.DS_Store +Thumbs.db +/.Trash-1000 +.idea/ \ No newline at end of file diff --git a/vendor/nicolab/php-ftp-client/LICENSE b/vendor/nicolab/php-ftp-client/LICENSE new file mode 100644 index 000000000..ce9fd6381 --- /dev/null +++ b/vendor/nicolab/php-ftp-client/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2014 Nicolas Tallefourtane dev@nicolab.net + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/vendor/nicolab/php-ftp-client/README.md b/vendor/nicolab/php-ftp-client/README.md new file mode 100644 index 000000000..227314ce0 --- /dev/null +++ b/vendor/nicolab/php-ftp-client/README.md @@ -0,0 +1,249 @@ +# nicolab/php-ftp-client + +A flexible FTP and SSL-FTP client for PHP. +This lib provides helpers easy to use to manage the remote files. + +> This package is aimed to remain simple and light. It's only a wrapper of the FTP native API of PHP, with some useful helpers. If you want to customize some methods, you can do this by inheriting one of the [3 classes of the package](src/FtpClient). + + +## Install + + * Use composer: _require_ `nicolab/php-ftp-client` + + * Or use GIT clone command: `git clone git@github.com:Nicolab/php-ftp-client.git` + + * Or download the library, configure your autoloader or include the 3 files of `php-ftp-client/src/FtpClient` directory. + + +## Getting Started + +Connect to a server FTP : + +```php +$ftp = new \FtpClient\FtpClient(); +$ftp->connect($host); +$ftp->login($login, $password); +``` + +OR + +Connect to a server FTP via SSL (on port 990 or another port) : + +```php +$ftp = new \FtpClient\FtpClient(); +$ftp->connect($host, true, 990); +$ftp->login($login, $password); +``` + +Note: The connection is implicitly closed at the end of script execution (when the object is destroyed). Therefore it is unnecessary to call `$ftp->close()`, except for an explicit re-connection. + + +### Usage + +Upload all files and all directories is easy : + +```php +// upload with the BINARY mode +$ftp->putAll($source_directory, $target_directory); + +// Is equal to +$ftp->putAll($source_directory, $target_directory, FTP_BINARY); + +// or upload with the ASCII mode +$ftp->putAll($source_directory, $target_directory, FTP_ASCII); +``` + +*Note : FTP_ASCII and FTP_BINARY are predefined PHP internal constants.* + +Get a directory size : + +```php +// size of the current directory +$size = $ftp->dirSize(); + +// size of a given directory +$size = $ftp->dirSize('/path/of/directory'); +``` + +Count the items in a directory : + +```php +// count in the current directory +$total = $ftp->count(); + +// count in a given directory +$total = $ftp->count('/path/of/directory'); + +// count only the "files" in the current directory +$total_file = $ftp->count('.', 'file'); + +// count only the "files" in a given directory +$total_file = $ftp->count('/path/of/directory', 'file'); + +// count only the "directories" in a given directory +$total_dir = $ftp->count('/path/of/directory', 'directory'); + +// count only the "symbolic links" in a given directory +$total_link = $ftp->count('/path/of/directory', 'link'); +``` + +Detailed list of all files and directories : + +```php +// scan the current directory and returns the details of each item +$items = $ftp->scanDir(); + +// scan the current directory (recursive) and returns the details of each item +var_dump($ftp->scanDir('.', true)); +``` + +Result: + + 'directory#www' => + array (size=10) + 'permissions' => string 'drwx---r-x' (length=10) + 'number' => string '3' (length=1) + 'owner' => string '32385' (length=5) + 'group' => string 'users' (length=5) + 'size' => string '5' (length=1) + 'month' => string 'Nov' (length=3) + 'day' => string '24' (length=2) + 'time' => string '17:25' (length=5) + 'name' => string 'www' (length=3) + 'type' => string 'directory' (length=9) + + 'link#www/index.html' => + array (size=11) + 'permissions' => string 'lrwxrwxrwx' (length=10) + 'number' => string '1' (length=1) + 'owner' => string '0' (length=1) + 'group' => string 'users' (length=5) + 'size' => string '38' (length=2) + 'month' => string 'Nov' (length=3) + 'day' => string '16' (length=2) + 'time' => string '14:57' (length=5) + 'name' => string 'index.html' (length=10) + 'type' => string 'link' (length=4) + 'target' => string '/var/www/shared/index.html' (length=26) + + 'file#www/README' => + array (size=10) + 'permissions' => string '-rw----r--' (length=10) + 'number' => string '1' (length=1) + 'owner' => string '32385' (length=5) + 'group' => string 'users' (length=5) + 'size' => string '0' (length=1) + 'month' => string 'Nov' (length=3) + 'day' => string '24' (length=2) + 'time' => string '17:25' (length=5) + 'name' => string 'README' (length=6) + 'type' => string 'file' (length=4) + + +All FTP PHP functions are supported and some improved : + +```php +// Requests execution of a command on the FTP server +$ftp->exec($command); + +// Turns passive mode on or off +$ftp->pasv(true); + +// Set permissions on a file via FTP +$ftp->chmod(0777, 'file.php'); + +// Removes a directory +$ftp->rmdir('path/of/directory/to/remove'); + +// Removes a directory (recursive) +$ftp->rmdir('path/of/directory/to/remove', true); + +// Creates a directory +$ftp->mkdir('path/of/directory/to/create'); + +// Creates a directory (recursive), +// creates automaticaly the sub directory if not exist +$ftp->mkdir('path/of/directory/to/create', true); + +// and more ... +``` + +Get the help information of remote FTP server : + +```php +var_dump($ftp->help()); +``` + +Result : + + array (size=6) + 0 => string '214-The following SITE commands are recognized' (length=46) + 1 => string ' ALIAS' (length=6) + 2 => string ' CHMOD' (length=6) + 3 => string ' IDLE' (length=5) + 4 => string ' UTIME' (length=6) + 5 => string '214 Pure-FTPd - http://pureftpd.org/' (length=36) + + +_Note : The result depend of FTP server._ + + +### Extend + +Create your custom `FtpClient`. + +```php +// MyFtpClient.php + +/** + * My custom FTP Client + * @inheritDoc + */ +class MyFtpClient extends \FtpClient\FtpClient { + + public function removeByTime($path, $timestamp) { + // your code here + } + + public function search($regex) { + // your code here + } +} +``` + +```php +// example.php +$ftp = new MyFtpClient(); +$ftp->connect($host); +$ftp->login($login, $password); + +// remove the old files +$ftp->removeByTime('/www/mysite.com/demo', time() - 86400)); + +// search PNG files +$ftp->search('/(.*)\.png$/i'); +``` + + +## API doc + +See the [source code](https://github.com/Nicolab/php-ftp-client/tree/master/src/FtpClient) for more details. +It is fully documented :blue_book: + + +## Testing + +Tested with "atoum" unit testing framework. + + +## License + +[MIT](https://github.com/Nicolab/php-ftp-client/blob/master/LICENSE) c) 2014, Nicolas Tallefourtane. + + +## Author + +| [![Nicolas Tallefourtane - Nicolab.net](http://www.gravatar.com/avatar/d7dd0f4769f3aa48a3ecb308f0b457fc?s=64)](http://nicolab.net) | +|---| +| [Nicolas Talle](http://nicolab.net) | +| [![Make a donation via Paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donate_SM.gif)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=PGRH4ZXP36GUC) | diff --git a/vendor/nicolab/php-ftp-client/composer.json b/vendor/nicolab/php-ftp-client/composer.json new file mode 100644 index 000000000..3e1556d2a --- /dev/null +++ b/vendor/nicolab/php-ftp-client/composer.json @@ -0,0 +1,23 @@ +{ + "name": "nicolab/php-ftp-client", + "type": "library", + "description": "A flexible FTP and SSL-FTP client for PHP. This lib provides helpers easy to use to manage the remote files.", + "license": "MIT", + "keywords": ["ftp", "sftp", "ssl-ftp", "ssl", "file", "server", "lib", "helper"], + "homepage": "https://github.com/Nicolab/php-ftp-client", + + "authors" : [ + { + "name" : "Nicolas Tallefourtane", + "email" : "dev@nicolab.net", + "homepage" : "http://nicolab.net" + } + ], + "require": { + "php": ">=5.4", + "ext-ftp": "*" + }, + "autoload": { + "psr-0": {"FtpClient": "src/"} + } +} diff --git a/vendor/nicolab/php-ftp-client/src/FtpClient/FtpClient.php b/vendor/nicolab/php-ftp-client/src/FtpClient/FtpClient.php new file mode 100644 index 000000000..1b55b7c0e --- /dev/null +++ b/vendor/nicolab/php-ftp-client/src/FtpClient/FtpClient.php @@ -0,0 +1,938 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Nicolas Tallefourtane http://nicolab.net + */ +namespace FtpClient; + +use \Countable; + +/** + * The FTP and SSL-FTP client for PHP. + * + * @method bool alloc() alloc(int $filesize, string &$result = null) Allocates space for a file to be uploaded + * @method bool cdup() cdup() Changes to the parent directory + * @method bool chdir() chdir(string $directory) Changes the current directory on a FTP server + * @method int chmod() chmod(int $mode, string $filename) Set permissions on a file via FTP + * @method bool delete() delete(string $path) Deletes a file on the FTP server + * @method bool exec() exec(string $command) Requests execution of a command on the FTP server + * @method bool fget() fget(resource $handle, string $remote_file, int $mode, int $resumepos = 0) Downloads a file from the FTP server and saves to an open file + * @method bool fput() fput(string $remote_file, resource $handle, int $mode, int $startpos = 0) Uploads from an open file to the FTP server + * @method mixed get_option() get_option(int $option) Retrieves various runtime behaviours of the current FTP stream + * @method bool get() get(string $local_file, string $remote_file, int $mode, int $resumepos = 0) Downloads a file from the FTP server + * @method int mdtm() mdtm(string $remote_file) Returns the last modified time of the given file + * @method int nb_continue() nb_continue() Continues retrieving/sending a file (non-blocking) + * @method int nb_fget() nb_fget(resource $handle, string $remote_file, int $mode, int $resumepos = 0) Retrieves a file from the FTP server and writes it to an open file (non-blocking) + * @method int nb_fput() nb_fput(string $remote_file, resource $handle, int $mode, int $startpos = 0) Stores a file from an open file to the FTP server (non-blocking) + * @method int nb_get() nb_get(string $local_file, string $remote_file, int $mode, int $resumepos = 0) Retrieves a file from the FTP server and writes it to a local file (non-blocking) + * @method int nb_put() nb_put(string $remote_file, string $local_file, int $mode, int $startpos = 0) Stores a file on the FTP server (non-blocking) + * @method bool pasv() pasv(bool $pasv) Turns passive mode on or off + * @method bool put() put(string $remote_file, string $local_file, int $mode, int $startpos = 0) Uploads a file to the FTP server + * @method string pwd() pwd() Returns the current directory name + * @method bool quit() quit() Closes an FTP connection + * @method array raw() raw(string $command) Sends an arbitrary command to an FTP server + * @method bool rename() rename(string $oldname, string $newname) Renames a file or a directory on the FTP server + * @method bool set_option() set_option(int $option, mixed $value) Set miscellaneous runtime FTP options + * @method bool site() site(string $command) Sends a SITE command to the server + * @method int size() size(string $remote_file) Returns the size of the given file + * @method string systype() systype() Returns the system type identifier of the remote FTP server + * + * @author Nicolas Tallefourtane + */ +class FtpClient implements Countable +{ + /** + * The connection with the server. + * + * @var resource + */ + protected $conn; + + /** + * PHP FTP functions wrapper. + * + * @var FtpWrapper + */ + private $ftp; + + /** + * Constructor. + * + * @param resource|null $connection + * @throws FtpException If FTP extension is not loaded. + */ + public function __construct($connection = null) + { + if (!extension_loaded('ftp')) { + throw new FtpException('FTP extension is not loaded!'); + } + + if ($connection) { + $this->conn = $connection; + } + + $this->setWrapper(new FtpWrapper($this->conn)); + } + + /** + * Close the connection when the object is destroyed. + */ + public function __destruct() + { + if ($this->conn) { + $this->ftp->close(); + } + } + + /** + * Call an internal method or a FTP method handled by the wrapper. + * + * Wrap the FTP PHP functions to call as method of FtpClient object. + * The connection is automaticaly passed to the FTP PHP functions. + * + * @param string $method + * @param array $arguments + * @return mixed + * @throws FtpException When the function is not valid + */ + public function __call($method, array $arguments) + { + return $this->ftp->__call($method, $arguments); + } + + /** + * Overwrites the PHP limit + * + * @param string|null $memory The memory limit, if null is not modified + * @param int $time_limit The max execution time, unlimited by default + * @param bool $ignore_user_abort Ignore user abort, true by default + * @return FtpClient + */ + public function setPhpLimit($memory = null, $time_limit = 0, $ignore_user_abort = true) + { + if (null !== $memory) { + ini_set('memory_limit', $memory); + } + + ignore_user_abort($ignore_user_abort); + set_time_limit($time_limit); + + return $this; + } + + /** + * Get the help information of the remote FTP server. + * + * @return array + */ + public function help() + { + return $this->ftp->raw('help'); + } + + /** + * Open a FTP connection. + * + * @param string $host + * @param bool $ssl + * @param int $port + * @param int $timeout + * + * @return FtpClient + * @throws FtpException If unable to connect + */ + public function connect($host, $ssl = false, $port = 21, $timeout = 90) + { + if ($ssl) { + $this->conn = $this->ftp->ssl_connect($host, $port, $timeout); + } else { + $this->conn = $this->ftp->connect($host, $port, $timeout); + } + + if (!$this->conn) { + throw new FtpException('Unable to connect'); + } + + return $this; + } + + /** + * Closes the current FTP connection. + * + * @return bool + */ + public function close() + { + if ($this->conn) { + $this->ftp->close(); + $this->conn = null; + } + } + + /** + * Get the connection with the server. + * + * @return resource + */ + public function getConnection() + { + return $this->conn; + } + + /** + * Get the wrapper. + * + * @return FtpWrapper + */ + public function getWrapper() + { + return $this->ftp; + } + + /** + * Logs in to an FTP connection. + * + * @param string $username + * @param string $password + * + * @return FtpClient + * @throws FtpException If the login is incorrect + */ + public function login($username = 'anonymous', $password = '') + { + $result = $this->ftp->login($username, $password); + + if ($result === false) { + throw new FtpException('Login incorrect'); + } + + return $this; + } + + /** + * Returns the last modified time of the given file. + * Return -1 on error + * + * @param string $remoteFile + * @param string|null $format + * + * @return int + */ + public function modifiedTime($remoteFile, $format = null) + { + $time = $this->ftp->mdtm($remoteFile); + + if ($time !== -1 && $format !== null) { + return date($format, $time); + } + + return $time; + } + + /** + * Changes to the parent directory. + * + * @throws FtpException + * @return FtpClient + */ + public function up() + { + $result = $this->ftp->cdup(); + + if ($result === false) { + throw new FtpException('Unable to get parent folder'); + } + + return $this; + } + + /** + * Returns a list of files in the given directory. + * + * @param string $directory The directory, by default is "." the current directory + * @param bool $recursive + * @param callable $filter A callable to filter the result, by default is asort() PHP function. + * The result is passed in array argument, + * must take the argument by reference ! + * The callable should proceed with the reference array + * because is the behavior of several PHP sorting + * functions (by reference ensure directly the compatibility + * with all PHP sorting functions). + * + * @return array + * @throws FtpException If unable to list the directory + */ + public function nlist($directory = '.', $recursive = false, $filter = 'sort') + { + if (!$this->isDir($directory)) { + throw new FtpException('"'.$directory.'" is not a directory'); + } + + $files = $this->ftp->nlist($directory); + + if ($files === false) { + throw new FtpException('Unable to list directory'); + } + + $result = array(); + $dir_len = strlen($directory); + + // if it's the current + if (false !== ($kdot = array_search('.', $files))) { + unset($files[$kdot]); + } + + // if it's the parent + if(false !== ($kdot = array_search('..', $files))) { + unset($files[$kdot]); + } + + if (!$recursive) { + $result = $files; + + // working with the reference (behavior of several PHP sorting functions) + $filter($result); + + return $result; + } + + // utils for recursion + $flatten = function (array $arr) use (&$flatten) { + $flat = []; + + foreach ($arr as $k => $v) { + if (is_array($v)) { + $flat = array_merge($flat, $flatten($v)); + } else { + $flat[] = $v; + } + } + + return $flat; + }; + + foreach ($files as $file) { + $file = $directory.'/'.$file; + + // if contains the root path (behavior of the recursivity) + if (0 === strpos($file, $directory, $dir_len)) { + $file = substr($file, $dir_len); + } + + if ($this->isDir($file)) { + $result[] = $file; + $items = $flatten($this->nlist($file, true, $filter)); + + foreach ($items as $item) { + $result[] = $item; + } + + } else { + $result[] = $file; + } + } + + $result = array_unique($result); + $filter($result); + + return $result; + } + + /** + * Creates a directory. + * + * @see FtpClient::rmdir() + * @see FtpClient::remove() + * @see FtpClient::put() + * @see FtpClient::putAll() + * + * @param string $directory The directory + * @param bool $recursive + * @return array + */ + public function mkdir($directory, $recursive = false) + { + if (!$recursive or $this->isDir($directory)) { + return $this->ftp->mkdir($directory); + } + + $result = false; + $pwd = $this->ftp->pwd(); + $parts = explode('/', $directory); + + foreach ($parts as $part) { + if ($part == '') { + continue; + } + + if (!@$this->ftp->chdir($part)) { + $result = $this->ftp->mkdir($part); + $this->ftp->chdir($part); + } + } + + $this->ftp->chdir($pwd); + + return $result; + } + + /** + * Remove a directory. + * + * @see FtpClient::mkdir() + * @see FtpClient::cleanDir() + * @see FtpClient::remove() + * @see FtpClient::delete() + * @param string $directory + * @param bool $recursive Forces deletion if the directory is not empty + * @return bool + * @throws FtpException If unable to list the directory to remove + */ + public function rmdir($directory, $recursive = true) + { + if ($recursive) { + $files = $this->nlist($directory, false, 'rsort'); + + // remove children + foreach ($files as $file) { + $this->remove($file, true); + } + } + + // remove the directory + return $this->ftp->rmdir($directory); + } + + /** + * Empty directory. + * + * @see FtpClient::remove() + * @see FtpClient::delete() + * @see FtpClient::rmdir() + * + * @param string $directory + * @return bool + */ + public function cleanDir($directory) + { + if (!$files = $this->nlist($directory)) { + return $this->isEmpty($directory); + } + + // remove children + foreach ($files as $file) { + $this->remove($file, true); + } + + return $this->isEmpty($directory); + } + + /** + * Remove a file or a directory. + * + * @see FtpClient::rmdir() + * @see FtpClient::cleanDir() + * @see FtpClient::delete() + * @param string $path The path of the file or directory to remove + * @param bool $recursive Is effective only if $path is a directory, {@see FtpClient::rmdir()} + * @return bool + */ + public function remove($path, $recursive = false) + { + try { + if (@$this->ftp->delete($path) + or ($this->isDir($path) and $this->rmdir($path, $recursive))) { + return true; + } + + return false; + } catch (\Exception $e) { + return false; + } + } + + /** + * Check if a directory exist. + * + * @param string $directory + * @return bool + * @throws FtpException + */ + public function isDir($directory) + { + $pwd = $this->ftp->pwd(); + + if ($pwd === false) { + throw new FtpException('Unable to resolve the current directory'); + } + + if (@$this->ftp->chdir($directory)) { + $this->ftp->chdir($pwd); + return true; + } + + $this->ftp->chdir($pwd); + + return false; + } + + /** + * Check if a directory is empty. + * + * @param string $directory + * @return bool + */ + public function isEmpty($directory) + { + return $this->count($directory, null, false) === 0 ? true : false; + } + + /** + * Scan a directory and returns the details of each item. + * + * @see FtpClient::nlist() + * @see FtpClient::rawlist() + * @see FtpClient::parseRawList() + * @see FtpClient::dirSize() + * @param string $directory + * @param bool $recursive + * @return array + */ + public function scanDir($directory = '.', $recursive = false) + { + return $this->parseRawList($this->rawlist($directory, $recursive)); + } + + /** + * Returns the total size of the given directory in bytes. + * + * @param string $directory The directory, by default is the current directory. + * @param bool $recursive true by default + * @return int The size in bytes. + */ + public function dirSize($directory = '.', $recursive = true) + { + $items = $this->scanDir($directory, $recursive); + $size = 0; + + foreach ($items as $item) { + $size += (int) $item['size']; + } + + return $size; + } + + /** + * Count the items (file, directory, link, unknown). + * + * @param string $directory The directory, by default is the current directory. + * @param string|null $type The type of item to count (file, directory, link, unknown) + * @param bool $recursive true by default + * @return int + */ + public function count($directory = '.', $type = null, $recursive = true) + { + $items = (null === $type ? $this->nlist($directory, $recursive) + : $this->scanDir($directory, $recursive)); + + $count = 0; + foreach ($items as $item) { + if (null === $type or $item['type'] == $type) { + $count++; + } + } + + return $count; + } + + /** + * Downloads a file from the FTP server into a string + * + * @param string $remote_file + * @param int $mode + * @param int $resumepos + * @return string|null + */ + public function getContent($remote_file, $mode = FTP_BINARY, $resumepos = 0) + { + $handle = fopen('php://temp', 'r+'); + + if ($this->fget($handle, $remote_file, $mode, $resumepos)) { + rewind($handle); + return stream_get_contents($handle); + } + + return null; + } + + /** + * Uploads a file to the server from a string. + * + * @param string $remote_file + * @param string $content + * @return FtpClient + * @throws FtpException When the transfer fails + */ + public function putFromString($remote_file, $content) + { + $handle = fopen('php://temp', 'w'); + + fwrite($handle, $content); + rewind($handle); + + if ($this->ftp->fput($remote_file, $handle, FTP_BINARY)) { + return $this; + } + + throw new FtpException('Unable to put the file "'.$remote_file.'"'); + } + + /** + * Uploads a file to the server. + * + * @param string $local_file + * @return FtpClient + * @throws FtpException When the transfer fails + */ + public function putFromPath($local_file) + { + $remote_file = basename($local_file); + $handle = fopen($local_file, 'r'); + + if ($this->ftp->fput($remote_file, $handle, FTP_BINARY)) { + rewind($handle); + return $this; + } + + throw new FtpException( + 'Unable to put the remote file from the local file "'.$local_file.'"' + ); + } + + /** + * Upload files. + * + * @param string $source_directory + * @param string $target_directory + * @param int $mode + * @return FtpClient + */ + public function putAll($source_directory, $target_directory, $mode = FTP_BINARY) + { + $d = dir($source_directory); + + // do this for each file in the directory + while ($file = $d->read()) { + + // to prevent an infinite loop + if ($file != "." && $file != "..") { + + // do the following if it is a directory + if (is_dir($source_directory.'/'.$file)) { + + if (!$this->isDir($target_directory.'/'.$file)) { + + // create directories that do not yet exist + $this->ftp->mkdir($target_directory.'/'.$file); + } + + // recursive part + $this->putAll( + $source_directory.'/'.$file, $target_directory.'/'.$file, + $mode + ); + } else { + + // put the files + $this->ftp->put( + $target_directory.'/'.$file, $source_directory.'/'.$file, + $mode + ); + } + } + } + + return $this; + } + + /** + * Downloads all files from remote FTP directory + * + * @param string $source_directory The remote directory + * @param string $target_directory The local directory + * @param int $mode + * @return FtpClient + */ + public function getAll($source_directory, $target_directory, $mode = FTP_BINARY) + { + if ($source_directory != ".") { + if ($this->ftp->chdir($source_directory) == false) { + throw new FtpException("Unable to change directory: ".$source_directory); + } + + if (!(is_dir($source_directory))) { + mkdir($source_directory); + } + + chdir($source_directory); + } + + $contents = $this->ftp->nlist("."); + + foreach ($contents as $file) { + if ($file == '.' || $file == '..') { + continue; + } + + $this->ftp->get($target_directory."/".$file, $file, $mode); + } + + $this->ftp->chdir(".."); + chdir(".."); + + return $this; + } + + /** + * Returns a detailed list of files in the given directory. + * + * @see FtpClient::nlist() + * @see FtpClient::scanDir() + * @see FtpClient::dirSize() + * @param string $directory The directory, by default is the current directory + * @param bool $recursive + * @return array + * @throws FtpException + */ + public function rawlist($directory = '.', $recursive = false) + { + if (!$this->isDir($directory)) { + throw new FtpException('"'.$directory.'" is not a directory.'); + } + + if (strpos($directory, " ") > 0) { + $ftproot = $this->ftp->pwd(); + $this->ftp->chdir($directory); + $list = $this->ftp->rawlist(""); + $this->ftp->chdir($ftproot); + } else { + $list = $this->ftp->rawlist($directory); + } + + $items = array(); + + if (!$list) { + return $items; + } + + if (false == $recursive) { + foreach ($list as $path => $item) { + $chunks = preg_split("/\s+/", $item); + + // if not "name" + if (empty($chunks[8]) || $chunks[8] == '.' || $chunks[8] == '..') { + continue; + } + + $path = $directory.'/'.$chunks[8]; + + if (isset($chunks[9])) { + $nbChunks = count($chunks); + + for ($i = 9; $i < $nbChunks; $i++) { + $path .= ' '.$chunks[$i]; + } + } + + + if (substr($path, 0, 2) == './') { + $path = substr($path, 2); + } + + $items[ $this->rawToType($item).'#'.$path ] = $item; + } + + return $items; + } + + $path = ''; + + foreach ($list as $item) { + $len = strlen($item); + + if (!$len + + // "." + || ($item[$len-1] == '.' && $item[$len-2] == ' ' + + // ".." + or $item[$len-1] == '.' && $item[$len-2] == '.' && $item[$len-3] == ' ') + ) { + + continue; + } + + $chunks = preg_split("/\s+/", $item); + + // if not "name" + if (empty($chunks[8]) || $chunks[8] == '.' || $chunks[8] == '..') { + continue; + } + + $path = $directory.'/'.$chunks[8]; + + if (isset($chunks[9])) { + $nbChunks = count($chunks); + + for ($i = 9; $i < $nbChunks; $i++) { + $path .= ' '.$chunks[$i]; + } + } + + if (substr($path, 0, 2) == './') { + $path = substr($path, 2); + } + + $items[$this->rawToType($item).'#'.$path] = $item; + + if ($item[0] == 'd') { + $sublist = $this->rawlist($path, true); + + foreach ($sublist as $subpath => $subitem) { + $items[$subpath] = $subitem; + } + } + } + + return $items; + } + + /** + * Parse raw list. + * + * @see FtpClient::rawlist() + * @see FtpClient::scanDir() + * @see FtpClient::dirSize() + * @param array $rawlist + * @return array + */ + public function parseRawList(array $rawlist) + { + $items = array(); + $path = ''; + + foreach ($rawlist as $key => $child) { + $chunks = preg_split("/\s+/", $child, 9); + + if (isset($chunks[8]) && ($chunks[8] == '.' or $chunks[8] == '..')) { + continue; + } + + if (count($chunks) === 1) { + $len = strlen($chunks[0]); + + if ($len && $chunks[0][$len-1] == ':') { + $path = substr($chunks[0], 0, -1); + } + + continue; + } + + // Prepare for filename that has space + $nameSlices = array_slice($chunks, 8, true); + + $item = [ + 'permissions' => $chunks[0], + 'number' => $chunks[1], + 'owner' => $chunks[2], + 'group' => $chunks[3], + 'size' => $chunks[4], + 'month' => $chunks[5], + 'day' => $chunks[6], + 'time' => $chunks[7], + 'name' => implode(' ', $nameSlices), + 'type' => $this->rawToType($chunks[0]), + ]; + + if ($item['type'] == 'link' && isset($chunks[10])) { + $item['target'] = $chunks[10]; // 9 is "->" + } + + // if the key is not the path, behavior of ftp_rawlist() PHP function + if (is_int($key) || false === strpos($key, $item['name'])) { + array_splice($chunks, 0, 8); + + $key = $item['type'].'#' + .($path ? $path.'/' : '') + .implode(' ', $chunks); + + if ($item['type'] == 'link') { + // get the first part of 'link#the-link.ext -> /path/of/the/source.ext' + $exp = explode(' ->', $key); + $key = rtrim($exp[0]); + } + + $items[$key] = $item; + } else { + // the key is the path, behavior of FtpClient::rawlist() method() + $items[$key] = $item; + } + } + + return $items; + } + + /** + * Convert raw info (drwx---r-x ...) to type (file, directory, link, unknown). + * Only the first char is used for resolving. + * + * @param string $permission Example : drwx---r-x + * + * @return string The file type (file, directory, link, unknown) + * @throws FtpException + */ + public function rawToType($permission) + { + if (!is_string($permission)) { + throw new FtpException('The "$permission" argument must be a string, "' + .gettype($permission).'" given.'); + } + + if (empty($permission[0])) { + return 'unknown'; + } + + switch ($permission[0]) { + case '-': + return 'file'; + + case 'd': + return 'directory'; + + case 'l': + return 'link'; + + default: + return 'unknown'; + } + } + + /** + * Set the wrapper which forward the PHP FTP functions to use in FtpClient instance. + * + * @param FtpWrapper $wrapper + * @return FtpClient + */ + protected function setWrapper(FtpWrapper $wrapper) + { + $this->ftp = $wrapper; + + return $this; + } +} diff --git a/vendor/nicolab/php-ftp-client/src/FtpClient/FtpException.php b/vendor/nicolab/php-ftp-client/src/FtpClient/FtpException.php new file mode 100644 index 000000000..f17ed7f8a --- /dev/null +++ b/vendor/nicolab/php-ftp-client/src/FtpClient/FtpException.php @@ -0,0 +1,20 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Nicolas Tallefourtane http://nicolab.net + */ +namespace FtpClient; + +/** + * The FtpException class. + * Exception thrown if an error on runtime of the FTP client occurs. + * @inheritDoc + * @author Nicolas Tallefourtane + */ +class FtpException extends \Exception {} diff --git a/vendor/nicolab/php-ftp-client/src/FtpClient/FtpWrapper.php b/vendor/nicolab/php-ftp-client/src/FtpClient/FtpWrapper.php new file mode 100644 index 000000000..fc763a07a --- /dev/null +++ b/vendor/nicolab/php-ftp-client/src/FtpClient/FtpWrapper.php @@ -0,0 +1,115 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Nicolas Tallefourtane http://nicolab.net + */ +namespace FtpClient; + +/** + * Wrap the PHP FTP functions + * + * @method bool alloc() alloc(int $filesize, string &$result = null) Allocates space for a file to be uploaded + * @method bool cdup() cdup() Changes to the parent directory + * @method bool chdir() chdir(string $directory) Changes the current directory on a FTP server + * @method int chmod() chmod(int $mode, string $filename) Set permissions on a file via FTP + * @method bool close() close() Closes an FTP connection + * @method bool delete() delete(string $path) Deletes a file on the FTP server + * @method bool exec() exec(string $command) Requests execution of a command on the FTP server + * @method bool fget() fget(resource $handle, string $remote_file, int $mode, int $resumepos = 0) Downloads a file from the FTP server and saves to an open file + * @method bool fput() fput(string $remote_file, resource $handle, int $mode, int $startpos = 0) Uploads from an open file to the FTP server + * @method mixed get_option() get_option(int $option) Retrieves various runtime behaviours of the current FTP stream + * @method bool get() get(string $local_file, string $remote_file, int $mode, int $resumepos = 0) Downloads a file from the FTP server + * @method bool login() login(string $username, string $password) Logs in to an FTP connection + * @method int mdtm() mdtm(string $remote_file) Returns the last modified time of the given file + * @method string mkdir() mkdir(string $directory) Creates a directory + * @method int nb_continue() nb_continue() Continues retrieving/sending a file (non-blocking) + * @method int nb_fget() nb_fget(resource $handle, string $remote_file, int $mode, int $resumepos = 0) Retrieves a file from the FTP server and writes it to an open file (non-blocking) + * @method int nb_fput() nb_fput(string $remote_file, resource $handle, int $mode, int $startpos = 0) Stores a file from an open file to the FTP server (non-blocking) + * @method int nb_get() nb_get(string $local_file, string $remote_file, int $mode, int $resumepos = 0) Retrieves a file from the FTP server and writes it to a local file (non-blocking) + * @method int nb_put() nb_put(string $remote_file, string $local_file, int $mode, int $startpos = 0) Stores a file on the FTP server (non-blocking) + * @method array nlist() nlist(string $directory) Returns a list of files in the given directory + * @method bool pasv() pasv(bool $pasv) Turns passive mode on or off + * @method bool put() put(string $remote_file, string $local_file, int $mode, int $startpos = 0) Uploads a file to the FTP server + * @method string pwd() pwd() Returns the current directory name + * @method bool quit() quit() Closes an FTP connection + * @method array raw() raw(string $command) Sends an arbitrary command to an FTP server + * @method array rawlist() rawlist(string $directory, bool $recursive = false) Returns a detailed list of files in the given directory + * @method bool rename() rename(string $oldname, string $newname) Renames a file or a directory on the FTP server + * @method bool rmdir() rmdir(string $directory) Removes a directory + * @method bool set_option() set_option(int $option, mixed $value) Set miscellaneous runtime FTP options + * @method bool site() site(string $command) Sends a SITE command to the server + * @method int size() size(string $remote_file) Returns the size of the given file + * @method string systype() systype() Returns the system type identifier of the remote FTP server + * + * @author Nicolas Tallefourtane + */ +class FtpWrapper +{ + /** + * The connection with the server + * + * @var resource + */ + protected $conn; + + /** + * Constructor. + * + * @param resource &$connection The FTP (or SSL-FTP) connection (takes by reference). + */ + public function __construct(&$connection) + { + $this->conn = &$connection; + } + + /** + * Forward the method call to FTP functions + * + * @param string $function + * @param array $arguments + * @return mixed + * @throws FtpException When the function is not valid + */ + public function __call($function, array $arguments) + { + $function = 'ftp_' . $function; + + if (function_exists($function)) { + array_unshift($arguments, $this->conn); + return @call_user_func_array($function, $arguments); + } + + throw new FtpException("{$function} is not a valid FTP function"); + } + + /** + * Opens a FTP connection + * + * @param string $host + * @param int $port + * @param int $timeout + * @return resource + */ + public function connect($host, $port = 21, $timeout = 90) + { + return @ftp_connect($host, $port, $timeout); + } + + /** + * Opens a Secure SSL-FTP connection + * @param string $host + * @param int $port + * @param int $timeout + * @return resource + */ + public function ssl_connect($host, $port = 21, $timeout = 90) + { + return @ftp_ssl_connect($host, $port, $timeout); + } +} diff --git a/vendor/nicolab/php-ftp-client/tests/.atoum.php b/vendor/nicolab/php-ftp-client/tests/.atoum.php new file mode 100644 index 000000000..cee6cf655 --- /dev/null +++ b/vendor/nicolab/php-ftp-client/tests/.atoum.php @@ -0,0 +1,10 @@ +addDefaultReport(); + +// This will add a green or red logo after each run depending on its status. +$report->addField(new atoum\report\fields\runner\result\logo()); + +$script->bootstrapFile(__DIR__. '/bootstrap.php'); +$runner->addTestsFromDirectory(__DIR__. '/units'); diff --git a/vendor/nicolab/php-ftp-client/tests/bootstrap.php b/vendor/nicolab/php-ftp-client/tests/bootstrap.php new file mode 100644 index 000000000..f6ab8c3b7 --- /dev/null +++ b/vendor/nicolab/php-ftp-client/tests/bootstrap.php @@ -0,0 +1,6 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Nicolas Tallefourtane http://nicolab.net + */ +namespace tests\units\FtpClient; + +use + mageekguy\atoum, + FtpClient\FtpClient as TestedClass +; + +/** + * Tests the FtpClient\FtpClient class. + * @author Nicolas Tallefourtane + */ +class FtpClient extends atoum\test +{ + + public function test__construct() + { + $this + ->given($ftp = new TestedClass()) + ->object($ftp) + ->isInstanceOf('\FtpClient\FtpClient') + ; + } +} diff --git a/vendor/nicolab/php-ftp-client/tests/units/FtpClient/FtpException.php b/vendor/nicolab/php-ftp-client/tests/units/FtpClient/FtpException.php new file mode 100644 index 000000000..7ae56da17 --- /dev/null +++ b/vendor/nicolab/php-ftp-client/tests/units/FtpClient/FtpException.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Nicolas Tallefourtane http://nicolab.net + */ +namespace tests\units\FtpClient; + +use + mageekguy\atoum, + FtpClient\FtpException as TestedClass +; + +/** + * Tests the FtpClient\FtpException class. + * @author Nicolas Tallefourtane + */ +class FtpException extends atoum\test +{ + + public function test__instance() + { + $ftp = new \FtpClient\FtpClient(); + + $this + ->given($e = new TestedClass()) + ->object($e) + ->isInstanceOf('\FtpClient\FtpException') + ->isInstanceOf('\Exception') + + ->exception(function () use ($ftp) { + $ftp->doNotExist(); + }) + ->isInstanceOf('\FtpClient\FtpException') + ->isInstanceOf('\Exception') + ; + } +} diff --git a/vendor/nicolab/php-ftp-client/tests/units/FtpClient/FtpWrapper.php b/vendor/nicolab/php-ftp-client/tests/units/FtpClient/FtpWrapper.php new file mode 100644 index 000000000..da67e91c2 --- /dev/null +++ b/vendor/nicolab/php-ftp-client/tests/units/FtpClient/FtpWrapper.php @@ -0,0 +1,53 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + * + * @copyright Nicolas Tallefourtane http://nicolab.net + */ +namespace tests\units\FtpClient; + +use + mageekguy\atoum, + FtpClient\FtpWrapper as TestedClass +; + +/** + * Tests the FtpClient\FtpWrapper class. + * @author Nicolas Tallefourtane + */ +class FtpWrapper extends atoum\test +{ + + public function test__construct() + { + $conn = null; + + $this + ->given($wrapper = new TestedClass($conn)) + ->object($wrapper) + ->isInstanceOf('\FtpClient\FtpWrapper') + ; + } + + public function test__call() + { + $conn = null; + + $this + ->given($wrapper = new TestedClass($conn)) + ->exception(function () use ($wrapper) { + $wrapper->doNotExist(); + }) + ->isInstanceOf('\FtpClient\FtpException') + ->isInstanceOf('\Exception') + + ->variable(array($wrapper, 'alloc')) + ->isCallable() + ; + } +} diff --git a/vendor/phpmailer/phpmailer/README.md b/vendor/phpmailer/phpmailer/README.md index 627064639..a000c9303 100644 --- a/vendor/phpmailer/phpmailer/README.md +++ b/vendor/phpmailer/phpmailer/README.md @@ -10,13 +10,13 @@ Build status: [![Build Status](https://travis-ci.org/PHPMailer/PHPMailer.svg)](h ## Class Features - Probably the world's most popular code for sending email from PHP! -- Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joomla! and many more +- Used by many open-source projects: WordPress, Drupal, 1CRM, SugarCRM, Yii, Joomla!, and many more - Integrated SMTP support - send without a local mail server - Send emails with multiple To, CC, BCC and Reply-to addresses - Multipart/alternative emails for mail clients that do not read HTML email - Add attachments, including inline - Support for UTF-8 content and 8bit, base64, binary, and quoted-printable encodings -- SMTP authentication with LOGIN, PLAIN, CRAM-MD5 and XOAUTH2 mechanisms over SSL and SMTP+STARTTLS transports +- SMTP authentication with LOGIN, PLAIN, CRAM-MD5, and XOAUTH2 mechanisms over SSL and SMTP+STARTTLS transports - Validates email addresses automatically - Protect against header injection attacks - Error messages in over 50 languages! @@ -26,12 +26,12 @@ Build status: [![Build Status](https://travis-ci.org/PHPMailer/PHPMailer.svg)](h - Much more! ## Why you might need it -Many PHP developers utilize email in their code. The only PHP function that supports this is the `mail()` function. However, it does not provide any assistance for making use of popular features such as HTML-based emails and attachments. +Many PHP developers need to send email from their code. The only PHP function that supports this is [`mail()`](https://www.php.net/manual/en/function.mail.php). However, it does not provide any assistance for making use of popular features such as encryption, authentication, HTML messages, and attachments. -Formatting email correctly is surprisingly difficult. There are myriad overlapping RFCs, requiring tight adherence to horribly complicated formatting and encoding rules - the vast majority of code that you'll find online that uses the `mail()` function directly is just plain wrong! -*Please* don't be tempted to do it yourself - if you don't use PHPMailer, there are many other excellent libraries that you should look at before rolling your own - try [SwiftMailer](https://swiftmailer.symfony.com/), [Zend/Mail](https://zendframework.github.io/zend-mail/), [eZcomponents](https://github.com/zetacomponents/Mail) etc. +Formatting email correctly is surprisingly difficult. There are myriad overlapping RFCs, requiring tight adherence to horribly complicated formatting and encoding rules – the vast majority of code that you'll find online that uses the `mail()` function directly is just plain wrong! +*Please* don't be tempted to do it yourself – if you don't use PHPMailer, there are many other excellent libraries that you should look at before rolling your own. Try [SwiftMailer](https://swiftmailer.symfony.com/), [Zend/Mail](https://zendframework.github.io/zend-mail/), [ZetaComponents](https://github.com/zetacomponents/Mail) etc. -The PHP `mail()` function usually sends via a local mail server, typically fronted by a `sendmail` binary on Linux, BSD and OS X platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP implementation allows email sending on Windows platforms without a local mail server. +The PHP `mail()` function usually sends via a local mail server, typically fronted by a `sendmail` binary on Linux, BSD, and macOS platforms, however, Windows usually doesn't include a local mail server; PHPMailer's integrated SMTP implementation allows email sending on Windows platforms without a local mail server. ## License This software is distributed under the [LGPL 2.1](http://www.gnu.org/licenses/lgpl-2.1.html) license, along with the [GPL Cooperation Commitment](https://gplcc.github.io/gplcc/). Please read LICENSE for information on the software availability and distribution. @@ -40,7 +40,7 @@ This software is distributed under the [LGPL 2.1](http://www.gnu.org/licenses/lg PHPMailer is available on [Packagist](https://packagist.org/packages/phpmailer/phpmailer) (using semantic versioning), and installation via [Composer](https://getcomposer.org) is the recommended way to install PHPMailer. Just add this line to your `composer.json` file: ```json -"phpmailer/phpmailer": "~6.0" +"phpmailer/phpmailer": "~6.1" ``` or run @@ -70,15 +70,13 @@ If you're not using the `SMTP` class explicitly (you're probably not), you don't If you don't speak git or just want a tarball, click the 'zip' button on the right of the project page in GitHub, though note that docs and examples are not included in the tarball. ## Legacy versions -PHPMailer 5.2 (which is compatible with PHP 5.0 - 7.0) is no longer being supported for feature updates, and will only be receiving security updates from now on. You will find the latest version of 5.2 in the [5.2-stable branch](https://github.com/PHPMailer/PHPMailer/tree/5.2-stable), and future versions of 5.2 will be tagged with 5.2.x version numbers, so existing Composer configs should remain working. If you're using PHP 5.5 or later, we recommend you make the necessary changes to switch to the 6.0 release. +PHPMailer 5.2 (which is compatible with PHP 5.0 - 7.0) is no longer being supported, even for security updates. You will find the latest version of 5.2 in the [5.2-stable branch](https://github.com/PHPMailer/PHPMailer/tree/5.2-stable). If you're using PHP 5.5 or later (which you should be), switch to the 6.x releases. -The 5.2 branch will not receive security updates after December 31st 2018. - -## Upgrading from 5.2 +### Upgrading from 5.2 The biggest changes are that source files are now in the `src/` folder, and PHPMailer now declares the namespace `PHPMailer\PHPMailer`. This has several important effects – [read the upgrade guide](https://github.com/PHPMailer/PHPMailer/tree/master/UPGRADING.md) for more details. ### Minimal installation -While installing the entire package manually or with Composer is simple, convenient and reliable, you may want to include only vital files in your project. At the very least you will need [src/PHPMailer.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/PHPMailer.php). If you're using SMTP, you'll need [src/SMTP.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/SMTP.php), and if you're using POP-before SMTP, you'll need [src/POP3.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/POP3.php). You can skip the [language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder if you're not showing errors to users and can make do with English-only errors. If you're using XOAUTH2 you will need [src/OAuth.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/OAuth.php) as well as the Composer dependencies for the services you wish to authenticate with. Really, it's much easier to use Composer! +While installing the entire package manually or with Composer is simple, convenient, and reliable, you may want to include only vital files in your project. At the very least you will need [src/PHPMailer.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/PHPMailer.php). If you're using SMTP, you'll need [src/SMTP.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/SMTP.php), and if you're using POP-before SMTP, you'll need [src/POP3.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/POP3.php). You can skip the [language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder if you're not showing errors to users and can make do with English-only errors. If you're using XOAUTH2 you will need [src/OAuth.php](https://github.com/PHPMailer/PHPMailer/tree/master/src/OAuth.php) as well as the Composer dependencies for the services you wish to authenticate with. Really, it's much easier to use Composer! ## A Simple Example @@ -87,22 +85,25 @@ While installing the entire package manually or with Composer is simple, conveni // Import PHPMailer classes into the global namespace // These must be at the top of your script, not inside a function use PHPMailer\PHPMailer\PHPMailer; +use PHPMailer\PHPMailer\SMTP; use PHPMailer\PHPMailer\Exception; -//Load Composer's autoloader +// Load Composer's autoloader require 'vendor/autoload.php'; -$mail = new PHPMailer(true); // Passing `true` enables exceptions +// Instantiation and passing `true` enables exceptions +$mail = new PHPMailer(true); + try { //Server settings - $mail->SMTPDebug = 2; // Enable verbose debug output - $mail->isSMTP(); // Set mailer to use SMTP - $mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers - $mail->SMTPAuth = true; // Enable SMTP authentication - $mail->Username = 'user@example.com'; // SMTP username - $mail->Password = 'secret'; // SMTP password - $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted - $mail->Port = 587; // TCP port to connect to + $mail->SMTPDebug = SMTP::DEBUG_SERVER; // Enable verbose debug output + $mail->isSMTP(); // Send using SMTP + $mail->Host = 'smtp1.example.com'; // Set the SMTP server to send through + $mail->SMTPAuth = true; // Enable SMTP authentication + $mail->Username = 'user@example.com'; // SMTP username + $mail->Password = 'secret'; // SMTP password + $mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; // Enable TLS encryption; `PHPMailer::ENCRYPTION_SMTPS` also accepted + $mail->Port = 587; // TCP port to connect to //Recipients $mail->setFrom('from@example.com', 'Mailer'); @@ -112,11 +113,11 @@ try { $mail->addCC('cc@example.com'); $mail->addBCC('bcc@example.com'); - //Attachments + // Attachments $mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments $mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name - //Content + // Content $mail->isHTML(true); // Set email format to HTML $mail->Subject = 'Here is the subject'; $mail->Body = 'This is the HTML message body in bold!'; @@ -125,16 +126,18 @@ try { $mail->send(); echo 'Message has been sent'; } catch (Exception $e) { - echo 'Message could not be sent. Mailer Error: ', $mail->ErrorInfo; + echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; } ``` You'll find plenty more to play with in the [examples](https://github.com/PHPMailer/PHPMailer/tree/master/examples) folder. +If you are re-using the instance (e.g. when sending to a mailing list), you may need to clear the recipient list to avoid sending duplicate messages. See [the mailing list example](https://github.com/PHPMailer/PHPMailer/blob/master/examples/mailing_list.phps) for further guidance. + That's it. You should now be ready to use PHPMailer! ## Localization -PHPMailer defaults to English, but in the [language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder you'll find numerous (48 at the time of writing!) translations for PHPMailer error messages that you may encounter. Their filenames contain [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) language code for the translations, for example `fr` for French. To specify a language, you need to tell PHPMailer which one to use, like this: +PHPMailer defaults to English, but in the [language](https://github.com/PHPMailer/PHPMailer/tree/master/language/) folder you'll find many translations for PHPMailer error messages that you may encounter. Their filenames contain [ISO 639-1](http://en.wikipedia.org/wiki/ISO_639-1) language code for the translations, for example `fr` for French. To specify a language, you need to tell PHPMailer which one to use, like this: ```php // To load the French version diff --git a/vendor/phpmailer/phpmailer/VERSION b/vendor/phpmailer/phpmailer/VERSION index 41bd15e2e..132c6def5 100644 --- a/vendor/phpmailer/phpmailer/VERSION +++ b/vendor/phpmailer/phpmailer/VERSION @@ -1 +1 @@ -6.0.7 \ No newline at end of file +6.1.1 \ No newline at end of file diff --git a/vendor/phpmailer/phpmailer/composer.json b/vendor/phpmailer/phpmailer/composer.json index ee4e890d2..d1b14171b 100644 --- a/vendor/phpmailer/phpmailer/composer.json +++ b/vendor/phpmailer/phpmailer/composer.json @@ -51,5 +51,5 @@ "PHPMailer\\Test\\": "test/" } }, - "license": "LGPL-2.1" + "license": "LGPL-2.1-only" } diff --git a/vendor/phpmailer/phpmailer/language/phpmailer.lang-af.php b/vendor/phpmailer/phpmailer/language/phpmailer.lang-af.php new file mode 100644 index 000000000..3c42d78e1 --- /dev/null +++ b/vendor/phpmailer/phpmailer/language/phpmailer.lang-af.php @@ -0,0 +1,25 @@ + + * @author Marcus Bointon */ class Exception extends \Exception { diff --git a/vendor/phpmailer/phpmailer/src/PHPMailer.php b/vendor/phpmailer/phpmailer/src/PHPMailer.php index 52104924d..4897b5e23 100644 --- a/vendor/phpmailer/phpmailer/src/PHPMailer.php +++ b/vendor/phpmailer/phpmailer/src/PHPMailer.php @@ -3,13 +3,13 @@ * PHPMailer - PHP email creation and transport class. * PHP Version 5.5. * - * @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project + * @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project * * @author Marcus Bointon (Synchro/coolbru) * @author Jim Jagielski (jimjag) * @author Andy Prevost (codeworxtech) * @author Brent R. Matzelle (original founder) - * @copyright 2012 - 2017 Marcus Bointon + * @copyright 2012 - 2019 Marcus Bointon * @copyright 2010 - 2012 Jim Jagielski * @copyright 2004 - 2009 Andy Prevost * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License @@ -23,13 +23,14 @@ /** * PHPMailer - PHP email creation and transport class. * - * @author Marcus Bointon (Synchro/coolbru) - * @author Jim Jagielski (jimjag) - * @author Andy Prevost (codeworxtech) - * @author Brent R. Matzelle (original founder) + * @author Marcus Bointon (Synchro/coolbru) + * @author Jim Jagielski (jimjag) + * @author Andy Prevost (codeworxtech) + * @author Brent R. Matzelle (original founder) */ class PHPMailer { + const CHARSET_ASCII = 'us-ascii'; const CHARSET_ISO88591 = 'iso-8859-1'; const CHARSET_UTF8 = 'utf-8'; @@ -46,6 +47,18 @@ class PHPMailer const ENCODING_BINARY = 'binary'; const ENCODING_QUOTED_PRINTABLE = 'quoted-printable'; + const ENCRYPTION_STARTTLS = 'tls'; + const ENCRYPTION_SMTPS = 'ssl'; + + const ICAL_METHOD_REQUEST = 'REQUEST'; + const ICAL_METHOD_PUBLISH = 'PUBLISH'; + const ICAL_METHOD_REPLY = 'REPLY'; + const ICAL_METHOD_ADD = 'ADD'; + const ICAL_METHOD_CANCEL = 'CANCEL'; + const ICAL_METHOD_REFRESH = 'REFRESH'; + const ICAL_METHOD_COUNTER = 'COUNTER'; + const ICAL_METHOD_DECLINECOUNTER = 'DECLINECOUNTER'; + /** * Email priority. * Options: null (default), 1 = High, 3 = Normal, 5 = low. @@ -145,6 +158,22 @@ class PHPMailer */ public $Ical = ''; + /** + * Value-array of "method" in Contenttype header "text/calendar" + * + * @var string[] + */ + protected static $IcalMethods = [ + self::ICAL_METHOD_REQUEST, + self::ICAL_METHOD_PUBLISH, + self::ICAL_METHOD_REPLY, + self::ICAL_METHOD_ADD, + self::ICAL_METHOD_CANCEL, + self::ICAL_METHOD_REFRESH, + self::ICAL_METHOD_COUNTER, + self::ICAL_METHOD_DECLINECOUNTER, + ]; + /** * The complete compiled MIME message body. * @@ -212,6 +241,8 @@ class PHPMailer * $_SERVER['SERVER_NAME'], gethostname(), php_uname('n'), or the value * 'localhost.localdomain'. * + * @see PHPMailer::$Helo + * * @var string */ public $Hostname = ''; @@ -258,7 +289,7 @@ class PHPMailer public $Port = 25; /** - * The SMTP HELO of the message. + * The SMTP HELO/EHLO name used for the SMTP connection. * Default is $Hostname. If $Hostname is empty, PHPMailer attempts to find * one with the same method described above for $Hostname. * @@ -270,7 +301,7 @@ class PHPMailer /** * What kind of encryption to use on the SMTP connection. - * Options: '', 'ssl' or 'tls'. + * Options: '', static::ENCRYPTION_STARTTLS, or static::ENCRYPTION_SMTPS. * * @var string */ @@ -340,15 +371,28 @@ class PHPMailer */ public $Timeout = 300; + /** + * Comma separated list of DSN notifications + * 'NEVER' under no circumstances a DSN must be returned to the sender. + * If you use NEVER all other notifications will be ignored. + * 'SUCCESS' will notify you when your mail has arrived at its destination. + * 'FAILURE' will arrive if an error occurred during delivery. + * 'DELAY' will notify you if there is an unusual delay in delivery, but the actual + * delivery's outcome (success or failure) is not yet decided. + * + * @see https://tools.ietf.org/html/rfc3461 See section 4.1 for more information about NOTIFY + */ + public $dsn = ''; + /** * SMTP class debug output mode. * Debug output level. * Options: - * * `0` No output - * * `1` Commands - * * `2` Data and commands - * * `3` As 2 plus connection status - * * `4` Low-level data output. + * * SMTP::DEBUG_OFF: No output + * * SMTP::DEBUG_CLIENT: Client messages + * * SMTP::DEBUG_SERVER: Client and server messages + * * SMTP::DEBUG_CONNECTION: As SERVER plus connection status + * * SMTP::DEBUG_LOWLEVEL: Noisy, low-level data output, rarely needed * * @see SMTP::$do_debug * @@ -514,9 +558,9 @@ class PHPMailer /** * What to put in the X-Mailer header. - * Options: An empty string for PHPMailer default, whitespace for none, or a string to use. + * Options: An empty string for PHPMailer default, whitespace/null for none, or a string to use. * - * @var string + * @var string|null */ public $XMailer = ''; @@ -701,7 +745,7 @@ class PHPMailer * * @var string */ - const VERSION = '6.0.7'; + const VERSION = '6.1.1'; /** * Error severity: message only, continue processing. @@ -731,6 +775,16 @@ class PHPMailer */ protected static $LE = "\r\n"; + /** + * The maximum line length supported by mail(). + * + * Background: mail() will sometimes corrupt messages + * with headers headers longer than 65 chars, see #818. + * + * @var int + */ + const MAIL_MAX_LINE_LENGTH = 63; + /** * The maximum line length allowed by RFC 2822 section 2.1.1. * @@ -927,6 +981,8 @@ public function isQmail() * @param string $address The email address to send to * @param string $name * + * @throws Exception + * * @return bool true on success, false if address already used or invalid in some way */ public function addAddress($address, $name = '') @@ -940,6 +996,8 @@ public function addAddress($address, $name = '') * @param string $address The email address to send to * @param string $name * + * @throws Exception + * * @return bool true on success, false if address already used or invalid in some way */ public function addCC($address, $name = '') @@ -953,6 +1011,8 @@ public function addCC($address, $name = '') * @param string $address The email address to send to * @param string $name * + * @throws Exception + * * @return bool true on success, false if address already used or invalid in some way */ public function addBCC($address, $name = '') @@ -966,6 +1026,8 @@ public function addBCC($address, $name = '') * @param string $address The email address to reply to * @param string $name * + * @throws Exception + * * @return bool true on success, false if address already used or invalid in some way */ public function addReplyTo($address, $name = '') @@ -994,10 +1056,12 @@ protected function addOrEnqueueAnAddress($kind, $address, $name) $pos = strrpos($address, '@'); if (false === $pos) { // At-sign is missing. - $error_message = sprintf('%s (%s): %s', + $error_message = sprintf( + '%s (%s): %s', $this->lang('invalid_address'), $kind, - $address); + $address + ); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1045,9 +1109,11 @@ protected function addOrEnqueueAnAddress($kind, $address, $name) protected function addAnAddress($kind, $address, $name = '') { if (!in_array($kind, ['to', 'cc', 'bcc', 'Reply-To'])) { - $error_message = sprintf('%s: %s', + $error_message = sprintf( + '%s: %s', $this->lang('Invalid recipient kind'), - $kind); + $kind + ); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1057,10 +1123,12 @@ protected function addAnAddress($kind, $address, $name = '') return false; } if (!static::validateAddress($address)) { - $error_message = sprintf('%s (%s): %s', + $error_message = sprintf( + '%s (%s): %s', $this->lang('invalid_address'), $kind, - $address); + $address + ); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1093,7 +1161,7 @@ protected function addAnAddress($kind, $address, $name = '') * Uses the imap_rfc822_parse_adrlist function if the IMAP extension is available. * Note that quotes in the name part are removed. * - * @see http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation + * @see http://www.andrew.cmu.edu/user/agreen1/testing/mrbs/web/Mail/RFC822.php A more careful implementation * * @param string $addrstr The address list string * @param bool $useimap Whether to use the IMAP extension to parse the list @@ -1163,12 +1231,15 @@ public function setFrom($address, $name = '', $auto = true) $name = trim(preg_replace('/[\r\n]+/', '', $name)); //Strip breaks and trim // Don't validate now addresses with IDN. Will be done in send(). $pos = strrpos($address, '@'); - if (false === $pos or - (!$this->has8bitChars(substr($address, ++$pos)) or !static::idnSupported()) and - !static::validateAddress($address)) { - $error_message = sprintf('%s (From): %s', + if (false === $pos + or (!$this->has8bitChars(substr($address, ++$pos)) or !static::idnSupported()) + and !static::validateAddress($address) + ) { + $error_message = sprintf( + '%s (From): %s', $this->lang('invalid_address'), - $address); + $address + ); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1304,7 +1375,7 @@ public static function idnSupported() * - Conversion to punycode is impossible (e.g. required PHP functions are not available) * or fails for any reason (e.g. domain contains characters not allowed in an IDN). * - * @see PHPMailer::$CharSet + * @see PHPMailer::$CharSet * * @param string $address The email address to convert * @@ -1370,8 +1441,8 @@ public function send() */ public function preSend() { - if ('smtp' == $this->Mailer or - ('mail' == $this->Mailer and stripos(PHP_OS, 'WIN') === 0) + if ('smtp' == $this->Mailer + or ('mail' == $this->Mailer and stripos(PHP_OS, 'WIN') === 0) ) { //SMTP mandates RFC-compliant line endings //and it's also used with mail() on Windows @@ -1418,10 +1489,12 @@ public function preSend() } $this->$address_kind = $this->punyencodeAddress($this->$address_kind); if (!static::validateAddress($this->$address_kind)) { - $error_message = sprintf('%s (%s): %s', + $error_message = sprintf( + '%s (%s): %s', $this->lang('invalid_address'), $address_kind, - $this->$address_kind); + $this->$address_kind + ); $this->setError($error_message); $this->edebug($error_message); if ($this->exceptions) { @@ -1538,7 +1611,7 @@ public function postSend() /** * Send mail using the $Sendmail program. * - * @see PHPMailer::$Sendmail + * @see PHPMailer::$Sendmail * * @param string $header The message headers * @param string $body The message body @@ -1668,7 +1741,7 @@ protected static function isPermittedPath($path) /** * Send mail using the PHP mail() function. * - * @see http://www.php.net/manual/en/book.mail.php + * @see http://www.php.net/manual/en/book.mail.php * * @param string $header The message headers * @param string $body The message body @@ -1789,7 +1862,7 @@ protected function smtpSend($header, $body) // Attempt to send to all recipients foreach ([$this->to, $this->cc, $this->bcc] as $togroup) { foreach ($togroup as $to) { - if (!$this->smtp->recipient($to[0])) { + if (!$this->smtp->recipient($to[0], $this->dsn)) { $error = $this->smtp->getError(); $bad_rcpt[] = ['to' => $to[0], 'error' => $error['detail']]; $isSent = false; @@ -1902,19 +1975,19 @@ public function smtpConnect($options = null) } $prefix = ''; $secure = $this->SMTPSecure; - $tls = ('tls' == $this->SMTPSecure); - if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and 'ssl' == $this->SMTPSecure)) { + $tls = (static::ENCRYPTION_STARTTLS == $this->SMTPSecure); + if ('ssl' == $hostinfo[2] or ('' == $hostinfo[2] and static::ENCRYPTION_SMTPS == $this->SMTPSecure)) { $prefix = 'ssl://'; $tls = false; // Can't have SSL and TLS at the same time - $secure = 'ssl'; + $secure = static::ENCRYPTION_SMTPS; } elseif ('tls' == $hostinfo[2]) { $tls = true; // tls doesn't use a prefix - $secure = 'tls'; + $secure = static::ENCRYPTION_STARTTLS; } //Do we need the OpenSSL extension? $sslext = defined('OPENSSL_ALGO_SHA256'); - if ('tls' === $secure or 'ssl' === $secure) { + if (static::ENCRYPTION_STARTTLS === $secure or static::ENCRYPTION_SMTPS === $secure) { //Check for an OpenSSL constant rather than using extension_loaded, which is sometimes disabled if (!$sslext) { throw new Exception($this->lang('extension_missing') . 'openssl', self::STOP_CRITICAL); @@ -2114,8 +2187,8 @@ public function addrFormat($addr) } return $this->encodeHeader($this->secureHeader($addr[1]), 'phrase') . ' <' . $this->secureHeader( - $addr[0] - ) . '>'; + $addr[0] + ) . '>'; } /** @@ -2357,7 +2430,7 @@ public function createHeader() if (null !== $this->Priority) { $result .= $this->headerLine('X-Priority', $this->Priority); } - if ('' == $this->XMailer) { + if ('' === $this->XMailer) { $result .= $this->headerLine( 'X-Mailer', 'PHPMailer ' . self::VERSION . ' (https://github.com/PHPMailer/PHPMailer)' @@ -2400,19 +2473,19 @@ public function getMailMIME() switch ($this->message_type) { case 'inline': $result .= $this->headerLine('Content-Type', static::CONTENT_TYPE_MULTIPART_RELATED . ';'); - $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"'); + $result .= $this->textLine(' boundary="' . $this->boundary[1] . '"'); break; case 'attach': case 'inline_attach': case 'alt_attach': case 'alt_inline_attach': $result .= $this->headerLine('Content-Type', static::CONTENT_TYPE_MULTIPART_MIXED . ';'); - $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"'); + $result .= $this->textLine(' boundary="' . $this->boundary[1] . '"'); break; case 'alt': case 'alt_inline': $result .= $this->headerLine('Content-Type', static::CONTENT_TYPE_MULTIPART_ALTERNATIVE . ';'); - $result .= $this->textLine("\tboundary=\"" . $this->boundary[1] . '"'); + $result .= $this->textLine(' boundary="' . $this->boundary[1] . '"'); break; default: // Catches case 'plain': and case '': @@ -2504,7 +2577,7 @@ public function createBody() if (static::ENCODING_8BIT == $bodyEncoding and !$this->has8bitChars($this->Body)) { $bodyEncoding = static::ENCODING_7BIT; //All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit - $bodyCharSet = 'us-ascii'; + $bodyCharSet = static::CHARSET_ASCII; } //If lines are too long, and we're not already using an encoding that will shorten them, //change to quoted-printable transfer encoding for the body part only @@ -2518,7 +2591,7 @@ public function createBody() if (static::ENCODING_8BIT == $altBodyEncoding and !$this->has8bitChars($this->AltBody)) { $altBodyEncoding = static::ENCODING_7BIT; //All ISO 8859, Windows codepage and UTF-8 charsets are ascii compatible up to 7-bit - $altBodyCharSet = 'us-ascii'; + $altBodyCharSet = static::CHARSET_ASCII; } //If lines are too long, and we're not already using an encoding that will shorten them, //change to quoted-printable transfer encoding for the alt body part only @@ -2546,7 +2619,8 @@ public function createBody() $body .= $mimepre; $body .= $this->textLine('--' . $this->boundary[1]); $body .= $this->headerLine('Content-Type', static::CONTENT_TYPE_MULTIPART_RELATED . ';'); - $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"'); + $body .= $this->textLine(' boundary="' . $this->boundary[2] . '";'); + $body .= $this->textLine(' type="' . static::CONTENT_TYPE_TEXT_HTML . '"'); $body .= static::$LE; $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, '', $bodyEncoding); $body .= $this->encodeString($this->Body, $bodyEncoding); @@ -2564,7 +2638,14 @@ public function createBody() $body .= $this->encodeString($this->Body, $bodyEncoding); $body .= static::$LE; if (!empty($this->Ical)) { - $body .= $this->getBoundary($this->boundary[1], '', static::CONTENT_TYPE_TEXT_CALENDAR . '; method=REQUEST', ''); + $method = static::ICAL_METHOD_REQUEST; + foreach (static::$IcalMethods as $imethod) { + if (stripos($this->Ical, 'METHOD:' . $imethod) !== false) { + $method = $imethod; + break; + } + } + $body .= $this->getBoundary($this->boundary[1], '', static::CONTENT_TYPE_TEXT_CALENDAR . '; method=' . $method, ''); $body .= $this->encodeString($this->Ical, $this->Encoding); $body .= static::$LE; } @@ -2577,7 +2658,8 @@ public function createBody() $body .= static::$LE; $body .= $this->textLine('--' . $this->boundary[1]); $body .= $this->headerLine('Content-Type', static::CONTENT_TYPE_MULTIPART_RELATED . ';'); - $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"'); + $body .= $this->textLine(' boundary="' . $this->boundary[2] . '";'); + $body .= $this->textLine(' type="' . static::CONTENT_TYPE_TEXT_HTML . '"'); $body .= static::$LE; $body .= $this->getBoundary($this->boundary[2], $bodyCharSet, static::CONTENT_TYPE_TEXT_HTML, $bodyEncoding); $body .= $this->encodeString($this->Body, $bodyEncoding); @@ -2590,7 +2672,7 @@ public function createBody() $body .= $mimepre; $body .= $this->textLine('--' . $this->boundary[1]); $body .= $this->headerLine('Content-Type', static::CONTENT_TYPE_MULTIPART_ALTERNATIVE . ';'); - $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"'); + $body .= $this->textLine(' boundary="' . $this->boundary[2] . '"'); $body .= static::$LE; $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, static::CONTENT_TYPE_PLAINTEXT, $altBodyEncoding); $body .= $this->encodeString($this->AltBody, $altBodyEncoding); @@ -2599,7 +2681,14 @@ public function createBody() $body .= $this->encodeString($this->Body, $bodyEncoding); $body .= static::$LE; if (!empty($this->Ical)) { - $body .= $this->getBoundary($this->boundary[2], '', static::CONTENT_TYPE_TEXT_CALENDAR . '; method=REQUEST', ''); + $method = static::ICAL_METHOD_REQUEST; + foreach (static::$IcalMethods as $imethod) { + if (stripos($this->Ical, 'METHOD:' . $imethod) !== false) { + $method = $imethod; + break; + } + } + $body .= $this->getBoundary($this->boundary[2], '', static::CONTENT_TYPE_TEXT_CALENDAR . '; method=' . $method, ''); $body .= $this->encodeString($this->Ical, $this->Encoding); } $body .= $this->endBoundary($this->boundary[2]); @@ -2610,14 +2699,15 @@ public function createBody() $body .= $mimepre; $body .= $this->textLine('--' . $this->boundary[1]); $body .= $this->headerLine('Content-Type', static::CONTENT_TYPE_MULTIPART_ALTERNATIVE . ';'); - $body .= $this->textLine("\tboundary=\"" . $this->boundary[2] . '"'); + $body .= $this->textLine(' boundary="' . $this->boundary[2] . '"'); $body .= static::$LE; $body .= $this->getBoundary($this->boundary[2], $altBodyCharSet, static::CONTENT_TYPE_PLAINTEXT, $altBodyEncoding); $body .= $this->encodeString($this->AltBody, $altBodyEncoding); $body .= static::$LE; $body .= $this->textLine('--' . $this->boundary[2]); $body .= $this->headerLine('Content-Type', static::CONTENT_TYPE_MULTIPART_RELATED . ';'); - $body .= $this->textLine("\tboundary=\"" . $this->boundary[3] . '"'); + $body .= $this->textLine(' boundary="' . $this->boundary[3] . '";'); + $body .= $this->textLine(' type="' . static::CONTENT_TYPE_TEXT_HTML . '"'); $body .= static::$LE; $body .= $this->getBoundary($this->boundary[3], $bodyCharSet, static::CONTENT_TYPE_TEXT_HTML, $bodyEncoding); $body .= $this->encodeString($this->Body, $bodyEncoding); @@ -2646,12 +2736,11 @@ public function createBody() if (!defined('PKCS7_TEXT')) { throw new Exception($this->lang('extension_missing') . 'openssl'); } - // @TODO would be nice to use php://temp streams here - $file = tempnam(sys_get_temp_dir(), 'mail'); - if (false === file_put_contents($file, $body)) { - throw new Exception($this->lang('signing') . ' Could not write temp file'); - } - $signed = tempnam(sys_get_temp_dir(), 'signed'); + + $file = tempnam(sys_get_temp_dir(), 'srcsign'); + $signed = tempnam(sys_get_temp_dir(), 'mailsign'); + file_put_contents($file, $body); + //Workaround for PHP bug https://bugs.php.net/bug.php?id=69197 if (empty($this->sign_extracerts_file)) { $sign = @openssl_pkcs7_sign( @@ -2672,6 +2761,7 @@ public function createBody() $this->sign_extracerts_file ); } + @unlink($file); if ($sign) { $body = file_get_contents($signed); @@ -2806,8 +2896,13 @@ public function textLine($value) * * @return bool */ - public function addAttachment($path, $name = '', $encoding = self::ENCODING_BASE64, $type = '', $disposition = 'attachment') - { + public function addAttachment( + $path, + $name = '', + $encoding = self::ENCODING_BASE64, + $type = '', + $disposition = 'attachment' + ) { try { if (!static::isPermittedPath($path) || !@is_file($path)) { throw new Exception($this->lang('file_access') . $path, self::STOP_CONTINUE); @@ -2818,11 +2913,15 @@ public function addAttachment($path, $name = '', $encoding = self::ENCODING_BASE $type = static::filenameToType($path); } - $filename = basename($path); + $filename = static::mb_pathinfo($path, PATHINFO_BASENAME); if ('' == $name) { $name = $filename; } + if (!$this->validateEncoding($encoding)) { + throw new Exception($this->lang('encoding') . $encoding); + } + $this->attachment[] = [ 0 => $path, 1 => $filename, @@ -2923,14 +3022,18 @@ protected function attachAll($disposition_type, $boundary) } if (!empty($cid)) { - $mime[] = sprintf('Content-ID: <%s>%s', $cid, static::$LE); + $mime[] = sprintf( + 'Content-ID: <%s>%s', + $this->encodeHeader($this->secureHeader($cid)), + static::$LE + ); } // If a filename contains any of these chars, it should be quoted, // but not otherwise: RFC2183 & RFC2045 5.1 // Fixes a warning in IETF's msglint MIME checker // Allow for bypassing the Content-Disposition header totally - if (!(empty($disposition))) { + if (!empty($disposition)) { $encoded_name = $this->encodeHeader($this->secureHeader($name)); if (preg_match('/[ \(\)<>@,;:\\"\/\[\]\?=]/', $encoded_name)) { $mime[] = sprintf( @@ -3015,6 +3118,8 @@ protected function encodeFile($path, $encoding = self::ENCODING_BASE64) * @param string $str The text to encode * @param string $encoding The encoding to use; one of 'base64', '7bit', '8bit', 'binary', 'quoted-printable' * + * @throws Exception + * * @return string */ public function encodeString($str, $encoding = self::ENCODING_BASE64) @@ -3044,6 +3149,9 @@ public function encodeString($str, $encoding = self::ENCODING_BASE64) break; default: $this->setError($this->lang('encoding') . $encoding); + if ($this->exceptions) { + throw new Exception($this->lang('encoding') . $encoding); + } break; } @@ -3086,51 +3194,57 @@ public function encodeHeader($str, $position = 'text') break; } - //RFCs specify a maximum line length of 78 chars, however mail() will sometimes - //corrupt messages with headers longer than 65 chars. See #818 - $lengthsub = 'mail' == $this->Mailer ? 13 : 0; - $maxlen = static::STD_LINE_LENGTH - $lengthsub; - // Try to select the encoding which should produce the shortest output + if ($this->has8bitChars($str)) { + $charset = $this->CharSet; + } else { + $charset = static::CHARSET_ASCII; + } + + // Q/B encoding adds 8 chars and the charset ("` =??[QB]??=`"). + $overhead = 8 + strlen($charset); + + if ('mail' == $this->Mailer) { + $maxlen = static::MAIL_MAX_LINE_LENGTH - $overhead; + } else { + $maxlen = static::STD_LINE_LENGTH - $overhead; + } + + // Select the encoding that produces the shortest output and/or prevents corruption. if ($matchcount > strlen($str) / 3) { - // More than a third of the content will need encoding, so B encoding will be most efficient + // More than 1/3 of the content needs encoding, use B-encode. $encoding = 'B'; - //This calculation is: - // max line length - // - shorten to avoid mail() corruption - // - Q/B encoding char overhead ("` =??[QB]??=`") - // - charset name length - $maxlen = static::STD_LINE_LENGTH - $lengthsub - 8 - strlen($this->CharSet); - if ($this->hasMultiBytes($str)) { - // Use a custom function which correctly encodes and wraps long - // multibyte strings without breaking lines within a character - $encoded = $this->base64EncodeWrapMB($str, "\n"); - } else { - $encoded = base64_encode($str); - $maxlen -= $maxlen % 4; - $encoded = trim(chunk_split($encoded, $maxlen, "\n")); - } - $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded); } elseif ($matchcount > 0) { - //1 or more chars need encoding, use Q-encode + // Less than 1/3 of the content needs encoding, use Q-encode. $encoding = 'Q'; - //Recalc max line length for Q encoding - see comments on B encode - $maxlen = static::STD_LINE_LENGTH - $lengthsub - 8 - strlen($this->CharSet); - $encoded = $this->encodeQ($str, $position); - $encoded = $this->wrapText($encoded, $maxlen, true); - $encoded = str_replace('=' . static::$LE, "\n", trim($encoded)); - $encoded = preg_replace('/^(.*)$/m', ' =?' . $this->CharSet . "?$encoding?\\1?=", $encoded); } elseif (strlen($str) > $maxlen) { - //No chars need encoding, but line is too long, so fold it - $encoded = trim($this->wrapText($str, $maxlen, false)); - if ($str == $encoded) { - //Wrapping nicely didn't work, wrap hard instead - $encoded = trim(chunk_split($str, static::STD_LINE_LENGTH, static::$LE)); - } - $encoded = str_replace(static::$LE, "\n", trim($encoded)); - $encoded = preg_replace('/^(.*)$/m', ' \\1', $encoded); + // No encoding needed, but value exceeds max line length, use Q-encode to prevent corruption. + $encoding = 'Q'; } else { - //No reformatting needed - return $str; + // No reformatting needed + $encoding = false; + } + + switch ($encoding) { + case 'B': + if ($this->hasMultiBytes($str)) { + // Use a custom function which correctly encodes and wraps long + // multibyte strings without breaking lines within a character + $encoded = $this->base64EncodeWrapMB($str, "\n"); + } else { + $encoded = base64_encode($str); + $maxlen -= $maxlen % 4; + $encoded = trim(chunk_split($encoded, $maxlen, "\n")); + } + $encoded = preg_replace('/^(.*)$/m', ' =?' . $charset . "?$encoding?\\1?=", $encoded); + break; + case 'Q': + $encoded = $this->encodeQ($str, $position); + $encoded = $this->wrapText($encoded, $maxlen, true); + $encoded = str_replace('=' . static::$LE, "\n", trim($encoded)); + $encoded = preg_replace('/^(.*)$/m', ' =?' . $charset . "?$encoding?\\1?=", $encoded); + break; + default: + return $str; } return trim(static::normalizeBreaks($encoded)); @@ -3286,6 +3400,10 @@ public function encodeQ($str, $position = 'text') * @param string $encoding File encoding (see $Encoding) * @param string $type File extension (MIME) type * @param string $disposition Disposition to use + * + * @throws Exception + * + * @return bool True on successfully adding an attachment */ public function addStringAttachment( $string, @@ -3294,21 +3412,38 @@ public function addStringAttachment( $type = '', $disposition = 'attachment' ) { - // If a MIME type is not specified, try to work it out from the file name - if ('' == $type) { - $type = static::filenameToType($filename); - } - // Append to $attachment array - $this->attachment[] = [ - 0 => $string, - 1 => $filename, - 2 => basename($filename), - 3 => $encoding, - 4 => $type, - 5 => true, // isStringAttachment - 6 => $disposition, - 7 => 0, - ]; + try { + // If a MIME type is not specified, try to work it out from the file name + if ('' == $type) { + $type = static::filenameToType($filename); + } + + if (!$this->validateEncoding($encoding)) { + throw new Exception($this->lang('encoding') . $encoding); + } + + // Append to $attachment array + $this->attachment[] = [ + 0 => $string, + 1 => $filename, + 2 => static::mb_pathinfo($filename, PATHINFO_BASENAME), + 3 => $encoding, + 4 => $type, + 5 => true, // isStringAttachment + 6 => $disposition, + 7 => 0, + ]; + } catch (Exception $exc) { + $this->setError($exc->getMessage()); + $this->edebug($exc->getMessage()); + if ($this->exceptions) { + throw $exc; + } + + return false; + } + + return true; } /** @@ -3328,37 +3463,57 @@ public function addStringAttachment( * @param string $type File MIME type * @param string $disposition Disposition to use * + * @throws Exception + * * @return bool True on successfully adding an attachment */ - public function addEmbeddedImage($path, $cid, $name = '', $encoding = self::ENCODING_BASE64, $type = '', $disposition = 'inline') - { - if (!static::isPermittedPath($path) || !@is_file($path)) { - $this->setError($this->lang('file_access') . $path); + public function addEmbeddedImage( + $path, + $cid, + $name = '', + $encoding = self::ENCODING_BASE64, + $type = '', + $disposition = 'inline' + ) { + try { + if (!static::isPermittedPath($path) || !@is_file($path)) { + throw new Exception($this->lang('file_access') . $path, self::STOP_CONTINUE); + } - return false; - } + // If a MIME type is not specified, try to work it out from the file name + if ('' == $type) { + $type = static::filenameToType($path); + } - // If a MIME type is not specified, try to work it out from the file name - if ('' == $type) { - $type = static::filenameToType($path); - } + if (!$this->validateEncoding($encoding)) { + throw new Exception($this->lang('encoding') . $encoding); + } - $filename = basename($path); - if ('' == $name) { - $name = $filename; - } + $filename = static::mb_pathinfo($path, PATHINFO_BASENAME); + if ('' == $name) { + $name = $filename; + } - // Append to $attachment array - $this->attachment[] = [ - 0 => $path, - 1 => $filename, - 2 => $name, - 3 => $encoding, - 4 => $type, - 5 => false, // isStringAttachment - 6 => $disposition, - 7 => $cid, - ]; + // Append to $attachment array + $this->attachment[] = [ + 0 => $path, + 1 => $filename, + 2 => $name, + 3 => $encoding, + 4 => $type, + 5 => false, // isStringAttachment + 6 => $disposition, + 7 => $cid, + ]; + } catch (Exception $exc) { + $this->setError($exc->getMessage()); + $this->edebug($exc->getMessage()); + if ($this->exceptions) { + throw $exc; + } + + return false; + } return true; } @@ -3378,6 +3533,8 @@ public function addEmbeddedImage($path, $cid, $name = '', $encoding = self::ENCO * @param string $type MIME type - will be used in preference to any automatically derived type * @param string $disposition Disposition to use * + * @throws Exception + * * @return bool True on successfully adding an attachment */ public function addStringEmbeddedImage( @@ -3388,26 +3545,62 @@ public function addStringEmbeddedImage( $type = '', $disposition = 'inline' ) { - // If a MIME type is not specified, try to work it out from the name - if ('' == $type and !empty($name)) { - $type = static::filenameToType($name); - } - - // Append to $attachment array - $this->attachment[] = [ - 0 => $string, - 1 => $name, - 2 => $name, - 3 => $encoding, - 4 => $type, - 5 => true, // isStringAttachment - 6 => $disposition, - 7 => $cid, - ]; + try { + // If a MIME type is not specified, try to work it out from the name + if ('' == $type and !empty($name)) { + $type = static::filenameToType($name); + } + + if (!$this->validateEncoding($encoding)) { + throw new Exception($this->lang('encoding') . $encoding); + } + + // Append to $attachment array + $this->attachment[] = [ + 0 => $string, + 1 => $name, + 2 => $name, + 3 => $encoding, + 4 => $type, + 5 => true, // isStringAttachment + 6 => $disposition, + 7 => $cid, + ]; + } catch (Exception $exc) { + $this->setError($exc->getMessage()); + $this->edebug($exc->getMessage()); + if ($this->exceptions) { + throw $exc; + } + + return false; + } return true; } + /** + * Validate encodings. + * + * @param $encoding + * + * @return bool + */ + protected function validateEncoding($encoding) + { + return in_array( + $encoding, + [ + self::ENCODING_7BIT, + self::ENCODING_QUOTED_PRINTABLE, + self::ENCODING_BASE64, + self::ENCODING_8BIT, + self::ENCODING_BINARY, + ], + true + ); + } + /** * Check if an embedded attachment is present with this cid. * @@ -3783,7 +3976,7 @@ public function msgHTML($message, $basedir = '', $advanced = false) // Do not change absolute URLs, including anonymous protocol and !preg_match('#^[a-z][a-z0-9+.-]*:?//#i', $url) ) { - $filename = basename($url); + $filename = static::mb_pathinfo($url, PATHINFO_BASENAME); $directory = dirname($url); if ('.' == $directory) { $directory = ''; @@ -4014,7 +4207,7 @@ public static function filenameToType($filename) * Multi-byte-safe pathinfo replacement. * Drop-in replacement for pathinfo(), but multibyte- and cross-platform-safe. * - * @see http://www.php.net/manual/en/function.pathinfo.php#107461 + * @see http://www.php.net/manual/en/function.pathinfo.php#107461 * * @param string $path A filename or path, does not need to exist as a file * @param int|string $options Either a PATHINFO_* constant, @@ -4026,7 +4219,7 @@ public static function mb_pathinfo($path, $options = null) { $ret = ['dirname' => '', 'basename' => '', 'extension' => '', 'filename' => '']; $pathinfo = []; - if (preg_match('#^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^\.\\\\/]+?)|))[\\\\/\.]*$#im', $path, $pathinfo)) { + if (preg_match('#^(.*?)[\\\\/]*(([^/\\\\]*?)(\.([^.\\\\/]+?)|))[\\\\/.]*$#m', $path, $pathinfo)) { if (array_key_exists(1, $pathinfo)) { $ret['dirname'] = $pathinfo[1]; } @@ -4063,9 +4256,9 @@ public static function mb_pathinfo($path, $options = null) * You should avoid this function - it's more verbose, less efficient, more error-prone and * harder to debug than setting properties directly. * Usage Example: - * `$mail->set('SMTPSecure', 'tls');` + * `$mail->set('SMTPSecure', static::ENCRYPTION_STARTTLS);` * is the same as: - * `$mail->SMTPSecure = 'tls';`. + * `$mail->SMTPSecure = static::ENCRYPTION_STARTTLS;`. * * @param string $name The property name to set * @param mixed $value The value to set the property to @@ -4221,7 +4414,7 @@ public function DKIM_Sign($signHeader) * Uses the 'relaxed' algorithm from RFC6376 section 3.4.2. * Canonicalized headers should *always* use CRLF, regardless of mailer setting. * - * @see https://tools.ietf.org/html/rfc6376#section-3.4.2 + * @see https://tools.ietf.org/html/rfc6376#section-3.4.2 * * @param string $signHeader Header * @@ -4229,12 +4422,14 @@ public function DKIM_Sign($signHeader) */ public function DKIM_HeaderC($signHeader) { - //Unfold all header continuation lines - //Also collapses folded whitespace. //Note PCRE \s is too broad a definition of whitespace; RFC5322 defines it as `[ \t]` //@see https://tools.ietf.org/html/rfc5322#section-2.2 //That means this may break if you do something daft like put vertical tabs in your headers. - $signHeader = preg_replace('/\r\n[ \t]+/', ' ', $signHeader); + //Unfold header lines + $signHeader = preg_replace('/\r\n[ \t]+/m', '', $signHeader); + //Collapse internal whitespace to a single space +// $signHeader = preg_replace('/[ \t]+/', ' ', $signHeader); + //Break headers out into an array $lines = explode("\r\n", $signHeader); foreach ($lines as $key => $line) { //If the header is missing a :, skip it as it's invalid @@ -4246,12 +4441,12 @@ public function DKIM_HeaderC($signHeader) list($heading, $value) = explode(':', $line, 2); //Lower-case header name $heading = strtolower($heading); - //Collapse white space within the value - $value = preg_replace('/[ \t]{2,}/', ' ', $value); + //Collapse white space within the value, also convert WSP to space + $value = preg_replace('/[ \t]+/', ' ', $value); //RFC6376 is slightly unclear here - it says to delete space at the *end* of each value //But then says to delete space before and after the colon. //Net result is the same as trimming both ends of the value. - //by elimination, the same applies to the field name + //By elimination, the same applies to the field name $lines[$key] = trim($heading, " \t") . ':' . trim($value, " \t"); } @@ -4263,7 +4458,7 @@ public function DKIM_HeaderC($signHeader) * Uses the 'simple' algorithm from RFC6376 section 3.4.3. * Canonicalized bodies should *always* use CRLF, regardless of mailer setting. * - * @see https://tools.ietf.org/html/rfc6376#section-3.4.3 + * @see https://tools.ietf.org/html/rfc6376#section-3.4.3 * * @param string $body Message Body * @@ -4346,7 +4541,7 @@ public function DKIM_Add($headers_line, $subject, $body) $extraHeaderKeys .= ':' . $key; $extraHeaderValues .= $value . "\r\n"; if ($this->DKIM_copyHeaderFields) { - $extraCopyHeaderFields .= "\t|" . str_replace('|', '=7C', $this->DKIM_QP($value)) . ";\r\n"; + $extraCopyHeaderFields .= ' |' . str_replace('|', '=7C', $this->DKIM_QP($value)) . ";\r\n"; } } if ($this->DKIM_copyHeaderFields) { @@ -4354,10 +4549,10 @@ public function DKIM_Add($headers_line, $subject, $body) $to = str_replace('|', '=7C', $this->DKIM_QP($to_header)); $date = str_replace('|', '=7C', $this->DKIM_QP($date_header)); $subject = str_replace('|', '=7C', $this->DKIM_QP($subject_header)); - $copiedHeaderFields = "\tz=$from\r\n" . - "\t|$to\r\n" . - "\t|$date\r\n" . - "\t|$subject;\r\n" . + $copiedHeaderFields = " z=$from\r\n" . + " |$to\r\n" . + " |$date\r\n" . + " |$subject;\r\n" . $extraCopyHeaderFields; } $body = $this->DKIM_BodyC($body); @@ -4374,12 +4569,12 @@ public function DKIM_Add($headers_line, $subject, $body) $DKIMlen . '; s=' . $this->DKIM_selector . ";\r\n" . - "\tt=" . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" . - "\th=From:To:Date:Subject" . $extraHeaderKeys . ";\r\n" . - "\td=" . $this->DKIM_domain . ';' . $ident . "\r\n" . + ' t=' . $DKIMtime . '; c=' . $DKIMcanonicalization . ";\r\n" . + ' h=From:To:Date:Subject' . $extraHeaderKeys . ";\r\n" . + ' d=' . $this->DKIM_domain . ';' . $ident . "\r\n" . $copiedHeaderFields . - "\tbh=" . $DKIMb64 . ";\r\n" . - "\tb="; + ' bh=' . $DKIMb64 . ";\r\n" . + ' b='; $toSign = $this->DKIM_HeaderC( $from_header . "\r\n" . $to_header . "\r\n" . diff --git a/vendor/phpmailer/phpmailer/src/POP3.php b/vendor/phpmailer/phpmailer/src/POP3.php index 66cf27304..e6ad6310a 100644 --- a/vendor/phpmailer/phpmailer/src/POP3.php +++ b/vendor/phpmailer/phpmailer/src/POP3.php @@ -3,13 +3,13 @@ * PHPMailer POP-Before-SMTP Authentication Class. * PHP Version 5.5. * - * @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project + * @see https://github.com/PHPMailer/PHPMailer/ The PHPMailer GitHub project * * @author Marcus Bointon (Synchro/coolbru) * @author Jim Jagielski (jimjag) * @author Andy Prevost (codeworxtech) * @author Brent R. Matzelle (original founder) - * @copyright 2012 - 2017 Marcus Bointon + * @copyright 2012 - 2019 Marcus Bointon * @copyright 2010 - 2012 Jim Jagielski * @copyright 2004 - 2009 Andy Prevost * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License @@ -29,14 +29,14 @@ * and then loop through your mail sending script. Providing this process doesn't * take longer than the verification period lasts on your POP3 server, you should be fine. * 3) This is really ancient technology; you should only need to use it to talk to very old systems. - * 4) This POP3 class is deliberately lightweight and incomplete, and implements just + * 4) This POP3 class is deliberately lightweight and incomplete, implementing just * enough to do authentication. * If you want a more complete class there are other POP3 classes for PHP available. * - * @author Richard Davey (original author) - * @author Marcus Bointon (Synchro/coolbru) - * @author Jim Jagielski (jimjag) - * @author Andy Prevost (codeworxtech) + * @author Richard Davey (original author) + * @author Marcus Bointon (Synchro/coolbru) + * @author Jim Jagielski (jimjag) + * @author Andy Prevost (codeworxtech) */ class POP3 { @@ -45,7 +45,7 @@ class POP3 * * @var string */ - const VERSION = '6.0.7'; + const VERSION = '6.1.1'; /** * Default POP3 port number. diff --git a/vendor/phpmailer/phpmailer/src/SMTP.php b/vendor/phpmailer/phpmailer/src/SMTP.php index da85442bf..77df57ce9 100644 --- a/vendor/phpmailer/phpmailer/src/SMTP.php +++ b/vendor/phpmailer/phpmailer/src/SMTP.php @@ -9,7 +9,7 @@ * @author Jim Jagielski (jimjag) * @author Andy Prevost (codeworxtech) * @author Brent R. Matzelle (original founder) - * @copyright 2012 - 2017 Marcus Bointon + * @copyright 2012 - 2019 Marcus Bointon * @copyright 2010 - 2012 Jim Jagielski * @copyright 2004 - 2009 Andy Prevost * @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License @@ -24,8 +24,8 @@ * PHPMailer RFC821 SMTP email transport class. * Implements RFC 821 SMTP commands and provides some utility methods for sending mail to an SMTP server. * - * @author Chris Ryan - * @author Marcus Bointon + * @author Chris Ryan + * @author Marcus Bointon */ class SMTP { @@ -34,7 +34,7 @@ class SMTP * * @var string */ - const VERSION = '6.0.7'; + const VERSION = '6.1.1'; /** * SMTP line break constant. @@ -59,26 +59,36 @@ class SMTP /** * Debug level for no output. + * + * @var int */ const DEBUG_OFF = 0; /** * Debug level to show client -> server messages. + * + * @var int */ const DEBUG_CLIENT = 1; /** * Debug level to show client -> server and server -> client messages. + * + * @var int */ const DEBUG_SERVER = 2; /** * Debug level to show connection status, client -> server and server -> client messages. + * + * @var int */ const DEBUG_CONNECTION = 3; /** * Debug level to show all messages. + * + * @var int */ const DEBUG_LOWLEVEL = 4; @@ -745,7 +755,7 @@ public function hello($host = '') * * @return bool * - * @see hello() + * @see hello() */ protected function sendHello($hello, $host) { @@ -853,14 +863,35 @@ public function quit($close_on_error = true) * Implements from RFC 821: RCPT TO: . * * @param string $address The address the message is being sent to + * @param string $dsn Comma separated list of DSN notifications. NEVER, SUCCESS, FAILURE + * or DELAY. If you specify NEVER all other notifications are ignored. * * @return bool */ - public function recipient($address) + public function recipient($address, $dsn = '') { + if (empty($dsn)) { + $rcpt = 'RCPT TO:<' . $address . '>'; + } else { + $dsn = strtoupper($dsn); + $notify = []; + + if (strpos($dsn, 'NEVER') !== false) { + $notify[] = 'NEVER'; + } else { + foreach (['SUCCESS', 'FAILURE', 'DELAY'] as $value) { + if (strpos($dsn, $value) !== false) { + $notify[] = $value; + } + } + } + + $rcpt = 'RCPT TO:<' . $address . '> NOTIFY=' . implode(',', $notify); + } + return $this->sendCommand( 'RCPT TO', - 'RCPT TO:<' . $address . '>', + $rcpt, [250, 251] ); } @@ -904,7 +935,7 @@ protected function sendCommand($command, $commandstring, $expect) $this->last_reply = $this->get_lines(); // Fetch SMTP code and possible error code explanation $matches = []; - if (preg_match('/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]) )?/', $this->last_reply, $matches)) { + if (preg_match('/^([0-9]{3})[ -](?:([0-9]\\.[0-9]\\.[0-9]{1,2}) )?/', $this->last_reply, $matches)) { $code = $matches[1]; $code_ex = (count($matches) > 2 ? $matches[2] : null); // Cut off error code from each response line @@ -1289,7 +1320,7 @@ protected function errorHandler($errno, $errmsg, $errfile = '', $errline = 0) * If no reply has been received yet, it will return null. * If no pattern was matched, it will return false. * - * @return bool|null|string + * @return bool|string|null */ protected function recordLastTransactionID() { @@ -1315,7 +1346,7 @@ protected function recordLastTransactionID() * If no reply has been received yet, it will return null. * If no pattern was matched, it will return false. * - * @return bool|null|string + * @return bool|string|null * * @see recordLastTransactionID() */ diff --git a/vendor/qcloud/cos-sdk-v5/.travis.yml b/vendor/qcloud/cos-sdk-v5/.travis.yml index 0392843cd..99220f268 100644 --- a/vendor/qcloud/cos-sdk-v5/.travis.yml +++ b/vendor/qcloud/cos-sdk-v5/.travis.yml @@ -1,6 +1,6 @@ language: php php: - - 5.4 + - 5.6 script: - composer install - phpunit -v diff --git a/vendor/qcloud/cos-sdk-v5/sample/putBucketCors.php b/vendor/qcloud/cos-sdk-v5/sample/putBucketCors.php index 1135bb9b2..375077bff 100644 --- a/vendor/qcloud/cos-sdk-v5/sample/putBucketCors.php +++ b/vendor/qcloud/cos-sdk-v5/sample/putBucketCors.php @@ -15,27 +15,15 @@ try { $result = $cosClient->putBucketCors(array( 'Bucket' => 'examplebucket-125000000', //格式:BucketName-APPID - 'Rules' => array( + 'CORSRules' => array( array( - 'Expiration' => array( - 'Days' => integer, - ), - 'ID' => 'string', - 'Filter' => array( - 'Prefix' => 'string' - ), - 'Status' => 'string', - 'Transitions' => array( - array( - 'Days' => integer, - 'StorageClass' => 'string' - ), - // ... repeated - ), + 'ID' => '1234', + 'AllowedHeaders' => array('*'), + 'AllowedMethods' => array('PUT'), + 'AllowedOrigins' => array('http://www.qq.com'), ), - // ... repeated - ) - ); + ), + )); // 请求成功 print_r($result); } catch (\Exception $e) { diff --git a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/BucketStyleListener.php b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/BucketStyleListener.php index b1bd56671..0288d32a5 100644 --- a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/BucketStyleListener.php +++ b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/BucketStyleListener.php @@ -47,7 +47,6 @@ public static function getSubscribedEvents() { * @param Event $event Event emitted. */ public function onCommandAfterPrepare(Event $event) { - $command = $event['command']; $bucket = $command['Bucket']; $request = $command->getRequest(); @@ -73,15 +72,15 @@ public function onCommandAfterPrepare(Event $event) { } } $request->setHeader('Date', gmdate('D, d M Y H:i:s T')); - $request->setPath(preg_replace("#^/{$bucket}#", '', $request->getPath())); + $url_bucket = rawurlencode($bucket); + $request->setPath(preg_replace("#^/{$url_bucket}#", '', $request->getPath())); if ($this->appId != null && endWith($bucket,'-'.$this->appId) == False) { $bucket = $bucket.'-'.$this->appId; } -// $request->setPath(urldecode($request->getPath())); $request->getParams()->set('bucket', $bucket)->set('key', $key); - + $realHost = $bucket. '.' . $request->getHost(); if($this->ipport != null) { $request->setHost($this->ipport); diff --git a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Client.php b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Client.php index 2ec9218b5..1042386f9 100644 --- a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Client.php +++ b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Client.php @@ -12,7 +12,7 @@ use Qcloud\Cos\TokenListener; class Client extends GSClient { - const VERSION = '1.3.2'; + const VERSION = '1.3.4'; private $region; // string: region. private $credentials; @@ -66,7 +66,6 @@ public function __construct($config) { $this->addSubscriber(new TokenListener($this->token)); $this->addSubscriber(new SignatureListener($this->secretId, $this->secretKey)); $this->addSubscriber(new BucketStyleListener($this->appId, $this->ip, $this->port, $this->endpoint)); - // Allow for specifying bodies with file paths and file handles $this->addSubscriber(new UploadBodyListener(array('PutObject', 'UploadPart'))); } @@ -122,6 +121,7 @@ public function Upload($bucket, $key, $body, $options = array()) { ) + $options['params']); $rt['Location'] = $rt['ObjectURL']; + $rt['Location'] = ltrim($rt['Location'], $this->schema. "://"); unset($rt['ObjectURL']); } else { @@ -132,6 +132,8 @@ public function Upload($bucket, $key, $body, $options = array()) { ) + $options['params']); $rt = $multipartUpload->performUploading(); + unset($rt['Bucket']); + unset($rt['Key']); } return $rt; } diff --git a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/ExceptionParser.php b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/ExceptionParser.php index ab1cd9b4c..be65eedb8 100644 --- a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/ExceptionParser.php +++ b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/ExceptionParser.php @@ -27,13 +27,10 @@ public function parse(RequestInterface $request, Response $response) { } try { - $xml = new \SimpleXMLElement($body); + $xml = new \SimpleXMLElement(utf8_encode($body)); $this->parseBody($xml, $data); return $data; } catch (\Exception $e) { - // Gracefully handle parse errors. This could happen when the - // server responds with a non-XML response (e.g., private beta - // services). $data['code'] = 'PhpInternalXmlParseError'; $data['message'] = 'A non-XML response was received'; return $data; diff --git a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Signature.php b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Signature.php index ae5fa10d0..28eb41eb4 100644 --- a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Signature.php +++ b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Signature.php @@ -11,10 +11,10 @@ public function __construct($accessKey, $secretKey) { public function __destruct() { } public function signRequest(RequestInterface $request) { - + $host = $request->getHeader('Host'); $signTime = (string)(time() - 60) . ';' . (string)(time() + 3600); $httpString = strtolower($request->getMethod()) . "\n" . urldecode($request->getPath()) . - "\n\nhost=" . $request->getHost() . "\n"; + "\n\nhost=" . $host . "\n"; $sha1edHttpString = sha1($httpString); $stringToSign = "sha1\n$signTime\n$sha1edHttpString\n"; $signKey = hash_hmac('sha1', $signTime, $this->secretKey); @@ -28,9 +28,10 @@ public function createAuthorization( RequestInterface $request, $expires = "10 minutes" ) { + $host = $request->getHeader('Host'); $signTime = (string)(time() - 60) . ';' . (string)(strtotime($expires)); $httpString = strtolower($request->getMethod()) . "\n" . urldecode($request->getPath()) . - "\n\nhost=" . $request->getHost() . "\n"; + "\n\nhost=" . $host . "\n"; $sha1edHttpString = sha1($httpString); $stringToSign = "sha1\n$signTime\n$sha1edHttpString\n"; $signKey = hash_hmac('sha1', $signTime, $this->secretKey); @@ -48,4 +49,4 @@ public function createPresignedUrl( $request->getQuery()->add('sign', $authorization); return $request->getUrl(); } -} \ No newline at end of file +} diff --git a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Tests/Test.php b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Tests/Test.php index 4a8462ec2..8b50b18db 100644 --- a/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Tests/Test.php +++ b/vendor/qcloud/cos-sdk-v5/src/Qcloud/Cos/Tests/Test.php @@ -606,6 +606,7 @@ public function testGetBucketLifecycle() ) ) )); + sleep(3); $result = $this->cosClient->getBucketLifecycle(array( // Bucket is required 'Bucket' => $this->bucket, diff --git a/vendor/qiniu/php-sdk/.travis.yml b/vendor/qiniu/php-sdk/.travis.yml index cada8cd09..e4eee7bea 100644 --- a/vendor/qiniu/php-sdk/.travis.yml +++ b/vendor/qiniu/php-sdk/.travis.yml @@ -7,6 +7,8 @@ php: - 5.6 - 7.0 +dist: trusty + before_script: - export QINIU_TEST_ENV="travis" - travis_retry composer self-update diff --git a/vendor/qiniu/php-sdk/docs/sms/example.php b/vendor/qiniu/php-sdk/docs/sms/example.php new file mode 100644 index 000000000..541c0d6c2 --- /dev/null +++ b/vendor/qiniu/php-sdk/docs/sms/example.php @@ -0,0 +1,70 @@ + 'code' ); +try { + //发送短信 + $resp = $client->sendMessage($template_id, $mobiles, $code); + print_r($resp); +} catch (\Exception $e) { + echo "Error:", $e, "\n"; +}exit; +//模板模块 +$name="tstest001"; +$template="tesy001 ${code}"; +$type="notification"; +$description="tstest001"; +$signature_id="1131464448834277376"; +$id="1131810682442883072"; + +try { + //创建模板 + $resp = $client->createTemplate($name, $template, $type, $description, $signature_id); + print_r($resp); + //查询模板 + $resp = $client->queryTemplate(); + print_r($resp); + //修改模板 + $resp = $client->updateTemplate($id, $name, $template, $description, $signature_id); + print_r($resp); + //删除模板 + $resp = $client->deleteTemplate($id); + print_r($resp); +} catch (\Exception $e) { + echo "Error:", $e, "\n"; +} +//签名模块 +$signature = 'lfxlive2'; +$source = 'enterprises_and_institutions'; +$pic="/Users/Desktop/sss.jpg"; +$audit_status="passed"; +$page=1; +$page_size=1; +$id="1131464448834277376"; + +try { + //创建签名 + $resp = $client->createSignature($signature, $source, $pic); + print_r($resp); + //查询签名 + $resp = $client->checkSignature($audit_status); + //修改签名 + $resp = $client->updateSignature($id, $signature, $source, $pic); + print_r($resp); + //删除ID + $resp = $client->deleteSignature($id); + print_r($resp); +} catch (\Exception $e) { + echo "Error:", $e, "\n"; +} diff --git a/vendor/qiniu/php-sdk/examples/bucket_lifecycleRule.php b/vendor/qiniu/php-sdk/examples/bucket_lifecycleRule.php new file mode 100644 index 000000000..3f7fefd5b --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/bucket_lifecycleRule.php @@ -0,0 +1,30 @@ +bucketLifecycleRule( + $bucket, + $name, + $prefix, + $delete_after_days, + $to_line_after_days +); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/delete_bucket.php b/vendor/qiniu/php-sdk/examples/delete_bucket.php new file mode 100644 index 000000000..dc2e30505 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/delete_bucket.php @@ -0,0 +1,20 @@ +deleteBucket($name); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/delete_bucketEvent.php b/vendor/qiniu/php-sdk/examples/delete_bucketEvent.php new file mode 100644 index 000000000..00df6cae2 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/delete_bucketEvent.php @@ -0,0 +1,21 @@ +deleteBucketEvent($bucket, $name); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/delete_bucketLifecycleRule.php b/vendor/qiniu/php-sdk/examples/delete_bucketLifecycleRule.php new file mode 100644 index 000000000..a53699267 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/delete_bucketLifecycleRule.php @@ -0,0 +1,21 @@ +deleteBucketLifecycleRule($bucket, $name); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketEvents.php b/vendor/qiniu/php-sdk/examples/get_bucketEvents.php new file mode 100644 index 000000000..53a5c88d2 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketEvents.php @@ -0,0 +1,20 @@ +getBucketEvents($bucket); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketLifecycleRules.php b/vendor/qiniu/php-sdk/examples/get_bucketLifecycleRules.php new file mode 100644 index 000000000..652bee8ce --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketLifecycleRules.php @@ -0,0 +1,20 @@ +getBucketLifecycleRules($bucket); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketList.php b/vendor/qiniu/php-sdk/examples/get_bucketList.php new file mode 100644 index 000000000..74aaa65f3 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketList.php @@ -0,0 +1,20 @@ +listbuckets($region); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketQuota.php b/vendor/qiniu/php-sdk/examples/get_bucketQuota.php new file mode 100644 index 000000000..563395d61 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketQuota.php @@ -0,0 +1,20 @@ +getBucketQuota($bucket); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketinfo.php b/vendor/qiniu/php-sdk/examples/get_bucketinfo.php new file mode 100644 index 000000000..ff052a436 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketinfo.php @@ -0,0 +1,20 @@ +bucketInfo($bucket); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_bucketinfos.php b/vendor/qiniu/php-sdk/examples/get_bucketinfos.php new file mode 100644 index 000000000..0ad650325 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_bucketinfos.php @@ -0,0 +1,20 @@ +bucketInfos($region); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/get_corsRules.php b/vendor/qiniu/php-sdk/examples/get_corsRules.php new file mode 100644 index 000000000..fbfde2d21 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/get_corsRules.php @@ -0,0 +1,20 @@ +getCorsRules($bucket); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_bucketAccessMode.php b/vendor/qiniu/php-sdk/examples/put_bucketAccessMode.php new file mode 100644 index 000000000..b4539264a --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_bucketAccessMode.php @@ -0,0 +1,21 @@ +putBucketAccessMode($bucket, $private); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_bucketAccessStyleMode.php b/vendor/qiniu/php-sdk/examples/put_bucketAccessStyleMode.php new file mode 100644 index 000000000..2f7c27f2b --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_bucketAccessStyleMode.php @@ -0,0 +1,21 @@ +putBucketAccessStyleMode($bucket, $mode); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_bucketEvent.php b/vendor/qiniu/php-sdk/examples/put_bucketEvent.php new file mode 100644 index 000000000..33dbb44c0 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_bucketEvent.php @@ -0,0 +1,25 @@ +putBucketEvent($bucket, $name, $prefix, $suffix, $event, $callbackURL); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_bucketMaxAge.php b/vendor/qiniu/php-sdk/examples/put_bucketMaxAge.php new file mode 100644 index 000000000..77092e90a --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_bucketMaxAge.php @@ -0,0 +1,21 @@ +putBucketMaxAge($bucket, $maxAge); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_bucketQuota.php b/vendor/qiniu/php-sdk/examples/put_bucketQuota.php new file mode 100644 index 000000000..18082b631 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_bucketQuota.php @@ -0,0 +1,22 @@ +putBucketQuota($bucket, $size, $count); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/put_referAntiLeech.php b/vendor/qiniu/php-sdk/examples/put_referAntiLeech.php new file mode 100644 index 000000000..6828bc9ac --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/put_referAntiLeech.php @@ -0,0 +1,23 @@ +putReferAntiLeech($bucket, $mode, $norefer, $pattern); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/rs_pub_domain.php b/vendor/qiniu/php-sdk/examples/rs_pub_domain.php new file mode 100644 index 000000000..2e81922eb --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/rs_pub_domain.php @@ -0,0 +1,19 @@ +publishDomain($bucket, $domain); +if ($err) { + print_r($err); +} diff --git a/vendor/qiniu/php-sdk/examples/rsf_v2list_bucket.php b/vendor/qiniu/php-sdk/examples/rsf_v2list_bucket.php new file mode 100644 index 000000000..4dcf27096 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/rsf_v2list_bucket.php @@ -0,0 +1,33 @@ +listFilesv2($bucket, $prefix, $marker, $limit, $delimiter, true); + +if ($err) { + print_r($err); +} else { + print_r($ret); +} diff --git a/vendor/qiniu/php-sdk/examples/update_bucketEvent.php b/vendor/qiniu/php-sdk/examples/update_bucketEvent.php new file mode 100644 index 000000000..26347ac41 --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/update_bucketEvent.php @@ -0,0 +1,25 @@ +updateBucketEvent($bucket, $name, $prefix, $suffix, $event, $callbackURL); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/examples/update_bucketLifecycleRule.php b/vendor/qiniu/php-sdk/examples/update_bucketLifecycleRule.php new file mode 100644 index 000000000..85eb07a6b --- /dev/null +++ b/vendor/qiniu/php-sdk/examples/update_bucketLifecycleRule.php @@ -0,0 +1,30 @@ +updateBucketLifecycleRule( + $bucket, + $name, + $prefix, + $delete_after_days, + $to_line_after_days +); +if ($err) { + print_r($err); +} else { + print_r($Info); +} diff --git a/vendor/qiniu/php-sdk/src/Qiniu/Cdn/CdnManager.php b/vendor/qiniu/php-sdk/src/Qiniu/Cdn/CdnManager.php index c32475793..9b462f31a 100644 --- a/vendor/qiniu/php-sdk/src/Qiniu/Cdn/CdnManager.php +++ b/vendor/qiniu/php-sdk/src/Qiniu/Cdn/CdnManager.php @@ -170,23 +170,16 @@ private function post($url, $body) public static function createTimestampAntiLeechUrl($rawUrl, $encryptKey, $durationInSeconds) { $parsedUrl = parse_url($rawUrl); - $deadline = time() + $durationInSeconds; $expireHex = dechex($deadline); - $path = isset($parsedUrl['path']) ? $parsedUrl['path'] : ''; - $path = implode('/', array_map('rawurlencode', explode('/', $path))); $strToSign = $encryptKey . $path . $expireHex; $signStr = md5($strToSign); - - $url = $parsedUrl['scheme'].'://'.$parsedUrl['host'].$path; - if (isset($parsedUrl['query'])) { - $signedUrl = $url . '&sign=' . $signStr . '&t=' . $expireHex; + $signedUrl = $rawUrl . '&sign=' . $signStr . '&t=' . $expireHex; } else { - $signedUrl = $url . '?sign=' . $signStr . '&t=' . $expireHex; + $signedUrl = $rawUrl . '?sign=' . $signStr . '&t=' . $expireHex; } - return $signedUrl; } } diff --git a/vendor/qiniu/php-sdk/src/Qiniu/Config.php b/vendor/qiniu/php-sdk/src/Qiniu/Config.php index ec75df68b..c80cd309f 100644 --- a/vendor/qiniu/php-sdk/src/Qiniu/Config.php +++ b/vendor/qiniu/php-sdk/src/Qiniu/Config.php @@ -3,7 +3,7 @@ final class Config { - const SDK_VER = '7.2.9'; + const SDK_VER = '7.2.10'; const BLOCK_SIZE = 4194304; //4*1024*1024 分块上传块大小,该参数为接口规格,不能修改 diff --git a/vendor/qiniu/php-sdk/src/Qiniu/Region.php b/vendor/qiniu/php-sdk/src/Qiniu/Region.php new file mode 100644 index 000000000..eae21d199 --- /dev/null +++ b/vendor/qiniu/php-sdk/src/Qiniu/Region.php @@ -0,0 +1,196 @@ +srcUpHosts = $srcUpHosts; + $this->cdnUpHosts = $cdnUpHosts; + $this->rsHost = $rsHost; + $this->rsfHost = $rsfHost; + $this->apiHost = $apiHost; + $this->iovipHost = $iovipHost; + } + + //华东机房 + public static function regionHuadong() + { + $regionHuadong = new Region( + array("up.qiniup.com", 'up-jjh.qiniup.com', 'up-xs.qiniup.com'), + array('upload.qiniup.com', 'upload-jjh.qiniup.com', 'upload-xs.qiniup.com'), + 'rs.qbox.me', + 'rsf.qbox.me', + 'api.qiniu.com', + 'iovip.qbox.me' + ); + return $regionHuadong; + } + + //华东机房内网上传 + public static function qvmRegionHuadong() + { + $qvmRegionHuadong = new Region( + array("free-qvm-z0-xs.qiniup.com"), + 'rs.qbox.me', + 'rsf.qbox.me', + 'api.qiniu.com', + 'iovip.qbox.me' + ); + return $qvmRegionHuadong; + } + + //华北机房内网上传 + public static function qvmRegionHuabei() + { + $qvmRegionHuabei = new Region( + array("free-qvm-z1-zz.qiniup.com"), + "rs-z1.qbox.me", + "rsf-z1.qbox.me", + "api-z1.qiniu.com", + "iovip-z1.qbox.me" + ); + return $qvmRegionHuabei; + } + + //华北机房 + public static function regionHuabei() + { + $regionHuabei = new Region( + array('up-z1.qiniup.com'), + array('upload-z1.qiniup.com'), + "rs-z1.qbox.me", + "rsf-z1.qbox.me", + "api-z1.qiniu.com", + "iovip-z1.qbox.me" + ); + + return $regionHuabei; + } + + //华南机房 + public static function regionHuanan() + { + $regionHuanan = new Region( + array('up-z2.qiniup.com', 'up-dg.qiniup.com', 'up-fs.qiniup.com'), + array('upload-z2.qiniup.com', 'upload-dg.qiniup.com', 'upload-fs.qiniup.com'), + "rs-z2.qbox.me", + "rsf-z2.qbox.me", + "api-z2.qiniu.com", + "iovip-z2.qbox.me" + ); + return $regionHuanan; + } + + //北美机房 + public static function regionNorthAmerica() + { + //北美机房 + $regionNorthAmerica = new Region( + array('up-na0.qiniup.com'), + array('upload-na0.qiniup.com'), + "rs-na0.qbox.me", + "rsf-na0.qbox.me", + "api-na0.qiniu.com", + "iovip-na0.qbox.me" + ); + return $regionNorthAmerica; + } + + //新加坡机房 + public static function regionSingapore() + { + //新加坡机房 + $regionSingapore = new Region( + array('up-as0.qiniup.com'), + array('upload-as0.qiniup.com'), + "rs-as0.qbox.me", + "rsf-as0.qbox.me", + "api-as0.qiniu.com", + "iovip-as0.qbox.me" + ); + return $regionSingapore; + } + + /* + * GET /v2/query?ak=&&bucket= + **/ + public static function queryRegion($ak, $bucket) + { + $Region = new Region(); + $url = Config::API_HOST . '/v2/query' . "?ak=$ak&bucket=$bucket"; + $ret = Client::Get($url); + if (!$ret->ok()) { + return array(null, new Error($url, $ret)); + } + $r = ($ret->body === null) ? array() : $ret->json(); + //parse Region; + + $iovipHost = $r['io']['src']['main'][0]; + $Region->iovipHost = $iovipHost; + $accMain = $r['up']['acc']['main'][0]; + array_push($Region->cdnUpHosts, $accMain); + if (isset($r['up']['acc']['backup'])) { + foreach ($r['up']['acc']['backup'] as $key => $value) { + array_push($Region->cdnUpHosts, $value); + } + } + $srcMain = $r['up']['src']['main'][0]; + array_push($Region->srcUpHosts, $srcMain); + if (isset($r['up']['src']['backup'])) { + foreach ($r['up']['src']['backup'] as $key => $value) { + array_push($Region->srcUpHosts, $value); + } + } + + //set specific hosts + if (strstr($Region->iovipHost, "z1") !== false) { + $Region->rsHost = "rs-z1.qbox.me"; + $Region->rsfHost = "rsf-z1.qbox.me"; + $Region->apiHost = "api-z1.qiniu.com"; + } elseif (strstr($Region->iovipHost, "z2") !== false) { + $Region->rsHost = "rs-z2.qbox.me"; + $Region->rsfHost = "rsf-z2.qbox.me"; + $Region->apiHost = "api-z2.qiniu.com"; + } elseif (strstr($Region->iovipHost, "na0") !== false) { + $Region->rsHost = "rs-na0.qbox.me"; + $Region->rsfHost = "rsf-na0.qbox.me"; + $Region->apiHost = "api-na0.qiniu.com"; + } elseif (strstr($Region->iovipHost, "as0") !== false) { + $Region->rsHost = "rs-as0.qbox.me"; + $Region->rsfHost = "rsf-as0.qbox.me"; + $Region->apiHost = "api-as0.qiniu.com"; + } else { + $Region->rsHost = "rs.qbox.me"; + $Region->rsfHost = "rsf.qbox.me"; + $Region->apiHost = "api.qiniu.com"; + } + + return $Region; + } +} diff --git a/vendor/qiniu/php-sdk/src/Qiniu/Rtc/AppClient.php b/vendor/qiniu/php-sdk/src/Qiniu/Rtc/AppClient.php index 0fd0019a4..a7dc11e1e 100755 --- a/vendor/qiniu/php-sdk/src/Qiniu/Rtc/AppClient.php +++ b/vendor/qiniu/php-sdk/src/Qiniu/Rtc/AppClient.php @@ -33,7 +33,7 @@ public function createApp($hub, $title, $maxUsers = null, $noAutoKickUser = null if (!empty($maxUsers)) { $params['maxUsers'] = $maxUsers; } - if (!empty($noAutoKickUser)) { + if ($noAutoKickUser !== null) { $params['noAutoKickUser'] = $noAutoKickUser; } $body = json_encode($params); @@ -65,7 +65,7 @@ public function updateApp($appId, $hub, $title, $maxUsers = null, $mergePublishR if (!empty($maxUsers)) { $params['maxUsers'] = $maxUsers; } - if (!empty($noAutoKickUser)) { + if ($noAutoKickUser !== null) { $params['noAutoKickUser'] = $noAutoKickUser; } if (!empty($mergePublishRtmp)) { diff --git a/vendor/qiniu/php-sdk/src/Qiniu/Sms/Sms.php b/vendor/qiniu/php-sdk/src/Qiniu/Sms/Sms.php new file mode 100644 index 000000000..f19a124fb --- /dev/null +++ b/vendor/qiniu/php-sdk/src/Qiniu/Sms/Sms.php @@ -0,0 +1,337 @@ +auth = $auth; + + $this->baseURL = sprintf("%s/%s/", Config::SMS_HOST, Config::SMS_VERSION); + } + + /* + * 创建签名 + * signature: string 类型,必填,【长度限制8个字符内】超过长度会报错 + * source: string 类型,必填,申请签名时必须指定签名来源。取值范围为: + nterprises_and_institutions 企事业单位的全称或简称 + website 工信部备案网站的全称或简称 + app APP应用的全称或简称 + public_number_or_small_program 公众号或小程序的全称或简称 + store_name 电商平台店铺名的全称或简称 + trade_name 商标名的全称或简称, + * pics: 本地的图片路径 string 类型,可选 + *@return: 类型array { + "signature_id": + } + */ + public function createSignature($signature, $source, $pics = null) + { + $params['signature'] = $signature; + $params['source'] = $source; + if (!empty($pics)) { + $params['pics'] = $this->imgToBase64($pics); + } + $body = json_encode($params); + $url =$this->baseURL.'signature'; + $ret = $this->post($url, $body); + return $ret; + } + + /* + * 编辑签名 + * id 签名id : string 类型,必填, + * signature: string 类型,必填, + * source: string 类型,必填,申请签名时必须指定签名来源。取值范围为: + enterprises_and_institutions 企事业单位的全称或简称 + website 工信部备案网站的全称或简称 + app APP应用的全称或简称 + public_number_or_small_program 公众号或小程序的全称或简称 + store_name 电商平台店铺名的全称或简称 + trade_name 商标名的全称或简称, + * pics: 本地的图片路径 string 类型,可选, + * @return: 类型array { + "signature": string + } + */ + public function updateSignature($id, $signature, $source, $pics = null) + { + $params['signature'] = $signature; + $params['source'] = $source; + if (!empty($pics)) { + $params['pics'] = $this->imgToBase64($pics); + } + $body = json_encode($params); + $url =$this->baseURL.'signature/'.$id; + $ret = $this->PUT($url, $body); + return $ret; + } + + /* + * 查询签名 + * audit_status: 审核状态 string 类型,可选, + 取值范围为: "passed"(通过), "rejected"(未通过), "reviewing"(审核中) + * page:页码 int 类型, + * page_size: 分页大小 int 类型,可选, 默认为20 + *@return: 类型array { + "items": [{ + "id": string, + "signature": string, + "source": string, + "audit_status": string, + "reject_reason": string, + "created_at": int64, + "updated_at": int64 + }...], + "total": int, + "page": int, + "page_size": int, + } + */ + public function checkSignature($audit_status = null, $page = 1, $page_size = 20) + { + + $url = sprintf( + "%s?audit_status=%s&page=%s&page_size=%s", + $this->baseURL.'signature', + $audit_status, + $page, + $page_size + ); + $ret = $this->get($url); + return $ret; + } + + + /* + * 删除签名 + * id 签名id string 类型,必填, + * @retrun : 请求成功 HTTP 状态码为 200 + */ + public function deleteSignature($id) + { + $url = $this->baseURL . 'signature/' . $id; + list(, $err) = $this->delete($url); + return $err; + } + + + + + /* + * 创建模板 + * name : 模板名称 string 类型 ,必填 + * template: 模板内容 string 类型,必填 + * type: 模板类型 string 类型,必填, + 取值范围为: notification (通知类短信), verification (验证码短信), marketing (营销类短信) + * description: 申请理由简述 string 类型,必填 + * signature_id: 已经审核通过的签名 string 类型,必填 + * @return: 类型 array { + "template_id": string + } + */ + public function createTemplate( + $name, + $template, + $type, + $description, + $signture_id + ) { + $params['name'] = $name; + $params['template'] = $template; + $params['type'] = $type; + $params['description'] = $description; + $params['signature_id'] = $signture_id; + + $body = json_encode($params); + $url =$this->baseURL.'template'; + $ret = $this->post($url, $body); + return $ret; + } + + /* + * 查询模板 + * audit_status: 审核状态 string 类型 ,可选, + 取值范围为: passed (通过), rejected (未通过), reviewing (审核中) + * page: 页码 int 类型,可选,默认为 1 + * page_size: 分页大小 int 类型,可选,默认为 20 + * @return: 类型array{ + "items": [{ + "id": string, + "name": string, + "template": string, + "audit_status": string, + "reject_reason": string, + "type": string, + "signature_id": string, // 模版绑定的签名ID + "signature_text": string, // 模版绑定的签名内容 + "created_at": int64, + "updated_at": int64 + }...], + "total": int, + "page": int, + "page_size": int + } + */ + public function queryTemplate($audit_status = null, $page = 1, $page_size = 20) + { + + $url = sprintf( + "%s?audit_status=%s&page=%s&page_size=%s", + $this->baseURL.'template', + $audit_status, + $page, + $page_size + ); + $ret = $this->get($url); + return $ret; + } + + /* + * 编辑模板 + * id :模板id + * name : 模板名称 string 类型 ,必填 + * template: 模板内容 string 类型,必填 + * description: 申请理由简述 string 类型,必填 + * signature_id: 已经审核通过的签名 string 类型,必填 + * @retrun : 请求成功 HTTP 状态码为 200 + */ + public function updateTemplate( + $id, + $name, + $template, + $description, + $signature_id + ) { + $params['name'] = $name; + $params['template'] = $template; + $params['description'] = $description; + $params['signature_id'] = $signature_id; + $body = json_encode($params); + $url =$this->baseURL.'template/'.$id; + $ret = $this->PUT($url, $body); + return $ret; + } + + /* + * 删除模板 + * id :模板id string 类型,必填, + * @retrun : 请求成功 HTTP 状态码为 200 + */ + public function deleteTemplate($id) + { + $url = $this->baseURL . 'template/' . $id; + list(, $err) = $this->delete($url); + return $err; + } + + /* + * 发送短信 + * 编辑模板 + * template_id :模板id string类型,必填 + * mobiles : 手机号数组 []string 类型 ,必填 + * parameters: 模板内容 map[string]string 类型,可选 + * @return: 类型json { + "job_id": string + } + */ + public function sendMessage($template_id, $mobiles, $parameters = null) + { + $params['template_id'] = $template_id; + $params['mobiles'] = $mobiles; + if (!empty($parameters)) { + $params['parameters'] = $parameters; + } + $body = json_encode($params); + $url =$this->baseURL.'message'; + $ret = $this->post($url, $body); + return $ret; + } + + public function imgToBase64($img_file) + { + $img_base64 = ''; + if (file_exists($img_file)) { + $app_img_file = $img_file; // 图片路径 + $img_info = getimagesize($app_img_file); // 取得图片的大小,类型等 + $fp = fopen($app_img_file, "r"); // 图片是否可读权限 + if ($fp) { + $filesize = filesize($app_img_file); + if ($filesize > 5*1024*1024) { + die("pic size < 5M !"); + } + $content = fread($fp, $filesize); + $file_content = chunk_split(base64_encode($content)); // base64编码 + switch ($img_info[2]) { //判读图片类型 + case 1: + $img_type = 'gif'; + break; + case 2: + $img_type = 'jpg'; + break; + case 3: + $img_type = 'png'; + break; + } + //合成图片的base64编码 + $img_base64 = 'data:image/' . $img_type . ';base64,' . $file_content; + } + fclose($fp); + } + + return $img_base64; + } + + private function get($url, $cType = null) + { + $rtcToken = $this->auth->authorizationV2($url, "GET", null, $cType); + $rtcToken['Content-Type'] = $cType; + $ret = Client::get($url, $rtcToken); + if (!$ret->ok()) { + return array(null, new Error($url, $ret)); + } + return array($ret->json(), null); + } + + private function delete($url, $contentType = 'application/json') + { + $rtcToken = $this->auth->authorizationV2($url, "DELETE", null, $contentType); + $rtcToken['Content-Type'] = $contentType; + $ret = Client::delete($url, $rtcToken); + if (!$ret->ok()) { + return array(null, new Error($url, $ret)); + } + return array($ret->json(), null); + } + + private function post($url, $body, $contentType = 'application/json') + { + $rtcToken = $this->auth->authorizationV2($url, "POST", $body, $contentType); + $rtcToken['Content-Type'] = $contentType; + $ret = Client::post($url, $body, $rtcToken); + if (!$ret->ok()) { + return array(null, new Error($url, $ret)); + } + $r = ($ret->body === null) ? array() : $ret->json(); + return array($r, null); + } + private function PUT($url, $body, $contentType = 'application/json') + { + $rtcToken = $this->auth->authorizationV2($url, "PUT", $body, $contentType); + $rtcToken['Content-Type'] = $contentType; + $ret = Client::put($url, $body, $rtcToken); + if (!$ret->ok()) { + return array(null, new Error($url, $ret)); + } + $r = ($ret->body === null) ? array() : $ret->json(); + return array($r, null); + } +} diff --git a/vendor/qiniu/php-sdk/src/Qiniu/Storage/BucketManager.php b/vendor/qiniu/php-sdk/src/Qiniu/Storage/BucketManager.php index e38f433ea..0a2413dd4 100644 --- a/vendor/qiniu/php-sdk/src/Qiniu/Storage/BucketManager.php +++ b/vendor/qiniu/php-sdk/src/Qiniu/Storage/BucketManager.php @@ -59,7 +59,7 @@ public function listbuckets( $line = 'false', $shared = 'false' ) { - $path = '/v3/buckets?region=' . $region . '&line=' . $line . '&shared=' . $share; + $path = '/v3/buckets?region=' . $region . '&line=' . $line . '&shared=' . $shared; $info = $this->ucPost($path); return $info; } diff --git a/vendor/qiniu/php-sdk/src/Qiniu/Storage/UploadManager.php b/vendor/qiniu/php-sdk/src/Qiniu/Storage/UploadManager.php index 209df11ad..8fbd504ca 100644 --- a/vendor/qiniu/php-sdk/src/Qiniu/Storage/UploadManager.php +++ b/vendor/qiniu/php-sdk/src/Qiniu/Storage/UploadManager.php @@ -46,7 +46,7 @@ public function put( $data, $params = null, $mime = 'application/octet-stream', - $fname = null + $fname = "default_filename" ) { $params = self::trimParams($params); diff --git a/vendor/qiniu/php-sdk/tests/Qiniu/Tests/CdnManagerTest.php b/vendor/qiniu/php-sdk/tests/Qiniu/Tests/CdnManagerTest.php index 3c45bbdfd..892197da7 100755 --- a/vendor/qiniu/php-sdk/tests/Qiniu/Tests/CdnManagerTest.php +++ b/vendor/qiniu/php-sdk/tests/Qiniu/Tests/CdnManagerTest.php @@ -25,7 +25,7 @@ protected function setUp() $this->cdnManager = new CdnManager($testAuth); $this->encryptKey = $timestampAntiLeechEncryptKey; - $this->imgUrl = $customDomain . '/24.jpg'; + $this->imgUrl = $customDomain . '/sdktest.png'; } public function testCreateTimestampAntiLeechUrl() diff --git a/vendor/qiniu/php-sdk/tests/Qiniu/Tests/DownloadTest.php b/vendor/qiniu/php-sdk/tests/Qiniu/Tests/DownloadTest.php index 82990f2a1..5373ab379 100755 --- a/vendor/qiniu/php-sdk/tests/Qiniu/Tests/DownloadTest.php +++ b/vendor/qiniu/php-sdk/tests/Qiniu/Tests/DownloadTest.php @@ -8,7 +8,7 @@ class DownloadTest extends \PHPUnit_Framework_TestCase public function test() { global $testAuth; - $base_url = 'http://private-res.qiniudn.com/gogopher.jpg'; + $base_url = 'http://sdk.peterpy.cn/gogopher.jpg'; $private_url = $testAuth->privateDownloadUrl($base_url); $response = Client::get($private_url); $this->assertEquals(200, $response->statusCode); @@ -17,7 +17,7 @@ public function test() public function testFop() { global $testAuth; - $base_url = 'http://private-res.qiniudn.com/gogopher.jpg?exif'; + $base_url = 'http://sdk.peterpy.cn/gogopher.jpg?exif'; $private_url = $testAuth->privateDownloadUrl($base_url); $response = Client::get($private_url); $this->assertEquals(200, $response->statusCode); diff --git a/vendor/qiniu/php-sdk/tests/Qiniu/Tests/FopTest.php b/vendor/qiniu/php-sdk/tests/Qiniu/Tests/FopTest.php index e1ea730e8..6cbdb7f76 100755 --- a/vendor/qiniu/php-sdk/tests/Qiniu/Tests/FopTest.php +++ b/vendor/qiniu/php-sdk/tests/Qiniu/Tests/FopTest.php @@ -8,7 +8,7 @@ class FopTest extends \PHPUnit_Framework_TestCase { public function testExifPub() { - $fop = new Operation('testres.qiniudn.com'); + $fop = new Operation('sdk.peterpy.cn'); list($exif, $error) = $fop->execute('gogopher.jpg', 'exif'); $this->assertNull($error); $this->assertNotNull($exif); diff --git a/vendor/qiniu/php-sdk/tests/bootstrap.php b/vendor/qiniu/php-sdk/tests/bootstrap.php index c300057c2..5cbce3570 100755 --- a/vendor/qiniu/php-sdk/tests/bootstrap.php +++ b/vendor/qiniu/php-sdk/tests/bootstrap.php @@ -21,7 +21,7 @@ //cdn $timestampAntiLeechEncryptKey = getenv('QINIU_TIMESTAMP_ENCRPTKEY'); -$customDomain = "http://phpsdk.peterpy.cn"; +$customDomain = "http://sdk.peterpy.cn"; $tid = getenv('TRAVIS_JOB_NUMBER'); if (!empty($tid)) { diff --git a/vendor/upyun/sdk/.gitattributes b/vendor/upyun/sdk/.gitattributes new file mode 100644 index 000000000..7cf65400e --- /dev/null +++ b/vendor/upyun/sdk/.gitattributes @@ -0,0 +1,6 @@ +* text=auto + +/examples export-ignore +/tests export-ignore +/doc.md export-ignore +/phpunit.xml export-ignore diff --git a/vendor/upyun/sdk/README.md b/vendor/upyun/sdk/README.md index 12f49b7e5..8eda96a7c 100644 --- a/vendor/upyun/sdk/README.md +++ b/vendor/upyun/sdk/README.md @@ -95,6 +95,15 @@ $file = fopen('/local/path/file', 'r'); $client->write('/save/path', $file); ``` +#### 使用并行式断点续传上传文件 + +``` +$serviceConfig->setUploadType('BLOCK_PARALLEL'); +$client = new Upyun($serviceConfig); +$file = fopen('/local/path/file', 'r'); +$client->write('/save/path', $file); +``` + #### 上传图片并转换格式为 `png`,详见[上传作图](http://docs.upyun.com/cloud/image/#_2) ``` diff --git a/vendor/upyun/sdk/doc.md b/vendor/upyun/sdk/doc.md deleted file mode 100644 index 6da98893e..000000000 --- a/vendor/upyun/sdk/doc.md +++ /dev/null @@ -1,517 +0,0 @@ -# SDK 文档 - -又拍云 php sdk 中所有封装的接口,均通过 `Upyun\Upyun` 类封装,后续新版本也会保持 -该类方法向下兼容,sdk 中其他类及其方法不保证兼容性。如果有使用疑问欢迎提 [issues](https://github.com/upyun/php-sdk/issues) - -## 方法列表 - -* [Upyun](#upyun) - * [__construct](#__construct) - * [setConfig](#setconfig) 更新服务配置 - * [write](#write) 上传一个文件到又拍云存储 - * [read](#read) 读取云存储文件/目录内容 - * [has](#has) 判断文件是否存在于又拍云存储 - * [info](#info) 获取云存储文件/目录的基本信息 - * [getMimetype](#getmimetype) 获取云存储文件类型 - * [delete](#delete) 删除文件或者目录 - * [createDir](#createdir) 创建目录 - * [deleteDir](#deletedir) 删除文件或者目录 - * [usage](#usage) 获取目录下存储使用量 - * [purge](#purge) 刷新缓存 - * [process](#process) 异步云处理 - * [queryProcessStatus](#queryprocessstatus) 查询异步云处理任务进度 - * [queryProcessResult](#queryprocessresult) 查询异步云处理任务结果 - -## Upyun - -`Upyun\Upyun` 类实现了又拍云云存储和云处理的所有接口,通过该类可以实现文件上传、下载;图片视频等多媒体资源云处理。 -本文档中,提到的"服务"是指又拍云文件加速回又拍云源类型的服务(即原先的存储类服务)。 - -* 命名空间: `\Upyun\Upyun` - - -### __construct - -Upyun constructor. - -```php -Upyun::__construct( \Upyun\Config $config ) -``` - -**参数列表:** - -- **\Upyun\Config** `$config` - 服务配置 - ---- - -### setConfig - -更新服务配置 - -```php -Upyun::setConfig( \Upyun\Config $config ) -``` - - 当需要操作的新的服务时,使用该方法传入新的服务配置即可 - -**参数列表:** - -- **\Upyun\Config** `$config` - 服务配置 - ---- - - -### write - -上传一个文件到又拍云存储 - -```php -Upyun::write( string $path, string|resource $content, array $params = array(), boolean $withAsyncProcess = false ) -``` - - 上传的文件格式支持文件流或者字符串方式上传。除简单的文件上传外,针对多媒体资源(图片、音视频),还可以设置同步/异步预处理多媒体资源,例如:图片的裁剪缩放,音视频的转码截图等等众多又拍云强大的云处理功能 - - -**参数列表:** - - -- **string** `$path` - 被上传的文件在又拍云存储服务中保存的路径 - -- **string|resource** `$content` - 被上传的文件内容(字符串),或者打开该文件获得的文件句柄(文件流)。当上传本地大文件时,推荐使用文件流的方式上传 - -- **array** `$params` - 上传文件时,附加的自定义参数。支持 Content-MD5 Content-Type Content-Secret 等,详见 [上传参数](http://docs.upyun.com/api/rest_api/#_2),例如: - - 设置文件[保护秘钥](http://docs.upyun.com/api/rest_api/#Content-Secret) `write($path, $content, array('Content-Secret' => 'my-secret'))`; - - 添加[文件元信息](http://docs.upyun.com/api/rest_api/#metadata) `write($path, $content, array('X-Upyun-Meta-Foo' => - 'bar'))` - - [图片同步预处理](http://docs.upyun.com/cloud/image/#_5) `write($path, $content, array('x-gmkerl-thumb' => '/format/png'))` - -- **boolean** `$withAsyncProcess` - 默认为 `false`,当上传图片或者音视频资源时,可以设置该参数为 `true`,开启图片音视频的[异步处理功能](http://docs.upyun.com/api/form_api/#_6) ,例如: - ``` - // 以下参数会将新上传的图片,再异步生成另一份 png 格式的图片,原图不受影响 - write($path, $content, array( - 'apps' => array( - array( - 'name' => 'thumb', //异步图片处理任务 - 'x-gmkerl-thumb' => '/format/png', // 格式化图片为 png 格式 - 'save_as': '/iamge/png/new.png', // 处理成功后的图片保存路径 - 'notify_url': 'http://your.notify.url' // 异步任务完成后的回调地址 - ) - ) - ), true); - ``` - - -**返回值:** - -若文件是图片则返回图片基本信息,如:`array('x-upyun-width' => 123, 'x-upyun-height' => 50, 'x-upyun-frames' -=> 1, 'x-upyun-file-type' => 'JPEG')`,否则返回空数组。当使用异步预处理功能时,返回结果为布尔值,成功为 `true`。 - - - ---- - - -### read - -读取云存储文件/目录内容 - -```php -Upyun::read( string $path, resource $saveHandler = NULL, array $params = array() ) -``` - - - - -**参数列表:** - - -- **string** `$path` - 又拍云存储中的文件或者目录路径 - -- **resource** `$saveHandler` - 文件内容写入本地文件流。例如 `$saveHandler = fopen('/local/file', 'w') - `。当设置该参数时,将以文件流的方式,直接将又拍云中的文件写入本地的文件流,或其他可以写入的流 - -- **array** `$params` - 可选参数,读取目录内容时,需要设置三个参数: `X-List-Iter` 分页开始位置(第一页不需要设置),`X-List-Limit` 获取的文件数量(默认 100,最大 - 10000),`X-List-Order` 结果以时间正序或者倒序 - - -**返回值:** - -$return 当读取文件且没有设置 `$saveHandler` 参数时,返回一个字符串类型,表示文件内容;设置了 `$saveHandler` 参数时,返回布尔值 -`true`。当读取目录时,返回一个数组,表示目录下的文件列表。目录下文件内容过多时,需要通过判断返回数组中的 `is_end` 属性,进行分页读取内容 - - - ---- - - -### has - -判断文件是否存在于又拍云存储 - -```php -Upyun::has( string $path ) -``` - - 注意: 对刚删除的文件, 立即调用该方法可能会返回 true, 因为服务端执行删除操作后可能会有很短暂的延迟. - - -**参数列表:** - - -- **string** `$path` - 云存储的文件路径 - - -**返回值:** - -存在时返回 `true`,否则返回 `false` - - - ---- - - -### info - -获取云存储文件/目录的基本信息 - -```php -Upyun::info( string $path, array $otherHeaders) -``` - - - - -**参数列表:** - - -- **string** `$path` - 云存储的文件路径 - -- **string** `$otherHeaders` - 设置了后,方法将返回其他 http header 中的信息,默认为空 - -**返回值:** - -返回一个数组,默认包含以下 key -- `x-upyun-file-type` 当 $path 是目录时,值为 *folder*,当 $path 是文件时,值为 *file*, -- `x-upyun-file-size` 文件大小 -- `x-upyun-file-date` 文件的创建时间 - - - ---- - -### getMimetype - -获取云存储文件的文档类型 - -```php -Upyun::getMimetype( string $path ) -``` - - - - -**参数列表:** - - -- **string** `$path` - 云存储的文件路径 - - -**返回值:** - -文档类型,e.g: `appcation/json`,获取失败返回空字符串 - - - ---- - - -### delete - -删除文件或者目录 - -```php -Upyun::delete( string $path, boolean $async = false ) -``` - - - - -**参数列表:** - - -- **string** `$path` - 文件或目录在又拍云存储的路径 - -- **boolean** `$async` - 是否异步删除,默认为 false,表示同步删除。当需要批量删除大量文件时,必须选择异步删除 - - -**返回值:** - -删除成功返回 true,否则 false - - - ---- - - -### createDir - -创建目录 - -```php -Upyun::createDir( string $path ) -``` - - - - -**参数列表:** - - -- **string** `$path` - 需要在又拍云存储创建的目录路径 - - -**返回值:** - -创建成功返回 true,否则返回 false - - - ---- - - -### deleteDir - -删除文件或者目录 - -```php -Upyun::deleteDir( string $path ) -``` - - - - -**参数列表:** - - -- **string** `$path` - 需要被删除的云存储文件或目录路径 - - -**返回值:** - -成功返回 true,否则 false - - - ---- - - -### usage - -获取目录下存储使用量 - -```php -Upyun::usage( string $path = '/' ) -``` - - - - -**参数列表:** - - -- **string** `$path` - 云存储目录路径,默认为根目录,表示整个云存储服务使用的空间大小 - - -**返回值:** - -存储使用量,单位字节 - - - ---- - - -### purge - -刷新缓存 - -```php -Upyun::purge( array|string $urls ) -``` - - - - -**参数列表:** - - -- **array|string** `$urls` - 需要刷新的文件 url 列表 - - -**返回值:** - -刷新失败的 url 列表,若全部刷新成功则为空数组 - - - ---- - - -### process - -异步云处理 - -```php -Upyun::process( array $tasks, string $type, string $source ) -``` - - 该方法是基于[又拍云云处理](http://docs.upyun.com/cloud/) 服务实现,可以实现音视频的转码、切片、剪辑;文件的压缩解压缩;文件拉取功能 - - 注意: - - 所有需要调用该方法处理的资源,必须已经上传到云存储服务 - - 使用 `process` 之前,必须配置 `config->processNotifyUrl`,否则会提交任务失败 - -例如视频转码: -``` - process(array( - array( - 'type' => 'video', // video 表示视频任务, audio 表示音频任务 - 'avopts' => '/s/240p(4:3)/as/1/r/30', // 处理参数,`s` 表示输出的分辨率,`r` 表示视频帧率,`as` 表示是否自动调整分辨率 - 'save_as' => '/video/240/new.mp4', // 新视频在又拍云存储的保存路径 - ), - ... // 同时还可以添加其他任务 -), Upyun::$PROCESS_TYPE_MEDIA, $source) -``` -注意,被处理的资源需要已经上传到又拍云云存储 - - -**参数列表:** - - -- **array** `$tasks` - 需要处理的任务 - -- **string** `$type` - 异步云处理任务类型,可选值: - - `Upyun::$PROCESS_TYPE_MEDIA` 异步音视频处理 - - `Upyun::$PROCESS_TYPE_ZIP` 文件压缩 - - `Upyun::$PROCESS_TYPE_UNZIP` 文件解压 - - `Upyun::$PROCESS_TYPE_SYNC_FILE` 文件拉取 - - `Upyun::$PROCESS_TYPE_STITCH` 图片拼接 - -- **string** `$source` - 可选参数,处理异步音视频任务时,需要传递该参数,表示需要处理的文件路径 - - -**返回值:** - -任务 ID,提交了多少任务,便会返回多少任务 ID,与提交任务的顺序保持一致。可以通过任务 ID 查询处理进度。格式如下: -``` -array( - '35f0148d414a688a275bf915ba7cebb2', - '98adbaa52b2f63d6d7f327a0ff223348', -) -``` - - - ---- - - -### queryProcessStatus - -音视频预处理任务进度查询 - -```php -Upyun::queryProcessStatus( array $taskIds ) -``` - - 根据 `process` 方法返回的任务 ID,通过该访问查询处理进度 - - -**参数列表:** - - -- **array** `$taskIds` - 任务 ID - - -**返回值:** - -查询失败返回布尔值 `false`,否则返回每个任务的百分比进度信息,格式如下: -``` -array( - '35f0148d414a688a275bf915ba7cebb2' => 100, // 100 表示任务完成 - 'c3103189fa906a5354d29bd807e8dc51' => 35, - '98adbaa52b2f63d6d7f327a0ff223348' => null, // null 表示任务未开始,或异常 -) -``` - - - ---- - - -### queryProcessResult - -音视频预处理任务结果查询 - -```php -Upyun::queryProcessResult( array $taskIds ) -``` - - 根据 `process` 方法返回的任务 ID,通过该访问查询处理结果,会包含每个任务详细信息 - - -**参数列表:** - - -- **array** `$taskIds` - 任务 ID - - -**返回值:** - -查询失败返回 `false`,否则返回每个任务的处理结果,格式如下: -``` -array( - '9d9c32b63a1034834e77672c6f51f661' => array( - 'path' => array('/v2.mp4'), - 'signature' => '4042c1f07f546d28', - 'status_code' => 200, - 'service' => 'your_storage_service', - 'description' => 'OK', - 'task_id' => '9d9c32b63a1034834e77672c6f51f661', - 'timestamp' => 1472010684 - ) -) -``` - - - ---- - - - - --------- -> This document was automatically generated from source code comments on 2017-02-06 using [phpDocumentor](http://www.phpdoc.org/) and [cvuorinen/phpdoc-markdown-public](https://github.com/cvuorinen/phpdoc-markdown-public) diff --git a/vendor/upyun/sdk/examples/client-upload/Readme.md b/vendor/upyun/sdk/examples/client-upload/Readme.md deleted file mode 100644 index 9d025c8b3..000000000 --- a/vendor/upyun/sdk/examples/client-upload/Readme.md +++ /dev/null @@ -1,13 +0,0 @@ -## 客户端上传 - -本示例展示了如何使用表单 API, 直接从客户端进行安全的文件上传, 这种方式不需要客户服务器进行中转, 节省了客户服务器流量, 并且支持 HTTP/HTTPS 两种协议 - -DEMO 使用 `sdkimg` 空间进行演示, 上传成功后, 访问路径为 `http://sdkimg.b0.upaiyun.com/` 拼接保存路径 - -#### 运行示例 - -- `cd examples/client-upload` -- `php -S localhost:9000` - -打开浏览器访问 `http://localhost:9000`, 选则文件上传即可. -示例中使用 body 签名,避免 header 签名存在跨域失败的情况,因为 `Access-Control-Allow-Headers: *` 兼容性不好,是刚设定的协议[标准](https://github.com/whatwg/fetch) diff --git a/vendor/upyun/sdk/examples/client-upload/index.html b/vendor/upyun/sdk/examples/client-upload/index.html deleted file mode 100644 index b2a39ab93..000000000 --- a/vendor/upyun/sdk/examples/client-upload/index.html +++ /dev/null @@ -1,64 +0,0 @@ - - - - - Document - - - - - - -
-
- Client Upload Demo - - -
-
- - - - diff --git a/vendor/upyun/sdk/examples/client-upload/normalize.css b/vendor/upyun/sdk/examples/client-upload/normalize.css deleted file mode 100644 index 73454f7fc..000000000 --- a/vendor/upyun/sdk/examples/client-upload/normalize.css +++ /dev/null @@ -1,427 +0,0 @@ -/*! normalize.css v3.0.2 | MIT License | git.io/normalize */ - -/** - * 1. Set default font family to sans-serif. - * 2. Prevent iOS text size adjust after orientation change, without disabling - * user zoom. - */ - -html { - font-family: sans-serif; /* 1 */ - -ms-text-size-adjust: 100%; /* 2 */ - -webkit-text-size-adjust: 100%; /* 2 */ -} - -/** - * Remove default margin. - */ - -body { - margin: 0; -} - -/* HTML5 display definitions - ========================================================================== */ - -/** - * Correct `block` display not defined for any HTML5 element in IE 8/9. - * Correct `block` display not defined for `details` or `summary` in IE 10/11 - * and Firefox. - * Correct `block` display not defined for `main` in IE 11. - */ - -article, -aside, -details, -figcaption, -figure, -footer, -header, -hgroup, -main, -menu, -nav, -section, -summary { - display: block; -} - -/** - * 1. Correct `inline-block` display not defined in IE 8/9. - * 2. Normalize vertical alignment of `progress` in Chrome, Firefox, and Opera. - */ - -audio, -canvas, -progress, -video { - display: inline-block; /* 1 */ - vertical-align: baseline; /* 2 */ -} - -/** - * Prevent modern browsers from displaying `audio` without controls. - * Remove excess height in iOS 5 devices. - */ - -audio:not([controls]) { - display: none; - height: 0; -} - -/** - * Address `[hidden]` styling not present in IE 8/9/10. - * Hide the `template` element in IE 8/9/11, Safari, and Firefox < 22. - */ - -[hidden], -template { - display: none; -} - -/* Links - ========================================================================== */ - -/** - * Remove the gray background color from active links in IE 10. - */ - -a { - background-color: transparent; -} - -/** - * Improve readability when focused and also mouse hovered in all browsers. - */ - -a:active, -a:hover { - outline: 0; -} - -/* Text-level semantics - ========================================================================== */ - -/** - * Address styling not present in IE 8/9/10/11, Safari, and Chrome. - */ - -abbr[title] { - border-bottom: 1px dotted; -} - -/** - * Address style set to `bolder` in Firefox 4+, Safari, and Chrome. - */ - -b, -strong { - font-weight: bold; -} - -/** - * Address styling not present in Safari and Chrome. - */ - -dfn { - font-style: italic; -} - -/** - * Address variable `h1` font-size and margin within `section` and `article` - * contexts in Firefox 4+, Safari, and Chrome. - */ - -h1 { - font-size: 2em; - margin: 0.67em 0; -} - -/** - * Address styling not present in IE 8/9. - */ - -mark { - background: #ff0; - color: #000; -} - -/** - * Address inconsistent and variable font size in all browsers. - */ - -small { - font-size: 80%; -} - -/** - * Prevent `sub` and `sup` affecting `line-height` in all browsers. - */ - -sub, -sup { - font-size: 75%; - line-height: 0; - position: relative; - vertical-align: baseline; -} - -sup { - top: -0.5em; -} - -sub { - bottom: -0.25em; -} - -/* Embedded content - ========================================================================== */ - -/** - * Remove border when inside `a` element in IE 8/9/10. - */ - -img { - border: 0; -} - -/** - * Correct overflow not hidden in IE 9/10/11. - */ - -svg:not(:root) { - overflow: hidden; -} - -/* Grouping content - ========================================================================== */ - -/** - * Address margin not present in IE 8/9 and Safari. - */ - -figure { - margin: 1em 40px; -} - -/** - * Address differences between Firefox and other browsers. - */ - -hr { - -moz-box-sizing: content-box; - box-sizing: content-box; - height: 0; -} - -/** - * Contain overflow in all browsers. - */ - -pre { - overflow: auto; -} - -/** - * Address odd `em`-unit font size rendering in all browsers. - */ - -code, -kbd, -pre, -samp { - font-family: monospace, monospace; - font-size: 1em; -} - -/* Forms - ========================================================================== */ - -/** - * Known limitation: by default, Chrome and Safari on OS X allow very limited - * styling of `select`, unless a `border` property is set. - */ - -/** - * 1. Correct color not being inherited. - * Known issue: affects color of disabled elements. - * 2. Correct font properties not being inherited. - * 3. Address margins set differently in Firefox 4+, Safari, and Chrome. - */ - -button, -input, -optgroup, -select, -textarea { - color: inherit; /* 1 */ - font: inherit; /* 2 */ - margin: 0; /* 3 */ -} - -/** - * Address `overflow` set to `hidden` in IE 8/9/10/11. - */ - -button { - overflow: visible; -} - -/** - * Address inconsistent `text-transform` inheritance for `button` and `select`. - * All other form control elements do not inherit `text-transform` values. - * Correct `button` style inheritance in Firefox, IE 8/9/10/11, and Opera. - * Correct `select` style inheritance in Firefox. - */ - -button, -select { - text-transform: none; -} - -/** - * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` - * and `video` controls. - * 2. Correct inability to style clickable `input` types in iOS. - * 3. Improve usability and consistency of cursor style between image-type - * `input` and others. - */ - -button, -html input[type="button"], /* 1 */ -input[type="reset"], -input[type="submit"] { - -webkit-appearance: button; /* 2 */ - cursor: pointer; /* 3 */ -} - -/** - * Re-set default cursor for disabled elements. - */ - -button[disabled], -html input[disabled] { - cursor: default; -} - -/** - * Remove inner padding and border in Firefox 4+. - */ - -button::-moz-focus-inner, -input::-moz-focus-inner { - border: 0; - padding: 0; -} - -/** - * Address Firefox 4+ setting `line-height` on `input` using `!important` in - * the UA stylesheet. - */ - -input { - line-height: normal; -} - -/** - * It's recommended that you don't attempt to style these elements. - * Firefox's implementation doesn't respect box-sizing, padding, or width. - * - * 1. Address box sizing set to `content-box` in IE 8/9/10. - * 2. Remove excess padding in IE 8/9/10. - */ - -input[type="checkbox"], -input[type="radio"] { - box-sizing: border-box; /* 1 */ - padding: 0; /* 2 */ -} - -/** - * Fix the cursor style for Chrome's increment/decrement buttons. For certain - * `font-size` values of the `input`, it causes the cursor style of the - * decrement button to change from `default` to `text`. - */ - -input[type="number"]::-webkit-inner-spin-button, -input[type="number"]::-webkit-outer-spin-button { - height: auto; -} - -/** - * 1. Address `appearance` set to `searchfield` in Safari and Chrome. - * 2. Address `box-sizing` set to `border-box` in Safari and Chrome - * (include `-moz` to future-proof). - */ - -input[type="search"] { - -webkit-appearance: textfield; /* 1 */ - -moz-box-sizing: content-box; - -webkit-box-sizing: content-box; /* 2 */ - box-sizing: content-box; -} - -/** - * Remove inner padding and search cancel button in Safari and Chrome on OS X. - * Safari (but not Chrome) clips the cancel button when the search input has - * padding (and `textfield` appearance). - */ - -input[type="search"]::-webkit-search-cancel-button, -input[type="search"]::-webkit-search-decoration { - -webkit-appearance: none; -} - -/** - * Define consistent border, margin, and padding. - */ - -fieldset { - border: 1px solid #c0c0c0; - margin: 0 2px; - padding: 0.35em 0.625em 0.75em; -} - -/** - * 1. Correct `color` not being inherited in IE 8/9/10/11. - * 2. Remove padding so people aren't caught out if they zero out fieldsets. - */ - -legend { - border: 0; /* 1 */ - padding: 0; /* 2 */ -} - -/** - * Remove default vertical scrollbar in IE 8/9/10/11. - */ - -textarea { - overflow: auto; -} - -/** - * Don't inherit the `font-weight` (applied by a rule above). - * NOTE: the default cannot safely be changed in Chrome and Safari on OS X. - */ - -optgroup { - font-weight: bold; -} - -/* Tables - ========================================================================== */ - -/** - * Remove most spacing between table cells. - */ - -table { - border-collapse: collapse; - border-spacing: 0; -} - -td, -th { - padding: 0; -} \ No newline at end of file diff --git a/vendor/upyun/sdk/examples/client-upload/policy.php b/vendor/upyun/sdk/examples/client-upload/policy.php deleted file mode 100644 index 46fa47b0b..000000000 --- a/vendor/upyun/sdk/examples/client-upload/policy.php +++ /dev/null @@ -1,21 +0,0 @@ -setFormApiKey('Mv83tlocuzkmfKKUFbz2s04FzTw='); - -$data['save-key'] = $_GET['save_path']; -$data['expiration'] = time() + 120; -$data['bucket'] = BUCKET; -$policy = Util::base64Json($data); -$method = 'POST'; -$uri = '/' . $data['bucket']; -$signature = Signature::getBodySignature($config, $method, $uri, null, $policy); -echo json_encode(array( - 'policy' => $policy, - 'authorization' => $signature -)); diff --git a/vendor/upyun/sdk/examples/list-all-file.php b/vendor/upyun/sdk/examples/list-all-file.php deleted file mode 100644 index 8be8d05dc..000000000 --- a/vendor/upyun/sdk/examples/list-all-file.php +++ /dev/null @@ -1,35 +0,0 @@ -read('/', null, array( - 'X-List-Limit' => 100, - 'X-List-Iter' => $start, - )); - - if (is_array($list['files'])) { - foreach ($list['files'] as $file) { - $total++; - if ($file['type'] === 'N') { - echo '文件名: '; - } else { - echo '目录名: '; - } - echo $file['name']; - echo ' 大小:' . $file['size']; - echo ' 修改时间:' . date('Y-m-d H:i:s', $file['time']); - echo "\n"; - } - } - $start = $list['iter']; -} while (!$list['is_end']); - -echo '总共存有文件 ' . $total . ' 个'; diff --git a/vendor/upyun/sdk/phpunit.xml b/vendor/upyun/sdk/phpunit.xml deleted file mode 100644 index adfa7f614..000000000 --- a/vendor/upyun/sdk/phpunit.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - ./tests/SignatureTest.php - ./tests/UpyunTest.php - - - - - ./src/ - - - - - - diff --git a/vendor/upyun/sdk/src/Upyun/Api/Rest.php b/vendor/upyun/sdk/src/Upyun/Api/Rest.php index f63d775e7..be4b0a044 100644 --- a/vendor/upyun/sdk/src/Upyun/Api/Rest.php +++ b/vendor/upyun/sdk/src/Upyun/Api/Rest.php @@ -105,4 +105,28 @@ public function withHeaders($headers) } return $this; } + + public function toRequest() + { + $url = $this->endpoint . $this->storagePath; + $body = null; + if ($this->file && $this->method === 'PUT') { + $body = $this->file; + } + + $request = new Psr7\Request( + $this->method, + Util::encodeURI($url), + $this->headers, + $body + ); + $authHeader = Signature::getHeaderSign($this->config, + $this->method, + $request->getUri()->getPath() + ); + foreach ($authHeader as $head => $value) { + $request = $request->withHeader($head, $value); + } + return $request; + } } diff --git a/vendor/upyun/sdk/src/Upyun/Config.php b/vendor/upyun/sdk/src/Upyun/Config.php index b32b80980..1b99b6c4b 100644 --- a/vendor/upyun/sdk/src/Upyun/Config.php +++ b/vendor/upyun/sdk/src/Upyun/Config.php @@ -32,7 +32,7 @@ class Config public $useSsl; /** - * @var string 上传使用的接口类型,可以设置为 `REST`:使用 rest api 上传,`AUTO` 根据文件大小自动判断,`BLOCK` 使用断点续传 + * @var string 上传使用的接口类型,可以设置为 `REST`:使用 rest api 上传,`AUTO` 根据文件大小自动判断,`BLOCK` 使用串行式断点续传,`BLOCK_PARALLEL` 使用并行式断点续传 * 当上传小文件时,不推荐使用断点续传;上传时如果设置了异步预处理`withAsyncProcess=true`,将会使用表单 api 上传 */ public $uploadType = 'AUTO'; @@ -42,6 +42,11 @@ class Config */ public $sizeBoundary = 31457280; + /** + * @var int 并行式断点续传的并发数 + */ + public $concurrency = 5; + /** * @var int request timeout seconds */ @@ -144,4 +149,14 @@ public function getProtocol() { return $this->useSsl ? 'https://' : 'http://'; } + + public function setUploadType($uploadType) + { + $this->uploadType = $uploadType; + } + + public function setConcurrency($concurrency) + { + $this->concurrency = $concurrency; + } } diff --git a/vendor/upyun/sdk/src/Upyun/Uploader.php b/vendor/upyun/sdk/src/Upyun/Uploader.php index 862644e34..95e6f2f5c 100644 --- a/vendor/upyun/sdk/src/Upyun/Uploader.php +++ b/vendor/upyun/sdk/src/Upyun/Uploader.php @@ -4,6 +4,8 @@ use Upyun\Api\Rest; use Upyun\Api\Form; use GuzzleHttp\Psr7; +use GuzzleHttp\Pool; +use GuzzleHttp\Client; class Uploader { @@ -37,13 +39,15 @@ public function upload($path, $file, $params, $withAsyncProcess) ->withHeaders($params) ->withFile($stream) ->send(); + } elseif ($this->config->uploadType === 'BLOCK_PARALLEL') { + return $this->concurrentPointUpload($path, $stream, $params); } else { return $this->pointUpload($path, $stream, $params); } } /** - * 断点续传 + * 串行式断点续传 * @param $path * @param $stream * @param $params @@ -108,7 +112,8 @@ private function pointUpload($path, $stream, $params) private function needUseBlock($fileSize) { - if ($this->config->uploadType === 'BLOCK') { + if ($this->config->uploadType === 'BLOCK' || + $this->config->uploadType === 'BLOCK_PARALLEL') { return true; } elseif ($this->config->uploadType === 'AUTO' && $fileSize >= $this->config->sizeBoundary) { @@ -117,4 +122,81 @@ private function needUseBlock($fileSize) return false; } } + + /** + * 并行式断点续传 + * @param $path + * @param $stream + * @param $params + * + * @return mixed|\Psr\Http\Message\ResponseInterface + * @throws \Exception + */ + private function concurrentPointUpload($path, $stream, $params) + { + $req = new Rest($this->config); + + $headers = array(); + if (is_array($params)) { + foreach ($params as $key => $val) { + $headers['X-Upyun-Meta-' . $key] = $val; + } + } + $res = $req->request('PUT', $path) + ->withHeaders(array_merge(array( + 'X-Upyun-Multi-Disorder' => 'true', + 'X-Upyun-Multi-Stage' => 'initiate', + 'X-Upyun-Multi-Type' => Psr7\mimetype_from_filename($path), + 'X-Upyun-Multi-Length' => $stream->getSize(), + ), $headers)) + ->send(); + if ($res->getStatusCode() !== 204) { + throw new \Exception('init request failed when poinit upload!'); + } + + $init = Util::getHeaderParams($res->getHeaders()); + $uuid = $init['x-upyun-multi-uuid']; + $requests = function ($req, $path, $stream, $uuid) { + $blockSize = 1024 * 1024; + $total = ceil($stream->getSize() / $blockSize); + for ($i = 0; $i < $total; $i++) { + $fileBlock = $stream->read($blockSize); + yield $req->request('PUT', $path) + ->withHeaders(array( + 'X-Upyun-Multi-Stage' => 'upload', + 'X-Upyun-Multi-Uuid' => $uuid, + 'X-Upyun-Part-Id' => $i + )) + ->withFile(Psr7\stream_for($fileBlock)) + ->toRequest(); + } + }; + $client = new Client([ + 'timeout' => $this->config->timeout, + ]); + $pool = new Pool($client, $requests($req, $path, $stream, $uuid), [ + 'concurrency' => $this->config->concurrency, + 'fulfilled' => function ($res) { + if ($res->getStatusCode() !== 204) { + throw new \Exception('upload request failed when poinit upload!'); + } + }, + 'rejected' => function () { + throw new \Exception('upload request failed when poinit upload!'); + }, + ]); + $promise = $pool->promise(); + $promise->wait(); + + $res = $req->request('PUT', $path) + ->withHeaders(array( + 'X-Upyun-Multi-Uuid' => $uuid, + 'X-Upyun-Multi-Stage' => 'complete' + )) + ->send(); + if ($res->getStatusCode() != 204 && $res->getStatusCode() != 201) { + throw new \Exception('end request failed when poinit upload!'); + } + return $res; + } } diff --git a/vendor/upyun/sdk/src/Upyun/Upyun.php b/vendor/upyun/sdk/src/Upyun/Upyun.php index 08cfa1251..caa0c841e 100644 --- a/vendor/upyun/sdk/src/Upyun/Upyun.php +++ b/vendor/upyun/sdk/src/Upyun/Upyun.php @@ -377,7 +377,7 @@ public function process($tasks, $type, $source = '') case self::$PROCESS_TYPE_SYNC_FILE: $options['app_name'] = 'spiderman'; break; - case self::$PROCESS_TYPE_SYNC_FILE: + case self::$PROCESS_TYPE_CONVERT: $options['app_name'] = 'uconvert'; break; case self::$PROCESS_TYPE_STITCH: @@ -460,7 +460,7 @@ public function m3u8Concat($files, $saveAs) * @param string $file 需要剪辑的又拍云云存储中的 m3u8 文件路径 * @param string $saveAs 剪辑完成后新的 m3u8 文件保存路径 * @param array $slice 需要被保留或删除的片段。 - * @param bool $$isInclude 默认为 `true` 表示 `$slice` 参数描述的片段被保留,否则表示 `$slice` 参数描述的片段被删除 + * @param bool $isInclude 默认为 `true` 表示 `$slice` 参数描述的片段被保留,否则表示 `$slice` 参数描述的片段被删除 * @param bool $index 指定 `$slice` 参数的格式,默认为 `false` 表示使用时间范围描述片段,单位秒:`[<开始时间>, <结束时间>]`;`true` 表示使用 `m3u8` 文件的分片序号,从 0 开始,这种方式可以一次对多个片段操作 * * @return array 见 [m3u8 剪辑 - 响应](http://docs.upyun.com/cloud/sync_video/#_6) @@ -473,7 +473,7 @@ public function m3u8Clip($file, $saveAs, $slice = array(), $isInclude = true, $i 'save_as' => $saveAs, 'index' => $index, ]; - if ($$isInclude) { + if ($isInclude) { $params['include'] = $slice; } else { $params['exclude'] = $slice; diff --git a/vendor/upyun/sdk/tests/SignatureTest.php b/vendor/upyun/sdk/tests/SignatureTest.php deleted file mode 100644 index 0fd88f1f9..000000000 --- a/vendor/upyun/sdk/tests/SignatureTest.php +++ /dev/null @@ -1,25 +0,0 @@ -config = new Config('bucket', 'operator', 'password'); - } - - public function testGetBodySignature() - { - $sign = Signature::getBodySignature($this->config, 'POST', '/bucket'); - $this->assertEquals($sign, 'UPYUN operator:Xx3G6+DAvUyCL2Y2npSW/giTFI8='); - } -} diff --git a/vendor/upyun/sdk/tests/UpyunTest.php b/vendor/upyun/sdk/tests/UpyunTest.php deleted file mode 100644 index b6721252b..000000000 --- a/vendor/upyun/sdk/tests/UpyunTest.php +++ /dev/null @@ -1,272 +0,0 @@ -setFormApiKey('Mv83tlocuzkmfKKUFbz2s04FzTw='); - $config->processNotifyUrl = 'http://localhost:9999'; - self::$upyun = new Upyun($config); - self::$tempFilePath = __DIR__ . '/assets/test.txt'; - touch(self::$tempFilePath); - } - - public static function tearDownAfterClass() - { - unlink(self::$tempFilePath); - } - - public function testWriteString() - { - $filename = '/中文/测试 +.txt'; - $content = 'test file content'; - self::$upyun->write($filename, $content); - $size = getUpyunFileSize($filename); - $this->assertEquals($size, strlen($content)); - } - - public function testWriteStream() - { - $filename = 'test.jpeg'; - $f = fopen(__DIR__ . '/assets/sample.jpeg', 'rb'); - if (!$f) { - throw new \Exception('open test file failed!'); - } - self::$upyun->write($filename, $f); - $size = getUpyunFileSize($filename); - $this->assertEquals($size, PIC_SIZE); - } - - public function testWriteWithAsyncProcess() - { - $filename = 'test_async.jpeg'; - $newFilename = 'test_async.png'; - $f = fopen(__DIR__ . '/assets/sample.jpeg', 'rb'); - if (!$f) { - throw new \Exception('open test file failed!'); - } - $result = self::$upyun->write($filename, $f, array( - 'apps' => array( - array( - 'name' => 'thumb', - 'x-gmkerl-thumb' => '/format/png/fw/50', - 'save_as' => $newFilename, - ) - ) - ), true); - $size = getUpyunFileSize($filename); - $this->assertEquals($size, PIC_SIZE); - $this->assertEquals($result, true); - } - - public function testWriteWithException() - { - $fs = new Upyun(new Config(BUCKET, USER_NAME, 'error-password')); - try { - $fs->write('test.txt', 'test file content'); - } catch (\Exception $e) { - return ; - } - throw new \Exception('should get sign error.'); - } - - /** - * @depends testWriteString - */ - public function testReadFile() - { - $name = 'test-read.txt'; - $str = 'test file content 2'; - self::$upyun->write($name, $str); - - //读取内容写入字符串 - $content = self::$upyun->read($name); - $this->assertEquals($content, $str); - - //读取内容写入文件流 - $this->assertTrue(self::$upyun->read($name, fopen(self::$tempFilePath, 'wb'))); - $this->assertEquals($str, file_get_contents(self::$tempFilePath)); - } - - /** - * @depends testWriteString - * @depends testReadFile - */ - public function testDeleteFile() - { - self::$upyun->write('test-delete.txt', 'test file content 3'); - self::$upyun->delete('test-delete.txt'); - try { - self::$upyun->read('test-delete.txt'); - } catch (\Exception $e) { - return ; - } - throw new \Exception('delete file failed'); - } - - /** - * @expectedException \Exception - */ - public function testDeleteNotExistsFile() - { - self::$upyun->delete('not-exists-test.txt'); - } - - /** - */ - public function testHas() - { - $name = 'test-has.txt'; - self::$upyun->write($name, 'test file content 4'); - $this->assertEquals(self::$upyun->has($name), true); - self::$upyun->delete($name); - sleep(5); - $this->assertEquals(self::$upyun->has($name), false); - } - - /** - * @depends testWriteString - * @depends testDeleteFile - */ - public function testInfo() - { - self::$upyun->write('test-info.txt', 'test file content 4'); - $info = self::$upyun->info('test-info.txt'); - $this->assertEquals($info['x-upyun-file-type'], 'file'); - $this->assertEquals($info['x-upyun-file-size'], 19); - } - - /** - * @depends testInfo - */ - public function testGetMimetype() - { - $type = self::$upyun->getMimetype('test-info.txt'); - $this->assertEquals($type, 'text/plain'); - } - - /** - */ - public function testCreateDir() - { - self::$upyun->createDir('/test-dir'); - $this->assertEquals(self::$upyun->has('/test-dir'), true); - self::$upyun->createDir('/test-dir2/'); - $this->assertEquals(self::$upyun->has('/test-dir2'), true); - } - - public function testReadDir() - { - $list = self::$upyun->read('/test-dir2/'); - $this->assertEquals($list['is_end'], true); - self::$upyun->write('/test-dir2/test.txt', 'test file content 5'); - $list = self::$upyun->read('/test-dir2/'); - $this->assertEquals($list['is_end'], true); - $this->assertEquals(count($list['files']), 1); - $file = $list['files'][0]; - $this->assertEquals($file['name'], 'test.txt'); - $this->assertEquals($file['type'], 'N'); - $this->assertEquals($file['size'], 19); - } - - /** - * @depends testCreateDir - */ - public function testDeleteDir() - { - $result = self::$upyun->createDir('/test-delete-dir'); - $this->assertEquals($result, true); - sleep(5); - $result = self::$upyun->deleteDir('/test-delete-dir'); - $this->assertEquals($result, true); - } - - public function testUsage() - { - $size = self::$upyun->usage(); - $this->assertTrue($size > 0); - } - - public function testPurge() - { - $urls = self::$upyun->purge(getFileUrl('test.txt')); - $this->assertTrue(empty($urls)); - - $invalidUrl = 'http://xxxx.b0.xxxxxxxx-upyun.com/test.txt'; - $urls = self::$upyun->purge($invalidUrl); - $this->assertTrue(count($urls) === 1); - $this->assertTrue($urls[0] === $invalidUrl); - } - - public function testProcess() - { - $source = 'php-sdk-sample.mp4'; - self::$upyun->write($source, fopen(__DIR__ . '/assets/SampleVideo_640x360_1mb.mp4', 'r')); - $result = self::$upyun->process(array( - array('type' => 'video', 'avopts' => '/s/240p(4:3)/as/1/r/30', 'return_info' => true, 'save_as' => '/video/result.mp4') - ), Upyun::$PROCESS_TYPE_MEDIA, $source); - $this->assertTrue(strlen($result[0]) === 32); - self::$taskId = $result[0]; - - // test zip - $result2 = self::$upyun->process(array(array( - 'sources' => ['./php-sdk-sample.mp4'], - 'save_as' => '/php-sdk-sample-mp4.zip' - )), Upyun::$PROCESS_TYPE_ZIP); - $this->assertTrue(strlen($result2[0]) === 32); - } - - /** - * @depends testProcess - */ - public function testQueryProcessStatus() - { - sleep(5); - $status = self::$upyun->queryProcessStatus(array(self::$taskId)); - $this->assertTrue(array_key_exists(self::$taskId, $status)); - } - - /** - * @depends testProcess - */ - public function testQueryProcessResult() - { - sleep(5); - $result = self::$upyun->queryProcessResult(array(self::$taskId)); - $this->assertTrue($result[self::$taskId]['path'][0] === '/video/result.mp4'); - $this->assertTrue($result[self::$taskId]['status_code'] === 200); - } - - public function testAvMeta() - { - $source = 'php-sdk-sample.mp4'; - self::$upyun->write($source, fopen(__DIR__ . '/assets/SampleVideo_640x360_1mb.mp4', 'r')); - $result = self::$upyun->avMeta('/php-sdk-sample.mp4'); - $this->assertTrue(count($result) === 2); - $this->assertTrue($result['streams'][0]['type'] === 'video'); - } - - public function testSnapshot() - { - $source = 'php-sdk-sample.mp4'; - self::$upyun->write($source, fopen(__DIR__ . '/assets/SampleVideo_640x360_1mb.mp4', 'r')); - $result = self::$upyun->snapshot('/php-sdk-sample.mp4', '/snapshot.jpg', '00:00:01', '720x480', 'jpg'); - $this->assertTrue($result['status_code'] === 200); - } -} diff --git a/vendor/upyun/sdk/tests/assets/SampleVideo_640x360_1mb.mp4 b/vendor/upyun/sdk/tests/assets/SampleVideo_640x360_1mb.mp4 deleted file mode 100644 index 02c2060bd..000000000 Binary files a/vendor/upyun/sdk/tests/assets/SampleVideo_640x360_1mb.mp4 and /dev/null differ diff --git a/vendor/upyun/sdk/tests/assets/sample.jpeg b/vendor/upyun/sdk/tests/assets/sample.jpeg deleted file mode 100644 index dbfe17d37..000000000 Binary files a/vendor/upyun/sdk/tests/assets/sample.jpeg and /dev/null differ diff --git a/vendor/upyun/sdk/tests/bootstrap.php b/vendor/upyun/sdk/tests/bootstrap.php deleted file mode 100644 index 04f822f4f..000000000 --- a/vendor/upyun/sdk/tests/bootstrap.php +++ /dev/null @@ -1,31 +0,0 @@ -