PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 2.2.0
Email Encoder – Protect Email Addresses and Phone Numbers v2.2.0
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 / integrations / classes / foggy_email.php
email-encoder-bundle / core / includes / integrations / classes Last commit date
avada_builder.php 2 years ago bricks_builder.php 2 years ago divi_theme.php 2 years ago foggy_email.php 2 years ago google_site_kit.php 2 years ago maintenance.php 2 years ago oxygen_builder.php 2 years ago the_events_calendar.php 2 years ago
foggy_email.php
303 lines
1 <?php
2
3 // Exit if accessed directly.
4 if ( !defined( 'ABSPATH' ) ) exit;
5
6 if( ! class_exists( 'Email_Encoder_Integration_FoggyEmail' ) ){
7
8 /**
9 * Class Email_Encoder_Integration_FoggyEmail
10 *
11 * This class integrates support for the oxygen page builder https://oxygenbuilder.com/
12 *
13 * @since 2.0.6
14 * @package EEB
15 * @author Ironikus <info@ironikus.com>
16 */
17
18 class Email_Encoder_Integration_FoggyEmail{
19
20 /**
21 * The main page name for our admin page
22 *
23 * @var string
24 * @since 2.0.6
25 */
26 private $page_name;
27
28 /**
29 * The main page title for our admin page
30 *
31 * @var string
32 * @since 2.0.6
33 */
34 private $page_title;
35
36 /**
37 * Our Email_Encoder_Run constructor.
38 */
39 function __construct(){
40 $this->page_name = EEB()->settings->get_page_name();
41 $this->page_title = EEB()->settings->get_page_title();
42 $this->foggy_key = 'foggy_email_emails';
43 $this->foggy_emails = $this->load_foggy_emails();
44 $this->api_endpoint = 'https://foggy.email/api/';
45 $this->add_hooks();
46 }
47
48 /**
49 * ######################
50 * ###
51 * #### HELPERS
52 * ###
53 * ######################
54 */
55
56 public function is_active(){
57 return false; //Got discontinued
58 }
59
60 /**
61 * ######################
62 * ###
63 * #### FOGGY EMAILS
64 * ###
65 * ######################
66 */
67
68 public function load_foggy_emails(){
69
70 $return = array();
71 $emails = get_option( $this->foggy_key );
72 if( ! empty( $emails ) && is_array( $emails ) ){
73 $return = $emails;
74 } else {
75 if( ! is_array( $emails ) ){
76 $emails = array();
77 }
78 }
79
80 return $return;
81 }
82
83 /**
84 * Define all of our necessary hooks
85 */
86 private function add_hooks(){
87 add_filter( 'eeb/settings/pre_filter_fields', array( $this, 'load_foggy_email_settings' ), 10 );
88 add_filter( 'eeb/validate/filter_page_content', array( $this, 'disguise_emails' ), 10, 2 );
89 add_filter( 'eeb/validate/filter_content_content', array( $this, 'disguise_emails' ), 10, 2 );
90 add_action( 'init', array( $this, 'maybe_deactivate_foggy_email' ), 5 );
91 #add_action( 'init', array( $this, 'reload_settings' ), 5 );
92 }
93
94 /**
95 * ######################
96 * ###
97 * #### CORE LOGIC
98 * ###
99 * ######################
100 */
101
102 public function maybe_deactivate_foggy_email(){
103 $foggy_email_api_key = (string) EEB()->settings->get_setting( 'foggy_email_api_key', true );
104 $emails = get_option( $this->foggy_key );
105
106 //Make sure after deactivating the logic, the emails get removed as well
107 if( empty( $foggy_email_api_key ) && ! empty( $emails ) ){
108
109 //Allow a hard reset of the added emails
110 if( isset( $_GET['eeb_fggy_email_clear_entries'] ) && current_user_can( 'manage_options' ) ){
111 $emails = null;
112 }
113
114 if( is_array( $emails ) ){
115 foreach( $emails as $key => $mail ){
116 if( isset( $mail['alias'] ) && isset( $mail['api_key'] ) ){
117 $alias = $mail['alias'];
118 $api_key = base64_decode( $mail['api_key'] );
119
120 if( ! empty( $alias ) && ! empty( $api_key ) ){
121 $check = $this->delete_foggy_email( $api_key, $alias );
122 if( $check ){
123 unset( $emails[ $key ] );
124 }
125 }
126 }
127 }
128 }
129
130 if( empty( $emails ) ){
131 delete_option( $this->foggy_key );
132 } else {
133 update_option( $this->foggy_key, $emails );
134 }
135 }
136 }
137
138 public function disguise_emails( $content, $protect_using ){
139 $foggy_email_api_key = (string) EEB()->settings->get_setting( 'foggy_email_api_key', true );
140
141 //Shorten circuit if nothing is set
142 if( empty( $foggy_email_api_key ) ){
143 return $content;
144 }
145
146 $self = $this;
147 $content = EEB()->validate->filter_plain_emails( $content, function ( $match ) use ( $self ) {
148 return $self->get_disguised_email( $match[0] );
149 }, 'no_encoding', false);
150
151 return $content;
152 }
153
154 public function get_disguised_email( $email ){
155
156 if( ! is_email( $email ) || strpos( $email, 'neat.email' ) !== FALSE ){
157 return $email;
158 }
159
160 $email_key = base64_encode( $email );
161 if( isset( $this->foggy_emails[ $email_key ] ) ){
162 $alias_email = $this->foggy_emails[ $email_key ]['alias_email'];
163
164 if( ! empty( $alias_email ) ){
165 if( is_email( $alias_email ) ){
166 $email = $alias_email;
167 }
168 }
169 } else {
170 $email = $this->create_foggy_email( $email );
171 }
172
173 return $email;
174 }
175
176 public function create_foggy_email( $email ){
177 $foggy_email_api_key = (string) EEB()->settings->get_setting( 'foggy_email_api_key', true );
178
179 $return = $email;
180 $args = array(
181 'foggyemail_api' => 'create_alias'
182 );
183 $endpoint = EEB()->helpers->built_url( $this->api_endpoint, $args );
184
185 $http_args = array(
186 'method' => 'POST',
187 'timeout' => 45,
188 'blocking' => true,
189 'headers' => array(
190 'Content-Type' => 'application/json'
191 ),
192 'body' => json_encode( array(
193 'foggyemail_ussauth' => $foggy_email_api_key,
194 'email' => $email,
195 ) ),
196 'cookies' => array()
197 );
198 $http_args = apply_filters( 'eeb/integrations/foggy_email/http_args', $http_args, $email );
199
200 $response = wp_remote_post( $endpoint, $http_args );
201
202 if ( ! is_wp_error( $response ) && isset( $response['body'] ) ) {
203 $response_data = json_decode( $response['body'], true );
204 if( ! empty( $response_data ) ){
205 if( isset( $response_data['success'] ) && $response_data['success'] == 'true' ){
206 if( isset( $response_data['data'] ) && isset( $response_data['data']['alias'] ) && isset( $response_data['data']['domain'] ) ){
207 $email_key = base64_encode( $email );
208 $this->foggy_emails[ $email_key ] = array(
209 'email' => $email,
210 'alias' => $response_data['data']['alias'],
211 'alias_email' => $response_data['data']['alias_email'],
212 'domain' => $response_data['data']['domain'],
213 'date' => date( "Y-m-d H:i:s" ),
214 'api_key' => base64_encode( $foggy_email_api_key )
215 );
216
217 update_option( $this->foggy_key, $this->foggy_emails );
218 $return = $response_data['data']['alias_email'];
219 }
220 }
221 }
222 }
223
224 return $return;
225 }
226
227 public function delete_foggy_email( $foggy_email_api_key, $alias ){
228
229 $return = false;
230 $args = array(
231 'foggyemail_api' => 'delete_alias'
232 );
233 $endpoint = EEB()->helpers->built_url( $this->api_endpoint, $args );
234
235 $http_args = array(
236 'method' => 'POST',
237 'timeout' => 45,
238 'blocking' => true,
239 'headers' => array(
240 'Content-Type' => 'application/json'
241 ),
242 'body' => json_encode( array(
243 'foggyemail_ussauth' => $foggy_email_api_key,
244 'alias' => $alias,
245 ) ),
246 'cookies' => array()
247 );
248 $response = wp_remote_post( $endpoint, $http_args );
249
250 if ( ! is_wp_error( $response ) && isset( $response['body'] ) ) {
251 $response_data = json_decode( $response['body'], true );
252 if( ! empty( $response_data ) ){
253 if( isset( $response_data['success'] ) && $response_data['success'] == 'true' ){
254 $return = true;
255 }
256 }
257 }
258
259 return $return;
260 }
261
262 /**
263 * ######################
264 * ###
265 * #### SCRIPTS & STYLES
266 * ###
267 * ######################
268 */
269
270 public function reload_settings(){
271 EEB()->settings->reload_settings();
272 }
273
274 public function load_foggy_email_settings( $fields ){
275
276 $slug = 'foggy_email_api_key';
277 $new_field = array(
278 'fieldset' => array( 'slug' => 'main', 'label' => 'Label' ),
279 'id' => $slug,
280 'type' => 'text',
281 'advanced' => false,
282 'title' => __('Foggy Email API Key', 'email-encoder-bundle'),
283 'placeholder' => '',
284 'required' => false,
285 'description' => __('Create anonymous emails using <a title="Visit Foggy Email" target="_blank" href="https://foggy.email">https://foggy.email</a> - This will turn every of your emails into a disguised email. For example: <strong>you@example.com</strong> turns into <strong>luhhsd@neat.email</strong>, which will forward every email to <strong>you@example.com</strong>', 'email-encoder-bundle')
286 );
287
288 if( is_array( $fields ) ){
289 if( ! isset( $fields[ $slug ] ) ){
290 $fields[ $slug ] = $new_field;
291 }
292 }
293
294 return $fields;
295
296 }
297
298
299 }
300
301 new Email_Encoder_Integration_FoggyEmail();
302 }
303