PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 2.2.0
Email Encoder – Protect Email Addresses and Phone Numbers v2.2.0
2.5.0 2.4.8 trunk 0.10 0.11 0.12 0.20 0.21 0.22 0.30 0.31 0.32 0.40 0.41 0.42 0.50 0.60 0.70 0.71 0.80 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.5 1.5.2 1.51 1.53 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7
email-encoder-bundle / core / includes / classes / class-email-encoder-bundle-settings.php
email-encoder-bundle / core / includes / classes Last commit date
class-email-encoder-bundle-ajax.php 2 years ago class-email-encoder-bundle-helpers.php 2 years ago class-email-encoder-bundle-run-admin.php 2 years ago class-email-encoder-bundle-run.php 2 years ago class-email-encoder-bundle-settings.php 2 years ago class-email-encoder-bundle-validate.php 2 years ago index.php 2 years ago
class-email-encoder-bundle-settings.php
1032 lines
1 <?php
2
3 /**
4 * Class Email_Encoder_Settings
5 *
6 * This class contains all of our important settings
7 * Here you can configure the whole plugin behavior.
8 *
9 * @since 2.0.0
10 * @package EEB
11 * @author Ironikus <info@ironikus.com>
12 */
13 class Email_Encoder_Settings{
14
15 /**
16 * Our globally used capability
17 *
18 * @var string
19 * @since 2.0.0
20 */
21 private $admin_cap;
22
23 /**
24 * The main page name
25 *
26 * @var string
27 * @since 2.0.0
28 */
29 private $page_name;
30
31 /**
32 * The page title
33 *
34 * @var string
35 * @since 2.0.0
36 */
37 private $page_title;
38
39 /**
40 * The final output buffer hook
41 *
42 * @var string
43 * @since 2.1.10
44 */
45 private $final_outout_buffer_hook;
46
47 /**
48 * The widget callback
49 *
50 * @var string
51 * @since 2.1.10
52 */
53 private $widget_callback_hook;
54
55 /**
56 * The settings key
57 *
58 * @var string
59 * @since 2.1.10
60 */
61 private $settings_key;
62
63 /**
64 * The versions key
65 *
66 * @var string
67 * @since 2.1.10
68 */
69 private $version_key;
70
71 /**
72 * The image secret key
73 *
74 * @var string
75 * @since 2.1.10
76 */
77 private $image_secret_key;
78
79 /**
80 * The @ character identifier
81 *
82 * @var string
83 * @since 2.1.10
84 */
85 private $at_identifier;
86
87 /**
88 * The previous version
89 *
90 * @var string
91 * @since 2.1.10
92 */
93 private $previous_version;
94
95 /**
96 * The hook priorities
97 *
98 * @var string
99 * @since 2.1.10
100 */
101 private $hook_priorities;
102
103 /**
104 * The safe HTML attributes (against XSS)
105 *
106 * @var string
107 * @since 2.1.10
108 */
109 private $safe_attr_html;
110
111 /**
112 * The email regex
113 *
114 * @var string
115 * @since 2.1.10
116 */
117 private $email_regex;
118
119 /**
120 * The soft (HTML) attribute regex
121 *
122 * @var string
123 * @since 2.1.10
124 */
125 private $soft_attribute_regex;
126
127 /**
128 * The available settings
129 *
130 * @var string
131 * @since 2.1.10
132 */
133 private $settings;
134
135 /**
136 * The version
137 *
138 * @var string
139 * @since 2.1.10
140 */
141 private $version;
142
143 /**
144 * The email image secret
145 *
146 * @var string
147 * @since 2.1.10
148 */
149 private $email_image_secret;
150
151 /**
152 * Email_Encoder_Settings constructor.
153 *
154 * We define all of our necessary settings in here.
155 * If you need to do plugin related changes, everything will
156 * be available in this file.
157 */
158 function __construct(){
159 $this->admin_cap = 'manage_options';
160 $this->page_name = 'email-encoder-bundle-option-page';
161 $this->page_title = EEB_NAME;
162 $this->final_outout_buffer_hook = 'final_output';
163 $this->widget_callback_hook = 'widget_output';
164 $this->template_tags = array( 'eeb_filter' => 'template_tag_eeb_filter', 'eeb_mailto' => 'template_tag_eeb_mailto' );
165 $this->settings_key = 'WP_Email_Encoder_Bundle_options';
166 $this->version_key = 'email-encoder-bundle-version';
167 $this->image_secret_key = 'email-encoder-bundle-img-key';
168 $this->at_identifier = '##eebAddIdent##';
169 $this->previous_version = null;
170 $this->hook_priorities = array(
171 'buffer_final_output' => 1000,
172 'setup_single_filter_hooks' => 100,
173 'add_custom_template_tags' => 10,
174 'load_frontend_header_styling' => 10,
175 'eeb_dynamic_sidebar_params' => 100, //deprecated but kept for compatibility
176 'filter_rss' => 100,
177 'filter_page' => 100,
178 'filter_content' => 100,
179 'first_version_init' => 100,
180 'version_update' => 100,
181 'display_email_image' => 10,
182 'callback_rss_remove_shortcodes' => 10,
183 'load_ajax_scripts_styles' => 10,
184 'load_ajax_scripts_styles_admin' => 10,
185 );
186 $this->safe_attr_html = array(
187 'p' => array(
188 'id' => array(),
189 'class' => array(),
190 'style' => array(),
191 'align' => array(),
192 'lang' => array(),
193 'dir' => array(),
194 ),
195 'div' => array(
196 'id' => array(),
197 'class' => array(),
198 'style' => array(),
199 'align' => array(),
200 'lang' => array(),
201 'dir' => array(),
202 ),
203 'span' => array(
204 'id' => array(),
205 'class' => array(),
206 'style' => array(),
207 'lang' => array(),
208 'dir' => array(),
209 ),
210 'strong' => array(),
211 'center' => array(),
212 'ul' => array(
213 'id' => array(),
214 'class' => array(),
215 'style' => array(),
216 'lang' => array(),
217 'dir' => array(),
218 ),
219 'ol' => array(
220 'id' => array(),
221 'class' => array(),
222 'style' => array(),
223 'lang' => array(),
224 'dir' => array(),
225 ),
226 'li' => array(
227 'id' => array(),
228 'class' => array(),
229 'style' => array(),
230 'lang' => array(),
231 'dir' => array(),
232 ),
233 'a' => array(
234 'id' => array(),
235 'class' => array(),
236 'style' => array(),
237 'href' => array(),
238 'title' => array(),
239 'rel' => array(),
240 'target' => array(),
241 'lang' => array(),
242 'dir' => array(),
243 ),
244 'img' => array(
245 'id' => array(),
246 'class' => array(),
247 'style' => array(),
248 'src' => array(),
249 'alt' => array(),
250 'width' => array(),
251 'height' => array(),
252 'align' => array(),
253 'title' => array(),
254 ),
255 );
256
257 //Regex
258 $this->email_regex = '([_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,}))';
259 $this->soft_attribute_regex = array(
260 'woocommerce_variation_attribute_tag' => '/data-product_variations="([^"]*)"/i',
261 'jetpack_carousel_image_attribute_tag' => '/data-image-meta="([^"]*)"/i',
262 'html_placeholder_tag' => '/placeholder="([^"]*)"/i',
263 );
264
265 //Load data
266 $this->settings = $this->load_settings();
267 $this->version = $this->load_version();
268 $this->email_image_secret = $this->load_email_image_secret();
269 }
270
271 /**
272 * ######################
273 * ###
274 * #### MAIN SETTINGS
275 * ###
276 * ######################
277 */
278
279 /**
280 * Load the settings for our admin settings page
281 *
282 * @return array - An array with all available settings and filled values
283 */
284 private function load_settings(){
285 $fields = array(
286
287 'protect' => array(
288 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
289 'id' => 'protect',
290 'type' => 'multi-input',
291 'input-type' => 'radio',
292 'title' => __( 'Protect emails', 'email-encoder-bundle' ),
293 'inputs' => array(
294 1 => array(
295 'label' => __( 'Full-page scan', 'email-encoder-bundle' ),
296 'description' => __('This will check the whole page against any mails and secures them.', 'email-encoder-bundle' )
297 ),
298 2 => array(
299 'label' => __( 'Wordpress filters', 'email-encoder-bundle' ),
300 'description' => __('Secure only mails that occur within WordPress filters. (Not recommended)', 'email-encoder-bundle' ),
301 'advanced' => true,
302 ),
303 3 => array(
304 'label' => __( 'Don\'t do anything.', 'email-encoder-bundle' ),
305 'description' => __('This turns off the protection for emails. (Not recommended)', 'email-encoder-bundle')
306 ),
307 ),
308 'required' => false
309 ),
310
311 'protect_using' => array(
312 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
313 'id' => 'protect_using',
314 'type' => 'multi-input',
315 'input-type' => 'radio',
316 'title' => __( 'Protect emails using', 'email-encoder-bundle' ),
317 'inputs' => array(
318 'with_javascript' => array(
319 'label' => __( 'automatically the best method (including javascript)', 'email-encoder-bundle' )
320 ),
321 'without_javascript' => array(
322 'label' => __( 'automatically the best method (excluding javascript)', 'email-encoder-bundle' ),
323 ),
324 'strong_method' => array(
325 'label' => __( 'a strong method that replaces all emails with a "*protection text*".', 'email-encoder-bundle' ),
326 'description' => __('You can configure the protection text within the advanced settings.', 'email-encoder-bundle')
327 ),
328 'char_encode' => array(
329 'label' => __( 'simple HTML character encoding.', 'email-encoder-bundle' ),
330 'description' => __('Offers good (but not the best) protection, which saves you in most scenarios.', 'email-encoder-bundle')
331 ),
332 ),
333 'required' => false
334 ),
335
336 'filter_body' => array(
337 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
338 'id' => 'filter_body',
339 'type' => 'multi-input',
340 'input-type' => 'checkbox',
341 'advanced' => true,
342 'title' => __( 'Protect...', 'email-encoder-bundle' ),
343 'label' => __( 'Customize what this plugin protects.', 'email-encoder-bundle' ),
344 'inputs' => array(
345 'filter_rss' => array(
346 'advanced' => true,
347 'label' => __( 'RSS feed', 'email-encoder-bundle' ),
348 'description' => __( 'Activating this option results in protecting the rss feed based on the given protection method.', 'email-encoder-bundle' )
349 ),
350 'ajax_requests' => array(
351 'advanced' => true,
352 'label' => __( 'Ajax requests', 'email-encoder-bundle' ),
353 'description' => __( 'By default, ajax requests can send clear emails in some situations. Activating this settings will apply encoding to ajax-relate requests.', 'email-encoder-bundle' )
354 ),
355 'admin_requests' => array(
356 'advanced' => true,
357 'label' => __( 'Admin requests', 'email-encoder-bundle' ),
358 'description' => __( 'By default, we only protect frontend requests (Everything people see on your website). Activating this setting will also protect the backend of your website (The admin area).', 'email-encoder-bundle' )
359 ),
360 'remove_shortcodes_rss' => array(
361 'advanced' => true,
362 'label' => __( 'Remove all shortcodes from the RSS feeds', 'email-encoder-bundle' ),
363 'description' => __( 'Activating this option results in protecting the rss feed based on the given protection method.', 'email-encoder-bundle' )
364 ),
365 'input_strong_protection' => array(
366 'advanced' => true,
367 'label' => __( 'input form email fields using strong protection.', 'email-encoder-bundle' ),
368 'description' => __( 'Warning: this option could conflict with certain form plugins. Test it first. (Requires javascript)', 'email-encoder-bundle' )
369 ),
370 'encode_mailtos' => array(
371 'advanced' => true,
372 'label' => __( 'plain emails by converting them to mailto links', 'email-encoder-bundle' ),
373 'description' => __( 'Plain emails will be automatically converted to mailto links where possible.', 'email-encoder-bundle' )
374 ),
375 'convert_plain_to_image' => array(
376 'advanced' => true,
377 'label' => __( 'plain emails by converting them to png images', 'email-encoder-bundle' ),
378 'description' => __( 'Plain emails will be automatically converted to png images where possible.', 'email-encoder-bundle' )
379 ),
380 'protect_shortcode_tags' => array(
381 'advanced' => true,
382 'label' => __( 'shortcode content', 'email-encoder-bundle' ),
383 'description' => __( 'Protect every shortcode content separately. (This may slows down your site)', 'email-encoder-bundle' )
384 ),
385 'filter_hook' => array(
386 'advanced' => true,
387 'label' => __( 'emails from "init" hook', 'email-encoder-bundle' ),
388 'description' => __( 'Check this option if you want to register the email filters on the "init" hook instead of the "wp" hook.', 'email-encoder-bundle' )
389 ),
390 'deactivate_rtl' => array(
391 'advanced' => true,
392 'label' => __( 'mailto links without CSS direction', 'email-encoder-bundle' ),
393 'description' => __( 'Check this option if your site does not support CSS directions.', 'email-encoder-bundle' )
394 ),
395 'no_script_tags' => array(
396 'advanced' => true,
397 'label' => __( 'no script tags', 'email-encoder-bundle' ),
398 'description' => __( 'Check this option if you face issues with encoded script tags. This will deactivate protection for script tags.', 'email-encoder-bundle' )
399 ),
400 'no_attribute_validation' => array(
401 'advanced' => true,
402 'label' => __( 'html attributes without soft encoding.', 'email-encoder-bundle' ),
403 'description' => __( 'Do not soft-filter all html attributes. This might optimizes the performance, but can break the site if other plugins use your email in attribute tags.', 'email-encoder-bundle' )
404 ),
405 ),
406 'required' => false,
407 ),
408
409 'image_settings' => array(
410 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
411 'id' => 'image_settings',
412 'type' => 'multi-input',
413 'input-type' => 'text',
414 'advanced' => true,
415 'title' => __( 'Image settings', 'email-encoder-bundle' ),
416 'label' => __( 'Customize the settings for dynamically created images.', 'email-encoder-bundle' ),
417 'inputs' => array(
418 'image_color' => array(
419 'advanced' => true,
420 'label' => __( 'Image Colors', 'email-encoder-bundle' ),
421 'description' => __( 'Please include RGB colors, comme saparated. E.g.: 0,0,255', 'email-encoder-bundle' )
422 ),
423 'image_background_color' => array(
424 'advanced' => true,
425 'label' => __( 'Image Background Colors', 'email-encoder-bundle' ),
426 'description' => __( 'Please include RGB colors, comme saparated. E.g.: 0,0,255', 'email-encoder-bundle' )
427 ),
428 'image_text_opacity' => array(
429 'advanced' => true,
430 'label' => __( 'Text Opacity', 'email-encoder-bundle' ),
431 'description' => __( 'Change the text opacity for the created images. 0 = not transparent - 127 = completely transprent', 'email-encoder-bundle' )
432 ),
433 'image_background_opacity' => array(
434 'advanced' => true,
435 'label' => __( 'Background Opacity', 'email-encoder-bundle' ),
436 'description' => __( 'Change the background opacity for the created images. 0 = not transparent - 127 = completely transprent', 'email-encoder-bundle' )
437 ),
438 'image_font_size' => array(
439 'advanced' => true,
440 'label' => __( 'Font Size', 'email-encoder-bundle' ),
441 'description' => __( 'Change the font size of the image text. Default: 4 - You can choose from 1 - 5', 'email-encoder-bundle' )
442 ),
443 'image_underline' => array(
444 'advanced' => true,
445 'label' => __( 'Text Underline', 'email-encoder-bundle' ),
446 'description' => __( 'Adds a line beneath the text to highlight it as a link. empty or 0 deactivates the border. 1 = 1px', 'email-encoder-bundle' )
447 ),
448 ),
449 'required' => false,
450 ),
451
452 'skip_posts' => array(
453 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
454 'id' => 'skip_posts',
455 'type' => 'text',
456 'advanced' => true,
457 'title' => __('Exclude post id\'s from protection', 'email-encoder-bundle'),
458 'placeholder' => '',
459 'required' => false,
460 'description' => __('By comma separating post id\'s ( e.g. 123,4535,643), you are able to exclude these posts from the logic protection.', 'email-encoder-bundle')
461 ),
462
463 'skip_query_parameters' => array(
464 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
465 'id' => 'skip_query_parameters',
466 'type' => 'text',
467 'advanced' => true,
468 'title' => __('Exclude URL parameters from protection', 'email-encoder-bundle'),
469 'placeholder' => '',
470 'required' => false,
471 'description' => __('By comma separating URL (Query) parameters ( e.g. param1,param2), you are able to exclude URLs with these parameters from the protection. URL or Query parameters are found at the end of your URL (e.g. domain.com?param1=test)', 'email-encoder-bundle')
472 ),
473
474 'protection_text' => array(
475 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
476 'id' => 'protection_text',
477 'type' => 'text',
478 'advanced' => true,
479 'title' => __('Set protection text *', 'email-encoder-bundle'),
480 'placeholder' => '',
481 'required' => false,
482 'description' => __('This text will be shown for protected email addresses and within noscript tags.', 'email-encoder-bundle')
483 ),
484
485 'class_name' => array(
486 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
487 'id' => 'class_name',
488 'type' => 'text',
489 'advanced' => true,
490 'title' => __('Additional classes', 'email-encoder-bundle'),
491 'label' => __('Add extra classes to mailto links.', 'email-encoder-bundle'),
492 'placeholder' => '',
493 'required' => false,
494 'description' => __('Leave blank for none', 'email-encoder-bundle')
495 ),
496
497 'custom_href_attr' => array(
498 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
499 'id' => 'custom_href_attr',
500 'type' => 'text',
501 'advanced' => true,
502 'title' => __('Protect custom href attributes', 'email-encoder-bundle'),
503 'label' => __('Protect href atrributes such as tel:, ftp:, file:, etc.', 'email-encoder-bundle'),
504 'placeholder' => '',
505 'required' => false,
506 'description' => __('Add the href attributes you want to protect as a comme-separated list. E.g. tel,file,ftp', 'email-encoder-bundle')
507 ),
508
509 'footer_scripts' => array(
510 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
511 'id' => 'footer_scripts',
512 'type' => 'checkbox',
513 'advanced' => true,
514 'title' => __('Load scripts in footer', 'email-encoder-bundle'),
515 'label' => __('Check this button if you want to load all frontend scripts within the footer.', 'email-encoder-bundle'),
516 'placeholder' => '',
517 'required' => false,
518 'description' => __('This forces every script to be enqueued within the footer.', 'email-encoder-bundle')
519 ),
520
521 'show_encoded_check' => array(
522 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
523 'id' => 'show_encoded_check',
524 'type' => 'checkbox',
525 'title' => __('Security Check', 'email-encoder-bundle'),
526 'label' => __('Mark emails on the site as successfully encoded', 'email-encoder-bundle') . '<i class="dashicons-before dashicons-lock" style="color:green;"></i>',
527 'placeholder' => '',
528 'required' => false,
529 'description' => __('Only visible for admin users. If your emails look broken, simply deactivate this feature. This also loads the dashicons style.', 'email-encoder-bundle')
530 ),
531
532 'own_admin_menu' => array(
533 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
534 'id' => 'own_admin_menu',
535 'type' => 'checkbox',
536 'advanced' => true,
537 'title' => __('Admin Menu', 'email-encoder-bundle'),
538 'label' => __('Show this page in the main menu item', 'email-encoder-bundle'),
539 'placeholder' => '',
540 'required' => false,
541 'description' => __('Otherwise it will be shown in "Settings"-menu.', 'email-encoder-bundle')
542 ),
543
544 'encoder_form' => array(
545 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
546 'id' => 'encoder_form',
547 'type' => 'multi-input',
548 'input-type' => 'checkbox',
549 'advanced' => true,
550 'title' => __( 'Encoder form settings', 'email-encoder-bundle' ),
551 'inputs' => array(
552 'encoder_form_frontend' => array(
553 'label' => __( 'Encoder form frontend', 'email-encoder-bundle' ),
554 'description' => __( 'Activate this to use the [eeb_form] shortcode or the PHP template function eeb_form() within the frontend.', 'email-encoder-bundle' )
555 ),
556 'powered_by' => array(
557 'label' => __( 'Show a "powered by" link on bottom of the encoder form', 'email-encoder-bundle' ),
558 ),
559 ),
560 'required' => false
561 ),
562
563 'advanced_settings' => array(
564 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
565 'id' => 'advanced_settings',
566 'type' => 'checkbox',
567 'title' => __('Advanced Settings', 'email-encoder-bundle'),
568 'label' => __('Show advanced settings for more configuration possibilities.', 'email-encoder-bundle'),
569 'placeholder' => '',
570 'required' => false,
571 'description' => __('Activate the advanced settings in case you want to customize the default logic or you want to troubleshoot the plugin.', 'email-encoder-bundle')
572 ),
573
574 );
575
576 $fields = apply_filters( 'eeb/settings/pre_filter_fields', $fields );
577
578 $default_values = array(
579 'protect' => 1,
580 'filter_rss' => 1,
581 'powered_by' => 1,
582 'protect_using' => 'with_javascript',
583 'class_name' => 'mail-link',
584 'protection_text' => '*protected email*',
585 'image_color' => '0,0,0',
586 'image_background_color'=> '0,0,0',
587 'image_text_opacity' => '0',
588 'image_underline' => '0',
589 'image_background_opacity' => '127',
590 'image_font_size' => '4',
591 );
592 $values = get_option( $this->settings_key );
593
594 if( empty( $values ) && ! is_array( $values ) ){
595 update_option( $this->settings_key, $default_values );
596 $values = $default_values;
597 }
598
599 //Bakwards compatibility
600 if( ! isset( $values['protect_using'] ) ){
601 $values['protect_using'] = 'with_javascript';
602 $values['encoder_form_frontend'] = 1;
603 }
604
605 //In case the mailto functiinality was deactivated, we will set it do "Do nothing" as well.
606 if( ! isset( $values['protect'] ) ){
607 $values['protect'] = 1;
608 }
609 ///Backwards compatibility
610
611 //Value corrections
612 if( ! isset( $values['image_color'] ) ){
613 $values['image_color'] = $default_values['image_color'];
614 }
615 $image_color = explode( ',', $values['image_color'] );
616 if( count( $image_color ) != 3 ){
617 $values['image_color'] = $default_values['image_color'];
618 }
619 foreach( explode( ',', $values['image_color'] ) as $image_color_key => $image_color_single ){
620 if( ! is_numeric( trim( $image_color_single ) ) ){
621 $values['image_color'] = $default_values['image_color'];
622 }
623 }
624
625 if( ! isset( $values['image_background_color'] ) ){
626 $values['image_background_color'] = $default_values['image_background_color'];
627 }
628 $image_background_color = explode( ',', $values['image_background_color'] );
629 if( count( $image_background_color ) != 3 ){
630 $values['image_background_color'] = $default_values['image_background_color'];
631 }
632 foreach( explode( ',', $values['image_background_color'] ) as $image_background_color_key => $image_background_color_single ){
633 if( ! is_numeric( trim( $image_background_color_single ) ) ){
634 $values['image_background_color'] = $default_values['image_background_color'];
635 }
636 }
637
638 if( ! isset( $values['image_text_opacity'] ) || ! is_numeric( $values['image_text_opacity'] ) ){
639 $values['image_text_opacity'] = $default_values['image_text_opacity'];
640 }
641 if( ! isset( $values['image_background_opacity'] ) || ! is_numeric( $values['image_background_opacity'] ) ){
642 $values['image_background_opacity'] = $default_values['image_background_opacity'];
643 }
644 if( ! isset( $values['image_font_size'] ) || ! is_numeric( $values['image_font_size'] ) ){
645 $values['image_font_size'] = $default_values['image_font_size'];
646 }
647 ///Value corrections
648
649 foreach( $fields as $key => $field ){
650 if( $field['type'] === 'multi-input' ){
651 foreach( $field['inputs'] as $smi_key => $smi_data ){
652
653 if( $field['input-type'] === 'radio' ){
654 if( isset( $values[ $key ] ) && (string) $values[ $key ] === (string) $smi_key ){
655 $fields[ $key ]['value'] = $values[ $key ];
656 }
657 } else {
658 if( isset( $values[ $smi_key ] ) ){
659 $fields[ $key ]['inputs'][ $smi_key ]['value'] = $values[ $smi_key ];
660 }
661 }
662
663 }
664 } else {
665 if( isset( $values[ $key ] ) ){
666 $fields[ $key ]['value'] = $values[ $key ];
667 }
668 }
669 }
670
671 return apply_filters( 'eeb/settings/fields', $fields );
672 }
673
674 /**
675 * ######################
676 * ###
677 * #### VERSIONING
678 * ###
679 * ######################
680 */
681
682 public function load_version(){
683
684 $current_version = get_option( $this->get_version_key() );
685
686 if( empty( $current_version ) ){
687 $current_version = EEB_VERSION;
688 update_option( $this->get_version_key(), $current_version );
689
690 add_action( 'init', array( $this, 'first_version_init' ), $this->get_hook_priorities( 'first_version_init' ) );
691 } else {
692 if( $current_version !== EEB_VERSION ){
693 $this->previous_version = $current_version;
694 $current_version = EEB_VERSION;
695 update_option( $this->get_version_key(), $current_version );
696
697 add_action( 'init', array( $this, 'version_update' ), $this->get_hook_priorities( 'version_update' ) );
698 }
699 }
700
701 return $current_version;
702 }
703
704 public function load_email_image_secret(){
705
706 if( ! (bool) $this->get_setting( 'convert_plain_to_image', true, 'filter_body' ) ){
707 return false;
708 }
709
710 $image_descret = get_option( $this->get_image_secret_key() );
711
712 if( ! empty( $image_descret ) ){
713 return $image_descret;
714 }
715
716 $key = '';
717
718 for ($i = 0; $i < 265; $i++) {
719 $key .= chr(mt_rand(33, 126));
720 }
721
722 update_option( $this->get_image_secret_key(), $key );
723
724 return $key;
725 }
726
727 /**
728 * Fires an action after our settings key was initially set
729 * the very first time.
730 *
731 * @return void
732 */
733 public function first_version_init(){
734 do_action( 'eeb/settings/first_version_init', EEB_VERSION );
735 }
736
737 /**
738 * Fires after the version of the plugin is initially updated
739 *
740 * @return void
741 */
742 public function version_update(){
743 do_action( 'eeb/settings/version_update', EEB_VERSION, $this->previous_version );
744 }
745
746 /**
747 * ######################
748 * ###
749 * #### CALLABLE FUNCTIONS
750 * ###
751 * ######################
752 */
753
754 /**
755 * Our admin cap handler function
756 *
757 * This function handles the admin capability throughout
758 * the whole plugin.
759 *
760 * $target - With the target function you can make a more precised filtering
761 * by changing it for specific actions.
762 *
763 * @param string $target - A identifier where the call comes from
764 * @return mixed
765 */
766 public function get_admin_cap( $target = 'main' ){
767 /**
768 * Customize the globally used capability for this plugin
769 *
770 * This filter is called every time the capability is needed.
771 */
772 return apply_filters( 'eeb/settings/capability', $this->admin_cap, $target );
773 }
774
775 /**
776 * Return the page name for our admin page
777 *
778 * @return string - the page name
779 */
780 public function get_page_name(){
781 /*
782 * Filter the page name based on your needs
783 */
784 return apply_filters( 'eeb/settings/page_name', $this->page_name );
785 }
786
787 /**
788 * Return the page title for our admin page
789 *
790 * @return string - the page title
791 */
792 public function get_page_title(){
793 /*
794 * Filter the page title based on your needs.
795 */
796 return apply_filters( 'eeb/settings/page_title', $this->page_title );
797 }
798
799 /**
800 * Return the settings_key
801 *
802 * @return string - the settings key
803 */
804 public function get_settings_key(){
805 return $this->settings_key;
806 }
807
808 /**
809 * Return the version_key
810 *
811 * @return string - the version_key
812 */
813 public function get_version_key(){
814 return $this->version_key;
815 }
816
817 /**
818 * Return the image_secret_key
819 *
820 * @return string - the image_secret_key
821 */
822 public function get_image_secret_key(){
823 return $this->image_secret_key;
824 }
825
826 /**
827 * Return the email_image_secret
828 *
829 * @return string - the email_image_secret
830 */
831 public function get_email_image_secret(){
832 return $this->email_image_secret;
833 }
834
835 /**
836 * Return the version
837 *
838 * @return string - the version
839 */
840 public function get_version(){
841 return apply_filters( 'eeb/settings/get_version', $this->version );
842 }
843
844 /**
845 * Return the default template tags
846 *
847 * @return array - the template tags
848 */
849 public function get_template_tags(){
850 return apply_filters( 'eeb/settings/get_template_tags', $this->template_tags );
851 }
852
853 /**
854 * Return the widget callback hook name
855 *
856 * @return string - the final widget callback hook name
857 */
858 public function get_widget_callback_hook(){
859 return apply_filters( 'eeb/settings/widget_callback_hook', $this->widget_callback_hook );
860 }
861
862 /**
863 * Return the final output buffer hook name
864 *
865 * @return string - the final output buffer hook name
866 */
867 public function get_final_outout_buffer_hook(){
868 return apply_filters( 'eeb/settings/final_outout_buffer_hook', $this->final_outout_buffer_hook );
869 }
870
871 /**
872 * Return the @ symbol identifier
873 *
874 * @return string - the @ symbol identifier
875 */
876 public function get_at_identifier(){
877 return apply_filters( 'eeb/settings/at_identifier', $this->at_identifier );
878 }
879
880 /**
881 * @link http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/
882 * @param boolean $include
883 * @return string
884 */
885 public function get_email_regex( $include = false ){
886
887 if ($include === true) {
888 $return = $this->email_regex;
889 } else {
890 $return = '/' . $this->email_regex . '/i';
891 }
892
893 return apply_filters( 'eeb/settings/get_email_regex', $return, $include );
894 }
895
896 /**
897 * Get Woocommerce variation attribute regex
898 *
899 * @param boolean $include
900 * @return string
901 */
902 public function get_soft_attribute_regex( $single = null ){
903
904 $return = $this->soft_attribute_regex;
905
906 if( $single !== null ){
907 if( isset( $this->soft_attribute_regex[ $single ] ) ){
908 $return = $this->soft_attribute_regex[ $single ];
909 } else {
910 $return = false;
911 }
912 }
913
914 return apply_filters( 'eeb/settings/get_soft_attribute_regex', $return, $single );
915 }
916
917 /**
918 * Get hook priorities
919 *
920 * @param boolean $single - wether you want to return only a single hook priority or not
921 * @return mixed - An array or string of hook priority(-ies)
922 */
923 public function get_hook_priorities( $single = false ){
924
925 $return = $this->hook_priorities;
926 $default = false;
927
928 if( $single ){
929 if( isset( $this->hook_priorities[ $single ] ) ){
930 $return = $this->hook_priorities[ $single ];
931 } else {
932 $return = 10;
933 $default = true;
934 }
935 }
936
937 return apply_filters( 'eeb/settings/get_hook_priorities', $return, $default, $single );
938 }
939
940 /**
941 * Get a collection of safe HTML attributes
942 *
943 * @return array
944 */
945 public function get_safe_html_attr(){
946 return apply_filters( 'eeb/settings/get_safe_html_attr', $this->safe_attr_html );
947 }
948
949 /**
950 * ######################
951 * ###
952 * #### Settings helper
953 * ###
954 * ######################
955 */
956
957 /**
958 * Get the admin page url
959 *
960 * @return string - The admin page url
961 */
962 public function get_admin_page_url(){
963
964 $url = admin_url( "options-general.php?page=" . $this->get_page_name() );
965
966 return apply_filters( 'eeb/settings/get_admin_page_url', $url );
967 }
968
969 /**
970 * Helper function to reload the settings
971 *
972 * @return array - An array of all available settings
973 */
974 public function reload_settings(){
975
976 $this->settings = $this->load_settings();
977
978 return $this->settings;
979 }
980
981 /**
982 * Return the default strings that are available
983 * for this plugin.
984 *
985 * @param $slug - the identifier for your specified setting
986 * @param $single - wether you only want to return the value or the whole settings element
987 * @param $group - in case you call a multi-input that contains multiple values (e.g. checkbox), you can set a sub-slug to grab the sub value
988 * @return mixed - the default string
989 */
990 public function get_setting( $slug = '', $single = false, $group = '' ){
991 $return = $this->settings;
992
993 if( empty( $slug ) ){
994 return $return;
995 }
996
997 if( isset( $this->settings[ $slug ] ) || ( ! empty( $group ) && isset( $this->settings[ $group ] ) ) ){
998 if( $single ){
999 $return = false; // Default false
1000
1001 //Set default to the main valie if available given with radio buttons)
1002 if( isset( $this->settings[ $slug ]['value'] ) ){
1003 $return = $this->settings[ $slug ]['value'];
1004 }
1005
1006 if(
1007 ! empty( $group )
1008 && isset( $this->settings[ $group ]['type'] )
1009 && $this->settings[ $group ]['type'] === 'multi-input'
1010 )
1011 {
1012 if( isset( $this->settings[ $group ]['inputs'][ $slug ] ) && isset( $this->settings[ $group ]['inputs'][ $slug ]['value'] ) ){
1013 $return = $this->settings[ $group ]['inputs'][ $slug ]['value'];
1014 }
1015 }
1016
1017 } else {
1018
1019 if( ! empty( $group ) && isset( $this->settings[ $group ] ) ){
1020 $return = $this->settings[ $group ];
1021 } else {
1022 $return = $this->settings[ $slug ];
1023 }
1024
1025 }
1026
1027 }
1028
1029 return $return;
1030 }
1031
1032 }