├── .gitignore
├── LICENSE.txt
├── README.md
├── composer.json
├── composer.lock
└── src
├── FlmngrServer.php
├── fs
├── CachedFile.php
├── DriverLocal.php
└── FileSystem.php
├── lib
├── CommonRequest.php
├── IFmRequest.php
├── JsonCodec.php
├── MessageException.php
├── Profile.php
└── file
│ ├── Utils.php
│ └── blurHash
│ ├── AC.php
│ ├── Base83.php
│ ├── Blurhash.php
│ ├── Color.php
│ └── DC.php
├── model
├── FMDir.php
├── FMFile.php
├── ImageInfo.php
└── Message.php
└── resp
└── Response.php
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea/
2 | vendor/
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://flmngr.com)
2 |
3 | # Flmngr PHP backend
4 |
5 | > Server-side part of the Flmngr file manager for PHP
6 |
7 | [](https://flmngr.com)
8 |
9 | [Flmngr file manager](https://flmngr.com) is used to upload and manage files and images. Can be a standalone file manager (React/Angular/etc. or custom JavaScript or TypeScript integrations) or work together with [TinyMCE](https://flmngr.com/doc/install-tinymce-plugin), [CKEditor 4](https://flmngr.com/doc/install-ckeditor-plugin), [CKEditor 5](https://flmngr.com/doc/install-ckeditor-5-plugin), [N1ED](https://n1ed.com), or any other JS components.
10 |
11 | This package is a server-side implementation needed to support requests from the file manager dialog when using PHP on the server. It will handle some single URL and let the file manager receive file lists and send file commands to the server.
12 |
13 | ## Install
14 | Install the [Flmngr composer package](https://packagist.org/packages/edsdk/flmngr-server-php) using the console command in the project folder:
15 |
16 | ```
17 | composer require edsdk/flmngr-server-php
18 | ```
19 |
20 | Visit the page with a [detailed manual](https://flmngr.com/doc/install-file-manager-server) on how to install it.
21 |
22 | If you prefer not to use Composer, there is a [no-Composer PHP script](https://flmngr.com/doc/install-php-file-manager-include) for such cases.
23 |
24 | ## Usage
25 |
26 | To handle some URL you want in your web application, create a file which will be the entry point for all requests, e.g. `flmngr.php`:
27 |
28 | ```php
29 | '/var/www/files',
34 | )
35 | );
36 | ```
37 |
38 | The file `flmngr.php` should be placed on the same level as the `vendor` directory. It can be placed in some other location as well, but do not forget to change the path in the `require` call.
39 |
40 | Do not forget to create the directories you specify and set the correct permissions (read and write) to allow access to them.
41 |
42 | If you want to allow access to uploaded files (which is usually the case) please do not forget to open access to the files directory.
43 |
44 | Also, please refer to the [example of using](https://flmngr.com/doc/open-file-manager) Flmngr with ImgPen for editing and uploading images.
45 |
46 | ## Debugging
47 |
48 | In case of any problem, we have a **very** detailed Question-Answer [debug manual](https://flmngr.com/doc/file-manager-debug).
49 |
50 | ## See Also
51 |
52 | - [Flmngr](https://flmngr.com) - Flmngr file manager.
53 | - [Install Flmngr PHP backend](https://flmngr.com/doc/install-file-manager-server) - the detailed manual on how to install PHP file manager on the server.
54 | - [Flmngr codepens](https://codepen.io/flmngr/pens/public) - collection of JS samples on CodePen.
55 | - [Flmngr API](https://flmngr.com/doc/api) - API of Flmngr client.
56 | - [N1ED](https://n1ed.com) - a website content builder with Flmngr file manager aboard, also works as a plugin for CKEditor 4, TinyMCE, which has modules for different CMSs.
57 |
58 |
59 | ## License
60 |
61 | GNU Lesser General Public License v3; see LICENSE.txt
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "edsdk/flmngr-server-php",
3 | "description": "Flmngr file manager PHP backend",
4 | "type": "library",
5 | "keywords": ["file", "manager", "finder", "image", "upload", "server", "imgpen"],
6 | "homepage": "https://flmngr.com",
7 | "license": "proprietary",
8 | "minimum-stability": "stable",
9 |
10 | "authors": [
11 | {
12 | "name": "EdSDK team (the authors of N1ED and Flmngr)",
13 | "email": "support@helpdesk.edsdk.com"
14 | }
15 | ],
16 | "autoload": {
17 | "psr-4": {
18 | "EdSDK\\FlmngrServer\\": "src/"
19 | }
20 | },
21 | "require": {
22 | "ext-gd": "*",
23 | "ext-curl": "*",
24 | "ext-json": "*",
25 | "ext-exif": "*"
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/composer.lock:
--------------------------------------------------------------------------------
1 | {
2 | "_readme": [
3 | "This file locks the dependencies of your project to a known state",
4 | "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5 | "This file is @generated automatically"
6 | ],
7 | "content-hash": "2693a47846db38ca4afe247bcf4d6dbd",
8 | "packages": [
9 | {
10 | "name": "aws/aws-crt-php",
11 | "version": "v1.0.2",
12 | "source": {
13 | "type": "git",
14 | "url": "https://github.com/awslabs/aws-crt-php.git",
15 | "reference": "3942776a8c99209908ee0b287746263725685732"
16 | },
17 | "dist": {
18 | "type": "zip",
19 | "url": "https://api.github.com/repos/awslabs/aws-crt-php/zipball/3942776a8c99209908ee0b287746263725685732",
20 | "reference": "3942776a8c99209908ee0b287746263725685732",
21 | "shasum": ""
22 | },
23 | "require": {
24 | "php": ">=5.5"
25 | },
26 | "require-dev": {
27 | "phpunit/phpunit": "^4.8.35|^5.4.3"
28 | },
29 | "type": "library",
30 | "autoload": {
31 | "classmap": [
32 | "src/"
33 | ]
34 | },
35 | "notification-url": "https://packagist.org/downloads/",
36 | "license": [
37 | "Apache-2.0"
38 | ],
39 | "authors": [
40 | {
41 | "name": "AWS SDK Common Runtime Team",
42 | "email": "aws-sdk-common-runtime@amazon.com"
43 | }
44 | ],
45 | "description": "AWS Common Runtime for PHP",
46 | "homepage": "http://aws.amazon.com/sdkforphp",
47 | "keywords": [
48 | "amazon",
49 | "aws",
50 | "crt",
51 | "sdk"
52 | ],
53 | "support": {
54 | "issues": "https://github.com/awslabs/aws-crt-php/issues",
55 | "source": "https://github.com/awslabs/aws-crt-php/tree/v1.0.2"
56 | },
57 | "time": "2021-09-03T22:57:30+00:00"
58 | },
59 | {
60 | "name": "aws/aws-sdk-php",
61 | "version": "3.219.5",
62 | "source": {
63 | "type": "git",
64 | "url": "https://github.com/aws/aws-sdk-php.git",
65 | "reference": "7e8da5b45d545ca3129a14e972001698212b1a00"
66 | },
67 | "dist": {
68 | "type": "zip",
69 | "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/7e8da5b45d545ca3129a14e972001698212b1a00",
70 | "reference": "7e8da5b45d545ca3129a14e972001698212b1a00",
71 | "shasum": ""
72 | },
73 | "require": {
74 | "aws/aws-crt-php": "^1.0.2",
75 | "ext-json": "*",
76 | "ext-pcre": "*",
77 | "ext-simplexml": "*",
78 | "guzzlehttp/guzzle": "^5.3.3 || ^6.2.1 || ^7.0",
79 | "guzzlehttp/promises": "^1.4.0",
80 | "guzzlehttp/psr7": "^1.7.0 || ^2.1.1",
81 | "mtdowling/jmespath.php": "^2.6",
82 | "php": ">=5.5"
83 | },
84 | "require-dev": {
85 | "andrewsville/php-token-reflection": "^1.4",
86 | "aws/aws-php-sns-message-validator": "~1.0",
87 | "behat/behat": "~3.0",
88 | "doctrine/cache": "~1.4",
89 | "ext-dom": "*",
90 | "ext-openssl": "*",
91 | "ext-pcntl": "*",
92 | "ext-sockets": "*",
93 | "nette/neon": "^2.3",
94 | "paragonie/random_compat": ">= 2",
95 | "phpunit/phpunit": "^4.8.35 || ^5.6.3",
96 | "psr/cache": "^1.0",
97 | "psr/simple-cache": "^1.0",
98 | "sebastian/comparator": "^1.2.3"
99 | },
100 | "suggest": {
101 | "aws/aws-php-sns-message-validator": "To validate incoming SNS notifications",
102 | "doctrine/cache": "To use the DoctrineCacheAdapter",
103 | "ext-curl": "To send requests using cURL",
104 | "ext-openssl": "Allows working with CloudFront private distributions and verifying received SNS messages",
105 | "ext-sockets": "To use client-side monitoring"
106 | },
107 | "type": "library",
108 | "extra": {
109 | "branch-alias": {
110 | "dev-master": "3.0-dev"
111 | }
112 | },
113 | "autoload": {
114 | "files": [
115 | "src/functions.php"
116 | ],
117 | "psr-4": {
118 | "Aws\\": "src/"
119 | }
120 | },
121 | "notification-url": "https://packagist.org/downloads/",
122 | "license": [
123 | "Apache-2.0"
124 | ],
125 | "authors": [
126 | {
127 | "name": "Amazon Web Services",
128 | "homepage": "http://aws.amazon.com"
129 | }
130 | ],
131 | "description": "AWS SDK for PHP - Use Amazon Web Services in your PHP project",
132 | "homepage": "http://aws.amazon.com/sdkforphp",
133 | "keywords": [
134 | "amazon",
135 | "aws",
136 | "cloud",
137 | "dynamodb",
138 | "ec2",
139 | "glacier",
140 | "s3",
141 | "sdk"
142 | ],
143 | "support": {
144 | "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
145 | "issues": "https://github.com/aws/aws-sdk-php/issues",
146 | "source": "https://github.com/aws/aws-sdk-php/tree/3.219.5"
147 | },
148 | "time": "2022-04-15T18:16:29+00:00"
149 | },
150 | {
151 | "name": "guzzlehttp/guzzle",
152 | "version": "7.4.2",
153 | "source": {
154 | "type": "git",
155 | "url": "https://github.com/guzzle/guzzle.git",
156 | "reference": "ac1ec1cd9b5624694c3a40be801d94137afb12b4"
157 | },
158 | "dist": {
159 | "type": "zip",
160 | "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ac1ec1cd9b5624694c3a40be801d94137afb12b4",
161 | "reference": "ac1ec1cd9b5624694c3a40be801d94137afb12b4",
162 | "shasum": ""
163 | },
164 | "require": {
165 | "ext-json": "*",
166 | "guzzlehttp/promises": "^1.5",
167 | "guzzlehttp/psr7": "^1.8.3 || ^2.1",
168 | "php": "^7.2.5 || ^8.0",
169 | "psr/http-client": "^1.0",
170 | "symfony/deprecation-contracts": "^2.2 || ^3.0"
171 | },
172 | "provide": {
173 | "psr/http-client-implementation": "1.0"
174 | },
175 | "require-dev": {
176 | "bamarni/composer-bin-plugin": "^1.4.1",
177 | "ext-curl": "*",
178 | "php-http/client-integration-tests": "^3.0",
179 | "phpunit/phpunit": "^8.5.5 || ^9.3.5",
180 | "psr/log": "^1.1 || ^2.0 || ^3.0"
181 | },
182 | "suggest": {
183 | "ext-curl": "Required for CURL handler support",
184 | "ext-intl": "Required for Internationalized Domain Name (IDN) support",
185 | "psr/log": "Required for using the Log middleware"
186 | },
187 | "type": "library",
188 | "extra": {
189 | "branch-alias": {
190 | "dev-master": "7.4-dev"
191 | }
192 | },
193 | "autoload": {
194 | "files": [
195 | "src/functions_include.php"
196 | ],
197 | "psr-4": {
198 | "GuzzleHttp\\": "src/"
199 | }
200 | },
201 | "notification-url": "https://packagist.org/downloads/",
202 | "license": [
203 | "MIT"
204 | ],
205 | "authors": [
206 | {
207 | "name": "Graham Campbell",
208 | "email": "hello@gjcampbell.co.uk",
209 | "homepage": "https://github.com/GrahamCampbell"
210 | },
211 | {
212 | "name": "Michael Dowling",
213 | "email": "mtdowling@gmail.com",
214 | "homepage": "https://github.com/mtdowling"
215 | },
216 | {
217 | "name": "Jeremy Lindblom",
218 | "email": "jeremeamia@gmail.com",
219 | "homepage": "https://github.com/jeremeamia"
220 | },
221 | {
222 | "name": "George Mponos",
223 | "email": "gmponos@gmail.com",
224 | "homepage": "https://github.com/gmponos"
225 | },
226 | {
227 | "name": "Tobias Nyholm",
228 | "email": "tobias.nyholm@gmail.com",
229 | "homepage": "https://github.com/Nyholm"
230 | },
231 | {
232 | "name": "Márk Sági-Kazár",
233 | "email": "mark.sagikazar@gmail.com",
234 | "homepage": "https://github.com/sagikazarmark"
235 | },
236 | {
237 | "name": "Tobias Schultze",
238 | "email": "webmaster@tubo-world.de",
239 | "homepage": "https://github.com/Tobion"
240 | }
241 | ],
242 | "description": "Guzzle is a PHP HTTP client library",
243 | "keywords": [
244 | "client",
245 | "curl",
246 | "framework",
247 | "http",
248 | "http client",
249 | "psr-18",
250 | "psr-7",
251 | "rest",
252 | "web service"
253 | ],
254 | "support": {
255 | "issues": "https://github.com/guzzle/guzzle/issues",
256 | "source": "https://github.com/guzzle/guzzle/tree/7.4.2"
257 | },
258 | "funding": [
259 | {
260 | "url": "https://github.com/GrahamCampbell",
261 | "type": "github"
262 | },
263 | {
264 | "url": "https://github.com/Nyholm",
265 | "type": "github"
266 | },
267 | {
268 | "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/guzzle",
269 | "type": "tidelift"
270 | }
271 | ],
272 | "time": "2022-03-20T14:16:28+00:00"
273 | },
274 | {
275 | "name": "guzzlehttp/promises",
276 | "version": "1.5.1",
277 | "source": {
278 | "type": "git",
279 | "url": "https://github.com/guzzle/promises.git",
280 | "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da"
281 | },
282 | "dist": {
283 | "type": "zip",
284 | "url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da",
285 | "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da",
286 | "shasum": ""
287 | },
288 | "require": {
289 | "php": ">=5.5"
290 | },
291 | "require-dev": {
292 | "symfony/phpunit-bridge": "^4.4 || ^5.1"
293 | },
294 | "type": "library",
295 | "extra": {
296 | "branch-alias": {
297 | "dev-master": "1.5-dev"
298 | }
299 | },
300 | "autoload": {
301 | "files": [
302 | "src/functions_include.php"
303 | ],
304 | "psr-4": {
305 | "GuzzleHttp\\Promise\\": "src/"
306 | }
307 | },
308 | "notification-url": "https://packagist.org/downloads/",
309 | "license": [
310 | "MIT"
311 | ],
312 | "authors": [
313 | {
314 | "name": "Graham Campbell",
315 | "email": "hello@gjcampbell.co.uk",
316 | "homepage": "https://github.com/GrahamCampbell"
317 | },
318 | {
319 | "name": "Michael Dowling",
320 | "email": "mtdowling@gmail.com",
321 | "homepage": "https://github.com/mtdowling"
322 | },
323 | {
324 | "name": "Tobias Nyholm",
325 | "email": "tobias.nyholm@gmail.com",
326 | "homepage": "https://github.com/Nyholm"
327 | },
328 | {
329 | "name": "Tobias Schultze",
330 | "email": "webmaster@tubo-world.de",
331 | "homepage": "https://github.com/Tobion"
332 | }
333 | ],
334 | "description": "Guzzle promises library",
335 | "keywords": [
336 | "promise"
337 | ],
338 | "support": {
339 | "issues": "https://github.com/guzzle/promises/issues",
340 | "source": "https://github.com/guzzle/promises/tree/1.5.1"
341 | },
342 | "funding": [
343 | {
344 | "url": "https://github.com/GrahamCampbell",
345 | "type": "github"
346 | },
347 | {
348 | "url": "https://github.com/Nyholm",
349 | "type": "github"
350 | },
351 | {
352 | "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/promises",
353 | "type": "tidelift"
354 | }
355 | ],
356 | "time": "2021-10-22T20:56:57+00:00"
357 | },
358 | {
359 | "name": "guzzlehttp/psr7",
360 | "version": "2.2.1",
361 | "source": {
362 | "type": "git",
363 | "url": "https://github.com/guzzle/psr7.git",
364 | "reference": "c94a94f120803a18554c1805ef2e539f8285f9a2"
365 | },
366 | "dist": {
367 | "type": "zip",
368 | "url": "https://api.github.com/repos/guzzle/psr7/zipball/c94a94f120803a18554c1805ef2e539f8285f9a2",
369 | "reference": "c94a94f120803a18554c1805ef2e539f8285f9a2",
370 | "shasum": ""
371 | },
372 | "require": {
373 | "php": "^7.2.5 || ^8.0",
374 | "psr/http-factory": "^1.0",
375 | "psr/http-message": "^1.0",
376 | "ralouphie/getallheaders": "^3.0"
377 | },
378 | "provide": {
379 | "psr/http-factory-implementation": "1.0",
380 | "psr/http-message-implementation": "1.0"
381 | },
382 | "require-dev": {
383 | "bamarni/composer-bin-plugin": "^1.4.1",
384 | "http-interop/http-factory-tests": "^0.9",
385 | "phpunit/phpunit": "^8.5.8 || ^9.3.10"
386 | },
387 | "suggest": {
388 | "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses"
389 | },
390 | "type": "library",
391 | "extra": {
392 | "branch-alias": {
393 | "dev-master": "2.2-dev"
394 | }
395 | },
396 | "autoload": {
397 | "psr-4": {
398 | "GuzzleHttp\\Psr7\\": "src/"
399 | }
400 | },
401 | "notification-url": "https://packagist.org/downloads/",
402 | "license": [
403 | "MIT"
404 | ],
405 | "authors": [
406 | {
407 | "name": "Graham Campbell",
408 | "email": "hello@gjcampbell.co.uk",
409 | "homepage": "https://github.com/GrahamCampbell"
410 | },
411 | {
412 | "name": "Michael Dowling",
413 | "email": "mtdowling@gmail.com",
414 | "homepage": "https://github.com/mtdowling"
415 | },
416 | {
417 | "name": "George Mponos",
418 | "email": "gmponos@gmail.com",
419 | "homepage": "https://github.com/gmponos"
420 | },
421 | {
422 | "name": "Tobias Nyholm",
423 | "email": "tobias.nyholm@gmail.com",
424 | "homepage": "https://github.com/Nyholm"
425 | },
426 | {
427 | "name": "Márk Sági-Kazár",
428 | "email": "mark.sagikazar@gmail.com",
429 | "homepage": "https://github.com/sagikazarmark"
430 | },
431 | {
432 | "name": "Tobias Schultze",
433 | "email": "webmaster@tubo-world.de",
434 | "homepage": "https://github.com/Tobion"
435 | },
436 | {
437 | "name": "Márk Sági-Kazár",
438 | "email": "mark.sagikazar@gmail.com",
439 | "homepage": "https://sagikazarmark.hu"
440 | }
441 | ],
442 | "description": "PSR-7 message implementation that also provides common utility methods",
443 | "keywords": [
444 | "http",
445 | "message",
446 | "psr-7",
447 | "request",
448 | "response",
449 | "stream",
450 | "uri",
451 | "url"
452 | ],
453 | "support": {
454 | "issues": "https://github.com/guzzle/psr7/issues",
455 | "source": "https://github.com/guzzle/psr7/tree/2.2.1"
456 | },
457 | "funding": [
458 | {
459 | "url": "https://github.com/GrahamCampbell",
460 | "type": "github"
461 | },
462 | {
463 | "url": "https://github.com/Nyholm",
464 | "type": "github"
465 | },
466 | {
467 | "url": "https://tidelift.com/funding/github/packagist/guzzlehttp/psr7",
468 | "type": "tidelift"
469 | }
470 | ],
471 | "time": "2022-03-20T21:55:58+00:00"
472 | },
473 | {
474 | "name": "league/flysystem",
475 | "version": "3.0.17",
476 | "source": {
477 | "type": "git",
478 | "url": "https://github.com/thephpleague/flysystem.git",
479 | "reference": "29eb78cac0be0c22237c5e0f6f98234d97037d79"
480 | },
481 | "dist": {
482 | "type": "zip",
483 | "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/29eb78cac0be0c22237c5e0f6f98234d97037d79",
484 | "reference": "29eb78cac0be0c22237c5e0f6f98234d97037d79",
485 | "shasum": ""
486 | },
487 | "require": {
488 | "league/mime-type-detection": "^1.0.0",
489 | "php": "^8.0.2"
490 | },
491 | "conflict": {
492 | "aws/aws-sdk-php": "3.209.31 || 3.210.0",
493 | "guzzlehttp/guzzle": "<7.0",
494 | "guzzlehttp/ringphp": "<1.1.1",
495 | "symfony/http-client": "<5.2"
496 | },
497 | "require-dev": {
498 | "async-aws/s3": "^1.5",
499 | "async-aws/simple-s3": "^1.0",
500 | "aws/aws-sdk-php": "^3.198.1",
501 | "composer/semver": "^3.0",
502 | "ext-fileinfo": "*",
503 | "ext-ftp": "*",
504 | "ext-zip": "*",
505 | "friendsofphp/php-cs-fixer": "^3.5",
506 | "google/cloud-storage": "^1.23",
507 | "microsoft/azure-storage-blob": "^1.1",
508 | "phpseclib/phpseclib": "^2.0",
509 | "phpstan/phpstan": "^0.12.26",
510 | "phpunit/phpunit": "^9.5.11",
511 | "sabre/dav": "^4.3.1"
512 | },
513 | "type": "library",
514 | "autoload": {
515 | "psr-4": {
516 | "League\\Flysystem\\": "src"
517 | }
518 | },
519 | "notification-url": "https://packagist.org/downloads/",
520 | "license": [
521 | "MIT"
522 | ],
523 | "authors": [
524 | {
525 | "name": "Frank de Jonge",
526 | "email": "info@frankdejonge.nl"
527 | }
528 | ],
529 | "description": "File storage abstraction for PHP",
530 | "keywords": [
531 | "WebDAV",
532 | "aws",
533 | "cloud",
534 | "file",
535 | "files",
536 | "filesystem",
537 | "filesystems",
538 | "ftp",
539 | "s3",
540 | "sftp",
541 | "storage"
542 | ],
543 | "support": {
544 | "issues": "https://github.com/thephpleague/flysystem/issues",
545 | "source": "https://github.com/thephpleague/flysystem/tree/3.0.17"
546 | },
547 | "funding": [
548 | {
549 | "url": "https://offset.earth/frankdejonge",
550 | "type": "custom"
551 | },
552 | {
553 | "url": "https://github.com/frankdejonge",
554 | "type": "github"
555 | },
556 | {
557 | "url": "https://tidelift.com/funding/github/packagist/league/flysystem",
558 | "type": "tidelift"
559 | }
560 | ],
561 | "time": "2022-04-14T14:57:13+00:00"
562 | },
563 | {
564 | "name": "league/flysystem-aws-s3-v3",
565 | "version": "3.0.13",
566 | "source": {
567 | "type": "git",
568 | "url": "https://github.com/thephpleague/flysystem-aws-s3-v3.git",
569 | "reference": "0074cf016e21a6d1eb99b6db70acdd23743fc371"
570 | },
571 | "dist": {
572 | "type": "zip",
573 | "url": "https://api.github.com/repos/thephpleague/flysystem-aws-s3-v3/zipball/0074cf016e21a6d1eb99b6db70acdd23743fc371",
574 | "reference": "0074cf016e21a6d1eb99b6db70acdd23743fc371",
575 | "shasum": ""
576 | },
577 | "require": {
578 | "aws/aws-sdk-php": "^3.132.4",
579 | "league/flysystem": "^2.0.0 || ^3.0.0",
580 | "league/mime-type-detection": "^1.0.0",
581 | "php": "^8.0.2"
582 | },
583 | "conflict": {
584 | "guzzlehttp/guzzle": "<7.0",
585 | "guzzlehttp/ringphp": "<1.1.1"
586 | },
587 | "type": "library",
588 | "autoload": {
589 | "psr-4": {
590 | "League\\Flysystem\\AwsS3V3\\": ""
591 | }
592 | },
593 | "notification-url": "https://packagist.org/downloads/",
594 | "license": [
595 | "MIT"
596 | ],
597 | "authors": [
598 | {
599 | "name": "Frank de Jonge",
600 | "email": "info@frankdejonge.nl"
601 | }
602 | ],
603 | "description": "AWS S3 filesystem adapter for Flysystem.",
604 | "keywords": [
605 | "Flysystem",
606 | "aws",
607 | "file",
608 | "files",
609 | "filesystem",
610 | "s3",
611 | "storage"
612 | ],
613 | "support": {
614 | "issues": "https://github.com/thephpleague/flysystem-aws-s3-v3/issues",
615 | "source": "https://github.com/thephpleague/flysystem-aws-s3-v3/tree/3.0.13"
616 | },
617 | "time": "2022-04-01T22:05:11+00:00"
618 | },
619 | {
620 | "name": "league/mime-type-detection",
621 | "version": "1.11.0",
622 | "source": {
623 | "type": "git",
624 | "url": "https://github.com/thephpleague/mime-type-detection.git",
625 | "reference": "ff6248ea87a9f116e78edd6002e39e5128a0d4dd"
626 | },
627 | "dist": {
628 | "type": "zip",
629 | "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/ff6248ea87a9f116e78edd6002e39e5128a0d4dd",
630 | "reference": "ff6248ea87a9f116e78edd6002e39e5128a0d4dd",
631 | "shasum": ""
632 | },
633 | "require": {
634 | "ext-fileinfo": "*",
635 | "php": "^7.2 || ^8.0"
636 | },
637 | "require-dev": {
638 | "friendsofphp/php-cs-fixer": "^3.2",
639 | "phpstan/phpstan": "^0.12.68",
640 | "phpunit/phpunit": "^8.5.8 || ^9.3"
641 | },
642 | "type": "library",
643 | "autoload": {
644 | "psr-4": {
645 | "League\\MimeTypeDetection\\": "src"
646 | }
647 | },
648 | "notification-url": "https://packagist.org/downloads/",
649 | "license": [
650 | "MIT"
651 | ],
652 | "authors": [
653 | {
654 | "name": "Frank de Jonge",
655 | "email": "info@frankdejonge.nl"
656 | }
657 | ],
658 | "description": "Mime-type detection for Flysystem",
659 | "support": {
660 | "issues": "https://github.com/thephpleague/mime-type-detection/issues",
661 | "source": "https://github.com/thephpleague/mime-type-detection/tree/1.11.0"
662 | },
663 | "funding": [
664 | {
665 | "url": "https://github.com/frankdejonge",
666 | "type": "github"
667 | },
668 | {
669 | "url": "https://tidelift.com/funding/github/packagist/league/flysystem",
670 | "type": "tidelift"
671 | }
672 | ],
673 | "time": "2022-04-17T13:12:02+00:00"
674 | },
675 | {
676 | "name": "mtdowling/jmespath.php",
677 | "version": "2.6.1",
678 | "source": {
679 | "type": "git",
680 | "url": "https://github.com/jmespath/jmespath.php.git",
681 | "reference": "9b87907a81b87bc76d19a7fb2d61e61486ee9edb"
682 | },
683 | "dist": {
684 | "type": "zip",
685 | "url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/9b87907a81b87bc76d19a7fb2d61e61486ee9edb",
686 | "reference": "9b87907a81b87bc76d19a7fb2d61e61486ee9edb",
687 | "shasum": ""
688 | },
689 | "require": {
690 | "php": "^5.4 || ^7.0 || ^8.0",
691 | "symfony/polyfill-mbstring": "^1.17"
692 | },
693 | "require-dev": {
694 | "composer/xdebug-handler": "^1.4 || ^2.0",
695 | "phpunit/phpunit": "^4.8.36 || ^7.5.15"
696 | },
697 | "bin": [
698 | "bin/jp.php"
699 | ],
700 | "type": "library",
701 | "extra": {
702 | "branch-alias": {
703 | "dev-master": "2.6-dev"
704 | }
705 | },
706 | "autoload": {
707 | "files": [
708 | "src/JmesPath.php"
709 | ],
710 | "psr-4": {
711 | "JmesPath\\": "src/"
712 | }
713 | },
714 | "notification-url": "https://packagist.org/downloads/",
715 | "license": [
716 | "MIT"
717 | ],
718 | "authors": [
719 | {
720 | "name": "Michael Dowling",
721 | "email": "mtdowling@gmail.com",
722 | "homepage": "https://github.com/mtdowling"
723 | }
724 | ],
725 | "description": "Declaratively specify how to extract elements from a JSON document",
726 | "keywords": [
727 | "json",
728 | "jsonpath"
729 | ],
730 | "support": {
731 | "issues": "https://github.com/jmespath/jmespath.php/issues",
732 | "source": "https://github.com/jmespath/jmespath.php/tree/2.6.1"
733 | },
734 | "time": "2021-06-14T00:11:39+00:00"
735 | },
736 | {
737 | "name": "psr/http-client",
738 | "version": "1.0.1",
739 | "source": {
740 | "type": "git",
741 | "url": "https://github.com/php-fig/http-client.git",
742 | "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621"
743 | },
744 | "dist": {
745 | "type": "zip",
746 | "url": "https://api.github.com/repos/php-fig/http-client/zipball/2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
747 | "reference": "2dfb5f6c5eff0e91e20e913f8c5452ed95b86621",
748 | "shasum": ""
749 | },
750 | "require": {
751 | "php": "^7.0 || ^8.0",
752 | "psr/http-message": "^1.0"
753 | },
754 | "type": "library",
755 | "extra": {
756 | "branch-alias": {
757 | "dev-master": "1.0.x-dev"
758 | }
759 | },
760 | "autoload": {
761 | "psr-4": {
762 | "Psr\\Http\\Client\\": "src/"
763 | }
764 | },
765 | "notification-url": "https://packagist.org/downloads/",
766 | "license": [
767 | "MIT"
768 | ],
769 | "authors": [
770 | {
771 | "name": "PHP-FIG",
772 | "homepage": "http://www.php-fig.org/"
773 | }
774 | ],
775 | "description": "Common interface for HTTP clients",
776 | "homepage": "https://github.com/php-fig/http-client",
777 | "keywords": [
778 | "http",
779 | "http-client",
780 | "psr",
781 | "psr-18"
782 | ],
783 | "support": {
784 | "source": "https://github.com/php-fig/http-client/tree/master"
785 | },
786 | "time": "2020-06-29T06:28:15+00:00"
787 | },
788 | {
789 | "name": "psr/http-factory",
790 | "version": "1.0.1",
791 | "source": {
792 | "type": "git",
793 | "url": "https://github.com/php-fig/http-factory.git",
794 | "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be"
795 | },
796 | "dist": {
797 | "type": "zip",
798 | "url": "https://api.github.com/repos/php-fig/http-factory/zipball/12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
799 | "reference": "12ac7fcd07e5b077433f5f2bee95b3a771bf61be",
800 | "shasum": ""
801 | },
802 | "require": {
803 | "php": ">=7.0.0",
804 | "psr/http-message": "^1.0"
805 | },
806 | "type": "library",
807 | "extra": {
808 | "branch-alias": {
809 | "dev-master": "1.0.x-dev"
810 | }
811 | },
812 | "autoload": {
813 | "psr-4": {
814 | "Psr\\Http\\Message\\": "src/"
815 | }
816 | },
817 | "notification-url": "https://packagist.org/downloads/",
818 | "license": [
819 | "MIT"
820 | ],
821 | "authors": [
822 | {
823 | "name": "PHP-FIG",
824 | "homepage": "http://www.php-fig.org/"
825 | }
826 | ],
827 | "description": "Common interfaces for PSR-7 HTTP message factories",
828 | "keywords": [
829 | "factory",
830 | "http",
831 | "message",
832 | "psr",
833 | "psr-17",
834 | "psr-7",
835 | "request",
836 | "response"
837 | ],
838 | "support": {
839 | "source": "https://github.com/php-fig/http-factory/tree/master"
840 | },
841 | "time": "2019-04-30T12:38:16+00:00"
842 | },
843 | {
844 | "name": "psr/http-message",
845 | "version": "1.0.1",
846 | "source": {
847 | "type": "git",
848 | "url": "https://github.com/php-fig/http-message.git",
849 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363"
850 | },
851 | "dist": {
852 | "type": "zip",
853 | "url": "https://api.github.com/repos/php-fig/http-message/zipball/f6561bf28d520154e4b0ec72be95418abe6d9363",
854 | "reference": "f6561bf28d520154e4b0ec72be95418abe6d9363",
855 | "shasum": ""
856 | },
857 | "require": {
858 | "php": ">=5.3.0"
859 | },
860 | "type": "library",
861 | "extra": {
862 | "branch-alias": {
863 | "dev-master": "1.0.x-dev"
864 | }
865 | },
866 | "autoload": {
867 | "psr-4": {
868 | "Psr\\Http\\Message\\": "src/"
869 | }
870 | },
871 | "notification-url": "https://packagist.org/downloads/",
872 | "license": [
873 | "MIT"
874 | ],
875 | "authors": [
876 | {
877 | "name": "PHP-FIG",
878 | "homepage": "http://www.php-fig.org/"
879 | }
880 | ],
881 | "description": "Common interface for HTTP messages",
882 | "homepage": "https://github.com/php-fig/http-message",
883 | "keywords": [
884 | "http",
885 | "http-message",
886 | "psr",
887 | "psr-7",
888 | "request",
889 | "response"
890 | ],
891 | "support": {
892 | "source": "https://github.com/php-fig/http-message/tree/master"
893 | },
894 | "time": "2016-08-06T14:39:51+00:00"
895 | },
896 | {
897 | "name": "ralouphie/getallheaders",
898 | "version": "3.0.3",
899 | "source": {
900 | "type": "git",
901 | "url": "https://github.com/ralouphie/getallheaders.git",
902 | "reference": "120b605dfeb996808c31b6477290a714d356e822"
903 | },
904 | "dist": {
905 | "type": "zip",
906 | "url": "https://api.github.com/repos/ralouphie/getallheaders/zipball/120b605dfeb996808c31b6477290a714d356e822",
907 | "reference": "120b605dfeb996808c31b6477290a714d356e822",
908 | "shasum": ""
909 | },
910 | "require": {
911 | "php": ">=5.6"
912 | },
913 | "require-dev": {
914 | "php-coveralls/php-coveralls": "^2.1",
915 | "phpunit/phpunit": "^5 || ^6.5"
916 | },
917 | "type": "library",
918 | "autoload": {
919 | "files": [
920 | "src/getallheaders.php"
921 | ]
922 | },
923 | "notification-url": "https://packagist.org/downloads/",
924 | "license": [
925 | "MIT"
926 | ],
927 | "authors": [
928 | {
929 | "name": "Ralph Khattar",
930 | "email": "ralph.khattar@gmail.com"
931 | }
932 | ],
933 | "description": "A polyfill for getallheaders.",
934 | "support": {
935 | "issues": "https://github.com/ralouphie/getallheaders/issues",
936 | "source": "https://github.com/ralouphie/getallheaders/tree/develop"
937 | },
938 | "time": "2019-03-08T08:55:37+00:00"
939 | },
940 | {
941 | "name": "symfony/deprecation-contracts",
942 | "version": "v3.0.1",
943 | "source": {
944 | "type": "git",
945 | "url": "https://github.com/symfony/deprecation-contracts.git",
946 | "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c"
947 | },
948 | "dist": {
949 | "type": "zip",
950 | "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/26954b3d62a6c5fd0ea8a2a00c0353a14978d05c",
951 | "reference": "26954b3d62a6c5fd0ea8a2a00c0353a14978d05c",
952 | "shasum": ""
953 | },
954 | "require": {
955 | "php": ">=8.0.2"
956 | },
957 | "type": "library",
958 | "extra": {
959 | "branch-alias": {
960 | "dev-main": "3.0-dev"
961 | },
962 | "thanks": {
963 | "name": "symfony/contracts",
964 | "url": "https://github.com/symfony/contracts"
965 | }
966 | },
967 | "autoload": {
968 | "files": [
969 | "function.php"
970 | ]
971 | },
972 | "notification-url": "https://packagist.org/downloads/",
973 | "license": [
974 | "MIT"
975 | ],
976 | "authors": [
977 | {
978 | "name": "Nicolas Grekas",
979 | "email": "p@tchwork.com"
980 | },
981 | {
982 | "name": "Symfony Community",
983 | "homepage": "https://symfony.com/contributors"
984 | }
985 | ],
986 | "description": "A generic function and convention to trigger deprecation notices",
987 | "homepage": "https://symfony.com",
988 | "support": {
989 | "source": "https://github.com/symfony/deprecation-contracts/tree/v3.0.1"
990 | },
991 | "funding": [
992 | {
993 | "url": "https://symfony.com/sponsor",
994 | "type": "custom"
995 | },
996 | {
997 | "url": "https://github.com/fabpot",
998 | "type": "github"
999 | },
1000 | {
1001 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
1002 | "type": "tidelift"
1003 | }
1004 | ],
1005 | "time": "2022-01-02T09:55:41+00:00"
1006 | },
1007 | {
1008 | "name": "symfony/polyfill-mbstring",
1009 | "version": "v1.25.0",
1010 | "source": {
1011 | "type": "git",
1012 | "url": "https://github.com/symfony/polyfill-mbstring.git",
1013 | "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825"
1014 | },
1015 | "dist": {
1016 | "type": "zip",
1017 | "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825",
1018 | "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825",
1019 | "shasum": ""
1020 | },
1021 | "require": {
1022 | "php": ">=7.1"
1023 | },
1024 | "provide": {
1025 | "ext-mbstring": "*"
1026 | },
1027 | "suggest": {
1028 | "ext-mbstring": "For best performance"
1029 | },
1030 | "type": "library",
1031 | "extra": {
1032 | "branch-alias": {
1033 | "dev-main": "1.23-dev"
1034 | },
1035 | "thanks": {
1036 | "name": "symfony/polyfill",
1037 | "url": "https://github.com/symfony/polyfill"
1038 | }
1039 | },
1040 | "autoload": {
1041 | "files": [
1042 | "bootstrap.php"
1043 | ],
1044 | "psr-4": {
1045 | "Symfony\\Polyfill\\Mbstring\\": ""
1046 | }
1047 | },
1048 | "notification-url": "https://packagist.org/downloads/",
1049 | "license": [
1050 | "MIT"
1051 | ],
1052 | "authors": [
1053 | {
1054 | "name": "Nicolas Grekas",
1055 | "email": "p@tchwork.com"
1056 | },
1057 | {
1058 | "name": "Symfony Community",
1059 | "homepage": "https://symfony.com/contributors"
1060 | }
1061 | ],
1062 | "description": "Symfony polyfill for the Mbstring extension",
1063 | "homepage": "https://symfony.com",
1064 | "keywords": [
1065 | "compatibility",
1066 | "mbstring",
1067 | "polyfill",
1068 | "portable",
1069 | "shim"
1070 | ],
1071 | "support": {
1072 | "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.25.0"
1073 | },
1074 | "funding": [
1075 | {
1076 | "url": "https://symfony.com/sponsor",
1077 | "type": "custom"
1078 | },
1079 | {
1080 | "url": "https://github.com/fabpot",
1081 | "type": "github"
1082 | },
1083 | {
1084 | "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
1085 | "type": "tidelift"
1086 | }
1087 | ],
1088 | "time": "2021-11-30T18:21:41+00:00"
1089 | }
1090 | ],
1091 | "packages-dev": [],
1092 | "aliases": [],
1093 | "minimum-stability": "stable",
1094 | "stability-flags": [],
1095 | "prefer-stable": false,
1096 | "prefer-lowest": false,
1097 | "platform": {
1098 | "ext-gd": "*",
1099 | "ext-curl": "*",
1100 | "ext-json": "*"
1101 | },
1102 | "platform-dev": [],
1103 | "plugin-api-version": "2.3.0"
1104 | }
1105 |
--------------------------------------------------------------------------------
/src/FlmngrServer.php:
--------------------------------------------------------------------------------
1 | parseRequest();
63 | }
64 |
65 | $codec = 0;
66 | if (isset($request->post['codec'])) {
67 | $codec = $request->post['codec'];
68 | } else if (isset($request->get['codec'])) {
69 | $codec = $request->get['codec'];
70 | }
71 | if ($codec !== 0) {
72 | FlmngrServer::decodeRequest($request, $codec);
73 | error_log(print_r($request, true));
74 | }
75 |
76 | $fileSystem = new FileSystem($config);
77 |
78 | if (FlmngrServer::checkUploadLimit($request)) {
79 | return;
80 | } // file size exceed the limit from php.ini
81 |
82 | if (isset($request->post['embedPreviews'])) {
83 | $fileSystem->embedPreviews = $request->post['embedPreviews'];
84 | }
85 |
86 | $action = NULL;
87 | if ($request->requestMethod === 'POST') {
88 | if (isset($request->post['action'])) {
89 | $action = $request->post['action'];
90 | }
91 | }
92 | else {
93 | if ($request->requestMethod === 'GET') {
94 | $action = $request->get['action'];
95 | }
96 | else {
97 | return;
98 | }
99 | }
100 |
101 | $data = TRUE; // will be optionally filled by request
102 | switch ($action) {
103 | case 'dirList':
104 | $data = $fileSystem->reqGetDirs($request);
105 | break;
106 | case 'dirCreate':
107 | $fileSystem->reqCreateDir($request);
108 | break;
109 | case 'dirRename':
110 | $fileSystem->reqRename($request);
111 | break;
112 | case 'dirDelete':
113 | $fileSystem->reqDeleteDir($request);
114 | break;
115 | case 'dirCopy':
116 | $fileSystem->reqCopyDir($request);
117 | break;
118 | case 'dirMove':
119 | $fileSystem->reqMove($request);
120 | break;
121 | case 'fileList':
122 | $data = $fileSystem->reqGetFiles($request);
123 | break;
124 | case 'fileListPaged':
125 | $data = $fileSystem->reqGetFilesPaged($request);
126 | break;
127 | case 'fileListSpecified':
128 | $data = $fileSystem->reqGetFilesSpecified($request);
129 | break;
130 | case 'fileDelete':
131 | $fileSystem->reqDeleteFiles($request);
132 | break;
133 | case 'fileCopy':
134 | $fileSystem->reqCopyFiles($request);
135 | break;
136 | case 'fileRename':
137 | $fileSystem->reqRename($request);
138 | break;
139 | case 'fileMove':
140 | $fileSystem->reqMoveFiles($request);
141 | break;
142 | case 'fileResize':
143 | $data = $fileSystem->reqResizeFile($request);
144 | break;
145 | case 'fileResize2':
146 | $data = $fileSystem->reqResizeFile2($request);
147 | break;
148 | case 'fileOriginal':
149 | list($mimeType, $data) = $fileSystem->reqGetImageOriginal($request);
150 | header('Content-Type:' . $mimeType);
151 | fpassthru($data);
152 | die();
153 | case 'filePreview':
154 | list($mimeType, $data) = $fileSystem->reqGetImagePreview($request);
155 | header('Content-Type:' . $mimeType);
156 | fpassthru($data);
157 | die();
158 | case 'filePreviewAndResolution':
159 | $data = $fileSystem->reqGetImagePreviewAndResolution($request);
160 | break;
161 | case 'uploadFile':
162 | case 'upload':
163 | $data = $fileSystem->reqUpload($request);
164 | break;
165 | case 'getVersion':
166 | $data = $fileSystem->reqGetVersion($request);
167 | break;
168 | default:
169 | throw new MessageException(Message::createMessage(FALSE,Message::ACTION_NOT_FOUND));
170 | }
171 | $resp = new Response(NULL, $data);
172 | } catch (MessageException $e) {
173 |
174 | if (isset($config["messageExceptionLogger"])) {
175 | $config["messageExceptionLogger"]($e, $request);
176 | } else {
177 |
178 | $sourceException = $e->getSourceException();
179 |
180 | // Log only messages with an exception
181 | if ($sourceException != NULL) {
182 | error_log("FLMNGR exception.\n");
183 | error_log("REQUEST:\n");
184 | error_log(print_r($request, TRUE)."\n");
185 | error_log("\n");
186 |
187 | error_log("RESPONSE:\n");
188 | error_log(print_r($e->getFailMessage(), TRUE)."\n");
189 |
190 | error_log("EXCEPTION:\n");
191 | error_log($sourceException."\n");
192 | }
193 | }
194 |
195 | $resp = new Response($e->getFailMessage(), NULL);
196 | }
197 |
198 | $strResp = JsonCodec::s_toJson($resp);
199 |
200 | try {
201 | http_response_code(200);
202 | header('Content-Type: application/json; charset=UTF-8');
203 | print $strResp;
204 | } catch (Exception $e) {
205 | error_log($e);
206 | }
207 | }
208 |
209 | private static function decodeRequest($request, $codec) {
210 | if ($codec == 1) {
211 | // Base 64 values
212 | foreach($request->post as $key => $value) {
213 | if ($key !== 'codec') {
214 | if (is_array($value)) {
215 | for ($i=0; $ipost[$key][$i] = base64_decode('' . $request->post[$key][$i]);
217 | }
218 | } else {
219 | $request->post[$key] = base64_decode('' . $value);
220 | }
221 | }
222 | }
223 | foreach($request->get as $key => $value) {
224 | if ($key !== 'codec') {
225 | if (is_array($value)) {
226 | for ($i=0; $iget[$key][$i] = base64_decode('' . $request->get[$key][$i]);
228 | }
229 | } else {
230 | $request->get[$key] = base64_decode('' . $value);
231 | }
232 | }
233 | }
234 | return; // OK
235 | }
236 | throw new Exception('Unknown codec = ' . $codec . ' received from the client. You need to update the server side or check did you set Flmngr.codec correctly.');
237 | }
238 |
239 | private static function iniGetBytes($val) {
240 | $val = trim(ini_get($val));
241 | if ($val != '') {
242 | $last = strtolower(substr($val, strlen($val) - 1));
243 | }
244 | else {
245 | $last = '';
246 | }
247 | if ($last !== '') {
248 | $val = substr($val, 0, strlen($val) - 1);
249 | }
250 |
251 | switch ($last) {
252 | // The 'G' modifier is available since PHP 5.1.0
253 | case 'g':
254 | $val *= 1024;
255 | // fall through
256 | case 'm':
257 | $val *= 1024;
258 | // fall through
259 | case 'k':
260 | $val *= 1024;
261 | // fall through
262 | }
263 |
264 | return $val;
265 | }
266 |
267 | private static function checkUploadLimit($request) {
268 | $isError = FALSE;
269 | $maxSizeParameter = NULL;
270 | if (isset($_SERVER['CONTENT_LENGTH'])) {
271 | if (
272 | $_SERVER['CONTENT_LENGTH'] >
273 | FlmngrServer::iniGetBytes('post_max_size')
274 | ) {
275 | $isError = TRUE;
276 | $maxSizeParameter = 'post_max_size';
277 | }
278 | }
279 | if (!$isError) {
280 | if (isset($request->files['file'])) {
281 | $file = $request->files['file'];
282 | if ($file['tmp_name'] === '') {
283 | $isError = TRUE;
284 | $maxSizeParameter = 'upload_max_filesize';
285 | }
286 | }
287 | }
288 |
289 | if ($isError) {
290 | $maxSizeValueRaw = ini_get($maxSizeParameter);
291 | $maxSizeValueFormatted = FlmngrServer::iniGetBytes($maxSizeParameter);
292 |
293 | $resp = new Response(
294 | Message::createMessage(
295 | FALSE,
296 | Message::FILE_SIZE_EXCEEDS_SYSTEM_LIMIT,
297 | '' . $_SERVER['CONTENT_LENGTH'],
298 | '' . $maxSizeValueFormatted,
299 | $maxSizeParameter . " = " . $maxSizeValueRaw
300 | ),
301 | NULL
302 | );
303 |
304 | $strResp = JsonCodec::s_toJson($resp);
305 |
306 | try {
307 | http_response_code(200);
308 | header('Content-Type: application/json; charset=UTF-8');
309 | print $strResp;
310 | } catch (Exception $e) {
311 | error_log($e);
312 | }
313 |
314 | return TRUE;
315 | }
316 | else {
317 | return FALSE;
318 | }
319 |
320 | }
321 |
322 | }
323 |
--------------------------------------------------------------------------------
/src/fs/CachedFile.php:
--------------------------------------------------------------------------------
1 | fileRelative = $fileRelative;
48 | $this->driverFiles = $driverFiles;
49 | $this->driverCache = $driverCache;
50 |
51 | $this->cacheFileRelative = '/previews' . $fileRelative;
52 |
53 | $this->cacheFileJsonRelative = $this->cacheFileRelative . '.json';
54 | $this->cacheFilePreviewRelative = $this->cacheFileRelative . '.png';
55 |
56 | $this->driverCache->makeRootDir();
57 | }
58 |
59 | // Clears cache for this file
60 | function delete() {
61 | if ($this->driverCache->exists($this->cacheFileJsonRelative)) {
62 | $this->driverCache->delete($this->cacheFileJsonRelative);
63 | }
64 | if ($this->driverCache->exists($this->cacheFilePreviewRelative)) {
65 | $this->driverCache->delete($this->cacheFilePreviewRelative);
66 | }
67 | }
68 |
69 | function getInfo() {
70 | if (!$this->driverCache->exists($this->cacheFileJsonRelative)) {
71 |
72 | try {
73 |
74 | // We do not calculate BlurHash/width/height here due to this is a long operation
75 | // BlurHash/width/height will be calculated and JSON file will be updated on the first getCachedImagePreview() call
76 |
77 | $info = [
78 | 'mtime' => $this->driverFiles->lastModified($this->fileRelative),
79 | 'size' => $this->driverFiles->size($this->fileRelative),
80 | ];
81 | $this->writeInfo($info);
82 |
83 | } catch (Exception $e) {
84 | error_log("Exception while getting image size of " . $this->fileRelative);
85 | error_log($e);
86 | }
87 | }
88 |
89 | $content = $this->driverCache->get($this->cacheFileJsonRelative);
90 | $json = json_decode($content, TRUE);
91 | if ($json === NULL) {
92 | error_log("Unable to parse JSON from file " . $this->cacheFileJsonRelative);
93 | return NULL;
94 | }
95 |
96 | return $json;
97 | }
98 |
99 | private function writeInfo($info) {
100 | $dirname = dirname($this->cacheFileJsonRelative);
101 | if (!$this->driverCache->exists($dirname)) {
102 | $this->driverCache->makeDirectory($dirname);
103 | }
104 | $this->driverCache->put($this->cacheFileJsonRelative, json_encode($info));
105 | }
106 |
107 | function getPreview($preview_width, $preview_height, $contents) {
108 | $cacheFilePreviewRelative = $this->cacheFileRelative . '.png';
109 |
110 | if ($this->driverCache->exists($cacheFilePreviewRelative)) {
111 | $info = $this->getInfo();
112 | if (
113 | $info == NULL ||
114 | $info['mtime'] !== $this->driverFiles->lastModified($this->fileRelative) ||
115 | $info['size'] !== $this->driverFiles->size($this->fileRelative)
116 | ) {
117 | // Delete preview if it was changed, will be recreated below
118 | $this->driverCache->delete($cacheFilePreviewRelative);
119 | }
120 | }
121 |
122 | $resizedImage = NULL;
123 | if (!$this->driverCache->exists($cacheFilePreviewRelative)) {
124 |
125 | if (Utils::getMimeType($this->fileRelative) === 'image/svg+xml') {
126 | return ['image/svg+xml', $this->fileRelative, FALSE]; // FALSE means from files folder
127 | }
128 |
129 | if ($contents === NULL) {
130 | $contents = $this->driverFiles->get($this->fileRelative);
131 | }
132 | $image = imagecreatefromstring($contents);
133 | if (!$image) {
134 | throw new MessageException(
135 | Message::createMessage(FALSE,Message::IMAGE_PROCESS_ERROR)
136 | );
137 | }
138 |
139 | $orientation = $this->driverFiles->getExifOrientation($this->fileRelative);
140 | if ($orientation === 3) {
141 | $image = imagerotate($image, 180, 0);
142 | } else if ($orientation === 6) {
143 | $image = imagerotate($image, -90, 0);
144 | } else if ($orientation === 8) {
145 | $image = imagerotate($image, 90, 0);
146 | }
147 |
148 | $original_width = imagesx($image);
149 | $original_height = imagesy($image);
150 | if ($original_width == FALSE || $original_height == FALSE) {
151 | throw new MessageException(
152 | Message::createMessage(FALSE, Message::IMAGE_PROCESS_ERROR)
153 | );
154 | }
155 |
156 | $original_ratio = $original_width / $original_height;
157 |
158 | if ($preview_width == NULL) {
159 | $preview_width = max(1, floor($original_ratio * $preview_height));
160 | }
161 | else {
162 | if ($preview_height == NULL) {
163 | $preview_height = max(1, floor((1 / $original_ratio) * $preview_width));
164 | }
165 | }
166 |
167 | $preview_ratio = $preview_width / $preview_height;
168 |
169 | if ($original_ratio >= $preview_ratio) {
170 | $preview_height = max(1, floor($original_height * $preview_width / $original_width));
171 | }
172 | else {
173 | $preview_width = max(1, floor($original_width * $preview_height / $original_height));
174 | }
175 |
176 | $resizedImage = imagecreatetruecolor($preview_width, $preview_height);
177 |
178 | $colorGray1 = imagecolorallocate($resizedImage, 240, 240, 240);
179 | $colorGray2 = imagecolorallocate($resizedImage, 250, 250, 250);
180 | $rectSize = 20;
181 | for ($x = 0; $x <= floor($preview_width / $rectSize); $x++) {
182 | for ($y = 0; $y <= floor($preview_height / $rectSize); $y++) {
183 | imagefilledrectangle($resizedImage, $x * $rectSize, $y * $rectSize, $preview_width, $preview_height, ($x + $y) % 2 == 0 ? $colorGray1 : $colorGray2);
184 | }
185 | }
186 |
187 | imagecopyresampled(
188 | $resizedImage,
189 | $image,
190 | 0,
191 | 0,
192 | 0,
193 | 0,
194 | $preview_width,
195 | $preview_height,
196 | $original_width,
197 | $original_height
198 | );
199 |
200 | //$i = strrpos($cacheFilePreviewRelative, '/');
201 | //$cacheDirPreviewRelative = substr($cacheFilePreviewRelative, 0, $i);
202 | // clearstatcache(TRUE, $cacheDirPreviewAbsolute);
203 |
204 | $imageContents = Utils::writeImageContents(Utils::getExt($cacheFilePreviewRelative), $resizedImage, 80);
205 |
206 | if ($this->driverCache->put($cacheFilePreviewRelative, $imageContents) === FALSE) {
207 | throw new MessageException(
208 | Message::createMessage(
209 | TRUE,
210 | Message::FM_UNABLE_TO_WRITE_PREVIEW_IN_CACHE_DIR,
211 | $cacheFilePreviewRelative
212 | )
213 | );
214 | }
215 | }
216 |
217 | // Update BlurHash
218 | if ($resizedImage == NULL) {
219 | $resizedImage = @imagecreatefromstring($this->driverCache->get($cacheFilePreviewRelative));
220 | }
221 |
222 | $pixels = [];
223 | $xxCache = imagesx($resizedImage);
224 | $yyCache = imagesy($resizedImage);
225 | for ($y = 0; $y < $yyCache; $y++) {
226 | $row = [];
227 | for ($x = 0; $x < $xxCache; $x++) {
228 | $index = imagecolorat($resizedImage, $x, $y);
229 | $colors = imagecolorsforindex($resizedImage, $index);
230 | $row[] = [$colors['red'], $colors['green'], $colors['blue']];
231 | }
232 | $pixels[] = $row;
233 | }
234 |
235 | $components_x = 4;
236 | $components_y = 3;
237 |
238 | $cachedImageInfo = $this->getInfo();
239 | if (count($pixels) > 0) {
240 | $cachedImageInfo["blurHash"] = Blurhash::encode($pixels, $components_x, $components_y);
241 | if (isset($original_width)) {
242 | $cachedImageInfo["width"] = $original_width;
243 | }
244 | if (isset($original_height)) {
245 | $cachedImageInfo["height"] = $original_height;
246 | }
247 | $this->writeInfo($cachedImageInfo);
248 | }
249 |
250 | return ['image/png', $cacheFilePreviewRelative, TRUE]; // TRUE means from cache folder
251 | }
252 |
253 | }
--------------------------------------------------------------------------------
/src/fs/DriverLocal.php:
--------------------------------------------------------------------------------
1 | driverCache = $driverCache;
48 | }
49 |
50 | function __construct($config, $isCacheDriver = FALSE) {
51 | $this->isCacheDriver = $isCacheDriver;
52 |
53 | if (isset($config['clearCacheChunks'])) {
54 | $this->clearCacheChunks = $config['clearCacheChunks'];
55 | }
56 |
57 | if (!in_array('dir', array_keys($config)) || $config['dir'] === NULL) {
58 | try {
59 | throw new MessageException(
60 | Message::createMessage(
61 | $this->isCacheDriver,
62 | Message::FM_ROOT_DIR_IS_NOT_SET
63 | )
64 | );
65 | } catch (Exception $e) {
66 | error_log(print_r($e, TRUE));
67 | }
68 | }
69 |
70 | $this->dir = rtrim($config['dir'], '\\/');
71 |
72 | $this->makeRootDir();
73 |
74 | if (!is_readable($this->dir)) {
75 | throw new MessageException(
76 | Message::createMessage(
77 | $this->isCacheDriver,
78 | Message::FM_DIR_IS_NOT_READABLE,
79 | $this->dir
80 | )
81 | );
82 | }
83 |
84 | if (!is_writable($this->dir)) {
85 | throw new MessageException(
86 | Message::createMessage(
87 | $this->isCacheDriver,
88 | Message::FM_DIR_IS_NOT_WRITABLE,
89 | $this->dir
90 | )
91 | );
92 | }
93 |
94 | }
95 |
96 | private function getCacheChunkPath($chunkName) {
97 | return "/fs/" . $chunkName . ".json";
98 | }
99 |
100 | // Returns "path-to-cache/fs/driver-name/chunk-name.json" content
101 | // i. e. ".cache/fs/all-files.json"
102 | // if file modify time is not older then $validSeconds
103 | // Returns NULL if file does not exist of outdated
104 | function &getCacheChunk($chunkName, $validSeconds) {
105 |
106 | if (in_array($chunkName, array_keys($this->cacheChunks))) {
107 | return $this->cacheChunks[$chunkName];
108 | }
109 |
110 | $profile = new Profile("getCacheChunk()");
111 | $profile->profile("Get chunk " . $chunkName);
112 |
113 | $chunkPath = $this->getCacheChunkPath($chunkName);
114 | if (
115 | $this->driverCache->fileExists($chunkPath) &&
116 | time() - $this->driverCache->lastModified($chunkPath) <= $validSeconds &&
117 | !in_array($chunkName, $this->clearCacheChunks)
118 | ) {
119 | $profile->profile("File read start: " . $chunkPath);
120 | $content = $this->driverCache->get($chunkPath);
121 | $profile->profile("File was finish: " . $chunkPath);
122 |
123 | $json = json_decode($content, JSON_OBJECT_AS_ARRAY);
124 | $profile->profile("JSON decoded: " . $chunkPath);
125 | $profile->total();
126 |
127 | $this->cacheChunks[$chunkName] = $json;
128 |
129 | return $json;
130 | } else {
131 | if (in_array($chunkName, $this->clearCacheChunks))
132 | error_log("Forced invalidating cache chunk");
133 | $null = NULL;
134 | return $null;
135 | }
136 |
137 | }
138 |
139 | function setCacheChunk($chunkName, &$json) {
140 | $chunkPath = $this->getCacheChunkPath($chunkName);
141 | $chunkPathDir = dirname($chunkPath);
142 | $this->driverCache->makeDirectory($chunkPathDir, 0777, TRUE);
143 | $this->driverCache->put($chunkPath, json_encode($json, JSON_PRETTY_PRINT));
144 | }
145 |
146 | function deleteCacheChunk($chunkName) {
147 | try {
148 | $chunkPath = $this->getCacheChunkPath($chunkName);
149 | if ($this->driverCache->fileExists($chunkPath)) {
150 | $this->driverCache->delete($chunkPath);
151 | }
152 | } catch (Exception $e) {
153 | error_log("Error on deleting cache chunk");
154 | error_log($e);
155 | }
156 | }
157 |
158 | function getDriverName() {
159 | return "Local";
160 | }
161 |
162 | function getDir() {
163 | return $this->dir;
164 | }
165 |
166 | function size($path) {
167 | return filesize($this->dir . $path);
168 | }
169 |
170 | function lastModified($path) {
171 | return filemtime($this->dir . $path);
172 | }
173 |
174 | function makeDirectory($path) {
175 |
176 | if (file_exists($this->dir . $path) && is_dir($this->dir . $path)) {
177 | return;
178 | }
179 |
180 | $result = mkdir($this->dir . $path, 0777, TRUE);
181 | if (
182 | !$result &&
183 | !(file_exists($this->dir . $path) && is_dir($this->dir . $path)) // could be created in another thread (request)
184 | ) {
185 | throw new MessageException(
186 | Message::createMessage(
187 | $this->isCacheDriver,
188 | Message::FM_UNABLE_TO_CREATE_DIRECTORY,
189 | $path
190 | )
191 | );
192 | }
193 | }
194 |
195 | function getRootDirName() {
196 | $i = strrpos($this->dir, '/');
197 | if ($i === FALSE) {
198 | return $this->dir;
199 | }
200 | return substr($this->dir, $i + 1);
201 | }
202 |
203 | function makeRootDir() {
204 | if (!$this->directoryExists("")) {
205 | $this->makeDirectory("");
206 | }
207 | }
208 |
209 | const MAX_DEPTH = 20;
210 |
211 | function allDirectories($dirFrom, $maxDepth) {
212 | $dirs = [];
213 | $fDir = $this->dir . $dirFrom;
214 |
215 | if (!file_exists($fDir) || !is_dir($fDir)) {
216 | error_log("Root directory does not exist: " . $fDir);
217 | throw new MessageException(
218 | Message::createMessage(
219 | $this->isCacheDriver,
220 | Message::FM_ROOT_DIR_DOES_NOT_EXIST
221 | )
222 | );
223 | }
224 | $hideDirs[] = '.cache';
225 |
226 | $path = '';
227 | if ($dirFrom != '') {
228 | $path = rtrim(basename($this->dir) . '/' . rtrim(dirname($dirFrom), '/'), '/');
229 | }
230 | $this->getDirs__fill($dirs, $fDir, $hideDirs, $path, 0, $maxDepth);
231 |
232 | return $dirs;
233 | }
234 |
235 | private function getDirs__fill(&$dirs, $fDir, $hideDirs, $path, $currDepth, $maxDepth) {
236 | $i = strrpos($fDir, '/');
237 | if ($i !== FALSE) {
238 | $dirName = substr($fDir, $i + 1);
239 | }
240 | else {
241 | $dirName = $fDir;
242 | }
243 |
244 | $dirs[] = (strlen($path) > 0 ? '/' . $path : '') . '/' . $dirName;
245 |
246 | $rawDirs = glob($fDir . '/*', GLOB_ONLYDIR);
247 | if ($rawDirs === FALSE) {
248 | throw new MessageException(
249 | Message::createMessage(
250 | $this->isCacheDriver,
251 | Message::FM_UNABLE_TO_LIST_CHILDREN_IN_DIRECTORY,
252 | $path
253 | )
254 | );
255 | }
256 |
257 | foreach ($rawDirs as $dir) {
258 | $dir = str_replace($fDir . '/', '', $dir);
259 |
260 | $isHide = FALSE;
261 | for ($j = 0; $j < count($hideDirs) && !$isHide; $j++) {
262 | $isHide = $isHide || fnmatch($hideDirs[$j], $dir);
263 | }
264 |
265 | if (is_dir($fDir . '/' . $dir) && !$isHide && $currDepth < min($maxDepth, self::MAX_DEPTH)) {
266 | $this->getDirs__fill(
267 | $dirs,
268 | $fDir . '/' . $dir,
269 | $hideDirs,
270 | $path . (strlen($path) > 0 ? '/' : '') . $dirName,
271 | $currDepth + 1,
272 | $maxDepth
273 | );
274 | }
275 | }
276 | }
277 |
278 | function directories($path) {
279 | $dirs = [];
280 | try {
281 | $rawDirs = glob($this->dir . $path . '/*', GLOB_ONLYDIR);
282 | } catch (Exception $e) {
283 | throw new MessageException(
284 | Message::createMessage(
285 | $this->isCacheDriver,
286 | Message::FM_UNABLE_TO_LIST_CHILDREN_IN_DIRECTORY,
287 | $path
288 | ),
289 | $e
290 | );
291 | }
292 | foreach ($rawDirs as $dir) {
293 | $dirs[] = str_replace($this->dir . $path . '/', '', $dir);
294 | }
295 | return $dirs;
296 | }
297 |
298 | function files($path) {
299 | try {
300 | $rawFiles = glob($this->dir . $path . '/*');
301 | } catch (Exception $e) {
302 | error_log("Error while reading dir contents: " . $path);
303 | error_log($e);
304 | throw new MessageException(
305 | Message::createMessage(
306 | $this->isCacheDriver,
307 | Message::FM_UNABLE_TO_LIST_CHILDREN_IN_DIRECTORY,
308 | $path
309 | ),
310 | $e
311 | );
312 | }
313 |
314 | $files = [];
315 | foreach ($rawFiles as $file) {
316 | if (is_file($file)) {
317 | $filename = basename($file);
318 | $files[] = [
319 | 'name' => $filename,
320 | 'mtime' => $this->lastModified($path . '/' . $filename),
321 | 'size' => $this->size($path . '/' . $filename),
322 | ];
323 | }
324 | }
325 | return $files;
326 | }
327 |
328 | function move($path, $newName) {
329 | $res = rename($this->dir . $path, $this->dir . $newName);
330 | if ($res === FALSE) {
331 | throw new MessageException(
332 | Message::createMessage(
333 | $this->isCacheDriver,
334 | Message::FM_UNABLE_TO_RENAME
335 | )
336 | );
337 | }
338 | }
339 |
340 | function getMimeType($path) {
341 | return Utils::getMimeType($this->dir . $path);
342 | }
343 |
344 | function exists($path) {
345 | return file_exists($this->dir . $path);
346 | }
347 |
348 | function directoryExists($path) {
349 | return file_exists($this->dir . $path) && is_dir($this->dir . $path);
350 | }
351 |
352 | function fileExists($path) {
353 | return file_exists($this->dir . $path) && is_file($this->dir . $path);
354 | }
355 |
356 | // Get file contents
357 | function get($path) {
358 | return file_get_contents($this->dir . $path);
359 | }
360 |
361 | function getExifOrientation($path) {
362 | if (function_exists('exif_read_data')) {
363 | $exif = @exif_read_data($this->dir . $path);
364 | return (isset($exif) && isset($exif['Orientation'])) ? $exif['Orientation'] : 0;
365 | } else {
366 | return 0;
367 | }
368 | }
369 |
370 | // Put file contents
371 | function put($path, $contents) {
372 | $this->makeDirectory(dirname($path)); // ensure dir exists
373 | file_put_contents($this->dir . $path, $contents);
374 | }
375 |
376 | // Dir (not empty) or file
377 | function delete($path) {
378 | if (is_file($this->dir . $path)) {
379 | $result = @unlink($this->dir . $path);
380 | if ($result === FALSE) {
381 | throw new MessageException(
382 | Message::createMessage(
383 | $this->isCacheDriver,
384 | Message::UNABLE_TO_DELETE_FILE,
385 | $path
386 | )
387 | );
388 | }
389 |
390 | }
391 | else {
392 |
393 | // There can be a try to delete unexisting file (in cache dir),
394 | // so we will have is_file() == false and fall here.
395 | // So there is required to check does this dir actually exists.
396 | if (is_dir($this->dir . $path)) {
397 |
398 | foreach ($this->directories($path) as $dir) {
399 | $this->delete($path . '/' . $dir);
400 | }
401 |
402 | foreach ($this->files($path) as $file) {
403 | $this->delete($path . '/' . $file['name']);
404 | }
405 |
406 | $this->deleteDirectory($path);
407 |
408 | }
409 | }
410 | }
411 |
412 | // Delete empty dir
413 | function deleteDirectory($path) {
414 | $result = rmdir($this->dir . $path);
415 | if ($result === FALSE) {
416 | throw new MessageException(
417 | Message::createMessage(
418 | $this->isCacheDriver,
419 | Message::FM_UNABLE_TO_DELETE_DIRECTORY
420 | )
421 | );
422 | }
423 | }
424 |
425 | // Returns stream for `fpassthru`
426 | function readStream($path) {
427 | return fopen($this->dir . $path, 'rb');
428 | }
429 |
430 | function copyFile($pathSrc, $pathDst) {
431 | $res = copy($this->dir . $pathSrc, $this->dir . $pathDst);
432 | if ($res === FALSE) {
433 | throw new MessageException(
434 | Message::createMessage(
435 | $this->isCacheDriver,
436 | Message::FM_ERROR_ON_COPYING_FILES
437 | )
438 | );
439 | }
440 | }
441 |
442 | function copyDirectory($src, $dst) {
443 | $this->copyDirectory__recurse($src, $dst, FALSE);
444 | }
445 |
446 | private function copyDirectory__recurse($src, $dst, $createThisDstDir) {
447 | // Do not create a root directory (target directory to copy inside already exists)
448 | if ($createThisDstDir) {
449 | $this->makeDirectory($dst);
450 | }
451 |
452 | $fFiles = $this->files($src);
453 | foreach ($fFiles as $file) {
454 | $fileName = $file['name'];
455 | if ($fileName != '.' && $fileName != '..') {
456 | if ($this->directoryExists(TRUE, $src . '/' . $fileName)) {
457 | $this->copyDir__recurse(
458 | $src . '/' . $fileName,
459 | $dst . '/' . $fileName,
460 | TRUE
461 | );
462 | }
463 | else {
464 | $this->copyFile($src . '/' . $fileName, $dst . '/' . $fileName);
465 | }
466 | }
467 | }
468 | }
469 |
470 | function uploadFile__getName($file, $dir, $isOverwrite) {
471 | if ($isOverwrite) {
472 | // Remove existing file if exists
473 | $name = $file['name'];
474 | if ($this->exists($dir . '/' . $name))
475 | $this->delete($dir . '/' . $name);
476 | } else {
477 | // Get free file name
478 | $i = -1;
479 | do {
480 | $i++;
481 | if ($i == 0) {
482 | $name = $file['name'];
483 | }
484 | else {
485 | $name =
486 | Utils::getNameWithoutExt($file['name']) .
487 | '_' .
488 | $i .
489 | (Utils::getExt($file['name']) != NULL
490 | ? '.' . Utils::getExt($file['name'])
491 | : '');
492 | }
493 | $ok = !$this->exists($dir . '/' . $name);
494 | } while (!$ok);
495 | }
496 | return $name;
497 | }
498 |
499 | function uploadFile($file, $dir, $isOverwrite) {
500 |
501 | $name = $this->uploadFile__getName($file, $dir, $isOverwrite);
502 |
503 | $dirDst = $this->dir . $dir;
504 | if (!file_exists($dirDst)) {
505 | mkdir($dirDst, 0777, true);
506 | }
507 |
508 | $result = move_uploaded_file($file['tmp_name'], $dirDst. '/' . $name);
509 | if (!$result) {
510 | error_log("Unable to upload file " . $file['tmp_name'] . " to " . $dir . '/' . $file['name']);
511 | throw new MessageException(
512 | Message::createMessage(
513 | $this->isCacheDriver,
514 | Message::WRITING_FILE_ERROR,
515 | $dir . '/' . $file['name']
516 | )
517 | );
518 | }
519 |
520 | return $name;
521 | }
522 |
523 | }
--------------------------------------------------------------------------------
/src/fs/FileSystem.php:
--------------------------------------------------------------------------------
1 | driverFiles = in_array('driverFiles', array_keys($config)) ? $config['driverFiles'] : new DriverLocal(['dir' => $dirFiles]);
43 | $this->driverCache = in_array('driverCache', array_keys($config)) ? $config['driverCache'] : new DriverLocal(['dir' => $dirCache], TRUE);
44 | $this->driverFiles->setDriverCache($this->driverCache);
45 | }
46 |
47 | private function getRelativePath($path) {
48 | if (strpos($path, '..') !== FALSE) {
49 | throw new MessageException(
50 | Message::createMessage(
51 | FALSE,
52 | Message::FM_DIR_NAME_CONTAINS_INVALID_SYMBOLS
53 | )
54 | );
55 | }
56 |
57 | if (strpos($path, '/') !== 0) {
58 | $path = '/' . $path;
59 | }
60 |
61 | $rootDirName = $this->driverFiles->getRootDirName();
62 |
63 | if ($path === '/Files') {
64 | $path = '/' . $rootDirName;
65 | }
66 | else {
67 | if (strpos($path, '/Files/') === 0) {
68 | $path = '/' . $rootDirName . '/' . substr($path, 7);
69 | }
70 | }
71 | if (strpos($path, '/' . $rootDirName) !== 0) {
72 | throw new MessageException(
73 | Message::createMessage(
74 | FALSE,
75 | Message::FM_DIR_NAME_INCORRECT_ROOT
76 | )
77 | );
78 | }
79 |
80 | return substr($path, strlen('/' . $rootDirName));
81 | }
82 |
83 | /**
84 | * Requests from controller
85 | */
86 | function reqGetDirs($request) {
87 | $hideDirs = isset($request->post['hideDirs']) ? $request->post['hideDirs'] : [];
88 |
89 | // It's allowed to send with first slash or without it (equivalent forms).
90 | // The same is for trailing slash
91 | $dirFrom = isset($request->post['fromDir']) ? $request->post['fromDir'] : '';
92 | $dirFrom = '/' . trim($dirFrom, '/');
93 | if ($dirFrom === '/')
94 | $dirFrom = '';
95 | if (strpos($dirFrom, '..') !== FALSE) {
96 | throw new MessageException(
97 | Message::createMessage(
98 | FALSE,
99 | Message::FM_DIR_NAME_CONTAINS_INVALID_SYMBOLS
100 | )
101 | );
102 | }
103 |
104 | // 0 means get dirs from $dirFrom only
105 | $maxDepth = isset($request->post['maxDepth']) ? $request->post['maxDepth'] : 99;
106 |
107 | $dirs = [];
108 | $hideDirs[] = '.cache';
109 |
110 | // Add root directory if it is ""
111 | $dirRoot = $this->driverFiles->getRootDirName();
112 | $i = strrpos($dirRoot, '/');
113 | if ($i !== FALSE) {
114 | $dirRoot = substr($dirRoot, $i + 1);
115 | }
116 | $dirRoot .= $dirFrom;
117 |
118 | $addFilesPrefix = $dirRoot === "";
119 |
120 | // A flat list of child directories
121 | $dirsStr = $this->driverFiles->allDirectories($dirFrom, $maxDepth);
122 |
123 | // Add files
124 | foreach ($dirsStr as $dirStr) {
125 | $dirArr = preg_split('/\\//', $dirStr);
126 | if ($addFilesPrefix) {
127 | array_unshift($dirArr, "Files");
128 | }
129 | $filled = count($dirArr) <= $maxDepth + 1;
130 | $dirs[] = new FMDir(
131 | $dirArr[count($dirArr) - 1],
132 | join('/', array_splice($dirArr, 0, count($dirArr) - 1)),
133 | $filled
134 | );
135 | }
136 |
137 | return $dirs;
138 | }
139 |
140 | // Legacy request for Flmngr v1
141 | public function reqGetFiles($request) {
142 | $path = $request->post['d'];
143 |
144 | // with "/root_dir_name" in the start
145 | $path = $this->getRelativePath($path);
146 |
147 | $fFiles = $this->driverFiles->files($path);
148 |
149 | $files = [];
150 | for ($i = 0; $i < count($fFiles); $i++) {
151 | $fFile = $fFiles[$i]['name'];
152 |
153 | if (preg_match('/-(preview|medium|original)\\.[^.]+$/', $fFile) === 1) {
154 | continue;
155 | }
156 |
157 | $filePath = $path . '/' . $fFile;
158 | if (is_file($filePath)) {
159 | $preview = NULL;
160 | try {
161 | $imageInfo = Utils::getImageInfo($filePath);
162 | if ($this->embedPreviews === TRUE) {
163 | $preview = $this->getCachedImagePreview($filePath, NULL);
164 | $preview[1] = ($preview[2] === FALSE ? $this->driverFiles : $this->driverCache)->get($preview[1]); // convert path to content
165 | $preview = "data:" . $preview[0] . ";base64," . base64_encode($preview[1]);
166 | }
167 |
168 | } catch (Exception $e) {
169 | $imageInfo = new ImageInfo();
170 | $imageInfo->width = NULL;
171 | $imageInfo->height = NULL;
172 | }
173 | $file = new FMFile(
174 | $path,
175 | $fFile,
176 | filesize($filePath),
177 | filemtime($filePath),
178 | $imageInfo
179 | );
180 | if ($preview != NULL) {
181 | $file->preview = $preview;
182 | }
183 |
184 | $files[] = $file;
185 | }
186 | }
187 |
188 | return $files;
189 | }
190 |
191 | public function reqGetFilesPaged($request) {
192 | $dirPath = $request->post['dir'];
193 | $maxFiles = $request->post['maxFiles'];
194 | $alwaysInclude = isset($request->post['alwaysInclude']) ? $request->post['alwaysInclude'] : []; // does not affect to filters, only for paged files
195 | $lastFile = isset($request->post['lastFile']) ? $request->post['lastFile'] : NULL;
196 | $lastIndex = isset($request->post['lastIndex']) ? $request->post['lastIndex'] : NULL;
197 | $whiteList = isset($request->post['whiteList']) ? $request->post['whiteList'] : [];
198 | $blackList = isset($request->post['blackList']) ? $request->post['blackList'] : [];
199 | $filter = isset($request->post['filter']) ? $request->post['filter'] : "**";
200 | $orderBy = $request->post['orderBy'];
201 | $orderAsc = $request->post['orderAsc'];
202 | $formatIds = $request->post['formatIds'];
203 | $formatSuffixes = $request->post['formatSuffixes'];
204 |
205 | // Convert /root_dir/1/2/3 to 1/2/3
206 | $dirPath = $this->getRelativePath($dirPath);
207 |
208 |
209 | $files = []; // file name to sort values (like [filename, date, size])
210 | $formatFiles = []; // format to array(owner file name to file name)
211 | foreach ($formatIds as $formatId) {
212 | $formatFiles[$formatId] = [];
213 | }
214 |
215 | $fFiles = $this->driverFiles->files($dirPath);
216 | $profile = new Profile("reqGetFilesPaged()");
217 |
218 | foreach ($fFiles as $file) {
219 |
220 | $format = NULL;
221 | $name = Utils::getNameWithoutExt($file['name']);
222 | if (Utils::isImage($file['name'])) {
223 | for ($i = 0; $i < count($formatIds); $i++) {
224 | $isFormatFile = Utils::endsWith($name, $formatSuffixes[$i]);
225 | if ($isFormatFile) {
226 | $format = $formatIds[$i];
227 | $name = substr($name, 0, -strlen($formatSuffixes[$i]));
228 | break;
229 | }
230 | }
231 | }
232 |
233 | $ext = Utils::getExt($file['name']);
234 | if ($ext != NULL) {
235 | $name = $name . '.' . $ext;
236 | }
237 |
238 | if ($format == NULL) {
239 | switch ($orderBy) {
240 | case 'date':
241 | $files[$file['name']] = [
242 | $file['mtime'],
243 | $file['name'],
244 | $file['size'],
245 | ];
246 | break;
247 | case 'size':
248 | $files[$file['name']] = [
249 | $file['size'],
250 | $file['name'],
251 | $file['mtime'],
252 | ];
253 | break;
254 | case 'name':
255 | default:
256 | $files[$file['name']] = [
257 | $file['name'],
258 | $file['mtime'],
259 | $file['size'],
260 | ];
261 | break;
262 | }
263 | }
264 | else {
265 | $formatFiles[$format][$name] = $file['name'];
266 | }
267 | }
268 | $profile->profile("Scan dir finished");
269 |
270 | // Remove files outside of white list, and their formats too
271 | if (count($whiteList) > 0) { // only if whitelist is set
272 | foreach ($files as $file => $v) {
273 |
274 | $isMatch = FALSE;
275 | foreach ($whiteList as $mask) {
276 | if (fnmatch($mask, $file, FNM_CASEFOLD) === TRUE) {
277 | $isMatch = TRUE;
278 | }
279 | }
280 |
281 | if (!$isMatch) {
282 | unset($files[$file]);
283 | foreach ($formatFiles as $format => $formatFilesCurr) {
284 | if (isset($formatFilesCurr[$file])) {
285 | unset($formatFilesCurr[$file]);
286 | }
287 | }
288 | }
289 | }
290 | }
291 |
292 | $profile->profile("White list finished");
293 |
294 | // Remove files outside of black list, and their formats too
295 | foreach ($files as $file => $v) {
296 |
297 | $isMatch = FALSE;
298 | foreach ($blackList as $mask) {
299 | if (fnmatch($mask, $file, FNM_CASEFOLD) === TRUE) {
300 | $isMatch = TRUE;
301 | }
302 | }
303 |
304 | if ($isMatch) {
305 | unset($files[$file]);
306 | foreach ($formatFiles as $format => $formatFilesCurr) {
307 | if (isset($formatFilesCurr[$file])) {
308 | unset($formatFilesCurr[$file]);
309 | }
310 | }
311 | }
312 | }
313 |
314 | $countTotal = count($files);
315 |
316 | $profile->profile("Black list finished");
317 |
318 | // Remove files not matching the filter, and their formats too
319 | foreach ($files as $file => $v) {
320 |
321 | $isMatch = fnmatch($filter, $file) === TRUE;
322 | if (!$isMatch) {
323 | unset($files[$file]);
324 | foreach ($formatFiles as $format => $formatFilesCurr) {
325 | if (isset($formatFilesCurr[$file])) {
326 | unset($formatFilesCurr[$file]);
327 | }
328 | }
329 | }
330 | }
331 |
332 | $countFiltered = count($files);
333 |
334 | $profile->profile("Filter finished");
335 |
336 | uasort($files, function ($arr1, $arr2) {
337 |
338 | for ($i = 0; $i < count($arr1); $i++) {
339 | if (is_string($arr1[$i])) {
340 | $v = strnatcmp($arr1[$i], $arr2[$i]);
341 | if ($v !== 0) {
342 | return $v;
343 | }
344 | }
345 | else {
346 | if ($arr1[$i] > $arr2[$i]) {
347 | return 1;
348 | }
349 | if ($arr1[$i] < $arr2[$i]) {
350 | return -1;
351 | }
352 | }
353 | }
354 |
355 | return 0;
356 | });
357 |
358 | $fileNames = array_keys($files);
359 |
360 | if (strtolower($orderAsc) !== "true") {
361 | $fileNames = array_reverse($fileNames);
362 | }
363 |
364 | $profile->profile("Sorting finished");
365 |
366 | $startIndex = 0;
367 | if ($lastIndex) {
368 | $startIndex = $lastIndex + 1;
369 | }
370 | if ($lastFile) { // $lastFile priority is higher than $lastIndex
371 | $i = array_search($lastFile, $fileNames);
372 | if ($i !== FALSE) {
373 | $startIndex = $i + 1;
374 | }
375 | }
376 |
377 | $isEnd = $startIndex + $maxFiles >= count($fileNames); // are there any files after current page?
378 |
379 | // $fileNames = array_slice($fileNames, $startIndex, $maxFiles);
380 | // Do the same, but respecting "alwaysInclude":
381 | if ($startIndex > 0 || $maxFiles < count($fileNames)) {
382 | for ($i=count($alwaysInclude)-1; $i>=0; $i--) {
383 | $index = array_search($alwaysInclude[$i], $fileNames);
384 | if ($index === FALSE) {
385 | // Remove unexisting items from "alwaysInclude"
386 | array_splice($alwaysInclude, $i, 1);
387 | } else {
388 | // And existing items from "fileNames"
389 | array_splice($fileNames, $index, 1);
390 | }
391 | }
392 | // Get a page
393 | $fileNames = array_slice($fileNames, $startIndex, $maxFiles);
394 | // Add to the start of the page all "alwaysInclude" files
395 | for ($i=count($alwaysInclude)-1; $i>=0; $i--)
396 | array_unshift($fileNames, $alwaysInclude[$i]);
397 | }
398 |
399 | $profile->profile("Page slice finished");
400 |
401 | $resultFiles = [];
402 |
403 | // Create result file list for output,
404 | // attach image attributes and image formats for image files.
405 | foreach ($fileNames as $fileName) {
406 |
407 | $resultFile = $this->getFileStructure($dirPath, $fileName);
408 |
409 | // Find formats of these files
410 | foreach ($formatIds as $formatId) {
411 | if (array_key_exists($fileName, $formatFiles[$formatId])) {
412 | $formatFileName = $formatFiles[$formatId][$fileName];
413 |
414 | $formatFile = $this->getFileStructure($dirPath, $formatFileName);
415 | $resultFile['formats'][$formatId] = $formatFile;
416 | }
417 | }
418 |
419 | $resultFiles[] = $resultFile;
420 | }
421 |
422 | $profile->profile("Create output list finished");
423 | $profile->total();
424 |
425 | return [
426 | 'files' => $resultFiles,
427 | 'countTotal' => $countTotal,
428 | 'countFiltered' => $countFiltered,
429 | 'isEnd' => $isEnd,
430 | ];
431 | }
432 |
433 | public function getFileStructure($dirPath, $fileName) {
434 | $cachedImageInfo = $this->getCachedImageInfo($dirPath . '/' . $fileName);
435 | $resultFile = [
436 | 'name' => "" . $fileName,
437 | 'size' => $cachedImageInfo['size'],
438 | 'timestamp' => $cachedImageInfo['mtime'],
439 | ];
440 |
441 | if (Utils::isImage($fileName)) {
442 |
443 | $resultFile['width'] = isset($cachedImageInfo['width']) ? $cachedImageInfo['width'] : NULL;
444 | $resultFile['height'] = isset($cachedImageInfo['height']) ? $cachedImageInfo['height'] : NULL;
445 | $resultFile['blurHash'] = isset($cachedImageInfo['blurHash']) ? $cachedImageInfo['blurHash'] : NULL;
446 |
447 | $resultFile['formats'] = [];
448 | }
449 |
450 | return $resultFile;
451 | }
452 |
453 | function reqGetImagePreview($request) {
454 | $filePath = isset($request->get['f']) ? $request->get['f'] : $request->post['f'];
455 | //$width = isset($request->get['width']) ? $request->get['width'] :
456 | // (isset($request->post['width']) ? $request->post['width'] : NULL);
457 | //$height = isset($request->get['height']) ? $request->get['height'] :
458 | // (isset($request->post['height']) ? $request->post['height'] : NULL);
459 |
460 | $filePath = $this->getRelativePath($filePath);
461 | $result = $this->getCachedImagePreview($filePath, NULL);
462 |
463 | // Convert path to contents
464 | $result[1] = ($result[2] === FALSE ? $this->driverFiles : $this->driverCache)->readStream($result[1]);
465 | return $result;
466 | }
467 |
468 | function reqGetImagePreviewAndResolution($request) {
469 |
470 | $filePath = isset($request->get['f']) ? $request->get['f'] : $request->post['f'];
471 | $width = isset($request->get['width']) ? $request->get['width'] :
472 | (isset($request->post['width']) ? $request->post['width'] : NULL);
473 | $height = isset($request->get['height']) ? $request->get['height'] :
474 | (isset($request->post['height']) ? $request->post['height'] : NULL);
475 |
476 | $filePath = $this->getRelativePath($filePath);
477 | $previewAndResolution = $this->getCachedImagePreviewAndResolution($filePath, NULL);
478 |
479 | $result = [
480 | 'width' => $previewAndResolution[1],
481 | 'height' => $previewAndResolution[2],
482 | 'preview' => $previewAndResolution[0] != NULL ? ("data:" . $previewAndResolution[0][0] . ";base64," . base64_encode(($previewAndResolution[0][2] === FALSE ? $this->driverFiles : $this->driverCache)->get($previewAndResolution[0][1]))) : NULL,
483 | ];
484 |
485 | return $result;
486 | }
487 |
488 | function reqCopyDir($request) {
489 | $dirPath = $request->post['d']; // full path
490 | $newPath = $request->post['n']; // full path
491 |
492 | $dirPath = $this->getRelativePath($dirPath);
493 | $newPath = $this->getRelativePath($newPath);
494 |
495 | $this->driverFiles->copyDirectory($dirPath, $newPath);
496 | }
497 |
498 | function reqCopyFiles($request) {
499 | $files = $request->post['fs'];
500 | $newPath = $request->post['n'];
501 |
502 | $filesPaths = preg_split('/\|/', $files);
503 | for ($i = 0; $i < count($filesPaths); $i++) {
504 | $filesPaths[$i] = $this->getRelativePath($filesPaths[$i]);
505 | }
506 | $newPath = $this->getRelativePath($newPath);
507 |
508 | for ($i = 0; $i < count($filesPaths); $i++) {
509 | $this->driverFiles->copyFile($filesPaths[$i], rtrim($newPath, '\\/') . '/' . basename($filesPaths[$i]));
510 | }
511 | }
512 |
513 | function getCachedFile($filePath) {
514 | return new CachedFile(
515 | $filePath,
516 | $this->driverFiles,
517 | $this->driverCache
518 | );
519 | }
520 |
521 | private $PREVIEW_WIDTH = 159;
522 |
523 | private $PREVIEW_HEIGHT = 139;
524 |
525 | function getCachedImageInfo($filePath) {
526 | $profile = new Profile("getCachedImageInfo()");
527 | $result = $this->getCachedFile($filePath)->getInfo();
528 | $profile->total();
529 | return $result;
530 | }
531 |
532 | function getCachedImagePreview($filePath, $contents) {
533 | $profile = new Profile("getCachedImagePreview()");
534 | $result = $this->getCachedFile($filePath)
535 | ->getPreview($this->PREVIEW_WIDTH, $this->PREVIEW_HEIGHT, $contents);
536 | $profile->total();
537 | return $result;
538 | }
539 |
540 | function getCachedImagePreviewAndResolution($filePath, $contents) {
541 |
542 | $profile = new Profile("getCachedImagePreviewAndResolution()");
543 |
544 | $cachedFile = $this->getCachedFile($filePath);
545 |
546 | $preview = $cachedFile->getPreview($this->PREVIEW_WIDTH, $this->PREVIEW_HEIGHT, $contents);
547 | $info = $cachedFile->getInfo();
548 |
549 | $result = [
550 | $preview,
551 | isset($info['width']) ? $info['width'] : NULL,
552 | isset($info['height']) ? $info['height'] : NULL,
553 | ];
554 | $profile->total();
555 | return $result;
556 | }
557 |
558 | function reqCreateDir($request) {
559 | $dirPath = $request->post['d'];
560 | $name = $request->post['n'];
561 |
562 | $dirPath = $this->getRelativePath($dirPath);
563 |
564 | if ($name === "") {
565 | throw new MessageException(
566 | Message::createMessage(
567 | FALSE,
568 | Message::MALFORMED_REQUEST
569 | )
570 | );
571 | }
572 |
573 | if (strpos($name, '/') !== FALSE) {
574 | throw new MessageException(
575 | Message::createMessage(
576 | FALSE,
577 | Message::FM_DIR_NAME_CONTAINS_INVALID_SYMBOLS
578 | )
579 | );
580 | }
581 | $this->driverFiles->makeDirectory($dirPath . '/' . $name);
582 | }
583 |
584 | function reqDeleteDir($request) {
585 | $dirPath = $request->post['d'];
586 |
587 | $dirPath = $this->getRelativePath($dirPath);
588 |
589 | $this->driverFiles->delete($dirPath);
590 | }
591 |
592 | function reqMove($request) {
593 | $path = $request->post['d'];
594 | $newPath = $request->post['n']; // path without name
595 |
596 | $path = $this->getRelativePath($path);
597 | $newPath = $this->getRelativePath($newPath);
598 |
599 | $this->driverFiles->move($path, $newPath . '/' . basename($path));
600 | }
601 |
602 | function reqRename($request) {
603 | $path = isset($request->post['d']) ? $request->post['d'] : $request->post['f'];
604 | $newName = $request->post['n']; // name without path
605 |
606 | if (strpos($newName, '/') !== FALSE) {
607 | throw new MessageException(
608 | Message::createMessage(
609 | FALSE,
610 | Message::FM_DIR_NAME_CONTAINS_INVALID_SYMBOLS
611 | )
612 | );
613 | }
614 |
615 | $path = $this->getRelativePath($path);
616 |
617 | $this->driverFiles->move($path, rtrim(dirname($path), '\\/') . '/' . $newName);
618 | }
619 |
620 | function reqMoveFiles($request) {
621 | $filesPaths = preg_split('/\|/', $request->post['fs']); // array of file paths
622 | $newPath = $request->post['n']; // dir without filename
623 |
624 | for ($i = 0; $i < count($filesPaths); $i++) {
625 | $filesPaths[$i] = $this->getRelativePath($filesPaths[$i]);
626 | }
627 | $newPath = $this->getRelativePath($newPath);
628 |
629 | for ($i = 0; $i < count($filesPaths); $i++) {
630 | $filePath = $filesPaths[$i];
631 | $index = strrpos($filePath, '/');
632 | $name = $index === FALSE ? $filePath : substr($filePath, $index + 1);
633 | $this->driverFiles->move($filePath, $newPath . '/' . $name);
634 | }
635 | }
636 |
637 | protected function deleteFormatsAndClearCachePreviewForFile($filePath, $formatSuffixes) {
638 | $fullPaths = [];
639 |
640 | $index = strrpos($filePath, '.');
641 | if ($index !== FALSE) {
642 | $fullPathPrefix = substr($filePath, 0, $index);
643 | } else {
644 | $fullPathPrefix = $filePath;
645 | }
646 | if (isset($formatSuffixes) && is_array($formatSuffixes)) {
647 | for ($j = 0; $j < count($formatSuffixes); $j++) {
648 | $exts = ["png", "jpg", "jpeg", "webp"];
649 | for ($k = 0; $k < count($exts); $k++) {
650 | $fullPaths[] = $fullPathPrefix . $formatSuffixes[$j] . '.' . $exts[$k];
651 | }
652 | }
653 | }
654 |
655 | $cachedFile = $this->getCachedFile($filePath);
656 | $cachedFile->delete();
657 |
658 | for ($j = 0; $j < count($fullPaths); $j++) {
659 | if ($this->driverFiles->fileExists($fullPaths[$j])) {
660 | $this->driverFiles->delete($fullPaths[$j]);
661 | }
662 | }
663 | }
664 |
665 | protected function updateFormatsAndClearCachePreviewForFile($filePath, $formatSuffixes, $formatMaxWidths, $formatMaxHeights) {
666 |
667 | $fileNameWithoutExt = $filePath;
668 | $indexSlash = strrpos($fileNameWithoutExt, '/');
669 | if ($indexSlash !== FALSE)
670 | $fileNameWithoutExt = substr($fileNameWithoutExt, $indexSlash + 1);
671 | $indexDot = strrpos($fileNameWithoutExt, '.');
672 | if ($indexDot !== FALSE)
673 | $fileNameWithoutExt = substr($fileNameWithoutExt, 0, $indexDot);
674 |
675 | for ($j = 0; $j < count($formatSuffixes); $j++) {
676 | try {
677 | $this->resizeFile2Impl(
678 | $filePath,
679 | $fileNameWithoutExt . $formatSuffixes[$j],
680 | $formatMaxWidths[$j],
681 | $formatMaxHeights[$j],
682 | 'IF_EXISTS'
683 | );
684 | } catch (Exception $e) {
685 | // Supressing FM_NOT_ERROR_NOT_NEEDED_TO_UPDATE not-a-error
686 | //error_log(print_r($e, TRUE));
687 | }
688 | }
689 | $cachedFile = $this->getCachedFile($filePath);
690 | $cachedFile->delete();
691 | }
692 |
693 | // "suffixes" is an optional parameter (does not supported by Flmngr UI v1)
694 | function reqDeleteFiles($request) {
695 | $filesPaths = preg_split('/\|/', $request->post['fs']);
696 | $formatSuffixes = $request->post['formatSuffixes'];
697 |
698 | for ($i = 0; $i < count($filesPaths); $i++) {
699 | $filesPaths[$i] = $this->getRelativePath($filesPaths[$i]);
700 | $this->driverFiles->delete($filesPaths[$i]);
701 | }
702 |
703 | foreach ($filesPaths as $filePath) {
704 | $this->deleteFormatsAndClearCachePreviewForFile($filePath, $formatSuffixes);
705 | }
706 | }
707 |
708 | // $files are like: "file.jpg" or "dir/file.png" - they start not with "/root_dir/"
709 | // This is because we need to validate files before dir tree is loaded on a client
710 | public function reqGetFilesSpecified($request) {
711 | $files = $request->post['files'];
712 |
713 | $result = [];
714 | for ($i = 0; $i < count($files); $i++) {
715 |
716 | $file = '/' . $files[$i];
717 |
718 | if (strpos($file, '..') !== FALSE) {
719 | throw new MessageException(
720 | Message::createMessage(
721 | FALSE,
722 | Message::FM_DIR_NAME_CONTAINS_INVALID_SYMBOLS
723 | )
724 | );
725 | }
726 |
727 | if ($this->driverFiles->fileExists($file)) {
728 |
729 | $result[] = [
730 | "dir" => dirname($file),
731 | "file" => $this->getFileStructure(dirname($file), basename($file)),
732 | ];
733 | }
734 |
735 | }
736 | return $result;
737 | }
738 |
739 | // Legacy request used in V1 client only
740 | function reqResizeFile($request) {
741 | return $this->reqResizeFile2($request)["url"];
742 | }
743 |
744 | // mode:
745 | // "ALWAYS"
746 | // To recreate image preview in any case (even it is already generated before)
747 | // Used when user uploads a new image and needs to get its preview
748 |
749 | // "DO_NOT_UPDATE"
750 | // To create image only if it does not exist, if exists - its path will be returned
751 | // Used when user selects existing image in file manager and needs its preview
752 |
753 | // "IF_EXISTS"
754 | // To recreate preview if it already exists
755 | // Used when file was reuploaded, edited and we recreate previews for all formats we do not need right now, but used somewhere else
756 |
757 | // File uploaded / saved in image editor and reuploaded: $mode is "ALWAYS" for required formats, "IF_EXISTS" for the others
758 | // User selected image in file manager: $mode is "DO_NOT_UPDATE" for required formats and there is no requests for the otheres
759 | function reqResizeFile2($request) {
760 | // $filePath here starts with "/", not with "/root_dir" as usual
761 | // so there will be no getRelativePath call
762 | $filePath = $request->post['f'];
763 | $newFileNameWithoutExt = $request->post['n'];
764 | $width = $request->post['mw'];
765 | $height = $request->post['mh'];
766 | $mode = $request->post['mode'];
767 |
768 | if (strpos($filePath, '..') !== FALSE) {
769 | throw new MessageException(
770 | Message::createMessage(
771 | FALSE,
772 | Message::FM_DIR_NAME_CONTAINS_INVALID_SYMBOLS
773 | )
774 | );
775 | }
776 |
777 | return $this->resizeFile2Impl(
778 | $filePath,
779 | $newFileNameWithoutExt,
780 | $width,
781 | $height,
782 | $mode
783 | );
784 | }
785 |
786 | function resizeFile2Impl(
787 | $filePath,
788 | $newFileNameWithoutExt,
789 | $width,
790 | $height,
791 | $mode
792 | ) {
793 |
794 | if (
795 | strpos($newFileNameWithoutExt, '..') !== FALSE ||
796 | strpos($newFileNameWithoutExt, '/') !== FALSE ||
797 | strpos($newFileNameWithoutExt, '\\') !== FALSE
798 | ) {
799 | throw new MessageException(
800 | Message::createMessage(
801 | FALSE,
802 | Message::FM_DIR_NAME_CONTAINS_INVALID_SYMBOLS
803 | )
804 | );
805 | }
806 |
807 | $index = strrpos($filePath, '/');
808 | $oldFileNameWithExt = substr($filePath, $index + 1);
809 | $newExt = 'png';
810 | $oldExt = strtolower(Utils::getExt($filePath));
811 | if ($oldExt === "svg") {
812 | return [
813 | "url" => $filePath,
814 | "width" => -1,
815 | "height" => -1
816 | ];
817 | }
818 | if ($oldExt === 'jpg' || $oldExt === 'jpeg') {
819 | $newExt = 'jpg';
820 | }
821 | if ($oldExt === 'webp') {
822 | $newExt = 'webp';
823 | }
824 | $dstPath =
825 | substr($filePath, 0, $index) .
826 | '/' .
827 | $newFileNameWithoutExt .
828 | '.' .
829 | $newExt;
830 |
831 | if (
832 | Utils::getNameWithoutExt($dstPath) ===
833 | Utils::getNameWithoutExt($filePath)
834 | ) {
835 | // This is `default` format request - we need to process the image itself without changing its extension
836 | $dstPath = $filePath;
837 | }
838 |
839 | $isDstPathExists = $this->driverFiles->fileExists($dstPath);
840 | if ($mode === 'IF_EXISTS' && !$isDstPathExists) {
841 | throw new MessageException(
842 | Message::createMessage(
843 | FALSE,
844 | Message::FM_NOT_ERROR_NOT_NEEDED_TO_UPDATE
845 | )
846 | );
847 | }
848 |
849 | if ($mode === 'DO_NOT_UPDATE' && $isDstPathExists) {
850 |
851 | // TODO: a preview is not needed, only a resolution
852 | $info = $this->getCachedImagePreviewAndResolution(
853 | $dstPath,
854 | $this->driverFiles->get($dstPath)
855 | );
856 | return [
857 | "url" => $dstPath,
858 | "width" => $info[1],
859 | "height" => $info[2]
860 | ];
861 | }
862 |
863 | $contents = $this->driverFiles->get($filePath);
864 | $image = imagecreatefromstring($contents);
865 |
866 | if (!$image) {
867 | throw new MessageException(
868 | FALSE,
869 | Message::createMessage(
870 | FALSE,
871 | Message::IMAGE_PROCESS_ERROR
872 | )
873 | );
874 | }
875 | imagesavealpha($image, TRUE);
876 |
877 | $orientation = $this->driverFiles->getExifOrientation($filePath);
878 | if ($orientation === 3) {
879 | $image = imagerotate($image, 180, 0);
880 | } else if ($orientation === 6) {
881 | $image = imagerotate($image, -90, 0);
882 | } else if ($orientation === 8) {
883 | $image = imagerotate($image, 90, 0);
884 | }
885 |
886 | $this->getCachedImagePreview($filePath, $contents); // to force writing image/width into cache file
887 | $imageInfo = $this->getCachedImageInfo($filePath);
888 |
889 | $originalWidth = $imageInfo['width'];
890 | $originalHeight = $imageInfo['height'];
891 |
892 | $needToFitWidth = $originalWidth > $width && $width > 0;
893 | $needToFitHeight = $originalHeight > $height && $height > 0;
894 | if ($needToFitWidth && $needToFitHeight) {
895 | if ($width / $originalWidth < $height / $originalHeight) {
896 | $needToFitHeight = FALSE;
897 | }
898 | else {
899 | $needToFitWidth = FALSE;
900 | }
901 | }
902 |
903 | if (!$needToFitWidth && !$needToFitHeight) {
904 | // if we generated the preview in past, we need to update it in any case
905 | if (
906 | !$isDstPathExists ||
907 | $newFileNameWithoutExt . '.' . $oldExt === $oldFileNameWithExt
908 | ) {
909 | // return old file due to it has correct width/height to be used as a preview
910 |
911 | // TODO: a preview is not needed, only a resolution
912 | $info = $this->getCachedImagePreviewAndResolution(
913 | $filePath,
914 | $this->driverFiles->get($filePath)
915 | );
916 | return [
917 | "url" => $filePath,
918 | "width" => $info[1],
919 | "height" => $info[2]
920 | ];
921 | }
922 | else {
923 | $width = $originalWidth;
924 | $height = $originalHeight;
925 | }
926 | }
927 |
928 | if ($needToFitWidth) {
929 | $ratio = $width / $originalWidth;
930 | $height = max(1, floor($originalHeight * $ratio));
931 | }
932 | elseif ($needToFitHeight) {
933 | $ratio = $height / $originalHeight;
934 | $width = max(1, floor($originalWidth * $ratio));
935 | }
936 |
937 | $resizedImage = imagecreatetruecolor($width, $height);
938 | imagealphablending($resizedImage, FALSE);
939 | imagesavealpha($resizedImage, TRUE);
940 |
941 | imagecopyresampled(
942 | $resizedImage,
943 | $image,
944 | 0,
945 | 0,
946 | 0,
947 | 0,
948 | $width,
949 | $height,
950 | $originalWidth,
951 | $originalHeight
952 | );
953 |
954 | $ext = strtolower(Utils::getExt($dstPath));
955 | ob_start();
956 | if ($ext === 'png') {
957 | imagepng($resizedImage);
958 | }
959 | elseif ($ext === 'jpg' || $ext === 'jpeg') {
960 | imagejpeg($resizedImage);
961 | }
962 | elseif ($ext === 'bmp') {
963 | imagebmp($resizedImage);
964 | }
965 | elseif ($ext === 'webp') {
966 | imagewebp($resizedImage);
967 | } // do not resize other formats (i. e. GIF)
968 |
969 | $stringData = ob_get_contents(); // read from buffer
970 | ob_end_clean(); // delete buffer
971 | $this->driverFiles->put($dstPath, $stringData);
972 |
973 | return [
974 | "url" => $dstPath,
975 | "width" => intval($width),
976 | "height" => intval($height)
977 | ];
978 | }
979 |
980 | function reqGetImageOriginal($request) {
981 | $filePath = isset($request->get['f']) ? $request->get['f'] : $request->post['f'];
982 |
983 | $filePath = $this->getRelativePath($filePath);
984 |
985 | $mimeType = Utils::getMimeType($filePath);
986 | if ($mimeType == NULL) {
987 | throw new MessageException(
988 | Message::createMessage(
989 | FALSE,
990 | Message::FM_FILE_IS_NOT_IMAGE
991 | )
992 | );
993 | }
994 |
995 | $stream = $this->driverFiles->readStream($filePath);
996 |
997 | return [$mimeType, $stream];
998 | }
999 |
1000 | function reqGetVersion($request) {
1001 | return [
1002 | 'version' => '6',
1003 | 'build' => '14',
1004 | 'language' => 'php',
1005 | 'storage' => $this->driverFiles->getDriverName(),
1006 | 'dirFiles' => $this->driverFiles->getDir(),
1007 | 'dirCache' => $this->driverCache->getDir(),
1008 | ];
1009 | }
1010 |
1011 | public function reqUpload($request) {
1012 |
1013 | $dir = isset($request->post['dir']) ? $request->post['dir'] : '/';
1014 | $dir = $this->getRelativePath('/' . $this->driverFiles->getRootDirName() . $dir);
1015 |
1016 | $isOverwrite = isset($request->post['mode']) && $request->post['mode'] === "OVERWRITE";
1017 |
1018 | if (!isset($request->files['file'])) {
1019 | throw new MessageException(
1020 | Message::createMessage(
1021 | FALSE,
1022 | Message::FILES_NOT_SET
1023 | )
1024 | );
1025 | }
1026 | $file = $request->files['file'];
1027 |
1028 | $name = $this->driverFiles->uploadFile($file, $dir, $isOverwrite);
1029 |
1030 | if ($isOverwrite) {
1031 | $formatSuffixes = $request->post['formatSuffixes'];
1032 |
1033 | if (isset($request->post['formatMaxWidths']) && isset($request->post['formatMaxHeights'])) {
1034 | // New corrected behavior since version 6, build 13
1035 | $formatMaxWidths = $request->post['formatMaxWidths'];
1036 | $formatMaxHeights = $request->post['formatMaxHeights'];
1037 | $this->updateFormatsAndClearCachePreviewForFile($dir . '/' . $name, $formatSuffixes, $formatMaxWidths, $formatMaxHeights);
1038 | } else {
1039 | // Old behavior till version 6, build 12
1040 | $this->deleteFormatsAndClearCachePreviewForFile($dir . '/' . $name, $formatSuffixes);
1041 | }
1042 |
1043 | }
1044 |
1045 | $resultFile = $this->getFileStructure($dir, $name);
1046 |
1047 | return [
1048 | 'file' => $resultFile,
1049 | ];
1050 | }
1051 |
1052 | }
1053 |
--------------------------------------------------------------------------------
/src/lib/CommonRequest.php:
--------------------------------------------------------------------------------
1 | requestMethod = $_SERVER['REQUEST_METHOD'];
29 | $this->files = $_FILES;
30 | $this->post = $_POST;
31 | $this->get = $_GET;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/src/lib/IFmRequest.php:
--------------------------------------------------------------------------------
1 | config = $config;
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/lib/JsonCodec.php:
--------------------------------------------------------------------------------
1 | m_actions = $actions;
31 | }
32 |
33 | public function fromJson($json) {
34 | $json = stripslashes($json);
35 | $jsonObj = json_decode($json, FALSE);
36 | if ($jsonObj === NULL) {
37 | throw new Exception('Unable to parse JSON');
38 | }
39 | if (!isset($jsonObj->action)) {
40 | throw new Exception('"Unable to detect action in JSON"');
41 | }
42 | $action = $this->m_actions->getAction($jsonObj->action);
43 | if ($action === NULL) {
44 | throw new Exception('JSON action is incorrect: ' . $action);
45 | }
46 | return $jsonObj;
47 | }
48 |
49 | public function toJson($resp) {
50 | return JsonCodec::s_toJson($resp);
51 | }
52 |
53 | public static function s_toJson($resp) {
54 | $json = json_encode($resp);
55 | $json = str_replace('\\u0000*\\u0000', '', $json);
56 | $json = str_replace('\\u0000', '', $json);
57 | return $json;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/lib/MessageException.php:
--------------------------------------------------------------------------------
1 | message = (array) $message;
33 | $this->sourceException = $sourceException;
34 | if ($sourceException == NULL) {
35 | try {
36 | throw new Exception("(manually created exception)");
37 | } catch (Exception $e) {
38 | $this->sourceException = $e;
39 | }
40 | }
41 | }
42 |
43 | public function getFailMessage() {
44 | return $this->message;
45 | }
46 |
47 | public function getSourceException() {
48 | return $this->sourceException;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/src/lib/Profile.php:
--------------------------------------------------------------------------------
1 | title = $functionTitle;
31 | $this->now = microtime(TRUE);
32 | $this->start = $this->now;
33 | }
34 |
35 | public function profile($text) {
36 | $now = microtime(TRUE);
37 | $time = $now - $this->now;
38 | //error_log($this->title . ": " . number_format($time, 3, ",", "") . " sec " . $text . "\n");
39 | $this->now = $now;
40 | }
41 |
42 | public function total() {
43 | $now = microtime(TRUE);
44 | $time = $now - $this->start;
45 | //error_log($this->title . ": " . number_format($time, 3, ",", "") . " sec TOTAL\n");
46 | }
47 |
48 | }
--------------------------------------------------------------------------------
/src/lib/file/Utils.php:
--------------------------------------------------------------------------------
1 | ";
46 |
47 | public static function fixFileName($name) {
48 | $newName = '';
49 | for ($i = 0; $i < strlen($name); $i++) {
50 | $ch = substr($name, $i, 1);
51 | if (strpos(Utils::PROHIBITED_SYMBOLS, $ch) !== FALSE) {
52 | $ch = '_';
53 | }
54 | $newName = $newName . $ch;
55 | }
56 | return $newName;
57 | }
58 |
59 | public static function isFileNameSyntaxOk($name) {
60 | if (strlen($name) == 0 || $name == '.' || strpos($name, '..') > -1) {
61 | return FALSE;
62 | }
63 |
64 | for ($i = 0; $i < strlen(Utils::PROHIBITED_SYMBOLS); $i++) {
65 | if (
66 | strpos($name, substr(Utils::PROHIBITED_SYMBOLS, $i, 1)) !==
67 | FALSE
68 | ) {
69 | return FALSE;
70 | }
71 | }
72 |
73 | if (strlen($name) > 260) {
74 | return FALSE;
75 | }
76 |
77 | /*
78 | * TODO: fix this and uncomment
79 | * On Windows + IIS + PHP produces:
80 | * Warning: preg_match(): Unknown modifier '\' in ...\vendor\edsdk\file-uploader-server-php\src\lib\file\Utils.php on line 83
81 | *
82 | * if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
83 | // https://stackoverflow.com/questions/6730009/validate-a-file-name-on-windows
84 | // https://msdn.microsoft.com/en-us/library/aa365247(v=vs.85).aspx#file_and_directory_names
85 | $pattern =
86 | "/" .
87 | "^" .
88 | "(?!" .
89 | " (?:" .
90 | " CON|PRN|AUX|NUL|" .
91 | " COM[1-9]|LPT[1-9]" .
92 | " )" .
93 | " (?:\\.[^.]*)?" .
94 | " $" .
95 | ")" .
96 | "[^<>:\"/\\\\|?*\\x00-\\x1F]*" .
97 | "[^<>:\"/\\\\|?*\\x00-\\x1F\\ .]" .
98 | "$/ui";
99 | if (!preg_match($pattern, $name))
100 | return false;
101 | }*/
102 |
103 | return TRUE;
104 | }
105 |
106 | public static function isImage($name) {
107 | $exts = ['gif', 'jpg', 'jpeg', 'png', 'svg', 'webp', 'bmp'];
108 | $ext = Utils::getExt($name);
109 | for ($i = 0; $i < count($exts); $i++) {
110 | if ($ext !== NULL && $exts[$i] === strtolower($ext)) {
111 | return TRUE;
112 | }
113 | }
114 | return FALSE;
115 | }
116 |
117 | public static function addTrailingSlash($value) {
118 | if (
119 | $value != NULL &&
120 | (strlen($value) == 0 || !substr($value, strlen($value) - 1) == '/')
121 | ) {
122 | $value .= '/';
123 | }
124 | return $value;
125 | }
126 |
127 | public static function removeTrailingSlash($value) {
128 | if (
129 | $value != NULL &&
130 | (strlen($value) > 0 && substr($value, strlen($value) - 1) == '/')
131 | ) {
132 | $value = substr(0, strlen($value) - 1);
133 | }
134 | return $value;
135 | }
136 |
137 | public static function getMimeType($filePath) {
138 | $mimeType = NULL;
139 | $filePath = strtolower($filePath);
140 | if (Utils::endsWith($filePath, '.png')) {
141 | $mimeType = 'image/png';
142 | }
143 | if (Utils::endsWith($filePath, '.gif')) {
144 | $mimeType = 'image/gif';
145 | }
146 | if (Utils::endsWith($filePath, '.bmp')) {
147 | $mimeType = 'image/bmp';
148 | }
149 | if (
150 | Utils::endsWith($filePath, '.jpg') ||
151 | Utils::endsWith($filePath, '.jpeg')
152 | ) {
153 | $mimeType = 'image/jpeg';
154 | }
155 | if (Utils::endsWith($filePath, '.webp')) {
156 | $mimeType = 'image/webp';
157 | }
158 | if (Utils::endsWith($filePath, '.svg')) {
159 | $mimeType = 'image/svg+xml';
160 | }
161 |
162 | return $mimeType;
163 | }
164 |
165 | public static function endsWith($str, $ends) {
166 | return substr($str, -strlen($ends)) === $ends;
167 | }
168 |
169 | public static function normalizeNoEndSeparator($path) {
170 | // TODO: normalize
171 | return rtrim($path, '/');
172 | }
173 |
174 | public static function writeImageContents($ext, $image, $jpegQuality) {
175 | ob_start();
176 | switch (strtolower($ext)) {
177 | case 'gif':
178 | imagegif($image);
179 | break;
180 | case 'jpeg':
181 | case 'jpg':
182 | imagejpeg(
183 | $image,
184 | NULL,
185 | $jpegQuality
186 | );
187 | break;
188 | case 'png':
189 | imagepng($image);
190 | break;
191 | case 'bmp':
192 | imagewbmp($image);
193 | break;
194 | }
195 | $contents = ob_get_clean();
196 | return $contents;
197 | }
198 |
199 | public static function getImageInfo($file) {
200 | $size = @getimagesize($file);
201 | if ($size === FALSE) {
202 | //error_log("Unable to read image info of " . $file);
203 | throw new MessageException(
204 | Message::createMessage(
205 | FALSE,
206 | Message::IMAGE_PROCESS_ERROR
207 | )
208 | );
209 | }
210 |
211 | $imageInfo = new ImageInfo();
212 | $imageInfo->width = $size[0];
213 | $imageInfo->height = $size[1];
214 | return $imageInfo;
215 | }
216 |
217 | }
218 |
--------------------------------------------------------------------------------
/src/lib/file/blurHash/AC.php:
--------------------------------------------------------------------------------
1 | 0 ? 1 : ($base < 0 ? -1 : 0);
32 | return $sign * pow(abs($base), $exp);
33 | }
34 | }
--------------------------------------------------------------------------------
/src/lib/file/blurHash/Base83.php:
--------------------------------------------------------------------------------
1 | 9) || ($components_y < 1 || $components_y > 9)) {
11 | throw new InvalidArgumentException("x and y component counts must be between 1 and 9 inclusive.");
12 | }
13 | $height = count($image);
14 | $width = count($image[0]);
15 |
16 | $image_linear = $image;
17 | if (!$linear) {
18 | $image_linear = [];
19 | for ($y = 0; $y < $height; $y++) {
20 | $line = [];
21 | for ($x = 0; $x < $width; $x++) {
22 | $pixel = $image[$y][$x];
23 | $line[] = [
24 | Color::toLinear($pixel[0]),
25 | Color::toLinear($pixel[1]),
26 | Color::toLinear($pixel[2]),
27 | ];
28 | }
29 | $image_linear[] = $line;
30 | }
31 | }
32 |
33 | $components = [];
34 | $scale = 1 / ($width * $height);
35 | for ($y = 0; $y < $components_y; $y++) {
36 | for ($x = 0; $x < $components_x; $x++) {
37 | $normalisation = $x == 0 && $y == 0 ? 1 : 2;
38 | $r = $g = $b = 0;
39 | for ($i = 0; $i < $width; $i++) {
40 | for ($j = 0; $j < $height; $j++) {
41 | $color = $image_linear[$j][$i];
42 | $basis = $normalisation
43 | * cos(M_PI * $i * $x / $width)
44 | * cos(M_PI * $j * $y / $height);
45 |
46 | $r += $basis * $color[0];
47 | $g += $basis * $color[1];
48 | $b += $basis * $color[2];
49 | }
50 | }
51 |
52 | $components[] = [
53 | $r * $scale,
54 | $g * $scale,
55 | $b * $scale,
56 | ];
57 | }
58 | }
59 |
60 | $dc_value = DC::encode(array_shift($components) ?: []);
61 |
62 | $max_ac_component = 0;
63 | foreach ($components as $component) {
64 | $component[] = $max_ac_component;
65 | $max_ac_component = max($component);
66 | }
67 |
68 | $quant_max_ac_component = (int) max(0, min(82, floor($max_ac_component * 166 - 0.5)));
69 | $ac_component_norm_factor = ($quant_max_ac_component + 1) / 166;
70 |
71 | $ac_values = [];
72 | foreach ($components as $component) {
73 | $ac_values[] = AC::encode($component, $ac_component_norm_factor);
74 | }
75 |
76 | $blurhash = Base83::encode($components_x - 1 + ($components_y - 1) * 9, 1);
77 | $blurhash .= Base83::encode($quant_max_ac_component, 1);
78 | $blurhash .= Base83::encode($dc_value, 4);
79 | foreach ($ac_values as $ac_value) {
80 | $blurhash .= Base83::encode((int) $ac_value, 2);
81 | }
82 |
83 | return $blurhash;
84 | }
85 |
86 | public static function decode($blurhash, $width, $height, $punch = 1.0, $linear = FALSE) {
87 | if (empty($blurhash) || strlen($blurhash) < 6) {
88 | throw new InvalidArgumentException("Blurhash string must be at least 6 characters");
89 | }
90 |
91 | $size_info = Base83::decode($blurhash[0]);
92 | $size_y = floor($size_info / 9) + 1;
93 | $size_x = ($size_info % 9) + 1;
94 |
95 | $length = strlen($blurhash);
96 | $expected_length = (int) (4 + (2 * $size_y * $size_x));
97 | if ($length !== $expected_length) {
98 | throw new InvalidArgumentException("Blurhash length mismatch: length is {$length} but it should be {$expected_length}");
99 | }
100 |
101 | $colors = [DC::decode(Base83::decode(substr($blurhash, 2, 4)))];
102 |
103 | $quant_max_ac_component = Base83::decode($blurhash[1]);
104 | $max_value = ($quant_max_ac_component + 1) / 166;
105 | for ($i = 1; $i < $size_x * $size_y; $i++) {
106 | $value = Base83::decode(substr($blurhash, 4 + $i * 2, 2));
107 | $colors[$i] = AC::decode($value, $max_value * $punch);
108 | }
109 |
110 | $pixels = [];
111 | for ($y = 0; $y < $height; $y++) {
112 | $row = [];
113 | for ($x = 0; $x < $width; $x++) {
114 | $r = $g = $b = 0;
115 | for ($j = 0; $j < $size_y; $j++) {
116 | for ($i = 0; $i < $size_x; $i++) {
117 | $color = $colors[$i + $j * $size_x];
118 | $basis =
119 | cos((M_PI * $x * $i) / $width) *
120 | cos((M_PI * $y * $j) / $height);
121 |
122 | $r += $color[0] * $basis;
123 | $g += $color[1] * $basis;
124 | $b += $color[2] * $basis;
125 | }
126 | }
127 |
128 | $row[] = $linear ? [$r, $g, $b] : [
129 | Color::toSRGB($r),
130 | Color::toSRGB($g),
131 | Color::toSRGB($b),
132 | ];
133 | }
134 | $pixels[] = $row;
135 | }
136 |
137 | return $pixels;
138 | }
139 | }
--------------------------------------------------------------------------------
/src/lib/file/blurHash/Color.php:
--------------------------------------------------------------------------------
1 | > 16;
16 | $g = ($value >> 8) & 255;
17 | $b = $value & 255;
18 | return [
19 | Color::toLinear($r),
20 | Color::toLinear($g),
21 | Color::toLinear($b),
22 | ];
23 | }
24 | }
--------------------------------------------------------------------------------
/src/model/FMDir.php:
--------------------------------------------------------------------------------
1 | path = $path;
39 | $this->name = $name;
40 | $this->f = 0; // legacy
41 | $this->d = 0; // legacy
42 | $this->filled = $filled;
43 |
44 | $this->p =
45 | (strlen($this->path) > 0 ? '/' . $this->path : '') .
46 | '/' .
47 | $this->name;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/model/FMFile.php:
--------------------------------------------------------------------------------
1 | p = "/" . $path . "/" . $name;
37 | $this->s = $cachedImageInfo['size'];
38 | $this->t = $cachedImageInfo['mtime'];
39 | $this->w = $cachedImageInfo['width'] == 0 ? NULL : $cachedImageInfo['width'];
40 | $this->h = $cachedImageInfo['height'] == 0 ? NULL : $cachedImageInfo['height'];
41 | }
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/model/ImageInfo.php:
--------------------------------------------------------------------------------
1 | isCacheIssue = $isCacheIssue;
134 | }
135 |
136 | public static function createMessage(
137 | $isCacheException,
138 | $code,
139 | $arg1 = NULL,
140 | $arg2 = NULL,
141 | $arg3 = NULL
142 | ) {
143 | $msg = new Message($isCacheException);
144 | $msg->code = $code;
145 | if ($arg1 != NULL) {
146 | $msg->args = [];
147 | $msg->args[] = $arg1;
148 | if ($arg2 != NULL) {
149 | $msg->args[] = $arg2;
150 | if ($arg3 != NULL) {
151 | $msg->args[] = $arg3;
152 | }
153 | }
154 | }
155 | return $msg;
156 | }
157 |
158 | }
159 |
--------------------------------------------------------------------------------
/src/resp/Response.php:
--------------------------------------------------------------------------------
1 | error = $message;
31 | $this->data = $data;
32 | }
33 |
34 | }
35 |
--------------------------------------------------------------------------------