Compare commits

...

162 Commits

Author SHA1 Message Date
2fa83dcc94 Merge branch 'feature/select-word' into develop 2023-09-01 12:24:33 +03:00
c1af2ba5b4 nodejs: onRequestSelectDocument / setRequestedDocument 2023-09-01 12:24:25 +03:00
fa84f451c2 Merge pull request #432 from ONLYOFFICE/feature/ruby-matrix-formats
ruby: add support for formats
2023-09-01 11:58:34 +03:00
87e9da1212 Merge pull request #444 from ONLYOFFICE/refactor/php-linting
php: many changes to satisfy linter
2023-09-01 09:40:05 +03:00
22dbacaa63 ruby: replace the previous implementation of formats 2023-08-31 11:44:52 +04:00
d192d1e0e8 ruby: add tests for the format module 2023-08-31 11:44:52 +04:00
5b115f7dbc ruby: add format module 2023-08-31 11:44:52 +04:00
41a22934a0 ruby: add document-formats submodule 2023-08-31 11:44:51 +04:00
94f4e83d79 php: update lint action 2023-08-31 11:40:28 +04:00
8ed0c4771d php: many changes to satisfy linter
- Delete unused imports.
- Rename methods and variables from snake case to camel case.
- Shorten code lines.
2023-08-31 11:40:25 +04:00
0445184cbc php: add rules to lint variable names 2023-08-31 11:37:14 +04:00
e4750e7a61 php: set targets for the lint recipe 2023-08-31 11:37:14 +04:00
a78450453d Merge pull request #450 from ONLYOFFICE/feature/csharp-restore
Feature/csharp restore
2023-08-30 22:50:03 +03:00
ca139938e9 csharp: restore to changelog 2023-08-30 22:47:52 +03:00
8ae9dc6fff Merge remote-tracking branch 'remotes/origin/develop' into feature/csharp-restore 2023-08-30 22:47:14 +03:00
9c0121e69f Merge pull request #449 from ONLYOFFICE/feature/csharp-mvc-restore
Feature/csharp mvc restore
2023-08-30 22:46:25 +03:00
e11861b30f csharp-mvc: restore to changelog 2023-08-30 22:46:08 +03:00
21842b772d Merge remote-tracking branch 'remotes/origin/feature/select-cell' into develop 2023-08-30 22:19:14 +03:00
17a1485d52 nodejs: onRequestSelectSpreadsheet/setRequestedSpreadsheet 2023-08-30 22:18:51 +03:00
07c752ed81 nodejs: refactoring 2023-08-30 22:12:59 +03:00
8c704687a7 php: not used function (fd4dfea7d7) 2023-08-30 12:18:34 +03:00
b691eb5717 Merge pull request #436 from ONLYOFFICE/feature/python-matrix-formats
python: add support for formats
2023-08-30 11:24:44 +03:00
dc35b240d1 Merge pull request #448 from ONLYOFFICE/hotfix/restore-paths
fixed restore file paths
2023-08-29 16:45:29 +03:00
527e5053e6 nodejs: fixed restore file paths (Fix Bug 63842) 2023-08-29 16:44:41 +03:00
1839a5c26b nodejs: fix linter 2023-08-29 15:12:52 +03:00
ccb81a60e1 python: replace the previous implementation of formats 2023-08-25 10:06:09 +04:00
b73a70e6d0 python: add tests for the format module 2023-08-25 10:06:09 +04:00
89e64fe71e python: add format module 2023-08-25 10:06:06 +04:00
2ffc44f339 python: add document-formats submodule 2023-08-25 10:06:05 +04:00
4e515a66ef python: add tests for the memoize module 2023-08-25 10:05:59 +04:00
a758f9a6d8 python: add memoize module 2023-08-25 10:05:52 +04:00
0131724cab Merge pull request #445 from ONLYOFFICE/feature/python-msgspec
python: add msgspec
2023-08-24 18:26:33 +03:00
a178dbc612 python: 3rd party licenses 2023-08-24 18:25:48 +03:00
4064f73c89 nodejs: Fix Bug 63800 template image (9048082cb7) 2023-08-24 16:03:33 +03:00
561af8444c Merge remote-tracking branch 'remotes/origin/feature/auto-convert' into develop 2023-08-23 15:16:48 +03:00
091bf10374 nodejs: convert after uploading only tagged formats 2023-08-23 15:16:23 +03:00
63461b3eb6 csharp-mvc: fixed urls for version data 2023-08-23 13:45:58 +03:00
bd20af2096 csharp-mvc: added version restore 2023-08-23 13:03:23 +03:00
2611fae25c csharp-mvc: use ajax for display version history 2023-08-23 12:16:23 +03:00
c740e21e83 csharp: fixed urls for version data 2023-08-23 11:44:41 +03:00
8193d5b9f2 csharp: jwt to version data 2023-08-22 16:41:21 +03:00
1f109c2b88 csharp: added version restore 2023-08-22 16:20:52 +03:00
a676da0a61 python: add msgspec 2023-08-22 12:43:16 +04:00
5f0fcfebd2 csharp: use ajax for display version history 2023-08-21 21:31:06 +03:00
292640aa95 Merge pull request #441 from ONLYOFFICE/feature/php-matrix-formats
php: add support for formats
2023-08-18 14:28:24 +03:00
9aedba8be3 php: 3rd party licenses 2023-08-18 14:26:03 +03:00
c98e8d03d2 Merge pull request #431 from ONLYOFFICE/feature/ruby-internal-network
ruby: add support for internal network
2023-08-17 17:02:21 +03:00
5951870870 Merge pull request #434 from ONLYOFFICE/feature/python-internal-network
python: add support for internal network
2023-08-16 15:06:04 +03:00
9bc6964274 Merge pull request #443 from ONLYOFFICE/feature/php-internal-network
php: add support for internal network
2023-08-16 15:04:41 +03:00
2051f3028e Merge remote-tracking branch 'remotes/origin/release/v7.5.0' into develop 2023-08-16 13:40:15 +03:00
869f8e7ba7 Merge remote-tracking branch 'remotes/origin/feature/referenceData-open' into develop 2023-08-16 13:36:58 +03:00
815b5fb428 nodejs: onRequestOpen for referenceData source file 2023-08-16 13:20:19 +03:00
13a1a6ba2c Merge pull request #440 from ONLYOFFICE/feature/java-spring-templates
java-spring: move document-templates to the assets directory
2023-08-15 11:44:41 +03:00
a3b93fee99 java-spring: update paths to the new location of templates 2023-08-15 12:42:49 +04:00
36cca57dd8 java-spring: move document-templates to the assets directory 2023-08-15 12:42:48 +04:00
53f315c5ee php: add public and private document-server urls to the compose 2023-08-15 10:45:58 +04:00
7c0d8cd59d php: add support for the internal network for the track endpoint 2023-08-15 10:45:58 +04:00
3405af796c php: add tests for the proxy module 2023-08-15 10:45:58 +04:00
b4905eb94e php: add proxy module 2023-08-15 10:45:58 +04:00
5a3330beb2 php: add support for specifying public and private document-server urls 2023-08-15 10:45:58 +04:00
5d16a50f0f php: remove the final keyword for a few classes 2023-08-15 10:45:58 +04:00
d8b6b0bbb5 Merge pull request #433 from ONLYOFFICE/feature/ruby-templates
ruby: move document-templates to the assets directory
2023-08-14 16:43:31 +03:00
7b6c9b5683 ruby: update paths to the new location of templates 2023-08-14 17:36:24 +04:00
d4bed077e0 ruby: move document-templates to the assets directory 2023-08-14 17:36:24 +04:00
8aba537cea Merge pull request #442 from ONLYOFFICE/feature/php-docker
php: add support for containerization
2023-08-14 15:23:51 +03:00
9cc6612bb2 Merge branch 'feature/submit-form' into develop 2023-08-14 11:25:50 +03:00
4bae7d8bf5 nodejs: submitForm to chamgelog 2023-08-14 11:25:14 +03:00
59c9061306 nodejs: fix max length (a06aa8c8b3) 2023-08-14 11:16:23 +03:00
2fb011185a Revert "nodejs: hide submit button"
This reverts commit 94cb70c0db.

# Conflicts:
#	web/documentserver-example/nodejs/app.js
#	web/documentserver-example/nodejs/helpers/users.js
2023-08-14 11:07:23 +03:00
49a58e687d nodejs: 1.6.0 (50a4ddbd11) 2023-08-14 10:43:43 +03:00
42e1b0635a Merge pull request #427 from ONLYOFFICE/feature/java-restore-endpoint
java: add restore endpoint
2023-08-14 09:59:33 +03:00
e9d8b60c13 java: add restore endpoint 2023-08-11 20:39:59 +04:00
33119ca2ad php: replace the previous implementation of formats 2023-08-11 20:35:30 +04:00
913c1350c2 php: add tests for the format module 2023-08-11 20:35:25 +04:00
fa34f5a44e php: add format module 2023-08-11 20:35:19 +04:00
5784171806 php: add serializer 2023-08-11 20:27:56 +04:00
8829f969d3 php: add docker files 2023-08-11 20:25:42 +04:00
ab48645ba8 php: add the recipe to work with docker 2023-08-11 20:25:42 +04:00
5d0f1b62d0 Merge pull request #430 from ONLYOFFICE/feature/java-spring-restore-endpoint
java-spring: add restore endpoint
2023-08-11 17:23:24 +03:00
78747c1cae Merge pull request #438 from ONLYOFFICE/feature/java-templates
java: move document-templates to the assets directory
2023-08-08 15:07:10 +03:00
2955dc004f java: update paths to the new location of templates 2023-08-08 14:47:51 +04:00
85981abd00 java: move document-templates to the assets directory 2023-08-08 14:47:51 +04:00
7542c6ca6e Merge pull request #435 from ONLYOFFICE/feature/python-templates
python: move document-templates to the assets directory
2023-08-08 12:32:04 +03:00
ab0553d988 Merge remote-tracking branch 'remotes/origin/develop' into release/v7.5.0 2023-08-08 12:14:21 +03:00
57e498ebba Merge remote-tracking branch 'remotes/origin/feature/referenceData-key' into develop 2023-08-08 12:06:57 +03:00
ce1052139e nodejs: fix forcesave (Fix Bug 63570) (bf04979c31) 2023-08-08 11:52:29 +03:00
350ea4e678 Merge pull request #426 from ONLYOFFICE/feature/php-project-structure
php: normalize project structure
2023-08-04 22:43:29 +03:00
979391e413 Merge remote-tracking branch 'remotes/origin/feature/referenceData-key' into release/v7.5.0 2023-08-04 13:41:56 +03:00
2b454e23d5 php: simplify the test receipt 2023-08-03 17:14:48 +04:00
9ed5f19d6b php: update urls to the new favicon location 2023-08-03 17:14:48 +04:00
851b2e48c7 php: move favicon files to the images directory 2023-08-03 17:14:48 +04:00
be40222d1a php: rename project namespace 2023-08-03 17:14:48 +04:00
d701f1565b php: update autoload map 2023-08-03 17:14:48 +04:00
2f39fb3bc6 php: update urls to new other files location 2023-08-03 17:14:48 +04:00
626f051aab php: move other files to the source directory 2023-08-03 17:14:48 +04:00
acd4bf87e7 php: update urls to the new global files location 2023-08-03 17:14:48 +04:00
9a9e122eec php: move global files to the source directory 2023-08-03 17:14:48 +04:00
340eaa31f4 php: update urls to the new scripts location 2023-08-03 17:14:48 +04:00
6433f502ad php: move scripts to the assets directory 2023-08-03 17:14:48 +04:00
cbfbf77f0f php: update urls to the new styles location 2023-08-03 17:14:48 +04:00
173641a7af php: move styles to the assets directory 2023-08-03 17:14:48 +04:00
ce37d1de20 php: update urls to the new images location 2023-08-03 17:14:48 +04:00
ce80e89028 php: move images to the assets directory 2023-08-03 17:14:48 +04:00
63365e176e java-spring: add restore endpoint 2023-08-03 12:34:14 +04:00
32a60c09aa python: add public and private document-server urls to the compose 2023-08-02 10:49:34 +04:00
5a03024cd3 python: add support for the internal network for the track endpoint 2023-08-02 10:49:34 +04:00
cb6416c481 python: sort imports 2023-08-02 10:49:34 +04:00
55e4247687 python: add tests for proxy manager 2023-08-02 10:49:34 +04:00
a0620905b2 python: add proxy manager to resolve the document-server url 2023-08-02 10:49:34 +04:00
3fcef4096a python: remove the strict CORS hint 2023-08-02 10:49:34 +04:00
4e5349c1c4 python: add tests for specifying public and private document-server urls 2023-08-02 10:49:34 +04:00
538eec1ff3 python: add support for specifying public and private document-server urls 2023-08-02 10:49:34 +04:00
10e67c787c ruby: add public and private document-server urls to the compose 2023-08-02 10:17:14 +04:00
565a27d981 ruby: add support for the internal network for the track endpoint 2023-08-02 10:17:14 +04:00
7304c1e67a ruby: add tests for proxy manager 2023-08-02 10:17:14 +04:00
f9ba90d3ac ruby: add proxy manager to resolve the document-server url 2023-08-02 10:17:14 +04:00
d2f40c5395 ruby: add tests for specifying public and private document-server urls 2023-08-02 10:17:14 +04:00
ca0b7adcee ruby: add support for specifying public and private document-server urls 2023-08-02 10:17:14 +04:00
df7cfda2fb Merge pull request #429 from ONLYOFFICE/fix/java-spring-save-previous
java-spring: add a step to save the previous version of the file during processing save
2023-07-31 15:37:55 +03:00
9ebef04f3d Merge pull request #415 from ONLYOFFICE/feature/ruby-docker
ruby: add support for containerization
2023-07-31 15:36:46 +03:00
a6ed970bca Merge pull request #413 from ONLYOFFICE/feature/python-docker
python: add support for containerization
2023-07-31 15:36:06 +03:00
7f659bc95e Merge pull request #428 from ONLYOFFICE/fix/php-lint-action
php: update php lint action to latest changes
2023-07-31 09:46:00 +03:00
3c4a1c1c31 Merge pull request #425 from ONLYOFFICE/feature/php-server-configuration
php: simplify server configuration
2023-07-29 15:42:55 +03:00
2bae0567ad nodejs: fix for ie (496a150620) 2023-07-28 17:26:53 +03:00
419fbf90f9 python: update paths to the new location of templates 2023-07-27 17:10:50 +04:00
2d637b88df python: move document-templates to the assets directory 2023-07-27 17:10:50 +04:00
13e2d5b33c python: add recipes to work with docker 2023-07-27 16:12:43 +04:00
f208fe1939 python: add docker files 2023-07-27 16:12:43 +04:00
b3cc35cb5e python: add support for the ADDRESS env variable 2023-07-27 16:12:43 +04:00
8b316b0786 python: move the lint recipe to the bottom of file 2023-07-27 16:12:43 +04:00
c57fcbfd90 python: delete recipes sorting in the help recipe 2023-07-27 16:12:43 +04:00
1939b85c8c ruby: disable strict hosts policy 2023-07-27 11:26:40 +04:00
ee0ac33820 ruby: add recipes to work with docker 2023-07-27 11:26:40 +04:00
c93579d98f ruby: add docker files 2023-07-27 11:26:40 +04:00
61a9e122cd ruby: move the lint recipe to the bottom of file 2023-07-27 11:26:40 +04:00
e88a9f5bed ruby: delete recipes sorting in the help recipe 2023-07-27 11:26:40 +04:00
f1ce0fb415 ruby: rename server recipes 2023-07-27 11:26:40 +04:00
3b142d92fc php: update urls to new endpoints 2023-07-26 17:42:48 +04:00
1898da660e php: simplify server configuration 2023-07-26 17:42:48 +04:00
0629cf0797 php: add HTTPStatus enum 2023-07-26 17:42:48 +04:00
7737670a6d php: delete IIS config 2023-07-26 17:42:48 +04:00
5bdcac42e3 php: add recipes to start the server 2023-07-26 17:42:48 +04:00
4b8ffa26cc php: add fpm config 2023-07-26 17:41:53 +04:00
a4b6fcb512 java-spring: add a step to save the previous version of the file during processing save 2023-07-26 17:34:07 +04:00
523b10c979 php: update php lint action to latest changes 2023-07-26 17:03:50 +04:00
1d4bc95c29 Merge pull request #424 from ONLYOFFICE/feature/php-configuration-manager
php: add support for configuration via environment variables
2023-07-26 15:31:05 +03:00
e94a4863aa php: replace json config with configuration manager 2023-07-26 12:07:58 +04:00
edda981ab7 php: append configuration directory to test recipe 2023-07-26 12:07:55 +04:00
65ebf9a5b1 php: add configuration manager tests 2023-07-26 12:07:55 +04:00
a081cd1f06 php: add configuration manager 2023-07-26 12:07:55 +04:00
04c5ee8cd7 php: add URL tests 2023-07-26 12:07:55 +04:00
3ebf3fabee php: add URL class 2023-07-26 12:07:52 +04:00
403efc1325 php: add tests for the path absolute function 2023-07-26 11:27:50 +04:00
7deedcaa5e php: enrich Path with new methods 2023-07-26 11:27:50 +04:00
161e26dd8a Merge pull request #423 from ONLYOFFICE/feature/php-missed-tests
php: add missed path tests and rewrite path methods a bit
2023-07-26 10:21:30 +03:00
09804349fa php: update path instances due to new methods 2023-07-24 14:22:28 +04:00
83a83f4f5d php: fix make test receipt 2023-07-24 14:22:28 +04:00
79ee987003 php: add path tests 2023-07-24 14:22:28 +04:00
434484cac3 php: separate path normalization from join 2023-07-24 14:22:25 +04:00
a0bafb0e4b php: simplify path string generation 2023-07-24 12:41:43 +04:00
184aded727 php: remove path separator from constructor options 2023-07-24 12:41:40 +04:00
7304166d8f nodejs: key in referenceData 2023-07-12 12:00:37 +03:00
186 changed files with 6379 additions and 1616 deletions

View File

@ -25,7 +25,5 @@ jobs:
php-version: '8.2'
tools: cs2pr, phpcs
- name: Run phpcs
run: |
phpcs --version
phpcs -q --extensions=php,module,inc,install,test,profile,theme,info --ignore=node_modules,bower_components,vendor,css,js,lib --standard=./ruleset.xml ./
- name: Lint
run: phpcs src index.php

40
.gitmodules vendored
View File

@ -1,11 +1,3 @@
[submodule "web/documentserver-example/java/src/main/resources/assets"]
path = web/documentserver-example/java/src/main/resources/assets
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/python/assets"]
path = web/documentserver-example/python/assets
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/csharp-mvc/assets"]
path = web/documentserver-example/csharp-mvc/assets
url = https://github.com/ONLYOFFICE/document-templates
@ -14,14 +6,6 @@
path = web/documentserver-example/csharp/assets
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/ruby/public/assets"]
path = web/documentserver-example/ruby/public/assets
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/java-spring/src/main/resources/assets"]
path = web/documentserver-example/java-spring/src/main/resources/assets
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/nodejs/public/assets/document-templates"]
path = web/documentserver-example/nodejs/public/assets/document-templates
url = https://github.com/ONLYOFFICE/document-templates
@ -38,3 +22,27 @@
path = web/documentserver-example/php/assets/document-formats
url = https://github.com/ONLYOFFICE/document-formats
branch = master
[submodule "web/documentserver-example/python/assets/document-templates"]
path = web/documentserver-example/python/assets/document-templates
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/java/src/main/resources/assets/document-templates"]
path = web/documentserver-example/java/src/main/resources/assets/document-templates
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/ruby/assets/document-templates"]
path = web/documentserver-example/ruby/assets/document-templates
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/java-spring/src/main/resources/assets/document-templates"]
path = web/documentserver-example/java-spring/src/main/resources/assets/document-templates
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/python/assets/document-formats"]
path = web/documentserver-example/python/assets/document-formats
url = https://github.com/ONLYOFFICE/document-formats
branch = master
[submodule "web/documentserver-example/ruby/assets/document-formats"]
path = web/documentserver-example/ruby/assets/document-formats
url = https://github.com/ONLYOFFICE/document-formats
branch = master

View File

@ -307,6 +307,14 @@ PHPUnit - The PHP Unit Testing framework. (https://github.com/sebastianb
License: BSD 3-Clause
License File: phpunit.license
property-access - Provides functions to read and write from/to an object or array using a simple string notation. (https://github.com/symfony/property-access/blob/6.3/LICENSE)
License: MIT
License File: property-access.license
serializer - Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON. (https://github.com/symfony/serializer/blob/6.3/LICENSE)
License: MIT
License File: serializer.license
web/documentserver-example/python
@ -346,6 +354,10 @@ jQuery.UI - jQuery UI is an open source library of interface components —
License: MIT
License File: jQuery.UI.license
msgspec - A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML. (https://github.com/jcrist/msgspec/blob/0.18.1/LICENSE)
License: BSD 3-Clause
License File: msgspec.license
mypy - Optional static typing for Python. (https://github.com/python/mypy/blob/master/LICENSE)
License: MIT
License File: mypy.license

View File

@ -1,5 +1,10 @@
# Change Log
- nodejs: onRequestSelectDocument method
- nodejs: onRequestSelectSpreadsheet method
- nodejs: onRequestOpen
- nodejs: submitForm
- nodejs: key in referenceData
- nodejs: change reference source
- php: using a repo with a list of formats
- nodejs: using a repo with a list of formats
@ -9,6 +14,10 @@
- python: restore from history
- ruby: restore from history
- php: restore from history
- csharp-mvc: getting history by a separate request
- csharp-mvc: restore from history
- csharp: getting history by a separate request
- csharp: restore from history
## 1.6.0
- nodejs: setUsers for region protection

View File

@ -17,7 +17,6 @@
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Web;
@ -236,123 +235,6 @@ namespace OnlineEditorsExampleMVC.Models
return jss.Serialize(config);
}
// get the document history
public void GetHistory(out string history, out string historyData)
{
var storagePath = WebConfigurationManager.AppSettings["storage-path"];
var jss = new JavaScriptSerializer();
var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(FileName, null));
history = null;
historyData = null;
if (DocManagerHelper.GetFileVersion(histDir) > 0) // if the file was modified (the file version is greater than 0)
{
var currentVersion = DocManagerHelper.GetFileVersion(histDir);
var hist = new List<Dictionary<string, object>>();
var histData = new Dictionary<string, object>();
for (var i = 1; i <= currentVersion; i++) // run through all the file versions
{
var obj = new Dictionary<string, object>();
var dataObj = new Dictionary<string, object>();
var verDir = DocManagerHelper.VersionDir(histDir, i); // get the path to the given file version
var key = i == currentVersion ? Key : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key
obj.Add("key", key);
obj.Add("version", i);
if (i == 1) // check if the version number is equal to 1
{
var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file
if (File.Exists(infoPath))
{
var info = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(infoPath));
obj.Add("created", info["created"]); // write meta information to the object (user information and creation date)
obj.Add("user", new Dictionary<string, object>() {
{ "id", info["id"] },
{ "name", info["name"] },
});
}
}
var ext = Path.GetExtension(FileName).ToLower();
dataObj.Add("fileType", ext.Replace(".", ""));
dataObj.Add("key", key);
// write file url to the data object
string prevFileUrl;
string directPrevFileUrl;
if (Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath))
{
prevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext)
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""));
directPrevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext, false)
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
}
else {
prevFileUrl = i == currentVersion ? FileUri
: DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext);
directPrevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext, false)
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
}
dataObj.Add("url", prevFileUrl);
if (IsEnabledDirectUrl)
{
dataObj.Add("directUrl", directPrevFileUrl);
}
dataObj.Add("version", i);
if (i > 1) // check if the version number is greater than 1 (the file was modified)
{
// get the path to the changes.json file
var changes = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(Path.Combine(DocManagerHelper.VersionDir(histDir, i - 1), "changes.json")));
var changesArray = (ArrayList)changes["changes"];
var change = changesArray.Count > 0
? (Dictionary<string, object>)changesArray[0]
: new Dictionary<string, object>();
// write information about changes to the object
obj.Add("changes", change.Count > 0 ? changes["changes"] : null);
obj.Add("serverVersion", changes["serverVersion"]);
obj.Add("created", change.Count > 0 ? change["created"] : null);
obj.Add("user", change.Count > 0 ? change["user"] : null);
var prev = (Dictionary<string, object>)histData[(i - 2).ToString()]; // get the history data from the previous file version
dataObj.Add("previous", IsEnabledDirectUrl ? new Dictionary<string, object>() { // write information about previous file version to the data object with direct url
{ "fileType", prev["fileType"] },
{ "key", prev["key"] }, // write key and url information about previous file version
{ "url", prev["url"] },
{ "directUrl", prev["directUrl"] },
} : new Dictionary<string, object>() { // write information about previous file version to the data object without direct url
{ "fileType", prev["fileType"] },
{ "key", prev["key"] }, // write key and url information about previous file version
{ "url", prev["url"] },
});
// write the path to the diff.zip archive with differences in this file version
var changesUrl = DocManagerHelper.GetHistoryDownloadUrl(FileName, (i - 1).ToString(), "diff.zip");
dataObj.Add("changesUrl", changesUrl);
}
if(JwtManager.Enabled)
{
var token = JwtManager.Encode(dataObj);
dataObj.Add("token", token);
}
hist.Add(obj); // add object dictionary to the hist list
histData.Add((i - 1).ToString(), dataObj); // write data object information to the history data
}
// write history information about the current file version to the history object
history = jss.Serialize(new Dictionary<string, object>()
{
{ "currentVersion", currentVersion },
{ "history", hist }
});
historyData = jss.Serialize(histData);
}
}
// get a document which will be compared with the current document
public void GetCompareFileData(out string compareConfig)
{

View File

@ -190,6 +190,47 @@
}
};
var onRequestHistory = function () {
let xhr = new XMLHttpRequest();
xhr.open("GET", "webeditor.ashx?type=gethistory&filename=<%= Model.FileName %>");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send();
xhr.onload = function () {
console.log(xhr.responseText);
docEditor.refreshHistory(JSON.parse(xhr.responseText));
}
};
var onRequestHistoryData = function (event) {
var ver = event.data;
let xhr = new XMLHttpRequest();
xhr.open("GET", "webeditor.ashx?type=getversiondata&filename=<%= Model.FileName %>&version=" + ver + "&directUrl=" + !!config.document.directUrl);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send();
xhr.onload = function () {
console.log(xhr.responseText);
docEditor.setHistoryData(JSON.parse(xhr.responseText)); // send the link to the document for viewing the version history
}
};
var onRequestRestore = function (event) {
var fileName = "<%= Model.FileName %>";
var version = event.data.version;
var data = {
fileName: fileName,
version: version
};
let xhr = new XMLHttpRequest();
xhr.open("POST", "webeditor.ashx?type=restore&directUrl=" + !!config.document.directUrl);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(data));
xhr.onload = function () {
docEditor.refreshHistory(JSON.parse(xhr.responseText));
}
}
config = <%= Model.GetDocConfig(Request, Url) %>;
config.width = "100%";
@ -207,30 +248,19 @@
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
};
<% string hist, histData; %>
<% Model.GetHistory(out hist, out histData); %>
<% string usersForMentions; %>
<% Model.GetUsersMentions(Request, out usersForMentions); %>
if (config.editorConfig.user.id) {
<% if (!string.IsNullOrEmpty(hist) && !string.IsNullOrEmpty(histData))
{ %>
// the user is trying to show the document version history
config.events['onRequestHistory'] = function () {
docEditor.refreshHistory(<%= hist %>); // show the document version history
};
// the user is trying to click the specific document version in the document version history
config.events['onRequestHistoryData'] = function (event) {
var ver = event.data;
var histData = <%= histData %>;
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
};
// the user is trying to go back to the document from viewing the document version history
config.events['onRequestHistoryClose'] = function () {
document.location.reload();
};
<% } %>
// the user is trying to show the document version history
config.events['onRequestHistory'] = onRequestHistory;
// the user is trying to click the specific document version in the document version history
config.events['onRequestHistoryData'] = onRequestHistoryData;
// the user is trying to go back to the document from viewing the document version history
config.events['onRequestHistoryClose'] = function () {
document.location.reload();
};
config.events['onRequestRestore'] = onRequestRestore;
// add mentions for not anonymous users
<% if (!string.IsNullOrEmpty(usersForMentions))

View File

@ -17,6 +17,7 @@
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
@ -50,6 +51,15 @@ namespace OnlineEditorsExampleMVC
case "downloadhistory":
DownloadHistory(context);
break;
case "gethistory":
GetHistory(context);
break;
case "getversiondata":
GetVersionData(context);
break;
case "restore":
Restore(context);
break;
case "convert":
Convert(context);
break;
@ -513,6 +523,173 @@ namespace OnlineEditorsExampleMVC
get { return false; }
}
private static void GetHistory(HttpContext context)
{
var jss = new JavaScriptSerializer();
var fileName = context.Request["filename"];
var history = GetHistory(fileName);
context.Response.Write(jss.Serialize(history));
}
private static void GetVersionData(HttpContext context)
{
var storagePath = WebConfigurationManager.AppSettings["storage-path"];
var jss = new JavaScriptSerializer();
var fileName = context.Request["filename"];
int version;
if (!int.TryParse(context.Request["version"], out version))
{
context.Response.Write("{ \"error\": \"Version number invalid!\"}");
return;
}
var versionData = new Dictionary<string, object>();
var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(fileName, null));
var lastVersion = DocManagerHelper.GetFileVersion(histDir);
var verDir = DocManagerHelper.VersionDir(histDir, version);
var key = version == lastVersion
? ServiceConverter.GenerateRevisionId(DocManagerHelper.CurUserHostAddress()
+ "/" + fileName + "/"
+ File.GetLastWriteTime(DocManagerHelper.StoragePath(fileName, null)).GetHashCode())
: File.ReadAllText(Path.Combine(verDir, "key.txt"));
var ext = Path.GetExtension(fileName).ToLower();
versionData.Add("fileType", ext.Replace(".", ""));
versionData.Add("key", key);
// write file url to the data object
string prevFileUrl;
string directPrevFileUrl;
if (Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath))
{
prevFileUrl = version == lastVersion ? DocManagerHelper.GetDownloadUrl(fileName)
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""));
directPrevFileUrl = version == lastVersion ? DocManagerHelper.GetDownloadUrl(fileName, false)
: DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
}
else
{
prevFileUrl = version == lastVersion ? DocManagerHelper.GetFileUri(fileName, true)
: DocManagerHelper.GetHistoryDownloadUrl(fileName, version.ToString(), "prev" + ext);
directPrevFileUrl = version == lastVersion ? DocManagerHelper.GetFileUri(fileName, false)
: DocManagerHelper.GetHistoryDownloadUrl(fileName, version.ToString(), "prev" + ext, false);
}
versionData.Add("url", prevFileUrl);
var isEnableDirectUrl = string.Equals(DocManagerHelper.GetDirectUrl(), "true");
if (isEnableDirectUrl)
{
versionData.Add("directUrl", directPrevFileUrl); // write direct url to the data object
}
versionData.Add("version", version);
if (version > 1)
{
var prevVerDir = DocManagerHelper.VersionDir(histDir, version - 1);
var prevUrl = Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath)
? DocManagerHelper.GetDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", ""))
: DocManagerHelper.GetHistoryDownloadUrl(fileName, (version - 1).ToString(), "prev" + ext);
var prevKey = File.ReadAllText(Path.Combine(prevVerDir, "key.txt"));
Dictionary<string, object> dataPrev = new Dictionary<string, object>() { // write information about previous file version to the data object
{ "fileType", ext.Replace(".", "") },
{ "key", prevKey }, // write key and url information about previous file version
{ "url", prevUrl }
};
string directPrevUrl;
if (isEnableDirectUrl)
{
directPrevUrl = Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath)
? DocManagerHelper.GetDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", ""), false)
: DocManagerHelper.GetHistoryDownloadUrl(fileName, version.ToString(), "prev" + ext, false);
dataPrev.Add("directUrl", directPrevUrl);
}
versionData.Add("previous", dataPrev);
if (File.Exists(Path.Combine(prevVerDir, "diff.zip")))
{
var changesUrl = DocManagerHelper.GetHistoryDownloadUrl(fileName, (version - 1).ToString(), "diff.zip");
versionData.Add("changesUrl", changesUrl);
}
}
if (JwtManager.Enabled)
{
var token = JwtManager.Encode(versionData);
versionData.Add("token", token);
}
context.Response.Write(jss.Serialize(versionData));
}
private static void Restore(HttpContext context)
{
string fileData;
try
{
using (var receiveStream = context.Request.InputStream)
using (var readStream = new StreamReader(receiveStream))
{
fileData = readStream.ReadToEnd();
if (string.IsNullOrEmpty(fileData)) return;
}
}
catch (Exception e)
{
throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
}
var jss = new JavaScriptSerializer();
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
var fileName = (string)body["fileName"];
var version = (int)body["version"];
var key = ServiceConverter.GenerateRevisionId(DocManagerHelper.CurUserHostAddress()
+ "/" + fileName + "/"
+ File.GetLastWriteTime(DocManagerHelper.StoragePath(fileName, null)).GetHashCode());
var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(fileName, null));
var currentVersionDir = DocManagerHelper.VersionDir(histDir, DocManagerHelper.GetFileVersion(histDir));
var verDir = DocManagerHelper.VersionDir(histDir, version);
if (!Directory.Exists(currentVersionDir)) Directory.CreateDirectory(currentVersionDir);
var ext = Path.GetExtension(fileName).ToLower();
File.Copy(DocManagerHelper.StoragePath(fileName, null), Path.Combine(currentVersionDir, "prev" + ext));
File.WriteAllText(Path.Combine(currentVersionDir, "key.txt"), key);
var changesPath = Path.Combine(DocManagerHelper.VersionDir(histDir, version - 1), "changes.json");
if (File.Exists(changesPath))
{
File.Copy(changesPath, Path.Combine(currentVersionDir, "changes.json"));
}
File.Copy(Path.Combine(verDir, "prev" + ext), DocManagerHelper.StoragePath(fileName, null), true);
var fileInfo = new FileInfo(DocManagerHelper.StoragePath(fileName, null));
fileInfo.LastWriteTimeUtc = DateTime.UtcNow;
var history = GetHistory(fileName);
context.Response.Write(jss.Serialize(history));
}
// download a history file
private static void DownloadHistory(HttpContext context)
{
@ -687,6 +864,70 @@ namespace OnlineEditorsExampleMVC
context.Response.Write(jss.Serialize(data));
}
// get the document history
private static Dictionary<string, object> GetHistory(string fileName)
{
var jss = new JavaScriptSerializer();
var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(fileName, null));
var history = new Dictionary<string, object>();
var currentVersion = DocManagerHelper.GetFileVersion(histDir);
var currentKey = ServiceConverter.GenerateRevisionId(DocManagerHelper.CurUserHostAddress()
+ "/" + fileName + "/"
+ File.GetLastWriteTime(DocManagerHelper.StoragePath(fileName, null)).GetHashCode());
var versionList = new List<Dictionary<string, object>>();
for (var versionNum = 1; versionNum <= currentVersion; versionNum++)
{
var versionObj = new Dictionary<string, object>();
var verDir = DocManagerHelper.VersionDir(histDir, versionNum); // get the path to the given file version
var key = versionNum == currentVersion ? currentKey : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key
versionObj.Add("key", key);
versionObj.Add("version", versionNum);
var changesPath = Path.Combine(DocManagerHelper.VersionDir(histDir, versionNum - 1), "changes.json");
if (versionNum == 1 || !File.Exists(changesPath)) // check if the version number is equal to 1
{
var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file
if (File.Exists(infoPath))
{
var info = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(infoPath));
versionObj.Add("created", info["created"]); // write meta information to the object (user information and creation date)
versionObj.Add("user", new Dictionary<string, object>()
{
{ "id", info["id"] },
{ "name", info["name"] },
});
}
}
else if (versionNum > 1) // check if the version number is greater than 1 (the file was modified)
{
// get the path to the changes.json file
var changes = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(changesPath));
var changesArray = (ArrayList)changes["changes"];
var change = changesArray.Count > 0
? (Dictionary<string, object>)changesArray[0]
: new Dictionary<string, object>();
// write information about changes to the object
versionObj.Add("changes", change.Count > 0 ? changes["changes"] : null);
versionObj.Add("serverVersion", changes["serverVersion"]);
versionObj.Add("created", change.Count > 0 ? change["created"] : null);
versionObj.Add("user", change.Count > 0 ? change["user"] : null);
}
versionList.Add(versionObj);
}
history.Add("currentVersion", currentVersion);
history.Add("history", versionList);
return history;
}
}
}

View File

@ -633,5 +633,12 @@ namespace OnlineEditorsExample
string isEnabledDirectUrl = HttpUtility.ParseQueryString(HttpContext.Current.Request.Url.Query).Get("directUrl");
return "&directUrl=" + (isEnabledDirectUrl != null ? isEnabledDirectUrl : "false");
}
// get direct url flag
public static bool IsEnabledDirectUrl()
{
string isEnabledDirectUrl = HttpUtility.ParseQueryString(HttpContext.Current.Request.Url.Query).Get("directUrl");
return isEnabledDirectUrl != null ? Convert.ToBoolean(isEnabledDirectUrl) : false;
}
}
}

View File

@ -221,20 +221,49 @@
};
if (config.editorConfig.user.id) {
<% if (!string.IsNullOrEmpty(History) && !string.IsNullOrEmpty(HistoryData))
{ %>
config.events['onRequestHistory'] = function () { // the user is trying to show the document version history
docEditor.refreshHistory(<%= History %>); // show the document version history
config.events['onRequestHistory'] = function (event) { // the user is trying to show the document version history
let xhr = new XMLHttpRequest();
xhr.open("GET", "webeditor.ashx?type=gethistory&filename=<%= FileName %>");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send();
xhr.onload = function () {
console.log(xhr.responseText);
docEditor.refreshHistory(JSON.parse(xhr.responseText));
}
};
config.events['onRequestHistoryData'] = function (event) { // the user is trying to click the specific document version in the document version history
var ver = event.data;
let xhr = new XMLHttpRequest();
xhr.open("GET", "webeditor.ashx?type=getversiondata&filename=<%= FileName %>&version=" + ver + "&directUrl=" + !!config.document.directUrl);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send();
xhr.onload = function () {
console.log(xhr.responseText);
docEditor.setHistoryData(JSON.parse(xhr.responseText)); // send the link to the document for viewing the version history
}
};
config.events['onRequestHistoryClose'] = function () { // the user is trying to go back to the document from viewing the document version history
document.location.reload();
};
config.events['onRequestRestore'] = function (event) {
var fileName = "<%= FileName %>";
var version = event.data.version;
var data = {
fileName: fileName,
version: version
};
config.events['onRequestHistoryData'] = function (event) { // the user is trying to click the specific document version in the document version history
var ver = event.data;
var histData = <%= HistoryData %>;
docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history
};
config.events['onRequestHistoryClose'] = function () { // the user is trying to go back to the document from viewing the document version history
document.location.reload();
};
<% } %>
let xhr = new XMLHttpRequest();
xhr.open("POST", "webeditor.ashx?type=restore&directUrl=" + !!config.document.directUrl);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(data));
xhr.onload = function () {
docEditor.refreshHistory(JSON.parse(xhr.responseText));
}
};
// add mentions for not anonymous users
<% if (!string.IsNullOrEmpty(UsersForMentions))

View File

@ -17,7 +17,6 @@
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Web;
@ -61,8 +60,6 @@ namespace OnlineEditorsExample
}
protected string DocConfig { get; private set; }
protected string History { get; private set; }
protected string HistoryData { get; private set; }
protected string InsertImageConfig { get; private set; }
protected string CompareFileData { get; private set; }
protected string DataMailMergeRecipients { get; private set; }
@ -195,7 +192,7 @@ namespace OnlineEditorsExample
{
{ "title", FileName },
{ "url", getDownloadUrl(FileName) },
{ "directUrl", IsEnabledDirectUrl() ? directUrl : "" },
{ "directUrl", _Default.IsEnabledDirectUrl() ? directUrl : "" },
{ "fileType", ext.Trim('.') },
{ "key", Key },
{
@ -320,134 +317,10 @@ namespace OnlineEditorsExample
// get users for mentions
List<Dictionary<string, object>> usersData = Users.getUsersForMentions(user.id);
UsersForMentions = !user.id.Equals("uid-0") ? jss.Serialize(usersData) : null;
Dictionary<string, object> hist;
Dictionary<string, object> histData;
// get the document history
GetHistory(out hist, out histData);
if (hist != null && histData != null)
{
History = jss.Serialize(hist);
HistoryData = jss.Serialize(histData);
}
}
catch { }
}
// get the document history
private void GetHistory(out Dictionary<string, object> history, out Dictionary<string, object> historyData)
{
var storagePath = WebConfigurationManager.AppSettings["storage-path"];
var jss = new JavaScriptSerializer();
var histDir = _Default.HistoryDir(_Default.StoragePath(FileName, null));
history = null;
historyData = null;
if (_Default.GetFileVersion(histDir) > 0) // if the file was modified (the file version is greater than 0)
{
var currentVersion = _Default.GetFileVersion(histDir);
var hist = new List<Dictionary<string, object>>();
var histData = new Dictionary<string, object>();
for (var i = 1; i <= currentVersion; i++) // run through all the file versions
{
var obj = new Dictionary<string, object>();
var dataObj = new Dictionary<string, object>();
var verDir = _Default.VersionDir(histDir, i); // get the path to the given file version
var key = i == currentVersion ? Key : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key
obj.Add("key", key);
obj.Add("version", i);
if (i == 1) // check if the version number is equal to 1
{
var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file
if (File.Exists(infoPath)) {
var info = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(infoPath));
obj.Add("created", info["created"]); // write meta information to the object (user information and creation date)
obj.Add("user", new Dictionary<string, object>() {
{ "id", info["id"] },
{ "name", info["name"] },
});
}
}
var ext = Path.GetExtension(FileName).ToLower();
dataObj.Add("fileType", ext.Replace(".", ""));
dataObj.Add("key", key);
// write file url to the data object
var directPrevFileUrl = i == currentVersion ? _Default.FileUri(FileName, false) : MakePublicHistoryUrl(FileName, i.ToString(), "prev" + ext, false);
var prevFileUrl = i == currentVersion ? FileUri : MakePublicHistoryUrl(FileName, i.ToString(), "prev" + ext);
if (Path.IsPathRooted(storagePath))
{
prevFileUrl = i == currentVersion ? getDownloadUrl(FileName) : getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""));
directPrevFileUrl = i == currentVersion ? getDownloadUrl(FileName, false) : getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
}
dataObj.Add("url", prevFileUrl); // write file url to the data object
if (IsEnabledDirectUrl())
{
dataObj.Add("directUrl", directPrevFileUrl); // write direct url to the data object
}
dataObj.Add("version", i);
if (i > 1) // check if the version number is greater than 1 (the file was modified)
{
// get the path to the changes.json file
var changes = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(Path.Combine(_Default.VersionDir(histDir, i - 1), "changes.json")));
var changesArray = (ArrayList)changes["changes"];
var change = changesArray.Count > 0
? (Dictionary<string, object>)changesArray[0]
: new Dictionary<string, object>();
// write information about changes to the object
obj.Add("changes", change.Count > 0 ? changes["changes"] : null);
obj.Add("serverVersion", changes["serverVersion"]);
obj.Add("created", change.Count > 0 ? change["created"] : null);
obj.Add("user", change.Count > 0 ? change["user"] : null);
var prev = (Dictionary<string, object>)histData[(i - 2).ToString()]; // get the history data from the previous file version
Dictionary<string, object> dataPrev = new Dictionary<string, object>() { // write information about previous file version to the data object
{ "fileType", prev["fileType"] },
{ "key", prev["key"] }, // write key and url information about previous file version
{ "url", prev["url"] }
};
if (IsEnabledDirectUrl())
{
dataPrev.Add("directUrl", prev["directUrl"]);
}
dataObj.Add("previous", dataPrev);
// write the path to the diff.zip archive with differences in this file version
var changesUrl = MakePublicHistoryUrl(FileName, (i - 1).ToString(), "diff.zip");
dataObj.Add("changesUrl", changesUrl);
}
if (JwtManager.Enabled)
{
var token = JwtManager.Encode(dataObj);
dataObj.Add("token", token);
}
hist.Add(obj); // add object dictionary to the hist list
histData.Add((i - 1).ToString(), dataObj); // write data object information to the history data
}
// write history information about the current file version to the history object
history = new Dictionary<string, object>()
{
{ "currentVersion", currentVersion },
{ "history", hist }
};
historyData = histData;
}
}
// get a logo config
private Dictionary<string, object> GetLogoConfig()
{
@ -469,7 +342,7 @@ namespace OnlineEditorsExample
{ "url", InsertImageUrl.ToString()}
};
if (IsEnabledDirectUrl())
if (_Default.IsEnabledDirectUrl())
{
logoConfig.Add("directUrl", DirectImageUrl.ToString());
}
@ -506,7 +379,7 @@ namespace OnlineEditorsExample
{ "url", compareFileUrl.ToString() }
};
if (IsEnabledDirectUrl())
if (_Default.IsEnabledDirectUrl())
{
dataCompareFile.Add("directUrl", DirectFileUrl.ToString());
}
@ -545,7 +418,7 @@ namespace OnlineEditorsExample
{ "url", mailmergeUrl.ToString() }
};
if (IsEnabledDirectUrl())
if (_Default.IsEnabledDirectUrl())
{
mailMergeConfig.Add("directUrl", DirectMailMergeUrl.ToString());
}
@ -589,21 +462,6 @@ namespace OnlineEditorsExample
return _Default.GetServerUrl(true) + fullPath.Substring(root.Length).Replace(Path.DirectorySeparatorChar, '/');
}
// create the public history url
private string MakePublicHistoryUrl(string filename, string version, string file, Boolean isServer = true)
{
var userAddress = isServer ? "&userAddress=" + HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)) : "";
var fileUrl = new UriBuilder(_Default.GetServerUrl(isServer));
fileUrl.Path = HttpRuntime.AppDomainAppVirtualPath
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
+ "webeditor.ashx";
fileUrl.Query = "type=downloadhistory&fileName=" + HttpUtility.UrlEncode(filename)
+ "&ver=" + version + "&file=" + file
+ userAddress;
return fileUrl.ToString();
}
// create demo document
private static void Try(string type, string sample, HttpRequest request)
{
@ -652,12 +510,5 @@ namespace OnlineEditorsExample
{ "name", uname }
}));
}
// get direct url flag
private static bool IsEnabledDirectUrl()
{
string isEnabledDirectUrl = HttpUtility.ParseQueryString(HttpContext.Current.Request.Url.Query).Get("directUrl");
return isEnabledDirectUrl != null ? Convert.ToBoolean(isEnabledDirectUrl) : false;
}
}
}

View File

@ -26,7 +26,9 @@ using System.Diagnostics;
using System.Web.Configuration;
using System.Linq;
using System.Net;
using System.Collections;
using System.Net.Sockets;
using ASC.Api.DocumentConverter;
namespace OnlineEditorsExample
{
@ -48,6 +50,15 @@ namespace OnlineEditorsExample
case "downloadhistory":
DownloadHistory(context);
break;
case "gethistory":
GetHistory(context);
break;
case "getversiondata":
GetVersionData(context);
break;
case "restore":
Restore(context);
break;
case "convert":
Convert(context);
break;
@ -333,6 +344,164 @@ namespace OnlineEditorsExample
get { return false; }
}
private static void GetHistory(HttpContext context)
{
var jss = new JavaScriptSerializer();
var fileName = context.Request["filename"];
var history = GetHistory(fileName);
context.Response.Write(jss.Serialize(history));
}
private static void GetVersionData(HttpContext context)
{
var storagePath = WebConfigurationManager.AppSettings["storage-path"];
var jss = new JavaScriptSerializer();
var fileName = context.Request["filename"];
int version;
if (!int.TryParse(context.Request["version"], out version))
{
context.Response.Write("{ \"error\": \"Version number invalid!\"}");
return;
}
var versionData = new Dictionary<string, object>();
var histDir = _Default.HistoryDir(_Default.StoragePath(fileName, null));
var lastVersion = _Default.GetFileVersion(histDir);
var verDir = _Default.VersionDir(histDir, version);
var lastVersionUri = _Default.FileUri(fileName, true);
var key = version == lastVersion
? ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null)
+ "/" + Path.GetFileName(lastVersionUri)
+ "/" + File.GetLastWriteTime(_Default.StoragePath(fileName, null)).GetHashCode())
: File.ReadAllText(Path.Combine(verDir, "key.txt"));
var ext = Path.GetExtension(fileName).ToLower();
versionData.Add("fileType", ext.Replace(".", ""));
versionData.Add("key", key);
var directPrevFileUrl = version == lastVersion ? _Default.FileUri(fileName, false) : MakePublicHistoryUrl(fileName, version.ToString(), "prev" + ext, false);
var prevFileUrl = version == lastVersion ? lastVersionUri : MakePublicHistoryUrl(fileName, version.ToString(), "prev" + ext);
if (Path.IsPathRooted(storagePath))
{
prevFileUrl = version == lastVersion ? DocEditor.getDownloadUrl(fileName) : DocEditor.getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""));
directPrevFileUrl = version == lastVersion ? DocEditor.getDownloadUrl(fileName, false) : DocEditor.getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false);
}
versionData.Add("url", prevFileUrl);
if (_Default.IsEnabledDirectUrl())
{
versionData.Add("directUrl", directPrevFileUrl); // write direct url to the data object
}
versionData.Add("version", version);
if (version > 1)
{
var prevVerDir = _Default.VersionDir(histDir, version - 1);
var prevUrl = MakePublicHistoryUrl(fileName, (version - 1).ToString(), "prev" + ext);
if (Path.IsPathRooted(storagePath))
prevUrl = DocEditor.getDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", ""));
var prevKey = File.ReadAllText(Path.Combine(prevVerDir, "key.txt"));
Dictionary<string, object> dataPrev = new Dictionary<string, object>() { // write information about previous file version to the data object
{ "fileType", ext.Replace(".", "") },
{ "key", prevKey }, // write key and url information about previous file version
{ "url", prevUrl }
};
string directPrevUrl;
if (_Default.IsEnabledDirectUrl())
{
directPrevUrl = Path.IsPathRooted(storagePath)
? DocEditor.getDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", ""), false)
: MakePublicHistoryUrl(fileName, (version - 1).ToString(), "prev" + ext, false);
dataPrev.Add("directUrl", directPrevUrl); // write direct url to the data object
}
versionData.Add("previous", dataPrev);
if (File.Exists(Path.Combine(prevVerDir, "diff.zip")))
{
var changesUrl = MakePublicHistoryUrl(fileName, (version - 1).ToString(), "diff.zip");
versionData.Add("changesUrl", changesUrl);
}
}
if (JwtManager.Enabled)
{
var token = JwtManager.Encode(versionData);
versionData.Add("token", token);
}
context.Response.Write(jss.Serialize(versionData));
}
private void Restore(HttpContext context)
{
string fileData;
try
{
using (var receiveStream = context.Request.InputStream)
using (var readStream = new StreamReader(receiveStream))
{
fileData = readStream.ReadToEnd();
if (string.IsNullOrEmpty(fileData)) return;
}
}
catch (Exception e)
{
throw new HttpException((int)HttpStatusCode.BadRequest, e.Message);
}
var jss = new JavaScriptSerializer();
var body = jss.Deserialize<Dictionary<string, object>>(fileData);
var fileName = (string)body["fileName"];
var version = (int)body["version"];
var lastVersionUri = _Default.FileUri(fileName, true);
var key = ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null)
+ "/" + Path.GetFileName(lastVersionUri)
+ "/" + File.GetLastWriteTime(_Default.StoragePath(fileName, null)).GetHashCode());
var histDir = _Default.HistoryDir(_Default.StoragePath(fileName, null));
var currentVersionDir = _Default.VersionDir(histDir, _Default.GetFileVersion(histDir));
var verDir = _Default.VersionDir(histDir, version);
if (!Directory.Exists(currentVersionDir)) Directory.CreateDirectory(currentVersionDir);
var ext = Path.GetExtension(fileName).ToLower();
File.Copy(_Default.StoragePath(fileName, null), Path.Combine(currentVersionDir, "prev" + ext));
File.WriteAllText(Path.Combine(currentVersionDir, "key.txt"), key);
var changesPath = Path.Combine(_Default.VersionDir(histDir, version - 1), "changes.json");
if (File.Exists(changesPath))
{
File.Copy(changesPath, Path.Combine(currentVersionDir, "changes.json"));
}
File.Copy(Path.Combine(verDir, "prev" + ext), _Default.StoragePath(fileName, null), true);
var fileInfo = new FileInfo(_Default.StoragePath(fileName, null));
fileInfo.LastWriteTimeUtc = DateTime.UtcNow;
var history = GetHistory(fileName);
context.Response.Write(jss.Serialize(history));
}
private static void DownloadHistory(HttpContext context)
{
try
@ -504,5 +673,84 @@ namespace OnlineEditorsExample
context.Response.Write(jss.Serialize(data));
}
// get the document history
private static Dictionary<string, object> GetHistory(string fileName)
{
var jss = new JavaScriptSerializer();
var histDir = _Default.HistoryDir(_Default.StoragePath(fileName, null));
var history = new Dictionary<string, object>();
var currentVersion = _Default.GetFileVersion(histDir);
var currentFileUri = _Default.FileUri(fileName, true);
var currentKey = ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null)
+ "/" + Path.GetFileName(currentFileUri)
+ "/" + File.GetLastWriteTime(_Default.StoragePath(fileName, null)).GetHashCode());
var versionList = new List<Dictionary<string, object>>();
for (var versionNum = 1; versionNum <= currentVersion; versionNum++)
{
var versionObj = new Dictionary<string, object>();
var verDir = _Default.VersionDir(histDir, versionNum); // get the path to the given file version
var key = versionNum == currentVersion ? currentKey : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key
versionObj.Add("key", key);
versionObj.Add("version", versionNum);
var changesPath = Path.Combine(_Default.VersionDir(histDir, versionNum - 1), "changes.json");
if (versionNum == 1 || !File.Exists(changesPath)) // check if the version number is equal to 1
{
var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file
if (File.Exists(infoPath))
{
var info = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(infoPath));
versionObj.Add("created", info["created"]); // write meta information to the object (user information and creation date)
versionObj.Add("user", new Dictionary<string, object>()
{
{ "id", info["id"] },
{ "name", info["name"] },
});
}
}
else if (versionNum > 1) // check if the version number is greater than 1 (the file was modified)
{
// get the path to the changes.json file
var changes = jss.Deserialize<Dictionary<string, object>>(File.ReadAllText(changesPath));
var changesArray = (ArrayList)changes["changes"];
var change = changesArray.Count > 0
? (Dictionary<string, object>)changesArray[0]
: new Dictionary<string, object>();
// write information about changes to the object
versionObj.Add("changes", change.Count > 0 ? changes["changes"] : null);
versionObj.Add("serverVersion", changes["serverVersion"]);
versionObj.Add("created", change.Count > 0 ? change["created"] : null);
versionObj.Add("user", change.Count > 0 ? change["user"] : null);
}
versionList.Add(versionObj);
}
history.Add("currentVersion", currentVersion);
history.Add("history", versionList);
return history;
}
// create the public history url
private static string MakePublicHistoryUrl(string filename, string version, string file, Boolean isServer = true)
{
var userAddress = isServer ? "&userAddress=" + HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)) : "";
var fileUrl = new UriBuilder(_Default.GetServerUrl(isServer));
fileUrl.Path = HttpRuntime.AppDomainAppVirtualPath
+ (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/")
+ "webeditor.ashx";
fileUrl.Query = "type=downloadhistory&fileName=" + HttpUtility.UrlEncode(filename)
+ "&ver=" + version + "&file=" + file
+ userAddress;
return fileUrl.ToString();
}
}
}

View File

@ -35,6 +35,8 @@ import com.onlyoffice.integration.documentserver.util.file.FileUtility;
import com.onlyoffice.integration.documentserver.util.service.ServiceConverter;
import com.onlyoffice.integration.documentserver.managers.document.DocumentManager;
import com.onlyoffice.integration.documentserver.managers.callback.CallbackManager;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.springframework.beans.factory.annotation.Autowired;
@ -49,6 +51,7 @@ import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@ -56,14 +59,20 @@ import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.InetAddress;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
@ -355,13 +364,13 @@ public class FileController {
@GetMapping("/assets")
public ResponseEntity<Resource> assets(@RequestParam("name")
final String name) { // get sample files from the assests
String fileName = Path.of("assets", "sample", fileUtility.getFileName(name)).toString();
String fileName = Path.of("assets", "document-templates", "sample", fileUtility.getFileName(name)).toString();
return downloadFile(fileName);
}
@GetMapping("/csv")
public ResponseEntity<Resource> csv() { // download a csv file
String fileName = Path.of("assets", "sample", "csv.csv").toString();
String fileName = Path.of("assets", "document-templates", "sample", "csv.csv").toString();
return downloadFile(fileName);
}
@ -528,4 +537,88 @@ public class FileController {
return "{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}";
}
}
@PutMapping("/restore")
@ResponseBody
public String restore(@RequestBody final JSONObject body) {
try {
String sourceBasename = (String) body.get("fileName");
Integer version = (Integer) body.get("version");
String userID = (String) body.get("userId");
String sourceStringFile = storagePathBuilder.getFileLocation(sourceBasename);
File sourceFile = new File(sourceStringFile);
Path sourcePathFile = sourceFile.toPath();
String historyDirectory = storagePathBuilder.getHistoryDir(sourcePathFile.toString());
Integer bumpedVersion = storagePathBuilder.getFileVersion(historyDirectory, false);
String bumpedVersionStringDirectory = documentManager.versionDir(historyDirectory, bumpedVersion, true);
File bumpedVersionDirectory = new File(bumpedVersionStringDirectory);
if (!bumpedVersionDirectory.exists()) {
bumpedVersionDirectory.mkdir();
}
Path bumpedKeyPathFile = Paths.get(bumpedVersionStringDirectory, "key.txt");
String bumpedKeyStringFile = bumpedKeyPathFile.toString();
File bumpedKeyFile = new File(bumpedKeyStringFile);
String bumpedKey = serviceConverter.generateRevisionId(
storagePathBuilder.getStorageLocation()
+ "/"
+ sourceBasename
+ "/"
+ Long.toString(sourceFile.lastModified())
);
FileWriter bumpedKeyFileWriter = new FileWriter(bumpedKeyFile);
bumpedKeyFileWriter.write(bumpedKey);
bumpedKeyFileWriter.close();
Integer userInnerID = Integer.parseInt(userID.replace("uid-", ""));
User user = userService.findUserById(userInnerID).get();
Path bumpedChangesPathFile = Paths.get(bumpedVersionStringDirectory, "changes.json");
String bumpedChangesStringFile = bumpedChangesPathFile.toString();
File bumpedChangesFile = new File(bumpedChangesStringFile);
JSONObject bumpedChangesUser = new JSONObject();
// Don't add the `uid-` prefix.
// https://github.com/ONLYOFFICE/document-server-integration/issues/437#issuecomment-1663526562
bumpedChangesUser.put("id", user.getId());
bumpedChangesUser.put("name", user.getName());
JSONObject bumpedChangesChangesItem = new JSONObject();
bumpedChangesChangesItem.put("created", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
bumpedChangesChangesItem.put("user", bumpedChangesUser);
JSONArray bumpedChangesChanges = new JSONArray();
bumpedChangesChanges.add(bumpedChangesChangesItem);
JSONObject bumpedChanges = new JSONObject();
bumpedChanges.put("serverVersion", null);
bumpedChanges.put("changes", bumpedChangesChanges);
String bumpedChangesContent = bumpedChanges.toJSONString();
FileWriter bumpedChangesFileWriter = new FileWriter(bumpedChangesFile);
bumpedChangesFileWriter.write(bumpedChangesContent);
bumpedChangesFileWriter.close();
String sourceExtension = fileUtility.getFileExtension(sourceBasename);
String previousBasename = "prev" + sourceExtension;
Path bumpedFile = Paths.get(bumpedVersionStringDirectory, previousBasename);
Files.move(sourcePathFile, bumpedFile);
String recoveryVersionStringDirectory = documentManager.versionDir(historyDirectory, version, true);
Path recoveryPathFile = Paths.get(recoveryVersionStringDirectory, previousBasename);
String recoveryStringFile = recoveryPathFile.toString();
FileInputStream recoveryStream = new FileInputStream(recoveryStringFile);
storageMutator.createFile(sourcePathFile, recoveryStream);
recoveryStream.close();
JSONObject responseBody = new JSONObject();
responseBody.put("error", null);
responseBody.put("success", true);
return responseBody.toJSONString();
} catch (Exception error) {
error.printStackTrace();
JSONObject responseBody = new JSONObject();
responseBody.put("error", error.getMessage());
responseBody.put("success", false);
return responseBody.toJSONString();
}
}
}

View File

@ -163,6 +163,8 @@ public class DefaultCallbackManager implements CallbackManager {
storageMutator.createDirectory(ver); // create the file version directory
lastVersion.toFile().renameTo(new File(versionDir + File.separator + "prev" + curExt));
saveFile(byteArrayFile, toSave); // save document file
byte[] byteArrayChanges = getDownloadFile(changesUri); // download file changes

View File

@ -217,8 +217,14 @@ public class DefaultDocumentManager implements DocumentManager {
public String createDemo(final String fileExt, final Boolean sample, final String uid, final String uname) {
String demoName = (sample ? "sample." : "new.")
+ fileExt; // create sample or new template file with the necessary extension
String demoPath = "assets" + File.separator + (sample ? "sample" : "new")
+ File.separator + demoName; // get the path to the sample document
String demoPath =
"assets"
+ File.separator
+ "document-templates"
+ File.separator
+ (sample ? "sample" : "new")
+ File.separator
+ demoName;
// get a file name with an index if the file with such a name already exists
String fileName = getCorrectName(demoName);

View File

@ -172,6 +172,28 @@
}
};
function onRequestRestore(event) {
const query = new URLSearchParams(window.location.search)
const config = [[${model}]]
const payload = {
fileName: query.get('fileName'),
version: event.data.version,
userId: config.editorConfig.user.id
}
const request = new XMLHttpRequest()
request.open('PUT', 'restore')
request.setRequestHeader('Content-Type', 'application/json')
request.send(JSON.stringify(payload))
request.onload = function () {
if (request.status != 200) {
response = JSON.parse(request.response)
innerAlert(response.error)
return
}
document.location.reload()
}
}
config.width = "100%";
config.height = "100%";
config.events = {
@ -184,6 +206,7 @@
"onRequestInsertImage": onRequestInsertImage,
"onRequestCompareFile": onRequestCompareFile,
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
"onRequestRestore": onRequestRestore
};
var histArray = [[${fileHistory}]];

View File

@ -48,6 +48,7 @@ import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
@ -57,7 +58,9 @@ import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
@ -126,6 +129,9 @@ public class IndexServlet extends HttpServlet {
case "reference":
reference(request, response, writer);
break;
case "restore":
restore(request, response, writer);
break;
default:
break;
}
@ -451,7 +457,7 @@ public class IndexServlet extends HttpServlet {
private static void csv(final HttpServletRequest request,
final HttpServletResponse response,
final PrintWriter writer) {
String fileName = "assets/sample/csv.csv";
String fileName = "assets/document-templates/sample/csv.csv";
URL fileUrl = Thread.currentThread().getContextClassLoader().getResource(fileName);
Path filePath = null;
try {
@ -466,7 +472,7 @@ public class IndexServlet extends HttpServlet {
private static void assets(final HttpServletRequest request,
final HttpServletResponse response,
final PrintWriter writer) {
String fileName = "assets/sample/" + FileUtility.getFileName(request.getParameter("name"));
String fileName = "assets/document-templates/sample/" + FileUtility.getFileName(request.getParameter("name"));
URL fileUrl = Thread.currentThread().getContextClassLoader().getResource(fileName);
Path filePath = null;
try {
@ -728,6 +734,97 @@ public class IndexServlet extends HttpServlet {
}
}
private static void restore(final HttpServletRequest request,
final HttpServletResponse response,
final PrintWriter writer) {
try {
Scanner scanner = new Scanner(request.getInputStream());
scanner.useDelimiter("\\A");
String bodyString = scanner.hasNext() ? scanner.next() : "";
scanner.close();
JSONParser parser = new JSONParser();
JSONObject body = (JSONObject) parser.parse(bodyString);
String sourceBasename = (String) body.get("fileName");
Integer version = ((Long) body.get("version")).intValue();
String userID = (String) body.get("userId");
String sourceStringFile = DocumentManager.storagePath(sourceBasename, null);
File sourceFile = new File(sourceStringFile);
Path sourcePathFile = sourceFile.toPath();
String historyDirectory = DocumentManager.historyDir(sourceStringFile);
Integer bumpedVersion = DocumentManager.getFileVersion(historyDirectory);
String bumpedVersionStringDirectory = DocumentManager.versionDir(historyDirectory, bumpedVersion);
File bumpedVersionDirectory = new File(bumpedVersionStringDirectory);
if (!bumpedVersionDirectory.exists()) {
bumpedVersionDirectory.mkdir();
}
Path bumpedKeyPathFile = Paths.get(bumpedVersionStringDirectory, "key.txt");
String bumpedKeyStringFile = bumpedKeyPathFile.toString();
File bumpedKeyFile = new File(bumpedKeyStringFile);
String bumpedKey = ServiceConverter.generateRevisionId(
DocumentManager.curUserHostAddress(null)
+ "/"
+ sourceBasename
+ "/"
+ Long.toString(sourceFile.lastModified())
);
FileWriter bumpedKeyFileWriter = new FileWriter(bumpedKeyFile);
bumpedKeyFileWriter.write(bumpedKey);
bumpedKeyFileWriter.close();
User user = Users.getUser(userID);
Path bumpedChangesPathFile = Paths.get(bumpedVersionStringDirectory, "changes.json");
String bumpedChangesStringFile = bumpedChangesPathFile.toString();
File bumpedChangesFile = new File(bumpedChangesStringFile);
JSONObject bumpedChangesUser = new JSONObject();
bumpedChangesUser.put("id", user.getId());
bumpedChangesUser.put("name", user.getName());
JSONObject bumpedChangesChangesItem = new JSONObject();
bumpedChangesChangesItem.put("created", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
bumpedChangesChangesItem.put("user", bumpedChangesUser);
JSONArray bumpedChangesChanges = new JSONArray();
bumpedChangesChanges.add(bumpedChangesChangesItem);
JSONObject bumpedChanges = new JSONObject();
bumpedChanges.put("serverVersion", null);
bumpedChanges.put("changes", bumpedChangesChanges);
String bumpedChangesContent = bumpedChanges.toJSONString();
FileWriter bumpedChangesFileWriter = new FileWriter(bumpedChangesFile);
bumpedChangesFileWriter.write(bumpedChangesContent);
bumpedChangesFileWriter.close();
String sourceExtension = FileUtility.getFileExtension(sourceBasename);
String previousBasename = "prev" + sourceExtension;
Path bumpedFile = Paths.get(bumpedVersionStringDirectory, previousBasename);
Files.move(sourcePathFile, bumpedFile);
String recoveryVersionStringDirectory = DocumentManager.versionDir(historyDirectory, version);
Path recoveryPathFile = Paths.get(recoveryVersionStringDirectory, previousBasename);
String recoveryStringFile = recoveryPathFile.toString();
FileInputStream recoveryStream = new FileInputStream(recoveryStringFile);
DocumentManager.createFile(sourcePathFile, recoveryStream);
recoveryStream.close();
JSONObject responseBody = new JSONObject();
responseBody.put("error", null);
responseBody.put("success", true);
String responseContent = responseBody.toJSONString();
writer.write(responseContent);
} catch (Exception error) {
error.printStackTrace();
JSONObject responseBody = new JSONObject();
responseBody.put("error", error.getMessage());
responseBody.put("success", false);
String responseContent = responseBody.toJSONString();
writer.write(responseContent);
}
}
// process get request
@Override
protected void doGet(final HttpServletRequest request,
@ -742,6 +839,12 @@ public class IndexServlet extends HttpServlet {
processRequest(request, response);
}
@Override
protected void doPut(final HttpServletRequest request,
final HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
}
// get servlet information
@Override
public String getServletInfo() {

View File

@ -306,7 +306,12 @@ public final class DocumentManager {
String demoName = (sample ? "sample." : "new.") + fileExt;
// get the path to the sample document
String demoPath = "assets" + File.separator + (sample ? "sample" : "new") + File.separator;
String demoPath = "assets"
+ File.separator
+ "document-templates"
+ File.separator
+ (sample ? "sample" : "new")
+ File.separator;
// get a file name with an index if the file with such a name already exists
String fileName = getCorrectName(demoName, null);

View File

@ -173,6 +173,26 @@
}
};
function onRequestRestore(event) {
const query = new URLSearchParams(window.location.search)
const payload = {
fileName: query.get('fileName'),
version: event.data.version,
userId: config.editorConfig.user.id
}
const request = new XMLHttpRequest()
request.open('PUT', 'IndexServlet?type=restore')
request.send(JSON.stringify(payload))
request.onload = function () {
if (request.status != 200) {
response = JSON.parse(request.response)
innerAlert(response.error)
return
}
document.location.reload()
}
}
config = JSON.parse('<%= FileModel.serialize(Model) %>');
config.width = "100%";
config.height = "100%";
@ -186,6 +206,7 @@
"onRequestInsertImage": onRequestInsertImage,
"onRequestCompareFile": onRequestCompareFile,
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
"onRequestRestore": onRequestRestore
};
<%

View File

@ -1,4 +1,4 @@
/**
/**
*
* (c) Copyright Ascensio System SIA 2023
*
@ -521,12 +521,14 @@ app.post('/reference', (req, res) => { // define a handler for renaming file
const data = {
fileType: fileUtility.getFileExtension(fileName).slice(1),
key: req.DocManager.getKey(fileName),
url: req.DocManager.getDownloadUrl(fileName, true),
directUrl: req.body.directUrl ? req.DocManager.getDownloadUrl(fileName) : null,
referenceData: {
fileKey: JSON.stringify({ fileName, userAddress: req.DocManager.curUserHostAddress() }),
instanceId: req.DocManager.getServerUrl(),
},
link: `${req.DocManager.getServerUrl()}/editor?fileName=${encodeURIComponent(fileName)}`,
path: fileName,
};
@ -549,13 +551,16 @@ app.put('/restore', (req, res) => { // define a handler for restore file version
const filePath = req.DocManager.storagePath(fileName, userAddress);
const historyPath = req.DocManager.historyPath(fileName, userAddress);
const newVersion = req.DocManager.countVersion(historyPath) + 1;
const versionPath = `${historyPath}\\${version}\\prev${fileUtility.getFileExtension(fileName)}`;
const newVersionPath = `${historyPath}\\${newVersion}`;
const versionPath = path.join(`${historyPath}`, `${version}`, `prev${fileUtility.getFileExtension(fileName)}`);
const newVersionPath = path.join(`${historyPath}`, `${newVersion}`);
if (fileSystem.existsSync(versionPath)) {
req.DocManager.createDirectory(newVersionPath);
req.DocManager.copyFile(filePath, `${newVersionPath}\\prev${fileUtility.getFileExtension(fileName)}`);
fileSystem.writeFileSync(`${newVersionPath}\\key.txt`, key);
req.DocManager.copyFile(
filePath,
path.join(`${newVersionPath}`, `prev${fileUtility.getFileExtension(fileName)}`),
);
fileSystem.writeFileSync(path.join(`${newVersionPath}`, 'key.txt'), key);
req.DocManager.copyFile(versionPath, filePath);
result.success = true;
} else {
@ -682,7 +687,6 @@ app.post('/track', async (req, res) => { // define a handler for tracking file c
try {
const resp = documentService.getResponseUri(data);
await callbackProcessSave(resp.uri, body, fileName, userAddress, fileName);
return;
} catch (ex) {
console.log(ex);
await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName);
@ -711,18 +715,22 @@ app.post('/track', async (req, res) => { // define a handler for tracking file c
const downloadExt = `.${body.fileType}`;
const isSubmitForm = body.forcesavetype === 3; // SubmitForm
let correctName = '';
let correctName = fileName;
let forcesavePath = '';
if (isSubmitForm) {
// new file
if (newFileName) {
correctName = req.DocManager.getCorrectName(`${fileUtility.getFileName(fileName, true)}
-form${downloadExt}`, userAddress);
correctName = req.DocManager.getCorrectName(
`${fileUtility.getFileName(fileName, true)}-form${downloadExt}`,
userAddress,
);
} else {
const ext = fileUtility.getFileExtension(fileName);
correctName = req.DocManager.getCorrectName(`${fileUtility.getFileName(fileName, true)}
-form${ext}`, userAddress);
correctName = req.DocManager.getCorrectName(
`${fileUtility.getFileName(fileName, true)}-form${ext}`,
userAddress,
);
}
forcesavePath = req.DocManager.storagePath(correctName, userAddress);
} else {
@ -778,7 +786,6 @@ app.post('/track', async (req, res) => { // define a handler for tracking file c
try {
const resp = documentService.getResponseUri(data);
await callbackProcessForceSave(resp.uri, body, fileName, userAddress, false);
return;
} catch (ex) {
console.log(ex);
await callbackProcessForceSave(downloadUri, body, fileName, userAddress, true);
@ -947,7 +954,7 @@ app.get('/editor', (req, res) => { // define a handler for editing document
if (!canEdit && mode === 'edit') {
mode = 'view';
}
const submitForm = mode === 'fillForms' && userid === 'uid-1' && !1;
const submitForm = mode === 'fillForms' && userid === 'uid-1';
// file config data
const argss = {
@ -1005,14 +1012,14 @@ app.get('/editor', (req, res) => { // define a handler for editing document
url: `${req.DocManager.getServerUrl(true)}/images/logo.png`,
directUrl: !userDirectUrl ? null : `${req.DocManager.getServerUrl()}/images/logo.png`,
},
dataCompareFile: {
dataDocument: {
fileType: 'docx',
url: `${req.DocManager.getServerUrl(true)}/assets/document-templates/sample/sample.docx`,
directUrl: !userDirectUrl
? null
: `${req.DocManager.getServerUrl()}/assets/document-templates/sample/sample.docx`,
},
dataMailMergeRecipients: {
dataSpreadsheet: {
fileType: 'csv',
url: `${req.DocManager.getServerUrl(true)}/csv`,
directUrl: !userDirectUrl ? null : `${req.DocManager.getServerUrl()}/csv`,
@ -1037,13 +1044,13 @@ app.get('/editor', (req, res) => { // define a handler for editing document
cfgSignatureSecret,
{ expiresIn: cfgSignatureSecretExpiresIn },
);
argss.dataCompareFile.token = jwt.sign(
argss.dataCompareFile,
argss.dataDocument.token = jwt.sign(
argss.dataDocument,
cfgSignatureSecret,
{ expiresIn: cfgSignatureSecretExpiresIn },
);
argss.dataMailMergeRecipients.token = jwt.sign(
argss.dataMailMergeRecipients,
argss.dataSpreadsheet.token = jwt.sign(
argss.dataSpreadsheet,
cfgSignatureSecret,
{ expiresIn: cfgSignatureSecretExpiresIn },
);

View File

@ -389,14 +389,14 @@ DocManager.prototype.getTemplateImageUrl = function getTemplateImageUrl(fileType
}
if (fileType === fileUtility.fileType.cell) { // for cell type
return `${path}/images/file_xlsx.svg`;
return `${serverUrl}/images/file_xlsx.svg`;
}
if (fileType === fileUtility.fileType.slide) { // for slide type
return `${path}/images/file_pptx.svg`;
return `${serverUrl}/images/file_pptx.svg`;
}
return `${path}/images/file_docx.svg`; // the default value
return `${serverUrl}/images/file_docx.svg`; // the default value
};
// get document key

View File

@ -90,9 +90,7 @@ fileUtility.getFillExtensions = function getFillExtensions() {
fileUtility.getConvertExtensions = function getConvertExtensions() {
return supportedFormats.filter(
(format) => (format.type === 'word' && format.convert.includes('docx'))
|| (format.type === 'cell' && format.convert.includes('xlsx'))
|| (format.type === 'slide' && format.convert.includes('pptx')),
(format) => format.actions.includes('auto-convert'),
).reduce((extensions, format) => [...extensions, format.name], []);
};

View File

@ -52,7 +52,7 @@ const descrUser1 = [
'The file favorite state is undefined',
'Can create files from templates using data from the editor',
'Can see the information about all users',
// "Can submit forms"
'Can submit forms',
];
const descrUser2 = [
@ -62,7 +62,7 @@ const descrUser2 = [
'This file is marked as favorite',
'Can create new files from the editor',
'Can see the information about users from Group2 and users who dont belong to any group',
// "Cant submit forms"
'Cant submit forms',
];
const descrUser3 = [
@ -75,7 +75,7 @@ const descrUser3 = [
'Cant print the file',
'Can create new files from the editor',
'Can see the information about Group2 users',
// "Cant submit forms"
'Cant submit forms',
];
const descrUser0 = [
@ -91,7 +91,7 @@ const descrUser0 = [
'Can\'t view chat',
'Can\'t protect file',
'View file without collaboration',
// "Cant submit forms"
'Cant submit forms',
];
const users = [

View File

@ -1,12 +1,12 @@
{
"name": "OnlineEditorsExampleNodeJS",
"version": "4.1.0",
"version": "1.6.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "OnlineEditorsExampleNodeJS",
"version": "4.1.0",
"version": "1.6.0",
"license": "Apache",
"dependencies": {
"body-parser": "^1.19.0",

View File

@ -172,18 +172,21 @@
};
var onRequestInsertImage = function(event) { // the user is trying to insert an image by clicking the Image from Storage button
docEditor.insertImage({ // insert an image into the file
"c": event.data.c,
<%- JSON.stringify(dataInsertImage).substring(1, JSON.stringify(dataInsertImage).length - 1)%>
})
var data = <%- JSON.stringify(dataInsertImage) %>;
data.c = event.data.c;
docEditor.insertImage(data); // insert an image into the file
};
var onRequestCompareFile = function() { // the user is trying to select document for comparing by clicking the Document from Storage button
docEditor.setRevisedFile(<%- JSON.stringify(dataCompareFile) %>); // select a document for comparing
var onRequestSelectDocument = function() { // the user is trying to select document by clicking the Document from Storage button
var data = <%- JSON.stringify(dataDocument) %>;
data.c = event.data.c;
docEditor.setRequestedDocument(data); // select a document
};
var onRequestMailMergeRecipients = function (event) { // the user is trying to select recipients data by clicking the Mail merge button
docEditor.setMailMergeRecipients(<%- JSON.stringify(dataMailMergeRecipients) %>); // insert recipient data for mail merge into the file
var onRequestSelectSpreadsheet = function (event) { // the user is trying to select recipients data by clicking the Mail merge button
var data = <%- JSON.stringify(dataSpreadsheet) %>;
data.c = event.data.c;
docEditor.setRequestedSpreadsheet(data); // insert recipient data for mail merge into the file
};
var onRequestUsers = function (event) {
@ -211,19 +214,43 @@
innerAlert("onRequestSendNotify: " + data);
};
var onRequestOpen = function(event) { // user open external data source
innerAlert("onRequestOpen");
var windowName = event.data.windowName;
requestReference(event.data, function (data) {
if (data.error) {
var winEditor = window.open("", windowName);
winEditor.close();
innerAlert(data.error, true);
return;
}
var link = data.link;
window.open(link, windowName);
});
};
var onRequestReferenceData = function(event) { // user refresh external data source
innerAlert("onRequestReferenceData");
innerAlert(event.data);
requestReference(event.data, function (data) {
docEditor.setReferenceData(data);
});
};
var requestReference = function(data, callback) {
innerAlert(data);
event.data.directUrl = !!config.document.directUrl;
let xhr = new XMLHttpRequest();
xhr.open("POST", "reference");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(event.data));
xhr.send(JSON.stringify(data));
xhr.onload = function () {
innerAlert(xhr.responseText);
docEditor.setReferenceData(JSON.parse(xhr.responseText));
callback(JSON.parse(xhr.responseText));
}
};
@ -239,7 +266,8 @@
let fileList = JSON.parse(xhr.responseText);
let firstXlsxName;
let file;
for (file of fileList) {
for (var i = 0; i < fileList.length; i++) {
file = fileList[i];
if (file["title"]) {
if (getFileExt(file["title"]) === "xlsx")
{
@ -319,8 +347,9 @@
"onMakeActionLink": onMakeActionLink,
"onMetaChange": onMetaChange,
"onRequestInsertImage": onRequestInsertImage,
"onRequestCompareFile": onRequestCompareFile,
"onRequestMailMergeRecipients": onRequestMailMergeRecipients,
"onRequestSelectDocument": onRequestSelectDocument,
"onRequestSelectSpreadsheet": onRequestSelectSpreadsheet,
"onRequestOpen": onRequestOpen,
};
if (<%- JSON.stringify(editor.userid) %> != null) {

View File

@ -35,3 +35,11 @@ License File: PHP_CodeSniffer.license
PHPUnit - The PHP Unit Testing framework. (https://github.com/sebastianbergmann/phpunit/blob/main/LICENSE)
License: BSD 3-Clause
License File: phpunit.license
property-access - Provides functions to read and write from/to an object or array using a simple string notation. (https://github.com/symfony/property-access/blob/6.3/LICENSE)
License: MIT
License File: property-access.license
serializer - Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON. (https://github.com/symfony/serializer/blob/6.3/LICENSE)
License: MIT
License File: serializer.license

View File

@ -0,0 +1,14 @@
FROM php:8.2.8-fpm-alpine3.18 AS example
WORKDIR /srv
COPY . .
RUN \
chown -R www-data:www-data /srv && \
apk update && \
apk add --no-cache \
composer \
make && \
make prod
CMD ["make", "server-prod"]
FROM nginx:1.23.4-alpine3.17 AS proxy
COPY proxy/nginx.conf /etc/nginx/nginx.conf

View File

@ -1,22 +1,77 @@
.DEFAULT_GOAL := help
ADDRESS := $(ADDRESS)
PORT := $(PORT)
.PHONY: help
help: # Show help message for each of the Makefile recipes.
help: # Show help message for each of the Makefile recipes.
@grep -E "^[a-z-]+: #" $(MAKEFILE_LIST) | \
awk 'BEGIN {FS = ": # "}; {printf "%s: %s\n", $$1, $$2}'
.PHONY: dev
dev: # Install development dependencies.
dev: # Install development dependencies.
@composer install
.PHONY: prod
prod: # Install production dependencies.
prod: # Install production dependencies.
@composer install --no-dev
ifeq ($(ADDRESS),)
server-dev: \
export ADDRESS := localhost
else
server-dev: \
export ADDRESS := $(ADDRESS)
endif
ifeq ($(PORT),)
server-dev: \
export PORT := 9000
else
server-dev: \
export PORT := $(PORT)
endif
.PHONY: server-dev
server-dev: # Start the development server on localhost at $PORT (default: 9000).
@php --server $(ADDRESS):$(PORT)
ifeq ($(ADDRESS),)
server-prod: \
export ADDRESS := 0.0.0.0
else
server-prod: \
export ADDRESS := $(ADDRESS)
endif
ifeq ($(PORT),)
server-prod: \
export PORT := 9000
else
server-prod: \
export PORT := $(PORT)
endif
.PHONY: server-prod
server-prod: # Start the production server on 0.0.0.0 at $PORT (default: 9000).
@php-fpm --fpm-config php-fpm.conf
.PHONY: compose-prod
compose-prod: # Up containers in a production environment.
@docker-compose build
@docker-compose up --detach
.PHONY: lint
lint: # Lint the source code for the style.
@./vendor/bin/phpcs .
lint: # Lint the source code for the style.
@./vendor/bin/phpcs src index.php
.PHONY: test
test: # Run tests recursively.
@./vendor/bin/phpunit ./**/*Tests.php
test: # Run tests recursively.
@./vendor/bin/phpunit \
--test-suffix "Tests.php" \
--display-incomplete \
--display-deprecations \
--display-errors \
--display-notices \
--display-warnings \
src

View File

@ -151,19 +151,19 @@ label .checkbox {
}
.try-editor.word {
background-image: url("images/file_docx.svg");
background-image: url("/assets/images/file_docx.svg");
}
.try-editor.cell {
background-image: url("images/file_xlsx.svg");
background-image: url("/assets/images/file_xlsx.svg");
}
.try-editor.slide {
background-image: url("images/file_pptx.svg");
background-image: url("/assets/images/file_pptx.svg");
}
.try-editor.form {
background-image: url("images/file_docxf.svg");
background-image: url("/assets/images/file_docxf.svg");
}
.side-option {
@ -235,7 +235,7 @@ label .checkbox {
}
.file-upload {
background: url("images/file_upload.svg") no-repeat 0 transparent;
background: url("/assets/images/file_upload.svg") no-repeat 0 transparent;
cursor: pointer;
display: block;
font-size: 14px;
@ -308,7 +308,7 @@ label .checkbox {
}
.error-message {
background: url("images/error.svg") no-repeat scroll 4px 10px;
background: url("/assets/images/error.svg") no-repeat scroll 4px 10px;
color: #CB0000;
display: none;
line-height: 160%;
@ -329,15 +329,15 @@ label .checkbox {
}
.current {
background-image: url("images/loader16.gif");
background-image: url("/assets/images/loader16.gif");
}
.done {
background-image: url("images/done.svg");
background-image: url("/assets/images/done.svg");
}
.error {
background-image: url("images/notdone.svg");
background-image: url("/assets/images/notdone.svg");
}
.step-descr {
@ -451,17 +451,17 @@ footer table tr td:first-child {
.stored-edit.word,
.uploadFileName.word {
background-image: url("images/icon_docx.svg");
background-image: url("/assets/images/icon_docx.svg");
}
.stored-edit.cell,
.uploadFileName.cell {
background-image: url("images/icon_xlsx.svg");
background-image: url("/assets/images/icon_xlsx.svg");
}
.stored-edit.slide,
.uploadFileName.slide {
background-image: url("images/icon_pptx.svg");
background-image: url("/assets/images/icon_pptx.svg");
}
.stored-edit span {
@ -490,7 +490,7 @@ footer table tr td:first-child {
}
.dialog-close {
background: url("images/close.svg") no-repeat scroll left top;
background: url("/assets/images/close.svg") no-repeat scroll left top;
cursor: pointer;
float: right;
font-size: 1px;
@ -766,4 +766,4 @@ html {
position: absolute;
top: 50%;
transform: translate(-50%, -50%);
}
}

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

Before

Width:  |  Height:  |  Size: 781 B

After

Width:  |  Height:  |  Size: 781 B

View File

Before

Width:  |  Height:  |  Size: 547 B

After

Width:  |  Height:  |  Size: 547 B

View File

Before

Width:  |  Height:  |  Size: 425 B

After

Width:  |  Height:  |  Size: 425 B

View File

Before

Width:  |  Height:  |  Size: 331 B

After

Width:  |  Height:  |  Size: 331 B

View File

Before

Width:  |  Height:  |  Size: 507 B

After

Width:  |  Height:  |  Size: 507 B

View File

Before

Width:  |  Height:  |  Size: 757 B

After

Width:  |  Height:  |  Size: 757 B

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 593 B

After

Width:  |  Height:  |  Size: 593 B

View File

Before

Width:  |  Height:  |  Size: 144 KiB

After

Width:  |  Height:  |  Size: 144 KiB

View File

Before

Width:  |  Height:  |  Size: 738 B

After

Width:  |  Height:  |  Size: 738 B

View File

Before

Width:  |  Height:  |  Size: 477 B

After

Width:  |  Height:  |  Size: 477 B

View File

Before

Width:  |  Height:  |  Size: 691 B

After

Width:  |  Height:  |  Size: 691 B

View File

Before

Width:  |  Height:  |  Size: 992 B

After

Width:  |  Height:  |  Size: 992 B

View File

Before

Width:  |  Height:  |  Size: 1004 B

After

Width:  |  Height:  |  Size: 1004 B

View File

Before

Width:  |  Height:  |  Size: 379 B

After

Width:  |  Height:  |  Size: 379 B

View File

Before

Width:  |  Height:  |  Size: 233 B

After

Width:  |  Height:  |  Size: 233 B

View File

Before

Width:  |  Height:  |  Size: 832 B

After

Width:  |  Height:  |  Size: 832 B

View File

Before

Width:  |  Height:  |  Size: 631 B

After

Width:  |  Height:  |  Size: 631 B

View File

Before

Width:  |  Height:  |  Size: 832 B

After

Width:  |  Height:  |  Size: 832 B

View File

Before

Width:  |  Height:  |  Size: 488 B

After

Width:  |  Height:  |  Size: 488 B

View File

Before

Width:  |  Height:  |  Size: 673 B

After

Width:  |  Height:  |  Size: 673 B

View File

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

Before

Width:  |  Height:  |  Size: 5.5 KiB

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

Before

Width:  |  Height:  |  Size: 790 B

After

Width:  |  Height:  |  Size: 790 B

View File

Before

Width:  |  Height:  |  Size: 506 B

After

Width:  |  Height:  |  Size: 506 B

View File

Before

Width:  |  Height:  |  Size: 549 B

After

Width:  |  Height:  |  Size: 549 B

View File

Before

Width:  |  Height:  |  Size: 438 B

After

Width:  |  Height:  |  Size: 438 B

View File

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

Before

Width:  |  Height:  |  Size: 8.2 KiB

After

Width:  |  Height:  |  Size: 8.2 KiB

View File

@ -125,7 +125,7 @@ if (typeof jQuery != "undefined") {
jq("#filePass").val("");
timer = setTimeout(function () {
var requestAddress = "webeditor-ajax.php?type=convert&user=" + user;
var requestAddress = "convert?user=" + user;
jq.ajax({
async: true,
@ -247,7 +247,7 @@ if (typeof jQuery != "undefined") {
jq(document).on("click", "#beginEdit:not(.disable)", function () {
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
var url = "doceditor.php?fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl;
var url = "editor?fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl;
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
@ -256,7 +256,7 @@ if (typeof jQuery != "undefined") {
jq(document).on("click", "#beginView:not(.disable)", function () {
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
var url = "doceditor.php?action=view&fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl;
var url = "editor?action=view&fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl;
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
@ -265,7 +265,7 @@ if (typeof jQuery != "undefined") {
jq(document).on("click", "#beginEmbedded:not(.disable)", function () {
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
var url = "doceditor.php?type=embedded&fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl;
var url = "editor?type=embedded&fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl;
jq("#mainProgress").addClass("embedded");
jq("#beginEmbedded").addClass("disable");
@ -297,7 +297,7 @@ if (typeof jQuery != "undefined") {
jq(document).on("click", ".delete-file", function () {
var fileName = jq(this).attr("data");
var requestAddress = "webeditor-ajax.php?type=delete&fileName=" + fileName;
var requestAddress = "delete?fileName=" + fileName;
jq.ajax({
async: true,

View File

@ -1,103 +0,0 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace OnlineEditorsExamplePhp\Common;
final class Path {
public string $separator;
public ?string $dirname;
public ?string $basename;
public ?string $extension;
public ?string $filename;
public function __construct(
string $path,
string $separator = DIRECTORY_SEPARATOR
) {
$parsed_path = pathinfo($path);
$this->separator = $separator;
$this->dirname = self::dirname($parsed_path);
$this->basename = self::basename($parsed_path);
$this->extension = self::extension($parsed_path);
$this->filename = self::filename($parsed_path);
}
private static function dirname(array $path): ?string {
return isset($path['dirname'])
? $path['dirname']
: null;
}
private static function basename(array $path): ?string {
return isset($path['basename'])
? $path['basename']
: null;
}
private static function extension(array $path): ?string {
return isset($path['extension'])
? $path['extension']
: null;
}
private static function filename(array $path): ?string {
return isset($path['filename'])
? $path['filename']
: null;
}
public function string(): string {
$parts = array();
if (!$this->dirname && !$this->basename) {
return '.';
}
if ($this->dirname === $this->separator && $this->basename) {
return "{$this->dirname}{$this->basename}";
}
if ($this->dirname !== '.') {
$parts[] = $this->dirname;
}
if ($this->basename) {
$parts[] = $this->basename;
}
return implode($this->separator, $parts);
}
public function join(string ...$paths): self {
if (!isset($paths[0])) {
return $this;
}
$next_paths = array_slice($paths, 1);
if ($paths[0] == '' || $paths[0] == '.') {
return $this->join(...$next_paths);
}
$sub = new Path($paths[0], $this->separator);
$sub_string = $sub->string();
$string = $this->string();
$separator = str_starts_with($sub_string, $this->separator)
? ''
: $this->separator;
$joined_string = "{$string}{$separator}{$sub_string}";
$joined = new Path($joined_string, $this->separator);
return $joined->join(...$next_paths);
}
}

View File

@ -1,7 +1,9 @@
{
"require": {
"ext-mbstring": "*",
"firebase/php-jwt": "^6.8.1"
"firebase/php-jwt": "^6.8.1",
"symfony/serializer": "^6.3",
"symfony/property-access": "^6.3"
},
"require-dev": {
"squizlabs/php_codesniffer": "^3.7.2",
@ -9,10 +11,12 @@
},
"autoload": {
"psr-4": {
"OnlineEditorsExamplePhp\\" : "",
"OnlineEditorsExamplePhp\\Common\\": "common/",
"OnlineEditorsExamplePhp\\Helpers\\" : "helpers/",
"OnlineEditorsExamplePhp\\Views\\" : "views/"
"Example\\Common\\": "src/common/",
"Example\\Configuration\\" : "src/configuration/",
"Example\\Format\\" : "src/format/",
"Example\\Helpers\\" : "src/helpers/",
"Example\\Proxy\\": "src/proxy/",
"Example\\Views\\" : "src/views/"
}
}
}

View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "1408ebe84361a11eb7a751e9603b937f",
"content-hash": "5d476b9c61f48836ee5e6c9cab7a1980",
"packages": [
{
"name": "firebase/php-jwt",
@ -68,6 +68,742 @@
"source": "https://github.com/firebase/php-jwt/tree/v6.8.1"
},
"time": "2023-07-14T18:33:00+00:00"
},
{
"name": "symfony/deprecation-contracts",
"version": "v3.3.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "7c3aff79d10325257a001fcf92d991f24fc967cf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf",
"reference": "7c3aff79d10325257a001fcf92d991f24fc967cf",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "3.4-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
}
},
"autoload": {
"files": [
"function.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.3.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-05-23T14:45:45+00:00"
},
{
"name": "symfony/polyfill-ctype",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-ctype.git",
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a",
"reference": "5bbc823adecdae860bb64756d639ecfec17b050a",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"provide": {
"ext-ctype": "*"
},
"suggest": {
"ext-ctype": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Ctype\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Gert de Pagter",
"email": "BackEndTea@gmail.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for ctype functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"ctype",
"polyfill",
"portable"
],
"support": {
"source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/polyfill-intl-grapheme",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-grapheme.git",
"reference": "511a08c03c1960e08a883f4cffcacd219b758354"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/511a08c03c1960e08a883f4cffcacd219b758354",
"reference": "511a08c03c1960e08a883f4cffcacd219b758354",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"suggest": {
"ext-intl": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Intl\\Grapheme\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for intl's grapheme_* functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"grapheme",
"intl",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.27.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/polyfill-intl-normalizer",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-intl-normalizer.git",
"reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/19bd1e4fcd5b91116f14d8533c57831ed00571b6",
"reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"suggest": {
"ext-intl": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Intl\\Normalizer\\": ""
},
"classmap": [
"Resources/stubs"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for intl's Normalizer class and related functions",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"intl",
"normalizer",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.27.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/polyfill-mbstring",
"version": "v1.27.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/polyfill-mbstring.git",
"reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534",
"reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"provide": {
"ext-mbstring": "*"
},
"suggest": {
"ext-mbstring": "For best performance"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "1.27-dev"
},
"thanks": {
"name": "symfony/polyfill",
"url": "https://github.com/symfony/polyfill"
}
},
"autoload": {
"files": [
"bootstrap.php"
],
"psr-4": {
"Symfony\\Polyfill\\Mbstring\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony polyfill for the Mbstring extension",
"homepage": "https://symfony.com",
"keywords": [
"compatibility",
"mbstring",
"polyfill",
"portable",
"shim"
],
"support": {
"source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2022-11-03T14:55:06+00:00"
},
{
"name": "symfony/property-access",
"version": "v6.3.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/property-access.git",
"reference": "db9358571ce63f09c439c2fee6c12e5b090b69ac"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/property-access/zipball/db9358571ce63f09c439c2fee6c12e5b090b69ac",
"reference": "db9358571ce63f09c439c2fee6c12e5b090b69ac",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/deprecation-contracts": "^2.5|^3",
"symfony/property-info": "^5.4|^6.0"
},
"require-dev": {
"symfony/cache": "^5.4|^6.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\PropertyAccess\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides functions to read and write from/to an object or array using a simple string notation",
"homepage": "https://symfony.com",
"keywords": [
"access",
"array",
"extraction",
"index",
"injection",
"object",
"property",
"property-path",
"reflection"
],
"support": {
"source": "https://github.com/symfony/property-access/tree/v6.3.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-05-19T08:06:44+00:00"
},
{
"name": "symfony/property-info",
"version": "v6.3.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/property-info.git",
"reference": "7f3a03716112269741fe2a809f8f791a371d1fcd"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/property-info/zipball/7f3a03716112269741fe2a809f8f791a371d1fcd",
"reference": "7f3a03716112269741fe2a809f8f791a371d1fcd",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/string": "^5.4|^6.0"
},
"conflict": {
"phpdocumentor/reflection-docblock": "<5.2",
"phpdocumentor/type-resolver": "<1.5.1",
"symfony/dependency-injection": "<5.4"
},
"require-dev": {
"doctrine/annotations": "^1.10.4|^2",
"phpdocumentor/reflection-docblock": "^5.2",
"phpstan/phpdoc-parser": "^1.0",
"symfony/cache": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/serializer": "^5.4|^6.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\PropertyInfo\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Kévin Dunglas",
"email": "dunglas@gmail.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Extracts information about PHP class' properties using metadata of popular sources",
"homepage": "https://symfony.com",
"keywords": [
"doctrine",
"phpdoc",
"property",
"symfony",
"type",
"validator"
],
"support": {
"source": "https://github.com/symfony/property-info/tree/v6.3.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-05-19T08:06:44+00:00"
},
{
"name": "symfony/serializer",
"version": "v6.3.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/serializer.git",
"reference": "1d238ee3180bc047f8ab713bfb73848d553f4407"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/serializer/zipball/1d238ee3180bc047f8ab713bfb73848d553f4407",
"reference": "1d238ee3180bc047f8ab713bfb73848d553f4407",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/polyfill-ctype": "~1.8"
},
"conflict": {
"doctrine/annotations": "<1.12",
"phpdocumentor/reflection-docblock": "<3.2.2",
"phpdocumentor/type-resolver": "<1.4.0",
"symfony/dependency-injection": "<5.4",
"symfony/property-access": "<5.4",
"symfony/property-info": "<5.4",
"symfony/uid": "<5.4",
"symfony/yaml": "<5.4"
},
"require-dev": {
"doctrine/annotations": "^1.12|^2",
"phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0",
"symfony/cache": "^5.4|^6.0",
"symfony/config": "^5.4|^6.0",
"symfony/console": "^5.4|^6.0",
"symfony/dependency-injection": "^5.4|^6.0",
"symfony/error-handler": "^5.4|^6.0",
"symfony/filesystem": "^5.4|^6.0",
"symfony/form": "^5.4|^6.0",
"symfony/http-foundation": "^5.4|^6.0",
"symfony/http-kernel": "^5.4|^6.0",
"symfony/mime": "^5.4|^6.0",
"symfony/property-access": "^5.4|^6.0",
"symfony/property-info": "^5.4|^6.0",
"symfony/uid": "^5.4|^6.0",
"symfony/validator": "^5.4|^6.0",
"symfony/var-dumper": "^5.4|^6.0",
"symfony/var-exporter": "^5.4|^6.0",
"symfony/yaml": "^5.4|^6.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Serializer\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/serializer/tree/v6.3.1"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-06-21T19:54:33+00:00"
},
{
"name": "symfony/string",
"version": "v6.3.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/string.git",
"reference": "f2e190ee75ff0f5eced645ec0be5c66fac81f51f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/string/zipball/f2e190ee75ff0f5eced645ec0be5c66fac81f51f",
"reference": "f2e190ee75ff0f5eced645ec0be5c66fac81f51f",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-intl-grapheme": "~1.0",
"symfony/polyfill-intl-normalizer": "~1.0",
"symfony/polyfill-mbstring": "~1.0"
},
"conflict": {
"symfony/translation-contracts": "<2.5"
},
"require-dev": {
"symfony/error-handler": "^5.4|^6.0",
"symfony/http-client": "^5.4|^6.0",
"symfony/intl": "^6.2",
"symfony/translation-contracts": "^2.5|^3.0",
"symfony/var-exporter": "^5.4|^6.0"
},
"type": "library",
"autoload": {
"files": [
"Resources/functions.php"
],
"psr-4": {
"Symfony\\Component\\String\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way",
"homepage": "https://symfony.com",
"keywords": [
"grapheme",
"i18n",
"string",
"unicode",
"utf-8",
"utf8"
],
"support": {
"source": "https://github.com/symfony/string/tree/v6.3.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-03-21T21:06:29+00:00"
}
],
"packages-dev": [

View File

@ -1,66 +0,0 @@
{
"version": "1.6.0",
"fileSizeMax": 5242880,
"storagePath": "",
"alone": false,
"docServTimeout": "120000",
"docServSiteUrl": "https://documentserver/",
"docServConverterUrl": "ConvertService.ashx",
"docServApiUrl": "web-apps/apps/api/documents/api.js",
"docServPreloaderUrl": "web-apps/apps/api/documents/cache-scripts.html",
"docServCommandUrl": "coauthoring/CommandService.ashx",
"docServJwtSecret": "",
"docServJwtHeader": "Authorization",
"docServJwtUseForRequest": true,
"docServVerifyPeerOff": true,
"exampleUrl": "",
"mobileRegex": "android|avantgo|playbook|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino",
"languages": {
"en": "English",
"hy": "Armenian",
"az": "Azerbaijani",
"eu": "Basque",
"be": "Belarusian",
"bg": "Bulgarian",
"ca": "Catalan",
"zh": "Chinese (Simplified)",
"zh-TW": "Chinese (Traditional)",
"cs": "Czech",
"da": "Danish",
"nl": "Dutch",
"fi": "Finnish",
"fr": "French",
"gl": "Galego",
"de": "German",
"el": "Greek",
"hu": "Hungarian",
"id": "Indonesian",
"it": "Italian",
"ja": "Japanese",
"ko": "Korean",
"lo": "Lao",
"lv": "Latvian",
"ms": "Malay (Malaysia)",
"no": "Norwegian",
"pl": "Polish",
"pt": "Portuguese (Brazil)",
"pt-PT": "Portuguese (Portugal)",
"ro": "Romanian",
"ru": "Russian",
"si": "Sinhala (Sri Lanka)",
"sk": "Slovak",
"sl": "Slovenian",
"es": "Spanish",
"sv": "Swedish",
"tr": "Turkish",
"uk": "Ukrainian",
"vi": "Vietnamese",
"aa-AA": "Test Language"
}
}

View File

@ -1,26 +0,0 @@
<?php
/**
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
namespace OnlineEditorsExamplePhp;
use OnlineEditorsExamplePhp\Views\DocEditorView;
require_once dirname(__FILE__) . '/functions.php';
require_once dirname(__FILE__) . '/vendor/autoload.php';
$docEditorView = new DocEditorView($_REQUEST);
$docEditorView->render();

View File

@ -0,0 +1,41 @@
version: "3.8"
services:
document-server:
container_name: document-server
image: onlyoffice/documentserver:7.3.3.50
expose:
- "80"
environment:
- JWT_SECRET=your-256-bit-secret
example:
container_name: example
build:
context: .
target: example
expose:
- "80"
volumes:
- "example:/srv"
environment:
- ADDRESS=0.0.0.0
- DOCUMENT_SERVER_PRIVATE_URL=http://proxy:8080
- DOCUMENT_SERVER_PUBLIC_URL=http://localhost:8080
- EXAMPLE_URL=http://proxy
- JWT_SECRET=your-256-bit-secret
- PORT=80
proxy:
container_name: proxy
build:
context: .
target: proxy
ports:
- "80:80"
- "8080:8080"
volumes:
- "example:/srv"
volumes:
example:

View File

@ -1,125 +0,0 @@
<?php
namespace OnlineEditorsExamplePhp\Helpers;
/**
* (c) Copyright Ascensio System SIA 2023
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class ConfigManager
{
private mixed $config;
private mixed $configFormats;
public function __construct()
{
$this->config = json_decode($this->getConfigurationJson());
$this->configFormats = json_decode($this->getConfigurationFromatsJson());
}
private function getConfigurationJson(): bool|string
{
return file_exists("./config.json") ? file_get_contents("./config.json") : false;
}
private function getConfigurationFromatsJson(): bool|string
{
return file_exists("./assets/document-formats/onlyoffice-docs-formats.json")
? file_get_contents("./assets/document-formats/onlyoffice-docs-formats.json")
: false;
}
/**
* @param string|null $configName
* @return mixed
*/
public function getConfig(string $configName = null): mixed
{
if ($configName) {
return $this->config->$configName ?? "";
}
return $this->config;
}
public function getSuppotredFormats(): mixed
{
return $this->configFormats;
}
public function getSuppotredExtensions(): mixed
{
return array_reduce(
$this->configFormats,
function ($extensions, $format) {
$extensions[] = $format->name;
return $extensions;
}
);
}
public function getViewExtensions(): mixed
{
return array_reduce(
$this->configFormats,
function ($extensions, $format) {
if (in_array("view", $format->actions)) {
$extensions[] = $format->name;
}
return $extensions;
}
);
}
public function getEditExtensions(): mixed
{
return array_reduce(
$this->configFormats,
function ($extensions, $format) {
if (in_array("edit", $format->actions) || in_array("lossy-edit", $format->actions)) {
$extensions[] = $format->name;
}
return $extensions;
}
);
}
public function getFillExtensions(): mixed
{
return array_reduce(
$this->configFormats,
function ($extensions, $format) {
if (in_array("fill", $format->actions)) {
$extensions[] = $format->name;
}
return $extensions;
}
);
}
public function getConvertExtensions(): mixed
{
return array_reduce(
$this->configFormats,
function ($extensions, $format) {
if ($format->type === "word" && in_array("docx", $format->convert)
|| $format->type === "cell" && in_array("xlsx", $format->convert)
|| $format->type === "slide" && in_array("pptx", $format->convert)) {
$extensions[] = $format->name;
}
return $extensions;
}
);
}
}

View File

@ -1,4 +1,4 @@
<?php
<?php // phpcs:ignore PSR1.Files.SideEffects.FoundWithSymbols
/**
* (c) Copyright Ascensio System SIA 2023
*
@ -15,12 +15,144 @@
* limitations under the License.
*/
namespace OnlineEditorsExamplePhp;
namespace Example;
use OnlineEditorsExamplePhp\Views\IndexView;
require_once __DIR__ . '/vendor/autoload.php';
require_once __DIR__ . '/src/ajax.php';
require_once __DIR__ . '/src/functions.php';
require_once __DIR__ . '/src/trackmanager.php';
require_once dirname(__FILE__) . '/functions.php';
require_once dirname(__FILE__) . '/vendor/autoload.php';
use Example\Common\HTTPStatus;
use Example\Common\URL;
use Example\Configuration\ConfigurationManager;
use Example\Views\DocEditorView;
use Example\Views\IndexView;
$indexView = new IndexView($_REQUEST);
$indexView->render();
function configure()
{
$configManager = new ConfigurationManager();
if ($configManager->sslVerifyPeerModeEnabled()) {
// Ignore self-signed certificate.
stream_context_set_default([
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false
]
]);
}
}
function routers()
{
// TODO: delete fallback.
// In theory, the content type of the response should be declared inside the
// router function. However, this statement isn't true for all routers, and
// it's also not true for all branches in all routers. Therefore, we are
// setting the default content type for all routers here.
header('Content-Type: application/json; charset=utf-8');
header('Cache-Control: no-cache, must-revalidate, max-age=0');
header('Expires: Wed, 11 Jan 1984 05:00:00 GMT');
header('Pragma: no-cache');
@header_remove('Last-Modified');
header('X-Content-Type-Options: nosniff');
header('X-Robots-Tag: noindex');
$url = new URL($_SERVER['REQUEST_URI']);
sendlog($url->string(), 'webedior-ajax.log');
$path = $url->path();
if (!$path || $path === '/') {
header('Content-Type: text/html; charset=utf-8');
$view = new IndexView($_REQUEST);
$view->render();
return;
}
if (str_starts_with($path, '/editor')) {
header('Content-Type: text/html; charset=utf-8');
$view = new DocEditorView($_REQUEST);
$view->render();
return;
}
if (str_starts_with($path, '/assets')) {
$response = assets();
$response['status'] = 'success';
echo json_encode($response);
return;
}
if (str_starts_with($path, '/convert')) {
$response = convert();
$response['status'] = 'success';
echo json_encode($response);
return;
}
if (str_starts_with($path, '/csv')) {
$response = csv();
$response['status'] = 'success';
echo json_encode($response);
return;
}
if (str_starts_with($path, '/delete')) {
$response = delete();
$response['status'] = isset($response['error']) ? 'error' : 'success';
echo json_encode($response);
return;
}
if (str_starts_with($path, '/download')) {
$response = download();
$response['status'] = 'success';
echo json_encode($response);
return;
}
if (str_starts_with($path, '/files')) {
$response = files();
echo json_encode($response);
return;
}
if (str_starts_with($path, '/history')) {
$response = historyDownload();
$response['status'] = 'success';
echo json_encode($response);
return;
}
if (str_starts_with($path, '/reference')) {
$response = reference();
$response['status'] = 'success';
echo json_encode($response);
return;
}
if (str_starts_with($path, '/rename')) {
$response = renamefile();
$content = json_encode($response);
echo $content;
return;
}
if (str_starts_with($path, '/restore')) {
$response = restore();
echo json_encode($response);
return;
}
if (str_starts_with($path, '/saveas')) {
$response = saveas();
$response['status'] = 'success';
echo json_encode($response);
return;
}
if (str_starts_with($path, '/track')) {
$response = track();
$response['status'] = 'success';
echo json_encode($response);
return;
}
if (str_starts_with($path, '/upload')) {
$response = upload();
$response['status'] = isset($response['error']) ? 'error' : 'success';
echo json_encode($response);
return;
}
http_response_code(HTTPStatus::NotFound->value);
}
configure();
routers();

View File

@ -35,3 +35,11 @@ License File: PHP_CodeSniffer.license
PHPUnit - The PHP Unit Testing framework. (https://github.com/sebastianbergmann/phpunit/blob/main/LICENSE)
License: BSD 3-Clause
License File: phpunit.license
property-access - Provides functions to read and write from/to an object or array using a simple string notation. (https://github.com/symfony/property-access/blob/6.3/LICENSE)
License: MIT
License File: property-access.license
serializer - Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON. (https://github.com/symfony/serializer/blob/6.3/LICENSE)
License: MIT
License File: serializer.license

View File

@ -0,0 +1,19 @@
Copyright (c) 2004-present Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,19 @@
Copyright (c) 2004-present Fabien Potencier
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,13 @@
[global]
daemonize = no
[www]
user = www-data
group = www-data
listen = ${ADDRESS}:${PORT}
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
clear_env = no

View File

@ -10,4 +10,13 @@
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
<rule ref="Squiz.NamingConventions.ValidVariableName"/>
<rule ref="Squiz.NamingConventions.ValidVariableName.PublicHasUnderscore">
<severity>0</severity>
</rule>
<rule ref="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore">
<severity>0</severity>
</rule>
</ruleset>

View File

@ -0,0 +1,47 @@
worker_processes auto;
events {
worker_connections 512;
}
http {
include /etc/nginx/mime.types;
server {
listen 80;
root /srv;
server_name localhost;
location / {
index index.html index.php;
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass example:80;
}
}
server {
listen 8080;
server_name localhost;
location / {
client_max_body_size 100m;
proxy_http_version 1.1;
proxy_pass http://document-server;
proxy_redirect off;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_x_forwarded_host;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Real-IP $remote_addr;
}
}
}

View File

@ -15,13 +15,14 @@
* limitations under the License.
*/
namespace OnlineEditorsExamplePhp;
namespace Example;
use Exception;
use OnlineEditorsExamplePhp\Common\Path;
use OnlineEditorsExamplePhp\Helpers\ConfigManager;
use OnlineEditorsExamplePhp\Helpers\ExampleUsers;
use OnlineEditorsExamplePhp\Helpers\JwtManager;
use Example\Common\Path;
use Example\Configuration\ConfigurationManager;
use Example\Format\FormatManager;
use Example\Helpers\ExampleUsers;
use Example\Helpers\JwtManager;
/**
* Check if the request is an AJAX request
@ -48,41 +49,6 @@ function getHttpOrigin()
return $origin;
}
/**
* Set headers that prevent caching in all the browsers
*
* @return void
*/
function nocacheHeaders()
{
$headers = [
'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT',
'Cache-Control' => 'no-cache, must-revalidate, max-age=0',
'Pragma' => 'no-cache',
];
$headers['Last-Modified'] = false;
unset($headers['Last-Modified']);
// In PHP 5.3+, make sure we are not sending a Last-Modified header.
if (function_exists('header_remove')) {
@header_remove('Last-Modified');
} else {
// In PHP 5.2, send an empty Last-Modified header, but only as a
// last resort to override a header already sent. #WP23021
foreach (headers_list() as $header) {
if (0 === mb_stripos($header, 'Last-Modified')) {
$headers['Last-Modified'] = '';
break;
}
}
}
foreach ($headers as $name => $field_value) {
@header("{$name}: {$field_value}");
}
}
/**
* Save copy as...
*
@ -91,12 +57,14 @@ function nocacheHeaders()
function saveas()
{
try {
$configManager = new ConfigurationManager();
$formatManager = new FormatManager();
$post = json_decode(file_get_contents('php://input'), true);
$fileurl = $post["url"];
$title = $post["title"];
$extension = mb_strtolower(pathinfo($title, PATHINFO_EXTENSION));
$configManager = new ConfigManager();
$allexts = $configManager->getSuppotredExtensions();
$allexts = $formatManager->allExtensions();
$filename = GetCorrectName($title);
if (!in_array($extension, $allexts)) {
@ -104,11 +72,10 @@ function saveas()
return $result;
}
$headers = get_headers($fileurl, 1);
$content_length = $headers["Content-Length"];
$contentLength = $headers["Content-Length"];
$data = file_get_contents(str_replace(" ", "%20", $fileurl));
if ($data === false || $content_length <= 0 || $content_length >
$configManager->getConfig("fileSizeMax")) {
if ($data === false || $contentLength <= 0 || $contentLength > $configManager->maximumFileSize()) {
$result["error"] = "File size is incorrect";
return $result;
}
@ -134,7 +101,9 @@ function saveas()
*/
function upload()
{
$configManager = new ConfigManager();
$configManager = new ConfigurationManager();
$formatManager = new FormatManager();
if ($_FILES['files']['error'] > 0) {
$result["error"] = 'Error ' . json_encode($_FILES['files']['error']);
return $result;
@ -155,13 +124,13 @@ function upload()
$ext = mb_strtolower(pathinfo($_FILES['files']['name'], PATHINFO_EXTENSION)); // get file extension
// check if the file size is correct (it should be less than the max file size, but greater than 0)
if ($filesize <= 0 || $filesize > $configManager->getConfig("fileSizeMax")) {
if ($filesize <= 0 || $filesize > $configManager->maximumFileSize()) {
$result["error"] = 'File size is incorrect'; // if not, then an error occurs
return $result;
}
// check if the file extension is supported by the editor
if (!in_array($ext, $configManager->getSuppotredExtensions())) {
if (!in_array($ext, $formatManager->allExtensions())) {
$result["error"] = 'File type is not supported'; // if not, then an error occurs
return $result;
}
@ -204,8 +173,16 @@ function track()
return $data;
}
global $_trackerStatus;
$status = $_trackerStatus[$data->status]; // get status from the request body
$trackerStatus = [
0 => 'NotFound',
1 => 'Editing',
2 => 'MustSave',
3 => 'Corrupted',
4 => 'Closed',
6 => 'MustForceSave',
7 => 'CorruptedForceSave',
];
$status = $trackerStatus[$data->status]; // get status from the request body
$userAddress = $_GET["userAddress"];
$fileName = basename($_GET["fileName"]);
@ -243,23 +220,23 @@ function track()
*/
function convert()
{
$formatManager = new FormatManager();
$post = json_decode(file_get_contents('php://input'), true);
$fileName = basename($post["filename"]);
$filePass = $post["filePass"];
$lang = $_COOKIE["ulang"] ?? "";
$extension = mb_strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
$internalExtension = "ooxml";
$configManager = new ConfigManager();
// check if the file with such an extension can be converted
if (in_array($extension, $configManager->getConvertExtensions()) &&
if (in_array($extension, $formatManager->convertibleExtensions()) &&
$internalExtension != "") {
$fileUri = $post["fileUri"];
if ($fileUri == null || $fileUri == "") {
$fileUri = serverPath(true) . '/'
. "webeditor-ajax.php"
. "?type=download"
. "&fileName=" . urlencode($fileName)
. "download"
. "?fileName=" . urlencode($fileName)
. "&userAddress=" . getClientIp();
}
$key = getDocEditorKey($fileName);
@ -364,7 +341,7 @@ function files()
function assets()
{
$fileName = basename($_GET["name"]);
$filePath = dirname(__FILE__) .
$filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "document-templates"
. DIRECTORY_SEPARATOR . "sample" . DIRECTORY_SEPARATOR . $fileName;
downloadFile($filePath);
@ -378,7 +355,7 @@ function assets()
function csv()
{
$fileName = "csv.csv";
$filePath = dirname(__FILE__) .
$filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' .
DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "document-templates"
. DIRECTORY_SEPARATOR . "sample" . DIRECTORY_SEPARATOR . $fileName;
downloadFile($filePath);
@ -392,6 +369,8 @@ function csv()
function historyDownload()
{
try {
$configManager = new ConfigurationManager();
$fileName = basename($_GET["fileName"]); // get the file name
$userAddress = $_GET["userAddress"];
@ -400,9 +379,7 @@ function historyDownload()
$jwtManager = new JwtManager();
if ($jwtManager->isJwtEnabled()) {
$configManager = new ConfigManager();
$jwtHeader = $configManager->getConfig("docServJwtHeader") == "" ?
"Authorization" : $configManager->getConfig("docServJwtHeader");
$jwtHeader = $configManager->jwtHeader();
if (!empty(apache_request_headers()[$jwtHeader])) {
$token = $jwtManager->jwtDecode(mb_substr(
apache_request_headers()[$jwtHeader],
@ -439,17 +416,15 @@ function historyDownload()
function download()
{
try {
$configManager = new ConfigManager();
$fileName = realpath($configManager->getConfig("storagePath"))
=== $configManager->getConfig("storagePath") ?
$_GET["fileName"] : basename($_GET["fileName"]); // get the file name
$configManager = new ConfigurationManager();
$fileName = $_GET["fileName"];
$userAddress = $_GET["userAddress"] ?? null;
$isEmbedded = $_GET["&dmode"] ?? null;
$jwtManager = new JwtManager();
if ($jwtManager->isJwtEnabled() && $isEmbedded == null && $userAddress) {
$jwtHeader = $configManager->getConfig("docServJwtHeader") == "" ?
"Authorization" : $configManager->getConfig("docServJwtHeader");
$jwtHeader = $configManager->jwtHeader();
if (!empty(apache_request_headers()[$jwtHeader])) {
$token = $jwtManager->jwtDecode(mb_substr(
apache_request_headers()[$jwtHeader],
@ -489,7 +464,10 @@ function downloadFile($filePath)
// write headers to the response object
@header('Content-Length: ' . filesize($filePath));
@header('Content-Disposition: attachment; filename*=UTF-8\'\'' . str_replace("+", "%20", urlencode(basename($filePath))));
@header(
'Content-Disposition: attachment; filename*=UTF-8\'\'' .
str_replace("+", "%20", urlencode(basename($filePath)))
);
@header('Content-Type: ' . mime_content_type($filePath));
@header('Access-Control-Allow-Origin: *');
@ -613,31 +591,31 @@ function restore()
$input = file_get_contents('php://input');
$body = json_decode($input);
$source_basename = $body->fileName;
$sourceBasename = $body->fileName;
$version = $body->version;
$user_id = $body->userId;
$userID = $body->userId;
$source_file = getStoragePath($source_basename);
$history_directory = getHistoryDir($source_file);
$sourceFile = getStoragePath($sourceBasename);
$historyDirectory = getHistoryDir($sourceFile);
$bumped_version = getFileVersion($history_directory);
$bumped_version_string_directory = getVersionDir($history_directory, $bumped_version);
if (!file_exists($bumped_version_string_directory)) {
mkdir($bumped_version_string_directory);
$bumpedVersion = getFileVersion($historyDirectory);
$bumpedVersionStringDirectory = getVersionDir($historyDirectory, $bumpedVersion);
if (!file_exists($bumpedVersionStringDirectory)) {
mkdir($bumpedVersionStringDirectory);
}
$bumped_version_directory = new Path($bumped_version_string_directory);
$bumpedVersionDirectory = new Path($bumpedVersionStringDirectory);
$bumped_key_file = $bumped_version_directory->join('key.txt');
$bumped_key_string_file = $bumped_key_file->string();
$bumped_key = getDocEditorKey($source_basename);
file_put_contents($bumped_key_string_file, $bumped_key, LOCK_EX);
$bumpedKeyFile = $bumpedVersionDirectory->joinPath('key.txt');
$bumpedKeyStringFile = $bumpedKeyFile->string();
$bumpedKey = getDocEditorKey($sourceBasename);
file_put_contents($bumpedKeyStringFile, $bumpedKey, LOCK_EX);
$users = new ExampleUsers();
$user = $users->getUser($user_id);
$user = $users->getUser($userID);
$bumped_changes_file = $bumped_version_directory->join('changes.json');
$bumped_changes_string_file = $bumped_changes_file->string();
$bumped_changes = [
$bumpedChangesFile = $bumpedVersionDirectory->joinPath('changes.json');
$bumpedChangesStringFile = $bumpedChangesFile->string();
$bumpedChanges = [
'serverVersion' => null,
'changes' => array(
[
@ -649,21 +627,21 @@ function restore()
]
)
];
$bumped_changes_content = json_encode($bumped_changes, JSON_PRETTY_PRINT);
file_put_contents($bumped_changes_string_file, $bumped_changes_content, LOCK_EX);
$bumpedChangesContent = json_encode($bumpedChanges, JSON_PRETTY_PRINT);
file_put_contents($bumpedChangesStringFile, $bumpedChangesContent, LOCK_EX);
$source_extension = pathinfo($source_basename, PATHINFO_EXTENSION);
$previous_basename = "prev.{$source_extension}";
$sourceExtension = pathinfo($sourceBasename, PATHINFO_EXTENSION);
$previousBasename = "prev.{$sourceExtension}";
$bumped_file = $bumped_version_directory->join($previous_basename);
$bumped_string_file = $bumped_file->string();
copy($source_file, $bumped_string_file);
$bumpedFile = $bumpedVersionDirectory->joinPath($previousBasename);
$bumpedStringFile = $bumpedFile->string();
copy($sourceFile, $bumpedStringFile);
$recovery_version_string_directory = getVersionDir($history_directory, $version);
$recovery_version_directory = new Path($recovery_version_string_directory);
$recovery_file = $recovery_version_directory->join($previous_basename);
$recovery_string_file = $recovery_file->string();
copy($recovery_string_file, $source_file);
$recoveryVersionStringDirectory = getVersionDir($historyDirectory, $version);
$recoveryVersionDirectory = new Path($recoveryVersionStringDirectory);
$recoveryFile = $recoveryVersionDirectory->joinPath($previousBasename);
$recoveryStringFile = $recoveryFile->string();
copy($recoveryStringFile, $sourceFile);
return [
'error' => null,

View File

@ -0,0 +1,23 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Common;
enum HTTPStatus: int
{
case NotFound = 404;
}

View File

@ -0,0 +1,141 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Common;
final class Path
{
private string $separator = DIRECTORY_SEPARATOR;
private string $string;
public function __construct(string $path)
{
$this->string = $path;
}
public function string(): string
{
return $this->string;
}
public function dirname(): ?string
{
$string = $this->string();
$parsed = pathinfo($string, PATHINFO_DIRNAME);
return $parsed ?: null;
}
public function basename(): ?string
{
$string = $this->string();
$parsed = pathinfo($string, PATHINFO_BASENAME);
return $parsed ?: null;
}
public function extension(): ?string
{
$string = $this->string();
$parsed = pathinfo($string, PATHINFO_EXTENSION);
return $parsed ?: null;
}
public function filename(): ?string
{
$string = $this->string();
$parsed = pathinfo($string, PATHINFO_FILENAME);
return $parsed ?: null;
}
public function normalize(): self
{
$string = $this->string();
$filtered = array();
$slugs = explode($this->separator, $string);
foreach ($slugs as $slug) {
if ($slug === '.') {
continue;
}
if ($slug === '..') {
array_pop($filtered);
continue;
}
$filtered[] = $slug;
}
$joined = implode($this->separator, $filtered);
$escapedSeparator = preg_quote($this->separator, $this->separator);
$separatorRegex = "/{$escapedSeparator}{2,}/";
$separated = preg_replace($separatorRegex, $this->separator, $joined);
return new Path($separated);
}
public function joinPath(string $path): self
{
$string = $this->string();
$separator =
str_ends_with($string, $this->separator) ||
str_starts_with($path, $this->separator)
? ''
: $this->separator;
return new Path("{$string}{$separator}{$path}");
}
public function absolute(): bool
{
$string = $this->string();
$ntRegex = '/^[A-Za-z]:\\\\/';
if (preg_match($ntRegex, $string)) {
return true;
}
$ntSeparator = '\\';
if (str_starts_with($string, $ntSeparator)) {
return true;
}
$posixSeparator = '/';
if (str_starts_with($string, $posixSeparator)) {
return true;
}
return false;
}
public function exists(): bool
{
$string = $this->string();
return file_exists($string);
}
public function contents(): string
{
$string = $this->string();
return file_get_contents($string);
}
public function directory(): bool
{
$string = $this->string();
return is_dir($string);
}
public function makeDirectory(): bool
{
$string = $this->string();
return mkdir($string);
}
}

View File

@ -0,0 +1,45 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Common\Tests;
use PHPUnit\Framework\TestCase;
use Example\Common\Path;
final class PathAbsolutePOSIXTests extends TestCase
{
public function testRecognizesAnEmptyAsANonAbsolute()
{
$path = new Path('');
$absolute = $path->absolute();
$this->assertFalse($absolute);
}
public function testRecognizesARelativeAsANonAbsolute()
{
$path = new Path('.');
$absolute = $path->absolute();
$this->assertFalse($absolute);
}
public function testRecognizesAnAbsoluteAsAnAbsolute()
{
$path = new Path('/');
$absolute = $path->absolute();
$this->assertTrue($absolute);
}
}

View File

@ -0,0 +1,94 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Common\Tests;
use PHPUnit\Framework\TestCase;
use Example\Common\Path;
final class PathJoinPOSIXTests extends TestCase
{
public function testJoinsARelativeToAnEmptyOne()
{
$path = new Path('');
$joined = $path->joinPath('srv');
$this->assertEquals($joined->dirname(), '/');
$this->assertEquals($joined->basename(), 'srv');
$this->assertEquals($joined->extension(), null);
$this->assertEquals($joined->filename(), 'srv');
}
public function testJoinsARelativeToARelativeOne()
{
$path = new Path('.');
$joined = $path->joinPath('srv');
$this->assertEquals($joined->dirname(), '.');
$this->assertEquals($joined->basename(), 'srv');
$this->assertEquals($joined->extension(), null);
$this->assertEquals($joined->filename(), 'srv');
}
public function testJoinsARelativeToAnAbsoluteOne()
{
$path = new Path('/');
$joined = $path->joinPath('srv');
$this->assertEquals($joined->dirname(), '/');
$this->assertEquals($joined->basename(), 'srv');
$this->assertEquals($joined->extension(), null);
$this->assertEquals($joined->filename(), 'srv');
}
public function testJoinsAnAbsoluteToAnEmptyOne()
{
$path = new Path('');
$joined = $path->joinPath('/srv');
$this->assertEquals($joined->dirname(), '/');
$this->assertEquals($joined->basename(), 'srv');
$this->assertEquals($joined->extension(), null);
$this->assertEquals($joined->filename(), 'srv');
}
public function testJoinsAnAbsoluteToARelativeOne()
{
$path = new Path('.');
$joined = $path->joinPath('/srv');
$this->assertEquals($joined->dirname(), '.');
$this->assertEquals($joined->basename(), 'srv');
$this->assertEquals($joined->extension(), null);
$this->assertEquals($joined->filename(), 'srv');
}
public function testJoinsAnAbsoluteToAnAbsoluteOne()
{
$path = new Path('/');
$joined = $path->joinPath('/srv');
$this->assertEquals($joined->dirname(), '/');
$this->assertEquals($joined->basename(), 'srv');
$this->assertEquals($joined->extension(), null);
$this->assertEquals($joined->filename(), 'srv');
}
public function testJoinsAnUnnormalized()
{
$path = new Path('');
$joined = $path->joinPath('../srv');
$this->assertEquals($joined->dirname(), '/..');
$this->assertEquals($joined->basename(), 'srv');
$this->assertEquals($joined->extension(), null);
$this->assertEquals($joined->filename(), 'srv');
}
}

View File

@ -0,0 +1,34 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Common\Tests;
use PHPUnit\Framework\TestCase;
use Example\Common\Path;
final class PathNormalizePOSIXTests extends TestCase
{
public function testNormalizes()
{
$path = new Path('./srv///sub/.././sub/file.docx');
$normalized = $path->normalize();
$this->assertEquals($normalized->dirname(), 'srv/sub');
$this->assertEquals($normalized->basename(), 'file.docx');
$this->assertEquals($normalized->extension(), 'docx');
$this->assertEquals($normalized->filename(), 'file');
}
}

View File

@ -0,0 +1,174 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Common\Tests;
use PHPUnit\Framework\TestCase;
use Example\Common\Path;
final class PathStringPOSIXTests extends TestCase
{
public function testGeneratesWithAnEmpty()
{
$path = new Path('');
$string = $path->string();
$this->assertEquals($string, '');
}
public function testGeneratesWithAnEmptyRelative()
{
$path = new Path('.');
$string = $path->string();
$this->assertEquals($string, '.');
}
public function testGeneratesWithAnEmptyAbsolute()
{
$path = new Path('/');
$string = $path->string();
$this->assertEquals($string, '/');
}
public function testGeneratesWithARelative()
{
$path = new Path('srv');
$string = $path->string();
$this->assertEquals($string, 'srv');
}
public function testGeneratesWithARelativeContainingADirectory()
{
$path = new Path('srv/sub');
$string = $path->string();
$this->assertEquals($string, 'srv/sub');
}
public function testGeneratesWithARelativeContainingAFile()
{
$path = new Path('srv/file.json');
$string = $path->string();
$this->assertEquals($string, 'srv/file.json');
}
public function testGeneratesWithARelativeContainingADirectoryWithAFile()
{
$path = new Path('srv/sub/file.json');
$string = $path->string();
$this->assertEquals($string, 'srv/sub/file.json');
}
public function testGeneratesWithAnUnnormalizedRelative()
{
$path = new Path('srv////sub///file.json');
$string = $path->string();
$this->assertEquals($string, 'srv////sub///file.json');
}
public function testGeneratesWithAnNormalizedRelative()
{
$path = new Path('srv////sub///file.json');
$normalized = $path->normalize();
$string = $normalized->string();
$this->assertEquals($string, 'srv/sub/file.json');
}
public function testGeneratesWithAnExplicitRelative()
{
$path = new Path('./srv');
$string = $path->string();
$this->assertEquals($string, './srv');
}
public function testGeneratesWithAnExplicitRelativeContainingADirectory()
{
$path = new Path('./srv/sub');
$string = $path->string();
$this->assertEquals($string, './srv/sub');
}
public function testGeneratesWithAnExplicitRelativeContainingAFile()
{
$path = new Path('./srv/file.json');
$string = $path->string();
$this->assertEquals($string, './srv/file.json');
}
public function testGeneratesWithAnExplicitRelativeContainingADirectoryWithAFile()
{
$path = new Path('./srv/sub/file.json');
$string = $path->string();
$this->assertEquals($string, './srv/sub/file.json');
}
public function testGeneratesWithAnExplicitUnnormalizedRelative()
{
$path = new Path('./srv////sub///file.json');
$string = $path->string();
$this->assertEquals($string, './srv////sub///file.json');
}
public function testGeneratesWithAnExplicitNormalizedRelative()
{
$path = new Path('./srv////sub///file.json');
$normalized = $path->normalize();
$string = $normalized->string();
$this->assertEquals($string, 'srv/sub/file.json');
}
public function testGeneratesWithAnAbsolute()
{
$path = new Path('/srv');
$string = $path->string();
$this->assertEquals($string, '/srv');
}
public function testGeneratesWithAnAbsoluteContainingADirectory()
{
$path = new Path('/srv/sub');
$string = $path->string();
$this->assertEquals($string, '/srv/sub');
}
public function testGeneratesWithAnAbsoluteContainingAFile()
{
$path = new Path('/srv/file.json');
$string = $path->string();
$this->assertEquals($string, '/srv/file.json');
}
public function testGeneratesWithAnAbsoluteContainingADirectoryWithAFile()
{
$path = new Path('/srv/sub/file.json');
$string = $path->string();
$this->assertEquals($string, '/srv/sub/file.json');
}
public function testGeneratesWithAnUnnormalizedAbsolute()
{
$path = new Path('/srv////sub///file.json');
$string = $path->string();
$this->assertEquals($string, '/srv////sub///file.json');
}
public function testGeneratesWithAnNormalizedAbsolute()
{
$path = new Path('/srv////sub///file.json');
$normalized = $path->normalize();
$string = $normalized->string();
$this->assertEquals($string, '/srv/sub/file.json');
}
}

View File

@ -0,0 +1,144 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Common;
final class URL
{
private string $string;
public function __construct(string $url)
{
$this->string = $url;
}
public function string(): string
{
return $this->string;
}
public function scheme(): ?string
{
$string = $this->string();
return parse_url($string, PHP_URL_SCHEME) ?: null;
}
public function host(): ?string
{
$string = $this->string();
return parse_url($string, PHP_URL_HOST) ?: null;
}
public function port(): ?int
{
$string = $this->string();
return parse_url($string, PHP_URL_PORT) ?: null;
}
public function user(): ?string
{
$string = $this->string();
return parse_url($string, PHP_URL_USER) ?: null;
}
public function pass(): ?string
{
$string = $this->string();
return parse_url($string, PHP_URL_PASS) ?: null;
}
public function path(): ?string
{
$string = $this->string();
return parse_url($string, PHP_URL_PATH) ?: null;
}
public function query(): ?string
{
$string = $this->string();
return parse_url($string, PHP_URL_QUERY) ?: null;
}
public function fragment(): ?string
{
$string = $this->string();
return parse_url($string, PHP_URL_FRAGMENT) ?: null;
}
public static function fromComponents(
?string $scheme,
?string $host,
?int $port,
?string $user,
?string $pass,
?string $path,
?string $query,
?string $fragment
): URL {
$string = '';
if ($scheme) {
$string .= "{$scheme}://";
}
if ($user) {
$string .= $user;
}
if ($pass) {
$string .= ":{$pass}@";
}
if ($host) {
$string .= $host;
}
if ($port) {
$string .= ":{$port}";
}
if ($path) {
$string .= $path;
}
if ($query) {
$string .= "?{$query}";
}
if ($fragment) {
$string .= "#{$fragment}";
}
return new URL($string);
}
public function joinPath(string $path): self
{
$currentPath = $this->path();
$separator =
$currentPath &&
(
str_ends_with($currentPath, '/') ||
str_starts_with($path, '/')
) ||
!$currentPath && str_starts_with($path, '/')
? ''
: '/';
$separated = "{$currentPath}{$separator}{$path}";
return URL::fromComponents(
$this->scheme(),
$this->host(),
$this->port(),
$this->user(),
$this->pass(),
$separated,
$this->query(),
$this->fragment()
);
}
}

View File

@ -0,0 +1,46 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Common\Tests;
use PHPUnit\Framework\TestCase;
use Example\Common\URL;
final class URLFromComponentsTests extends TestCase
{
public function testCreates()
{
$url = URL::fromComponents(
'http',
'localhost',
8080,
'user',
'password',
'/path',
'q=value',
'fragment'
);
$this->assertEquals('http', $url->scheme());
$this->assertEquals('localhost', $url->host());
$this->assertEquals(8080, $url->port());
$this->assertEquals('user', $url->user());
$this->assertEquals('password', $url->pass());
$this->assertEquals('/path', $url->path());
$this->assertEquals('q=value', $url->query());
$this->assertEquals('fragment', $url->fragment());
}
}

View File

@ -0,0 +1,80 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Common\Tests;
use PHPUnit\Framework\TestCase;
use Example\Common\URL;
final class URLJoinPathTests extends TestCase
{
public function testJoinsARelativeToAnEmptyOne()
{
$url = new URL('http://localhost');
$joined = $url->joinPath('first');
$this->assertEquals('http', $joined->scheme());
$this->assertEquals('localhost', $joined->host());
$this->assertEquals(null, $joined->port());
$this->assertEquals(null, $joined->user());
$this->assertEquals(null, $joined->pass());
$this->assertEquals('/first', $joined->path());
$this->assertEquals(null, $joined->query());
$this->assertEquals(null, $joined->fragment());
}
public function testJoinsARelative()
{
$url = new URL('http://localhost/first');
$joined = $url->joinPath('second');
$this->assertEquals('http', $joined->scheme());
$this->assertEquals('localhost', $joined->host());
$this->assertEquals(null, $joined->port());
$this->assertEquals(null, $joined->user());
$this->assertEquals(null, $joined->pass());
$this->assertEquals('/first/second', $joined->path());
$this->assertEquals(null, $joined->query());
$this->assertEquals(null, $joined->fragment());
}
public function testJoinsAnAbsoluteToAnEmptyOne()
{
$url = new URL('http://localhost');
$joined = $url->joinPath('/first');
$this->assertEquals('http', $joined->scheme());
$this->assertEquals('localhost', $joined->host());
$this->assertEquals(null, $joined->port());
$this->assertEquals(null, $joined->user());
$this->assertEquals(null, $joined->pass());
$this->assertEquals('/first', $joined->path());
$this->assertEquals(null, $joined->query());
$this->assertEquals(null, $joined->fragment());
}
public function testJoinsAnAbsolute()
{
$url = new URL('http://localhost/first');
$joined = $url->joinPath('/second');
$this->assertEquals('http', $joined->scheme());
$this->assertEquals('localhost', $joined->host());
$this->assertEquals(null, $joined->port());
$this->assertEquals(null, $joined->user());
$this->assertEquals(null, $joined->pass());
$this->assertEquals('/first/second', $joined->path());
$this->assertEquals(null, $joined->query());
$this->assertEquals(null, $joined->fragment());
}
}

View File

@ -0,0 +1,34 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Common\Tests;
use PHPUnit\Framework\TestCase;
use Example\Common\URL;
final class URLStringTests extends TestCase
{
public function testGenerates()
{
$url = new URL('http://user:password@localhost:8080/path?q=value#fragment');
$string = $url->string();
$this->assertEquals(
'http://user:password@localhost:8080/path?q=value#fragment',
$string
);
}
}

View File

@ -0,0 +1,203 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Configuration;
use Example\Common\Path;
use Example\Common\URL;
class ConfigurationManager
{
public string $version = '1.6.0';
public function exampleURL(): ?URL
{
$url = getenv('EXAMPLE_URL');
if (!$url) {
return null;
}
return new URL($url);
}
public function documentServerPublicURL(): URL
{
$url = getenv('DOCUMENT_SERVER_PUBLIC_URL') ?: 'http://document-server';
return new URL($url);
}
public function documentServerPrivateURL(): URL
{
$url = getenv('DOCUMENT_SERVER_PRIVATE_URL');
if (!$url) {
return $this->documentServerPublicURL();
}
return new URL($url);
}
public function documentServerAPIURL(): URL
{
$serverURL = $this->documentServerPublicURL();
$path = getenv('DOCUMENT_SERVER_API_PATH')
?: 'web-apps/apps/api/documents/api.js';
return $serverURL->joinPath($path);
}
public function documentServerPreloaderURL(): URL
{
$serverURL = $this->documentServerPublicURL();
$path = getenv('DOCUMENT_SERVER_PRELOADER_PATH')
?: 'web-apps/apps/api/documents/cache-scripts.html';
return $serverURL->joinPath($path);
}
public function documentServerCommandURL(): URL
{
$serverURL = $this->documentServerPrivateURL();
$path = getenv('DOCUMENT_SERVER_COMMAND_PATH')
?: 'coauthoring/CommandService.ashx';
return $serverURL->joinPath($path);
}
public function documentServerConverterURL(): URL
{
$serverURL = $this->documentServerPrivateURL();
$path = getenv('DOCUMENT_SERVER_CONVERTER_PATH')
?: 'ConvertService.ashx';
return $serverURL->joinPath($path);
}
public function jwtSecret(): string
{
return getenv('JWT_SECRET') ?: '';
}
public function jwtHeader(): string
{
return getenv('JWT_HEADER') ?: 'Authorization';
}
public function jwtUseForRequest(): bool
{
$use = getenv('JWT_USE_FOR_REQUEST');
if (!$use) {
return true;
}
return filter_var($use, FILTER_VALIDATE_BOOLEAN);
}
public function sslVerifyPeerModeEnabled(): bool
{
$enabled = getenv('SSL_VERIFY_PEER_MODE_ENABLED');
if (!$enabled) {
return false;
}
return filter_var($enabled, FILTER_VALIDATE_BOOLEAN);
}
public function storagePath(): Path
{
$storagePath = getenv('STORAGE_PATH') ?: 'storage';
$storageDirectory = new Path($storagePath);
if ($storageDirectory->absolute()) {
return $storageDirectory;
}
$storageStringDirectory = $storageDirectory->string();
$currentDirectory = new Path(__DIR__);
$directory = $currentDirectory
->joinPath('..')
->joinPath('..')
->joinPath($storageStringDirectory);
return $directory->normalize();
}
public function singleUser(): bool
{
$single = getenv('SINGLE_USER');
if (!$single) {
return false;
}
return filter_var($single, FILTER_VALIDATE_BOOLEAN);
}
public function maximumFileSize(): int
{
$size = getenv('MAXIMUM_FILE_SIZE');
if (!$size) {
return 5 * 1024 * 1024;
}
return intval($size);
}
public function conversionTimeout(): int
{
$timeout = getenv('CONVERSION_TIMEOUT');
if (!$timeout) {
return 120 * 1000;
}
return intval($timeout);
}
/**
* @return string[]
*/
public function languages(): array
{
return [
'en' => "English",
'hy' => 'Armenian',
'az' => 'Azerbaijani',
'eu' => 'Basque',
'be' => 'Belarusian',
'bg' => 'Bulgarian',
'ca' => 'Catalan',
'zh' => 'Chinese (Simplified)',
'zh-TW' => 'Chinese (Traditional)',
'cs' => 'Czech',
'da' => 'Danish',
'nl' => 'Dutch',
'fi' => 'Finnish',
'fr' => 'French',
'gl' => 'Galego',
'de' => 'German',
'el' => 'Greek',
'hu' => 'Hungarian',
'id' => 'Indonesian',
'it' => 'Italian',
'ja' => 'Japanese',
'ko' => 'Korean',
'lo' => 'Lao',
'lv' => 'Latvian',
'ms' => 'Malay (Malaysia)',
'no' => 'Norwegian',
'pl' => 'Polish',
'pt' => 'Portuguese (Brazil)',
'pt-PT' => 'Portuguese (Portugal)',
'ro' => 'Romanian',
'ru' => 'Russian',
'si' => 'Sinhala (Sri Lanka)',
'sk' => 'Slovak',
'sl' => 'Slovenian',
'es' => 'Spanish',
'sv' => 'Swedish',
'tr' => 'Turkish',
'uk' => 'Ukrainian',
'vi' => 'Vietnamese',
'aa-AA' => 'Test Language'
];
}
}

View File

@ -0,0 +1,54 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Configuration\Tests;
use PHPUnit\Framework\TestCase;
use Example\Configuration\ConfigurationManager;
final class ConfigurationManagerConversionTimeoutTests extends TestCase
{
public array $env;
public function __construct(string $name)
{
$this->env = getenv();
parent::__construct($name);
}
protected function setUp(): void
{
foreach ($this->env as $key => $value) {
putenv("{$key}={$value}");
}
}
public function testAssignsADefaultValue()
{
$configManager = new ConfigurationManager();
$timeout = $configManager->conversionTimeout();
$this->assertEquals(120_000, $timeout);
}
public function testAssignsAValueFromTheEnvironment()
{
putenv('CONVERSION_TIMEOUT=10');
$configManager = new ConfigurationManager();
$timeout = $configManager->conversionTimeout();
$this->assertEquals(10, $timeout);
}
}

View File

@ -0,0 +1,60 @@
<?php
//
// (c) Copyright Ascensio System SIA 2023
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
namespace Example\Configuration\Tests;
use PHPUnit\Framework\TestCase;
use Example\Configuration\ConfigurationManager;
final class ConfigurationManagerDocumentServerAPIURLTests extends TestCase
{
public array $env;
public function __construct(string $name)
{
$this->env = getenv();
parent::__construct($name);
}
protected function setUp(): void
{
foreach ($this->env as $key => $value) {
putenv("{$key}={$value}");
}
}
public function testAssignsADefaultValue()
{
$configManager = new ConfigurationManager();
$url = $configManager->documentServerAPIURL();
$this->assertEquals(
'http://document-server/web-apps/apps/api/documents/api.js',
$url->string()
);
}
public function testAssignsAValueFromTheEnvironment()
{
putenv('DOCUMENT_SERVER_API_PATH=/api');
$configManager = new ConfigurationManager();
$url = $configManager->documentServerAPIURL();
$this->assertEquals(
'http://document-server/api',
$url->string()
);
}
}

Some files were not shown because too many files have changed in this diff Show More