PluginProbe ʕ •ᴥ•ʔ
Check & Log Email – Easy Email Testing & Mail logging / 2.0.2
Check & Log Email – Easy Email Testing & Mail logging v2.0.2
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
797 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 $old_settings = get_site_option('check-email-log-global-smtp');
534
535 if ( ! empty( $old_settings ) && is_array( $old_settings ) ) {
536 $updated_settings = array_merge( $old_settings, $all_fields );
537 } else {
538 $updated_settings = $all_fields;
539 }
540 update_site_option( 'check-email-log-global-smtp', $updated_settings );
541 if ( isset($all_fields['mailer'] ) == 'outlook' && isset( $_POST['check-email-outlook-options'] ) ) {
542 $outlook_fields = array_map('sanitize_text_field', wp_unslash($_POST['check-email-outlook-options']));
543 if(isset($outlook_fields['client_id']) && !empty($outlook_fields['client_id'])){
544 $outlook_option['client_id'] = base64_encode($outlook_fields['client_id']);
545 }
546 if(isset($outlook_fields['client_secret']) && !empty($outlook_fields['client_secret'])){
547 $outlook_option['client_secret'] = base64_encode($outlook_fields['client_secret']);
548 }
549 $auth = new CheckEmail\Core\Auth( 'outlook' );
550 $auth->update_mailer_option( $outlook_option );
551 }
552 wp_send_json_success();
553 }
554 } else {
555 wp_send_json_error(esc_html__('Invalid input', 'check-email') );
556 }
557 }
558
559 add_action( 'wp_ajax_update_network_settings', 'ck_mail_update_network_settings' );
560
561
562 // email and phone encoding start
563 /**
564 * Define filter-priority constant, unless it has already been defined.
565 */
566 if ( ! defined( 'CHECK_EMAIL_E_FILTER_PRIORITY' ) ) {
567 define(
568 'CHECK_EMAIL_E_FILTER_PRIORITY',
569 (integer) get_option( 'check_email_e_filter_priority', 2000 )
570 );
571 }
572
573 if ( ! defined( 'CHECK_EMAIL_E_REGEXP' ) ) {
574 define(
575 'CHECK_EMAIL_E_REGEXP',
576 '{
577 (?:mailto:)? # Optional mailto:
578 (?:
579 [-!#$%&*+/=?^_`.{|}~\w\x80-\xFF]+ # Local part before @
580 |
581 ".*?" # Quoted local part
582 )
583 \@ # At sign (@)
584 (?:
585 [-a-z0-9\x80-\xFF]+(\.[-a-z0-9\x80-\xFF]+)*\.[a-z]+ # Domain name
586 |
587 \[[\d.a-fA-F:]+\] # IPv4/IPv6 address
588 )
589 }xi'
590 );
591 }
592
593
594 $encode_options = get_option('check-email-email-encode-options', true);
595 $is_enable = ( isset( $encode_options['is_enable'] ) ) ? $encode_options['is_enable'] : 0;
596 $email_using = ( isset( $encode_options['email_using'] ) ) ? $encode_options['email_using'] : "";
597 if ( $is_enable && $email_using == 'filters' ) {
598 foreach ( array( 'the_content', 'the_excerpt', 'widget_text', 'comment_text', 'comment_excerpt' ) as $filter ) {
599 add_filter( $filter, 'check_email_e_encode_emails', CHECK_EMAIL_E_FILTER_PRIORITY );
600 }
601 }
602 if ( $is_enable && $email_using == 'full_page' ) {
603 add_action( 'wp', 'check_email_full_page_scanner',999 );
604 }
605
606 add_action( 'init', 'check_email_e_register_shortcode', 2000 );
607
608 function check_email_e_register_shortcode() {
609 if ( ! shortcode_exists( 'checkmail-encode' ) ) {
610 add_shortcode( 'checkmail-encode', 'check_email_e_shortcode' );
611 }
612 }
613
614 function check_email_rot47($str) {
615 $rotated = '';
616 foreach (str_split($str) as $char) {
617 $ascii = ord($char);
618 if ($ascii >= 33 && $ascii <= 126) {
619 $rotated .= chr(33 + (($ascii + 14) % 94));
620 } else {
621 $rotated .= $char;
622 }
623 }
624 return $rotated;
625 }
626
627 function check_email_encode_str( $string, $hex = false ) {
628 $encode_options = get_option('check-email-email-encode-options', true);
629 $email_technique = ( isset( $encode_options['email_technique'] ) ) ? $encode_options['email_technique'] : "";
630 if (strpos($string, 'mailto:') !== false) {
631 $string = str_replace('mailto:', '', $string);
632 switch ($email_technique) {
633 case 'css_direction':
634 $reversed_email = strrev($string);
635 // Wrap it with the span and necessary CSS
636 return 'mailto:'.esc_html($reversed_email);
637 break;
638 case 'rot_13':
639 $encoded_email = check_email_rot13($string);
640 return 'mailto:'.esc_html($encoded_email);
641 break;
642 case 'rot_47':
643 $encoded_email = check_email_rot47($string);
644 return 'mailto:'.esc_html($encoded_email);
645 break;
646
647 default:
648 # code...
649 break;
650 }
651 }else{
652 switch ($email_technique) {
653 case 'css_direction':
654 $reversed_email = strrev($string);
655 // Wrap it with the span and necessary CSS
656 return ' <span style="direction: rtl; unicode-bidi: bidi-override;">' . esc_html($reversed_email) . '</span>';
657 break;
658 case 'rot_13':
659 $encoded_email = check_email_rot13($string);
660 return ' <span class="check-email-encoded-email" >' . esc_html($encoded_email).' </span>';
661 break;
662 case 'rot_47':
663 $encoded_email = check_email_rot47($string);
664 return ' <span class="check-email-rot47-email" >' . esc_html($encoded_email).' </span>';
665 break;
666
667 default:
668 # code...
669 break;
670 }
671 }
672
673
674 $chars = str_split( $string );
675 $seed = wp_rand( 0, (int) abs( crc32( $string ) / strlen( $string ) ) );
676
677
678 foreach ( $chars as $key => $char ) {
679 $ord = ord( $char );
680
681 if ( $ord < 128 ) { // ignore non-ascii chars
682 $r = ( $seed * ( 1 + $key ) ) % 100; // pseudo "random function"
683
684 if ( $r > 75 && $char !== '@' && $char !== '.' ); // plain character (not encoded), except @-signs and dots
685 else if ( $hex && $r < 25 ) $chars[ $key ] = '%' . bin2hex( $char ); // hex
686 else if ( $r < 45 ) $chars[ $key ] = '&#x' . dechex( $ord ) . ';'; // hexadecimal
687 else $chars[ $key ] = "&#{$ord};"; // decimal (ascii)
688 }
689 }
690
691 return implode( '', $chars );
692 }
693
694 function check_email_e_shortcode( $attributes, $content = '' ) {
695 $atts = shortcode_atts( array(
696 'link' => null,
697 'class' => null,
698 ), $attributes, 'checkmail-encode' );
699
700
701 $method = apply_filters( 'check_email_e_method', 'check_email_encode_str' );
702
703 if ( ! empty( $atts[ 'link' ] ) ) {
704 $link = esc_url( $atts[ 'link' ], null, 'shortcode' );
705
706 if ( $link === '' ) {
707 return $method( $content );
708 }
709
710 if ( empty( $atts[ 'class' ] ) ) {
711 return sprintf(
712 '<a href="%s">%s</a>',
713 $method( $link ),
714 $method( $content )
715 );
716 }
717
718 return sprintf(
719 '<a href="%s" class="%s">%s</a>',
720 $method( $link ),
721 esc_attr( $atts[ 'class' ] ),
722 $method( $content )
723 );
724 }
725
726 return $method( $content );
727 }
728
729 function check_email_e_encode_emails( $string ) {
730 if ( ! is_string( $string ) ) {
731 return $string;
732 }
733 // abort if `check_email_e_at_sign_check` is true and `$string` doesn't contain a @-sign
734 if ( apply_filters( 'check_email_e_at_sign_check', true ) && strpos( $string, '@' ) === false ) {
735 return $string;
736 }
737 // override encoding function with the 'check_email_e_method' filter
738 $method = apply_filters( 'check_email_e_method', 'check_email_encode_str' );
739
740 $regexp = apply_filters( 'check_email_e_regexp', CHECK_EMAIL_E_REGEXP );
741
742 $callback = function ( $matches ) use ( $method ) {
743 return $method( $matches[ 0 ] );
744 };
745
746 if ( has_filter( 'check_email_e_callback' ) ) {
747 $callback = apply_filters( 'check_email_e_callback', $callback, $method );
748 return preg_replace_callback( $regexp, $callback, $string );
749 }
750
751 return preg_replace_callback( $regexp, $callback, $string );
752 }
753
754 function check_email_full_page_scanner() {
755 if(!is_admin() ) {
756 ob_start('check_email_full_page_callback');
757 }
758 }
759 function check_email_full_page_callback($string) {
760 return check_email_e_encode_emails($string);
761 }
762
763
764 add_action( 'wp_enqueue_scripts', 'ck_mail_enqueue_encoder_js' );
765
766 function ck_mail_enqueue_encoder_js() {
767 $encode_options = get_option('check-email-email-encode-options', true);
768 $is_enable = ( isset( $encode_options['is_enable'] ) ) ? $encode_options['is_enable'] : 0;
769 if ( $is_enable ) {
770 $email_using = ( isset( $encode_options['email_using'] ) ) ? $encode_options['email_using'] : "";
771 $email_technique = ( isset( $encode_options['email_technique'] ) ) ? $encode_options['email_technique'] : "";
772
773 $check_email = wpchill_check_email();
774 $plugin_dir_url = plugin_dir_url( $check_email->get_plugin_file() );
775 $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
776 wp_register_script( 'checkemail_encoder', $plugin_dir_url . 'assets/js/check-email-front'. $suffix .'.js', array(), $check_email->get_version(), true );
777 $data = array();
778 $data['email_using'] = $email_using;
779 $data['is_enable'] = $is_enable;
780 $data['email_technique'] = $email_technique;
781
782 wp_localize_script( 'checkemail_encoder', 'checkemail_encoder_data', $data );
783 wp_enqueue_script( 'checkemail_encoder' );
784 }
785 }
786
787 function check_email_rot13( $string ) {
788
789 $from = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
790 $to = 'nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM';
791
792 return strtr( $string, $from, $to );
793 }
794
795 // email and phone encoding end
796
797