forked from ONLYOFFICE/onlyoffice-wordpress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
onlyoffice-wordpress.php
143 lines (128 loc) · 4.46 KB
/
onlyoffice-wordpress.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/**
* The plugin bootstrap file.
*
* @package Onlyoffice_Plugin
*
* Plugin Name: ONLYOFFICE
* Plugin URI: https://github.com/ONLYOFFICE/onlyoffice-wordpress
* Description: Add ONLYOFFICE editor on page
* Version: 1.1.0
* Requires at least: 5.7
* Requires PHP: 7.4
* Author: Ascensio System SIA
* Author URI: https://www.onlyoffice.com
* License: GNU General Public License v2.0
* License URI: https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* Text Domain: onlyoffice-plugin
* Domain Path: /languages
*/
/**
*
* (c) Copyright Ascensio System SIA 2023
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* Currently plugin version.
*/
define( 'ONLYOFFICE_PLUGIN_VERSION', '1.1.0' );
define( 'ONLYOFFICE_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
/**
* The code that runs during plugin activation.
* This action is documented in includes/class-onlyoffice-plugin-activator.php
*/
function activate_plugin_name() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-onlyoffice-plugin-activator.php';
Onlyoffice_Plugin_Activator::activate();
}
/**
* The code that runs during plugin deactivation.
* This action is documented in includes/class-onlyoffice-plugin-deactivator.php
*/
function deactivate_plugin_name() {
require_once plugin_dir_path( __FILE__ ) . 'includes/class-onlyoffice-plugin-deactivator.php';
Onlyoffice_Plugin_Deactivator::deactivate();
}
/**
* Uninstall hook.
*/
function uninstall_onlyoffice_wordpress_plugin() {
delete_option( 'onlyoffice_settings' );
delete_option( 'onlyoffice-plugin-uuid' );
delete_option( 'onlyoffice-plugin-bytes' );
}
register_activation_hook( __FILE__, 'activate_plugin_name' );
register_deactivation_hook( __FILE__, 'deactivate_plugin_name' );
register_uninstall_hook( __FILE__, 'uninstall_onlyoffice_wordpress_plugin' );
/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require plugin_dir_path( __FILE__ ) . 'includes/class-onlyoffice-plugin.php';
/**
* Begins execution of the plugin.
*
* Since everything within the plugin is registered via hooks,
* then kicking off the plugin from this point in the file does
* not affect the page life cycle.
*
* @since 1.0.0
*/
function run_plugin_name() {
$plugin = new Onlyoffice_Plugin();
$plugin->run();
}
run_plugin_name();
/**
* Data about additional ONLYOFFICE formats.
*
* @since 2.0.0
*
* @param array $mimes The array of mime types.
* @return array
*/
function onlyoffice_forms_mime_types( $mimes ) {
$mimes['oform'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.oform';
$mimes['docxf'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.docxf';
return $mimes;
}
/**
* Function for `wp_check_filetype_and_ext` filter-hook.
*
* @since 2.0.0
*
* @param array $data Values for the extension, mime type, and corrected filename.
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to $file being in a tmp directory).
*
* @return array
*/
function onlyoffice_add_allow_upload_extension_exception( $data, $file, $filename ) {
$ext = pathinfo( $filename, PATHINFO_EXTENSION );
switch ( $ext ) {
case 'oform':
$data['ext'] = 'oform';
$data['type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.oform';
break;
case 'docxf':
$data['ext'] = 'docxf';
$data['type'] = 'application/vnd.openxmlformats-officedocument.wordprocessingml.document.docxf';
break;
}
return $data;
}
add_filter( 'upload_mimes', 'onlyoffice_forms_mime_types' );
add_filter( 'wp_check_filetype_and_ext', 'onlyoffice_add_allow_upload_extension_exception', 10, 5 );