PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 2.0.5
Email Encoder – Protect Email Addresses and Phone Numbers v2.0.5
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-run.php
email-encoder-bundle / core / includes / classes Last commit date
class-email-encoder-bundle-ajax.php 6 years ago class-email-encoder-bundle-helpers.php 6 years ago class-email-encoder-bundle-run-admin.php 6 years ago class-email-encoder-bundle-run.php 6 years ago class-email-encoder-bundle-settings.php 6 years ago class-email-encoder-bundle-validate.php 6 years ago index.php 6 years ago
class-email-encoder-bundle-run.php
599 lines
1 <?php
2
3 /**
4 * Class Email_Encoder_Run
5 *
6 * Thats where we bring the plugin to life
7 *
8 * @since 2.0.0
9 * @package EEB
10 * @author Ironikus <info@ironikus.com>
11 */
12
13 class Email_Encoder_Run{
14
15 /**
16 * The main page name for our admin page
17 *
18 * @var string
19 * @since 2.0.0
20 */
21 private $page_name;
22
23 /**
24 * The main page title for our admin page
25 *
26 * @var string
27 * @since 2.0.0
28 */
29 private $page_title;
30
31 /**
32 * Our Email_Encoder_Run constructor.
33 */
34 function __construct(){
35 $this->page_name = EEB()->settings->get_page_name();
36 $this->page_title = EEB()->settings->get_page_title();
37 $this->final_outout_buffer_hook = EEB()->settings->get_final_outout_buffer_hook();
38 $this->widget_callback_hook = EEB()->settings->get_widget_callback_hook();
39 $this->add_hooks();
40 }
41
42 /**
43 * Define all of our necessary hooks
44 */
45 private function add_hooks(){
46 $filter_hook = (bool) EEB()->settings->get_setting( 'filter_hook', true, 'filter_body' );
47 if( $filter_hook ){
48 $hook_name = 'init';
49 } else {
50 $hook_name = 'wp';
51 }
52
53 add_action( 'wp', array( $this, 'display_email_image' ), EEB()->settings->get_hook_priorities( 'display_email_image' ) );
54 add_action( 'init', array( $this, 'buffer_final_output' ), EEB()->settings->get_hook_priorities( 'buffer_final_output' ) );
55 add_action( 'init', array( $this, 'add_custom_template_tags' ), EEB()->settings->get_hook_priorities( 'add_custom_template_tags' ) );
56 add_action( $hook_name, array( $this, 'setup_single_filter_hooks' ), EEB()->settings->get_hook_priorities( 'setup_single_filter_hooks' ) );
57 add_action( 'wp_enqueue_scripts', array( $this, 'load_frontend_header_styling' ), EEB()->settings->get_hook_priorities( 'load_frontend_header_styling' ) );
58 add_filter( 'dynamic_sidebar_params', array( $this, 'eeb_dynamic_sidebar_params' ), EEB()->settings->get_hook_priorities( 'eeb_dynamic_sidebar_params' ) );
59
60 //Add shortcodes
61 add_shortcode( 'eeb_protect_emails', array( $this, 'protect_content_shortcode' ) );
62 add_shortcode( 'eeb_protect_content', array( $this, 'shortcode_eeb_content' ) );
63 add_shortcode( 'eeb_mailto', array( $this, 'shortcode_eeb_email' ) );
64 add_shortcode( 'eeb_form', array( $this, 'shortcode_email_encoder_form' ) );
65
66 //BAckwards compatibility
67 add_shortcode( 'eeb_content', array( $this, 'shortcode_eeb_content' ) );
68 add_shortcode( 'eeb_email', array( $this, 'shortcode_eeb_email' ) );
69
70 do_action('eeb_ready', array($this, 'eeb_ready_callback_filter'), $this);
71
72 }
73
74 /**
75 * ######################
76 * ###
77 * #### CALLBACK FILTERS
78 * ###
79 * ######################
80 */
81
82 /**
83 * WP filter callback
84 * @param string $content
85 * @return string
86 */
87 public function eeb_ready_callback_filter( $content ) {
88
89 if( EEB()->validate->is_post_excluded() ){
90 return $content;
91 }
92
93 $protect_using = (string) EEB()->settings->get_setting( 'protect_using', true );
94
95 return EEB()->validate->filter_content( $content, $protect_using );
96 }
97
98 /**
99 * ######################
100 * ###
101 * #### PAGE BUFFERING & WIDGET FILTER
102 * ###
103 * ######################
104 */
105
106 /**
107 * Buffer the final output on the init hook
108 *
109 * @return void
110 */
111 public function buffer_final_output(){
112 if ( ! defined( 'WP_CLI' ) ) {
113 ob_start( array( $this, 'apply_content_filter' ) );
114 }
115 }
116
117 /**
118 * Apply the callabla function for ob_start()
119 *
120 * @param string $content
121 * @return string - the filtered content
122 */
123 public function apply_content_filter( $content ){
124 $filteredContent = apply_filters( $this->final_outout_buffer_hook, $content );
125
126 // remove filters after applying to prevent multiple applies
127 remove_all_filters( $this->final_outout_buffer_hook );
128
129 return $filteredContent;
130 }
131
132 /**
133 * Filter for "dynamic_sidebar_params" hook
134 *
135 * @global array $wp_registered_widgets
136 * @param array $params
137 * @return array
138 */
139 public function eeb_dynamic_sidebar_params( $params){
140 global $wp_registered_widgets;
141
142 if ( is_admin() ) {
143 return $params;
144 }
145
146 $widget_id = $params[0]['widget_id'];
147
148 // prevent overwriting when already set by another version of the widget output class
149 if ( isset( $wp_registered_widgets[ $widget_id ]['_wo_original_callback'] ) ) {
150 return $params;
151 }
152
153 $wp_registered_widgets[ $widget_id ]['_wo_original_callback'] = $wp_registered_widgets[ $widget_id ]['callback'];
154 $wp_registered_widgets[ $widget_id ]['callback'] = array( $this, 'call_widget_callback' );
155
156 return $params;
157 }
158
159 /**
160 * The Widget Callback
161 * @global array $wp_registered_widgets
162 */
163 public function call_widget_callback(){
164 global $wp_registered_widgets;
165
166 $original_callback_params = func_get_args();
167 $original_callback = null;
168
169 $widget_id = $original_callback_params[0]['widget_id'];
170
171 $original_callback = $wp_registered_widgets[ $widget_id ]['_wo_original_callback'];
172 $wp_registered_widgets[ $widget_id ]['callback'] = $original_callback;
173
174 $widget_id_base = $wp_registered_widgets[ $widget_id ]['callback'][0]->id_base;
175
176 if ( is_callable( $original_callback ) ) {
177 ob_start();
178 call_user_func_array( $original_callback, $original_callback_params );
179 $widget_output = ob_get_clean();
180
181 echo apply_filters( $this->widget_callback_hook, $widget_output, $widget_id_base, $widget_id );
182
183 // remove filters after applying to prevent multiple applies
184 remove_all_filters( $this->widget_callback_hook );
185 }
186 }
187
188 /**
189 * ######################
190 * ###
191 * #### SCRIPT ENQUEUEMENTS
192 * ###
193 * ######################
194 */
195
196 public function load_frontend_header_styling(){
197
198 $js_version = date( "ymd-Gis", filemtime( EEB_PLUGIN_DIR . 'core/includes/assets/js/custom.js' ));
199 $css_version = date( "ymd-Gis", filemtime( EEB_PLUGIN_DIR . 'core/includes/assets/css/style.css' ));
200 $protection_activated = (int) EEB()->settings->get_setting( 'protect', true );
201 $without_javascript = (string) EEB()->settings->get_setting( 'protect_using', true );
202 $footer_scripts = (bool) EEB()->settings->get_setting( 'footer_scripts', true );
203
204 if( $without_javascript !== 'without_javascript' ){
205 wp_enqueue_script( 'eeb-js-frontend', EEB_PLUGIN_URL . 'core/includes/assets/js/custom.js', array( 'jquery' ), $js_version, $footer_scripts );
206 }
207
208 wp_register_style( 'eeb-css-frontend', EEB_PLUGIN_URL . 'core/includes/assets/css/style.css', false, $css_version );
209 wp_enqueue_style ( 'eeb-css-frontend' );
210
211 if( (string) EEB()->settings->get_setting( 'show_encoded_check', true ) === '1' ){
212 wp_enqueue_style('dashicons');
213 }
214
215 }
216
217 /**
218 * ######################
219 * ###
220 * #### CORE LOGIC
221 * ###
222 * ######################
223 */
224
225 /**
226 * Register all single filters to protect your content
227 *
228 * @return void
229 */
230 public function setup_single_filter_hooks(){
231
232 if( EEB()->validate->is_post_excluded() ){
233 return;
234 }
235
236 $protection_method = (int) EEB()->settings->get_setting( 'protect', true );
237 $filter_rss = (int) EEB()->settings->get_setting( 'filter_rss', true, 'filter_body' );
238 $remove_shortcodes_rss = (int) EEB()->settings->get_setting( 'remove_shortcodes_rss', true, 'filter_body' );
239 $protect_shortcode_tags = (bool) EEB()->settings->get_setting( 'protect_shortcode_tags', true, 'filter_body' );
240 $protect_shortcode_tags_valid = false;
241
242 if ( is_feed() ) {
243
244 if( $filter_rss === 1 ){
245 add_filter( $this->final_outout_buffer_hook, array( $this, 'filter_rss' ), EEB()->settings->get_hook_priorities( 'filter_rss' ) );
246 }
247
248 if ( $remove_shortcodes_rss ) {
249 add_filter( $this->final_outout_buffer_hook, array( $this, 'callback_rss_remove_shortcodes' ), EEB()->settings->get_hook_priorities( 'callback_rss_remove_shortcodes' ) );
250 }
251
252 }
253
254 if ( $protection_method === 2 ) {
255 $protect_shortcode_tags_valid = true;
256
257 $filter_hooks = array(
258 'the_title',
259 'the_content',
260 'the_excerpt',
261 'get_the_excerpt',
262
263 //Comment related
264 'comment_text',
265 'comment_excerpt',
266 'comment_url',
267 'get_comment_author_url',
268 'get_comment_author_url_link',
269
270 //Widgets
271 'widget_title',
272 'widget_text',
273 'widget_content',
274 'widget_output',
275 );
276
277 $filter_hooks = apply_filters( 'eeb/frontend/wordpress_filters', $filter_hooks );
278
279 foreach ( $filter_hooks as $hook ) {
280 add_filter( $hook, array( $this, 'filter_content' ), EEB()->settings->get_hook_priorities( 'filter_content' ) );
281 }
282 } elseif( $protection_method === 1 ){
283 $protect_shortcode_tags_valid = true;
284
285 add_filter( $this->final_outout_buffer_hook, array( $this, 'filter_page' ), EEB()->settings->get_hook_priorities( 'filter_page' ) );
286 }
287
288 if( $protect_shortcode_tags_valid ){
289 if( $protect_shortcode_tags ){
290 add_filter( 'do_shortcode_tag', array( $this, 'filter_content' ), EEB()->settings->get_hook_priorities( 'do_shortcode_tag' ) );
291 }
292 }
293
294 }
295
296 /**
297 * Filter the page itself
298 *
299 * @param string $content
300 * @return string
301 */
302 public function filter_page( $content ){
303 $protect_using = (string) EEB()->settings->get_setting( 'protect_using', true );
304
305 return EEB()->validate->filter_page( $content, $protect_using );
306 }
307
308 /**
309 * Filter the whole content
310 *
311 * @param string $content
312 * @return string
313 */
314 public function filter_content( $content ){
315 $protect_using = (string) EEB()->settings->get_setting( 'protect_using', true );
316 return EEB()->validate->filter_content( $content, $protect_using );
317 }
318
319 /**
320 * Filter the rss content
321 *
322 * @param string $content
323 * @return string
324 */
325 public function filter_rss( $content ){
326 $protection_type = (string) EEB()->settings->get_setting( 'protect_using', true );
327 return EEB()->validate->filter_rss( $content, $protection_type );
328 }
329
330 /**
331 * RSS Callback Remove shortcodes
332 * @param string $content
333 * @return string
334 */
335 public function callback_rss_remove_shortcodes( $content ) {
336 // strip shortcodes like [eeb_content], [eeb_form]
337 $content = strip_shortcodes($content);
338
339 return $content;
340 }
341
342 /**
343 * ######################
344 * ###
345 * #### SHORTCODES
346 * ###
347 * ######################
348 */
349
350 /**
351 * Handle content filter shortcode
352 * @param array $atts
353 * @param string $content
354 */
355 public function protect_content_shortcode( $atts, $content = null ){
356 $protect = (int) EEB()->settings->get_setting( 'protect', true );
357 $protect_using = (string) EEB()->settings->get_setting( 'protect_using', true );
358 $protection_activated = ( $protect === 1 || $protect === 2 ) ? true : false;
359
360 if ( ! $protection_activated ) {
361 return $content;
362 }
363
364 if( isset( $atts['protect_using'] ) ){
365 $protect_using = $atts['protect_using'];
366 }
367
368 $content = EEB()->validate->filter_content( $content, $protect_using );
369
370 return $content;
371 }
372
373 /**
374 * Return the email encoder form
375 * @param array $atts
376 * @param string $content
377 */
378 public function shortcode_email_encoder_form( $atts = array(), $content = null ){
379 $display_encoder_form = (bool) EEB()->settings->get_setting( 'display_encoder_form', true, 'encoder_form' );
380
381 if( $display_encoder_form ){
382 return EEB()->validate->get_encoder_form();
383 }
384
385 return '';
386 }
387
388 /**
389 * Return the encoded content
390 * @param array $atts
391 * @param string $content
392 */
393 public function shortcode_eeb_content( $atts = array(), $content = null ){
394
395 $show_encoded_check = (string) EEB()->settings->get_setting( 'show_encoded_check', true );
396
397 if( ! isset( $atts['protection_text'] ) ){
398 $protection_text = __( EEB()->settings->get_setting( 'protection_text', true ), 'email-protection-text-eeb-content' );
399 } else {
400 $protection_text = wp_kses_post( $atts['protection_text'] );
401 }
402
403 if( isset( $atts['method'] ) ){
404 $method = sanitize_title( $atts['method'] );
405 } else {
406 $method = 'rot13';
407 }
408
409 switch( $method ){
410 case 'enc_ascii':
411 case 'rot13':
412 $content = EEB()->validate->encode_ascii( $content, $protection_text );
413 break;
414 case 'enc_escape':
415 case 'escape':
416 $content = EEB()->validate->encode_escape( $content, $protection_text );
417 break;
418 case 'enc_html':
419 case 'encode':
420 default:
421 $content = antispambot( $content );
422 break;
423 }
424
425 // mark link as successfullly encoded (for admin users)
426 if ( current_user_can( EEB()->settings->get_admin_cap( 'frontend-display-security-check' ) ) && $show_encoded_check ) {
427 $content .= '<i class="eeb-encoded dashicons-before dashicons-lock" title="' . __( 'Email encoded successfully!', 'email-encoder-bundle' ) . '"></i>';
428 }
429
430 return apply_filters( 'eeb/frontend/shortcode/eeb_protect_content', $content, $atts );
431 }
432
433 /**
434 * Return the encoded email
435 * @param array $atts
436 * @param string $content
437 */
438 public function shortcode_eeb_email( $atts = array(), $content = null ){
439
440 $show_encoded_check = (bool) EEB()->settings->get_setting( 'show_encoded_check', true );
441 $protection_text = __( EEB()->settings->get_setting( 'protection_text', true ), 'email-encoder-bundle' );
442
443 if( empty( $atts['email'] ) ){
444 return '';
445 } else {
446 $email = $atts['email'];
447 }
448
449 if( empty( $atts['extra_attrs'] ) ){
450 $extra_attrs = '';
451 } else {
452 $extra_attrs = $atts['extra_attrs'];
453 }
454
455 if( empty( $atts['method'] ) ){
456 $method = 'rot13';
457 } else {
458 $method = sanitize_title( $atts['method'] );
459 }
460
461 $custom_class = (string) EEB()->settings->get_setting( 'class_name', true );
462
463 if( empty( $atts['display'] ) ) {
464 $display = $email;
465 } else {
466 $display = html_entity_decode( $atts['display'] );
467 }
468
469 if( empty( $atts['noscript'] ) ) {
470 $noscript = $protection_text;
471 } else {
472 $noscript = html_entity_decode( $atts['noscript'] );
473 }
474
475 $class_name = ' ' . trim( $extra_attrs );
476 $class_name .= ' class="' . esc_attr( $custom_class ) . '"';
477 $mailto = '<a href="mailto:' . $email . '"'. $class_name . '>' . $display . '</a>';
478
479 switch( $method ){
480 case 'enc_ascii':
481 case 'rot13':
482 $mailto = EEB()->validate->encode_ascii( $mailto, $noscript );
483 break;
484 case 'enc_escape':
485 case 'escape':
486 $mailto = EEB()->validate->encode_escape( $mailto, $noscript );
487 break;
488 case 'enc_html':
489 case 'encode':
490 default:
491 $mailto = '<a href="mailto:' . antispambot( $email ) . '"'. $class_name . '>' . antispambot( $display ) . '</a>';
492 break;
493 }
494
495 // mark link as successfullly encoded (for admin users)
496 if ( current_user_can( EEB()->settings->get_admin_cap( 'frontend-display-security-check' ) ) && $show_encoded_check ) {
497 $mailto .= '<i class="eeb-encoded dashicons-before dashicons-lock" title="' . __( 'Email encoded successfully!', 'email-encoder-bundle' ) . '"></i>';
498 }
499
500 return apply_filters( 'eeb/frontend/shortcode/eeb_mailto', $mailto );
501 }
502
503 /**
504 * ######################
505 * ###
506 * #### EMAIL IMAGE
507 * ###
508 * ######################
509 */
510
511 public function display_email_image(){
512
513 if( ! isset( $_GET['eeb_mail'] ) ){
514 return;
515 }
516
517 $email = sanitize_email( base64_decode( $_GET['eeb_mail'] ) );
518
519 if( ! is_email( $email ) || ! isset( $_GET['eeb_hash'] ) ){
520 return;
521 }
522
523 $hash = (string) $_GET['eeb_hash'];
524 $secret = EEB()->settings->get_email_image_secret();
525
526 if( EEB()->validate->generate_email_signature( $email, $secret ) !== $hash ){
527 wp_die( __('Your signture is invalid.', 'email-encoder-bundle') );
528 }
529
530 $image = EEB()->validate->email_to_image( $email );
531
532 if( empty( $image ) ){
533 wp_die( __('Your email could not be converted.', 'email-encoder-bundle') );
534 }
535
536 header('Content-type: image/png');
537 echo $image;
538 die();
539
540 }
541
542 /**
543 * ######################
544 * ###
545 * #### TEMPLATE TAGS
546 * ###
547 * ######################
548 */
549
550 public function add_custom_template_tags(){
551 $template_tags = EEB()->settings->get_template_tags();
552
553 foreach( $template_tags as $hook => $callback ){
554
555 //Make sure we only call our own custom template tags
556 if( is_callable( array( $this, $callback ) ) ){
557 apply_filters( $hook, array( $this, $callback ), 10 );
558 }
559
560 }
561 }
562
563 /**
564 * Filter for the eeb_filter template tag
565 *
566 * This function is called dynamically by add_custom_template_tags
567 * using the EEB()->settings->get_template_tags() callback.
568 *
569 * @param string $content - the default content
570 * @return string - the filtered content
571 */
572 public function template_tag_eeb_filter( $content ){
573 $protect_using = (string) EEB()->settings->get_setting( 'protect_using', true );
574 return EEB()->validate->filter_content( $content, $protect_using );
575 }
576
577 /**
578 * Filter for the eeb_filter template tag
579 *
580 * This function is called dynamically by add_custom_template_tags
581 * using the EEB()->settings->get_template_tags() callback.
582 *
583 * @param string $content - the default content
584 * @return string - the filtered content
585 */
586 public function template_tag_eeb_mailto( $email, $display = null, $atts = array() ){
587 if ( is_array( $display ) ) {
588 // backwards compatibility (old params: $display, $attrs = array())
589 $atts = $display;
590 $display = $email;
591 } else {
592 $atts['href'] = 'mailto:'.$email;
593 }
594
595 return EEB()->validate->create_protected_mailto( $display, $atts );
596 }
597
598 }
599