PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 2.5.0
Email Encoder – Protect Email Addresses and Phone Numbers v2.5.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 / src / Functions.php
email-encoder-bundle / src Last commit date
Admin 1 month ago Front 1 month ago Integrations 4 months ago Traits 4 months ago Validate 1 month ago Functions.php 3 months ago Tester.php 5 months ago
Functions.php
144 lines
1 <?php
2
3 namespace OnlineOptimisation\EmailEncoderBundle;
4
5 use OnlineOptimisation\EmailEncoderBundle\Traits\PluginHelper;
6
7 class Functions
8 {
9 use PluginHelper;
10
11 public function boot(): void
12 {
13 $this->log(__METHOD__);
14 }
15
16
17 public function eeb_form(): string
18 {
19 return EEB()->validate->form->get_encoder_form();
20 }
21
22
23 public function eeb_mailto( string $email, ?string $display = null, string $extra_attrs = '', ?string $method = null ): string
24 {
25 $email = sanitize_email( $email );
26 $custom_class = (string) EEB()->settings->get_setting( 'class_name', true );
27
28 if( empty( $display ) ) {
29 $display = $email;
30 } else {
31 $display = wp_kses( html_entity_decode( $display ), [] );
32 }
33
34 $protection_text = (string) EEB()->settings->get_setting( 'protection_text', true );
35 $class_name = ' ' . EEB()->helpers->sanitize_html_attributes( $extra_attrs );
36 $class_name .= ' class="' . esc_attr( $custom_class ) . '"';
37 $mailto = '<a href="mailto:' . $email . '"'. $class_name . '>' . $display . '</a>';
38
39 if( empty( $method ) ){
40 $protect_using = (string) EEB()->settings->get_setting( 'protect_using', true );
41 if( ! empty( $protect_using ) ){
42 $method = $protect_using;
43 }
44 }
45
46 switch( $method ){
47 case 'enc_ascii':
48 case 'rot13':
49 $mailto = EEB()->validate->encoding->encode_ascii( $mailto, $protection_text );
50 break;
51 case 'enc_escape':
52 case 'escape':
53 $mailto = EEB()->validate->encoding->encode_escape( $mailto, $protection_text );
54 break;
55 case 'with_javascript':
56 $mailto = EEB()->validate->encoding->dynamic_js_email_encoding( $mailto, $protection_text );
57 break;
58 case 'without_javascript':
59 $mailto = EEB()->validate->encoding->encode_email_css( $mailto );
60 break;
61 case 'char_encode':
62 $mailto = EEB()->validate->filters->filter_plain_emails( $mailto, null, 'char_encode' );
63 break;
64 case 'strong_method':
65 $mailto = EEB()->validate->filters->filter_plain_emails( $mailto );
66 break;
67 case 'enc_html':
68 case 'encode':
69 default:
70 $mailto = '<a href="mailto:' . antispambot( $email ) . '"'. $class_name . '>' . antispambot( $display ) . '</a>';
71 break;
72 }
73
74 return apply_filters( 'eeb/frontend/template_func/eeb_mailto', $mailto );
75 }
76
77
78 /**
79 * Template function for encoding content
80 *
81 * @global Eeb_Site $Eeb_Site
82 * @param string $content
83 * @param string $method Optional, default null
84 * @return string
85 */
86 public function eeb_protect_content( string $content, ?string $method = null, ?string $protection_text = null ): string
87 {
88 if( empty( $protection_text ) ){
89 $protection_text = (string) EEB()->settings->get_setting( 'protection_text', true );
90 } else {
91 $protection_text = wp_kses_post( $protection_text );
92 }
93
94 if( ! empty( $method ) ){
95 $method = sanitize_title( $method );
96 } else {
97 $method = 'rot13';
98 }
99
100 switch( $method ){
101 case 'enc_ascii':
102 case 'rot13':
103 $content = EEB()->validate->encoding->encode_ascii( $content, $protection_text );
104 break;
105 case 'enc_escape':
106 case 'escape':
107 $content = EEB()->validate->encoding->encode_escape( $content, $protection_text );
108 break;
109 case 'enc_html':
110 case 'encode':
111 default:
112 $content = antispambot( $content );
113 break;
114 }
115
116 return apply_filters( 'eeb/frontend/template_func/eeb_protect_content', $content );
117 }
118
119 /**
120 * Template function for encoding emails in the given content
121 *
122 * @global Eeb_Site $Eeb_Site
123 * @param string $content
124 * @param mixed $method
125 * @param boolean $enc_mailtos Optional, default true (deprectaed)
126 * @param boolean $enc_plain_emails Optional, default true (deprectaed)
127 * @param boolean $enc_input_fields Optional, default true (deprectaed)
128 * @return string
129 */
130 public function eeb_protect_emails( string $content, $method = null, bool $enc_mailtos = true, bool $enc_plain_emails = true, bool $enc_input_fields = true ): string
131 {
132
133 //backwards compatibility for enc tags
134 if( $method === null || is_bool( $method ) ){
135 $protect_using = (string) EEB()->settings->get_setting( 'protect_using', true );
136 } else {
137 $protect_using = sanitize_title( $method );
138 }
139
140 $content = EEB()->validate->filters->filter_content( $content, $protect_using );
141 return apply_filters( 'eeb/frontend/template_func/eeb_protect_emails', $content, $protect_using );
142 }
143 }
144