PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 2.4.3
Email Encoder – Protect Email Addresses and Phone Numbers v2.4.3
2.5.3 2.5.2 2.5.1 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 6 months ago class-email-encoder-bundle-helpers.php 6 months ago class-email-encoder-bundle-settings.php 6 months ago index.php 6 years ago
class-email-encoder-bundle-settings.php
528 lines
1 <?php
2
3 namespace Legacy\EmailEncoderBundle;
4
5 class Email_Encoder_Settings {
6
7 public const PROTECT_FULL_PAGE = 1;
8 public const PROTECT_FILTERS_ONLY = 2;
9 public const PROTECT_DISABLED = 3;
10
11 private string $admin_cap = 'manage_options';
12 private string $page_name = 'email-encoder-bundle-option-page';
13 private string $page_title;
14 private string $final_output_buffer_hook = 'final_output';
15 private string $widget_callback_hook = 'widget_output';
16 private string $settings_key= 'WP_Email_Encoder_Bundle_options';
17 private string $version_key= 'email-encoder-bundle-version';
18 private string $image_secret_key = 'email-encoder-bundle-img-key';
19 private string $at_identifier = '##eebAddIdent##';
20 private ?string $previous_version = null;
21
22 /** @var array< string, int > */
23 private array $hook_priorities = [ // deprecated!
24 'buffer_final_output' => 1000,
25 'setup_single_filter_hooks' => 100,
26 'add_custom_template_tags' => 10,
27 'load_frontend_header_styling' => 10,
28 'filter_rss' => 100,
29 'filter_page' => 100,
30 'filter_content' => 100,
31 'first_version_init' => 100,
32 'version_update' => 100,
33 'display_email_image' => 999,
34 'callback_rss_remove_shortcodes' => 10,
35 'load_ajax_scripts_styles' => 10,
36 'load_ajax_scripts_styles_admin' => 10,
37 'reload_settings_for_integrations' => 5,
38 // 'eeb_dynamic_sidebar_params' => 100, //deprecated but kept for compatibility
39 ];
40
41 /** @var array< string, array< string, mixed > > */
42 private array $safe_attr_html;
43
44 private string $email_regex = '([_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[A-Za-z]{2,}))';
45
46 /** @var array< string, string > > */
47 private array $soft_attribute_regex = [
48 'woocommerce_variation_attribute_tag' => '/data-product_variations="([^"]*)"/i',
49 'jetpack_carousel_image_attribute_tag' => '/data-image-meta="([^"]*)"/i',
50 'html_placeholder_tag' => '/placeholder="([^"]*)"/i',
51 ];
52
53 /** @var array< string, array< string, mixed > > */
54 private array $settings = [];
55
56 private string $version;
57 private string $email_image_secret;
58
59 /** @var array< string, string > > */
60 private array $template_tags= [
61 'eeb_filter' => 'template_tag_eeb_filter',
62 'eeb_mailto' => 'template_tag_eeb_mailto'
63 ];
64
65 /** @var array< string, mixed > > */
66 private array $default_values = [
67 'protect' => self::PROTECT_FULL_PAGE,
68 'filter_rss' => 1,
69 'powered_by' => 1,
70 'protect_using' => 'with_javascript',
71 'class_name' => 'mail-link',
72 'protection_text' => '*protected email*',
73 'image_color' => '0,0,0',
74 'image_background_color' => '0,0,0',
75 'image_text_opacity' => '0',
76 'image_underline' => '0',
77 'image_background_opacity' => '127',
78 'image_font_size' => '4',
79 ];
80
81 /**
82 * Email_Encoder_Settings constructor.
83 *
84 * We define all of our necessary settings in here.
85 * If you need to do plugin related changes, everything will
86 * be available in this file.
87 */
88 function __construct() {
89 $this->page_title = EEB_NAME;
90 $this->safe_attr_html = require EEB_PLUGIN_DIR . '/config/SafeHtmlConfig.php';
91
92 add_action( 'init', [ $this, 'load_settings' ] );
93 add_action( 'init', [ $this, 'load_version' ] );
94 add_action( 'init', [ $this, 'load_email_image_secret' ] );
95 }
96
97 /**
98 * @return array< string, mixed >
99 */
100 public function get_saved(): array {
101 return get_option( $this->settings_key, [] );
102 }
103 /**
104 * ######################
105 * ###
106 * #### MAIN SETTINGS
107 * ###
108 * ######################
109 */
110
111 /**
112 * Load the settings for our admin settings page
113 *
114 * @return void
115 */
116 public function load_settings() {
117
118 $fields = require EEB_PLUGIN_DIR . '/config/SettingsConfig.php';
119 $fields = apply_filters( 'eeb/settings/pre_filter_fields', $fields );
120
121 $saved_values = get_option( $this->settings_key, [] );
122 $values = array_replace_recursive( $this->default_values, $saved_values );
123
124
125 if ( $values != $saved_values ) {
126 update_option( $this->settings_key, $values );
127 error_log( 'Updated option ' . $this->settings_key);
128 }
129
130 foreach ( $fields as $key => $field ) {
131 if ( $field['type'] === 'multi-input' ) {
132 foreach ( $field['inputs'] as $smi_key => $smi_data ) {
133
134 if ( $field['input-type'] === 'radio' ) {
135 if ( isset( $values[ $key ] ) && (string) $values[ $key ] === (string) $smi_key ) {
136 $fields[ $key ]['value'] = $values[ $key ];
137 }
138 }
139 else {
140 if ( isset( $values[ $smi_key ] ) ) {
141 $fields[ $key ]['inputs'][ $smi_key ]['value'] = $values[ $smi_key ];
142 }
143 }
144
145 }
146 }
147 else {
148 if ( isset( $values[ $key ] ) ) {
149 $fields[ $key ]['value'] = $values[ $key ];
150 }
151 }
152 }
153
154 $this->settings = apply_filters( 'eeb/settings/fields', $fields );
155 }
156
157 /**
158 * ######################
159 * ###
160 * #### VERSIONING
161 * ###
162 * ######################
163 */
164
165 /**
166 * @return string
167 */
168 public function load_version() {
169
170 $current_version = get_option( $this->get_version_key() );
171
172 if ( empty( $current_version ) ) {
173 $current_version = EEB_VERSION;
174 update_option( $this->get_version_key(), $current_version );
175
176 add_action( 'init', array( $this, 'first_version_init' ), $this->get_hook_priorities( 'first_version_init' ) );
177 }
178 else {
179 if ( $current_version !== EEB_VERSION ) {
180 $this->previous_version = $current_version;
181 $current_version = EEB_VERSION;
182 update_option( $this->get_version_key(), $current_version );
183
184 add_action( 'init', array( $this, 'version_update' ), $this->get_hook_priorities( 'version_update' ) );
185 }
186 }
187
188 $this->version = $current_version;
189 return $current_version;
190 }
191
192
193 public function load_email_image_secret(): void {
194
195 if ( ! (bool) $this->get_setting( 'convert_plain_to_image', true, 'filter_body' ) ) {
196 return;
197 }
198
199 $image_descret = get_option( $this->get_image_secret_key() );
200
201 if ( ! empty( $image_descret ) ) {
202 $this->email_image_secret = $image_descret;
203 return;
204 }
205
206 $key = '';
207
208 for ( $i = 0; $i < 265; $i++ ) {
209 $key .= chr( mt_rand( 33, 126 ) );
210 }
211
212 update_option( $this->get_image_secret_key(), $key );
213
214 $this->email_image_secret = $key;
215 // return $key;
216 }
217
218 /**
219 * Fires an action after our settings key was initially set
220 * the very first time.
221 *
222 * @return void
223 */
224 public function first_version_init(): void {
225 do_action( 'eeb/settings/first_version_init', EEB_VERSION );
226 }
227
228 /**
229 * Fires after the version of the plugin is initially updated
230 *
231 * @return void
232 */
233 public function version_update(): void {
234 do_action( 'eeb/settings/version_update', EEB_VERSION, $this->previous_version );
235 }
236
237 /**
238 * ######################
239 * ###
240 * #### CALLABLE FUNCTIONS
241 * ###
242 * ######################
243 */
244
245 /**
246 * Our admin cap handler function
247 *
248 * This function handles the admin capability throughout
249 * the whole plugin.
250 *
251 * $target - With the target function you can make a more precised filtering
252 * by changing it for specific actions.
253 *
254 * @param string $target - A identifier where the call comes from
255 * @return mixed
256 */
257 public function get_admin_cap( $target = 'main' ) {
258 /**
259 * Customize the globally used capability for this plugin
260 *
261 * This filter is called every time the capability is needed.
262 */
263 return apply_filters( 'eeb/settings/capability', $this->admin_cap, $target );
264 }
265
266 /**
267 * Return the page name for our admin page
268 *
269 * @return string - the page name
270 */
271 public function get_page_name() {
272 return apply_filters( 'eeb/settings/page_name', $this->page_name );
273 }
274
275 /**
276 * Return the page title for our admin page
277 *
278 * @return string - the page title
279 */
280 public function get_page_title() {
281 return apply_filters( 'eeb/settings/page_title', $this->page_title );
282 }
283
284 /**
285 * Return the settings_key
286 *
287 * @return string - the settings key
288 */
289 public function get_settings_key() {
290 return $this->settings_key;
291 }
292
293 /**
294 * Return the version_key
295 *
296 * @return string - the version_key
297 */
298 public function get_version_key() {
299 return $this->version_key;
300 }
301
302 /**
303 * Return the image_secret_key
304 *
305 * @return string - the image_secret_key
306 */
307 public function get_image_secret_key() {
308 return $this->image_secret_key;
309 }
310
311 /**
312 * Return the email_image_secret
313 *
314 * @return string - the email_image_secret
315 */
316 public function get_email_image_secret() {
317 return $this->email_image_secret;
318 }
319
320 /**
321 * Return the version
322 *
323 * @return string - the version
324 */
325 public function get_version() {
326 return apply_filters( 'eeb/settings/get_version', $this->version );
327 }
328
329 /**
330 * Return the default template tags
331 *
332 * @return array< string, string > - the template tags
333 */
334 public function get_template_tags() {
335 return apply_filters( 'eeb/settings/get_template_tags', $this->template_tags );
336 }
337
338 /**
339 * Return the widget callback hook name
340 *
341 * @return string - the final widget callback hook name
342 */
343 public function get_widget_callback_hook() {
344 return apply_filters( 'eeb/settings/widget_callback_hook', $this->widget_callback_hook );
345 }
346
347 /**
348 * Return the final output buffer hook name
349 *
350 * @return string - the final output buffer hook name
351 */
352 public function get_final_output_buffer_hook() {
353 return apply_filters( 'eeb/settings/final_output_buffer_hook', $this->final_output_buffer_hook );
354 }
355
356 /**
357 * Return the @ symbol identifier
358 *
359 * @return string - the @ symbol identifier
360 */
361 public function get_at_identifier() {
362 return apply_filters( 'eeb/settings/at_identifier', $this->at_identifier );
363 }
364
365 /**
366 * @link http://www.mkyong.com/regular-expressions/how-to-validate-email-address-with-regular-expression/
367 * @param boolean $include
368 * @return string
369 */
370 public function get_email_regex( $include = false ) {
371
372 if ( $include === true ) {
373 $return = $this->email_regex;
374 } else {
375 $return = '/' . $this->email_regex . '/i';
376 }
377
378 return apply_filters( 'eeb/settings/get_email_regex', $return, $include );
379 }
380
381 /**
382 * Get Woocommerce variation attribute regex
383 *
384 * @param string $single
385 * @return string
386 */
387 public function get_soft_attribute_regex( $single = null ) {
388
389 $return = $this->soft_attribute_regex;
390
391 if ( $single !== null ) {
392 if ( isset( $this->soft_attribute_regex[ $single ] ) ) {
393 $return = $this->soft_attribute_regex[ $single ];
394 } else {
395 $return = false;
396 }
397 }
398
399 return apply_filters( 'eeb/settings/get_soft_attribute_regex', $return, $single );
400 }
401
402 /**
403 * Get hook priorities
404 *
405 * @param string $single - wether you want to return only a single hook priority or not
406 * @return mixed - An array or string of hook priority(-ies)
407 */
408 public function get_hook_priorities( ?string $single = null ) {
409
410 $is_single = $single && isset( $this->hook_priorities[ $single ] );
411
412 $return = $is_single
413 ? $this->hook_priorities[ $single ]
414 : ( $single ? 10 : $this->hook_priorities )
415 ;
416 $default = $is_single ? true : false;
417
418 // if ( $single ) {
419 // if ( isset( $this->hook_priorities[ $single ] ) ) {
420 // $return = $this->hook_priorities[ $single ];
421 // $default = false;
422 // } else {
423 // $return = 10;
424 // $default = true;
425 // }
426 // }
427
428 return apply_filters( 'eeb/settings/get_hook_priorities', $return, $default, $single );
429 }
430
431 /**
432 * Get a collection of safe HTML attributes
433 *
434 * @return array< string, array< string, mixed > >
435 */
436 public function get_safe_html_attr() {
437 return apply_filters( 'eeb/settings/get_safe_html_attr', $this->safe_attr_html );
438 }
439
440 /**
441 * ######################
442 * ###
443 * #### Settings helper
444 * ###
445 * ######################
446 */
447
448 /**
449 * Get the admin page url
450 *
451 * @return string - The admin page url
452 */
453 public function get_admin_page_url() {
454
455 $url = admin_url( "options-general.php?page=" . $this->get_page_name() );
456
457 return apply_filters( 'eeb/settings/get_admin_page_url', $url );
458 }
459
460 /**
461 * Helper function to reload the settings
462 *
463 * @return void
464 */
465 public function reload_settings() {
466 $this->load_settings();
467 }
468
469 /**
470 * Return the default strings that are available for this plugin.
471 *
472 * @param string $slug - the identifier for your specified setting
473 * @param bool $single - wether you only want to return the value or the whole settings element
474 * @param string $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
475 * @return mixed - the default string
476 */
477 public function get_setting( $slug = '', $single = false, $group = '' ) {
478
479 // temporary fix to resolve calls before class is properly booted
480 if ( $this->settings === [] ) {
481 error_log( 'EmailEncoderBundle: Method get_settings() is accessed too early!' );
482 $this->load_settings();
483 }
484 // end of fix
485
486
487 $return = $this->settings;
488
489 if ( empty( $slug ) ) {
490 return $return;
491 }
492
493 if ( isset( $this->settings[ $slug ] ) || ( ! empty( $group ) && isset( $this->settings[ $group ] ) ) ) {
494 if ( $single ) {
495 $return = false; // Default false
496
497 //Set default to the main valie if available given with radio buttons)
498 if ( isset( $this->settings[ $slug ]['value'] ) ) {
499 $return = $this->settings[ $slug ]['value'];
500 }
501
502 if (
503 ! empty( $group )
504 && isset( $this->settings[ $group ]['type'] )
505 && $this->settings[ $group ]['type'] === 'multi-input'
506 )
507 {
508 if ( isset( $this->settings[ $group ]['inputs'][ $slug ] ) && isset( $this->settings[ $group ]['inputs'][ $slug ]['value'] ) ) {
509 $return = $this->settings[ $group ]['inputs'][ $slug ]['value'];
510 }
511 }
512
513 } else {
514
515 if ( ! empty( $group ) && isset( $this->settings[ $group ] ) ) {
516 $return = $this->settings[ $group ];
517 } else {
518 $return = $this->settings[ $slug ];
519 }
520
521 }
522
523 }
524
525 return $return;
526 }
527
528 }