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.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 4 months ago Front 4 months ago Integrations 4 months ago Traits 4 months ago Validate 4 months ago Functions.php 4 months ago Tester.php 4 months ago
Functions.php
142 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 $custom_class = (string) EEB()->settings->get_setting( 'class_name', true );
26
27 if( empty( $display ) ) {
28 $display = $email;
29 } else {
30 $display = html_entity_decode($display);
31 }
32
33 $class_name = ' ' . EEB()->helpers->sanitize_html_attributes( $extra_attrs );
34 $class_name .= ' class="' . esc_attr( $custom_class ) . '"';
35 $mailto = '<a href="mailto:' . $email . '"'. $class_name . '>' . $display . '</a>';
36
37 if( empty( $method ) ){
38 $protect_using = (string) EEB()->settings->get_setting( 'protect_using', true );
39 if( ! empty( $protect_using ) ){
40 $method = $protect_using;
41 }
42 }
43
44 switch( $method ){
45 case 'enc_ascii':
46 case 'rot13':
47 $mailto = EEB()->validate->encoding->encode_ascii( $mailto, $display );
48 break;
49 case 'enc_escape':
50 case 'escape':
51 $mailto = EEB()->validate->encoding->encode_escape( $mailto, $display );
52 break;
53 case 'with_javascript':
54 $mailto = EEB()->validate->encoding->dynamic_js_email_encoding( $mailto, $display );
55 break;
56 case 'without_javascript':
57 $mailto = EEB()->validate->encoding->encode_email_css( $mailto );
58 break;
59 case 'char_encode':
60 $mailto = EEB()->validate->filters->filter_plain_emails( $mailto, null, 'char_encode' );
61 break;
62 case 'strong_method':
63 $mailto = EEB()->validate->filters->filter_plain_emails( $mailto );
64 break;
65 case 'enc_html':
66 case 'encode':
67 default:
68 $mailto = '<a href="mailto:' . antispambot( $email ) . '"'. $class_name . '>' . antispambot( $display ) . '</a>';
69 break;
70 }
71
72 return apply_filters( 'eeb/frontend/template_func/eeb_mailto', $mailto );
73 }
74
75
76 /**
77 * Template function for encoding content
78 *
79 * @global Eeb_Site $Eeb_Site
80 * @param string $content
81 * @param string $method Optional, default null
82 * @return string
83 */
84 public function eeb_protect_content( string $content, ?string $method = null, ?string $protection_text = null ): string
85 {
86 if( empty( $protection_text ) ){
87 $protection_text = __( EEB()->settings->get_setting( 'protection_text', true ), 'email-encoder-bundle' );
88 } else {
89 $protection_text = wp_kses_post( $protection_text );
90 }
91
92 if( ! empty( $method ) ){
93 $method = sanitize_title( $method );
94 } else {
95 $method = 'rot13';
96 }
97
98 switch( $method ){
99 case 'enc_ascii':
100 case 'rot13':
101 $content = EEB()->validate->encoding->encode_ascii( $content, $protection_text );
102 break;
103 case 'enc_escape':
104 case 'escape':
105 $content = EEB()->validate->encoding->encode_escape( $content, $protection_text );
106 break;
107 case 'enc_html':
108 case 'encode':
109 default:
110 $content = antispambot( $content );
111 break;
112 }
113
114 return apply_filters( 'eeb/frontend/template_func/eeb_protect_content', $content );
115 }
116
117 /**
118 * Template function for encoding emails in the given content
119 *
120 * @global Eeb_Site $Eeb_Site
121 * @param string $content
122 * @param mixed $method
123 * @param boolean $enc_mailtos Optional, default true (deprectaed)
124 * @param boolean $enc_plain_emails Optional, default true (deprectaed)
125 * @param boolean $enc_input_fields Optional, default true (deprectaed)
126 * @return string
127 */
128 public function eeb_protect_emails( string $content, $method = null, bool $enc_mailtos = true, bool $enc_plain_emails = true, bool $enc_input_fields = true ): string
129 {
130
131 //backwards compatibility for enc tags
132 if( $method === null || is_bool( $method ) ){
133 $protect_using = (string) EEB()->settings->get_setting( 'protect_using', true );
134 } else {
135 $protect_using = sanitize_title( $method );
136 }
137
138 $content = EEB()->validate->filters->filter_content( $content, $protect_using );
139 return apply_filters( 'eeb/frontend/template_func/eeb_protect_emails', $content, $protect_using );
140 }
141 }
142