PluginProbe ʕ •ᴥ•ʔ
Check & Log Email – Easy Email Testing & Mail logging / 2.0.3
Check & Log Email – Easy Email Testing & Mail logging v2.0.3
2.0.15 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 2.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.13 2.0.13.1 2.0.13.2 2.0.14 2.0.2 2.0.3 2.0.4 2.0.5 2.0.5.1 2.0.6 2.0.7 2.0.8 2.0.9 trunk 0.5.7 0.6.0 0.6.1 0.6.2 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.12.1 1.0.13 1.0.13.1 1.0.2 1.0.3
check-email / include / helper-function.php
check-email / include Last commit date
Core 1 year ago Util 1 year ago Check_Email_Encode_Tab.php 1 year ago Check_Email_SMTP_Tab.php 1 year ago class-check-email-header-parser.php 1 year ago class-check-email-log-autoloader.php 1 year ago class-check-email-newsletter.php 1 year ago deactivate-feedback.php 1 year ago helper-function.php 1 year ago install.php 1 year ago
helper-function.php
874 lines
1 <?php
2
3 /**
4 * Helper Functions
5 *
6 * @package check-mail
7 * @subpackage Helper/Templates
8 * @copyright Copyright (c) 2016, René Hermenau
9 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
10 * @since 1.4.0
11 */
12 // Exit if accessed directly
13 if( !defined( 'ABSPATH' ) )
14 exit;
15
16 /**
17 * Helper method to check if user is in the plugins page.
18 *
19 * @author René Hermenau
20 * @since 1.4.0
21 *
22 * @return bool
23 */
24
25 /**
26 * display deactivation logic on plugins page
27 *
28 * @since 1.4.0
29 */
30 function ck_mail_is_plugins_page() {
31
32 if(function_exists('get_current_screen')){
33 $screen = get_current_screen();
34 if(is_object($screen)){
35 if($screen->id == 'plugins' || $screen->id == 'plugins-network'){
36 return true;
37 }
38 }
39 }
40 return false;
41 }
42
43 add_filter('admin_footer', 'ck_mail_add_deactivation_feedback_modal');
44
45 function ck_mail_add_deactivation_feedback_modal() {
46
47 if( is_admin() && ck_mail_is_plugins_page() ) {
48
49 require_once CK_MAIL_PATH ."/include/deactivate-feedback.php";
50 }
51
52 }
53
54 /**
55 * send feedback via email
56 *
57 * @since 1.4.0
58 */
59 function ck_mail_send_feedback() {
60 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: in form variable.
61 if( isset( $_POST['data'] ) ) {
62 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- Reason: in form variable.
63 parse_str( sanitize_text_field( wp_unslash($_POST['data'])), $form );
64 }
65
66 if( !isset( $form['ck_mail_security_nonce'] ) || isset( $form['ck_mail_security_nonce'] ) && !wp_verify_nonce( sanitize_text_field( $form['ck_mail_security_nonce'] ), 'ck_mail_ajax_check_nonce' ) ) {
67 echo esc_html__('security_nonce_not_verified', 'check-email');
68 die();
69 }
70 if ( !current_user_can( 'manage_options' ) ) {
71 die();
72 }
73
74 $text = '';
75 if( isset( $form['ck_mail_disable_text'] ) ) {
76 if (is_array($form['ck_mail_disable_text'])) {
77 $text = implode( " ", $form['ck_mail_disable_text'] );
78 }
79 }
80
81 $headers = array();
82
83 $from = isset( $form['ck_mail_disable_from'] ) ? $form['ck_mail_disable_from'] : '';
84 if( $from ) {
85 $headers[] = "From: $from";
86 $headers[] = "Reply-To: $from";
87 }
88
89 $subject = isset( $form['ck_mail_disable_reason'] ) ? $form['ck_mail_disable_reason'] : '(no reason given)';
90
91 if($subject == 'technical issue'){
92
93 $subject = 'Check & Log Email '.$subject;
94 $text = trim($text);
95
96 if(!empty($text)){
97
98 $text = 'technical issue description: '.$text;
99
100 }else{
101
102 $text = 'no description: '.$text;
103 }
104
105 }else{
106 $subject = 'Check & Log Email';
107 }
108
109 $success = wp_mail( 'team@magazine3.in', $subject, $text, $headers );
110
111 echo 'sent';
112 die();
113 }
114 add_action( 'wp_ajax_ck_mail_send_feedback', 'ck_mail_send_feedback' );
115
116
117 function ck_mail_enqueue_makebetter_email_js() {
118
119 if ( is_admin() && ck_mail_is_plugins_page() ) {
120
121 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
122
123 wp_register_script( 'ck_mail_make_better_js', CK_MAIL_URL . 'assets/js/admin/feedback'. $suffix .'.js', array( 'jquery' ), CK_MAIL_VERSION, true);
124 $data = array(
125 'ajax_url' => admin_url( 'admin-ajax.php' ),
126 'ck_mail_security_nonce' => wp_create_nonce('ck_mail_ajax_check_nonce'),
127 );
128
129 $data = apply_filters( 'ck_mail_localize_filter', $data, 'eztoc_admin_data' );
130
131 wp_localize_script( 'ck_mail_make_better_js', 'cn_ck_mail_admin_data', $data );
132 wp_enqueue_script( 'ck_mail_make_better_js' );
133 wp_enqueue_style( 'ck_mail_make_better_css', CK_MAIL_URL . 'assets/css/admin/feedback'. $suffix .'.css', array(), CK_MAIL_VERSION );
134
135 }
136
137 }
138 add_action( 'admin_enqueue_scripts', 'ck_mail_enqueue_makebetter_email_js' );
139
140
141 add_action('wp_ajax_ck_mail_subscribe_newsletter','ck_mail_subscribe_for_newsletter');
142
143 function ck_mail_subscribe_for_newsletter() {
144 if ( ! isset( $_POST['ck_mail_security_nonce'] ) ){
145 echo esc_html__('security_nonce_not_verified', 'check-email');
146 die();
147 }
148 if ( ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['ck_mail_security_nonce'] ) ), 'ck_mail_ajax_check_nonce' ) ) {
149 echo esc_html__('security_nonce_not_verified', 'check-email');
150 die();
151 }
152 if ( !current_user_can( 'manage_options' ) ) {
153 die();
154 }
155 if (isset( $_POST['name'] ) && isset( $_POST['email'] ) && isset( $_POST['website'] )) {
156 $api_url = 'http://magazine3.company/wp-json/api/central/email/subscribe';
157
158 $api_params = array(
159 'name' => sanitize_text_field(wp_unslash($_POST['name'])),
160 'email'=> sanitize_email(wp_unslash($_POST['email'])),
161 'website'=> sanitize_text_field(wp_unslash($_POST['website'])),
162 'type'=> 'checkmail'
163 );
164 wp_remote_post( $api_url, array( 'timeout' => 15, 'sslverify' => false, 'body' => $api_params ) );
165 }
166 wp_die();
167 }
168
169 function ck_mail_forward_mail($atts) {
170 if ( isset( $atts['to'] ) ) {
171 $to = $atts['to'];
172 if ( ! is_array( $to ) ) {
173 $to = explode( ',', $to );
174 }
175 }
176
177
178 if ( isset( $atts['subject'] ) ) {
179 $subject = $atts['subject'];
180 }
181
182 if ( isset( $atts['message'] ) ) {
183 $message = $atts['message'];
184 }
185
186 if ( isset( $atts['headers'] ) ) {
187 $headers = $atts['headers'];
188 }
189
190 if ( isset( $atts['attachments'] ) ) {
191 $attachments = $atts['attachments'];
192 }
193
194
195 $subject = esc_html__('Forward Email Check & Log ', 'check-email').$subject;
196
197 if ( ! is_array( $attachments ) ) {
198 $attachments = explode( "\n", str_replace( "\r\n", "\n", $attachments ) );
199 }
200 global $phpmailer;
201 if ( ! ( $phpmailer instanceof PHPMailer\PHPMailer\PHPMailer ) ) {
202 require_once ABSPATH . WPINC . '/PHPMailer/PHPMailer.php';
203 require_once ABSPATH . WPINC . '/PHPMailer/SMTP.php';
204 require_once ABSPATH . WPINC . '/PHPMailer/Exception.php';
205 $phpmailer = new PHPMailer\PHPMailer\PHPMailer( true );
206
207 $phpmailer::$validator = static function ( $email ) {
208 return (bool) is_email( $email );
209 };
210 }
211
212 // Headers.
213 $cc = array();
214 $bcc = array();
215 $reply_to = array();
216
217 if ( empty( $headers ) ) {
218 $headers = array();
219 } else {
220 if ( ! is_array( $headers ) ) {
221 $tempheaders = explode( "\n", str_replace( "\r\n", "\n", $headers ) );
222 } else {
223 $tempheaders = $headers;
224 }
225 $headers = array();
226
227 // If it's actually got contents.
228 if ( ! empty( $tempheaders ) ) {
229 // Iterate through the raw headers.
230 foreach ( (array) $tempheaders as $header ) {
231 if ( ! str_contains( $header, ':' ) ) {
232 if ( false !== stripos( $header, 'boundary=' ) ) {
233 $parts = preg_split( '/boundary=/i', trim( $header ) );
234 $boundary = trim( str_replace( array( "'", '"' ), '', $parts[1] ) );
235 }
236 continue;
237 }
238 // Explode them out.
239 list( $name, $content ) = explode( ':', trim( $header ), 2 );
240
241 // Cleanup crew.
242 $name = trim( $name );
243 $content = trim( $content );
244
245 switch ( strtolower( $name ) ) {
246 // Mainly for legacy -- process a "From:" header if it's there.
247 case 'from':
248 $bracket_pos = strpos( $content, '<' );
249 if ( false !== $bracket_pos ) {
250 // Text before the bracketed email is the "From" name.
251 if ( $bracket_pos > 0 ) {
252 $from_name = substr( $content, 0, $bracket_pos );
253 $from_name = str_replace( '"', '', $from_name );
254 $from_name = trim( $from_name );
255 }
256
257 $from_email = substr( $content, $bracket_pos + 1 );
258 $from_email = str_replace( '>', '', $from_email );
259 $from_email = trim( $from_email );
260
261 // Avoid setting an empty $from_email.
262 } elseif ( '' !== trim( $content ) ) {
263 $from_email = trim( $content );
264 }
265 break;
266 case 'content-type':
267 if ( str_contains( $content, ';' ) ) {
268 list( $type, $charset_content ) = explode( ';', $content );
269 $content_type = trim( $type );
270 if ( false !== stripos( $charset_content, 'charset=' ) ) {
271 $charset = trim( str_replace( array( 'charset=', '"' ), '', $charset_content ) );
272 } elseif ( false !== stripos( $charset_content, 'boundary=' ) ) {
273 $boundary = trim( str_replace( array( 'BOUNDARY=', 'boundary=', '"' ), '', $charset_content ) );
274 $charset = '';
275 }
276
277 // Avoid setting an empty $content_type.
278 } elseif ( '' !== trim( $content ) ) {
279 $content_type = trim( $content );
280 }
281 break;
282 case 'cc':
283 $cc = array_merge( (array) $cc, explode( ',', $content ) );
284 break;
285 case 'bcc':
286 $bcc = array_merge( (array) $bcc, explode( ',', $content ) );
287 break;
288 case 'reply-to':
289 $reply_to = array_merge( (array) $reply_to, explode( ',', $content ) );
290 break;
291 default:
292 // Add it to our grand headers array.
293 $headers[ trim( $name ) ] = trim( $content );
294 break;
295 }
296 }
297 }
298 }
299
300 // Empty out the values that may be set.
301 $phpmailer->clearAllRecipients();
302 $phpmailer->clearAttachments();
303 $phpmailer->clearCustomHeaders();
304 $phpmailer->clearReplyTos();
305 $phpmailer->Body = '';
306 $phpmailer->AltBody = '';
307
308 // Set "From" name and email.
309
310 // If we don't have a name from the input headers.
311 if ( ! isset( $from_name ) ) {
312 $from_name = 'WordPress';
313 }
314 if ( ! isset( $from_email ) ) {
315 // Get the site domain and get rid of www.
316 $sitename = wp_parse_url( network_home_url(), PHP_URL_HOST );
317 $from_email = 'wordpress@';
318
319 if ( null !== $sitename ) {
320 if ( str_starts_with( $sitename, 'www.' ) ) {
321 $sitename = substr( $sitename, 4 );
322 }
323
324 $from_email .= $sitename;
325 }
326 }
327
328 try {
329 $phpmailer->setFrom( $from_email, $from_name, false );
330 } catch ( PHPMailer\PHPMailer\Exception $e ) {
331 error_log(esc_html__('Error in forwar email check & log : ', 'check-email').$e->getMessage());
332 return false;
333 }
334
335 // Set mail's subject and body.
336 $phpmailer->Subject = $subject;
337 $phpmailer->Body = $message;
338
339 // Set destination addresses, using appropriate methods for handling addresses.
340 $address_headers = compact( 'to', 'cc', 'bcc', 'reply_to' );
341
342 foreach ( $address_headers as $address_header => $addresses ) {
343 if ( empty( $addresses ) ) {
344 continue;
345 }
346
347 foreach ( (array) $addresses as $address ) {
348 try {
349 // Break $recipient into name and address parts if in the format "Foo <bar@baz.com>".
350 $recipient_name = '';
351
352 if ( preg_match( '/(.*)<(.+)>/', $address, $matches ) ) {
353 if ( count( $matches ) === 3 ) {
354 $recipient_name = $matches[1];
355 $address = $matches[2];
356 }
357 }
358
359 switch ( $address_header ) {
360 case 'to':
361 $phpmailer->addAddress( $address, $recipient_name );
362 break;
363 case 'cc':
364 $phpmailer->addCc( $address, $recipient_name );
365 break;
366 case 'bcc':
367 $phpmailer->addBcc( $address, $recipient_name );
368 break;
369 case 'reply_to':
370 $phpmailer->addReplyTo( $address, $recipient_name );
371 break;
372 }
373 } catch ( PHPMailer\PHPMailer\Exception $e ) {
374 continue;
375 }
376 }
377 }
378
379 // Set to use PHP's mail().
380 $phpmailer->isMail();
381
382 // Set Content-Type and charset.
383
384 // If we don't have a Content-Type from the input headers.
385 if ( ! isset( $content_type ) ) {
386 $content_type = 'text/html';
387 }
388
389
390 $content_type = apply_filters( 'wp_mail_content_type', $content_type );
391
392 $phpmailer->ContentType = $content_type;
393
394 // Set whether it's plaintext, depending on $content_type.
395 if ( 'text/html' === $content_type ) {
396 $phpmailer->isHTML( true );
397 }
398
399 // If we don't have a charset from the input headers.
400 if ( ! isset( $charset ) ) {
401 $charset = get_bloginfo( 'charset' );
402 }
403
404
405 $phpmailer->CharSet = apply_filters( 'wp_mail_charset', $charset );
406
407 // Set custom headers.
408 if ( ! empty( $headers ) ) {
409 foreach ( (array) $headers as $name => $content ) {
410 // Only add custom headers not added automatically by PHPMailer.
411 if ( ! in_array( $name, array( 'MIME-Version', 'X-Mailer' ), true ) ) {
412 try {
413 $phpmailer->addCustomHeader( sprintf( '%1$s: %2$s', $name, $content ) );
414 } catch ( PHPMailer\PHPMailer\Exception $e ) {
415 continue;
416 }
417 }
418 }
419
420 if ( false !== stripos( $content_type, 'multipart' ) && ! empty( $boundary ) ) {
421 $phpmailer->addCustomHeader( sprintf( 'Content-Type: %s; boundary="%s"', $content_type, $boundary ) );
422 }
423 }
424
425 if ( ! empty( $attachments ) ) {
426 foreach ( $attachments as $filename => $attachment ) {
427 $filename = is_string( $filename ) ? $filename : '';
428
429 try {
430 $phpmailer->addAttachment( $attachment, $filename );
431 } catch ( PHPMailer\PHPMailer\Exception $e ) {
432 continue;
433 }
434 }
435 }
436
437 /**
438 * Fires after PHPMailer is initialized.
439 *
440 * @since 2.2.0
441 *
442 * @param PHPMailer $phpmailer The PHPMailer instance (passed by reference).
443 */
444 do_action_ref_array( 'phpmailer_init', array( &$phpmailer ) );
445
446 $mail_data = compact( 'to', 'subject', 'message', 'headers', 'attachments' );
447
448 // Send!
449 try {
450 $send = $phpmailer->send();
451 return $send;
452 } catch ( PHPMailer\PHPMailer\Exception $e ) {
453 error_log(esc_html__('Error in forwar email send check & log : ', 'check-email').$e->getMessage());
454 return false;
455 }
456 }
457
458 function ck_mail_create_error_logs() {
459
460 global $wpdb;
461
462 $table_name = $wpdb->prefix . 'check_email_error_logs';
463 $charset_collate = $wpdb->get_charset_collate();
464 // phpcs:disable.
465 if ( $wpdb->get_var( $wpdb->prepare( "show tables like %s",$wpdb->esc_like( $table_name )) ) != $table_name ) {
466
467 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
468 `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
469 `check_email_log_id` INT DEFAULT NULL,
470 `content` TEXT DEFAULT NULL,
471 `initiator` TEXT DEFAULT NULL,
472 `event_type` TINYINT UNSIGNED NOT NULL DEFAULT '0',
473 `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
474 PRIMARY KEY (id)
475 )
476 ENGINE='InnoDB'
477 {$charset_collate};";
478
479 $wpdb->query($sql);
480 }
481 // phpcs:enable.
482 }
483
484 function ck_mail_insert_error_logs($data_to_insert) {
485
486 global $wpdb;
487
488 $table_name = $wpdb->prefix . 'check_email_error_logs';
489 $wpdb->insert( $table_name, $data_to_insert ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.NotPrepared
490 }
491
492 function ck_mail_local_file_get_contents($file_path){
493
494 // Include WordPress Filesystem API
495 if ( ! function_exists( 'WP_Filesystem' ) ) {
496 require_once( ABSPATH . 'wp-admin/includes/file.php' );
497 }
498
499 // Initialize the API
500 global $wp_filesystem;
501 if ( ! WP_Filesystem() ) {
502 return false;
503 }
504 // Check if the file exists
505 if ( $wp_filesystem->exists( $file_path ) ) {
506 // Read the file content
507 $file_content = $wp_filesystem->get_contents( $file_path );
508 return $file_content;
509 } else {
510 return false;
511 }
512
513 }
514
515 function ck_mail_update_network_settings() {
516 // Check nonce
517 check_ajax_referer( 'ck_mail_ajax_check_nonce', 'nonce' );
518
519 // Check if user is allowed to manage network options
520 if ( ! current_user_can( 'manage_check_email' ) ) {
521 wp_send_json_error(esc_html__('Unauthorized user', 'check-email') );
522 return;
523 }
524 if ( isset( $_POST['check-email-log-global'] ) ) {
525 $all_fields = array_map('sanitize_text_field', wp_unslash($_POST['check-email-log-global']));
526
527 // Sanitize all the key
528 if ( ! empty( $all_fields ) ) {
529 foreach ($all_fields as $key => $value) {
530 $all_fields[sanitize_key( $key ) ] = sanitize_text_field( $value );
531 }
532 $all_fields['enable_smtp'] = 1;
533
534 if (!isset($all_fields['enable_global'])) {
535 $all_fields['enable_global'] = 0;
536 }
537 $old_settings = get_site_option('check-email-log-global-smtp');
538
539 if ( ! empty( $old_settings ) && is_array( $old_settings ) ) {
540 $updated_settings = array_merge( $old_settings, $all_fields );
541 } else {
542 $updated_settings = $all_fields;
543 }
544 update_site_option( 'check-email-log-global-smtp', $updated_settings );
545 if ( isset($all_fields['mailer'] ) == 'outlook' && isset( $_POST['check-email-outlook-options'] ) ) {
546 $outlook_fields = array_map('sanitize_text_field', wp_unslash($_POST['check-email-outlook-options']));
547 if(isset($outlook_fields['client_id']) && !empty($outlook_fields['client_id'])){
548 $outlook_option['client_id'] = base64_encode($outlook_fields['client_id']);
549 }
550 if(isset($outlook_fields['client_secret']) && !empty($outlook_fields['client_secret'])){
551 $outlook_option['client_secret'] = base64_encode($outlook_fields['client_secret']);
552 }
553 $auth = new CheckEmail\Core\Auth( 'outlook' );
554 $auth->update_mailer_option( $outlook_option );
555 }
556 wp_send_json_success();
557 }
558 } else {
559 wp_send_json_error(esc_html__('Invalid input', 'check-email') );
560 }
561 }
562
563 add_action( 'wp_ajax_update_network_settings', 'ck_mail_update_network_settings' );
564
565
566 // email and phone encoding start
567 /**
568 * Define filter-priority constant, unless it has already been defined.
569 */
570 if ( ! defined( 'CHECK_EMAIL_E_FILTER_PRIORITY' ) ) {
571 define(
572 'CHECK_EMAIL_E_FILTER_PRIORITY',
573 (integer) get_option( 'check_email_e_filter_priority', 2000 )
574 );
575 }
576
577 if ( ! defined( 'CHECK_EMAIL_E_REGEXP' ) ) {
578 define(
579 'CHECK_EMAIL_E_REGEXP',
580 '{
581 (?:mailto:)? # Optional mailto:
582 (?:
583 [-!#$%&*+/=?^_`.{|}~\w\x80-\xFF]+ # Local part before @
584 |
585 ".*?" # Quoted local part
586 )
587 \@ # At sign (@)
588 (?:
589 [-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+ # Domain name
590 |
591 \[[\d.a-fA-F:]+\] # IPv4/IPv6 address
592 )
593 }xi'
594 );
595 }
596
597
598 $encode_options = get_option('check-email-email-encode-options', true);
599 $is_enable = ( isset( $encode_options['is_enable'] ) ) ? $encode_options['is_enable'] : 0;
600 $email_using = ( isset( $encode_options['email_using'] ) ) ? $encode_options['email_using'] : "";
601 if ( $is_enable && $email_using == 'filters' ) {
602 foreach ( array( 'the_content', 'the_excerpt', 'widget_text', 'comment_text', 'comment_excerpt' ) as $filter ) {
603 add_filter( $filter, 'check_email_e_encode_emails', CHECK_EMAIL_E_FILTER_PRIORITY );
604 }
605 }
606 if ( $is_enable && $email_using == 'full_page' ) {
607 add_action( 'wp', 'check_email_full_page_scanner',999 );
608 }
609
610 add_action( 'init', 'check_email_e_register_shortcode', 2000 );
611
612 function check_email_e_register_shortcode() {
613 if ( ! shortcode_exists( 'checkmail-encode' ) ) {
614 add_shortcode( 'checkmail-encode', 'check_email_e_shortcode' );
615 }
616 }
617
618 function check_email_rot47($str) {
619 $rotated = '';
620 foreach (str_split($str) as $char) {
621 $ascii = ord($char);
622 if ($ascii >= 33 && $ascii <= 126) {
623 $rotated .= chr(33 + (($ascii + 14) % 94));
624 } else {
625 $rotated .= $char;
626 }
627 }
628 return $rotated;
629 }
630
631 function check_email_encode_str( $string, $hex = false ) {
632 $encode_options = get_option('check-email-email-encode-options', true);
633 $email_technique = ( isset( $encode_options['email_technique'] ) ) ? $encode_options['email_technique'] : "";
634 if (strpos($string, 'mailto:') !== false) {
635 $string = str_replace('mailto:', '', $string);
636 switch ($email_technique) {
637 case 'css_direction':
638 $reversed_email = strrev($string);
639 // Wrap it with the span and necessary CSS
640 return 'mailto:'.esc_html($reversed_email);
641 break;
642 case 'rot_13':
643 $encoded_email = check_email_rot13($string);
644 return 'mailto:'.esc_html($encoded_email);
645 break;
646 case 'rot_47':
647 $encoded_email = check_email_rot47($string);
648 return 'mailto:'.esc_html($encoded_email);
649 break;
650
651 default:
652 # code...
653 break;
654 }
655 }else{
656 switch ($email_technique) {
657 case 'css_direction':
658 $reversed_email = strrev($string);
659 // Wrap it with the span and necessary CSS
660 return ' <span style="direction: rtl; unicode-bidi: bidi-override;">' . esc_html($reversed_email) . '</span>';
661 break;
662 case 'rot_13':
663 $encoded_email = check_email_rot13($string);
664 return ' <span class="check-email-encoded-email" >' . esc_html($encoded_email).' </span>';
665 break;
666 case 'rot_47':
667 $encoded_email = check_email_rot47($string);
668 return ' <span class="check-email-rot47-email" >' . esc_html($encoded_email).' </span>';
669 break;
670
671 default:
672 # code...
673 break;
674 }
675 }
676
677
678 $chars = str_split( $string );
679 $seed = wp_rand( 0, (int) abs( crc32( $string ) / strlen( $string ) ) );
680
681
682 foreach ( $chars as $key => $char ) {
683 $ord = ord( $char );
684
685 if ( $ord < 128 ) { // ignore non-ascii chars
686 $r = ( $seed * ( 1 + $key ) ) % 100; // pseudo "random function"
687
688 if ( $r > 75 && $char !== '@' && $char !== '.' ); // plain character (not encoded), except @-signs and dots
689 else if ( $hex && $r < 25 ) $chars[ $key ] = '%' . bin2hex( $char ); // hex
690 else if ( $r < 45 ) $chars[ $key ] = '&#x' . dechex( $ord ) . ';'; // hexadecimal
691 else $chars[ $key ] = "&#{$ord};"; // decimal (ascii)
692 }
693 }
694
695 return implode( '', $chars );
696 }
697
698 function check_email_e_shortcode( $attributes, $content = '' ) {
699 $atts = shortcode_atts( array(
700 'link' => null,
701 'class' => null,
702 ), $attributes, 'checkmail-encode' );
703
704
705 $method = apply_filters( 'check_email_e_method', 'check_email_encode_str' );
706
707 if ( ! empty( $atts[ 'link' ] ) ) {
708 $link = esc_url( $atts[ 'link' ], null, 'shortcode' );
709
710 if ( $link === '' ) {
711 return $method( $content );
712 }
713
714 if ( empty( $atts[ 'class' ] ) ) {
715 return sprintf(
716 '<a href="%s">%s</a>',
717 $method( $link ),
718 $method( $content )
719 );
720 }
721
722 return sprintf(
723 '<a href="%s" class="%s">%s</a>',
724 $method( $link ),
725 esc_attr( $atts[ 'class' ] ),
726 $method( $content )
727 );
728 }
729
730 return $method( $content );
731 }
732
733 function check_email_e_encode_emails( $string ) {
734 if ( ! is_string( $string ) ) {
735 return $string;
736 }
737 // abort if `check_email_e_at_sign_check` is true and `$string` doesn't contain a @-sign
738 if ( apply_filters( 'check_email_e_at_sign_check', true ) && strpos( $string, '@' ) === false ) {
739 return $string;
740 }
741 // override encoding function with the 'check_email_e_method' filter
742 $method = apply_filters( 'check_email_e_method', 'check_email_encode_str' );
743
744 $regexp = apply_filters( 'check_email_e_regexp', CHECK_EMAIL_E_REGEXP );
745
746 $callback = function ( $matches ) use ( $method ) {
747 return $method( $matches[ 0 ] );
748 };
749
750 if ( has_filter( 'check_email_e_callback' ) ) {
751 $callback = apply_filters( 'check_email_e_callback', $callback, $method );
752 return preg_replace_callback( $regexp, $callback, $string );
753 }
754
755 return preg_replace_callback( $regexp, $callback, $string );
756 }
757
758 function check_email_full_page_scanner() {
759 if(!is_admin() ) {
760 ob_start('check_email_full_page_callback');
761 }
762 }
763 function check_email_full_page_callback($string) {
764 return check_email_e_encode_emails($string);
765 }
766
767
768 add_action( 'wp_enqueue_scripts', 'ck_mail_enqueue_encoder_js' );
769
770 function ck_mail_enqueue_encoder_js() {
771 $encode_options = get_option('check-email-email-encode-options', true);
772 $is_enable = ( isset( $encode_options['is_enable'] ) ) ? $encode_options['is_enable'] : 0;
773 if ( $is_enable ) {
774 $email_using = ( isset( $encode_options['email_using'] ) ) ? $encode_options['email_using'] : "";
775 $email_technique = ( isset( $encode_options['email_technique'] ) ) ? $encode_options['email_technique'] : "";
776
777 $check_email = wpchill_check_email();
778 $plugin_dir_url = plugin_dir_url( $check_email->get_plugin_file() );
779 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
780 wp_register_script( 'checkemail_encoder', $plugin_dir_url . 'assets/js/check-email-front'. $suffix .'.js', array(), $check_email->get_version(), true );
781 $data = array();
782 $data['email_using'] = $email_using;
783 $data['is_enable'] = $is_enable;
784 $data['email_technique'] = $email_technique;
785
786 wp_localize_script( 'checkemail_encoder', 'checkemail_encoder_data', $data );
787 wp_enqueue_script( 'checkemail_encoder' );
788 }
789 }
790
791 function check_email_rot13( $string ) {
792
793 $from = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
794 $to = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
795
796 return strtr( $string, $from, $to );
797 }
798
799 // email and phone encoding end
800
801 function check_email_track_email_open() {
802 if (isset($_GET['action']) && $_GET['action'] === 'check_email_track_email_open' && isset($_GET['open_tracking_id']) && isset($_GET['_wpnonce'])) {
803 if (!check_email_verify_extended_nonce($_GET['_wpnonce'])) {
804 return false;
805 }
806 $open_tracking_id = absint($_GET['open_tracking_id']);
807
808 if ($open_tracking_id) {
809 global $wpdb;
810 $table_name = $wpdb->prefix . 'check_email_log';
811
812 $query = $wpdb->prepare(
813 "SELECT * FROM {$table_name} WHERE open_tracking_id = %s",
814 $open_tracking_id
815 );
816
817 $record = $wpdb->get_row($query);
818
819 if ($record) {
820 $data_to_update = [
821 'open_count' => $record->open_count + 1
822 ];
823 $where = [
824 'open_tracking_id' => $open_tracking_id,
825 ];
826 $wpdb->update( $table_name, $data_to_update, $where );
827 header("Content-Type: image/png");
828 echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wcAAgMBAptL0ygAAAAASUVORK5CYII=');
829 exit;
830 }
831
832 }
833 }
834
835 }
836 add_action('init', 'check_email_track_email_open');
837
838 function check_email_generate_extended_nonce($action = -1, $lifetime = WEEK_IN_SECONDS) {
839 $i = wp_nonce_tick() - (floor(time() / $lifetime) - floor(time() / (DAY_IN_SECONDS * 2)));
840 return wp_create_nonce($action . $i);
841 }
842
843 function check_email_verify_extended_nonce($nonce, $action = -1, $lifetime = WEEK_IN_SECONDS) {
844 $i = wp_nonce_tick() - (floor(time() / $lifetime) - floor(time() / (DAY_IN_SECONDS * 2)));
845
846 if (wp_verify_nonce($nonce, $action . $i)) {
847 return true;
848 }
849 if (wp_verify_nonce($nonce, $action . ($i - 1))) {
850 return true;
851 }
852 return false;
853 }
854
855 function check_email_content_with_tracking($open_tracking_id) {
856 $nonce = check_email_generate_extended_nonce();
857 $tracking_url = add_query_arg(
858 array(
859 '_wpnonce'=>$nonce,
860 'open_tracking_id' => $open_tracking_id,
861 'action' => 'check_email_track_email_open',
862 ),
863 site_url('/check-email-tracking/')
864 );
865 $tracking_url = esc_url_raw($tracking_url);
866 $email_content = "
867 <img src='$tracking_url' class='check-email-tracking' alt='' width='1' height='1' style='display:none;' />
868 ";
869 return $email_content;
870 }
871
872
873
874