PluginProbe
E2Pdf – Export Pdf Tool for WordPress / 1.08.06
E2Pdf – Export Pdf Tool for WordPress v1.08.06
1.32.49 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 All 72 releases
e2pdf / classes / model / e2pdf-options.php

e2pdf-options.php in E2Pdf – Export Pdf Tool for WordPress 1.08.06, at classes/model/e2pdf-options.php

511 lines 23.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * E2pdf Options Helper
5 *
6 * @copyright Copyright 2017 https://e2pdf.com
7 * @license GPL v2
8 * @version 1
9 * @link https://e2pdf.com
10 * @since 0.00.01
11 */
12 if (!defined('ABSPATH')) {
13 die('Access denied.');
14 }
15
16 class Model_E2pdf_Options extends Model_E2pdf_Model {
17
18 function __construct() {
19 parent::__construct();
20 }
21
22 /**
23 * Get Options list
24 *
25 * @param bool $all - Get all options
26 * @param array $only_group - Array list of groups only to include
27 * @param array $exclude - Array list of groups to exclude
28 *
29 * @return array() - List of options
30 */
31 public static function get_options($all = true, $only_group = array(), $exclude = false) {
32
33 $helper = Helper_E2pdf_Helper::instance();
34 $extensions_options = array();
35 if ($all) {
36 $extensions_options[] = array(
37 'key' => 'e2pdf_disabled_extensions',
38 'value' => !is_array(get_option('e2pdf_disabled_extensions')) ? array() : get_option('e2pdf_disabled_extensions'),
39 );
40 } else {
41 $model_e2pdf_extension = new Model_E2pdf_Extension();
42 $extensions = $model_e2pdf_extension->extensions(false);
43 $disabled_extensions = !is_array(get_option('e2pdf_disabled_extensions')) ? array() : get_option('e2pdf_disabled_extensions');
44 foreach ($extensions as $extension) {
45 $extensions_options[] = array(
46 'name' => ucfirst($extension),
47 'key' => 'e2pdf_disabled_extensions[]',
48 'value' => in_array($extension, $disabled_extensions) ? $extension : '',
49 'checkbox_value' => $extension,
50 'placeholder' => __('Disable', 'e2pdf'),
51 'type' => 'checkbox',
52 );
53 }
54 if (isset($extensions_options['0'])) {
55 $extensions_options['0']['header'] = __('Extensions', 'e2pdf');
56 }
57 }
58
59 $options = array(
60 'static_group' => array(
61 'name' => __('Static', 'e2pdf'),
62 'options' => array(
63 array(
64 'key' => 'e2pdf_version',
65 'value' => $helper->get('version')
66 ),
67 array(
68 'key' => 'e2pdf_license',
69 'value' => get_option('e2pdf_license') === false ? false : get_option('e2pdf_license'),
70 ),
71 array(
72 'key' => 'e2pdf_email',
73 'value' => get_option('e2pdf_email') === false ? false : get_option('e2pdf_email'),
74 ),
75 array(
76 'key' => 'e2pdf_templates_screen_per_page',
77 'value' => get_option('e2pdf_templates_screen_per_page') === false ? '20' : get_option('e2pdf_templates_screen_per_page'),
78 )
79 )
80 ),
81 'common_group' => array(
82 'name' => __('Common', 'e2pdf'),
83 'options' => array(
84 array(
85 'name' => __('API Server', 'e2pdf'),
86 'key' => 'e2pdf_api',
87 'value' => apply_filters('e2pdf_api_server', 'api.e2pdf.com'),
88 'default_value' => 'api.e2pdf.com',
89 'type' => 'text',
90 'class' => '',
91 'placeholder' => 'api.e2pdf.com',
92 'readonly' => 'readonly'
93 ),
94 array(
95 'name' => __('PDF Processor', 'e2pdf'),
96 'key' => 'e2pdf_processor',
97 'value' => get_option('e2pdf_processor') === false ? '0' : get_option('e2pdf_processor'),
98 'default_value' => '0',
99 'type' => 'select',
100 'options' => array(
101 'Latest', 'Dev'
102 )
103 ),
104 array(
105 'name' => __('Cache', 'e2pdf'),
106 'key' => 'e2pdf_cache',
107 'value' => get_option('e2pdf_cache') === false ? '1' : get_option('e2pdf_cache'),
108 'default_value' => '0',
109 'type' => 'checkbox',
110 'checkbox_value' => '1',
111 'placeholder' => __('Turn on Cache', 'e2pdf'),
112 ),
113 array(
114 'name' => __('Debug', 'e2pdf'),
115 'key' => 'e2pdf_debug',
116 'value' => get_option('e2pdf_debug') === false ? '0' : get_option('e2pdf_debug'),
117 'default_value' => '0',
118 'type' => 'checkbox',
119 'checkbox_value' => '1',
120 'placeholder' => __('Turn on Debug mode', 'e2pdf'),
121 ),
122 array(
123 'name' => __('Hide warnings', 'e2pdf'),
124 'key' => 'e2pdf_hide_warnings',
125 'value' => get_option('e2pdf_hide_warnings') === false ? '0' : get_option('e2pdf_hide_warnings'),
126 'default_value' => '0',
127 'type' => 'checkbox',
128 'checkbox_value' => '1',
129 'placeholder' => __('Hide warnings', 'e2pdf'),
130 ),
131 array(
132 'name' => __('Connection Timout', 'e2pdf'),
133 'key' => 'e2pdf_connection_timeout',
134 'value' => get_option('e2pdf_connection_timeout') === false ? '300' : get_option('e2pdf_connection_timeout'),
135 'default_value' => '30',
136 'type' => 'text',
137 'class' => 'e2pdf-numbers',
138 'placeholder' => '0'
139 ),
140 array(
141 'name' => __('Memory/Time Usage', 'e2pdf'),
142 'key' => 'e2pdf_memory_time',
143 'value' => get_option('e2pdf_memory_time') === false ? '0' : get_option('e2pdf_memory_time'),
144 'default_value' => '0',
145 'type' => 'checkbox',
146 'checkbox_value' => '1',
147 'placeholder' => __('Show Memory/Time Usage', 'e2pdf'),
148 ),
149 array(
150 'name' => __('Developer Mode', 'e2pdf'),
151 'key' => 'e2pdf_developer',
152 'value' => get_option('e2pdf_developer') === false ? '0' : get_option('e2pdf_developer'),
153 'default_value' => '0',
154 'type' => 'checkbox',
155 'checkbox_value' => '1',
156 'placeholder' => __('Turn on Developer mode', 'e2pdf'),
157 ),
158 array(
159 'name' => __('Developer IPs', 'e2pdf'),
160 'key' => 'e2pdf_developer_ips',
161 'value' => get_option('e2pdf_developer_ips') === false ? '' : get_option('e2pdf_developer_ips'),
162 'default_value' => '',
163 'type' => 'textarea',
164 'placeholder' => __('Developer IPs', 'e2pdf'),
165 )
166 )
167 ),
168 'permissions_group' => array(
169 'name' => __('Permissions', 'e2pdf'),
170 'action' => 'permissions',
171 'options' => array()
172 ),
173 'fonts_group' => array(
174 'name' => __('Fonts', 'e2pdf'),
175 'action' => 'fonts',
176 'options' => array()
177 ),
178 'adobesign_group' => array(
179 'name' => __('Adobe Sign', 'e2pdf'),
180 'action' => 'adobesign',
181 'options' => array(
182 array(
183 'name' => __('Client ID', 'e2pdf'),
184 'key' => 'e2pdf_adobesign_client_id',
185 'value' => get_option('e2pdf_adobesign_client_id') === false ? '' : get_option('e2pdf_adobesign_client_id'),
186 'default_value' => '',
187 'type' => 'text',
188 'placeholder' => ''
189 ),
190 array(
191 'name' => __('Client Secret', 'e2pdf'),
192 'key' => 'e2pdf_adobesign_client_secret',
193 'value' => get_option('e2pdf_adobesign_client_secret') === false ? '' : get_option('e2pdf_adobesign_client_secret'),
194 'default_value' => '',
195 'type' => 'text',
196 'placeholder' => ''
197 ),
198 array(
199 'name' => __('Region', 'e2pdf'),
200 'key' => 'e2pdf_adobesign_region',
201 'value' => get_option('e2pdf_adobesign_region') === false ? '' : get_option('e2pdf_adobesign_region'),
202 'default_value' => '',
203 'type' => 'text',
204 'placeholder' => __('na2', 'e2pdf')
205 ),
206 array(
207 'name' => __('Code', 'e2pdf'),
208 'key' => 'e2pdf_adobesign_code',
209 'value' => get_option('e2pdf_adobesign_code') === false ? '' : get_option('e2pdf_adobesign_code'),
210 'default_value' => '',
211 'type' => get_option('e2pdf_debug') ? 'text' : 'hidden',
212 'placeholder' => ''
213 ),
214 array(
215 'name' => __('Api Access Point', 'e2pdf'),
216 'key' => 'e2pdf_adobesign_api_access_point',
217 'value' => get_option('e2pdf_adobesign_api_access_point') === false ? '' : get_option('e2pdf_adobesign_api_access_point'),
218 'default_value' => '',
219 'type' => get_option('e2pdf_debug') ? 'text' : 'hidden',
220 'placeholder' => ''
221 ),
222 array(
223 'name' => __('Refresh Token', 'e2pdf'),
224 'key' => 'e2pdf_adobesign_refresh_token',
225 'value' => get_option('e2pdf_adobesign_refresh_token') === false ? '' : get_option('e2pdf_adobesign_refresh_token'),
226 'default_value' => '',
227 'type' => get_option('e2pdf_debug') ? 'text' : 'hidden',
228 'placeholder' => ''
229 ),
230 array(
231 'name' => __('Access Token', 'e2pdf'),
232 'key' => 'e2pdf_adobesign_access_token',
233 'value' => get_transient('e2pdf_adobesign_access_token') === false ? '' : get_transient('e2pdf_adobesign_access_token'),
234 'default_value' => '',
235 'type' => get_option('e2pdf_debug') ? 'text' : 'hidden',
236 'placeholder' => ''
237 ),
238 array(
239 'header' => __('Scopes', 'e2pdf'),
240 'name' => __('user_read', 'e2pdf'),
241 'key' => 'e2pdf_adobesign_scope_user_read',
242 'value' => get_option('e2pdf_adobesign_scope_user_read') === false ? '' : get_option('e2pdf_adobesign_scope_user_read'),
243 'default_value' => '',
244 'type' => 'select',
245 'options' => array(
246 '' => __('disabled', 'e2pdf'),
247 'self' => 'self',
248 'group' => 'group',
249 'account' => 'account'
250 )
251 ),
252 array(
253 'name' => __('user_write', 'e2pdf'),
254 'key' => 'e2pdf_adobesign_scope_user_write',
255 'value' => get_option('e2pdf_adobesign_scope_user_write') === false ? '' : get_option('e2pdf_adobesign_scope_user_write'),
256 'default_value' => '',
257 'type' => 'select',
258 'options' => array(
259 '' => __('disabled', 'e2pdf'),
260 'self' => 'self',
261 'group' => 'group',
262 'account' => 'account'
263 )
264 ),
265 array(
266 'name' => __('user_login', 'e2pdf'),
267 'key' => 'e2pdf_adobesign_scope_user_login',
268 'value' => get_option('e2pdf_adobesign_scope_user_login') === false ? '' : get_option('e2pdf_adobesign_scope_user_login'),
269 'default_value' => '',
270 'type' => 'select',
271 'options' => array(
272 '' => __('disabled', 'e2pdf'),
273 'self' => 'self',
274 'group' => 'group',
275 'account' => 'account'
276 )
277 ),
278 array(
279 'name' => __('agreement_read', 'e2pdf'),
280 'key' => 'e2pdf_adobesign_scope_agreement_read',
281 'value' => get_option('e2pdf_adobesign_scope_agreement_read') === false ? '' : get_option('e2pdf_adobesign_scope_agreement_read'),
282 'default_value' => '',
283 'type' => 'select',
284 'options' => array(
285 '' => __('disabled', 'e2pdf'),
286 'self' => 'self',
287 'group' => 'group',
288 'account' => 'account'
289 )
290 ),
291 array(
292 'name' => __('agreement_write', 'e2pdf'),
293 'key' => 'e2pdf_adobesign_scope_agreement_write',
294 'value' => get_option('e2pdf_adobesign_scope_agreement_write') === false ? '' : get_option('e2pdf_adobesign_scope_agreement_write'),
295 'default_value' => '',
296 'type' => 'select',
297 'options' => array(
298 '' => __('disabled', 'e2pdf'),
299 'self' => 'self',
300 'group' => 'group',
301 'account' => 'account'
302 )
303 ),
304 array(
305 'name' => __('agreement_send', 'e2pdf'),
306 'key' => 'e2pdf_adobesign_scope_agreement_send',
307 'value' => get_option('e2pdf_adobesign_scope_agreement_send') === false ? '' : get_option('e2pdf_adobesign_scope_agreement_send'),
308 'default_value' => '',
309 'type' => 'select',
310 'options' => array(
311 '' => __('disabled', 'e2pdf'),
312 'self' => 'self',
313 'group' => 'group',
314 'account' => 'account'
315 )
316 ),
317 array(
318 'name' => __('widget_read', 'e2pdf'),
319 'key' => 'e2pdf_adobesign_scope_widget_read',
320 'value' => get_option('e2pdf_adobesign_scope_widget_read') === false ? '' : get_option('e2pdf_adobesign_scope_widget_read'),
321 'default_value' => '',
322 'type' => 'select',
323 'options' => array(
324 '' => __('disabled', 'e2pdf'),
325 'self' => 'self',
326 'group' => 'group',
327 'account' => 'account'
328 )
329 ),
330 array(
331 'name' => __('widget_write', 'e2pdf'),
332 'key' => 'e2pdf_adobesign_scope_widget_write',
333 'value' => get_option('e2pdf_adobesign_scope_widget_write') === false ? '' : get_option('e2pdf_adobesign_scope_widget_write'),
334 'default_value' => '',
335 'type' => 'select',
336 'options' => array(
337 '' => __('disabled', 'e2pdf'),
338 'self' => 'self',
339 'group' => 'group',
340 'account' => 'account'
341 )
342 ),
343 array(
344 'name' => __('library_read', 'e2pdf'),
345 'key' => 'e2pdf_adobesign_scope_library_read',
346 'value' => get_option('e2pdf_adobesign_scope_library_read') === false ? '' : get_option('e2pdf_adobesign_scope_library_read'),
347 'default_value' => '',
348 'type' => 'select',
349 'options' => array(
350 '' => __('disabled', 'e2pdf'),
351 'self' => 'self',
352 'group' => 'group',
353 'account' => 'account'
354 )
355 ),
356 array(
357 'name' => __('library_write', 'e2pdf'),
358 'key' => 'e2pdf_adobesign_scope_library_write',
359 'value' => get_option('e2pdf_adobesign_scope_library_write') === false ? '' : get_option('e2pdf_adobesign_scope_library_write'),
360 'default_value' => '',
361 'type' => 'select',
362 'options' => array(
363 '' => __('disabled', 'e2pdf'),
364 'self' => 'self',
365 'group' => 'group',
366 'account' => 'account'
367 )
368 ),
369 array(
370 'name' => __('workflow_read', 'e2pdf'),
371 'key' => 'e2pdf_adobesign_scope_workflow_read',
372 'value' => get_option('e2pdf_adobesign_scope_workflow_read') === false ? '' : get_option('e2pdf_adobesign_scope_workflow_read'),
373 'default_value' => '',
374 'type' => 'select',
375 'options' => array(
376 '' => __('disabled', 'e2pdf'),
377 'self' => 'self',
378 'group' => 'group',
379 'account' => 'account'
380 )
381 ),
382 array(
383 'name' => __('workflow_write', 'e2pdf'),
384 'key' => 'e2pdf_adobesign_scope_workflow_write',
385 'value' => get_option('e2pdf_adobesign_scope_workflow_write') === false ? '' : get_option('e2pdf_adobesign_scope_workflow_write'),
386 'default_value' => '',
387 'type' => 'select',
388 'options' => array(
389 '' => __('disabled', 'e2pdf'),
390 'self' => 'self',
391 'group' => 'group',
392 'account' => 'account'
393 )
394 ),
395 array(
396 'name' => __('webhook_read', 'e2pdf'),
397 'key' => 'e2pdf_adobesign_scope_webhook_read',
398 'value' => get_option('e2pdf_adobesign_scope_webhook_read') === false ? '' : get_option('e2pdf_adobesign_scope_webhook_read'),
399 'default_value' => '',
400 'type' => 'select',
401 'options' => array(
402 '' => __('disabled', 'e2pdf'),
403 'self' => 'self',
404 'group' => 'group',
405 'account' => 'account'
406 )
407 ),
408 array(
409 'name' => __('webhook_write', 'e2pdf'),
410 'key' => 'e2pdf_adobesign_scope_webhook_write',
411 'value' => get_option('e2pdf_adobesign_scope_webhook_write') === false ? '' : get_option('e2pdf_adobesign_scope_webhook_write'),
412 'default_value' => '',
413 'type' => 'select',
414 'options' => array(
415 '' => __('disabled', 'e2pdf'),
416 'self' => 'self',
417 'group' => 'group',
418 'account' => 'account'
419 )
420 ),
421 array(
422 'name' => __('webhook_retention', 'e2pdf'),
423 'key' => 'e2pdf_adobesign_scope_webhook_retention',
424 'value' => get_option('e2pdf_adobesign_scope_webhook_retention') === false ? '' : get_option('e2pdf_adobesign_scope_webhook_retention'),
425 'default_value' => '',
426 'type' => 'select',
427 'options' => array(
428 '' => __('disabled', 'e2pdf'),
429 'self' => 'self',
430 'group' => 'group',
431 'account' => 'account'
432 )
433 ),
434 )
435 ),
436 'extensions_group' => array(
437 'name' => __('Extensions', 'e2pdf'),
438 'action' => 'extensions',
439 'options' => $extensions_options
440 ),
441 );
442
443 $options = apply_filters('e2pdf_model_options_get_options_options', $options);
444
445 if ($all) {
446 $opt = array();
447 foreach ($options as $group_key => $group) {
448 foreach ($group['options'] as $option_key => $option) {
449 $opt[$option['key']] = $option['value'];
450 }
451 }
452 return $opt;
453 } else {
454 foreach ($options as $group_key => $group) {
455 if ($exclude) {
456 if (in_array($group_key, $only_group)) {
457 unset($options[$group_key]);
458 }
459 } else {
460 if (!in_array($group_key, $only_group)) {
461 unset($options[$group_key]);
462 }
463 }
464 }
465
466 return $options;
467 }
468 }
469
470 /**
471 * Update Options list by group
472 *
473 * @param string $group - Group data
474 * @param array $data - Array list of options to set
475 *
476 * @return bool - true
477 */
478 public static function update_options($group = '', $data = array()) {
479 $options = self::get_options(false, array($group));
480 foreach ($options as $group_key => $group) {
481 foreach ($group['options'] as $option_key => $option_value) {
482 if (array_key_exists($option_value['key'], $data)) {
483 update_option($option_value['key'], $data[$option_value['key']]);
484 }
485 }
486 }
487 return true;
488 }
489
490 /**
491 * Get Option value
492 *
493 * @param string $key - Option key
494 *
495 * @return mixed - Option value
496 */
497 public static function get_option($key) {
498 if ($key === 'e2pdf_developer_ips') {
499 $option = get_option($key);
500 $developers = explode("\r\n", $option);
501 if (!empty($developers)) {
502 return $developers;
503 }
504 return array();
505 } else {
506 return get_option($key);
507 }
508 }
509
510 }
511