PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.32.31
E2Pdf – Export Pdf Tool for WordPress v1.32.31
1.32.48 1.32.43 1.32.40 1.32.34 1.32.32 1.32.31 1.32.26 1.32.22 1.32.23 1.32.18 1.32.17 1.32.15 trunk 1.00.00 1.00.13 1.01.01 1.02.02 1.03.07 1.04.07 1.05.03 1.06.02 1.07.11 1.08.00 1.08.06 1.08.09 All 71 releases
e2pdf / classes / controller / e2pdf-settings.php

e2pdf-settings.php in E2Pdf – Export Pdf Tool for WordPress 1.32.31, at classes/controller/e2pdf-settings.php

407 lines 17.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf Settings Controller
5 * @copyright Copyright 2017 https://e2pdf.com
6 * @license GPLv3
7 * @version 1
8 * @link https://e2pdf.com
9 * @since 0.00.01
10 */
11 if (!defined('ABSPATH')) {
12 die('Access denied.');
13 }
14
15 class Controller_E2pdf_Settings extends Helper_E2pdf_View {
16
17 /**
18 * @url admin.php?page=e2pdf-settings
19 */
20 public function index_action() {
21 if ($this->post->get('_wpnonce')) {
22 if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_settings')) {
23 $reload = false;
24 if (
25 get_option('e2pdf_debug', '0') != $this->post->get('e2pdf_debug') ||
26 get_option('e2pdf_recovery_mode_email', '') != $this->post->get('e2pdf_recovery_mode_email') ||
27 ($this->post->get('e2pdf_debug') && get_option('e2pdf_memory_time', '0') != $this->post->get('e2pdf_debug'))
28 ) {
29 $reload = true;
30 }
31
32 $check_update = false;
33 if (get_option('e2pdf_dev_update', '0') != $this->post->get('e2pdf_dev_update')) {
34 $check_update = true;
35 }
36
37 if ($this->post->get('e2pdf_api') && $this->post->get('e2pdf_api') != get_option('e2pdf_api', 'api.e2pdf.com')) {
38 update_option('e2pdf_cached_fonts', array());
39 }
40
41 if (get_option('e2pdf_user_email', '') != $this->post->get('e2pdf_user_email')) {
42 $model_e2pdf_api = new Model_E2pdf_Api();
43 $model_e2pdf_api->set(
44 array(
45 'action' => 'common/owner',
46 'data' => array(
47 'email' => trim($this->post->get('e2pdf_user_email')),
48 ),
49 )
50 );
51 $request = $model_e2pdf_api->request();
52
53 if (isset($request['error'])) {
54 if ($request['error'] === 'incorrect_email') {
55 $request['error'] = sprintf(__('An account with that E-mail address was not found at E2Pdf.com. You can register at %s', 'e2pdf'), 'https://e2pdf.com/register');
56 }
57 $this->post->set('e2pdf_user_email', get_option('e2pdf_user_email', ''));
58 $this->add_notification('error', $request['error']);
59 }
60 }
61
62 if (get_option('e2pdf_cache', '1') !== $this->post->get('e2pdf_cache')) {
63 $this->helper->load('cache')->purge_objects_cache();
64 }
65
66 if (get_option('e2pdf_cache_fonts', '1') !== $this->post->get('e2pdf_cache_fonts')) {
67 $this->helper->load('cache')->purge_fonts_cache();
68 }
69
70 if (get_option('e2pdf_cache_pdfs', '0') !== $this->post->get('e2pdf_cache_pdfs')) {
71 $this->helper->load('cache')->purge_pdfs_cache();
72 }
73
74 Model_E2pdf_Options::update_options('common_group', $this->post->get());
75 $this->add_notification('update', __('Settings Saved', 'e2pdf'));
76
77 if ($this->post->get('e2pdf_cache_pdfs')) {
78 if (!wp_next_scheduled('e2pdf_cache_pdfs_cron')) {
79 wp_schedule_event(time(), 'hourly', 'e2pdf_cache_pdfs_cron');
80 }
81 } else {
82 wp_clear_scheduled_hook('e2pdf_cache_pdfs_cron');
83 $this->helper->load('cache')->purge_pdfs_cache();
84 }
85
86 if ($check_update) {
87 delete_site_transient('update_plugins');
88 }
89 if ($reload) {
90 $this->redirect($this->helper->get_url(array('page' => 'e2pdf-settings')));
91 }
92 } else {
93 wp_die($this->message('wp_verify_nonce_error'));
94 }
95 }
96
97 $this->view('options', Model_E2pdf_Options::get_options(false, array('common_group')));
98 $this->view('groups', $this->get_groups());
99 }
100
101 /**
102 * @url admin.php?page=e2pdf-settings&action=maintenance
103 */
104 public function maintenance_action() {
105 global $wpdb;
106 if ($this->post->get('_wpnonce')) {
107 if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_settings')) {
108 if ($this->post->get('e2pdf_purge_objects_cache')) {
109 $this->helper->load('cache')->purge_objects_cache();
110 $this->redirect(
111 $this->helper->get_url(
112 [
113 'page' => 'e2pdf-settings',
114 'action' => 'maintenance',
115 'notification' => $this->add_notification('update', __('Success', 'e2pdf')),
116 ]
117 )
118 );
119 } elseif ($this->post->get('e2pdf_purge_fonts_cache')) {
120 $this->helper->load('cache')->purge_fonts_cache();
121 $this->redirect(
122 $this->helper->get_url(
123 [
124 'page' => 'e2pdf-settings',
125 'action' => 'maintenance',
126 'notification' => $this->add_notification('update', __('Success', 'e2pdf')),
127 ]
128 )
129 );
130 } elseif ($this->post->get('e2pdf_purge_pdfs_cache')) {
131 $this->helper->load('cache')->purge_pdfs_cache();
132 $this->redirect(
133 $this->helper->get_url(
134 [
135 'page' => 'e2pdf-settings',
136 'action' => 'maintenance',
137 'notification' => $this->add_notification('update', __('Success', 'e2pdf')),
138 ]
139 )
140 );
141 } elseif ($this->post->get('e2pdf_purge_cache')) {
142 $this->helper->load('cache')->purge_cache();
143 $this->redirect(
144 $this->helper->get_url(
145 [
146 'page' => 'e2pdf-settings',
147 'action' => 'maintenance',
148 'notification' => $this->add_notification('update', __('Success', 'e2pdf')),
149 ]
150 )
151 );
152 } elseif ($this->post->get('e2pdf_db_optimize')) {
153 $db_prefix = $wpdb->prefix;
154 $this->helper->load('db')->db_optimize($db_prefix);
155 $this->redirect(
156 $this->helper->get_url(
157 [
158 'page' => 'e2pdf-settings',
159 'action' => 'maintenance',
160 'notification' => $this->add_notification('update', __('Success', 'e2pdf')),
161 ]
162 )
163 );
164 } elseif ($this->post->get('e2pdf_recovery_mode_limit')) {
165 delete_option('recovery_mode_email_last_sent');
166 $this->redirect(
167 $this->helper->get_url(
168 [
169 'page' => 'e2pdf-settings',
170 'action' => 'maintenance',
171 'notification' => $this->add_notification('update', __('Success', 'e2pdf')),
172 ]
173 )
174 );
175 }
176 } else {
177 wp_die($this->message('wp_verify_nonce_error'));
178 }
179 }
180
181 $this->view('groups', $this->get_groups());
182 }
183
184 /**
185 * @url admin.php?page=e2pdf-settings&action=fonts
186 */
187 public function fonts_action() {
188 $model_e2pdf_font = new Model_E2pdf_Font();
189 if ($this->post->get('_wpnonce')) {
190 if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_settings')) {
191 $font = $this->files->get('font');
192 $name = $font['name'];
193 $tmp = $font['tmp_name'];
194 $filename = pathinfo($name, PATHINFO_FILENAME);
195 $extension = strtolower(pathinfo($name, PATHINFO_EXTENSION));
196 $name = $filename . '.' . $extension;
197 $fonts = $model_e2pdf_font->get_fonts();
198 $font_name = false;
199 $exist = false;
200 if (in_array($extension, $model_e2pdf_font->get_allowed_extensions())) {
201 $font_name = $model_e2pdf_font->get_font_info(false, 4, $tmp);
202 if ($font_name) {
203 $exist = array_search($font_name, $fonts);
204 }
205 }
206 if (!$tmp) {
207 $this->add_notification('error', __('Choose Font file to upload', 'e2pdf'));
208 } elseif ($font['error']) {
209 $this->add_notification('error', $font['error']);
210 } elseif (!in_array($extension, $model_e2pdf_font->get_allowed_extensions())) {
211 $this->add_notification('error', sprintf(__('Only %s files allowed', 'e2pdf'), '.' . implode(', .', $model_e2pdf_font->get_allowed_extensions())));
212 } elseif (!$font_name) {
213 $this->add_notification('error', __('Invalid Type', 'e2pdf'));
214 } elseif (array_key_exists($name, $fonts) || $exist) {
215 $this->add_notification('error', __('A Font with this name already exists', 'e2pdf'));
216 } elseif (move_uploaded_file($font['tmp_name'], $this->helper->get('fonts_dir') . $name)) {
217 if (file_exists($this->helper->get('fonts_dir') . $name)) {
218 $this->add_notification('update', __('Font Uploaded', 'e2pdf'));
219 } else {
220 $this->add_notification('error', __('Something went wrong!', 'e2pdf'));
221 }
222 }
223 } else {
224 wp_die($this->message('wp_verify_nonce_error'));
225 }
226 }
227
228 $fonts = $model_e2pdf_font->get_fonts();
229
230 $this->view('fonts', $fonts);
231 $this->view('allowed_extensions', $model_e2pdf_font->get_allowed_extensions());
232 $this->view('cached_fonts', get_option('e2pdf_cached_fonts', array()));
233 $this->view('groups', $this->get_groups());
234 $this->view('upload_max_filesize', $this->helper->load('files')->get_upload_max_filesize());
235 }
236
237 /**
238 * @url admin.php?page=e2pdf-settings&action=adobesign
239 * Backward Compatibility
240 */
241 public function adobesign_action() {
242 $redirect_url = [
243 'page' => 'e2pdf-integrations',
244 'action' => 'adobesign',
245 ];
246 if ($this->get->get('code') && get_option('e2pdf_adobesign_client_id', '') && get_option('e2pdf_adobesign_client_secret', '')) {
247 $redirect_url['code'] = $this->get->get('code');
248 $redirect_url['_wpnonce'] = wp_create_nonce('e2pdf_adobe');
249 }
250 $this->redirect(
251 $this->helper->get_url(
252 $redirect_url
253 )
254 );
255 }
256
257 /**
258 * @url admin.php?page=e2pdf-settings&action=extension
259 */
260 public function extension_action() {
261 $group_key = $this->get->get('group');
262 if ($this->post->get('_wpnonce')) {
263 if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_settings')) {
264 Model_E2pdf_Options::update_options($group_key, $this->post->get());
265 $this->add_notification('update', __('Settings Saved', 'e2pdf'));
266 } else {
267 wp_die($this->message('wp_verify_nonce_error'));
268 }
269 }
270
271 $this->view('options', Model_E2pdf_Options::get_options(false, array($group_key)));
272 $this->view('groups', $this->get_groups());
273 }
274
275 /**
276 * @url admin.php?page=e2pdf-settings&action=extensions
277 */
278 public function extensions_action() {
279
280 if ($this->post->get('_wpnonce')) {
281 if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_settings')) {
282 if (!$this->post->get('e2pdf_disabled_extensions')) {
283 update_option('e2pdf_disabled_extensions', array());
284 } else {
285 update_option('e2pdf_disabled_extensions', array_filter($this->post->get('e2pdf_disabled_extensions')));
286 }
287 $this->redirect(
288 $this->helper->get_url(
289 [
290 'page' => 'e2pdf-settings',
291 'action' => 'extensions',
292 'notification' => $this->add_notification('update', __('Settings Saved', 'e2pdf')),
293 ]
294 )
295 );
296 } else {
297 wp_die($this->message('wp_verify_nonce_error'));
298 }
299 }
300 $this->view('options', Model_E2pdf_Options::get_options(false, array('extensions_group')));
301 $this->view('groups', $this->get_groups());
302 }
303
304 /**
305 * @url admin.php?page=e2pdf-settings&action=permissions
306 */
307 public function permissions_action() {
308 if ($this->post->get('_wpnonce')) {
309 if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_settings')) {
310 $permissions = $this->post->get('permissions');
311 $roles = wp_roles()->roles;
312 $caps = $this->helper->get_caps();
313 foreach ($permissions as $permission_key => $permission) {
314 $role = get_role($permission_key);
315 if ($role) {
316 foreach ($permission as $cap_key => $cap) {
317 if (isset($caps[$cap_key])) {
318 if ($cap) {
319 $role->add_cap($cap_key);
320 } else {
321 $role->remove_cap($cap_key);
322 }
323 }
324 }
325 }
326 }
327 $this->add_notification('update', __('Settings Saved', 'e2pdf'));
328 } else {
329 wp_die($this->message('wp_verify_nonce_error'));
330 }
331 }
332
333 $roles = wp_roles()->roles;
334 foreach ($roles as $role_key => $role) {
335 if (isset($role['capabilities']['manage_options']) && $role['capabilities']['manage_options']) {
336 unset($roles[$role_key]);
337 }
338 }
339
340 $this->view('groups', $this->get_groups());
341 $this->view('roles', $roles);
342 $this->view('caps', $this->helper->get_caps());
343 }
344
345 /**
346 * @url admin.php?page=e2pdf-settings&action=extensions
347 */
348 public function translation_action() {
349 if ($this->post->get('_wpnonce')) {
350 if (wp_verify_nonce($this->post->get('_wpnonce'), 'e2pdf_settings')) {
351 Model_E2pdf_Options::update_options('translation_group', $this->post->get());
352 $this->add_notification('update', __('Settings Saved', 'e2pdf'));
353 } else {
354 wp_die($this->message('wp_verify_nonce_error'));
355 }
356 }
357 $this->view('options', Model_E2pdf_Options::get_options(false, array('translation_group')));
358 $this->view('groups', $this->get_groups());
359 }
360
361 /**
362 * Get options list
363 * @return array() - Options list
364 */
365 public function get_groups() {
366 $groups = Model_E2pdf_Options::get_options(
367 false,
368 array(
369 'static_group',
370 'adobesign_group',
371 'gdrive_group',
372 'zapier_group',
373 ),
374 true
375 );
376
377 return $groups;
378 }
379
380 /**
381 * Remove font via ajax
382 * action: wp_ajax_e2pdf_delete_font
383 * function: e2pdf_delete_font
384 * @return json
385 */
386 public function ajax_delete_font() {
387 if (wp_verify_nonce($this->get->get('_wpnonce'), 'e2pdf_settings')) {
388 $font = $this->post->get('data');
389 $model_e2pdf_font = new Model_E2pdf_Font();
390 $model_e2pdf_font->delete_font($font);
391 $response = array(
392 'redirect' => $this->helper->get_url(
393 array(
394 'page' => 'e2pdf-settings',
395 'action' => 'fonts',
396 'notification' => $this->add_notification('update', __('Font Deleted', 'e2pdf')),
397 )
398 ),
399 );
400 } else {
401 $response['error'] = $this->message('wp_verify_nonce_error');
402 }
403
404 $this->json_response($response);
405 }
406 }
407