Passed
Push — master ( 6819a3...3d5b49 )
by Angel Fernando Quiroz
08:15
created

OnlyofficePlugin::installHook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 0
dl 0
loc 10
rs 10
c 1
b 0
f 0
1
<?php
2
/**
3
 * (c) Copyright Ascensio System SIA 2025.
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 *     http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
/**
19
 * Plugin class for the Onlyoffice plugin.
20
 *
21
 * @author Asensio System SIA
22
 */
23
class OnlyofficePlugin extends Plugin
24
{
25
    /**
26
     * OnlyofficePlugin name.
27
     */
28
    private string $pluginName = 'onlyoffice';
29
30
    /**
31
     * OnlyofficePlugin constructor.
32
     */
33
    protected function __construct()
34
    {
35
        parent::__construct(
36
            '1.5.0',
37
            'Asensio System SIA',
38
            [
39
                'enable_onlyoffice_plugin' => 'boolean',
40
                'document_server_url' => 'text',
41
                'jwt_secret' => 'text',
42
                'jwt_header' => 'text',
43
                'document_server_internal' => 'text',
44
                'storage_url' => 'text',
45
            ]
46
        );
47
    }
48
49
    /**
50
     * Create OnlyofficePlugin object.
51
     */
52
    public static function create(): OnlyofficePlugin
53
    {
54
        static $result = null;
55
56
        return $result ?: $result = new self();
57
    }
58
59
    /**
60
     * This method installs the plugin tables.
61
     */
62
    public function install()
63
    {
64
    }
65
66
    /**
67
     * This method drops the plugin tables.
68
     */
69
    public function uninstall()
70
    {
71
    }
72
73
    /**
74
     * Get link to plugin settings.
75
     *
76
     * @return string
77
     */
78
    public function getConfigLink()
79
    {
80
        return api_get_path(WEB_PATH).'main/admin/configure_plugin.php?name='.$this->pluginName;
81
    }
82
83
    /**
84
     * Get plugin name.
85
     *
86
     * @return string
87
     */
88
    public function getPluginName()
89
    {
90
        return $this->pluginName;
91
    }
92
93
    public static function isExtensionAllowed(string $extension): bool
94
    {
95
        $officeExtensions = [
96
            'ppt',
97
            'pptx',
98
            'odp',
99
            'xls',
100
            'xlsx',
101
            'ods',
102
            'csv',
103
            'doc',
104
            'docx',
105
            'odt',
106
            'pdf',
107
        ];
108
109
        return in_array($extension, $officeExtensions);
110
    }
111
}
112