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