正在显示
41 个修改的文件
包含
4803 行增加
和
0 行删除
.bowerrc
0 → 100644
.gitignore
0 → 100644
404.html
0 → 100644
| 1 | +<!doctype html> | ||
| 2 | +<html> | ||
| 3 | +<head> | ||
| 4 | +<meta charset="utf-8"> | ||
| 5 | +<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
| 6 | +<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"> | ||
| 7 | +<title>404</title> | ||
| 8 | +<style> | ||
| 9 | + body{ | ||
| 10 | + background-color:#444; | ||
| 11 | + font-size:14px; | ||
| 12 | + } | ||
| 13 | + h3{ | ||
| 14 | + font-size:60px; | ||
| 15 | + color:#eee; | ||
| 16 | + text-align:center; | ||
| 17 | + padding-top:30px; | ||
| 18 | + font-weight:normal; | ||
| 19 | + } | ||
| 20 | +</style> | ||
| 21 | +</head> | ||
| 22 | + | ||
| 23 | +<body> | ||
| 24 | +<h3>404,您请求的文件不存在!</h3> | ||
| 25 | +</body> | ||
| 26 | +</html> |
LICENSE
0 → 100644
| 1 | +Apache License | ||
| 2 | +Version 2.0, January 2004 | ||
| 3 | +http://www.apache.org/licenses/ | ||
| 4 | + | ||
| 5 | +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | ||
| 6 | + | ||
| 7 | +1. Definitions. | ||
| 8 | + | ||
| 9 | +"License" shall mean the terms and conditions for use, reproduction, and | ||
| 10 | +distribution as defined by Sections 1 through 9 of this document. | ||
| 11 | + | ||
| 12 | +"Licensor" shall mean the copyright owner or entity authorized by the copyright | ||
| 13 | +owner that is granting the License. | ||
| 14 | + | ||
| 15 | +"Legal Entity" shall mean the union of the acting entity and all other entities | ||
| 16 | +that control, are controlled by, or are under common control with that entity. | ||
| 17 | +For the purposes of this definition, "control" means (i) the power, direct or | ||
| 18 | +indirect, to cause the direction or management of such entity, whether by | ||
| 19 | +contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the | ||
| 20 | +outstanding shares, or (iii) beneficial ownership of such entity. | ||
| 21 | + | ||
| 22 | +"You" (or "Your") shall mean an individual or Legal Entity exercising | ||
| 23 | +permissions granted by this License. | ||
| 24 | + | ||
| 25 | +"Source" form shall mean the preferred form for making modifications, including | ||
| 26 | +but not limited to software source code, documentation source, and configuration | ||
| 27 | +files. | ||
| 28 | + | ||
| 29 | +"Object" form shall mean any form resulting from mechanical transformation or | ||
| 30 | +translation of a Source form, including but not limited to compiled object code, | ||
| 31 | +generated documentation, and conversions to other media types. | ||
| 32 | + | ||
| 33 | +"Work" shall mean the work of authorship, whether in Source or Object form, made | ||
| 34 | +available under the License, as indicated by a copyright notice that is included | ||
| 35 | +in or attached to the work (an example is provided in the Appendix below). | ||
| 36 | + | ||
| 37 | +"Derivative Works" shall mean any work, whether in Source or Object form, that | ||
| 38 | +is based on (or derived from) the Work and for which the editorial revisions, | ||
| 39 | +annotations, elaborations, or other modifications represent, as a whole, an | ||
| 40 | +original work of authorship. For the purposes of this License, Derivative Works | ||
| 41 | +shall not include works that remain separable from, or merely link (or bind by | ||
| 42 | +name) to the interfaces of, the Work and Derivative Works thereof. | ||
| 43 | + | ||
| 44 | +"Contribution" shall mean any work of authorship, including the original version | ||
| 45 | +of the Work and any modifications or additions to that Work or Derivative Works | ||
| 46 | +thereof, that is intentionally submitted to Licensor for inclusion in the Work | ||
| 47 | +by the copyright owner or by an individual or Legal Entity authorized to submit | ||
| 48 | +on behalf of the copyright owner. For the purposes of this definition, | ||
| 49 | +"submitted" means any form of electronic, verbal, or written communication sent | ||
| 50 | +to the Licensor or its representatives, including but not limited to | ||
| 51 | +communication on electronic mailing lists, source code control systems, and | ||
| 52 | +issue tracking systems that are managed by, or on behalf of, the Licensor for | ||
| 53 | +the purpose of discussing and improving the Work, but excluding communication | ||
| 54 | +that is conspicuously marked or otherwise designated in writing by the copyright | ||
| 55 | +owner as "Not a Contribution." | ||
| 56 | + | ||
| 57 | +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf | ||
| 58 | +of whom a Contribution has been received by Licensor and subsequently | ||
| 59 | +incorporated within the Work. | ||
| 60 | + | ||
| 61 | +2. Grant of Copyright License. | ||
| 62 | + | ||
| 63 | +Subject to the terms and conditions of this License, each Contributor hereby | ||
| 64 | +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, | ||
| 65 | +irrevocable copyright license to reproduce, prepare Derivative Works of, | ||
| 66 | +publicly display, publicly perform, sublicense, and distribute the Work and such | ||
| 67 | +Derivative Works in Source or Object form. | ||
| 68 | + | ||
| 69 | +3. Grant of Patent License. | ||
| 70 | + | ||
| 71 | +Subject to the terms and conditions of this License, each Contributor hereby | ||
| 72 | +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, | ||
| 73 | +irrevocable (except as stated in this section) patent license to make, have | ||
| 74 | +made, use, offer to sell, sell, import, and otherwise transfer the Work, where | ||
| 75 | +such license applies only to those patent claims licensable by such Contributor | ||
| 76 | +that are necessarily infringed by their Contribution(s) alone or by combination | ||
| 77 | +of their Contribution(s) with the Work to which such Contribution(s) was | ||
| 78 | +submitted. If You institute patent litigation against any entity (including a | ||
| 79 | +cross-claim or counterclaim in a lawsuit) alleging that the Work or a | ||
| 80 | +Contribution incorporated within the Work constitutes direct or contributory | ||
| 81 | +patent infringement, then any patent licenses granted to You under this License | ||
| 82 | +for that Work shall terminate as of the date such litigation is filed. | ||
| 83 | + | ||
| 84 | +4. Redistribution. | ||
| 85 | + | ||
| 86 | +You may reproduce and distribute copies of the Work or Derivative Works thereof | ||
| 87 | +in any medium, with or without modifications, and in Source or Object form, | ||
| 88 | +provided that You meet the following conditions: | ||
| 89 | + | ||
| 90 | +You must give any other recipients of the Work or Derivative Works a copy of | ||
| 91 | +this License; and | ||
| 92 | +You must cause any modified files to carry prominent notices stating that You | ||
| 93 | +changed the files; and | ||
| 94 | +You must retain, in the Source form of any Derivative Works that You distribute, | ||
| 95 | +all copyright, patent, trademark, and attribution notices from the Source form | ||
| 96 | +of the Work, excluding those notices that do not pertain to any part of the | ||
| 97 | +Derivative Works; and | ||
| 98 | +If the Work includes a "NOTICE" text file as part of its distribution, then any | ||
| 99 | +Derivative Works that You distribute must include a readable copy of the | ||
| 100 | +attribution notices contained within such NOTICE file, excluding those notices | ||
| 101 | +that do not pertain to any part of the Derivative Works, in at least one of the | ||
| 102 | +following places: within a NOTICE text file distributed as part of the | ||
| 103 | +Derivative Works; within the Source form or documentation, if provided along | ||
| 104 | +with the Derivative Works; or, within a display generated by the Derivative | ||
| 105 | +Works, if and wherever such third-party notices normally appear. The contents of | ||
| 106 | +the NOTICE file are for informational purposes only and do not modify the | ||
| 107 | +License. You may add Your own attribution notices within Derivative Works that | ||
| 108 | +You distribute, alongside or as an addendum to the NOTICE text from the Work, | ||
| 109 | +provided that such additional attribution notices cannot be construed as | ||
| 110 | +modifying the License. | ||
| 111 | +You may add Your own copyright statement to Your modifications and may provide | ||
| 112 | +additional or different license terms and conditions for use, reproduction, or | ||
| 113 | +distribution of Your modifications, or for any such Derivative Works as a whole, | ||
| 114 | +provided Your use, reproduction, and distribution of the Work otherwise complies | ||
| 115 | +with the conditions stated in this License. | ||
| 116 | + | ||
| 117 | +5. Submission of Contributions. | ||
| 118 | + | ||
| 119 | +Unless You explicitly state otherwise, any Contribution intentionally submitted | ||
| 120 | +for inclusion in the Work by You to the Licensor shall be under the terms and | ||
| 121 | +conditions of this License, without any additional terms or conditions. | ||
| 122 | +Notwithstanding the above, nothing herein shall supersede or modify the terms of | ||
| 123 | +any separate license agreement you may have executed with Licensor regarding | ||
| 124 | +such Contributions. | ||
| 125 | + | ||
| 126 | +6. Trademarks. | ||
| 127 | + | ||
| 128 | +This License does not grant permission to use the trade names, trademarks, | ||
| 129 | +service marks, or product names of the Licensor, except as required for | ||
| 130 | +reasonable and customary use in describing the origin of the Work and | ||
| 131 | +reproducing the content of the NOTICE file. | ||
| 132 | + | ||
| 133 | +7. Disclaimer of Warranty. | ||
| 134 | + | ||
| 135 | +Unless required by applicable law or agreed to in writing, Licensor provides the | ||
| 136 | +Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, | ||
| 137 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, | ||
| 138 | +including, without limitation, any warranties or conditions of TITLE, | ||
| 139 | +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are | ||
| 140 | +solely responsible for determining the appropriateness of using or | ||
| 141 | +redistributing the Work and assume any risks associated with Your exercise of | ||
| 142 | +permissions under this License. | ||
| 143 | + | ||
| 144 | +8. Limitation of Liability. | ||
| 145 | + | ||
| 146 | +In no event and under no legal theory, whether in tort (including negligence), | ||
| 147 | +contract, or otherwise, unless required by applicable law (such as deliberate | ||
| 148 | +and grossly negligent acts) or agreed to in writing, shall any Contributor be | ||
| 149 | +liable to You for damages, including any direct, indirect, special, incidental, | ||
| 150 | +or consequential damages of any character arising as a result of this License or | ||
| 151 | +out of the use or inability to use the Work (including but not limited to | ||
| 152 | +damages for loss of goodwill, work stoppage, computer failure or malfunction, or | ||
| 153 | +any and all other commercial damages or losses), even if such Contributor has | ||
| 154 | +been advised of the possibility of such damages. | ||
| 155 | + | ||
| 156 | +9. Accepting Warranty or Additional Liability. | ||
| 157 | + | ||
| 158 | +While redistributing the Work or Derivative Works thereof, You may choose to | ||
| 159 | +offer, and charge a fee for, acceptance of support, warranty, indemnity, or | ||
| 160 | +other liability obligations and/or rights consistent with this License. However, | ||
| 161 | +in accepting such obligations, You may act only on Your own behalf and on Your | ||
| 162 | +sole responsibility, not on behalf of any other Contributor, and only if You | ||
| 163 | +agree to indemnify, defend, and hold each Contributor harmless for any liability | ||
| 164 | +incurred by, or claims asserted against, such Contributor by reason of your | ||
| 165 | +accepting any such warranty or additional liability. | ||
| 166 | + | ||
| 167 | +END OF TERMS AND CONDITIONS | ||
| 168 | + | ||
| 169 | +APPENDIX: How to apply the Apache License to your work | ||
| 170 | + | ||
| 171 | +To apply the Apache License to your work, attach the following boilerplate | ||
| 172 | +notice, with the fields enclosed by brackets "{}" replaced with your own | ||
| 173 | +identifying information. (Don't include the brackets!) The text should be | ||
| 174 | +enclosed in the appropriate comment syntax for the file format. We also | ||
| 175 | +recommend that a file or class name and description of purpose be included on | ||
| 176 | +the same "printed page" as the copyright notice for easier identification within | ||
| 177 | +third-party archives. | ||
| 178 | + | ||
| 179 | + Copyright 2017 Karson | ||
| 180 | + | ||
| 181 | + Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 182 | + you may not use this file except in compliance with the License. | ||
| 183 | + You may obtain a copy of the License at | ||
| 184 | + | ||
| 185 | + http://www.apache.org/licenses/LICENSE-2.0 | ||
| 186 | + | ||
| 187 | + Unless required by applicable law or agreed to in writing, software | ||
| 188 | + distributed under the License is distributed on an "AS IS" BASIS, | ||
| 189 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 190 | + See the License for the specific language governing permissions and | ||
| 191 | + limitations under the License. |
README.md
0 → 100644
| 1 | +FastAdmin是一款基于ThinkPHP5+Bootstrap的极速后台开发框架。 | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +## 主要特性 | ||
| 5 | + | ||
| 6 | +* 基于`Auth`验证的权限管理系统 | ||
| 7 | + * 支持无限级父子级权限继承,父级的管理员可任意增删改子级管理员及权限设置 | ||
| 8 | + * 支持单管理员多角色 | ||
| 9 | + * 支持管理子级数据或个人数据 | ||
| 10 | +* 强大的一键生成功能 | ||
| 11 | + * 一键生成CRUD,包括控制器、模型、视图、JS、语言包、菜单、回收站等 | ||
| 12 | + * 一键压缩打包JS和CSS文件,一键CDN静态资源部署 | ||
| 13 | + * 一键生成控制器菜单和规则 | ||
| 14 | + * 一键生成API接口文档 | ||
| 15 | +* 完善的前端功能组件开发 | ||
| 16 | + * 基于`AdminLTE`二次开发 | ||
| 17 | + * 基于`Bootstrap`开发,自适应手机、平板、PC | ||
| 18 | + * 基于`RequireJS`进行JS模块管理,按需加载 | ||
| 19 | + * 基于`Less`进行样式开发 | ||
| 20 | +* 强大的插件扩展功能,在线安装卸载升级插件 | ||
| 21 | +* 通用的会员模块和API模块 | ||
| 22 | +* 共用同一账号体系的Web端会员中心权限验证和API接口会员权限验证 | ||
| 23 | +* 二级域名部署支持,同时域名支持绑定到应用插件 | ||
| 24 | +* 多语言支持,服务端及客户端支持 | ||
| 25 | +* 支持大文件分片上传、剪切板粘贴上传、拖拽上传,进度条显示,图片上传前压缩 | ||
| 26 | +* 支持表格固定列、固定表头、跨页选择、Excel导出、模板渲染等功能 | ||
| 27 | +* 强大的第三方应用模块支持([CMS](https://www.fastadmin.net/store/cms.html)、[博客](https://www.fastadmin.net/store/blog.html)、[知识付费问答](https://www.fastadmin.net/store/ask.html)、[在线投票系统](https://www.fastadmin.net/store/vote.html)、[B2C商城](https://www.fastadmin.net/store/shopro.html)、[B2B2C商城](https://www.fastadmin.net/store/wanlshop.html)) | ||
| 28 | +* 支持CMS、博客、知识付费问答无缝整合[Xunsearch全文搜索](https://www.fastadmin.net/store/xunsearch.html) | ||
| 29 | +* 第三方小程序支持([CMS小程序](https://www.fastadmin.net/store/cms.html)、[预订小程序](https://www.fastadmin.net/store/ball.html)、[问答小程序](https://www.fastadmin.net/store/ask.html)、[点餐小程序](https://www.fastadmin.net/store/unidrink.html)、[B2C小程序](https://www.fastadmin.net/store/shopro.html)、[B2B2C小程序](https://www.fastadmin.net/store/wanlshop.html)、[博客小程序](https://www.fastadmin.net/store/blog.html)) | ||
| 30 | +* 整合第三方短信接口(阿里云、腾讯云短信) | ||
| 31 | +* 无缝整合第三方云存储(七牛云、阿里云OSS、又拍云)功能,支持云储存分片上传 | ||
| 32 | +* 第三方富文本编辑器支持(Summernote、Kindeditor、百度编辑器) | ||
| 33 | +* 第三方登录(QQ、微信、微博)整合 | ||
| 34 | +* 第三方支付(微信、支付宝)无缝整合,微信支持PC端扫码支付 | ||
| 35 | +* 丰富的插件应用市场 | ||
| 36 | + | ||
| 37 | +## 安装使用 | ||
| 38 | + | ||
| 39 | +https://doc.fastadmin.net | ||
| 40 | + | ||
| 41 | +## 在线演示 | ||
| 42 | + | ||
| 43 | +https://demo.fastadmin.net | ||
| 44 | + | ||
| 45 | +用户名:admin | ||
| 46 | + | ||
| 47 | +密 码:123456 | ||
| 48 | + | ||
| 49 | +提 示:演示站数据无法进行修改,请下载源码安装体验全部功能 | ||
| 50 | + | ||
| 51 | +## 界面截图 | ||
| 52 | + | ||
| 53 | + | ||
| 54 | +## 问题反馈 | ||
| 55 | + | ||
| 56 | +在使用中有任何问题,请使用以下联系方式联系我们 | ||
| 57 | + | ||
| 58 | +交流社区: https://ask.fastadmin.net | ||
| 59 | + | ||
| 60 | +QQ群: [636393962](https://jq.qq.com/?_wv=1027&k=487PNBb)(满) [708784003](https://jq.qq.com/?_wv=1027&k=5ObjtwM)(满) [964776039](https://jq.qq.com/?_wv=1027&k=59qjU2P)(3群) [749803490](https://jq.qq.com/?_wv=1027&k=5tczi88)(满) [767103006](https://jq.qq.com/?_wv=1027&k=5Z1U751)(满) [675115483](https://jq.qq.com/?_wv=1027&k=54I6mts)(6群) | ||
| 61 | + | ||
| 62 | +Github: https://github.com/karsonzhang/fastadmin | ||
| 63 | + | ||
| 64 | +Gitee: https://gitee.com/karson/fastadmin | ||
| 65 | + | ||
| 66 | +## 特别鸣谢 | ||
| 67 | + | ||
| 68 | +感谢以下的项目,排名不分先后 | ||
| 69 | + | ||
| 70 | +ThinkPHP:http://www.thinkphp.cn | ||
| 71 | + | ||
| 72 | +AdminLTE:https://adminlte.io | ||
| 73 | + | ||
| 74 | +Bootstrap:http://getbootstrap.com | ||
| 75 | + | ||
| 76 | +jQuery:http://jquery.com | ||
| 77 | + | ||
| 78 | +Bootstrap-table:https://github.com/wenzhixin/bootstrap-table | ||
| 79 | + | ||
| 80 | +Nice-validator: https://validator.niceue.com | ||
| 81 | + | ||
| 82 | +SelectPage: https://github.com/TerryZ/SelectPage | ||
| 83 | + | ||
| 84 | +Layer: https://layer.layui.com | ||
| 85 | + | ||
| 86 | +DropzoneJS: https://www.dropzonejs.com | ||
| 87 | + | ||
| 88 | + | ||
| 89 | +## 版权信息 | ||
| 90 | + | ||
| 91 | +FastAdmin遵循Apache2开源协议发布,并提供免费使用。 | ||
| 92 | + | ||
| 93 | +本项目包含的第三方源码和二进制文件之版权信息另行标注。 | ||
| 94 | + | ||
| 95 | +版权所有Copyright © 2017-2020 by FastAdmin (https://www.fastadmin.net) | ||
| 96 | + | ||
| 97 | +All rights reserved。 |
UpdateSql-sunshuai.sql
0 → 100644
| 1 | + | ||
| 2 | +--------2021-03-09 基地管理房间预约新加sql ----- | ||
| 3 | +DROP TABLE IF EXISTS `fa_project_building`; | ||
| 4 | +CREATE TABLE `fa_project_building` ( | ||
| 5 | + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', | ||
| 6 | + `school_id` int(11) NOT NULL COMMENT '所属学校ID', | ||
| 7 | + `building_name` varchar(200) NOT NULL COMMENT '楼栋名称', | ||
| 8 | + `building_no` varchar(30) DEFAULT NULL COMMENT '楼栋编号', | ||
| 9 | + `building_desc` text NOT NULL COMMENT '楼栋介绍', | ||
| 10 | + `createtime` int(11) DEFAULT NULL COMMENT '创建时间', | ||
| 11 | + `updatetime` int(11) DEFAULT NULL COMMENT '更新时间', | ||
| 12 | + `deletetime` int(11) DEFAULT NULL COMMENT '删除时间', | ||
| 13 | + PRIMARY KEY (`id`) USING BTREE, | ||
| 14 | + UNIQUE KEY `building_no` (`building_no`) | ||
| 15 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='楼栋管理表'; | ||
| 16 | + | ||
| 17 | +DROP TABLE IF EXISTS `fa_project_floor`; | ||
| 18 | +CREATE TABLE `fa_project_floor` ( | ||
| 19 | + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', | ||
| 20 | + `building_id` int(11) NOT NULL COMMENT '所属楼栋ID', | ||
| 21 | + `school_id` int(11) NOT NULL COMMENT '所属学校ID', | ||
| 22 | + `floor_name` varchar(200) NOT NULL COMMENT '楼层名称', | ||
| 23 | + `floor_no` varchar(30) DEFAULT NULL COMMENT '楼栋编号', | ||
| 24 | + `createtime` int(11) DEFAULT NULL COMMENT '创建时间', | ||
| 25 | + `updatetime` int(11) DEFAULT NULL COMMENT '更新时间', | ||
| 26 | + `deletetime` int(11) DEFAULT NULL COMMENT '删除时间', | ||
| 27 | + PRIMARY KEY (`id`) USING BTREE, | ||
| 28 | + KEY `building_id_2` (`building_id`) USING BTREE, | ||
| 29 | + UNIQUE KEY `building_id` (`building_id`,`floor_no`) | ||
| 30 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='楼层管理表'; | ||
| 31 | + | ||
| 32 | +DROP TABLE IF EXISTS `fa_project_room`; | ||
| 33 | +CREATE TABLE `fa_project_room` ( | ||
| 34 | + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', | ||
| 35 | + `building_id` int(11) NOT NULL COMMENT '所属楼栋ID', | ||
| 36 | + `floor_id` int(11) NOT NULL COMMENT '所属楼层ID', | ||
| 37 | + `school_id` int(11) NOT NULL COMMENT '所属学校ID', | ||
| 38 | + `college_id` int(11) NOT NULL COMMENT '所属学院ID', | ||
| 39 | + `specialty_id` int(11) NOT NULL COMMENT '所属学院ID', | ||
| 40 | + `room_name` varchar(200) NOT NULL COMMENT '房间名称', | ||
| 41 | + `room_no` varchar(30) NOT NULL COMMENT '房间编号', | ||
| 42 | + `room_type` tinyint(2) NOT NULL COMMENT '【1:会议室;2:办公室;3:路演大厅;4:公共办公区;5:实验室;6:多媒体教室;】', | ||
| 43 | + `room_status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '【0:不开放;1:开放;】', | ||
| 44 | + `build_space` decimal(10,2) NOT NULL COMMENT '房间建筑面积', | ||
| 45 | + `room_space` decimal(10,2) NOT NULL COMMENT '房间使用面积', | ||
| 46 | + `count_people`int(11) NOT NULL COMMENT '容纳人数', | ||
| 47 | + `room_desc` text NOT NULL COMMENT '房间介绍', | ||
| 48 | + `createtime` int(11) DEFAULT NULL COMMENT '创建时间', | ||
| 49 | + `updatetime` int(11) DEFAULT NULL COMMENT '更新时间', | ||
| 50 | + `deletetime` int(11) DEFAULT NULL COMMENT '删除时间', | ||
| 51 | + PRIMARY KEY (`id`) USING BTREE, | ||
| 52 | + KEY `building_id` (`building_id`) USING BTREE, | ||
| 53 | + KEY `floor_id` (`floor_id`) USING BTREE, | ||
| 54 | + KEY `college_id` (`college_id`) USING BTREE, | ||
| 55 | + KEY `specialty_id` (`specialty_id`) USING BTREE, | ||
| 56 | + UNIQUE KEY `building_id_2` (`building_id`,`floor_id`,`room_no`) | ||
| 57 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='房间管理表'; | ||
| 58 | + | ||
| 59 | + | ||
| 60 | +DROP TABLE IF EXISTS `fa_project_floor`; | ||
| 61 | +CREATE TABLE `fa_project_floor` ( | ||
| 62 | + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', | ||
| 63 | + `building_id` int(11) NOT NULL COMMENT '所属楼栋ID', | ||
| 64 | + `school_id` int(11) NOT NULL COMMENT '所属学校ID', | ||
| 65 | + `floor_name` varchar(200) NOT NULL COMMENT '楼层名称', | ||
| 66 | + `floor_no` varchar(30) DEFAULT NULL COMMENT '楼栋编号', | ||
| 67 | + `createtime` int(11) DEFAULT NULL COMMENT '创建时间', | ||
| 68 | + `updatetime` int(11) DEFAULT NULL COMMENT '更新时间', | ||
| 69 | + `deletetime` int(11) DEFAULT NULL COMMENT '删除时间', | ||
| 70 | + PRIMARY KEY (`id`) USING BTREE, | ||
| 71 | + KEY `building_id_2` (`building_id`) USING BTREE, | ||
| 72 | + UNIQUE KEY `building_id` (`building_id`,`floor_no`) | ||
| 73 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='楼层管理表'; | ||
| 74 | + | ||
| 75 | +DROP TABLE IF EXISTS `fa_project_room_order`; | ||
| 76 | +CREATE TABLE `fa_project_room_order` ( | ||
| 77 | + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键ID', | ||
| 78 | + `room_id` int(11) NOT NULL COMMENT '房间ID', | ||
| 79 | + `user_id` int(11) NOT NULL COMMENT '申请人ID', | ||
| 80 | + `apply_date` date NOT NULL COMMENT '预约日期', | ||
| 81 | + `start_time` int(11) NOT NULL COMMENT '预约开始时间', | ||
| 82 | + `end_time` int(11) NOT NULL COMMENT '预约结束时间', | ||
| 83 | + `use_count` int(4) NOT NULL COMMENT '使用人数', | ||
| 84 | + `status` tinyint(2) NOT NULL default '1' COMMENT '【1:待审核;2:已通过;3:未通过;4:预约已取消】', | ||
| 85 | + `apply_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '【1:个人;2:公司;】', | ||
| 86 | + `apply_desc` text NOT NULL COMMENT '使用设备说明', | ||
| 87 | + `createtime` int(11) DEFAULT NULL COMMENT '创建时间', | ||
| 88 | + `updatetime` int(11) DEFAULT NULL COMMENT '更新时间', | ||
| 89 | + `deletetime` int(11) DEFAULT NULL COMMENT '删除时间', | ||
| 90 | + PRIMARY KEY (`id`) USING BTREE | ||
| 91 | +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='基地预约申请表'; | ||
| 92 | + | ||
| 93 | +--------2021-03-10 sunshuai 项目双选 修改 fa_project_double 表 sql ----- | ||
| 94 | +ALTER TABLE `innovation`.`fa_project_double` | ||
| 95 | +MODIFY COLUMN `project_des` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '双选项目描述' AFTER `project_type`, | ||
| 96 | +MODIFY COLUMN `members_standard` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '成员要求' AFTER `project_des`, | ||
| 97 | +MODIFY COLUMN `teachers_standard` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '指导教师要求' AFTER `members_standard`; | ||
| 98 | + | ||
| 99 | +ALTER TABLE `innovation`.`fa_project_double` | ||
| 100 | +ADD COLUMN `register_id` int(11) NULL DEFAULT 0 COMMENT 'register表id' AFTER `user_id`; | ||
| 101 | + | ||
| 102 | +--------2021-03-12 sunshuai 项目双选 修改 fa_project_double 表 sql ----- | ||
| 103 | +ALTER TABLE `innovation`.`fa_project_double` | ||
| 104 | +ADD COLUMN `school_id` int(11) NOT NULL DEFAULT 0 AFTER `project_container_id`; | ||
| 105 | + | ||
| 106 | +--------2021-03-18 sunshuai 标签表 修改 fa_match_tags 表 sql ----- | ||
| 107 | +ALTER TABLE `innovation`.`fa_match_tags` | ||
| 108 | +ADD COLUMN `default` tinyint(1) NULL DEFAULT 0 COMMENT '默认标签 1:是0否' AFTER `school_id`; | ||
| 109 | + | ||
| 110 | +ALTER TABLE `innovation`.`fa_review_tags` | ||
| 111 | +ADD COLUMN `default` tinyint(1) NULL DEFAULT 0 COMMENT '默认标签1是0否' AFTER `school_id`; | ||
| 112 | + | ||
| 113 | + | ||
| 114 | + | ||
| 115 | +CREATE TABLE `innovation`.`fa_banner` ( | ||
| 116 | + `banner_id` int(11) NOT NULL AUTO_INCREMENT, | ||
| 117 | + `image` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT 'banner地址', | ||
| 118 | + `url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '跳转地址', | ||
| 119 | + `school_id` int(11) NULL DEFAULT 0 COMMENT '学校id', | ||
| 120 | + `sort` int(11) NOT NULL DEFAULT 1 COMMENT '显示顺序', | ||
| 121 | + `status` enum('normal','hidden') CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT 'normal' COMMENT '状态', | ||
| 122 | + `createtime` int(11) NOT NULL DEFAULT 0, | ||
| 123 | + `updatetime` int(11) NOT NULL, | ||
| 124 | + `deletetime` int(11) DEFAULT NULL, | ||
| 125 | + PRIMARY KEY (`banner_id`) | ||
| 126 | +); | ||
| 127 | + | ||
| 128 | +ALTER TABLE `innovation`.`fa_banner` ENGINE = InnoDB; |
addons/nkeditor/.addonrc
0 → 100644
| 1 | +{"license":"regular","licenseto":"11004","licensekey":"UnHqP5791arJzSlC RbYOIxfUlzOnp7apQN7cfg==","files":["public\\assets\\addons\\nkeditor\\css\\common.css","public\\assets\\addons\\nkeditor\\css\\richtext.css","public\\assets\\addons\\nkeditor\\img\\download.png","public\\assets\\addons\\nkeditor\\img\\downloading.png","public\\assets\\addons\\nkeditor\\js\\customplugin.js","public\\assets\\addons\\nkeditor\\lang\\ar.js","public\\assets\\addons\\nkeditor\\lang\\en.js","public\\assets\\addons\\nkeditor\\lang\\ja-JP.js","public\\assets\\addons\\nkeditor\\lang\\ko.js","public\\assets\\addons\\nkeditor\\lang\\ru.js","public\\assets\\addons\\nkeditor\\lang\\zh-CN.js","public\\assets\\addons\\nkeditor\\lang\\zh-TW.js","public\\assets\\addons\\nkeditor\\less\\richtext.less","public\\assets\\addons\\nkeditor\\nkeditor.js","public\\assets\\addons\\nkeditor\\nkeditor.min.js","public\\assets\\addons\\nkeditor\\plugins\\anchor\\anchor.js","public\\assets\\addons\\nkeditor\\plugins\\autoheight\\autoheight.js","public\\assets\\addons\\nkeditor\\plugins\\baidumap\\baidumap.js","public\\assets\\addons\\nkeditor\\plugins\\baidumap\\index.html","public\\assets\\addons\\nkeditor\\plugins\\baidumap\\map.html","public\\assets\\addons\\nkeditor\\plugins\\clearhtml\\clearhtml.js","public\\assets\\addons\\nkeditor\\plugins\\code\\code.js","public\\assets\\addons\\nkeditor\\plugins\\code\\pretty.js","public\\assets\\addons\\nkeditor\\plugins\\code\\prism.css","public\\assets\\addons\\nkeditor\\plugins\\code\\prism.js","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\emoticons.js","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\0.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\1.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\10.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\100.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\101.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\102.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\103.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\104.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\105.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\106.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\107.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\108.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\109.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\11.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\110.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\111.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\112.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\113.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\114.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\115.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\116.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\117.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\118.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\119.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\12.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\120.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\121.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\122.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\123.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\124.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\125.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\126.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\127.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\128.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\129.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\13.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\130.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\131.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\132.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\133.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\134.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\14.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\15.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\16.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\17.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\18.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\19.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\2.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\20.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\21.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\22.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\23.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\24.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\25.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\26.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\27.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\28.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\29.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\3.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\30.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\31.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\32.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\33.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\34.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\35.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\36.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\37.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\38.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\39.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\4.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\40.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\41.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\42.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\43.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\44.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\45.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\46.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\47.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\48.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\49.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\5.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\50.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\51.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\52.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\53.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\54.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\55.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\56.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\57.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\58.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\59.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\6.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\60.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\61.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\62.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\63.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\64.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\65.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\66.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\67.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\68.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\69.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\7.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\70.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\71.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\72.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\73.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\74.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\75.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\76.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\77.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\78.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\79.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\8.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\80.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\81.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\82.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\83.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\84.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\85.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\86.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\87.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\88.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\89.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\9.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\90.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\91.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\92.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\93.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\94.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\95.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\96.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\97.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\98.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\99.gif","public\\assets\\addons\\nkeditor\\plugins\\emoticons\\images\\static.gif","public\\assets\\addons\\nkeditor\\plugins\\filemanager\\css\\filemanager.min.css","public\\assets\\addons\\nkeditor\\plugins\\filemanager\\filemanager.js","public\\assets\\addons\\nkeditor\\plugins\\filemanager\\FManager.js","public\\assets\\addons\\nkeditor\\plugins\\filemanager\\FManager.min.js","public\\assets\\addons\\nkeditor\\plugins\\fixtoolbar\\fixtoolbar.js","public\\assets\\addons\\nkeditor\\plugins\\flash\\flash.js","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\addimg.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\blur.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\brush.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\delimg.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\delimgH.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\empty.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\emptyH.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\eraser.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\init.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\redo.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\redoH.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\save.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\scale.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\scaleH.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\size.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\undo.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\images\\undoH.png","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\scrawl.css","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\scrawl.css.map","public\\assets\\addons\\nkeditor\\plugins\\graft\\css\\scrawl.scss","public\\assets\\addons\\nkeditor\\plugins\\graft\\graft.js","public\\assets\\addons\\nkeditor\\plugins\\graft\\index.html","public\\assets\\addons\\nkeditor\\plugins\\graft\\scrawl.js","public\\assets\\addons\\nkeditor\\plugins\\image\\image.js","public\\assets\\addons\\nkeditor\\plugins\\image\\images\\align_left.gif","public\\assets\\addons\\nkeditor\\plugins\\image\\images\\align_right.gif","public\\assets\\addons\\nkeditor\\plugins\\image\\images\\align_top.gif","public\\assets\\addons\\nkeditor\\plugins\\image\\images\\refresh.png","public\\assets\\addons\\nkeditor\\plugins\\insertfile\\insertfile.js","public\\assets\\addons\\nkeditor\\plugins\\lineheight\\lineheight.js","public\\assets\\addons\\nkeditor\\plugins\\link\\link.js","public\\assets\\addons\\nkeditor\\plugins\\map\\map.html","public\\assets\\addons\\nkeditor\\plugins\\map\\map.js","public\\assets\\addons\\nkeditor\\plugins\\media\\media.js","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\BUpload.js","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\BUpload.min.js","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\aep.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\asp.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\avi.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\c.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\conf.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\css.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\default.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\doc.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\eml.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\eps.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\fla.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\htm.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\idn.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\ini.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\java.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\js.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\jsf.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\markdown.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\mdb.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\midi.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\mov.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\mp3.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\mpeg.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\pdf.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\php.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\ppt.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\psd.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\pst.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\pub.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\py.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\rb.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\rmvb.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\scss.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\sql.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\tif.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\txt.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\vsd.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\wav.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\wma.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\wmv.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\xls.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\xml.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\icons\\zip.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\images\\dialog-title-bg.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\images\\icons-all.gif","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\images\\icons.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\images\\image.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\images\\loader.gif","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\images\\progress.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\images\\success.png","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\upload.css","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\upload.css.map","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\upload.min.css","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\css\\upload.scss","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\multiimage.js","public\\assets\\addons\\nkeditor\\plugins\\multiimage\\template\\template.html","public\\assets\\addons\\nkeditor\\plugins\\pagebreak\\pagebreak.js","public\\assets\\addons\\nkeditor\\plugins\\plainpaste\\plainpaste.js","public\\assets\\addons\\nkeditor\\plugins\\preview\\preview.js","public\\assets\\addons\\nkeditor\\plugins\\quickformat\\quickformat.js","public\\assets\\addons\\nkeditor\\plugins\\quote\\quote.js","public\\assets\\addons\\nkeditor\\plugins\\table\\table.js","public\\assets\\addons\\nkeditor\\plugins\\template\\html\\1.html","public\\assets\\addons\\nkeditor\\plugins\\template\\html\\2.html","public\\assets\\addons\\nkeditor\\plugins\\template\\html\\3.html","public\\assets\\addons\\nkeditor\\plugins\\template\\template.js","public\\assets\\addons\\nkeditor\\plugins\\wordpaste\\wordpaste.js","public\\assets\\addons\\nkeditor\\themes\\app.css","public\\assets\\addons\\nkeditor\\themes\\black\\editor.css","public\\assets\\addons\\nkeditor\\themes\\black\\editor.css.map","public\\assets\\addons\\nkeditor\\themes\\black\\editor.min.css","public\\assets\\addons\\nkeditor\\themes\\black\\editor.scss","public\\assets\\addons\\nkeditor\\themes\\black\\images\\nkeditor.png","public\\assets\\addons\\nkeditor\\themes\\black\\images\\nkeditor.svg","public\\assets\\addons\\nkeditor\\themes\\blue\\editor.css","public\\assets\\addons\\nkeditor\\themes\\blue\\editor.css.map","public\\assets\\addons\\nkeditor\\themes\\blue\\editor.min.css","public\\assets\\addons\\nkeditor\\themes\\blue\\editor.scss","public\\assets\\addons\\nkeditor\\themes\\blue\\images\\nkeditor.png","public\\assets\\addons\\nkeditor\\themes\\blue\\images\\nkeditor.svg","public\\assets\\addons\\nkeditor\\themes\\common\\anchor.gif","public\\assets\\addons\\nkeditor\\themes\\common\\blank.gif","public\\assets\\addons\\nkeditor\\themes\\common\\common.css","public\\assets\\addons\\nkeditor\\themes\\common\\common.css.map","public\\assets\\addons\\nkeditor\\themes\\common\\common.scss","public\\assets\\addons\\nkeditor\\themes\\common\\dialog-title-bg.png","public\\assets\\addons\\nkeditor\\themes\\common\\flash.gif","public\\assets\\addons\\nkeditor\\themes\\common\\flash.png","public\\assets\\addons\\nkeditor\\themes\\common\\flash.svg","public\\assets\\addons\\nkeditor\\themes\\common\\icons-all.gif","public\\assets\\addons\\nkeditor\\themes\\common\\loading.gif","public\\assets\\addons\\nkeditor\\themes\\common\\media.gif","public\\assets\\addons\\nkeditor\\themes\\common\\play.png","public\\assets\\addons\\nkeditor\\themes\\common\\play.svg","public\\assets\\addons\\nkeditor\\themes\\common\\rm.gif","public\\assets\\addons\\nkeditor\\themes\\default\\editor.css","public\\assets\\addons\\nkeditor\\themes\\default\\editor.min.css","public\\assets\\addons\\nkeditor\\themes\\default\\images\\background.png","public\\assets\\addons\\nkeditor\\themes\\default\\images\\default.png","public\\assets\\addons\\nkeditor\\themes\\default\\images\\scrawl.png","public\\assets\\addons\\nkeditor\\themes\\grey\\editor.css","public\\assets\\addons\\nkeditor\\themes\\grey\\editor.css.map","public\\assets\\addons\\nkeditor\\themes\\grey\\editor.min.css","public\\assets\\addons\\nkeditor\\themes\\grey\\editor.scss","public\\assets\\addons\\nkeditor\\themes\\grey\\images\\nkeditor.png","public\\assets\\addons\\nkeditor\\themes\\grey\\images\\nkeditor.svg","public\\assets\\addons\\nkeditor\\themes\\primary\\editor.css","public\\assets\\addons\\nkeditor\\themes\\primary\\editor.css.map","public\\assets\\addons\\nkeditor\\themes\\primary\\editor.min.css","public\\assets\\addons\\nkeditor\\themes\\primary\\editor.scss","public\\assets\\addons\\nkeditor\\themes\\primary\\images\\nkeditor.png","public\\assets\\addons\\nkeditor\\themes\\primary\\images\\nkeditor.svg"]} |
addons/nkeditor/Nkeditor.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace addons\nkeditor; | ||
| 4 | + | ||
| 5 | +use app\common\library\Menu; | ||
| 6 | +use think\Addons; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 富文本编辑器插件 | ||
| 10 | + */ | ||
| 11 | +class Nkeditor extends Addons | ||
| 12 | +{ | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 插件安装方法 | ||
| 16 | + * @return bool | ||
| 17 | + */ | ||
| 18 | + public function install() | ||
| 19 | + { | ||
| 20 | + | ||
| 21 | + return true; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 插件卸载方法 | ||
| 26 | + * @return bool | ||
| 27 | + */ | ||
| 28 | + public function uninstall() | ||
| 29 | + { | ||
| 30 | + | ||
| 31 | + return true; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 插件启用方法 | ||
| 36 | + * @return bool | ||
| 37 | + */ | ||
| 38 | + public function enable() | ||
| 39 | + { | ||
| 40 | + | ||
| 41 | + return true; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 插件禁用方法 | ||
| 46 | + * @return bool | ||
| 47 | + */ | ||
| 48 | + public function disable() | ||
| 49 | + { | ||
| 50 | + | ||
| 51 | + return true; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * @param $params | ||
| 56 | + */ | ||
| 57 | + public function configInit(&$params) | ||
| 58 | + { | ||
| 59 | + $config = $this->getConfig(); | ||
| 60 | + $params['nkeditor'] = ['theme' => $config['theme'], 'wordimageserver' => $config['wordimageserver']]; | ||
| 61 | + } | ||
| 62 | + | ||
| 63 | +} |
addons/nkeditor/README.md
0 → 100644
| 1 | +# NKeditor | ||
| 2 | +NKedtior是基于 kindeditor 进行二次开发的项目 | ||
| 3 | +kindeditor 是一款优秀的开源在线编辑器。轻量级且功能强大,代码量却不到百度的ueditor编辑器的一半。可惜已经4年没有更新了,由于业务的需求我们在kindeditor的基础上开发了 NKeditor, 主要做了一下工作: | ||
| 4 | +1. 调整编辑器和弹出 dialog 的样式,美化了UI | ||
| 5 | +2. 重写图片上传和批量图片上传插件,使用 html5 上传代替了 flash,实现了待上传图片预览,优化用户体验 | ||
| 6 | +3. 修复一些已知的bug,如 ajax 提交无法获取内容等 | ||
| 7 | +4. 新增涂鸦等功能 | ||
| 8 | + | ||
| 9 | +再次感谢 kindeditor 的开发者,为我们提供了如此优秀的在线编辑器,让我们能在前人的基础上继续贡献自己的微薄之力。 | ||
| 10 | + | ||
| 11 | +# 开源说明 | ||
| 12 | +本插件基于Nkeditor进行二次开发,修改的核心文件已开源于 https://gitee.com/karson/kindeditor | ||
| 13 | + | ||
| 14 | +# 特别感谢 | ||
| 15 | +[Kindeditor](https://gitee.com/luolonghao/kindeditor) | ||
| 16 | +[Nkeditor](https://gitee.com/blackfox/kindeditor) | ||
| 17 | + |
addons/nkeditor/bootstrap.js
0 → 100644
| 1 | +require.config({ | ||
| 2 | + paths: { | ||
| 3 | + 'nkeditor': '../addons/nkeditor/js/customplugin', | ||
| 4 | + 'nkeditor-core': '../addons/nkeditor/nkeditor.min', | ||
| 5 | + 'nkeditor-lang': '../addons/nkeditor/lang/zh-CN', | ||
| 6 | + }, | ||
| 7 | + shim: { | ||
| 8 | + 'nkeditor': { | ||
| 9 | + deps: [ | ||
| 10 | + 'nkeditor-core', | ||
| 11 | + 'nkeditor-lang' | ||
| 12 | + ] | ||
| 13 | + }, | ||
| 14 | + 'nkeditor-core': { | ||
| 15 | + deps: [ | ||
| 16 | + 'css!../addons/nkeditor/themes/black/editor.min.css', | ||
| 17 | + 'css!../addons/nkeditor/css/common.css' | ||
| 18 | + ], | ||
| 19 | + exports: 'window.KindEditor' | ||
| 20 | + }, | ||
| 21 | + 'nkeditor-lang': { | ||
| 22 | + deps: [ | ||
| 23 | + 'nkeditor-core' | ||
| 24 | + ] | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | +}); | ||
| 28 | +require(['form'], function (Form) { | ||
| 29 | + var _bindevent = Form.events.bindevent; | ||
| 30 | + Form.events.bindevent = function (form) { | ||
| 31 | + _bindevent.apply(this, [form]); | ||
| 32 | + if ($(".editor", form).size() > 0) { | ||
| 33 | + require(['nkeditor', 'upload'], function (Nkeditor, Upload) { | ||
| 34 | + var getImageFromClipboard, getImageFromDrop, getFileFromBase64; | ||
| 35 | + getImageFromClipboard = function (data) { | ||
| 36 | + var i, item; | ||
| 37 | + i = 0; | ||
| 38 | + while (i < data.clipboardData.items.length) { | ||
| 39 | + item = data.clipboardData.items[i]; | ||
| 40 | + if (item.type.indexOf("image") !== -1) { | ||
| 41 | + return item.getAsFile() || false; | ||
| 42 | + } | ||
| 43 | + i++; | ||
| 44 | + } | ||
| 45 | + return false; | ||
| 46 | + }; | ||
| 47 | + getImageFromDrop = function (data) { | ||
| 48 | + var i, item, images; | ||
| 49 | + i = 0; | ||
| 50 | + images = []; | ||
| 51 | + while (i < data.dataTransfer.files.length) { | ||
| 52 | + item = data.dataTransfer.files[i]; | ||
| 53 | + if (item.type.indexOf("image") !== -1) { | ||
| 54 | + images.push(item); | ||
| 55 | + } | ||
| 56 | + i++; | ||
| 57 | + } | ||
| 58 | + return images; | ||
| 59 | + }; | ||
| 60 | + getFileFromBase64 = function (data, url) { | ||
| 61 | + var arr = data.split(','), mime = arr[0].match(/:(.*?);/)[1], | ||
| 62 | + bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n); | ||
| 63 | + while (n--) { | ||
| 64 | + u8arr[n] = bstr.charCodeAt(n); | ||
| 65 | + } | ||
| 66 | + var filename, suffix; | ||
| 67 | + if (typeof url != 'undefined') { | ||
| 68 | + var urlArr = url.split('.'); | ||
| 69 | + filename = url.substr(url.lastIndexOf('/') + 1); | ||
| 70 | + suffix = urlArr.pop(); | ||
| 71 | + } else { | ||
| 72 | + filename = Math.random().toString(36).substring(5, 15); | ||
| 73 | + } | ||
| 74 | + if (!suffix) { | ||
| 75 | + suffix = data.substring("data:image/".length, data.indexOf(";base64")); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + var exp = new RegExp("\\." + suffix + "$", "i"); | ||
| 79 | + filename = exp.test(filename) ? filename : filename + "." + suffix; | ||
| 80 | + var file = new File([u8arr], filename, {type: mime}); | ||
| 81 | + return file; | ||
| 82 | + }; | ||
| 83 | + | ||
| 84 | + var getImageFromUrl = function (url, callback, outputFormat) { | ||
| 85 | + var canvas = document.createElement('CANVAS'), | ||
| 86 | + ctx = canvas.getContext('2d'), | ||
| 87 | + img = new Image; | ||
| 88 | + img.crossOrigin = 'Anonymous'; | ||
| 89 | + img.onload = function () { | ||
| 90 | + var urlArr = url.split('.'); | ||
| 91 | + var suffix = urlArr.pop(); | ||
| 92 | + suffix = suffix.match(/^(jpg|png|gif|bmp|jpeg)$/i) ? suffix : 'png'; | ||
| 93 | + | ||
| 94 | + try { | ||
| 95 | + canvas.height = img.height; | ||
| 96 | + canvas.width = img.width; | ||
| 97 | + ctx.drawImage(img, 0, 0); | ||
| 98 | + var dataURL = canvas.toDataURL(outputFormat || 'image/' + suffix); | ||
| 99 | + var file = getFileFromBase64(dataURL, url); | ||
| 100 | + } catch (e) { | ||
| 101 | + callback.call(this, null); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + callback.call(this, file); | ||
| 105 | + canvas = null; | ||
| 106 | + }; | ||
| 107 | + img.onerror = function (e) { | ||
| 108 | + callback.call(this, null); | ||
| 109 | + }; | ||
| 110 | + img.src = Fast.api.fixurl("/addons/nkeditor/index/download") + "?url=" + encodeURIComponent(url); | ||
| 111 | + }; | ||
| 112 | + //上传Word图片 | ||
| 113 | + Nkeditor.uploadwordimage = function (index, image) { | ||
| 114 | + var that = this; | ||
| 115 | + (function () { | ||
| 116 | + var file = getFileFromBase64(image); | ||
| 117 | + var placeholder = new RegExp("##" + index + "##", "g"); | ||
| 118 | + Upload.api.send(file, function (data) { | ||
| 119 | + that.html(that.html().replace(placeholder, Fast.api.cdnurl(data.url))); | ||
| 120 | + }, function (data) { | ||
| 121 | + that.html(that.html().replace(placeholder, "")); | ||
| 122 | + }); | ||
| 123 | + }(index, image)); | ||
| 124 | + }; | ||
| 125 | + | ||
| 126 | + Nkeditor.lang({ | ||
| 127 | + remoteimage: '下载远程图片' | ||
| 128 | + }); | ||
| 129 | + //远程下载图片 | ||
| 130 | + Nkeditor.plugin('remoteimage', function (K) { | ||
| 131 | + var editor = this, name = 'remoteimage'; | ||
| 132 | + editor.plugin.remoteimage = { | ||
| 133 | + download: function (e) { | ||
| 134 | + var that = this; | ||
| 135 | + var html = that.html(); | ||
| 136 | + var staging = {}, orgined = {}, index = 0, images = 0, completed = 0, failured = 0; | ||
| 137 | + var checkrestore = function () { | ||
| 138 | + if (completed + failured >= images) { | ||
| 139 | + $.each(staging, function (i, j) { | ||
| 140 | + that.html(that.html().replace("<code>" + i + "</code>", j)); | ||
| 141 | + }); | ||
| 142 | + } | ||
| 143 | + }; | ||
| 144 | + html.replace(/<code>([\s\S]*?)<\/code>/g, function (code) { | ||
| 145 | + staging[index] = code; | ||
| 146 | + return "<code>" + index + "</code>"; | ||
| 147 | + } | ||
| 148 | + ); | ||
| 149 | + html = html.replace(/<img([\s\S]*?)\ssrc\s*=\s*('|")((http(s?):)([\s\S]*?))('|")([\s\S]*?)[\/]?>/g, function () { | ||
| 150 | + images++; | ||
| 151 | + var url = arguments[3]; | ||
| 152 | + var placeholder = '<img src="' + Fast.api.cdnurl("/assets/addons/nkeditor/img/downloading.png") + '" data-index="' + index + '" />'; | ||
| 153 | + //如果是云存储的链接,则忽略 | ||
| 154 | + if (Config.upload.cdnurl && url.indexOf(Config.upload.cdnurl) > -1) { | ||
| 155 | + completed++; | ||
| 156 | + return arguments[0]; | ||
| 157 | + } else { | ||
| 158 | + orgined[index] = arguments[0]; | ||
| 159 | + } | ||
| 160 | + //下载远程图片 | ||
| 161 | + (function (index, url, placeholder) { | ||
| 162 | + getImageFromUrl(url, function (file) { | ||
| 163 | + if (!file) { | ||
| 164 | + failured++; | ||
| 165 | + that.html(that.html().replace(placeholder, orgined[index])); | ||
| 166 | + checkrestore(); | ||
| 167 | + } else { | ||
| 168 | + Upload.api.send(file, function (data) { | ||
| 169 | + completed++; | ||
| 170 | + that.html(that.html().replace(placeholder, '<img src="' + Fast.api.cdnurl(data.url) + '" />')); | ||
| 171 | + checkrestore(); | ||
| 172 | + }, function (data) { | ||
| 173 | + failured++; | ||
| 174 | + that.html(that.html().replace(placeholder, orgined[index])); | ||
| 175 | + checkrestore(); | ||
| 176 | + }); | ||
| 177 | + } | ||
| 178 | + }); | ||
| 179 | + })(index, url, placeholder); | ||
| 180 | + index++; | ||
| 181 | + return placeholder; | ||
| 182 | + }); | ||
| 183 | + if (index > 0) { | ||
| 184 | + that.html(html); | ||
| 185 | + } else { | ||
| 186 | + Toastr.info("没有需要下载的远程图片"); | ||
| 187 | + } | ||
| 188 | + } | ||
| 189 | + }; | ||
| 190 | + // 点击图标时执行 | ||
| 191 | + editor.clickToolbar(name, editor.plugin.remoteimage.download); | ||
| 192 | + }); | ||
| 193 | + | ||
| 194 | + $(".editor", form).each(function () { | ||
| 195 | + var that = this; | ||
| 196 | + Nkeditor.create(that, { | ||
| 197 | + width: '100%', | ||
| 198 | + filterMode: false, | ||
| 199 | + wellFormatMode: false, | ||
| 200 | + allowMediaUpload: true, //是否允许媒体上传 | ||
| 201 | + allowFileManager: true, | ||
| 202 | + allowImageUpload: true, | ||
| 203 | + fontSizeTable: ['9px', '10px', '12px', '14px', '16px', '18px', '21px', '24px', '32px'], | ||
| 204 | + wordImageServer: typeof Config.nkeditor != 'undefined' && Config.nkeditor.wordimageserver ? "127.0.0.1:10101" : "", //word图片替换服务器的IP和端口 | ||
| 205 | + cssPath: Fast.api.cdnurl('/assets/addons/nkeditor/plugins/code/prism.css'), | ||
| 206 | + cssData: "body {font-size: 13px}", | ||
| 207 | + fillDescAfterUploadImage: false, //是否在上传后继续添加描述信息 | ||
| 208 | + themeType: typeof Config.nkeditor != 'undefined' ? Config.nkeditor.theme : 'black', //编辑器皮肤,这个值从后台获取 | ||
| 209 | + fileManagerJson: Fast.api.fixurl("/addons/nkeditor/index/attachment/module/" + Config.modulename), | ||
| 210 | + items: [ | ||
| 211 | + 'source', 'undo', 'redo', 'preview', 'print', 'template', 'code', 'quote', 'cut', 'copy', 'paste', | ||
| 212 | + 'plainpaste', 'wordpaste', 'justifyleft', 'justifycenter', 'justifyright', | ||
| 213 | + 'justifyfull', 'insertorderedlist', 'insertunorderedlist', 'indent', 'outdent', 'subscript', | ||
| 214 | + 'superscript', 'clearhtml', 'quickformat', 'selectall', | ||
| 215 | + 'formatblock', 'fontname', 'fontsize', 'forecolor', 'hilitecolor', 'bold', | ||
| 216 | + 'italic', 'underline', 'strikethrough', 'lineheight', 'removeformat', 'image', 'multiimage', 'graft', | ||
| 217 | + 'flash', 'media', 'insertfile', 'table', 'hr', 'emoticons', 'baidumap', 'pagebreak', | ||
| 218 | + 'anchor', 'link', 'unlink', 'remoteimage', 'about', 'fullscreen' | ||
| 219 | + ], | ||
| 220 | + afterCreate: function () { | ||
| 221 | + var self = this; | ||
| 222 | + //Ctrl+回车提交 | ||
| 223 | + Nkeditor.ctrl(document, 13, function () { | ||
| 224 | + self.sync(); | ||
| 225 | + $(that).closest("form").submit(); | ||
| 226 | + }); | ||
| 227 | + Nkeditor.ctrl(self.edit.doc, 13, function () { | ||
| 228 | + self.sync(); | ||
| 229 | + $(that).closest("form").submit(); | ||
| 230 | + }); | ||
| 231 | + //粘贴上传 | ||
| 232 | + $("body", self.edit.doc).bind('paste', function (event) { | ||
| 233 | + var image, pasteEvent; | ||
| 234 | + pasteEvent = event.originalEvent; | ||
| 235 | + if (pasteEvent.clipboardData && pasteEvent.clipboardData.items) { | ||
| 236 | + image = getImageFromClipboard(pasteEvent); | ||
| 237 | + if (image) { | ||
| 238 | + event.preventDefault(); | ||
| 239 | + Upload.api.send(image, function (data) { | ||
| 240 | + self.exec("insertimage", Fast.api.cdnurl(data.url)); | ||
| 241 | + }); | ||
| 242 | + } | ||
| 243 | + } | ||
| 244 | + }); | ||
| 245 | + //挺拽上传 | ||
| 246 | + $("body", self.edit.doc).bind('drop', function (event) { | ||
| 247 | + var image, pasteEvent; | ||
| 248 | + pasteEvent = event.originalEvent; | ||
| 249 | + if (pasteEvent.dataTransfer && pasteEvent.dataTransfer.files) { | ||
| 250 | + images = getImageFromDrop(pasteEvent); | ||
| 251 | + if (images.length > 0) { | ||
| 252 | + event.preventDefault(); | ||
| 253 | + $.each(images, function (i, image) { | ||
| 254 | + Upload.api.send(image, function (data) { | ||
| 255 | + self.exec("insertimage", Fast.api.cdnurl(data.url)); | ||
| 256 | + }); | ||
| 257 | + }); | ||
| 258 | + } | ||
| 259 | + } | ||
| 260 | + }); | ||
| 261 | + }, | ||
| 262 | + //FastAdmin自定义处理 | ||
| 263 | + beforeUpload: function (callback, file) { | ||
| 264 | + var file = file ? file : $("input.ke-upload-file", this.form).prop('files')[0]; | ||
| 265 | + Upload.api.send(file, function (data) { | ||
| 266 | + var data = {code: '000', data: {url: Fast.api.cdnurl(data.url)}, title: '', width: '', height: '', border: '', align: ''}; | ||
| 267 | + callback(data); | ||
| 268 | + }); | ||
| 269 | + | ||
| 270 | + }, | ||
| 271 | + //错误处理 handler | ||
| 272 | + errorMsgHandler: function (message, type) { | ||
| 273 | + try { | ||
| 274 | + console.log(message, type); | ||
| 275 | + } catch (Error) { | ||
| 276 | + alert(message); | ||
| 277 | + } | ||
| 278 | + } | ||
| 279 | + }); | ||
| 280 | + }); | ||
| 281 | + }); | ||
| 282 | + } | ||
| 283 | + } | ||
| 284 | +}); |
addons/nkeditor/config.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +return [ | ||
| 4 | + [ | ||
| 5 | + //配置唯一标识 | ||
| 6 | + 'name' => 'theme', | ||
| 7 | + //显示的标题 | ||
| 8 | + 'title' => '编辑器主题', | ||
| 9 | + //类型 | ||
| 10 | + 'type' => 'select', | ||
| 11 | + //数据字典 | ||
| 12 | + 'content' => [ | ||
| 13 | + 'default' => '经典主题', | ||
| 14 | + 'black' => '雅黑主题', | ||
| 15 | + 'blue' => '淡蓝主题', | ||
| 16 | + 'grey' => '深灰主题', | ||
| 17 | + 'primary' => '深绿主题', | ||
| 18 | + ], | ||
| 19 | + //值 | ||
| 20 | + 'value' => 'black', | ||
| 21 | + //验证规则 | ||
| 22 | + 'rule' => 'required', | ||
| 23 | + //错误消息 | ||
| 24 | + 'msg' => '', | ||
| 25 | + //提示消息 | ||
| 26 | + 'tip' => '', | ||
| 27 | + //成功消息 | ||
| 28 | + 'ok' => '', | ||
| 29 | + //扩展信息 | ||
| 30 | + 'extend' => '' | ||
| 31 | + ], | ||
| 32 | + [ | ||
| 33 | + 'name' => 'wordimageserver', | ||
| 34 | + 'title' => '启用word图片替换服务器', | ||
| 35 | + 'type' => 'radio', | ||
| 36 | + 'content' => [ | ||
| 37 | + '1' => '是', | ||
| 38 | + '0' => '否', | ||
| 39 | + ], | ||
| 40 | + 'value' => '0', | ||
| 41 | + 'rule' => 'required', | ||
| 42 | + 'msg' => '', | ||
| 43 | + 'tip' => '如果启用,请务必先运行word.exe', | ||
| 44 | + 'ok' => '', | ||
| 45 | + 'extend' => '' | ||
| 46 | + ], | ||
| 47 | + [ | ||
| 48 | + 'name' => 'attachmentmode_admin', | ||
| 49 | + 'title' => '管理员附件选择模式', | ||
| 50 | + 'type' => 'select', | ||
| 51 | + 'content' => [ | ||
| 52 | + 'all' => '任何管理员均可以查看全部上传的文件', | ||
| 53 | + 'auth' => '仅可以查看自己及所有子管理员上传的文件', | ||
| 54 | + 'personal' => '仅可以查看选择自己上传的文件', | ||
| 55 | + ], | ||
| 56 | + 'value' => 'all', | ||
| 57 | + 'rule' => 'required', | ||
| 58 | + 'msg' => '', | ||
| 59 | + 'tip' => '', | ||
| 60 | + 'ok' => '', | ||
| 61 | + 'extend' => '' | ||
| 62 | + ], | ||
| 63 | + [ | ||
| 64 | + 'name' => 'attachmentmode_index', | ||
| 65 | + 'title' => '后台附件选择模式', | ||
| 66 | + 'type' => 'select', | ||
| 67 | + 'content' => [ | ||
| 68 | + 'all' => '任何会员均可以查看全部上传的文件', | ||
| 69 | + 'personal' => '仅可以查看选择自己上传的文件', | ||
| 70 | + ], | ||
| 71 | + 'value' => 'all', | ||
| 72 | + 'rule' => 'required', | ||
| 73 | + 'msg' => '', | ||
| 74 | + 'tip' => '', | ||
| 75 | + 'ok' => '', | ||
| 76 | + 'extend' => '' | ||
| 77 | + ], | ||
| 78 | +]; |
addons/nkeditor/controller/Index.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace addons\nkeditor\controller; | ||
| 4 | + | ||
| 5 | +use app\common\model\Attachment; | ||
| 6 | +use GuzzleHttp\Client; | ||
| 7 | +use think\addons\Controller; | ||
| 8 | + | ||
| 9 | +class Index extends Controller | ||
| 10 | +{ | ||
| 11 | + | ||
| 12 | + public function index() | ||
| 13 | + { | ||
| 14 | + $this->error('该插件暂无前台页面'); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + /** | ||
| 18 | + * 文件列表 | ||
| 19 | + */ | ||
| 20 | + public function attachment() | ||
| 21 | + { | ||
| 22 | + $model = new Attachment; | ||
| 23 | + $page = $this->request->request('page'); | ||
| 24 | + $fileType = $this->request->request('fileType'); | ||
| 25 | + $module = $this->request->param('module'); | ||
| 26 | + $pagesize = 15; | ||
| 27 | + $config = get_addon_config('nkeditor'); | ||
| 28 | + $type = []; | ||
| 29 | + $imageSuffix = ['png', 'jpg', 'jpeg', 'gif', 'bmp', 'webp']; | ||
| 30 | + if ($fileType == 'image') { | ||
| 31 | + $type = $imageSuffix; | ||
| 32 | + } else if ($fileType == 'flash') { | ||
| 33 | + $type = ['swf', 'flv']; | ||
| 34 | + } else if ($fileType == 'media') { | ||
| 35 | + $type = ['swf', 'flv', 'mp4', 'mpeg', 'mp3', 'wav', 'ogg', 'acc', 'webm']; | ||
| 36 | + } else if ($fileType == 'file') { | ||
| 37 | + | ||
| 38 | + } | ||
| 39 | + if ($module == 'admin') { | ||
| 40 | + $auth = \app\admin\library\Auth::instance(); | ||
| 41 | + if (!$auth->id) { | ||
| 42 | + $this->error('请登录后再操作!'); | ||
| 43 | + } else { | ||
| 44 | + $mode = $config['attachmentmode_admin']; | ||
| 45 | + } | ||
| 46 | + if ($mode == 'all') { | ||
| 47 | + | ||
| 48 | + } else { | ||
| 49 | + if (!$auth->isSuperAdmin()) { | ||
| 50 | + $adminIds = $mode == 'auth' ? $auth->getChildrenAdminIds(true) : [$auth->id]; | ||
| 51 | + $model->where('admin_id', 'in', $adminIds); | ||
| 52 | + } | ||
| 53 | + } | ||
| 54 | + } else { | ||
| 55 | + if (!$this->auth->id) { | ||
| 56 | + $this->error('请登录后再操作!'); | ||
| 57 | + } else { | ||
| 58 | + $mode = $config['attachmentmode_index']; | ||
| 59 | + } | ||
| 60 | + if ($mode == 'all') { | ||
| 61 | + | ||
| 62 | + } else { | ||
| 63 | + $model->where('user_id', 'in', [$this->auth->id]); | ||
| 64 | + } | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + if ($type) { | ||
| 68 | + $model->where('imagetype', 'in', $type); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + $list = $model | ||
| 72 | + ->order('id', 'desc') | ||
| 73 | + ->paginate($pagesize); | ||
| 74 | + | ||
| 75 | + $items = $list->items(); | ||
| 76 | + $data = []; | ||
| 77 | + foreach ($items as $k => &$v) { | ||
| 78 | + $v['imagetype'] = strtolower($v['imagetype']); | ||
| 79 | + $v['fullurl'] = cdnurl($v['url'], true); | ||
| 80 | + $data[] = [ | ||
| 81 | + 'width' => $v['imagewidth'], | ||
| 82 | + 'height' => $v['imageheight'], | ||
| 83 | + 'filesize' => $v['filesize'], | ||
| 84 | + 'oriURL' => $v['fullurl'], | ||
| 85 | + 'thumbURL' => !in_array($v['imagetype'], $imageSuffix) ? "https://tool.fastadmin.net/icon/{$v['imagetype']}.png" : $v['fullurl'], | ||
| 86 | + ]; | ||
| 87 | + } | ||
| 88 | + $result = [ | ||
| 89 | + 'code' => '000', | ||
| 90 | + 'count' => $list->total(), | ||
| 91 | + 'page' => $page, | ||
| 92 | + 'pagesize' => $pagesize, | ||
| 93 | + 'extra' => '', | ||
| 94 | + 'data' => $data | ||
| 95 | + ]; | ||
| 96 | + return json($result); | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public function download() | ||
| 100 | + { | ||
| 101 | + $url = $this->request->request("url"); | ||
| 102 | + $client = new Client(); | ||
| 103 | + $response = $client->get($url, ['verify' => false]); | ||
| 104 | + return $response->getBody(); | ||
| 105 | + } | ||
| 106 | + | ||
| 107 | +} |
addons/nkeditor/info.ini
0 → 100644
addons/nkeditor/license.txt
0 → 100644
| 1 | + GNU LESSER GENERAL PUBLIC LICENSE | ||
| 2 | + Version 2.1, February 1999 | ||
| 3 | + | ||
| 4 | + Copyright (C) 1991, 1999 Free Software Foundation, Inc. | ||
| 5 | + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 6 | + Everyone is permitted to copy and distribute verbatim copies | ||
| 7 | + of this license document, but changing it is not allowed. | ||
| 8 | + | ||
| 9 | +[This is the first released version of the Lesser GPL. It also counts | ||
| 10 | + as the successor of the GNU Library Public License, version 2, hence | ||
| 11 | + the version number 2.1.] | ||
| 12 | + | ||
| 13 | + Preamble | ||
| 14 | + | ||
| 15 | + The licenses for most software are designed to take away your | ||
| 16 | +freedom to share and change it. By contrast, the GNU General Public | ||
| 17 | +Licenses are intended to guarantee your freedom to share and change | ||
| 18 | +free software--to make sure the software is free for all its users. | ||
| 19 | + | ||
| 20 | + This license, the Lesser General Public License, applies to some | ||
| 21 | +specially designated software packages--typically libraries--of the | ||
| 22 | +Free Software Foundation and other authors who decide to use it. You | ||
| 23 | +can use it too, but we suggest you first think carefully about whether | ||
| 24 | +this license or the ordinary General Public License is the better | ||
| 25 | +strategy to use in any particular case, based on the explanations below. | ||
| 26 | + | ||
| 27 | + When we speak of free software, we are referring to freedom of use, | ||
| 28 | +not price. Our General Public Licenses are designed to make sure that | ||
| 29 | +you have the freedom to distribute copies of free software (and charge | ||
| 30 | +for this service if you wish); that you receive source code or can get | ||
| 31 | +it if you want it; that you can change the software and use pieces of | ||
| 32 | +it in new free programs; and that you are informed that you can do | ||
| 33 | +these things. | ||
| 34 | + | ||
| 35 | + To protect your rights, we need to make restrictions that forbid | ||
| 36 | +distributors to deny you these rights or to ask you to surrender these | ||
| 37 | +rights. These restrictions translate to certain responsibilities for | ||
| 38 | +you if you distribute copies of the library or if you modify it. | ||
| 39 | + | ||
| 40 | + For example, if you distribute copies of the library, whether gratis | ||
| 41 | +or for a fee, you must give the recipients all the rights that we gave | ||
| 42 | +you. You must make sure that they, too, receive or can get the source | ||
| 43 | +code. If you link other code with the library, you must provide | ||
| 44 | +complete object files to the recipients, so that they can relink them | ||
| 45 | +with the library after making changes to the library and recompiling | ||
| 46 | +it. And you must show them these terms so they know their rights. | ||
| 47 | + | ||
| 48 | + We protect your rights with a two-step method: (1) we copyright the | ||
| 49 | +library, and (2) we offer you this license, which gives you legal | ||
| 50 | +permission to copy, distribute and/or modify the library. | ||
| 51 | + | ||
| 52 | + To protect each distributor, we want to make it very clear that | ||
| 53 | +there is no warranty for the free library. Also, if the library is | ||
| 54 | +modified by someone else and passed on, the recipients should know | ||
| 55 | +that what they have is not the original version, so that the original | ||
| 56 | +author's reputation will not be affected by problems that might be | ||
| 57 | +introduced by others. | ||
| 58 | + | ||
| 59 | + Finally, software patents pose a constant threat to the existence of | ||
| 60 | +any free program. We wish to make sure that a company cannot | ||
| 61 | +effectively restrict the users of a free program by obtaining a | ||
| 62 | +restrictive license from a patent holder. Therefore, we insist that | ||
| 63 | +any patent license obtained for a version of the library must be | ||
| 64 | +consistent with the full freedom of use specified in this license. | ||
| 65 | + | ||
| 66 | + Most GNU software, including some libraries, is covered by the | ||
| 67 | +ordinary GNU General Public License. This license, the GNU Lesser | ||
| 68 | +General Public License, applies to certain designated libraries, and | ||
| 69 | +is quite different from the ordinary General Public License. We use | ||
| 70 | +this license for certain libraries in order to permit linking those | ||
| 71 | +libraries into non-free programs. | ||
| 72 | + | ||
| 73 | + When a program is linked with a library, whether statically or using | ||
| 74 | +a shared library, the combination of the two is legally speaking a | ||
| 75 | +combined work, a derivative of the original library. The ordinary | ||
| 76 | +General Public License therefore permits such linking only if the | ||
| 77 | +entire combination fits its criteria of freedom. The Lesser General | ||
| 78 | +Public License permits more lax criteria for linking other code with | ||
| 79 | +the library. | ||
| 80 | + | ||
| 81 | + We call this license the "Lesser" General Public License because it | ||
| 82 | +does Less to protect the user's freedom than the ordinary General | ||
| 83 | +Public License. It also provides other free software developers Less | ||
| 84 | +of an advantage over competing non-free programs. These disadvantages | ||
| 85 | +are the reason we use the ordinary General Public License for many | ||
| 86 | +libraries. However, the Lesser license provides advantages in certain | ||
| 87 | +special circumstances. | ||
| 88 | + | ||
| 89 | + For example, on rare occasions, there may be a special need to | ||
| 90 | +encourage the widest possible use of a certain library, so that it becomes | ||
| 91 | +a de-facto standard. To achieve this, non-free programs must be | ||
| 92 | +allowed to use the library. A more frequent case is that a free | ||
| 93 | +library does the same job as widely used non-free libraries. In this | ||
| 94 | +case, there is little to gain by limiting the free library to free | ||
| 95 | +software only, so we use the Lesser General Public License. | ||
| 96 | + | ||
| 97 | + In other cases, permission to use a particular library in non-free | ||
| 98 | +programs enables a greater number of people to use a large body of | ||
| 99 | +free software. For example, permission to use the GNU C Library in | ||
| 100 | +non-free programs enables many more people to use the whole GNU | ||
| 101 | +operating system, as well as its variant, the GNU/Linux operating | ||
| 102 | +system. | ||
| 103 | + | ||
| 104 | + Although the Lesser General Public License is Less protective of the | ||
| 105 | +users' freedom, it does ensure that the user of a program that is | ||
| 106 | +linked with the Library has the freedom and the wherewithal to run | ||
| 107 | +that program using a modified version of the Library. | ||
| 108 | + | ||
| 109 | + The precise terms and conditions for copying, distribution and | ||
| 110 | +modification follow. Pay close attention to the difference between a | ||
| 111 | +"work based on the library" and a "work that uses the library". The | ||
| 112 | +former contains code derived from the library, whereas the latter must | ||
| 113 | +be combined with the library in order to run. | ||
| 114 | + | ||
| 115 | + GNU LESSER GENERAL PUBLIC LICENSE | ||
| 116 | + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||
| 117 | + | ||
| 118 | + 0. This License Agreement applies to any software library or other | ||
| 119 | +program which contains a notice placed by the copyright holder or | ||
| 120 | +other authorized party saying it may be distributed under the terms of | ||
| 121 | +this Lesser General Public License (also called "this License"). | ||
| 122 | +Each licensee is addressed as "you". | ||
| 123 | + | ||
| 124 | + A "library" means a collection of software functions and/or data | ||
| 125 | +prepared so as to be conveniently linked with application programs | ||
| 126 | +(which use some of those functions and data) to form executables. | ||
| 127 | + | ||
| 128 | + The "Library", below, refers to any such software library or work | ||
| 129 | +which has been distributed under these terms. A "work based on the | ||
| 130 | +Library" means either the Library or any derivative work under | ||
| 131 | +copyright law: that is to say, a work containing the Library or a | ||
| 132 | +portion of it, either verbatim or with modifications and/or translated | ||
| 133 | +straightforwardly into another language. (Hereinafter, translation is | ||
| 134 | +included without limitation in the term "modification".) | ||
| 135 | + | ||
| 136 | + "Source code" for a work means the preferred form of the work for | ||
| 137 | +making modifications to it. For a library, complete source code means | ||
| 138 | +all the source code for all modules it contains, plus any associated | ||
| 139 | +interface definition files, plus the scripts used to control compilation | ||
| 140 | +and installation of the library. | ||
| 141 | + | ||
| 142 | + Activities other than copying, distribution and modification are not | ||
| 143 | +covered by this License; they are outside its scope. The act of | ||
| 144 | +running a program using the Library is not restricted, and output from | ||
| 145 | +such a program is covered only if its contents constitute a work based | ||
| 146 | +on the Library (independent of the use of the Library in a tool for | ||
| 147 | +writing it). Whether that is true depends on what the Library does | ||
| 148 | +and what the program that uses the Library does. | ||
| 149 | + | ||
| 150 | + 1. You may copy and distribute verbatim copies of the Library's | ||
| 151 | +complete source code as you receive it, in any medium, provided that | ||
| 152 | +you conspicuously and appropriately publish on each copy an | ||
| 153 | +appropriate copyright notice and disclaimer of warranty; keep intact | ||
| 154 | +all the notices that refer to this License and to the absence of any | ||
| 155 | +warranty; and distribute a copy of this License along with the | ||
| 156 | +Library. | ||
| 157 | + | ||
| 158 | + You may charge a fee for the physical act of transferring a copy, | ||
| 159 | +and you may at your option offer warranty protection in exchange for a | ||
| 160 | +fee. | ||
| 161 | + | ||
| 162 | + 2. You may modify your copy or copies of the Library or any portion | ||
| 163 | +of it, thus forming a work based on the Library, and copy and | ||
| 164 | +distribute such modifications or work under the terms of Section 1 | ||
| 165 | +above, provided that you also meet all of these conditions: | ||
| 166 | + | ||
| 167 | + a) The modified work must itself be a software library. | ||
| 168 | + | ||
| 169 | + b) You must cause the files modified to carry prominent notices | ||
| 170 | + stating that you changed the files and the date of any change. | ||
| 171 | + | ||
| 172 | + c) You must cause the whole of the work to be licensed at no | ||
| 173 | + charge to all third parties under the terms of this License. | ||
| 174 | + | ||
| 175 | + d) If a facility in the modified Library refers to a function or a | ||
| 176 | + table of data to be supplied by an application program that uses | ||
| 177 | + the facility, other than as an argument passed when the facility | ||
| 178 | + is invoked, then you must make a good faith effort to ensure that, | ||
| 179 | + in the event an application does not supply such function or | ||
| 180 | + table, the facility still operates, and performs whatever part of | ||
| 181 | + its purpose remains meaningful. | ||
| 182 | + | ||
| 183 | + (For example, a function in a library to compute square roots has | ||
| 184 | + a purpose that is entirely well-defined independent of the | ||
| 185 | + application. Therefore, Subsection 2d requires that any | ||
| 186 | + application-supplied function or table used by this function must | ||
| 187 | + be optional: if the application does not supply it, the square | ||
| 188 | + root function must still compute square roots.) | ||
| 189 | + | ||
| 190 | +These requirements apply to the modified work as a whole. If | ||
| 191 | +identifiable sections of that work are not derived from the Library, | ||
| 192 | +and can be reasonably considered independent and separate works in | ||
| 193 | +themselves, then this License, and its terms, do not apply to those | ||
| 194 | +sections when you distribute them as separate works. But when you | ||
| 195 | +distribute the same sections as part of a whole which is a work based | ||
| 196 | +on the Library, the distribution of the whole must be on the terms of | ||
| 197 | +this License, whose permissions for other licensees extend to the | ||
| 198 | +entire whole, and thus to each and every part regardless of who wrote | ||
| 199 | +it. | ||
| 200 | + | ||
| 201 | +Thus, it is not the intent of this section to claim rights or contest | ||
| 202 | +your rights to work written entirely by you; rather, the intent is to | ||
| 203 | +exercise the right to control the distribution of derivative or | ||
| 204 | +collective works based on the Library. | ||
| 205 | + | ||
| 206 | +In addition, mere aggregation of another work not based on the Library | ||
| 207 | +with the Library (or with a work based on the Library) on a volume of | ||
| 208 | +a storage or distribution medium does not bring the other work under | ||
| 209 | +the scope of this License. | ||
| 210 | + | ||
| 211 | + 3. You may opt to apply the terms of the ordinary GNU General Public | ||
| 212 | +License instead of this License to a given copy of the Library. To do | ||
| 213 | +this, you must alter all the notices that refer to this License, so | ||
| 214 | +that they refer to the ordinary GNU General Public License, version 2, | ||
| 215 | +instead of to this License. (If a newer version than version 2 of the | ||
| 216 | +ordinary GNU General Public License has appeared, then you can specify | ||
| 217 | +that version instead if you wish.) Do not make any other change in | ||
| 218 | +these notices. | ||
| 219 | + | ||
| 220 | + Once this change is made in a given copy, it is irreversible for | ||
| 221 | +that copy, so the ordinary GNU General Public License applies to all | ||
| 222 | +subsequent copies and derivative works made from that copy. | ||
| 223 | + | ||
| 224 | + This option is useful when you wish to copy part of the code of | ||
| 225 | +the Library into a program that is not a library. | ||
| 226 | + | ||
| 227 | + 4. You may copy and distribute the Library (or a portion or | ||
| 228 | +derivative of it, under Section 2) in object code or executable form | ||
| 229 | +under the terms of Sections 1 and 2 above provided that you accompany | ||
| 230 | +it with the complete corresponding machine-readable source code, which | ||
| 231 | +must be distributed under the terms of Sections 1 and 2 above on a | ||
| 232 | +medium customarily used for software interchange. | ||
| 233 | + | ||
| 234 | + If distribution of object code is made by offering access to copy | ||
| 235 | +from a designated place, then offering equivalent access to copy the | ||
| 236 | +source code from the same place satisfies the requirement to | ||
| 237 | +distribute the source code, even though third parties are not | ||
| 238 | +compelled to copy the source along with the object code. | ||
| 239 | + | ||
| 240 | + 5. A program that contains no derivative of any portion of the | ||
| 241 | +Library, but is designed to work with the Library by being compiled or | ||
| 242 | +linked with it, is called a "work that uses the Library". Such a | ||
| 243 | +work, in isolation, is not a derivative work of the Library, and | ||
| 244 | +therefore falls outside the scope of this License. | ||
| 245 | + | ||
| 246 | + However, linking a "work that uses the Library" with the Library | ||
| 247 | +creates an executable that is a derivative of the Library (because it | ||
| 248 | +contains portions of the Library), rather than a "work that uses the | ||
| 249 | +library". The executable is therefore covered by this License. | ||
| 250 | +Section 6 states terms for distribution of such executables. | ||
| 251 | + | ||
| 252 | + When a "work that uses the Library" uses material from a header file | ||
| 253 | +that is part of the Library, the object code for the work may be a | ||
| 254 | +derivative work of the Library even though the source code is not. | ||
| 255 | +Whether this is true is especially significant if the work can be | ||
| 256 | +linked without the Library, or if the work is itself a library. The | ||
| 257 | +threshold for this to be true is not precisely defined by law. | ||
| 258 | + | ||
| 259 | + If such an object file uses only numerical parameters, data | ||
| 260 | +structure layouts and accessors, and small macros and small inline | ||
| 261 | +functions (ten lines or less in length), then the use of the object | ||
| 262 | +file is unrestricted, regardless of whether it is legally a derivative | ||
| 263 | +work. (Executables containing this object code plus portions of the | ||
| 264 | +Library will still fall under Section 6.) | ||
| 265 | + | ||
| 266 | + Otherwise, if the work is a derivative of the Library, you may | ||
| 267 | +distribute the object code for the work under the terms of Section 6. | ||
| 268 | +Any executables containing that work also fall under Section 6, | ||
| 269 | +whether or not they are linked directly with the Library itself. | ||
| 270 | + | ||
| 271 | + 6. As an exception to the Sections above, you may also combine or | ||
| 272 | +link a "work that uses the Library" with the Library to produce a | ||
| 273 | +work containing portions of the Library, and distribute that work | ||
| 274 | +under terms of your choice, provided that the terms permit | ||
| 275 | +modification of the work for the customer's own use and reverse | ||
| 276 | +engineering for debugging such modifications. | ||
| 277 | + | ||
| 278 | + You must give prominent notice with each copy of the work that the | ||
| 279 | +Library is used in it and that the Library and its use are covered by | ||
| 280 | +this License. You must supply a copy of this License. If the work | ||
| 281 | +during execution displays copyright notices, you must include the | ||
| 282 | +copyright notice for the Library among them, as well as a reference | ||
| 283 | +directing the user to the copy of this License. Also, you must do one | ||
| 284 | +of these things: | ||
| 285 | + | ||
| 286 | + a) Accompany the work with the complete corresponding | ||
| 287 | + machine-readable source code for the Library including whatever | ||
| 288 | + changes were used in the work (which must be distributed under | ||
| 289 | + Sections 1 and 2 above); and, if the work is an executable linked | ||
| 290 | + with the Library, with the complete machine-readable "work that | ||
| 291 | + uses the Library", as object code and/or source code, so that the | ||
| 292 | + user can modify the Library and then relink to produce a modified | ||
| 293 | + executable containing the modified Library. (It is understood | ||
| 294 | + that the user who changes the contents of definitions files in the | ||
| 295 | + Library will not necessarily be able to recompile the application | ||
| 296 | + to use the modified definitions.) | ||
| 297 | + | ||
| 298 | + b) Use a suitable shared library mechanism for linking with the | ||
| 299 | + Library. A suitable mechanism is one that (1) uses at run time a | ||
| 300 | + copy of the library already present on the user's computer system, | ||
| 301 | + rather than copying library functions into the executable, and (2) | ||
| 302 | + will operate properly with a modified version of the library, if | ||
| 303 | + the user installs one, as long as the modified version is | ||
| 304 | + interface-compatible with the version that the work was made with. | ||
| 305 | + | ||
| 306 | + c) Accompany the work with a written offer, valid for at | ||
| 307 | + least three years, to give the same user the materials | ||
| 308 | + specified in Subsection 6a, above, for a charge no more | ||
| 309 | + than the cost of performing this distribution. | ||
| 310 | + | ||
| 311 | + d) If distribution of the work is made by offering access to copy | ||
| 312 | + from a designated place, offer equivalent access to copy the above | ||
| 313 | + specified materials from the same place. | ||
| 314 | + | ||
| 315 | + e) Verify that the user has already received a copy of these | ||
| 316 | + materials or that you have already sent this user a copy. | ||
| 317 | + | ||
| 318 | + For an executable, the required form of the "work that uses the | ||
| 319 | +Library" must include any data and utility programs needed for | ||
| 320 | +reproducing the executable from it. However, as a special exception, | ||
| 321 | +the materials to be distributed need not include anything that is | ||
| 322 | +normally distributed (in either source or binary form) with the major | ||
| 323 | +components (compiler, kernel, and so on) of the operating system on | ||
| 324 | +which the executable runs, unless that component itself accompanies | ||
| 325 | +the executable. | ||
| 326 | + | ||
| 327 | + It may happen that this requirement contradicts the license | ||
| 328 | +restrictions of other proprietary libraries that do not normally | ||
| 329 | +accompany the operating system. Such a contradiction means you cannot | ||
| 330 | +use both them and the Library together in an executable that you | ||
| 331 | +distribute. | ||
| 332 | + | ||
| 333 | + 7. You may place library facilities that are a work based on the | ||
| 334 | +Library side-by-side in a single library together with other library | ||
| 335 | +facilities not covered by this License, and distribute such a combined | ||
| 336 | +library, provided that the separate distribution of the work based on | ||
| 337 | +the Library and of the other library facilities is otherwise | ||
| 338 | +permitted, and provided that you do these two things: | ||
| 339 | + | ||
| 340 | + a) Accompany the combined library with a copy of the same work | ||
| 341 | + based on the Library, uncombined with any other library | ||
| 342 | + facilities. This must be distributed under the terms of the | ||
| 343 | + Sections above. | ||
| 344 | + | ||
| 345 | + b) Give prominent notice with the combined library of the fact | ||
| 346 | + that part of it is a work based on the Library, and explaining | ||
| 347 | + where to find the accompanying uncombined form of the same work. | ||
| 348 | + | ||
| 349 | + 8. You may not copy, modify, sublicense, link with, or distribute | ||
| 350 | +the Library except as expressly provided under this License. Any | ||
| 351 | +attempt otherwise to copy, modify, sublicense, link with, or | ||
| 352 | +distribute the Library is void, and will automatically terminate your | ||
| 353 | +rights under this License. However, parties who have received copies, | ||
| 354 | +or rights, from you under this License will not have their licenses | ||
| 355 | +terminated so long as such parties remain in full compliance. | ||
| 356 | + | ||
| 357 | + 9. You are not required to accept this License, since you have not | ||
| 358 | +signed it. However, nothing else grants you permission to modify or | ||
| 359 | +distribute the Library or its derivative works. These actions are | ||
| 360 | +prohibited by law if you do not accept this License. Therefore, by | ||
| 361 | +modifying or distributing the Library (or any work based on the | ||
| 362 | +Library), you indicate your acceptance of this License to do so, and | ||
| 363 | +all its terms and conditions for copying, distributing or modifying | ||
| 364 | +the Library or works based on it. | ||
| 365 | + | ||
| 366 | + 10. Each time you redistribute the Library (or any work based on the | ||
| 367 | +Library), the recipient automatically receives a license from the | ||
| 368 | +original licensor to copy, distribute, link with or modify the Library | ||
| 369 | +subject to these terms and conditions. You may not impose any further | ||
| 370 | +restrictions on the recipients' exercise of the rights granted herein. | ||
| 371 | +You are not responsible for enforcing compliance by third parties with | ||
| 372 | +this License. | ||
| 373 | + | ||
| 374 | + 11. If, as a consequence of a court judgment or allegation of patent | ||
| 375 | +infringement or for any other reason (not limited to patent issues), | ||
| 376 | +conditions are imposed on you (whether by court order, agreement or | ||
| 377 | +otherwise) that contradict the conditions of this License, they do not | ||
| 378 | +excuse you from the conditions of this License. If you cannot | ||
| 379 | +distribute so as to satisfy simultaneously your obligations under this | ||
| 380 | +License and any other pertinent obligations, then as a consequence you | ||
| 381 | +may not distribute the Library at all. For example, if a patent | ||
| 382 | +license would not permit royalty-free redistribution of the Library by | ||
| 383 | +all those who receive copies directly or indirectly through you, then | ||
| 384 | +the only way you could satisfy both it and this License would be to | ||
| 385 | +refrain entirely from distribution of the Library. | ||
| 386 | + | ||
| 387 | +If any portion of this section is held invalid or unenforceable under any | ||
| 388 | +particular circumstance, the balance of the section is intended to apply, | ||
| 389 | +and the section as a whole is intended to apply in other circumstances. | ||
| 390 | + | ||
| 391 | +It is not the purpose of this section to induce you to infringe any | ||
| 392 | +patents or other property right claims or to contest validity of any | ||
| 393 | +such claims; this section has the sole purpose of protecting the | ||
| 394 | +integrity of the free software distribution system which is | ||
| 395 | +implemented by public license practices. Many people have made | ||
| 396 | +generous contributions to the wide range of software distributed | ||
| 397 | +through that system in reliance on consistent application of that | ||
| 398 | +system; it is up to the author/donor to decide if he or she is willing | ||
| 399 | +to distribute software through any other system and a licensee cannot | ||
| 400 | +impose that choice. | ||
| 401 | + | ||
| 402 | +This section is intended to make thoroughly clear what is believed to | ||
| 403 | +be a consequence of the rest of this License. | ||
| 404 | + | ||
| 405 | + 12. If the distribution and/or use of the Library is restricted in | ||
| 406 | +certain countries either by patents or by copyrighted interfaces, the | ||
| 407 | +original copyright holder who places the Library under this License may add | ||
| 408 | +an explicit geographical distribution limitation excluding those countries, | ||
| 409 | +so that distribution is permitted only in or among countries not thus | ||
| 410 | +excluded. In such case, this License incorporates the limitation as if | ||
| 411 | +written in the body of this License. | ||
| 412 | + | ||
| 413 | + 13. The Free Software Foundation may publish revised and/or new | ||
| 414 | +versions of the Lesser General Public License from time to time. | ||
| 415 | +Such new versions will be similar in spirit to the present version, | ||
| 416 | +but may differ in detail to address new problems or concerns. | ||
| 417 | + | ||
| 418 | +Each version is given a distinguishing version number. If the Library | ||
| 419 | +specifies a version number of this License which applies to it and | ||
| 420 | +"any later version", you have the option of following the terms and | ||
| 421 | +conditions either of that version or of any later version published by | ||
| 422 | +the Free Software Foundation. If the Library does not specify a | ||
| 423 | +license version number, you may choose any version ever published by | ||
| 424 | +the Free Software Foundation. | ||
| 425 | + | ||
| 426 | + 14. If you wish to incorporate parts of the Library into other free | ||
| 427 | +programs whose distribution conditions are incompatible with these, | ||
| 428 | +write to the author to ask for permission. For software which is | ||
| 429 | +copyrighted by the Free Software Foundation, write to the Free | ||
| 430 | +Software Foundation; we sometimes make exceptions for this. Our | ||
| 431 | +decision will be guided by the two goals of preserving the free status | ||
| 432 | +of all derivatives of our free software and of promoting the sharing | ||
| 433 | +and reuse of software generally. | ||
| 434 | + | ||
| 435 | + NO WARRANTY | ||
| 436 | + | ||
| 437 | + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO | ||
| 438 | +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. | ||
| 439 | +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR | ||
| 440 | +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY | ||
| 441 | +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 442 | +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 443 | +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE | ||
| 444 | +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME | ||
| 445 | +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. | ||
| 446 | + | ||
| 447 | + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN | ||
| 448 | +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY | ||
| 449 | +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU | ||
| 450 | +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR | ||
| 451 | +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE | ||
| 452 | +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING | ||
| 453 | +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A | ||
| 454 | +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF | ||
| 455 | +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH | ||
| 456 | +DAMAGES. | ||
| 457 | + | ||
| 458 | + END OF TERMS AND CONDITIONS | ||
| 459 | + | ||
| 460 | + How to Apply These Terms to Your New Libraries | ||
| 461 | + | ||
| 462 | + If you develop a new library, and you want it to be of the greatest | ||
| 463 | +possible use to the public, we recommend making it free software that | ||
| 464 | +everyone can redistribute and change. You can do so by permitting | ||
| 465 | +redistribution under these terms (or, alternatively, under the terms of the | ||
| 466 | +ordinary General Public License). | ||
| 467 | + | ||
| 468 | + To apply these terms, attach the following notices to the library. It is | ||
| 469 | +safest to attach them to the start of each source file to most effectively | ||
| 470 | +convey the exclusion of warranty; and each file should have at least the | ||
| 471 | +"copyright" line and a pointer to where the full notice is found. | ||
| 472 | + | ||
| 473 | + <one line to give the library's name and a brief idea of what it does.> | ||
| 474 | + Copyright (C) <year> <name of author> | ||
| 475 | + | ||
| 476 | + This library is free software; you can redistribute it and/or | ||
| 477 | + modify it under the terms of the GNU Lesser General Public | ||
| 478 | + License as published by the Free Software Foundation; either | ||
| 479 | + version 2.1 of the License, or (at your option) any later version. | ||
| 480 | + | ||
| 481 | + This library is distributed in the hope that it will be useful, | ||
| 482 | + but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 483 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 484 | + Lesser General Public License for more details. | ||
| 485 | + | ||
| 486 | + You should have received a copy of the GNU Lesser General Public | ||
| 487 | + License along with this library; if not, write to the Free Software | ||
| 488 | + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 489 | + | ||
| 490 | +Also add information on how to contact you by electronic and paper mail. | ||
| 491 | + | ||
| 492 | +You should also get your employer (if you work as a programmer) or your | ||
| 493 | +school, if any, to sign a "copyright disclaimer" for the library, if | ||
| 494 | +necessary. Here is a sample; alter the names: | ||
| 495 | + | ||
| 496 | + Yoyodyne, Inc., hereby disclaims all copyright interest in the | ||
| 497 | + library `Frob' (a library for tweaking knobs) written by James Random Hacker. | ||
| 498 | + | ||
| 499 | + <signature of Ty Coon>, 1 April 1990 | ||
| 500 | + Ty Coon, President of Vice | ||
| 501 | + | ||
| 502 | +That's all there is to it! |
addons/nkeditor/nodejs/word.js
0 → 100644
| 1 | +/** | ||
| 2 | + * 代码来源:http://www.thinkphp.cn/topic/27567.html | ||
| 3 | + * 如需编译请使用 pkg -t node12-win word.js 命令编译成word.exe文件 | ||
| 4 | + */ | ||
| 5 | +var service = { | ||
| 6 | + http: require('http'), | ||
| 7 | + url: require('url'), | ||
| 8 | + querystring: require('querystring'), | ||
| 9 | + fs: require('fs'), | ||
| 10 | + config: { | ||
| 11 | + timeout: 60000, | ||
| 12 | + charset: 'utf8', | ||
| 13 | + port: 10101, | ||
| 14 | + host: '127.0.0.1' | ||
| 15 | + }, | ||
| 16 | + router: { | ||
| 17 | + index: function (res, query) { | ||
| 18 | + res.end('Server is running!'); | ||
| 19 | + }, | ||
| 20 | + check: function (res, query) { | ||
| 21 | + var result = {status: 1, info: 'success'}; | ||
| 22 | + result = JSON.stringify(result); | ||
| 23 | + if (typeof query.callback == 'string') { | ||
| 24 | + result = query.callback + '(' + result + ')'; | ||
| 25 | + } | ||
| 26 | + res.end(result); | ||
| 27 | + }, | ||
| 28 | + word: function (res, query) { | ||
| 29 | + var _this = service; | ||
| 30 | + var result = {status: 0, info: 'error'}; | ||
| 31 | + if (typeof query.file == 'string') { | ||
| 32 | + var img = query.file.match(/file:\/\/+(localhost)?(\S+\.(png|jpg|jpeg|gif|bmp))/i); | ||
| 33 | + console.log(img); | ||
| 34 | + if (img) { | ||
| 35 | + var base64 = _this.base64_encode(img[2]); | ||
| 36 | + result.status = 1; | ||
| 37 | + result.index = query.index; | ||
| 38 | + result.info = 'data:image/' + img[3] + ';base64,' + base64; | ||
| 39 | + } | ||
| 40 | + } | ||
| 41 | + result = JSON.stringify(result); | ||
| 42 | + if (typeof query.callback == 'string') { | ||
| 43 | + result = query.callback + '(' + result + ')'; | ||
| 44 | + } | ||
| 45 | + res.end(result); | ||
| 46 | + } | ||
| 47 | + }, | ||
| 48 | + start: function () { | ||
| 49 | + var _this = this; | ||
| 50 | + var Server = _this.http.createServer(function (req, res) { | ||
| 51 | + var URL = _this.url.parse(req.url); | ||
| 52 | + var receive = []; | ||
| 53 | + var router = null; | ||
| 54 | + switch (URL.pathname) { | ||
| 55 | + case '/word': | ||
| 56 | + router = _this.router.word; | ||
| 57 | + break; | ||
| 58 | + case '/check': | ||
| 59 | + router = _this.router.check; | ||
| 60 | + break; | ||
| 61 | + default: | ||
| 62 | + router = _this.router.index; | ||
| 63 | + } | ||
| 64 | + req.setEncoding(_this.config.charset); | ||
| 65 | + req.addListener('data', function (data) { | ||
| 66 | + receive.push(data); | ||
| 67 | + }); | ||
| 68 | + res.writeHead(200, {'Content-Type': 'text/plain'}); | ||
| 69 | + res.on("close", function () { | ||
| 70 | + console.log("res closed"); | ||
| 71 | + }); | ||
| 72 | + req.on("close", function () { | ||
| 73 | + console.log("req closed"); | ||
| 74 | + }); | ||
| 75 | + req.addListener('end', function () { | ||
| 76 | + router(res, _this.querystring.parse(URL.query)); | ||
| 77 | + }); | ||
| 78 | + }); | ||
| 79 | + Server.listen(_this.config.port, _this.config.host, 1024); | ||
| 80 | + Server.setTimeout(_this.config.timeout, function (cli) { | ||
| 81 | + cli.end('timeout\n'); | ||
| 82 | + }); | ||
| 83 | + console.log('Server running at http://' + _this.config.host + ':' + _this.config.port); | ||
| 84 | + }, | ||
| 85 | + //base64 | ||
| 86 | + base64_encode: function (file) { | ||
| 87 | + var bitmap = this.fs.readFileSync(file); | ||
| 88 | + return new Buffer.from(bitmap).toString('base64'); | ||
| 89 | + } | ||
| 90 | +}; | ||
| 91 | +service.start(); |
addons/upyun/.addonrc
0 → 100644
| 1 | +{"license":"regular","licenseto":"11004","licensekey":"GZKzguNmn4DxJVfQ 92slYxZ08YDsDsCXr\/i\/gA==","files":["public\\assets\\addons\\upyun\\js\\spark.js"]} |
addons/upyun/Upyun.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace addons\upyun; | ||
| 4 | + | ||
| 5 | +use think\Addons; | ||
| 6 | +use think\Loader; | ||
| 7 | +use Upyun\Config; | ||
| 8 | +use Upyun\Signature; | ||
| 9 | +use Upyun\Upyun as UpyunClient; | ||
| 10 | +use Upyun\Util; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 又拍云上传 | ||
| 14 | + */ | ||
| 15 | +class Upyun extends Addons | ||
| 16 | +{ | ||
| 17 | + | ||
| 18 | + /** | ||
| 19 | + * 插件安装方法 | ||
| 20 | + * @return bool | ||
| 21 | + */ | ||
| 22 | + public function install() | ||
| 23 | + { | ||
| 24 | + return true; | ||
| 25 | + } | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * 插件卸载方法 | ||
| 29 | + * @return bool | ||
| 30 | + */ | ||
| 31 | + public function uninstall() | ||
| 32 | + { | ||
| 33 | + return true; | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + /** | ||
| 37 | + * 添加命名空间 | ||
| 38 | + */ | ||
| 39 | + public function appInit() | ||
| 40 | + { | ||
| 41 | + if (!class_exists('\Upyun\Upyun')) { | ||
| 42 | + //添加支付包的命名空间 | ||
| 43 | + Loader::addNamespace('Upyun', ADDON_PATH . 'upyun' . DS . 'library' . DS . 'Upyun' . DS); | ||
| 44 | + } | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * | ||
| 49 | + * @return mixed | ||
| 50 | + */ | ||
| 51 | + public function uploadConfigInit(&$upload) | ||
| 52 | + { | ||
| 53 | + $config = $this->getConfig('upyun'); | ||
| 54 | + $config = $config ? $config : []; | ||
| 55 | + $config['bucket'] = isset($config['bucket']) ? $config['bucket'] : ''; | ||
| 56 | + $multiple = isset($config['multiple']) ? $config['multiple'] : false; | ||
| 57 | + | ||
| 58 | + $params = []; | ||
| 59 | + $params['save-key'] = isset($config['savekey']) ? $config['savekey'] : ''; | ||
| 60 | + $params['bucket'] = $config['bucket']; | ||
| 61 | + $params['expiration'] = time() + (isset($config['expire']) ? $config['expire'] : 600); | ||
| 62 | + | ||
| 63 | + $cfg = new Config($config['bucket'], $config['operator'], $config['password']); | ||
| 64 | + $policy = Util::base64Json($params); | ||
| 65 | + $signature = Signature::getBodySignature($cfg, 'POST', '/' . $params['bucket'], null, $policy); | ||
| 66 | + $upyuntoken = base64_encode($signature) . ":" . $policy; | ||
| 67 | + $multipart = [ | ||
| 68 | + 'upyuntoken' => $upyuntoken, | ||
| 69 | + ]; | ||
| 70 | + | ||
| 71 | + $upload = array_merge($upload, [ | ||
| 72 | + 'cdnurl' => $config['cdnurl'], | ||
| 73 | + 'uploadurl' => $config['uploadmode'] == 'client' ? $config['uploadurl'] : addon_url('upyun/index/upload'), | ||
| 74 | + 'uploadmode' => $config['uploadmode'], | ||
| 75 | + 'bucket' => $config['bucket'], | ||
| 76 | + 'maxsize' => $config['maxsize'], | ||
| 77 | + 'mimetype' => $config['mimetype'], | ||
| 78 | + 'savekey' => $config['savekey'], | ||
| 79 | + 'chunking' => (bool)($config['chunking'] ?? $upload['chunking']), | ||
| 80 | + 'chunksize' => (int)($config['chunksize'] ?? $upload['chunksize']), | ||
| 81 | + 'multipart' => ['upyuntoken' => $upyuntoken], | ||
| 82 | + 'storage' => $this->getName(), | ||
| 83 | + 'multiple' => $config['multiple'] ? true : false, | ||
| 84 | + ]); | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + /** | ||
| 88 | + * 附件删除后 | ||
| 89 | + */ | ||
| 90 | + public function uploadDelete($attachment) | ||
| 91 | + { | ||
| 92 | + $config = $this->getConfig(); | ||
| 93 | + if ($attachment['storage'] == 'upyun' && isset($config['syncdelete']) && $config['syncdelete']) { | ||
| 94 | + $cfg = new \Upyun\Config($config['bucket'], $config['operator'], $config['password']); | ||
| 95 | + $upyun = new UpyunClient($cfg); | ||
| 96 | + //同步删除又拍云文件 | ||
| 97 | + $ret = $upyun->delete($attachment->url); | ||
| 98 | + //如果是服务端中转,还需要删除本地文件 | ||
| 99 | + if ($config['uploadmode'] == 'server') { | ||
| 100 | + $filePath = ROOT_PATH . 'public' . str_replace('/', DS, $attachment->url); | ||
| 101 | + if ($filePath) { | ||
| 102 | + @unlink($filePath); | ||
| 103 | + } | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + return true; | ||
| 107 | + } | ||
| 108 | +} |
addons/upyun/bootstrap.js
0 → 100644
| 1 | +//修改上传的接口调用 | ||
| 2 | +require(['upload', '../addons/upyun/js/spark'], function (Upload, SparkMD5) { | ||
| 3 | + //获取文件MD5值 | ||
| 4 | + var getFileMd5 = function (file, cb) { | ||
| 5 | + var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice, | ||
| 6 | + chunkSize = 2097152, | ||
| 7 | + chunks = Math.ceil(file.size / chunkSize), | ||
| 8 | + currentChunk = 0, | ||
| 9 | + spark = new SparkMD5.ArrayBuffer(), | ||
| 10 | + fileReader = new FileReader(); | ||
| 11 | + | ||
| 12 | + fileReader.onload = function (e) { | ||
| 13 | + spark.append(e.target.result); | ||
| 14 | + currentChunk++; | ||
| 15 | + if (currentChunk < chunks) { | ||
| 16 | + loadNext(); | ||
| 17 | + } else { | ||
| 18 | + cb && cb(spark.end()); | ||
| 19 | + } | ||
| 20 | + }; | ||
| 21 | + | ||
| 22 | + fileReader.onerror = function () { | ||
| 23 | + console.warn('文件读取错误'); | ||
| 24 | + }; | ||
| 25 | + | ||
| 26 | + function loadNext() { | ||
| 27 | + var start = currentChunk * chunkSize, | ||
| 28 | + end = ((start + chunkSize) >= file.size) ? file.size : start + chunkSize; | ||
| 29 | + | ||
| 30 | + fileReader.readAsArrayBuffer(blobSlice.call(file, start, end)); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + loadNext(); | ||
| 34 | + }; | ||
| 35 | + | ||
| 36 | + //初始化中完成判断 | ||
| 37 | + Upload.events.onInit = function () { | ||
| 38 | + //如果上传接口不是七牛云,则不处理 | ||
| 39 | + if (this.options.url !== Config.upload.uploadurl) { | ||
| 40 | + return; | ||
| 41 | + } | ||
| 42 | + var _success = this.options.success; | ||
| 43 | + | ||
| 44 | + $.extend(this.options, { | ||
| 45 | + //关闭自动处理队列功能 | ||
| 46 | + autoQueue: false, | ||
| 47 | + chunkSuccess: function (chunk, file, response) { | ||
| 48 | + this.etags = this.etags ? this.etags : []; | ||
| 49 | + }, | ||
| 50 | + chunksUploaded: function (file, done) { | ||
| 51 | + var that = this; | ||
| 52 | + Fast.api.ajax({ | ||
| 53 | + url: "/addons/upyun/index/upload", | ||
| 54 | + data: { | ||
| 55 | + action: 'merge', | ||
| 56 | + filesize: file.size, | ||
| 57 | + filename: file.name, | ||
| 58 | + chunkid: file.upload.uuid, | ||
| 59 | + chunkcount: file.upload.totalChunkCount, | ||
| 60 | + width: file.width || 0, | ||
| 61 | + height: file.height || 0, | ||
| 62 | + type: file.type, | ||
| 63 | + upyuntoken: Config.upload.multipart.upyuntoken, | ||
| 64 | + url: file.params.url, | ||
| 65 | + uuid: file.params.uuid, | ||
| 66 | + etags: this.etags | ||
| 67 | + }, | ||
| 68 | + }, function (data, ret) { | ||
| 69 | + done(JSON.stringify(ret)); | ||
| 70 | + return false; | ||
| 71 | + }, function (data, ret) { | ||
| 72 | + file.accepted = false; | ||
| 73 | + that._errorProcessing([file], ret.msg); | ||
| 74 | + return false; | ||
| 75 | + }); | ||
| 76 | + | ||
| 77 | + }, | ||
| 78 | + }); | ||
| 79 | + | ||
| 80 | + this.on("addedfile", function (file) { | ||
| 81 | + var that = this; | ||
| 82 | + setTimeout(function () { | ||
| 83 | + if (file.status === 'error') { | ||
| 84 | + return; | ||
| 85 | + } | ||
| 86 | + var index = Layer.load(); | ||
| 87 | + getFileMd5(file, function (md5) { | ||
| 88 | + var chunk = that.options.chunking && file.size > that.options.chunkSize ? 1 : 0; | ||
| 89 | + Fast.api.ajax({ | ||
| 90 | + url: "/addons/upyun/index/params", | ||
| 91 | + data: {method: 'POST', md5: md5, name: file.name, type: file.type, size: file.size, chunk: chunk, chunkSize: that.options.chunkSize, upyuntoken: Config.upload.multipart.upyuntoken}, | ||
| 92 | + }, function (data) { | ||
| 93 | + Layer.close(index); | ||
| 94 | + file.md5 = md5; | ||
| 95 | + file.url = data.url; | ||
| 96 | + file.headers = data.headers; | ||
| 97 | + file.params = data; | ||
| 98 | + that.options.chunkSize = data.chunkSize; | ||
| 99 | + if (file.status != 'error') { | ||
| 100 | + //开始上传 | ||
| 101 | + that.enqueueFile(file); | ||
| 102 | + } else { | ||
| 103 | + that.removeFile(file); | ||
| 104 | + } | ||
| 105 | + return false; | ||
| 106 | + }, function () { | ||
| 107 | + Layer.close(index); | ||
| 108 | + }); | ||
| 109 | + }); | ||
| 110 | + }, 0); | ||
| 111 | + }); | ||
| 112 | + | ||
| 113 | + //先移除已有的事件 | ||
| 114 | + this.off("success", _success).on("success", function (file, response) { | ||
| 115 | + var ret = {code: 0, msg: response}; | ||
| 116 | + try { | ||
| 117 | + ret = typeof response === 'string' ? (response ? JSON.parse(response) : {url: file.url}) : response; | ||
| 118 | + if (file.xhr.status === 200) { | ||
| 119 | + console.log("SUCCESS:", ret); | ||
| 120 | + if (typeof ret.url !== 'undefined' && typeof ret.data === 'undefined') { | ||
| 121 | + ret = {code: 1, msg: "", data: {url: ret.url}}; | ||
| 122 | + } | ||
| 123 | + Fast.api.ajax({ | ||
| 124 | + url: "/addons/upyun/index/notify", | ||
| 125 | + data: {name: file.name, url: ret.data.url, md5: file.md5, size: file.size, width: file.width || 0, height: file.height || 0, type: file.type, upyuntoken: Config.upload.multipart.upyuntoken} | ||
| 126 | + }, function () { | ||
| 127 | + return false; | ||
| 128 | + }, function () { | ||
| 129 | + return false; | ||
| 130 | + }); | ||
| 131 | + } | ||
| 132 | + } catch (e) { | ||
| 133 | + console.error(e); | ||
| 134 | + } | ||
| 135 | + _success.call(this, file, ret); | ||
| 136 | + }); | ||
| 137 | + | ||
| 138 | + this.options.params = function (files, xhr, chunk) { | ||
| 139 | + var params = Config.upload.multipart; | ||
| 140 | + if (chunk) { | ||
| 141 | + return $.extend({}, params, { | ||
| 142 | + filesize: chunk.file.size, | ||
| 143 | + filename: chunk.file.name, | ||
| 144 | + chunkid: chunk.file.upload.uuid, | ||
| 145 | + chunkindex: chunk.index, | ||
| 146 | + chunkcount: chunk.file.upload.totalChunkCount, | ||
| 147 | + chunkfilesize: chunk.dataBlock.data.size, | ||
| 148 | + chunksize: this.options.chunkSize, | ||
| 149 | + width: chunk.file.width || 0, | ||
| 150 | + height: chunk.file.height || 0, | ||
| 151 | + type: chunk.file.type, | ||
| 152 | + url: chunk.file.params.url || "", | ||
| 153 | + uuid: chunk.file.params.uuid || "", | ||
| 154 | + }); | ||
| 155 | + } else { | ||
| 156 | + if (Config.upload.uploadmode === 'client') { | ||
| 157 | + | ||
| 158 | + } | ||
| 159 | + } | ||
| 160 | + return params; | ||
| 161 | + }; | ||
| 162 | + | ||
| 163 | + //如果是直传模式 | ||
| 164 | + if (Config.upload.uploadmode === 'client') { | ||
| 165 | + var _url = this.options.url; | ||
| 166 | + | ||
| 167 | + //分片上传时URL链接不同 | ||
| 168 | + this.options.url = function (files) { | ||
| 169 | + if (files[0].upload.chunked) { | ||
| 170 | + var chunk = null; | ||
| 171 | + files[0].upload.chunks.forEach(function (item) { | ||
| 172 | + if (item.status === 'uploading') { | ||
| 173 | + chunk = item; | ||
| 174 | + } | ||
| 175 | + }); | ||
| 176 | + if (!chunk) { | ||
| 177 | + return Config.upload.uploadurl + files[0].url + files[0].size; | ||
| 178 | + } else { | ||
| 179 | + this.options.headers = $.extend(this.options.headers, chunk.file.headers, {"Cache-Control": null, "User-agent": null, "X-Upyun-Part-Id": chunk.index + ""}); | ||
| 180 | + return Config.upload.uploadurl + files[0].url; | ||
| 181 | + } | ||
| 182 | + } else { | ||
| 183 | + this.options.headers = $.extend(this.options.headers, files[0].headers, {"Cache-Control": null, "User-agent": null}); | ||
| 184 | + return Config.upload.uploadurl + files[0].url; | ||
| 185 | + } | ||
| 186 | + return _url; | ||
| 187 | + }; | ||
| 188 | + | ||
| 189 | + var _method = this.options.method; | ||
| 190 | + this.options.method = function (files) { | ||
| 191 | + if (files[0].upload.chunked) { | ||
| 192 | + var chunk = null; | ||
| 193 | + files[0].upload.chunks.forEach(function (item) { | ||
| 194 | + if (item.status === 'uploading') { | ||
| 195 | + chunk = item; | ||
| 196 | + } | ||
| 197 | + }); | ||
| 198 | + if (!chunk) { | ||
| 199 | + return "POST"; | ||
| 200 | + } else { | ||
| 201 | + return "PUT"; | ||
| 202 | + } | ||
| 203 | + } else { | ||
| 204 | + return "PUT"; | ||
| 205 | + } | ||
| 206 | + return _method; | ||
| 207 | + }; | ||
| 208 | + | ||
| 209 | + //分片上传时需要变更提交的内容 | ||
| 210 | + this.on("sending", function (file, xhr, formData) { | ||
| 211 | + if (true) { | ||
| 212 | + var _send = xhr.send; | ||
| 213 | + xhr.send = function () { | ||
| 214 | + if (file.upload.chunked) { | ||
| 215 | + var chunk = null; | ||
| 216 | + file.upload.chunks.forEach(function (item) { | ||
| 217 | + if (item.status == 'uploading') { | ||
| 218 | + chunk = item; | ||
| 219 | + } | ||
| 220 | + }); | ||
| 221 | + if (chunk) { | ||
| 222 | + _send.call(xhr, chunk.dataBlock.data); | ||
| 223 | + } | ||
| 224 | + } else { | ||
| 225 | + _send.call(xhr, file); | ||
| 226 | + } | ||
| 227 | + }; | ||
| 228 | + } | ||
| 229 | + }); | ||
| 230 | + } | ||
| 231 | + }; | ||
| 232 | + | ||
| 233 | +}); |
addons/upyun/config.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +return [ | ||
| 4 | + [ | ||
| 5 | + 'name' => 'bucket', | ||
| 6 | + 'title' => 'bucket', | ||
| 7 | + 'type' => 'string', | ||
| 8 | + 'content' => [], | ||
| 9 | + 'value' => 'chuangxinchuangye', | ||
| 10 | + 'rule' => 'required', | ||
| 11 | + 'msg' => '', | ||
| 12 | + 'tip' => '服务名称', | ||
| 13 | + 'ok' => '', | ||
| 14 | + 'extend' => '', | ||
| 15 | + ], | ||
| 16 | + [ | ||
| 17 | + 'name' => 'cdnurl', | ||
| 18 | + 'title' => 'CDN地址', | ||
| 19 | + 'type' => 'string', | ||
| 20 | + 'content' => [], | ||
| 21 | + 'value' => 'http://chuangxinchuangye.posedu.com.cn/', | ||
| 22 | + 'rule' => 'required', | ||
| 23 | + 'msg' => '', | ||
| 24 | + 'tip' => '回事域名', | ||
| 25 | + 'ok' => '', | ||
| 26 | + 'extend' => '', | ||
| 27 | + ], | ||
| 28 | + [ | ||
| 29 | + 'name' => 'uploadurl', | ||
| 30 | + 'title' => '上传接口地址', | ||
| 31 | + 'type' => 'string', | ||
| 32 | + 'content' => [], | ||
| 33 | + 'value' => 'http://v0.api.upyun.com/chuangxinchuangye', | ||
| 34 | + 'rule' => 'required', | ||
| 35 | + 'msg' => '', | ||
| 36 | + 'tip' => '上传接口地址', | ||
| 37 | + 'ok' => '', | ||
| 38 | + 'extend' => '', | ||
| 39 | + ], | ||
| 40 | + [ | ||
| 41 | + 'name' => 'uploadmode', | ||
| 42 | + 'title' => '上传模式', | ||
| 43 | + 'type' => 'select', | ||
| 44 | + 'content' => [ | ||
| 45 | + 'client' => '客户端直传(速度快,无备份)', | ||
| 46 | + 'server' => '服务器中转(占用服务器带宽,有备份)', | ||
| 47 | + ], | ||
| 48 | + 'value' => 'client', | ||
| 49 | + 'rule' => '', | ||
| 50 | + 'msg' => '', | ||
| 51 | + 'tip' => '启用服务器中转时务必配置操作员和密码', | ||
| 52 | + 'ok' => '', | ||
| 53 | + 'extend' => '', | ||
| 54 | + ], | ||
| 55 | + [ | ||
| 56 | + 'name' => 'savekey', | ||
| 57 | + 'title' => '保存文件名', | ||
| 58 | + 'type' => 'string', | ||
| 59 | + 'content' => [], | ||
| 60 | + 'value' => '/uploads/{year}{mon}{day}/{filemd5}{.suffix}', | ||
| 61 | + 'rule' => 'required', | ||
| 62 | + 'msg' => '', | ||
| 63 | + 'tip' => '', | ||
| 64 | + 'ok' => '', | ||
| 65 | + 'extend' => '', | ||
| 66 | + ], | ||
| 67 | + [ | ||
| 68 | + 'name' => 'expire', | ||
| 69 | + 'title' => '上传有效时长', | ||
| 70 | + 'type' => 'string', | ||
| 71 | + 'content' => [], | ||
| 72 | + 'value' => '7200', | ||
| 73 | + 'rule' => 'required', | ||
| 74 | + 'msg' => '', | ||
| 75 | + 'tip' => '', | ||
| 76 | + 'ok' => '', | ||
| 77 | + 'extend' => '', | ||
| 78 | + ], | ||
| 79 | + [ | ||
| 80 | + 'name' => 'maxsize', | ||
| 81 | + 'title' => '最大可上传', | ||
| 82 | + 'type' => 'string', | ||
| 83 | + 'content' => [], | ||
| 84 | + 'value' => '20M', | ||
| 85 | + 'rule' => 'required', | ||
| 86 | + 'msg' => '', | ||
| 87 | + 'tip' => '', | ||
| 88 | + 'ok' => '', | ||
| 89 | + 'extend' => '', | ||
| 90 | + ], | ||
| 91 | + [ | ||
| 92 | + 'name' => 'mimetype', | ||
| 93 | + 'title' => '可上传后缀格式', | ||
| 94 | + 'type' => 'string', | ||
| 95 | + 'content' => [], | ||
| 96 | + 'value' => 'jpg,png,bmp,jpeg,gif,zip,rar,xls,xlsx', | ||
| 97 | + 'rule' => 'required', | ||
| 98 | + 'msg' => '', | ||
| 99 | + 'tip' => '', | ||
| 100 | + 'ok' => '', | ||
| 101 | + 'extend' => '', | ||
| 102 | + ], | ||
| 103 | + [ | ||
| 104 | + 'name' => 'multiple', | ||
| 105 | + 'title' => '多文件上传', | ||
| 106 | + 'type' => 'radio', | ||
| 107 | + 'content' => [ | ||
| 108 | + '否', | ||
| 109 | + '是', | ||
| 110 | + ], | ||
| 111 | + 'value' => '0', | ||
| 112 | + 'rule' => 'required', | ||
| 113 | + 'msg' => '', | ||
| 114 | + 'tip' => '', | ||
| 115 | + 'ok' => '', | ||
| 116 | + 'extend' => '', | ||
| 117 | + ], | ||
| 118 | + [ | ||
| 119 | + 'name' => 'thumbstyle', | ||
| 120 | + 'title' => '缩略图样式', | ||
| 121 | + 'type' => 'string', | ||
| 122 | + 'content' => [], | ||
| 123 | + 'value' => '!/fwfh/120x90', | ||
| 124 | + 'rule' => '', | ||
| 125 | + 'msg' => '', | ||
| 126 | + 'tip' => '用于附件管理缩略图样式,可使用:!/fwfh/120x90', | ||
| 127 | + 'ok' => '', | ||
| 128 | + 'extend' => '', | ||
| 129 | + ], | ||
| 130 | + [ | ||
| 131 | + 'name' => 'chunking', | ||
| 132 | + 'title' => '分片上传', | ||
| 133 | + 'type' => 'radio', | ||
| 134 | + 'content' => [ | ||
| 135 | + 1 => '开启', | ||
| 136 | + 0 => '关闭', | ||
| 137 | + ], | ||
| 138 | + 'value' => '1', | ||
| 139 | + 'rule' => 'required', | ||
| 140 | + 'msg' => '', | ||
| 141 | + 'tip' => '', | ||
| 142 | + 'ok' => '', | ||
| 143 | + 'extend' => '', | ||
| 144 | + ], | ||
| 145 | + [ | ||
| 146 | + 'name' => 'chunksize', | ||
| 147 | + 'title' => '分片大小', | ||
| 148 | + 'type' => 'number', | ||
| 149 | + 'content' => [], | ||
| 150 | + 'value' => '4194304', | ||
| 151 | + 'rule' => 'required', | ||
| 152 | + 'msg' => '', | ||
| 153 | + 'tip' => '', | ||
| 154 | + 'ok' => '', | ||
| 155 | + 'extend' => '', | ||
| 156 | + ], | ||
| 157 | + [ | ||
| 158 | + 'name' => 'operator', | ||
| 159 | + 'title' => '操作员', | ||
| 160 | + 'type' => 'string', | ||
| 161 | + 'content' => [], | ||
| 162 | + 'value' => 'zhaoyang', | ||
| 163 | + 'rule' => '', | ||
| 164 | + 'msg' => '服务端上传和删除文件时间使用', | ||
| 165 | + 'tip' => '', | ||
| 166 | + 'ok' => '', | ||
| 167 | + 'extend' => '', | ||
| 168 | + ], | ||
| 169 | + [ | ||
| 170 | + 'name' => 'password', | ||
| 171 | + 'title' => '密码', | ||
| 172 | + 'type' => 'string', | ||
| 173 | + 'content' => [], | ||
| 174 | + 'value' => 'Lxq0ykCsvZ6q7abFfvzw51QmcxgOxr3B', | ||
| 175 | + 'rule' => '', | ||
| 176 | + 'msg' => '服务端上传和删除文件时间使用', | ||
| 177 | + 'tip' => '', | ||
| 178 | + 'ok' => '', | ||
| 179 | + 'extend' => '', | ||
| 180 | + ], | ||
| 181 | + [ | ||
| 182 | + 'name' => 'syncdelete', | ||
| 183 | + 'title' => '附件删除时是否同步删除文件', | ||
| 184 | + 'type' => 'bool', | ||
| 185 | + 'content' => [], | ||
| 186 | + 'value' => '0', | ||
| 187 | + 'rule' => 'required', | ||
| 188 | + 'msg' => '', | ||
| 189 | + 'tip' => '', | ||
| 190 | + 'ok' => '', | ||
| 191 | + 'extend' => '', | ||
| 192 | + ], | ||
| 193 | + [ | ||
| 194 | + 'name' => '__tips__', | ||
| 195 | + 'title' => '温馨提示', | ||
| 196 | + 'type' => '', | ||
| 197 | + 'content' => [], | ||
| 198 | + 'value' => '在使用之前请注册又拍云账号并进行认证和创建云储存,注册链接:<a href="https://console.upyun.com/register/?invite=SyAt3ehQZ" target="_blank">https://console.upyun.com/register/?invite=SyAt3ehQZ</a>', | ||
| 199 | + 'rule' => '', | ||
| 200 | + 'msg' => '', | ||
| 201 | + 'tip' => '', | ||
| 202 | + 'ok' => '', | ||
| 203 | + 'extend' => '48 104', | ||
| 204 | + ], | ||
| 205 | +]; |
addons/upyun/controller/Index.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace addons\upyun\controller; | ||
| 4 | + | ||
| 5 | +use app\common\exception\UploadException; | ||
| 6 | +use app\common\library\Upload; | ||
| 7 | +use app\common\model\Attachment; | ||
| 8 | +use think\addons\Controller; | ||
| 9 | +use think\Config; | ||
| 10 | +use Upyun\Api\Rest; | ||
| 11 | +use Upyun\Signature; | ||
| 12 | +use Upyun\Upyun; | ||
| 13 | +use Upyun\Util; | ||
| 14 | + | ||
| 15 | +/** | ||
| 16 | + * 又拍云云储存 | ||
| 17 | + * | ||
| 18 | + */ | ||
| 19 | +class Index extends Controller | ||
| 20 | +{ | ||
| 21 | + | ||
| 22 | + /** | ||
| 23 | + * @var \Upyun\Config | ||
| 24 | + */ | ||
| 25 | + protected $config = null; | ||
| 26 | + | ||
| 27 | + public function _initialize() | ||
| 28 | + { | ||
| 29 | + //跨域检测 | ||
| 30 | + check_cors_request(); | ||
| 31 | + | ||
| 32 | + parent::_initialize(); | ||
| 33 | + Config::set('default_return_type', 'json'); | ||
| 34 | + | ||
| 35 | + $config = get_addon_config('upyun'); | ||
| 36 | + $this->config = new \Upyun\Config($config['bucket'], $config['operator'], $config['password']); | ||
| 37 | + } | ||
| 38 | + | ||
| 39 | + public function index() | ||
| 40 | + { | ||
| 41 | + Config::set('default_return_type', 'html'); | ||
| 42 | + $this->error("当前插件暂无前台页面"); | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 获取签名 | ||
| 47 | + */ | ||
| 48 | + public function params() | ||
| 49 | + { | ||
| 50 | + $this->check(); | ||
| 51 | + $name = $this->request->post('name'); | ||
| 52 | + $md5 = $this->request->post('md5'); | ||
| 53 | + $chunk = $this->request->post('chunk'); | ||
| 54 | + $config = get_addon_config('upyun'); | ||
| 55 | + | ||
| 56 | + $upload = new Upload(); | ||
| 57 | + $url = $upload->getSavekey($config['savekey'], $name, $md5); | ||
| 58 | + | ||
| 59 | + $signature = Signature::getHeaderSign($this->config, 'PUT', '/' . $config['bucket'] . $url); | ||
| 60 | + $data = []; | ||
| 61 | + $data['headers'] = $signature; | ||
| 62 | + $data['url'] = $url; | ||
| 63 | + if ($chunk) { | ||
| 64 | + $type = $this->request->post('type'); | ||
| 65 | + $fileSize = $this->request->post('size'); | ||
| 66 | + $chunkSize = $this->request->post('chunkSize'); | ||
| 67 | + //如果分片大小不是整数,则进行变更 | ||
| 68 | + if (!is_int($chunkSize / 1024 / 1024)) { | ||
| 69 | + $chunkSize = 1024 * 1024 * 2; | ||
| 70 | + } | ||
| 71 | + $req = new Rest($this->config); | ||
| 72 | + $res = $req->request('PUT', $url) | ||
| 73 | + ->withHeaders(array( | ||
| 74 | + 'X-Upyun-Multi-Disorder' => 'true', | ||
| 75 | + 'X-Upyun-Multi-Stage' => 'initiate', | ||
| 76 | + 'X-Upyun-Multi-Length' => (string)$fileSize, | ||
| 77 | + 'X-Upyun-Multi-Type' => $type, | ||
| 78 | + 'X-Upyun-Multi-Part-Size' => $chunkSize, | ||
| 79 | + )) | ||
| 80 | + ->send(); | ||
| 81 | + if ($res->getStatusCode() !== 204) { | ||
| 82 | + $this->error('初始化失败'); | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + $init = Util::getHeaderParams($res->getHeaders()); | ||
| 86 | + | ||
| 87 | + $data['headers']['X-Upyun-Multi-Stage'] = 'upload'; | ||
| 88 | + $data['headers']['X-Upyun-Multi-Uuid'] = $init['x-upyun-multi-uuid']; | ||
| 89 | + $data['uuid'] = $init['x-upyun-multi-uuid']; | ||
| 90 | + $data['chunkSize'] = $chunkSize; | ||
| 91 | + | ||
| 92 | + $this->success("", "", $data); | ||
| 93 | + } else { | ||
| 94 | + $this->success('', null, $data); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + return; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 服务器中转上传文件 | ||
| 102 | + * 上传分片 | ||
| 103 | + * 合并分片 | ||
| 104 | + */ | ||
| 105 | + public function upload() | ||
| 106 | + { | ||
| 107 | + $this->check(); | ||
| 108 | + $config = get_addon_config('upyun'); | ||
| 109 | + | ||
| 110 | + $chunkid = $this->request->post("chunkid"); | ||
| 111 | + if ($chunkid) { | ||
| 112 | + $action = $this->request->post("action"); | ||
| 113 | + $chunkindex = $this->request->post("chunkindex/d"); | ||
| 114 | + $chunkcount = $this->request->post("chunkcount/d"); | ||
| 115 | + $filesize = $this->request->post("filesize"); | ||
| 116 | + $filename = $this->request->post("filename"); | ||
| 117 | + $url = $this->request->post("url"); | ||
| 118 | + $uuid = $this->request->post("uuid"); | ||
| 119 | + | ||
| 120 | + if ($action == 'merge') { | ||
| 121 | + //合并分片 | ||
| 122 | + if ($config['uploadmode'] == 'server') { | ||
| 123 | + $attachment = null; | ||
| 124 | + //合并分片文件 | ||
| 125 | + try { | ||
| 126 | + $upload = new Upload(); | ||
| 127 | + $attachment = $upload->merge($chunkid, $chunkcount, $filename); | ||
| 128 | + } catch (UploadException $e) { | ||
| 129 | + $this->error($e->getMessage()); | ||
| 130 | + } | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + try { | ||
| 134 | + $req = new Rest($this->config); | ||
| 135 | + $res = $req->request('PUT', $url) | ||
| 136 | + ->withHeaders(array( | ||
| 137 | + 'X-Upyun-Multi-Uuid' => $uuid, | ||
| 138 | + 'X-Upyun-Multi-Stage' => 'complete' | ||
| 139 | + )) | ||
| 140 | + ->send(); | ||
| 141 | + if ($res->getStatusCode() != 204 && $res->getStatusCode() != 201) { | ||
| 142 | + throw new \Exception('end request failed when poinit upload!'); | ||
| 143 | + } | ||
| 144 | + } catch (\Exception $e) { | ||
| 145 | + $this->error($e->getMessage()); | ||
| 146 | + } | ||
| 147 | + $this->success("上传成功", '', ['url' => $url, 'fullurl' => cdnurl($url, true)]); | ||
| 148 | + } else { | ||
| 149 | + //默认普通上传文件 | ||
| 150 | + $file = $this->request->file('file'); | ||
| 151 | + try { | ||
| 152 | + $upload = new Upload($file); | ||
| 153 | + $file = $upload->chunk($chunkid, $chunkindex, $chunkcount); | ||
| 154 | + } catch (UploadException $e) { | ||
| 155 | + $this->error($e->getMessage()); | ||
| 156 | + } | ||
| 157 | + try { | ||
| 158 | + //上传分片到OSS | ||
| 159 | + $req = new Rest($this->config); | ||
| 160 | + $req->request('PUT', $url) | ||
| 161 | + ->withHeaders(array( | ||
| 162 | + 'X-Upyun-Multi-Stage' => 'upload', | ||
| 163 | + 'X-Upyun-Multi-Uuid' => $uuid, | ||
| 164 | + 'X-Upyun-Part-Id' => $chunkindex | ||
| 165 | + )) | ||
| 166 | + ->withFile($file) | ||
| 167 | + ->send(); | ||
| 168 | + } catch (\Exception $e) { | ||
| 169 | + $this->error($e->getMessage()); | ||
| 170 | + } | ||
| 171 | + | ||
| 172 | + $this->success("上传成功", "", [], 3, ['url' => $url]); | ||
| 173 | + } | ||
| 174 | + } else { | ||
| 175 | + $attachment = null; | ||
| 176 | + //默认普通上传文件 | ||
| 177 | + $file = $this->request->file('file'); | ||
| 178 | + try { | ||
| 179 | + $upload = new Upload($file); | ||
| 180 | + $attachment = $upload->upload(); | ||
| 181 | + } catch (UploadException $e) { | ||
| 182 | + $this->error($e->getMessage()); | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + //文件绝对路径 | ||
| 186 | + $filePath = $upload->getFile()->getRealPath() ?: $upload->getFile()->getPathname(); | ||
| 187 | + | ||
| 188 | + try { | ||
| 189 | + $upyun = new Upyun($this->config); | ||
| 190 | + $ret = $upyun->write($attachment->url, $upload->getFile()); | ||
| 191 | + //成功不做任何操作 | ||
| 192 | + } catch (\Exception $e) { | ||
| 193 | + $attachment->delete(); | ||
| 194 | + @unlink($filePath); | ||
| 195 | + $this->error("上传失败"); | ||
| 196 | + } | ||
| 197 | + | ||
| 198 | + $this->success("上传成功", '', ['url' => $attachment->url, 'fullurl' => cdnurl($attachment->url, true)]); | ||
| 199 | + } | ||
| 200 | + return; | ||
| 201 | + } | ||
| 202 | + | ||
| 203 | + /** | ||
| 204 | + * 回调 | ||
| 205 | + */ | ||
| 206 | + public function notify() | ||
| 207 | + { | ||
| 208 | + $this->check(); | ||
| 209 | + $size = $this->request->post('size'); | ||
| 210 | + $name = $this->request->post('name'); | ||
| 211 | + $md5 = $this->request->post('md5'); | ||
| 212 | + $type = $this->request->post('type'); | ||
| 213 | + $url = $this->request->post('url'); | ||
| 214 | + $suffix = substr($name, stripos($name, '.') + 1); | ||
| 215 | + $attachment = Attachment::where('url', $url)->where('storage', 'upyun')->find(); | ||
| 216 | + if (!$attachment) { | ||
| 217 | + $params = array( | ||
| 218 | + 'admin_id' => (int)session('admin.id'), | ||
| 219 | + 'user_id' => (int)cookie('uid'), | ||
| 220 | + 'filesize' => $size, | ||
| 221 | + 'filename' => $name, | ||
| 222 | + 'imagewidth' => 0, | ||
| 223 | + 'imageheight' => 0, | ||
| 224 | + 'imagetype' => $suffix, | ||
| 225 | + 'imageframes' => 0, | ||
| 226 | + 'mimetype' => $type, | ||
| 227 | + 'url' => $url, | ||
| 228 | + 'uploadtime' => time(), | ||
| 229 | + 'storage' => 'upyun', | ||
| 230 | + 'sha1' => $md5, | ||
| 231 | + ); | ||
| 232 | + Attachment::create($params); | ||
| 233 | + } | ||
| 234 | + $this->success(); | ||
| 235 | + return; | ||
| 236 | + } | ||
| 237 | + | ||
| 238 | + /** | ||
| 239 | + * 检查签名是否正确或过期 | ||
| 240 | + */ | ||
| 241 | + protected function check() | ||
| 242 | + { | ||
| 243 | + $upyuntoken = $this->request->post('upyuntoken', '', 'trim'); | ||
| 244 | + if (!$upyuntoken) { | ||
| 245 | + $this->error("参数不正确"); | ||
| 246 | + } | ||
| 247 | + $config = get_addon_config('upyun'); | ||
| 248 | + list($sign, $data) = explode(':', $upyuntoken); | ||
| 249 | + if (!$sign || !$data) { | ||
| 250 | + $this->error("参数不正确"); | ||
| 251 | + } | ||
| 252 | + $policy = $data; | ||
| 253 | + if (base64_decode($sign) !== Signature::getBodySignature($this->config, 'POST', '/' . $config['bucket'], null, $policy)) { | ||
| 254 | + $this->error("签名不正确"); | ||
| 255 | + } | ||
| 256 | + $json = json_decode(base64_decode($data), true); | ||
| 257 | + if ($json['expiration'] < time()) { | ||
| 258 | + $this->error("请求已经超时"); | ||
| 259 | + } | ||
| 260 | + } | ||
| 261 | + | ||
| 262 | +} |
addons/upyun/info.ini
0 → 100644
addons/upyun/library/Upyun/Api/Form.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace Upyun\Api; | ||
| 4 | + | ||
| 5 | +use Upyun\Signature; | ||
| 6 | +use Upyun\Util; | ||
| 7 | +use GuzzleHttp\Client; | ||
| 8 | + | ||
| 9 | +class Form extends Rest | ||
| 10 | +{ | ||
| 11 | + public function upload($path, $stream, $params) | ||
| 12 | + { | ||
| 13 | + $params['save-key'] = $path; | ||
| 14 | + $params['service'] = $this->config->serviceName; | ||
| 15 | + if (!isset($params['expiration'])) { | ||
| 16 | + $params['expiration'] = time() + 30 * 60 * 60; // 30 分钟 | ||
| 17 | + } | ||
| 18 | + | ||
| 19 | + $policy = Util::base64Json($params); | ||
| 20 | + $method = 'POST'; | ||
| 21 | + $signature = Signature::getBodySignature($this->config, $method, '/' . $params['service'], null, $policy); | ||
| 22 | + $client = new Client([ | ||
| 23 | + 'timeout' => $this->config->timeout, | ||
| 24 | + ]); | ||
| 25 | + | ||
| 26 | + $response = $client->request($method, $this->endpoint, array( | ||
| 27 | + 'multipart' => array( | ||
| 28 | + array( | ||
| 29 | + 'name' => 'policy', | ||
| 30 | + 'contents' => $policy, | ||
| 31 | + ), | ||
| 32 | + array( | ||
| 33 | + 'name' => 'authorization', | ||
| 34 | + 'contents' => $signature, | ||
| 35 | + ), | ||
| 36 | + array( | ||
| 37 | + 'name' => 'file', | ||
| 38 | + 'contents' => $stream, | ||
| 39 | + ) | ||
| 40 | + ) | ||
| 41 | + )); | ||
| 42 | + return $response->getStatusCode() === 200; | ||
| 43 | + } | ||
| 44 | +} |
addons/upyun/library/Upyun/Api/Pretreat.php
0 → 100644
| 1 | +<?php | ||
| 2 | +namespace Upyun\Api; | ||
| 3 | + | ||
| 4 | +use GuzzleHttp\Client; | ||
| 5 | +use Upyun\Config; | ||
| 6 | +use Upyun\Signature; | ||
| 7 | +use Upyun\Util; | ||
| 8 | + | ||
| 9 | +class Pretreat | ||
| 10 | +{ | ||
| 11 | + | ||
| 12 | + /** | ||
| 13 | + * @var Config | ||
| 14 | + */ | ||
| 15 | + protected $config; | ||
| 16 | + | ||
| 17 | + public function __construct(Config $config) | ||
| 18 | + { | ||
| 19 | + if (!$config->processNotifyUrl) { | ||
| 20 | + throw new \Exception("should config prosessNotifyUrl first."); | ||
| 21 | + } | ||
| 22 | + $this->config = $config; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public function process($tasks, $optionalParams = array()) | ||
| 26 | + { | ||
| 27 | + $encodedTasks = Util::base64Json($tasks); | ||
| 28 | + | ||
| 29 | + $client = new Client([ | ||
| 30 | + 'timeout' => $this->config->timeout, | ||
| 31 | + ]); | ||
| 32 | + | ||
| 33 | + $params = array( | ||
| 34 | + 'service' => $this->config->serviceName, | ||
| 35 | + 'notify_url' => $this->config->processNotifyUrl, | ||
| 36 | + 'tasks' => $encodedTasks, | ||
| 37 | + ); | ||
| 38 | + | ||
| 39 | + $params = array_merge($params, $optionalParams); | ||
| 40 | + | ||
| 41 | + $path = '/pretreatment/'; | ||
| 42 | + $method = 'POST'; | ||
| 43 | + $signedHeaders = Signature::getHeaderSign($this->config, $method, $path); | ||
| 44 | + | ||
| 45 | + $url = $this->config->getPretreatEndPoint() . $path; | ||
| 46 | + $response = $client->request($method, $url, [ | ||
| 47 | + 'headers' => $signedHeaders, | ||
| 48 | + 'form_params' => $params | ||
| 49 | + ]); | ||
| 50 | + | ||
| 51 | + $body = $response->getBody()->getContents(); | ||
| 52 | + return json_decode($body, true); | ||
| 53 | + } | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + public function query($taskIds, $path) | ||
| 57 | + { | ||
| 58 | + $client = new Client([ | ||
| 59 | + 'timeout' => $this->config->timeout, | ||
| 60 | + ]); | ||
| 61 | + | ||
| 62 | + $params = array( | ||
| 63 | + 'service' => $this->config->serviceName, | ||
| 64 | + 'task_ids' => implode(',', $taskIds) | ||
| 65 | + ); | ||
| 66 | + $path = $path . '?' . http_build_query($params); | ||
| 67 | + | ||
| 68 | + $method = 'GET'; | ||
| 69 | + $url = $this->config->getPretreatEndPoint() . $path; | ||
| 70 | + $signedHeaders = Signature::getHeaderSign($this->config, $method, $path); | ||
| 71 | + $response = $client->request($method, $url, [ | ||
| 72 | + 'headers' => $signedHeaders | ||
| 73 | + ]); | ||
| 74 | + | ||
| 75 | + if ($response->getStatusCode() === 200) { | ||
| 76 | + $body = $response->getBody()->getContents(); | ||
| 77 | + $result = json_decode($body, true); | ||
| 78 | + if (is_array($result)) { | ||
| 79 | + return $result['tasks']; | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + return false; | ||
| 83 | + } | ||
| 84 | +} |
addons/upyun/library/Upyun/Api/Rest.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace Upyun\Api; | ||
| 4 | + | ||
| 5 | +use GuzzleHttp\Client; | ||
| 6 | +use GuzzleHttp\Psr7; | ||
| 7 | +use Upyun\Config; | ||
| 8 | +use Upyun\Signature; | ||
| 9 | +use Upyun\Util; | ||
| 10 | + | ||
| 11 | +class Rest | ||
| 12 | +{ | ||
| 13 | + /** | ||
| 14 | + * @var Config | ||
| 15 | + */ | ||
| 16 | + protected $config; | ||
| 17 | + | ||
| 18 | + protected $endpoint; | ||
| 19 | + protected $method; | ||
| 20 | + protected $storagePath; | ||
| 21 | + public $headers = []; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * @var Psr7\Stream | ||
| 25 | + */ | ||
| 26 | + protected $file; | ||
| 27 | + | ||
| 28 | + | ||
| 29 | + public function __construct(Config $config) | ||
| 30 | + { | ||
| 31 | + $this->config = $config; | ||
| 32 | + $this->endpoint = $config->getProtocol() . Config::$restApiEndPoint . '/' . $config->serviceName; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + public function request($method, $storagePath) | ||
| 36 | + { | ||
| 37 | + $this->method = strtoupper($method); | ||
| 38 | + $this->storagePath = '/' . ltrim($storagePath, '/'); | ||
| 39 | + return $this; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + | ||
| 43 | + /** | ||
| 44 | + * @param string|resource $file | ||
| 45 | + * | ||
| 46 | + * @return $this | ||
| 47 | + */ | ||
| 48 | + public function withFile($file) | ||
| 49 | + { | ||
| 50 | + $stream = Psr7\stream_for($file); | ||
| 51 | + $this->file = $stream; | ||
| 52 | + | ||
| 53 | + return $this; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * @return mixed|\Psr\Http\Message\ResponseInterface | ||
| 58 | + */ | ||
| 59 | + public function send() | ||
| 60 | + { | ||
| 61 | + $client = new Client([ | ||
| 62 | + 'timeout' => $this->config->timeout, | ||
| 63 | + ]); | ||
| 64 | + | ||
| 65 | + $url = $this->endpoint . $this->storagePath; | ||
| 66 | + $body = null; | ||
| 67 | + if ($this->file && $this->method === 'PUT') { | ||
| 68 | + $body = $this->file; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + $request = new Psr7\Request( | ||
| 72 | + $this->method, | ||
| 73 | + Util::encodeURI($url), | ||
| 74 | + $this->headers, | ||
| 75 | + $body | ||
| 76 | + ); | ||
| 77 | + $authHeader = Signature::getHeaderSign($this->config, | ||
| 78 | + $this->method, | ||
| 79 | + $request->getUri()->getPath() | ||
| 80 | + ); | ||
| 81 | + foreach ($authHeader as $head => $value) { | ||
| 82 | + $request = $request->withHeader($head, $value); | ||
| 83 | + } | ||
| 84 | + $response = $client->send($request, [ | ||
| 85 | + 'debug' => $this->config->debug | ||
| 86 | + ]); | ||
| 87 | + | ||
| 88 | + return $response; | ||
| 89 | + } | ||
| 90 | + | ||
| 91 | + public function withHeader($header, $value) | ||
| 92 | + { | ||
| 93 | + $header = strtolower(trim($header)); | ||
| 94 | + | ||
| 95 | + $this->headers[$header] = $value; | ||
| 96 | + return $this; | ||
| 97 | + } | ||
| 98 | + | ||
| 99 | + public function withHeaders($headers) | ||
| 100 | + { | ||
| 101 | + if (is_array($headers)) { | ||
| 102 | + foreach ($headers as $header => $value) { | ||
| 103 | + $this->withHeader($header, $value); | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + return $this; | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + public function toRequest() | ||
| 110 | + { | ||
| 111 | + $url = $this->endpoint . $this->storagePath; | ||
| 112 | + $body = null; | ||
| 113 | + if ($this->file && $this->method === 'PUT') { | ||
| 114 | + $body = $this->file; | ||
| 115 | + } | ||
| 116 | + | ||
| 117 | + $request = new Psr7\Request( | ||
| 118 | + $this->method, | ||
| 119 | + Util::encodeURI($url), | ||
| 120 | + $this->headers, | ||
| 121 | + $body | ||
| 122 | + ); | ||
| 123 | + $authHeader = Signature::getHeaderSign($this->config, | ||
| 124 | + $this->method, | ||
| 125 | + $request->getUri()->getPath() | ||
| 126 | + ); | ||
| 127 | + foreach ($authHeader as $head => $value) { | ||
| 128 | + $request = $request->withHeader($head, $value); | ||
| 129 | + } | ||
| 130 | + return $request; | ||
| 131 | + } | ||
| 132 | +} |
addons/upyun/library/Upyun/Api/SyncVideo.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * 同步视频处理 | ||
| 4 | + */ | ||
| 5 | + | ||
| 6 | +namespace Upyun\Api; | ||
| 7 | + | ||
| 8 | +use GuzzleHttp\Client; | ||
| 9 | +use Upyun\Config; | ||
| 10 | +use Upyun\Signature; | ||
| 11 | + | ||
| 12 | + | ||
| 13 | +class SyncVideo { | ||
| 14 | + /** | ||
| 15 | + * @var Config | ||
| 16 | + */ | ||
| 17 | + protected $config; | ||
| 18 | + | ||
| 19 | + public function __construct(Config $config) | ||
| 20 | + { | ||
| 21 | + $this->config = $config; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + public function process($params, $path) { | ||
| 25 | + $client = new Client([ | ||
| 26 | + 'timeout' => $this->config->timeout, | ||
| 27 | + ]); | ||
| 28 | + | ||
| 29 | + $path = '/' . $this->config->serviceName . $path; | ||
| 30 | + $method = 'POST'; | ||
| 31 | + $signedHeaders = Signature::getHeaderSign($this->config, $method, $path); | ||
| 32 | + | ||
| 33 | + $url = $this->config->getSyncVideoEndPoint() . $path; | ||
| 34 | + $response = $client->request($method, $url, [ | ||
| 35 | + 'headers' => $signedHeaders, | ||
| 36 | + 'json' => $params | ||
| 37 | + ]); | ||
| 38 | + | ||
| 39 | + $body = $response->getBody()->getContents(); | ||
| 40 | + return json_decode($body, true); | ||
| 41 | + } | ||
| 42 | +} |
addons/upyun/library/Upyun/Config.php
0 → 100644
| 1 | +<?php | ||
| 2 | +namespace Upyun; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * Class Config | ||
| 6 | + * | ||
| 7 | + * @package Upyun | ||
| 8 | + */ | ||
| 9 | +class Config | ||
| 10 | +{ | ||
| 11 | + /** | ||
| 12 | + * @var string 服务名称,将会被弃用 | ||
| 13 | + */ | ||
| 14 | + public $bucketName; | ||
| 15 | + | ||
| 16 | + /** | ||
| 17 | + * @var string 服务名称 | ||
| 18 | + */ | ||
| 19 | + public $serviceName; | ||
| 20 | + /** | ||
| 21 | + * @var string 操作员名 | ||
| 22 | + */ | ||
| 23 | + public $operatorName; | ||
| 24 | + /** | ||
| 25 | + * @var string 操作员密码 md5 hash 值 | ||
| 26 | + */ | ||
| 27 | + public $operatorPassword; | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * @var bool 是否使用 https | ||
| 31 | + */ | ||
| 32 | + public $useSsl; | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * @var string 上传使用的接口类型,可以设置为 `REST`:使用 rest api 上传,`AUTO` 根据文件大小自动判断,`BLOCK` 使用串行式断点续传,`BLOCK_PARALLEL` 使用并行式断点续传 | ||
| 36 | + * 当上传小文件时,不推荐使用断点续传;上传时如果设置了异步预处理`withAsyncProcess=true`,将会使用表单 api 上传 | ||
| 37 | + */ | ||
| 38 | + public $uploadType = 'AUTO'; | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * @var int 上传的接口类型设置为 `AUTO` 时,文件大小的边界值:小于该值时,使用 rest api,否则使用断点续传。 默认 30M | ||
| 42 | + */ | ||
| 43 | + public $sizeBoundary = 31457280; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * @var int 并行式断点续传的并发数 | ||
| 47 | + */ | ||
| 48 | + public $concurrency = 5; | ||
| 49 | + | ||
| 50 | + /** | ||
| 51 | + * @var int request timeout seconds | ||
| 52 | + */ | ||
| 53 | + public $timeout = 60; | ||
| 54 | + | ||
| 55 | + | ||
| 56 | + /** | ||
| 57 | + * @var string 异步云处理的回调通知地址 | ||
| 58 | + */ | ||
| 59 | + public $processNotifyUrl; | ||
| 60 | + | ||
| 61 | + /** | ||
| 62 | + * @var boolean curl debug | ||
| 63 | + */ | ||
| 64 | + public $debug = false; | ||
| 65 | + | ||
| 66 | + private $version = '3.0.0'; | ||
| 67 | + | ||
| 68 | + | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * @var string 表单 api 的秘钥 | ||
| 72 | + */ | ||
| 73 | + private $formApiKey; | ||
| 74 | + | ||
| 75 | + /** | ||
| 76 | + * @var string rest api 和 form api 的接口地址 | ||
| 77 | + */ | ||
| 78 | + public static $restApiEndPoint; | ||
| 79 | + | ||
| 80 | + | ||
| 81 | + /** | ||
| 82 | + * rest api 和 form api 接口请求地址,详见:http://docs.upyun.com/api/rest_api/ | ||
| 83 | + */ | ||
| 84 | + const ED_AUTO = 'v0.api.upyun.com'; | ||
| 85 | + const ED_TELECOM = 'v1.api.upyun.com'; | ||
| 86 | + const ED_CNC = 'v2.api.upyun.com'; | ||
| 87 | + const ED_CTT = 'v3.api.upyun.com'; | ||
| 88 | + | ||
| 89 | + /** | ||
| 90 | + * 异步云处理接口地址 | ||
| 91 | + */ | ||
| 92 | + const ED_VIDEO = 'p0.api.upyun.com'; | ||
| 93 | + | ||
| 94 | + /** | ||
| 95 | + * 刷新接口地址 | ||
| 96 | + */ | ||
| 97 | + const ED_PURGE = 'http://purge.upyun.com/purge/'; | ||
| 98 | + | ||
| 99 | + /** | ||
| 100 | + * 同步视频处理接口地址 | ||
| 101 | + */ | ||
| 102 | + const ED_SYNC_VIDEO = 'p1.api.upyun.com'; | ||
| 103 | + | ||
| 104 | + public function __construct($serviceName, $operatorName, $operatorPassword) | ||
| 105 | + { | ||
| 106 | + $this->serviceName = $serviceName; | ||
| 107 | + $this->bucketName = $serviceName; | ||
| 108 | + $this->operatorName = $operatorName; | ||
| 109 | + $this->setOperatorPassword($operatorPassword); | ||
| 110 | + $this->useSsl = false; | ||
| 111 | + self::$restApiEndPoint = self::ED_AUTO; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public function setOperatorPassword($operatorPassword) | ||
| 115 | + { | ||
| 116 | + $this->operatorPassword = md5($operatorPassword); | ||
| 117 | + } | ||
| 118 | + | ||
| 119 | + public function getFormApiKey() | ||
| 120 | + { | ||
| 121 | + if (! $this->formApiKey) { | ||
| 122 | + throw new \Exception('form api key is empty.'); | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + return $this->formApiKey; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public function setFormApiKey($key) | ||
| 129 | + { | ||
| 130 | + $this->formApiKey = $key; | ||
| 131 | + } | ||
| 132 | + | ||
| 133 | + public function getVersion() | ||
| 134 | + { | ||
| 135 | + return $this->version; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + public function getPretreatEndPoint() | ||
| 139 | + { | ||
| 140 | + return $this->getProtocol() . self::ED_VIDEO; | ||
| 141 | + } | ||
| 142 | + | ||
| 143 | + public function getSyncVideoEndPoint() | ||
| 144 | + { | ||
| 145 | + return $this->getProtocol() . self::ED_SYNC_VIDEO; | ||
| 146 | + } | ||
| 147 | + | ||
| 148 | + public function getProtocol() | ||
| 149 | + { | ||
| 150 | + return $this->useSsl ? 'https://' : 'http://'; | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + public function setUploadType($uploadType) | ||
| 154 | + { | ||
| 155 | + $this->uploadType = $uploadType; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + public function setConcurrency($concurrency) | ||
| 159 | + { | ||
| 160 | + $this->concurrency = $concurrency; | ||
| 161 | + } | ||
| 162 | +} |
addons/upyun/library/Upyun/Signature.php
0 → 100644
| 1 | +<?php | ||
| 2 | +namespace Upyun; | ||
| 3 | + | ||
| 4 | +/** | ||
| 5 | + * Class Signature | ||
| 6 | + * @package Upyun | ||
| 7 | + */ | ||
| 8 | +class Signature | ||
| 9 | +{ | ||
| 10 | + /** | ||
| 11 | + * 获取分块上传接口的签名 | ||
| 12 | + */ | ||
| 13 | + const SIGN_MULTIPART = 1; | ||
| 14 | + /** | ||
| 15 | + * 生成视频处理接口的签名 | ||
| 16 | + */ | ||
| 17 | + const SIGN_VIDEO = 2; | ||
| 18 | + /** | ||
| 19 | + * 生成视频处理接口的签名(不需要操作员时使用) | ||
| 20 | + */ | ||
| 21 | + const SIGN_VIDEO_NO_OPERATOR = 3; | ||
| 22 | + | ||
| 23 | + /** | ||
| 24 | + * 获取 Header 签名需要的请求头 | ||
| 25 | + * | ||
| 26 | + * @param Config $serviceConfig | ||
| 27 | + * @param $method 请求方法 | ||
| 28 | + * @param $path 请求路径 | ||
| 29 | + * @param $contentMd5 文件内容 md5 | ||
| 30 | + * | ||
| 31 | + * @return array | ||
| 32 | + */ | ||
| 33 | + public static function getHeaderSign($serviceConfig, $method, $path, $contentMd5 = null) | ||
| 34 | + { | ||
| 35 | + $gmtDate = gmdate('D, d M Y H:i:s \G\M\T'); | ||
| 36 | + | ||
| 37 | + $policy = null; | ||
| 38 | + $sign = self::getBodySignature($serviceConfig, $method, $path, $gmtDate, $policy, $contentMd5); | ||
| 39 | + | ||
| 40 | + $headers = array( | ||
| 41 | + 'Authorization' => $sign, | ||
| 42 | + 'X-Date' => $gmtDate, | ||
| 43 | + 'User-agent' => 'Php-Sdk/' . $serviceConfig->getVersion() | ||
| 44 | + ); | ||
| 45 | + return $headers; | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + /** | ||
| 49 | + * 获取请求缓存刷新接口需要的签名头 | ||
| 50 | + * | ||
| 51 | + * @param Config $serviceConfig | ||
| 52 | + * @param $urlString | ||
| 53 | + * | ||
| 54 | + * @return array | ||
| 55 | + */ | ||
| 56 | + public static function getPurgeSignHeader(Config $serviceConfig, $urlString) | ||
| 57 | + { | ||
| 58 | + $gmtDate = gmdate('D, d M Y H:i:s \G\M\T'); | ||
| 59 | + $sign = md5("$urlString&{$serviceConfig->serviceName}&$gmtDate&{$serviceConfig->operatorPassword}"); | ||
| 60 | + return array( | ||
| 61 | + 'Authorization' => "UpYun {$serviceConfig->serviceName}:{$serviceConfig->operatorName}:$sign", | ||
| 62 | + 'Date' => $gmtDate, | ||
| 63 | + 'User-agent' => 'Php-Sdk/' . $serviceConfig->getVersion() . ' (purge api)' | ||
| 64 | + ); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 获取表单 API 需要的签名,依据 body 签名规则计算 | ||
| 69 | + * @param Config $serviceConfig | ||
| 70 | + * @param $method 请求方法 | ||
| 71 | + * @param $uri 请求路径 | ||
| 72 | + * @param $date 请求时间 | ||
| 73 | + * @param $policy | ||
| 74 | + * @param $contentMd5 请求 body 的 md5 | ||
| 75 | + * | ||
| 76 | + * @return array | ||
| 77 | + */ | ||
| 78 | + public static function getBodySignature(Config $serviceConfig, $method, $uri, $date = null, $policy = null, $contentMd5 = null) | ||
| 79 | + { | ||
| 80 | + $data = array( | ||
| 81 | + $method, | ||
| 82 | + $uri | ||
| 83 | + ); | ||
| 84 | + if ($date) { | ||
| 85 | + $data[] = $date; | ||
| 86 | + } | ||
| 87 | + | ||
| 88 | + if ($policy) { | ||
| 89 | + $data[] = $policy; | ||
| 90 | + } | ||
| 91 | + | ||
| 92 | + if ($contentMd5) { | ||
| 93 | + $data[] = $contentMd5; | ||
| 94 | + } | ||
| 95 | + $signature = base64_encode(hash_hmac('sha1', implode('&', $data), $serviceConfig->operatorPassword, true)); | ||
| 96 | + return 'UPYUN ' . $serviceConfig->operatorName . ':' . $signature; | ||
| 97 | + } | ||
| 98 | +} |
addons/upyun/library/Upyun/Uploader.php
0 → 100644
| 1 | +<?php | ||
| 2 | +namespace Upyun; | ||
| 3 | + | ||
| 4 | +use Upyun\Api\Rest; | ||
| 5 | +use Upyun\Api\Form; | ||
| 6 | +use GuzzleHttp\Psr7; | ||
| 7 | +use GuzzleHttp\Pool; | ||
| 8 | +use GuzzleHttp\Client; | ||
| 9 | + | ||
| 10 | +class Uploader | ||
| 11 | +{ | ||
| 12 | + /** | ||
| 13 | + * @var Config | ||
| 14 | + */ | ||
| 15 | + protected $config; | ||
| 16 | + | ||
| 17 | + protected $useBlock = false; | ||
| 18 | + | ||
| 19 | + | ||
| 20 | + public function __construct(Config $config) | ||
| 21 | + { | ||
| 22 | + $this->config = $config; | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + public function upload($path, $file, $params, $withAsyncProcess) | ||
| 26 | + { | ||
| 27 | + $stream = Psr7\stream_for($file); | ||
| 28 | + $size = $stream->getSize(); | ||
| 29 | + $useBlock = $this->needUseBlock($size); | ||
| 30 | + | ||
| 31 | + if ($withAsyncProcess) { | ||
| 32 | + $req = new Form($this->config); | ||
| 33 | + return $req->upload($path, $stream, $params); | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + if (! $useBlock) { | ||
| 37 | + $req = new Rest($this->config); | ||
| 38 | + return $req->request('PUT', $path) | ||
| 39 | + ->withHeaders($params) | ||
| 40 | + ->withFile($stream) | ||
| 41 | + ->send(); | ||
| 42 | + } elseif ($this->config->uploadType === 'BLOCK_PARALLEL') { | ||
| 43 | + return $this->concurrentPointUpload($path, $stream, $params); | ||
| 44 | + } else { | ||
| 45 | + return $this->pointUpload($path, $stream, $params); | ||
| 46 | + } | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * 串行式断点续传 | ||
| 51 | + * @param $path | ||
| 52 | + * @param $stream | ||
| 53 | + * @param $params | ||
| 54 | + * | ||
| 55 | + * @return mixed|\Psr\Http\Message\ResponseInterface | ||
| 56 | + * @throws \Exception | ||
| 57 | + */ | ||
| 58 | + private function pointUpload($path, $stream, $params) | ||
| 59 | + { | ||
| 60 | + $req = new Rest($this->config); | ||
| 61 | + $headers = array(); | ||
| 62 | + if (is_array($params)) { | ||
| 63 | + foreach ($params as $key => $val) { | ||
| 64 | + $headers['X-Upyun-Meta-' . $key] = $val; | ||
| 65 | + } | ||
| 66 | + } | ||
| 67 | + $res = $req->request('PUT', $path) | ||
| 68 | + ->withHeaders(array_merge(array( | ||
| 69 | + 'X-Upyun-Multi-Stage' => 'initiate', | ||
| 70 | + 'X-Upyun-Multi-Type' => Psr7\mimetype_from_filename($path), | ||
| 71 | + 'X-Upyun-Multi-Length' => $stream->getSize(), | ||
| 72 | + ), $headers)) | ||
| 73 | + ->send(); | ||
| 74 | + if ($res->getStatusCode() !== 204) { | ||
| 75 | + throw new \Exception('init request failed when poinit upload!'); | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + $init = Util::getHeaderParams($res->getHeaders()); | ||
| 79 | + $uuid = $init['x-upyun-multi-uuid']; | ||
| 80 | + $blockSize = 1024 * 1024; | ||
| 81 | + $partId = 0; | ||
| 82 | + do { | ||
| 83 | + $fileBlock = $stream->read($blockSize); | ||
| 84 | + $res = $req->request('PUT', $path) | ||
| 85 | + ->withHeaders(array( | ||
| 86 | + 'X-Upyun-Multi-Stage' => 'upload', | ||
| 87 | + 'X-Upyun-Multi-Uuid' => $uuid, | ||
| 88 | + 'X-Upyun-Part-Id' => $partId | ||
| 89 | + )) | ||
| 90 | + ->withFile(Psr7\stream_for($fileBlock)) | ||
| 91 | + ->send(); | ||
| 92 | + | ||
| 93 | + if ($res->getStatusCode() !== 204) { | ||
| 94 | + throw new \Exception('upload request failed when poinit upload!'); | ||
| 95 | + } | ||
| 96 | + $data = Util::getHeaderParams($res->getHeaders()); | ||
| 97 | + $partId = $data['x-upyun-next-part-id']; | ||
| 98 | + } while ($partId != -1); | ||
| 99 | + | ||
| 100 | + $res = $req->request('PUT', $path) | ||
| 101 | + ->withHeaders(array( | ||
| 102 | + 'X-Upyun-Multi-Uuid' => $uuid, | ||
| 103 | + 'X-Upyun-Multi-Stage' => 'complete' | ||
| 104 | + )) | ||
| 105 | + ->send(); | ||
| 106 | + | ||
| 107 | + if ($res->getStatusCode() != 204 && $res->getStatusCode() != 201) { | ||
| 108 | + throw new \Exception('end request failed when poinit upload!'); | ||
| 109 | + } | ||
| 110 | + return $res; | ||
| 111 | + } | ||
| 112 | + | ||
| 113 | + private function needUseBlock($fileSize) | ||
| 114 | + { | ||
| 115 | + if ($this->config->uploadType === 'BLOCK' || | ||
| 116 | + $this->config->uploadType === 'BLOCK_PARALLEL') { | ||
| 117 | + return true; | ||
| 118 | + } elseif ($this->config->uploadType === 'AUTO' && | ||
| 119 | + $fileSize >= $this->config->sizeBoundary) { | ||
| 120 | + return true; | ||
| 121 | + } else { | ||
| 122 | + return false; | ||
| 123 | + } | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + /** | ||
| 127 | + * 并行式断点续传 | ||
| 128 | + * @param $path | ||
| 129 | + * @param $stream | ||
| 130 | + * @param $params | ||
| 131 | + * | ||
| 132 | + * @return mixed|\Psr\Http\Message\ResponseInterface | ||
| 133 | + * @throws \Exception | ||
| 134 | + */ | ||
| 135 | + private function concurrentPointUpload($path, $stream, $params) | ||
| 136 | + { | ||
| 137 | + $req = new Rest($this->config); | ||
| 138 | + | ||
| 139 | + $headers = array(); | ||
| 140 | + if (is_array($params)) { | ||
| 141 | + foreach ($params as $key => $val) { | ||
| 142 | + $headers['X-Upyun-Meta-' . $key] = $val; | ||
| 143 | + } | ||
| 144 | + } | ||
| 145 | + $res = $req->request('PUT', $path) | ||
| 146 | + ->withHeaders(array_merge(array( | ||
| 147 | + 'X-Upyun-Multi-Disorder' => 'true', | ||
| 148 | + 'X-Upyun-Multi-Stage' => 'initiate', | ||
| 149 | + 'X-Upyun-Multi-Type' => Psr7\mimetype_from_filename($path), | ||
| 150 | + 'X-Upyun-Multi-Length' => $stream->getSize(), | ||
| 151 | + ), $headers)) | ||
| 152 | + ->send(); | ||
| 153 | + if ($res->getStatusCode() !== 204) { | ||
| 154 | + throw new \Exception('init request failed when poinit upload!'); | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + $init = Util::getHeaderParams($res->getHeaders()); | ||
| 158 | + $uuid = $init['x-upyun-multi-uuid']; | ||
| 159 | + $requests = function ($req, $path, $stream, $uuid) { | ||
| 160 | + $blockSize = 1024 * 1024; | ||
| 161 | + $total = ceil($stream->getSize() / $blockSize); | ||
| 162 | + for ($i = 0; $i < $total; $i++) { | ||
| 163 | + $fileBlock = $stream->read($blockSize); | ||
| 164 | + yield $req->request('PUT', $path) | ||
| 165 | + ->withHeaders(array( | ||
| 166 | + 'X-Upyun-Multi-Stage' => 'upload', | ||
| 167 | + 'X-Upyun-Multi-Uuid' => $uuid, | ||
| 168 | + 'X-Upyun-Part-Id' => $i | ||
| 169 | + )) | ||
| 170 | + ->withFile(Psr7\stream_for($fileBlock)) | ||
| 171 | + ->toRequest(); | ||
| 172 | + } | ||
| 173 | + }; | ||
| 174 | + $client = new Client([ | ||
| 175 | + 'timeout' => $this->config->timeout, | ||
| 176 | + ]); | ||
| 177 | + $pool = new Pool($client, $requests($req, $path, $stream, $uuid), [ | ||
| 178 | + 'concurrency' => $this->config->concurrency, | ||
| 179 | + 'fulfilled' => function ($res) { | ||
| 180 | + print_r($res); | ||
| 181 | + if ($res->getStatusCode() !== 204) { | ||
| 182 | + throw new \Exception('upload request failed when poinit upload!'); | ||
| 183 | + } | ||
| 184 | + }, | ||
| 185 | + 'rejected' => function () { | ||
| 186 | + throw new \Exception('upload request failed when poinit upload!'); | ||
| 187 | + }, | ||
| 188 | + ]); | ||
| 189 | + $promise = $pool->promise(); | ||
| 190 | + $promise->wait(); | ||
| 191 | + | ||
| 192 | + $res = $req->request('PUT', $path) | ||
| 193 | + ->withHeaders(array( | ||
| 194 | + 'X-Upyun-Multi-Uuid' => $uuid, | ||
| 195 | + 'X-Upyun-Multi-Stage' => 'complete' | ||
| 196 | + )) | ||
| 197 | + ->send(); | ||
| 198 | + if ($res->getStatusCode() != 204 && $res->getStatusCode() != 201) { | ||
| 199 | + throw new \Exception('end request failed when poinit upload!'); | ||
| 200 | + } | ||
| 201 | + return $res; | ||
| 202 | + } | ||
| 203 | +} |
addons/upyun/library/Upyun/Upyun.php
0 → 100644
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * 又拍云 PHP-SDK | ||
| 4 | + */ | ||
| 5 | +namespace Upyun; | ||
| 6 | + | ||
| 7 | +use Upyun\Api\Rest; | ||
| 8 | + | ||
| 9 | +use GuzzleHttp\Client; | ||
| 10 | +use GuzzleHttp\Psr7; | ||
| 11 | +use GuzzleHttp; | ||
| 12 | + | ||
| 13 | +/** | ||
| 14 | + * Class Upyun | ||
| 15 | + * | ||
| 16 | + * 又拍云云存储、云处理接口 | ||
| 17 | + * | ||
| 18 | + * Upyun 类实现了又拍云云存储和云处理的所有接口,通过该类可以实现文件上传、下载;图片视频等多媒体资源云处理。 | ||
| 19 | + * 本文档中,提到的"服务"是指又拍云文件加速回又拍云源类型的服务(即原先的存储类空间)。 | ||
| 20 | + * | ||
| 21 | + * @package Upyun | ||
| 22 | + */ | ||
| 23 | +class Upyun | ||
| 24 | +{ | ||
| 25 | + | ||
| 26 | + /** | ||
| 27 | + * @var Config: 服务配置 | ||
| 28 | + */ | ||
| 29 | + protected $config; | ||
| 30 | + | ||
| 31 | + // 异步云处理任务类型 | ||
| 32 | + /** | ||
| 33 | + * @var string 异步音视频处理 | ||
| 34 | + */ | ||
| 35 | + public static $PROCESS_TYPE_MEDIA = 'media'; | ||
| 36 | + /** | ||
| 37 | + * @var string 文件压缩 | ||
| 38 | + */ | ||
| 39 | + public static $PROCESS_TYPE_ZIP = 'zip-file'; | ||
| 40 | + /** | ||
| 41 | + * @var string 解压缩 | ||
| 42 | + */ | ||
| 43 | + public static $PROCESS_TYPE_UNZIP = 'unzip-file'; | ||
| 44 | + /** | ||
| 45 | + * @var string 文件拉取 | ||
| 46 | + */ | ||
| 47 | + public static $PROCESS_TYPE_SYNC_FILE = 'sync-remote-file-to-upyun'; | ||
| 48 | + /** | ||
| 49 | + * @var string 文档转换 | ||
| 50 | + */ | ||
| 51 | + public static $PROCESS_TYPE_CONVERT = 'document-type-convert'; | ||
| 52 | + /** | ||
| 53 | + * @var string 异步图片拼接 | ||
| 54 | + */ | ||
| 55 | + public static $PROCESS_TYPE_STITCH = 'picture-stitch'; | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * Upyun constructor. | ||
| 59 | + * | ||
| 60 | + * @param Config $config 服务配置 | ||
| 61 | + */ | ||
| 62 | + public function __construct(Config $config) | ||
| 63 | + { | ||
| 64 | + $this->setConfig($config); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * 配置服务信息 | ||
| 69 | + * | ||
| 70 | + * 当需要操作的新的服务时,使用该方法传入新的服务配置即可 | ||
| 71 | + * | ||
| 72 | + * @param Config $config 服务配置 | ||
| 73 | + * | ||
| 74 | + * @return $this | ||
| 75 | + */ | ||
| 76 | + public function setConfig(Config $config) | ||
| 77 | + { | ||
| 78 | + $this->config = $config; | ||
| 79 | + return $this; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + /** | ||
| 83 | + * 上传一个文件到又拍云存储 | ||
| 84 | + * | ||
| 85 | + * 上传的文件格式支持文件流或者字符串方式上传。除简单的文件上传外,针对多媒体资源(图片、音视频),还可以设置同步/异步预处理多媒体资源,例如:图片的裁剪缩放,音视频的转码截图等等众多又拍云强大的云处理功能 | ||
| 86 | + * | ||
| 87 | + * @param string $path 被上传的文件在又拍云存储服务中保存的路径 | ||
| 88 | + * @param string|resource $content 被上传的文件内容(字符串),或者打开该文件获得的文件句柄(文件流)。当上传本地大文件时,推荐使用文件流的方式上传 | ||
| 89 | + * @param array $params 上传文件时,附加的自定义参数。支持 Content-MD5 Content-Type Content-Secret 等,详见 [上传参数](http://docs.upyun.com/api/rest_api/#_2),例如: | ||
| 90 | + * - 设置文件[保护秘钥](http://docs.upyun.com/api/rest_api/#Content-Secret) `write($path, $content, array('Content-Secret' => 'my-secret'))`; | ||
| 91 | + * - 添加[文件元信息](http://docs.upyun.com/api/rest_api/#metadata) `write($path, $content, array('X-Upyun-Meta-Foo' => | ||
| 92 | + * 'bar'))` | ||
| 93 | + * - [图片同步预处理](http://docs.upyun.com/cloud/image/#_5) `write($path, $content, array('x-gmkerl-thumb' => '/format/png'))` | ||
| 94 | + * @param bool $withAsyncProcess 默认为 `false`,当上传图片或者音视频资源时,可以设置该参数为 `true`,开启图片音视频的[异步处理功能](http://docs.upyun.com/api/form_api/#_6) ,例如: | ||
| 95 | + *``` | ||
| 96 | + * // 以下参数会将新上传的图片,再异步生成另一份 png 格式的图片,原图不受影响 | ||
| 97 | + * write($path, $content, array( | ||
| 98 | + * 'apps' => array( | ||
| 99 | + * array( | ||
| 100 | + * 'name' => 'thumb', //异步图片处理任务 | ||
| 101 | + * 'x-gmkerl-thumb' => '/format/png', // 格式化图片为 png 格式 | ||
| 102 | + * 'save_as': '/iamge/png/new.png', // 处理成功后的图片保存路径 | ||
| 103 | + * 'notify_url': 'http://your.notify.url' // 异步任务完成后的回调地址 | ||
| 104 | + * ) | ||
| 105 | + * ) | ||
| 106 | + * ), true); | ||
| 107 | + *``` | ||
| 108 | + * | ||
| 109 | + * | ||
| 110 | + * | ||
| 111 | + * @return array|bool 若文件是图片则返回图片基本信息,如:`array('x-upyun-width' => 123, 'x-upyun-height' => 50, 'x-upyun-frames' | ||
| 112 | + * => 1, 'x-upyun-file-type' => 'JPEG')`,否则返回空数组。当使用异步预处理功能时,返回结果为布尔值,成功为 `true`。 | ||
| 113 | + * | ||
| 114 | + * @throws \Exception 上传失败时,抛出异常 | ||
| 115 | + */ | ||
| 116 | + public function write($path, $content, $params = array(), $withAsyncProcess = false) | ||
| 117 | + { | ||
| 118 | + if (!$content) { | ||
| 119 | + throw new \Exception('write content can not be empty.'); | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + $upload = new Uploader($this->config); | ||
| 123 | + $response = $upload->upload($path, $content, $params, $withAsyncProcess); | ||
| 124 | + if ($withAsyncProcess) { | ||
| 125 | + return $response; | ||
| 126 | + } | ||
| 127 | + return Util::getHeaderParams($response->getHeaders()); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * 读取云存储文件/目录内容 | ||
| 132 | + * | ||
| 133 | + * @param string $path 又拍云存储中的文件或者目录路径 | ||
| 134 | + * @param resource $saveHandler 文件内容写入本地文件流。例如 `$saveHandler = fopen('/local/file', 'w') | ||
| 135 | + * `。当设置该参数时,将以文件流的方式,直接将又拍云中的文件写入本地的文件流,或其他可以写入的流 | ||
| 136 | + * @param array $params 可选参数,读取目录内容时,需要设置三个参数: `X-List-Iter` 分页开始位置(第一页不需要设置),`X-List-Limit` 获取的文件数量(默认 100,最大 | ||
| 137 | + * 10000),`X-List-Order` 结果以时间正序或者倒序 | ||
| 138 | + * | ||
| 139 | + * @return mixed $return 当读取文件且没有设置 `$saveHandler` 参数时,返回一个字符串类型,表示文件内容;设置了 `$saveHandler` 参数时,返回布尔值 | ||
| 140 | + * `true`。当读取目录时,返回一个数组,表示目录下的文件列表。目录下文件内容过多时,需要通过判断返回数组中的 `is_end` 属性,进行分页读取内容 | ||
| 141 | + * | ||
| 142 | + * @throws \Exception | ||
| 143 | + */ | ||
| 144 | + public function read($path, $saveHandler = null, $params = array()) | ||
| 145 | + { | ||
| 146 | + $req = new Rest($this->config); | ||
| 147 | + $response = $req->request('GET', $path) | ||
| 148 | + ->withHeaders($params) | ||
| 149 | + ->send(); | ||
| 150 | + | ||
| 151 | + | ||
| 152 | + $params = Util::getHeaderParams($response->getHeaders()); | ||
| 153 | + | ||
| 154 | + | ||
| 155 | + if (! isset($params['x-upyun-list-iter'])) { | ||
| 156 | + if (is_resource($saveHandler)) { | ||
| 157 | + Psr7\copy_to_stream($response->getBody(), Psr7\stream_for($saveHandler)); | ||
| 158 | + return true; | ||
| 159 | + } else { | ||
| 160 | + return $response->getBody()->getContents(); | ||
| 161 | + } | ||
| 162 | + } else { | ||
| 163 | + $files = Util::parseDir($response->getBody()->getContents()); | ||
| 164 | + return array('files' => $files, 'is_end' => $params['x-upyun-list-iter'] === 'g2gCZAAEbmV4dGQAA2VvZg', 'iter' => $params['x-upyun-list-iter']); | ||
| 165 | + } | ||
| 166 | + } | ||
| 167 | + | ||
| 168 | + /** | ||
| 169 | + * 判断文件是否存在于又拍云存储 | ||
| 170 | + * | ||
| 171 | + * 注意: 对刚删除的文件, 立即调用该方法可能会返回 true, 因为服务端执行删除操作后可能会有很短暂的延迟. | ||
| 172 | + * | ||
| 173 | + * @param string $path 云存储的文件路径 | ||
| 174 | + * | ||
| 175 | + * @return bool 存在时返回 `true`,否则返回 `false` | ||
| 176 | + * @throws \Exception | ||
| 177 | + */ | ||
| 178 | + public function has($path) | ||
| 179 | + { | ||
| 180 | + $req = new Rest($this->config); | ||
| 181 | + try { | ||
| 182 | + $req->request('HEAD', $path) | ||
| 183 | + ->send(); | ||
| 184 | + } catch (GuzzleHttp\Exception\BadResponseException $e) { | ||
| 185 | + $statusCode = $e->getResponse()->getStatusCode(); | ||
| 186 | + if ($statusCode === 404) { | ||
| 187 | + return false; | ||
| 188 | + } else { | ||
| 189 | + throw $e; | ||
| 190 | + } | ||
| 191 | + } | ||
| 192 | + | ||
| 193 | + return true; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + /** | ||
| 197 | + * 获取云存储文件/目录的基本信息 | ||
| 198 | + * | ||
| 199 | + * @param string $path 云存储的文件路径 | ||
| 200 | + * @param array $otherHeaders 设置了后,方法将返回其他 http header 中的信息,默认为空 | ||
| 201 | + * | ||
| 202 | + * @return array 返回一个数组,默认包含以下 key | ||
| 203 | + * - `x-upyun-file-type` 当 $path 是目录时,值为 *folder*,当 $path 是文件时,值为 *file*, | ||
| 204 | + * - `x-upyun-file-size` 文件大小 | ||
| 205 | + * - `x-upyun-file-date` 文件的创建时间 | ||
| 206 | + */ | ||
| 207 | + public function info($path, $otherHeaders = array()) | ||
| 208 | + { | ||
| 209 | + $req = new Rest($this->config); | ||
| 210 | + $response = $req->request('HEAD', $path) | ||
| 211 | + ->send(); | ||
| 212 | + return Util::getHeaderParams($response->getHeaders(), $otherHeaders); | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + /** | ||
| 216 | + * 获取文件的文档类型 | ||
| 217 | + * @param string $path 云存储文件路径 | ||
| 218 | + * @return string 文档类型,e.g: `appcation/json`,获取失败返回空字符串 | ||
| 219 | + */ | ||
| 220 | + public function getMimetype($path) | ||
| 221 | + { | ||
| 222 | + $params = $this->info($path, array('content-type')); | ||
| 223 | + if (isset($params['content-type'])) { | ||
| 224 | + return explode(';', $params['content-type'])[0]; | ||
| 225 | + } | ||
| 226 | + return ''; | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + /** | ||
| 230 | + * 删除文件或者目录 | ||
| 231 | + * | ||
| 232 | + * @param string $path 文件或目录在又拍云存储的路径 | ||
| 233 | + * @param bool $async 是否异步删除,默认为 false,表示同步删除。当需要批量删除大量文件时,必须选择异步删除 | ||
| 234 | + * | ||
| 235 | + * @return bool 删除成功返回 true,否则 false | ||
| 236 | + * @throws \Exception 删除不存在的文件将会抛出异常 | ||
| 237 | + */ | ||
| 238 | + public function delete($path, $async = false) | ||
| 239 | + { | ||
| 240 | + $req = new Rest($this->config); | ||
| 241 | + $req->request('DELETE', $path); | ||
| 242 | + if ($async) { | ||
| 243 | + $req->withHeader('x-upyun-async', 'true'); | ||
| 244 | + } | ||
| 245 | + $res = $req->send(); | ||
| 246 | + return $res->getStatusCode() === 200; | ||
| 247 | + } | ||
| 248 | + | ||
| 249 | + /** | ||
| 250 | + * 创建目录 | ||
| 251 | + * | ||
| 252 | + * @param string $path 需要在又拍云存储创建的目录路径 | ||
| 253 | + * | ||
| 254 | + * @return bool 创建成功返回 true,否则返回 false | ||
| 255 | + * @throws \Exception | ||
| 256 | + */ | ||
| 257 | + public function createDir($path) | ||
| 258 | + { | ||
| 259 | + $path = rtrim($path, '/') . '/'; | ||
| 260 | + $req = new Rest($this->config); | ||
| 261 | + $res = $req->request('POST', $path) | ||
| 262 | + ->withHeader('folder', 'true') | ||
| 263 | + ->send(); | ||
| 264 | + return $res->getStatusCode() === 200; | ||
| 265 | + } | ||
| 266 | + | ||
| 267 | + /** | ||
| 268 | + * 删除文件或者目录 | ||
| 269 | + * | ||
| 270 | + * @param string $path 需要被删除的云存储文件或目录路径 | ||
| 271 | + * | ||
| 272 | + * @return bool 成功返回 true,否则 false | ||
| 273 | + * @throws \Exception | ||
| 274 | + */ | ||
| 275 | + public function deleteDir($path) | ||
| 276 | + { | ||
| 277 | + return $this->delete($path); | ||
| 278 | + } | ||
| 279 | + | ||
| 280 | + /** | ||
| 281 | + * 获取目录下存储使用量 | ||
| 282 | + * | ||
| 283 | + * @param string $path 云存储目录路径,默认为根目录,表示整个云存储服务使用的空间大小 | ||
| 284 | + * @return string 存储使用量,单位字节 | ||
| 285 | + * @throws \Exception | ||
| 286 | + */ | ||
| 287 | + public function usage($path = '/') | ||
| 288 | + { | ||
| 289 | + $path = rtrim($path, '/') . '/'; | ||
| 290 | + $req = new Rest($this->config); | ||
| 291 | + $response = $req->request('GET', $path . '?usage') | ||
| 292 | + ->send(); | ||
| 293 | + | ||
| 294 | + return $response->getBody()->getContents(); | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + /** | ||
| 298 | + * 刷新缓存 | ||
| 299 | + * | ||
| 300 | + * @param array|string $urls 需要刷新的文件 url 列表 | ||
| 301 | + * | ||
| 302 | + * @return array 刷新失败的 url 列表,若全部刷新成功则为空数组 | ||
| 303 | + */ | ||
| 304 | + public function purge($urls) | ||
| 305 | + { | ||
| 306 | + $urlString = $urls; | ||
| 307 | + if (is_array($urls)) { | ||
| 308 | + $urlString = implode("\n", $urls); | ||
| 309 | + } | ||
| 310 | + | ||
| 311 | + $client = new Client([ | ||
| 312 | + 'timeout' => $this->config->timeout | ||
| 313 | + ]); | ||
| 314 | + $response = $client->request('POST', Config::ED_PURGE, [ | ||
| 315 | + 'headers' => Signature::getPurgeSignHeader($this->config, $urlString), | ||
| 316 | + 'form_params' => ['purge' => $urlString] | ||
| 317 | + ]); | ||
| 318 | + $result = json_decode($response->getBody()->getContents(), true); | ||
| 319 | + return $result['invalid_domain_of_url']; | ||
| 320 | + } | ||
| 321 | + | ||
| 322 | + /** | ||
| 323 | + * 异步云处理 | ||
| 324 | + * | ||
| 325 | + * 该方法是基于[又拍云云处理](http://docs.upyun.com/cloud/) 服务实现,可以实现音视频的转码、切片、剪辑;文件的压缩解压缩;文件拉取功能 | ||
| 326 | + * | ||
| 327 | + * 注意: | ||
| 328 | + * - 所有需要调用该方法处理的资源,必须已经上传到云存储服务 | ||
| 329 | + * - 使用 `process` 之前,必须配置 `config->processNotifyUrl`,否则会提交任务失败 | ||
| 330 | + * | ||
| 331 | + * 例如视频转码: | ||
| 332 | + * ``` | ||
| 333 | + * process(array( | ||
| 334 | + * array( | ||
| 335 | + * 'type' => 'video', // video 表示视频任务, audio 表示音频任务 | ||
| 336 | + * 'avopts' => '/s/240p(4:3)/as/1/r/30', // 处理参数,`s` 表示输出的分辨率,`r` 表示视频帧率,`as` 表示是否自动调整分辨率 | ||
| 337 | + * 'save_as' => '/video/240/new.mp4', // 新视频在又拍云存储的保存路径 | ||
| 338 | + * ), | ||
| 339 | + * ... // 同时还可以添加其他任务 | ||
| 340 | + * ), Upyun::$PROCESS_TYPE_MEDIA, $source) | ||
| 341 | + * ``` | ||
| 342 | + * | ||
| 343 | + * @param array $tasks 需要处理的任务 | ||
| 344 | + * @param string $type 异步云处理任务类型,可选值: | ||
| 345 | + * - `Upyun::$PROCESS_TYPE_MEDIA` 异步音视频处理 | ||
| 346 | + * - `Upyun::$PROCESS_TYPE_ZIP` 文件压缩 | ||
| 347 | + * - `Upyun::$PROCESS_TYPE_UNZIP` 文件解压 | ||
| 348 | + * - `Upyun::$PROCESS_TYPE_SYNC_FILE` 文件拉取 | ||
| 349 | + * - `Upyun::$PROCESS_TYPE_STITCH` 图片拼接 | ||
| 350 | + * @param string $source 可选参数,处理异步音视频任务时,需要传递该参数,表示需要处理的文件路径 | ||
| 351 | + * | ||
| 352 | + * @return array 任务 ID,提交了多少任务,便会返回多少任务 ID,与提交任务的顺序保持一致。可以通过任务 ID 查询处理进度。格式如下: | ||
| 353 | + * ``` | ||
| 354 | + * array( | ||
| 355 | + * '35f0148d414a688a275bf915ba7cebb2', | ||
| 356 | + * '98adbaa52b2f63d6d7f327a0ff223348', | ||
| 357 | + * ) | ||
| 358 | + * ``` | ||
| 359 | + * @throws \Exception | ||
| 360 | + */ | ||
| 361 | + public function process($tasks, $type, $source = '') | ||
| 362 | + { | ||
| 363 | + $video = new Api\Pretreat($this->config); | ||
| 364 | + | ||
| 365 | + $options = array(); | ||
| 366 | + switch($type) { | ||
| 367 | + case self::$PROCESS_TYPE_MEDIA: | ||
| 368 | + $options['accept'] = 'json'; | ||
| 369 | + $options['source'] = $source; | ||
| 370 | + break; | ||
| 371 | + case self::$PROCESS_TYPE_ZIP: | ||
| 372 | + $options['app_name'] = 'compress'; | ||
| 373 | + break; | ||
| 374 | + case self::$PROCESS_TYPE_UNZIP: | ||
| 375 | + $options['app_name'] = 'depress'; | ||
| 376 | + break; | ||
| 377 | + case self::$PROCESS_TYPE_SYNC_FILE: | ||
| 378 | + $options['app_name'] = 'spiderman'; | ||
| 379 | + break; | ||
| 380 | + case self::$PROCESS_TYPE_CONVERT: | ||
| 381 | + $options['app_name'] = 'uconvert'; | ||
| 382 | + break; | ||
| 383 | + case self::$PROCESS_TYPE_STITCH: | ||
| 384 | + $options['app_name'] = 'jigsaw'; | ||
| 385 | + break; | ||
| 386 | + default: | ||
| 387 | + throw new \Exception('upyun - not support process type.'); | ||
| 388 | + | ||
| 389 | + } | ||
| 390 | + return $video->process($tasks, $options); | ||
| 391 | + } | ||
| 392 | + | ||
| 393 | + /** | ||
| 394 | + * 查询异步云处理任务进度 | ||
| 395 | + * | ||
| 396 | + * 根据 `process` 方法返回的任务 ID,通过该访问查询处理进度 | ||
| 397 | + * | ||
| 398 | + * @param array $taskIds 任务 ID | ||
| 399 | + * | ||
| 400 | + * @return bool|array 查询失败返回布尔值 `false`,否则返回每个任务的百分比进度信息,格式如下: | ||
| 401 | + * ``` | ||
| 402 | + * array( | ||
| 403 | + * '35f0148d414a688a275bf915ba7cebb2' => 100, // 100 表示任务完成 | ||
| 404 | + * 'c3103189fa906a5354d29bd807e8dc51' => 35, | ||
| 405 | + * '98adbaa52b2f63d6d7f327a0ff223348' => null, // null 表示任务未开始,或异常 | ||
| 406 | + * ) | ||
| 407 | + * ``` | ||
| 408 | + */ | ||
| 409 | + public function queryProcessStatus($taskIds) | ||
| 410 | + { | ||
| 411 | + $video = new Api\Pretreat($this->config); | ||
| 412 | + return $video->query($taskIds, '/status/'); | ||
| 413 | + } | ||
| 414 | + | ||
| 415 | + /** | ||
| 416 | + * 查询异步云处理任务结果 | ||
| 417 | + * | ||
| 418 | + * 根据 `process` 方法返回的任务 ID,通过该访问查询处理结果,会包含每个任务详细信息 | ||
| 419 | + * @param array $taskIds 任务 ID | ||
| 420 | + * | ||
| 421 | + * @return bool|mixed 查询失败返回 `false`,否则返回每个任务的处理结果,格式如下: | ||
| 422 | + * ``` | ||
| 423 | + * array( | ||
| 424 | + * '9d9c32b63a1034834e77672c6f51f661' => array( | ||
| 425 | + * 'path' => array('/v2.mp4'), | ||
| 426 | + * 'signature' => '4042c1f07f546d28', | ||
| 427 | + * 'status_code' => 200, | ||
| 428 | + * 'service_name' => 'your_storage_service', | ||
| 429 | + * 'description' => 'OK', | ||
| 430 | + * 'task_id' => '9d9c32b63a1034834e77672c6f51f661', | ||
| 431 | + * 'timestamp' => 1472010684 | ||
| 432 | + * ) | ||
| 433 | + * ) | ||
| 434 | + * ``` | ||
| 435 | + */ | ||
| 436 | + public function queryProcessResult($taskIds) | ||
| 437 | + { | ||
| 438 | + $video = new Api\Pretreat($this->config); | ||
| 439 | + return $video->query($taskIds, '/result/'); | ||
| 440 | + } | ||
| 441 | + | ||
| 442 | + /** | ||
| 443 | + * 多个 m3u8 文件拼接 | ||
| 444 | + * @param array $files 保存在又拍云云存储中的多个 m3u8 文件路径 | ||
| 445 | + * @param string $saveAs 拼接生成的新 m3u8 文件保存路径 | ||
| 446 | + * | ||
| 447 | + * @return array 见 [m3u8 拼接 - 响应](http://docs.upyun.com/cloud/sync_video/#_3) | ||
| 448 | + */ | ||
| 449 | + public function m3u8Concat($files, $saveAs) | ||
| 450 | + { | ||
| 451 | + $p = new Api\SyncVideo($this->config); | ||
| 452 | + return $p->process([ | ||
| 453 | + 'm3u8s' => $files, | ||
| 454 | + 'save_as' => $saveAs, | ||
| 455 | + ], '/m3u8er/concat'); | ||
| 456 | + } | ||
| 457 | + | ||
| 458 | + /** | ||
| 459 | + * 单个 m3u8 文件剪辑 | ||
| 460 | + * @param string $file 需要剪辑的又拍云云存储中的 m3u8 文件路径 | ||
| 461 | + * @param string $saveAs 剪辑完成后新的 m3u8 文件保存路径 | ||
| 462 | + * @param array $slice 需要被保留或删除的片段。 | ||
| 463 | + * @param bool $isInclude 默认为 `true` 表示 `$slice` 参数描述的片段被保留,否则表示 `$slice` 参数描述的片段被删除 | ||
| 464 | + * @param bool $index 指定 `$slice` 参数的格式,默认为 `false` 表示使用时间范围描述片段,单位秒:`[<开始时间>, <结束时间>]`;`true` 表示使用 `m3u8` 文件的分片序号,从 0 开始,这种方式可以一次对多个片段操作 | ||
| 465 | + * | ||
| 466 | + * @return array 见 [m3u8 剪辑 - 响应](http://docs.upyun.com/cloud/sync_video/#_6) | ||
| 467 | + */ | ||
| 468 | + public function m3u8Clip($file, $saveAs, $slice = array(), $isInclude = true, $index = false) | ||
| 469 | + { | ||
| 470 | + $p = new Api\SyncVideo($this->config); | ||
| 471 | + $params = [ | ||
| 472 | + 'm3u8' => $file, | ||
| 473 | + 'save_as' => $saveAs, | ||
| 474 | + 'index' => $index, | ||
| 475 | + ]; | ||
| 476 | + if ($isInclude) { | ||
| 477 | + $params['include'] = $slice; | ||
| 478 | + } else { | ||
| 479 | + $params['exclude'] = $slice; | ||
| 480 | + } | ||
| 481 | + return $p->process($params, '/m3u8er/clip'); | ||
| 482 | + } | ||
| 483 | + | ||
| 484 | + /** | ||
| 485 | + * 获取单个 m3u8 文件描述信息 | ||
| 486 | + * @param string $file 又拍云云存储的中的 m3u8 文件路径 | ||
| 487 | + * | ||
| 488 | + * @return array 见 [获取 m3u8 信息 - 响应](http://docs.upyun.com/cloud/sync_video/#_6) | ||
| 489 | + */ | ||
| 490 | + public function m3u8Meta($file) | ||
| 491 | + { | ||
| 492 | + $p = new Api\SyncVideo($this->config); | ||
| 493 | + return $p->process([ | ||
| 494 | + 'm3u8' => $file, | ||
| 495 | + ], '/m3u8er/get_meta'); | ||
| 496 | + } | ||
| 497 | + | ||
| 498 | + /** | ||
| 499 | + * 视频截图,可以对 mp4、m3u8 等视频文件进行截图 | ||
| 500 | + * @param string $file 需要截图的又拍云云存储中的视频文件路径 | ||
| 501 | + * @param string $saveAs 截图保存路径 | ||
| 502 | + * @param string $point 截图时间点,`HH:MM:SS` 格式 | ||
| 503 | + * @param string $size 截图尺寸 `宽x高` 格式的字符串。默认和视频尺寸一致 | ||
| 504 | + * @param string $format 截图保存的格式,默认根据 `$saveAs` 参数的后缀生成,可以指定 `jpg | png | webp` 三种格式 | ||
| 505 | + * | ||
| 506 | + * @return array 见 [视频截图 - 响应](http://docs.upyun.com/cloud/sync_video/#m3u8_2) | ||
| 507 | + */ | ||
| 508 | + public function snapshot($file, $saveAs, $point, $size = '', $format = '') | ||
| 509 | + { | ||
| 510 | + $p = new Api\SyncVideo($this->config); | ||
| 511 | + $params = [ | ||
| 512 | + 'source' => $file, | ||
| 513 | + 'save_as' => $saveAs, | ||
| 514 | + 'point' => $point, | ||
| 515 | + ]; | ||
| 516 | + if ($size) { | ||
| 517 | + $params['size'] = $size; | ||
| 518 | + } | ||
| 519 | + if ($format) { | ||
| 520 | + $params['format'] = $format; | ||
| 521 | + } | ||
| 522 | + return $p->process($params, '/snapshot'); | ||
| 523 | + } | ||
| 524 | + | ||
| 525 | + /** | ||
| 526 | + * 获取音视频文件元信息 | ||
| 527 | + * @param string $file 又拍云云存储的中的音视频文件路径 | ||
| 528 | + * | ||
| 529 | + * @return array 见 [获取音视频文件信息 - 响应](http://docs.upyun.com/cloud/sync_video/#_16) | ||
| 530 | + */ | ||
| 531 | + public function avMeta($file) | ||
| 532 | + { | ||
| 533 | + $p = new Api\SyncVideo($this->config); | ||
| 534 | + return $p->process([ | ||
| 535 | + 'source' => $file, | ||
| 536 | + ], '/avmeta/get_meta'); | ||
| 537 | + } | ||
| 538 | +} |
addons/upyun/library/Upyun/Util.php
0 → 100644
| 1 | +<?php | ||
| 2 | +namespace Upyun; | ||
| 3 | + | ||
| 4 | +class Util | ||
| 5 | +{ | ||
| 6 | + public static function trim($str) | ||
| 7 | + { | ||
| 8 | + if (is_array($str)) { | ||
| 9 | + return array_map(array('Util', 'trim'), $str); | ||
| 10 | + } else { | ||
| 11 | + return trim($str); | ||
| 12 | + } | ||
| 13 | + } | ||
| 14 | + | ||
| 15 | + public static function getHeaderParams($headers, $otherParams = array()) | ||
| 16 | + { | ||
| 17 | + $params = []; | ||
| 18 | + $otherParams = array_map('strtolower', $otherParams); | ||
| 19 | + foreach ($headers as $header => $value) { | ||
| 20 | + $header = strtolower($header); | ||
| 21 | + if (strpos($header, 'x-upyun-') !== false) { | ||
| 22 | + $params[$header] = $value[0]; | ||
| 23 | + } else if (in_array($header, $otherParams)) { | ||
| 24 | + $params[$header] = $value[0]; | ||
| 25 | + } | ||
| 26 | + } | ||
| 27 | + return $params; | ||
| 28 | + } | ||
| 29 | + | ||
| 30 | + public static function parseDir($body) | ||
| 31 | + { | ||
| 32 | + $files = array(); | ||
| 33 | + if (!$body) { | ||
| 34 | + return array(); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + $lines = explode("\n", $body); | ||
| 38 | + foreach ($lines as $line) { | ||
| 39 | + $file = []; | ||
| 40 | + list($file['name'], $file['type'], $file['size'], $file['time']) = explode("\t", $line, 4); | ||
| 41 | + $files[] = $file; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + return $files; | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + public static function base64Json($params) | ||
| 48 | + { | ||
| 49 | + return base64_encode(json_encode($params, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + public static function stringifyHeaders($headers) | ||
| 53 | + { | ||
| 54 | + $return = array(); | ||
| 55 | + foreach ($headers as $key => $value) { | ||
| 56 | + $return[] = "$key: $value"; | ||
| 57 | + } | ||
| 58 | + return $return; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public static function md5Hash($resource) | ||
| 62 | + { | ||
| 63 | + rewind($resource); | ||
| 64 | + $ctx = hash_init('md5'); | ||
| 65 | + hash_update_stream($ctx, $resource); | ||
| 66 | + $md5 = hash_final($ctx); | ||
| 67 | + return $md5; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + /** | ||
| 71 | + * GuzzleHttp\Psr\Uri use `parse_url`,not good for utf-8, | ||
| 72 | + * So should `encodeURI` first, before `new Psr7\Request` | ||
| 73 | + * @see http://stackoverflow.com/questions/4929584/encodeuri-in-php | ||
| 74 | + */ | ||
| 75 | + public static function encodeURI($url) | ||
| 76 | + { | ||
| 77 | + $unescaped = array( | ||
| 78 | + '%2D'=>'-','%5F'=>'_','%2E'=>'.','%21'=>'!', '%7E'=>'~', | ||
| 79 | + '%2A'=>'*', '%27'=>"'", '%28'=>'(', '%29'=>')' | ||
| 80 | + ); | ||
| 81 | + $reserved = array( | ||
| 82 | + '%3B'=>';','%2C'=>',','%2F'=>'/','%3F'=>'?','%3A'=>':', | ||
| 83 | + '%40'=>'@','%26'=>'&','%3D'=>'=','%2B'=>'+','%24'=>'$' | ||
| 84 | + ); | ||
| 85 | + $score = array( | ||
| 86 | + '%23'=>'#' | ||
| 87 | + ); | ||
| 88 | + return strtr(rawurlencode($url), array_merge($reserved, $unescaped, $score)); | ||
| 89 | + } | ||
| 90 | +} |
application/.htaccess
0 → 100644
| 1 | +deny from all |
application/admin/behavior/AdminLog.php
0 → 100644
application/admin/command/Addon.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace app\admin\command; | ||
| 4 | + | ||
| 5 | +use think\addons\AddonException; | ||
| 6 | +use think\addons\Service; | ||
| 7 | +use think\Config; | ||
| 8 | +use think\console\Command; | ||
| 9 | +use think\console\Input; | ||
| 10 | +use think\console\input\Option; | ||
| 11 | +use think\console\Output; | ||
| 12 | +use think\Db; | ||
| 13 | +use think\Exception; | ||
| 14 | +use think\exception\PDOException; | ||
| 15 | + | ||
| 16 | +class Addon extends Command | ||
| 17 | +{ | ||
| 18 | + | ||
| 19 | + protected function configure() | ||
| 20 | + { | ||
| 21 | + $this | ||
| 22 | + ->setName('addon') | ||
| 23 | + ->addOption('name', 'a', Option::VALUE_REQUIRED, 'addon name', null) | ||
| 24 | + ->addOption('action', 'c', Option::VALUE_REQUIRED, 'action(create/enable/disable/install/uninstall/refresh/upgrade/package/move)', 'create') | ||
| 25 | + ->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override', null) | ||
| 26 | + ->addOption('release', 'r', Option::VALUE_OPTIONAL, 'addon release version', null) | ||
| 27 | + ->addOption('uid', 'u', Option::VALUE_OPTIONAL, 'fastadmin uid', null) | ||
| 28 | + ->addOption('token', 't', Option::VALUE_OPTIONAL, 'fastadmin token', null) | ||
| 29 | + ->addOption('local', 'l', Option::VALUE_OPTIONAL, 'local package', null) | ||
| 30 | + ->setDescription('Addon manager'); | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + protected function execute(Input $input, Output $output) | ||
| 34 | + { | ||
| 35 | + $name = $input->getOption('name') ?: ''; | ||
| 36 | + $action = $input->getOption('action') ?: ''; | ||
| 37 | + if (stripos($name, 'addons' . DS) !== false) { | ||
| 38 | + $name = explode(DS, $name)[1]; | ||
| 39 | + } | ||
| 40 | + //强制覆盖 | ||
| 41 | + $force = $input->getOption('force'); | ||
| 42 | + //版本 | ||
| 43 | + $release = $input->getOption('release') ?: ''; | ||
| 44 | + //uid | ||
| 45 | + $uid = $input->getOption('uid') ?: ''; | ||
| 46 | + //token | ||
| 47 | + $token = $input->getOption('token') ?: ''; | ||
| 48 | + | ||
| 49 | + include dirname(__DIR__) . DS . 'common.php'; | ||
| 50 | + | ||
| 51 | + if (!$name) { | ||
| 52 | + throw new Exception('Addon name could not be empty'); | ||
| 53 | + } | ||
| 54 | + if (!$action || !in_array($action, ['create', 'disable', 'enable', 'install', 'uninstall', 'refresh', 'upgrade', 'package', 'move'])) { | ||
| 55 | + throw new Exception('Please input correct action name'); | ||
| 56 | + } | ||
| 57 | + | ||
| 58 | + // 查询一次SQL,判断连接是否正常 | ||
| 59 | + Db::execute("SELECT 1"); | ||
| 60 | + | ||
| 61 | + $addonDir = ADDON_PATH . $name . DS; | ||
| 62 | + switch ($action) { | ||
| 63 | + case 'create': | ||
| 64 | + //非覆盖模式时如果存在则报错 | ||
| 65 | + if (is_dir($addonDir) && !$force) { | ||
| 66 | + throw new Exception("addon already exists!\nIf you need to create again, use the parameter --force=true "); | ||
| 67 | + } | ||
| 68 | + //如果存在先移除 | ||
| 69 | + if (is_dir($addonDir)) { | ||
| 70 | + rmdirs($addonDir); | ||
| 71 | + } | ||
| 72 | + mkdir($addonDir, 0755, true); | ||
| 73 | + mkdir($addonDir . DS . 'controller', 0755, true); | ||
| 74 | + $menuList = \app\common\library\Menu::export($name); | ||
| 75 | + $createMenu = $this->getCreateMenu($menuList); | ||
| 76 | + $prefix = Config::get('database.prefix'); | ||
| 77 | + $createTableSql = ''; | ||
| 78 | + try { | ||
| 79 | + $result = Db::query("SHOW CREATE TABLE `" . $prefix . $name . "`;"); | ||
| 80 | + if (isset($result[0]) && isset($result[0]['Create Table'])) { | ||
| 81 | + $createTableSql = $result[0]['Create Table']; | ||
| 82 | + } | ||
| 83 | + } catch (PDOException $e) { | ||
| 84 | + | ||
| 85 | + } | ||
| 86 | + | ||
| 87 | + $data = [ | ||
| 88 | + 'name' => $name, | ||
| 89 | + 'addon' => $name, | ||
| 90 | + 'addonClassName' => ucfirst($name), | ||
| 91 | + 'addonInstallMenu' => $createMenu ? "\$menu = " . var_export_short($createMenu) . ";\n\tMenu::create(\$menu);" : '', | ||
| 92 | + 'addonUninstallMenu' => $menuList ? 'Menu::delete("' . $name . '");' : '', | ||
| 93 | + 'addonEnableMenu' => $menuList ? 'Menu::enable("' . $name . '");' : '', | ||
| 94 | + 'addonDisableMenu' => $menuList ? 'Menu::disable("' . $name . '");' : '', | ||
| 95 | + ]; | ||
| 96 | + $this->writeToFile("addon", $data, $addonDir . ucfirst($name) . '.php'); | ||
| 97 | + $this->writeToFile("config", $data, $addonDir . 'config.php'); | ||
| 98 | + $this->writeToFile("info", $data, $addonDir . 'info.ini'); | ||
| 99 | + $this->writeToFile("controller", $data, $addonDir . 'controller' . DS . 'Index.php'); | ||
| 100 | + if ($createTableSql) { | ||
| 101 | + $createTableSql = str_replace("`" . $prefix, '`__PREFIX__', $createTableSql); | ||
| 102 | + file_put_contents($addonDir . 'install.sql', $createTableSql); | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | + $output->info("Create Successed!"); | ||
| 106 | + break; | ||
| 107 | + case 'disable': | ||
| 108 | + case 'enable': | ||
| 109 | + try { | ||
| 110 | + //调用启用、禁用的方法 | ||
| 111 | + Service::$action($name, 0); | ||
| 112 | + } catch (AddonException $e) { | ||
| 113 | + if ($e->getCode() != -3) { | ||
| 114 | + throw new Exception($e->getMessage()); | ||
| 115 | + } | ||
| 116 | + if (!$force) { | ||
| 117 | + //如果有冲突文件则提醒 | ||
| 118 | + $data = $e->getData(); | ||
| 119 | + foreach ($data['conflictlist'] as $k => $v) { | ||
| 120 | + $output->warning($v); | ||
| 121 | + } | ||
| 122 | + $output->info("Are you sure you want to " . ($action == 'enable' ? 'override' : 'delete') . " all those files? Type 'yes' to continue: "); | ||
| 123 | + $line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r')); | ||
| 124 | + if (trim($line) != 'yes') { | ||
| 125 | + throw new Exception("Operation is aborted!"); | ||
| 126 | + } | ||
| 127 | + } | ||
| 128 | + //调用启用、禁用的方法 | ||
| 129 | + Service::$action($name, 1); | ||
| 130 | + } catch (Exception $e) { | ||
| 131 | + throw new Exception($e->getMessage()); | ||
| 132 | + } | ||
| 133 | + $output->info(ucfirst($action) . " Successed!"); | ||
| 134 | + break; | ||
| 135 | + case 'install': | ||
| 136 | + //非覆盖模式时如果存在则报错 | ||
| 137 | + if (is_dir($addonDir) && !$force) { | ||
| 138 | + throw new Exception("addon already exists!\nIf you need to install again, use the parameter --force=true "); | ||
| 139 | + } | ||
| 140 | + //如果存在先移除 | ||
| 141 | + if (is_dir($addonDir)) { | ||
| 142 | + rmdirs($addonDir); | ||
| 143 | + } | ||
| 144 | + // 获取本地路径 | ||
| 145 | + $local = $input->getOption('local'); | ||
| 146 | + try { | ||
| 147 | + Service::install($name, 0, ['version' => $release], $local); | ||
| 148 | + } catch (AddonException $e) { | ||
| 149 | + if ($e->getCode() != -3) { | ||
| 150 | + throw new Exception($e->getMessage()); | ||
| 151 | + } | ||
| 152 | + if (!$force) { | ||
| 153 | + //如果有冲突文件则提醒 | ||
| 154 | + $data = $e->getData(); | ||
| 155 | + foreach ($data['conflictlist'] as $k => $v) { | ||
| 156 | + $output->warning($v); | ||
| 157 | + } | ||
| 158 | + $output->info("Are you sure you want to override all those files? Type 'yes' to continue: "); | ||
| 159 | + $line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r')); | ||
| 160 | + if (trim($line) != 'yes') { | ||
| 161 | + throw new Exception("Operation is aborted!"); | ||
| 162 | + } | ||
| 163 | + } | ||
| 164 | + Service::install($name, 1, ['version' => $release, 'uid' => $uid, 'token' => $token], $local); | ||
| 165 | + } catch (Exception $e) { | ||
| 166 | + throw new Exception($e->getMessage()); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + $output->info("Install Successed!"); | ||
| 170 | + break; | ||
| 171 | + case 'uninstall': | ||
| 172 | + //非覆盖模式时如果存在则报错 | ||
| 173 | + if (!$force) { | ||
| 174 | + throw new Exception("If you need to uninstall addon, use the parameter --force=true "); | ||
| 175 | + } | ||
| 176 | + try { | ||
| 177 | + Service::uninstall($name, 0); | ||
| 178 | + } catch (AddonException $e) { | ||
| 179 | + if ($e->getCode() != -3) { | ||
| 180 | + throw new Exception($e->getMessage()); | ||
| 181 | + } | ||
| 182 | + if (!$force) { | ||
| 183 | + //如果有冲突文件则提醒 | ||
| 184 | + $data = $e->getData(); | ||
| 185 | + foreach ($data['conflictlist'] as $k => $v) { | ||
| 186 | + $output->warning($v); | ||
| 187 | + } | ||
| 188 | + $output->info("Are you sure you want to delete all those files? Type 'yes' to continue: "); | ||
| 189 | + $line = fgets(defined('STDIN') ? STDIN : fopen('php://stdin', 'r')); | ||
| 190 | + if (trim($line) != 'yes') { | ||
| 191 | + throw new Exception("Operation is aborted!"); | ||
| 192 | + } | ||
| 193 | + } | ||
| 194 | + Service::uninstall($name, 1); | ||
| 195 | + } catch (Exception $e) { | ||
| 196 | + throw new Exception($e->getMessage()); | ||
| 197 | + } | ||
| 198 | + | ||
| 199 | + $output->info("Uninstall Successed!"); | ||
| 200 | + break; | ||
| 201 | + case 'refresh': | ||
| 202 | + Service::refresh(); | ||
| 203 | + $output->info("Refresh Successed!"); | ||
| 204 | + break; | ||
| 205 | + case 'upgrade': | ||
| 206 | + Service::upgrade($name, ['version' => $release, 'uid' => $uid, 'token' => $token]); | ||
| 207 | + $output->info("Upgrade Successed!"); | ||
| 208 | + break; | ||
| 209 | + case 'package': | ||
| 210 | + $infoFile = $addonDir . 'info.ini'; | ||
| 211 | + if (!is_file($infoFile)) { | ||
| 212 | + throw new Exception(__('Addon info file was not found')); | ||
| 213 | + } | ||
| 214 | + | ||
| 215 | + $info = get_addon_info($name); | ||
| 216 | + if (!$info) { | ||
| 217 | + throw new Exception(__('Addon info file data incorrect')); | ||
| 218 | + } | ||
| 219 | + $infoname = isset($info['name']) ? $info['name'] : ''; | ||
| 220 | + if (!$infoname || !preg_match("/^[a-z]+$/i", $infoname) || $infoname != $name) { | ||
| 221 | + throw new Exception(__('Addon info name incorrect')); | ||
| 222 | + } | ||
| 223 | + | ||
| 224 | + $infoversion = isset($info['version']) ? $info['version'] : ''; | ||
| 225 | + if (!$infoversion || !preg_match("/^\d+\.\d+\.\d+$/i", $infoversion)) { | ||
| 226 | + throw new Exception(__('Addon info version incorrect')); | ||
| 227 | + } | ||
| 228 | + | ||
| 229 | + $addonTmpDir = RUNTIME_PATH . 'addons' . DS; | ||
| 230 | + if (!is_dir($addonTmpDir)) { | ||
| 231 | + @mkdir($addonTmpDir, 0755, true); | ||
| 232 | + } | ||
| 233 | + $addonFile = $addonTmpDir . $infoname . '-' . $infoversion . '.zip'; | ||
| 234 | + if (!class_exists('ZipArchive')) { | ||
| 235 | + throw new Exception(__('ZinArchive not install')); | ||
| 236 | + } | ||
| 237 | + $zip = new \ZipArchive; | ||
| 238 | + $zip->open($addonFile, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); | ||
| 239 | + | ||
| 240 | + $files = new \RecursiveIteratorIterator( | ||
| 241 | + new \RecursiveDirectoryIterator($addonDir), \RecursiveIteratorIterator::LEAVES_ONLY | ||
| 242 | + ); | ||
| 243 | + | ||
| 244 | + foreach ($files as $name => $file) { | ||
| 245 | + if (!$file->isDir()) { | ||
| 246 | + $filePath = $file->getRealPath(); | ||
| 247 | + $relativePath = str_replace(DS, '/', substr($filePath, strlen($addonDir))); | ||
| 248 | + if (!in_array($file->getFilename(), ['.git', '.DS_Store', 'Thumbs.db'])) { | ||
| 249 | + $zip->addFile($filePath, $relativePath); | ||
| 250 | + } | ||
| 251 | + } | ||
| 252 | + } | ||
| 253 | + $zip->close(); | ||
| 254 | + $output->info("Package Successed!"); | ||
| 255 | + break; | ||
| 256 | + case 'move': | ||
| 257 | + $movePath = [ | ||
| 258 | + 'adminOnlySelfDir' => ['admin/behavior', 'admin/controller', 'admin/library', 'admin/model', 'admin/validate', 'admin/view'], | ||
| 259 | + 'adminAllSubDir' => ['admin/lang'], | ||
| 260 | + 'publicDir' => ['public/assets/addons', 'public/assets/js/backend'] | ||
| 261 | + ]; | ||
| 262 | + $paths = []; | ||
| 263 | + $appPath = str_replace('/', DS, APP_PATH); | ||
| 264 | + $rootPath = str_replace('/', DS, ROOT_PATH); | ||
| 265 | + foreach ($movePath as $k => $items) { | ||
| 266 | + switch ($k) { | ||
| 267 | + case 'adminOnlySelfDir': | ||
| 268 | + foreach ($items as $v) { | ||
| 269 | + $v = str_replace('/', DS, $v); | ||
| 270 | + $oldPath = $appPath . $v . DS . $name; | ||
| 271 | + $newPath = $rootPath . "addons" . DS . $name . DS . "application" . DS . $v . DS . $name; | ||
| 272 | + $paths[$oldPath] = $newPath; | ||
| 273 | + } | ||
| 274 | + break; | ||
| 275 | + case 'adminAllSubDir': | ||
| 276 | + foreach ($items as $v) { | ||
| 277 | + $v = str_replace('/', DS, $v); | ||
| 278 | + $vPath = $appPath . $v; | ||
| 279 | + $list = scandir($vPath); | ||
| 280 | + foreach ($list as $_v) { | ||
| 281 | + if (!in_array($_v, ['.', '..']) && is_dir($vPath . DS . $_v)) { | ||
| 282 | + $oldPath = $appPath . $v . DS . $_v . DS . $name; | ||
| 283 | + $newPath = $rootPath . "addons" . DS . $name . DS . "application" . DS . $v . DS . $_v . DS . $name; | ||
| 284 | + $paths[$oldPath] = $newPath; | ||
| 285 | + } | ||
| 286 | + } | ||
| 287 | + } | ||
| 288 | + break; | ||
| 289 | + case 'publicDir': | ||
| 290 | + foreach ($items as $v) { | ||
| 291 | + $v = str_replace('/', DS, $v); | ||
| 292 | + $oldPath = $rootPath . $v . DS . $name; | ||
| 293 | + $newPath = $rootPath . 'addons' . DS . $name . DS . $v . DS . $name; | ||
| 294 | + $paths[$oldPath] = $newPath; | ||
| 295 | + } | ||
| 296 | + break; | ||
| 297 | + } | ||
| 298 | + } | ||
| 299 | + foreach ($paths as $oldPath => $newPath) { | ||
| 300 | + if (is_dir($oldPath)) { | ||
| 301 | + if ($force) { | ||
| 302 | + if (is_dir($newPath)) { | ||
| 303 | + $list = scandir($newPath); | ||
| 304 | + foreach ($list as $_v) { | ||
| 305 | + if (!in_array($_v, ['.', '..'])) { | ||
| 306 | + $file = $newPath . DS . $_v; | ||
| 307 | + @chmod($file, 0777); | ||
| 308 | + @unlink($file); | ||
| 309 | + } | ||
| 310 | + } | ||
| 311 | + @rmdir($newPath); | ||
| 312 | + } | ||
| 313 | + } | ||
| 314 | + copydirs($oldPath, $newPath); | ||
| 315 | + } | ||
| 316 | + } | ||
| 317 | + break; | ||
| 318 | + default: | ||
| 319 | + break; | ||
| 320 | + } | ||
| 321 | + } | ||
| 322 | + | ||
| 323 | + /** | ||
| 324 | + * 获取创建菜单的数组 | ||
| 325 | + * @param array $menu | ||
| 326 | + * @return array | ||
| 327 | + */ | ||
| 328 | + protected function getCreateMenu($menu) | ||
| 329 | + { | ||
| 330 | + $result = []; | ||
| 331 | + foreach ($menu as $k => & $v) { | ||
| 332 | + $arr = [ | ||
| 333 | + 'name' => $v['name'], | ||
| 334 | + 'title' => $v['title'], | ||
| 335 | + ]; | ||
| 336 | + if ($v['icon'] != 'fa fa-circle-o') { | ||
| 337 | + $arr['icon'] = $v['icon']; | ||
| 338 | + } | ||
| 339 | + if ($v['ismenu']) { | ||
| 340 | + $arr['ismenu'] = $v['ismenu']; | ||
| 341 | + } | ||
| 342 | + if (isset($v['childlist']) && $v['childlist']) { | ||
| 343 | + $arr['sublist'] = $this->getCreateMenu($v['childlist']); | ||
| 344 | + } | ||
| 345 | + $result[] = $arr; | ||
| 346 | + } | ||
| 347 | + return $result; | ||
| 348 | + } | ||
| 349 | + | ||
| 350 | + /** | ||
| 351 | + * 写入到文件 | ||
| 352 | + * @param string $name | ||
| 353 | + * @param array $data | ||
| 354 | + * @param string $pathname | ||
| 355 | + * @return mixed | ||
| 356 | + */ | ||
| 357 | + protected function writeToFile($name, $data, $pathname) | ||
| 358 | + { | ||
| 359 | + $search = $replace = []; | ||
| 360 | + foreach ($data as $k => $v) { | ||
| 361 | + $search[] = "{%{$k}%}"; | ||
| 362 | + $replace[] = $v; | ||
| 363 | + } | ||
| 364 | + $stub = file_get_contents($this->getStub($name)); | ||
| 365 | + $content = str_replace($search, $replace, $stub); | ||
| 366 | + | ||
| 367 | + if (!is_dir(dirname($pathname))) { | ||
| 368 | + mkdir(strtolower(dirname($pathname)), 0755, true); | ||
| 369 | + } | ||
| 370 | + return file_put_contents($pathname, $content); | ||
| 371 | + } | ||
| 372 | + | ||
| 373 | + /** | ||
| 374 | + * 获取基础模板 | ||
| 375 | + * @param string $name | ||
| 376 | + * @return string | ||
| 377 | + */ | ||
| 378 | + protected function getStub($name) | ||
| 379 | + { | ||
| 380 | + return __DIR__ . '/Addon/stubs/' . $name . '.stub'; | ||
| 381 | + } | ||
| 382 | + | ||
| 383 | +} |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace addons\{%name%}; | ||
| 4 | + | ||
| 5 | +use app\common\library\Menu; | ||
| 6 | +use think\Addons; | ||
| 7 | + | ||
| 8 | +/** | ||
| 9 | + * 插件 | ||
| 10 | + */ | ||
| 11 | +class {%addonClassName%} extends Addons | ||
| 12 | +{ | ||
| 13 | + | ||
| 14 | + /** | ||
| 15 | + * 插件安装方法 | ||
| 16 | + * @return bool | ||
| 17 | + */ | ||
| 18 | + public function install() | ||
| 19 | + { | ||
| 20 | + {%addonInstallMenu%} | ||
| 21 | + return true; | ||
| 22 | + } | ||
| 23 | + | ||
| 24 | + /** | ||
| 25 | + * 插件卸载方法 | ||
| 26 | + * @return bool | ||
| 27 | + */ | ||
| 28 | + public function uninstall() | ||
| 29 | + { | ||
| 30 | + {%addonUninstallMenu%} | ||
| 31 | + return true; | ||
| 32 | + } | ||
| 33 | + | ||
| 34 | + /** | ||
| 35 | + * 插件启用方法 | ||
| 36 | + * @return bool | ||
| 37 | + */ | ||
| 38 | + public function enable() | ||
| 39 | + { | ||
| 40 | + {%addonEnableMenu%} | ||
| 41 | + return true; | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * 插件禁用方法 | ||
| 46 | + * @return bool | ||
| 47 | + */ | ||
| 48 | + public function disable() | ||
| 49 | + { | ||
| 50 | + {%addonDisableMenu%} | ||
| 51 | + return true; | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * 实现钩子方法 | ||
| 56 | + * @return mixed | ||
| 57 | + */ | ||
| 58 | + public function testhook($param) | ||
| 59 | + { | ||
| 60 | + // 调用钩子时候的参数信息 | ||
| 61 | + print_r($param); | ||
| 62 | + // 当前插件的配置信息,配置信息存在当前目录的config.php文件中,见下方 | ||
| 63 | + print_r($this->getConfig()); | ||
| 64 | + // 可以返回模板,模板文件默认读取的为插件目录中的文件。模板名不能为空! | ||
| 65 | + //return $this->fetch('view/info'); | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | +} |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +return [ | ||
| 4 | + [ | ||
| 5 | + //配置唯一标识 | ||
| 6 | + 'name' => 'usernmae', | ||
| 7 | + //显示的标题 | ||
| 8 | + 'title' => '用户名', | ||
| 9 | + //类型 | ||
| 10 | + 'type' => 'string', | ||
| 11 | + //数据字典 | ||
| 12 | + 'content' => [ | ||
| 13 | + ], | ||
| 14 | + //值 | ||
| 15 | + 'value' => '', | ||
| 16 | + //验证规则 | ||
| 17 | + 'rule' => 'required', | ||
| 18 | + //错误消息 | ||
| 19 | + 'msg' => '', | ||
| 20 | + //提示消息 | ||
| 21 | + 'tip' => '', | ||
| 22 | + //成功消息 | ||
| 23 | + 'ok' => '', | ||
| 24 | + //扩展信息 | ||
| 25 | + 'extend' => '' | ||
| 26 | + ], | ||
| 27 | + [ | ||
| 28 | + 'name' => 'password', | ||
| 29 | + 'title' => '密码', | ||
| 30 | + 'type' => 'string', | ||
| 31 | + 'content' => [ | ||
| 32 | + ], | ||
| 33 | + 'value' => '', | ||
| 34 | + 'rule' => 'required', | ||
| 35 | + 'msg' => '', | ||
| 36 | + 'tip' => '', | ||
| 37 | + 'ok' => '', | ||
| 38 | + 'extend' => '' | ||
| 39 | + ], | ||
| 40 | +]; |
application/admin/command/Api.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace app\admin\command; | ||
| 4 | + | ||
| 5 | +use app\admin\command\Api\library\Builder; | ||
| 6 | +use think\Config; | ||
| 7 | +use think\console\Command; | ||
| 8 | +use think\console\Input; | ||
| 9 | +use think\console\input\Option; | ||
| 10 | +use think\console\Output; | ||
| 11 | +use think\Exception; | ||
| 12 | + | ||
| 13 | +class Api extends Command | ||
| 14 | +{ | ||
| 15 | + protected function configure() | ||
| 16 | + { | ||
| 17 | + $site = Config::get('site'); | ||
| 18 | + $this | ||
| 19 | + ->setName('api') | ||
| 20 | + ->addOption('url', 'u', Option::VALUE_OPTIONAL, 'default api url', '') | ||
| 21 | + ->addOption('module', 'm', Option::VALUE_OPTIONAL, 'module name(admin/index/api)', 'api') | ||
| 22 | + ->addOption('output', 'o', Option::VALUE_OPTIONAL, 'output index file name', 'api.html') | ||
| 23 | + ->addOption('template', 'e', Option::VALUE_OPTIONAL, '', 'index.html') | ||
| 24 | + ->addOption('force', 'f', Option::VALUE_OPTIONAL, 'force override general file', false) | ||
| 25 | + ->addOption('title', 't', Option::VALUE_OPTIONAL, 'document title', $site['name']) | ||
| 26 | + ->addOption('author', 'a', Option::VALUE_OPTIONAL, 'document author', $site['name']) | ||
| 27 | + ->addOption('class', 'c', Option::VALUE_OPTIONAL | Option::VALUE_IS_ARRAY, 'extend class', null) | ||
| 28 | + ->addOption('language', 'l', Option::VALUE_OPTIONAL, 'language', 'zh-cn') | ||
| 29 | + ->setDescription('Build Api document from controller'); | ||
| 30 | + } | ||
| 31 | + | ||
| 32 | + protected function execute(Input $input, Output $output) | ||
| 33 | + { | ||
| 34 | + $apiDir = __DIR__ . DS . 'Api' . DS; | ||
| 35 | + | ||
| 36 | + $force = $input->getOption('force'); | ||
| 37 | + $url = $input->getOption('url'); | ||
| 38 | + $language = $input->getOption('language'); | ||
| 39 | + $language = $language ? $language : 'zh-cn'; | ||
| 40 | + $langFile = $apiDir . 'lang' . DS . $language . '.php'; | ||
| 41 | + if (!is_file($langFile)) { | ||
| 42 | + throw new Exception('language file not found'); | ||
| 43 | + } | ||
| 44 | + $lang = include_once $langFile; | ||
| 45 | + // 目标目录 | ||
| 46 | + $output_dir = ROOT_PATH . 'public' . DS; | ||
| 47 | + $output_file = $output_dir . $input->getOption('output'); | ||
| 48 | + if (is_file($output_file) && !$force) { | ||
| 49 | + throw new Exception("api index file already exists!\nIf you need to rebuild again, use the parameter --force=true "); | ||
| 50 | + } | ||
| 51 | + // 模板文件 | ||
| 52 | + $template_dir = $apiDir . 'template' . DS; | ||
| 53 | + $template_file = $template_dir . $input->getOption('template'); | ||
| 54 | + if (!is_file($template_file)) { | ||
| 55 | + throw new Exception('template file not found'); | ||
| 56 | + } | ||
| 57 | + // 额外的类 | ||
| 58 | + $classes = $input->getOption('class'); | ||
| 59 | + // 标题 | ||
| 60 | + $title = $input->getOption('title'); | ||
| 61 | + // 作者 | ||
| 62 | + $author = $input->getOption('author'); | ||
| 63 | + // 模块 | ||
| 64 | + $module = $input->getOption('module'); | ||
| 65 | + | ||
| 66 | + $moduleDir = APP_PATH . $module . DS; | ||
| 67 | + if (!is_dir($moduleDir)) { | ||
| 68 | + throw new Exception('module not found'); | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + if (version_compare(PHP_VERSION, '7.0.0', '<')) { | ||
| 72 | + if (extension_loaded('Zend OPcache')) { | ||
| 73 | + $configuration = opcache_get_configuration(); | ||
| 74 | + $directives = $configuration['directives']; | ||
| 75 | + $configName = request()->isCli() ? 'opcache.enable_cli' : 'opcache.enable'; | ||
| 76 | + if (!$directives[$configName]) { | ||
| 77 | + throw new Exception("Please make sure {$configName} is turned on, Get help:https://forum.fastadmin.net/d/1321"); | ||
| 78 | + } | ||
| 79 | + } else { | ||
| 80 | + throw new Exception("Please make sure opcache already enabled, Get help:https://forum.fastadmin.net/d/1321"); | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + $controllerDir = $moduleDir . Config::get('url_controller_layer') . DS; | ||
| 85 | + $files = new \RecursiveIteratorIterator( | ||
| 86 | + new \RecursiveDirectoryIterator($controllerDir), | ||
| 87 | + \RecursiveIteratorIterator::LEAVES_ONLY | ||
| 88 | + ); | ||
| 89 | + | ||
| 90 | + foreach ($files as $name => $file) { | ||
| 91 | + if (!$file->isDir() && $file->getExtension() == 'php') { | ||
| 92 | + $filePath = $file->getRealPath(); | ||
| 93 | + $classes[] = $this->get_class_from_file($filePath); | ||
| 94 | + } | ||
| 95 | + } | ||
| 96 | + $classes = array_unique(array_filter($classes)); | ||
| 97 | + | ||
| 98 | + $config = [ | ||
| 99 | + 'sitename' => config('site.name'), | ||
| 100 | + 'title' => $title, | ||
| 101 | + 'author' => $author, | ||
| 102 | + 'description' => '', | ||
| 103 | + 'apiurl' => $url, | ||
| 104 | + 'language' => $language, | ||
| 105 | + ]; | ||
| 106 | + $builder = new Builder($classes); | ||
| 107 | + $content = $builder->render($template_file, ['config' => $config, 'lang' => $lang]); | ||
| 108 | + | ||
| 109 | + if (!file_put_contents($output_file, $content)) { | ||
| 110 | + throw new Exception('Cannot save the content to ' . $output_file); | ||
| 111 | + } | ||
| 112 | + $output->info("Build Successed!"); | ||
| 113 | + } | ||
| 114 | + | ||
| 115 | + /** | ||
| 116 | + * get full qualified class name | ||
| 117 | + * | ||
| 118 | + * @param string $path_to_file | ||
| 119 | + * @return string | ||
| 120 | + * @author JBYRNE http://jarretbyrne.com/2015/06/197/ | ||
| 121 | + */ | ||
| 122 | + protected function get_class_from_file($path_to_file) | ||
| 123 | + { | ||
| 124 | + //Grab the contents of the file | ||
| 125 | + $contents = file_get_contents($path_to_file); | ||
| 126 | + | ||
| 127 | + //Start with a blank namespace and class | ||
| 128 | + $namespace = $class = ""; | ||
| 129 | + | ||
| 130 | + //Set helper values to know that we have found the namespace/class token and need to collect the string values after them | ||
| 131 | + $getting_namespace = $getting_class = false; | ||
| 132 | + | ||
| 133 | + //Go through each token and evaluate it as necessary | ||
| 134 | + foreach (token_get_all($contents) as $token) { | ||
| 135 | + | ||
| 136 | + //If this token is the namespace declaring, then flag that the next tokens will be the namespace name | ||
| 137 | + if (is_array($token) && $token[0] == T_NAMESPACE) { | ||
| 138 | + $getting_namespace = true; | ||
| 139 | + } | ||
| 140 | + | ||
| 141 | + //If this token is the class declaring, then flag that the next tokens will be the class name | ||
| 142 | + if (is_array($token) && $token[0] == T_CLASS) { | ||
| 143 | + $getting_class = true; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + //While we're grabbing the namespace name... | ||
| 147 | + if ($getting_namespace === true) { | ||
| 148 | + | ||
| 149 | + //If the token is a string or the namespace separator... | ||
| 150 | + if (is_array($token) && in_array($token[0], [T_STRING, T_NS_SEPARATOR])) { | ||
| 151 | + | ||
| 152 | + //Append the token's value to the name of the namespace | ||
| 153 | + $namespace .= $token[1]; | ||
| 154 | + } elseif ($token === ';') { | ||
| 155 | + | ||
| 156 | + //If the token is the semicolon, then we're done with the namespace declaration | ||
| 157 | + $getting_namespace = false; | ||
| 158 | + } | ||
| 159 | + } | ||
| 160 | + | ||
| 161 | + //While we're grabbing the class name... | ||
| 162 | + if ($getting_class === true) { | ||
| 163 | + | ||
| 164 | + //If the token is a string, it's the name of the class | ||
| 165 | + if (is_array($token) && $token[0] == T_STRING) { | ||
| 166 | + | ||
| 167 | + //Store the token's value as the class name | ||
| 168 | + $class = $token[1]; | ||
| 169 | + | ||
| 170 | + //Got what we need, stope here | ||
| 171 | + break; | ||
| 172 | + } | ||
| 173 | + } | ||
| 174 | + } | ||
| 175 | + | ||
| 176 | + //Build the fully-qualified class name and return it | ||
| 177 | + return $namespace ? $namespace . '\\' . $class : $class; | ||
| 178 | + } | ||
| 179 | +} |
application/admin/command/Api/lang/zh-cn.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +return [ | ||
| 4 | + 'Info' => '基础信息', | ||
| 5 | + 'Sandbox' => '在线测试', | ||
| 6 | + 'Sampleoutput' => '返回示例', | ||
| 7 | + 'Headers' => 'Headers', | ||
| 8 | + 'Parameters' => '参数', | ||
| 9 | + 'Body' => '正文', | ||
| 10 | + 'Name' => '名称', | ||
| 11 | + 'Type' => '类型', | ||
| 12 | + 'Required' => '必选', | ||
| 13 | + 'Description' => '描述', | ||
| 14 | + 'Send' => '提交', | ||
| 15 | + 'Reset' => '重置', | ||
| 16 | + 'Tokentips' => 'Token在会员注册或登录后都会返回,WEB端同时存在于Cookie中', | ||
| 17 | + 'Apiurltips' => 'API接口URL', | ||
| 18 | + 'Savetips' => '点击保存后Token和Api url都将保存在本地Localstorage中', | ||
| 19 | + 'ReturnHeaders' => '响应头', | ||
| 20 | + 'ReturnParameters' => '返回参数', | ||
| 21 | + 'Response' => '响应输出', | ||
| 22 | +]; |
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace app\admin\command\Api\library; | ||
| 4 | + | ||
| 5 | +use think\Config; | ||
| 6 | + | ||
| 7 | +/** | ||
| 8 | + * @website https://github.com/calinrada/php-apidoc | ||
| 9 | + * @author Calin Rada <rada.calin@gmail.com> | ||
| 10 | + * @author Karson <karsonzhang@163.com> | ||
| 11 | + */ | ||
| 12 | +class Builder | ||
| 13 | +{ | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * | ||
| 17 | + * @var \think\View | ||
| 18 | + */ | ||
| 19 | + public $view = null; | ||
| 20 | + | ||
| 21 | + /** | ||
| 22 | + * parse classes | ||
| 23 | + * @var array | ||
| 24 | + */ | ||
| 25 | + protected $classes = []; | ||
| 26 | + | ||
| 27 | + /** | ||
| 28 | + * | ||
| 29 | + * @param array $classes | ||
| 30 | + */ | ||
| 31 | + public function __construct($classes = []) | ||
| 32 | + { | ||
| 33 | + $this->classes = array_merge($this->classes, $classes); | ||
| 34 | + $this->view = new \think\View(Config::get('template'), Config::get('view_replace_str')); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + protected function extractAnnotations() | ||
| 38 | + { | ||
| 39 | + foreach ($this->classes as $class) { | ||
| 40 | + $classAnnotation = Extractor::getClassAnnotations($class); | ||
| 41 | + // 如果忽略 | ||
| 42 | + if (isset($classAnnotation['ApiInternal'])) { | ||
| 43 | + continue; | ||
| 44 | + } | ||
| 45 | + Extractor::getClassMethodAnnotations($class); | ||
| 46 | + } | ||
| 47 | + $allClassAnnotation = Extractor::getAllClassAnnotations(); | ||
| 48 | + $allClassMethodAnnotation = Extractor::getAllClassMethodAnnotations(); | ||
| 49 | + | ||
| 50 | +// foreach ($allClassMethodAnnotation as $className => &$methods) { | ||
| 51 | +// foreach ($methods as &$method) { | ||
| 52 | +// //权重判断 | ||
| 53 | +// if ($method && !isset($method['ApiWeigh']) && isset($allClassAnnotation[$className]['ApiWeigh'])) { | ||
| 54 | +// $method['ApiWeigh'] = $allClassAnnotation[$className]['ApiWeigh']; | ||
| 55 | +// } | ||
| 56 | +// } | ||
| 57 | +// } | ||
| 58 | +// unset($methods); | ||
| 59 | + return [$allClassAnnotation, $allClassMethodAnnotation]; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + protected function generateHeadersTemplate($docs) | ||
| 63 | + { | ||
| 64 | + if (!isset($docs['ApiHeaders'])) { | ||
| 65 | + return []; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + $headerslist = array(); | ||
| 69 | + foreach ($docs['ApiHeaders'] as $params) { | ||
| 70 | + $tr = array( | ||
| 71 | + 'name' => $params['name'], | ||
| 72 | + 'type' => $params['type'], | ||
| 73 | + 'sample' => isset($params['sample']) ? $params['sample'] : '', | ||
| 74 | + 'required' => isset($params['required']) ? $params['required'] : false, | ||
| 75 | + 'description' => isset($params['description']) ? $params['description'] : '', | ||
| 76 | + ); | ||
| 77 | + $headerslist[] = $tr; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + return $headerslist; | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + protected function generateParamsTemplate($docs) | ||
| 84 | + { | ||
| 85 | + if (!isset($docs['ApiParams'])) { | ||
| 86 | + return []; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + $paramslist = array(); | ||
| 90 | + foreach ($docs['ApiParams'] as $params) { | ||
| 91 | + $tr = array( | ||
| 92 | + 'name' => $params['name'], | ||
| 93 | + 'type' => isset($params['type']) ? $params['type'] : 'string', | ||
| 94 | + 'sample' => isset($params['sample']) ? $params['sample'] : '', | ||
| 95 | + 'required' => isset($params['required']) ? $params['required'] : true, | ||
| 96 | + 'description' => isset($params['description']) ? $params['description'] : '', | ||
| 97 | + ); | ||
| 98 | + $paramslist[] = $tr; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + return $paramslist; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + protected function generateReturnHeadersTemplate($docs) | ||
| 105 | + { | ||
| 106 | + if (!isset($docs['ApiReturnHeaders'])) { | ||
| 107 | + return []; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + $headerslist = array(); | ||
| 111 | + foreach ($docs['ApiReturnHeaders'] as $params) { | ||
| 112 | + $tr = array( | ||
| 113 | + 'name' => $params['name'], | ||
| 114 | + 'type' => 'string', | ||
| 115 | + 'sample' => isset($params['sample']) ? $params['sample'] : '', | ||
| 116 | + 'required' => isset($params['required']) && $params['required'] ? 'Yes' : 'No', | ||
| 117 | + 'description' => isset($params['description']) ? $params['description'] : '', | ||
| 118 | + ); | ||
| 119 | + $headerslist[] = $tr; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + return $headerslist; | ||
| 123 | + } | ||
| 124 | + | ||
| 125 | + protected function generateReturnParamsTemplate($st_params) | ||
| 126 | + { | ||
| 127 | + if (!isset($st_params['ApiReturnParams'])) { | ||
| 128 | + return []; | ||
| 129 | + } | ||
| 130 | + | ||
| 131 | + $paramslist = array(); | ||
| 132 | + foreach ($st_params['ApiReturnParams'] as $params) { | ||
| 133 | + $tr = array( | ||
| 134 | + 'name' => $params['name'], | ||
| 135 | + 'type' => isset($params['type']) ? $params['type'] : 'string', | ||
| 136 | + 'sample' => isset($params['sample']) ? $params['sample'] : '', | ||
| 137 | + 'description' => isset($params['description']) ? $params['description'] : '', | ||
| 138 | + ); | ||
| 139 | + $paramslist[] = $tr; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + return $paramslist; | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + protected function generateBadgeForMethod($data) | ||
| 146 | + { | ||
| 147 | + $method = strtoupper(is_array($data['ApiMethod'][0]) ? $data['ApiMethod'][0]['data'] : $data['ApiMethod'][0]); | ||
| 148 | + $labes = array( | ||
| 149 | + 'POST' => 'label-primary', | ||
| 150 | + 'GET' => 'label-success', | ||
| 151 | + 'PUT' => 'label-warning', | ||
| 152 | + 'DELETE' => 'label-danger', | ||
| 153 | + 'PATCH' => 'label-default', | ||
| 154 | + 'OPTIONS' => 'label-info' | ||
| 155 | + ); | ||
| 156 | + | ||
| 157 | + return isset($labes[$method]) ? $labes[$method] : $labes['GET']; | ||
| 158 | + } | ||
| 159 | + | ||
| 160 | + public function parse() | ||
| 161 | + { | ||
| 162 | + list($allClassAnnotations, $allClassMethodAnnotations) = $this->extractAnnotations(); | ||
| 163 | + | ||
| 164 | + $sectorArr = []; | ||
| 165 | + foreach ($allClassAnnotations as $index => $allClassAnnotation) { | ||
| 166 | + $sector = isset($allClassAnnotation['ApiSector']) ? $allClassAnnotation['ApiSector'][0] : $allClassAnnotation['ApiTitle'][0]; | ||
| 167 | + $sectorArr[$sector] = isset($allClassAnnotation['ApiWeigh']) ? $allClassAnnotation['ApiWeigh'][0] : 0; | ||
| 168 | + } | ||
| 169 | + arsort($sectorArr); | ||
| 170 | + $routes = include_once CONF_PATH . 'route.php'; | ||
| 171 | + $subdomain = false; | ||
| 172 | + if (config('url_domain_deploy') && isset($routes['__domain__']) && isset($routes['__domain__']['api']) && $routes['__domain__']['api']) { | ||
| 173 | + $subdomain = true; | ||
| 174 | + } | ||
| 175 | + $counter = 0; | ||
| 176 | + $section = null; | ||
| 177 | + $weigh = 0; | ||
| 178 | + $docslist = []; | ||
| 179 | + foreach ($allClassMethodAnnotations as $class => $methods) { | ||
| 180 | + foreach ($methods as $name => $docs) { | ||
| 181 | + if (isset($docs['ApiSector'][0])) { | ||
| 182 | + $section = is_array($docs['ApiSector'][0]) ? $docs['ApiSector'][0]['data'] : $docs['ApiSector'][0]; | ||
| 183 | + } else { | ||
| 184 | + $section = $class; | ||
| 185 | + } | ||
| 186 | + if (0 === count($docs)) { | ||
| 187 | + continue; | ||
| 188 | + } | ||
| 189 | + $route = is_array($docs['ApiRoute'][0]) ? $docs['ApiRoute'][0]['data'] : $docs['ApiRoute'][0]; | ||
| 190 | + if ($subdomain) { | ||
| 191 | + $route = substr($route, 4); | ||
| 192 | + } | ||
| 193 | + $docslist[$section][$class . $name] = [ | ||
| 194 | + 'id' => $counter, | ||
| 195 | + 'method' => is_array($docs['ApiMethod'][0]) ? $docs['ApiMethod'][0]['data'] : $docs['ApiMethod'][0], | ||
| 196 | + 'method_label' => $this->generateBadgeForMethod($docs), | ||
| 197 | + 'section' => $section, | ||
| 198 | + 'route' => $route, | ||
| 199 | + 'title' => is_array($docs['ApiTitle'][0]) ? $docs['ApiTitle'][0]['data'] : $docs['ApiTitle'][0], | ||
| 200 | + 'summary' => is_array($docs['ApiSummary'][0]) ? $docs['ApiSummary'][0]['data'] : $docs['ApiSummary'][0], | ||
| 201 | + 'body' => isset($docs['ApiBody'][0]) ? is_array($docs['ApiBody'][0]) ? $docs['ApiBody'][0]['data'] : $docs['ApiBody'][0] : '', | ||
| 202 | + 'headerslist' => $this->generateHeadersTemplate($docs), | ||
| 203 | + 'paramslist' => $this->generateParamsTemplate($docs), | ||
| 204 | + 'returnheaderslist' => $this->generateReturnHeadersTemplate($docs), | ||
| 205 | + 'returnparamslist' => $this->generateReturnParamsTemplate($docs), | ||
| 206 | + 'weigh' => is_array($docs['ApiWeigh'][0]) ? $docs['ApiWeigh'][0]['data'] : $docs['ApiWeigh'][0], | ||
| 207 | + 'return' => isset($docs['ApiReturn']) ? is_array($docs['ApiReturn'][0]) ? $docs['ApiReturn'][0]['data'] : $docs['ApiReturn'][0] : '', | ||
| 208 | + ]; | ||
| 209 | + $counter++; | ||
| 210 | + } | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + //重建排序 | ||
| 214 | + foreach ($docslist as $index => &$methods) { | ||
| 215 | + $methodSectorArr = []; | ||
| 216 | + foreach ($methods as $name => $method) { | ||
| 217 | + $methodSectorArr[$name] = isset($method['weigh']) ? $method['weigh'] : 0; | ||
| 218 | + } | ||
| 219 | + arsort($methodSectorArr); | ||
| 220 | + $methods = array_merge(array_flip(array_keys($methodSectorArr)), $methods); | ||
| 221 | + } | ||
| 222 | + $docslist = array_merge(array_flip(array_keys($sectorArr)), $docslist); | ||
| 223 | + $docslist = array_filter($docslist , function($v) {return is_array($v) ; }) ; | ||
| 224 | + return $docslist; | ||
| 225 | + } | ||
| 226 | + | ||
| 227 | + public function getView() | ||
| 228 | + { | ||
| 229 | + return $this->view; | ||
| 230 | + } | ||
| 231 | + | ||
| 232 | + /** | ||
| 233 | + * 渲染 | ||
| 234 | + * @param string $template | ||
| 235 | + * @param array $vars | ||
| 236 | + * @return string | ||
| 237 | + */ | ||
| 238 | + public function render($template, $vars = []) | ||
| 239 | + { | ||
| 240 | + $docslist = $this->parse(); | ||
| 241 | + | ||
| 242 | + return $this->view->display(file_get_contents($template), array_merge($vars, ['docslist' => $docslist])); | ||
| 243 | + } | ||
| 244 | +} |
-
请 注册 或 登录 后发表评论