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