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 / classes / class-email-encoder-bundle-ajax.php
email-encoder-bundle / core / includes / classes Last commit date
class-email-encoder-bundle-ajax.php 2 years ago class-email-encoder-bundle-helpers.php 2 years ago class-email-encoder-bundle-run-admin.php 2 years ago class-email-encoder-bundle-run.php 2 years ago class-email-encoder-bundle-settings.php 2 years ago class-email-encoder-bundle-validate.php 2 years ago index.php 2 years ago
class-email-encoder-bundle-ajax.php
132 lines
1 <?php
2
3 /**
4 * Class Email_Encoder_Ajax
5 *
6 * Thats where we bring the plugin to life
7 *
8 * @since 2.0.0
9 * @package EEB
10 * @author Ironikus <info@ironikus.com>
11 */
12
13 class Email_Encoder_Ajax{
14
15 /**
16 * The main page name for our admin page
17 *
18 * @var string
19 * @since 2.0.0
20 */
21 private $page_name;
22
23 /**
24 * The main page title for our admin page
25 *
26 * @var string
27 * @since 2.0.0
28 */
29 private $page_title;
30
31 /**
32 * Our Email_Encoder_Run constructor.
33 */
34 function __construct(){
35 $this->page_name = EEB()->settings->get_page_name();
36 $this->page_title = EEB()->settings->get_page_title();
37 $this->add_hooks();
38 }
39
40 /**
41 * Define all of our necessary hooks
42 */
43 private function add_hooks(){
44
45 if(
46 EEB()->helpers->is_page( $this->page_name )
47 || ( wp_doing_ajax() && isset( $_POST['action'] ) && $_POST['action'] === 'eeb_get_email_form_output' )
48 ){
49 add_action( 'admin_enqueue_scripts', array( $this, 'load_ajax_scripts_styles' ), EEB()->settings->get_hook_priorities( 'load_ajax_scripts_styles_admin' ) );
50 add_action( 'wp_ajax_eeb_get_email_form_output', array( $this, 'eeb_ajax_email_encoder_response' ) );
51 }
52
53 $form_frontend = (bool) EEB()->settings->get_setting( 'encoder_form_frontend', true, 'encoder_form' );
54
55 if( $form_frontend ){
56 add_action( 'wp_enqueue_scripts', array( $this, 'load_ajax_scripts_styles' ), EEB()->settings->get_hook_priorities( 'load_ajax_scripts_styles' ) );
57 add_action( 'wp_ajax_nopriv_eeb_get_email_form_output', array( $this, 'eeb_ajax_email_encoder_response' ) );
58 }
59
60 }
61
62 /**
63 * ######################
64 * ###
65 * #### SCRIPTS & STYLES
66 * ###
67 * ######################
68 */
69
70 /**
71 * Register all necessary scripts and styles
72 *
73 * @since 2.0.0
74 */
75 public function load_ajax_scripts_styles() {
76
77 $js_version_form = date( "ymd-Gis", filemtime( EEB_PLUGIN_DIR . 'core/includes/assets/js/encoder-form.js' ));
78 wp_enqueue_script( 'eeb-js-ajax-ef', EEB_PLUGIN_URL . 'core/includes/assets/js/encoder-form.js', array('jquery'), $js_version_form, true );
79 wp_localize_script( 'eeb-js-ajax-ef', 'eeb_ef', array(
80 'ajaxurl' => admin_url( 'admin-ajax.php' ),
81 'security' => wp_create_nonce( $this->page_name )
82 ));
83
84 }
85
86 /**
87 * ######################
88 * ###
89 * #### CORE LOGIC
90 * ###
91 * ######################
92 */
93
94 public function eeb_ajax_email_encoder_response(){
95 check_ajax_referer( $this->page_name, 'eebsec' );
96
97 $email = html_entity_decode( sanitize_email( $_POST['eebEmail'] ) );
98 $method = sanitize_text_field( $_POST['eebMethod'] );
99 $display = html_entity_decode( $_POST['eebDisplay'] );
100 $custom_class = (string) EEB()->settings->get_setting( 'class_name', true );
101 $protection_text = __( EEB()->settings->get_setting( 'protection_text', true ), 'email-encoder-bundle' );
102
103 if( empty( $display ) ) {
104 $display = $email;
105 } else {
106 $display = wp_kses_post( $display );
107 }
108
109 $display = sanitize_text_field( $display );
110
111 $class_name = ' class="' . esc_attr( $custom_class ) . '"';
112 $mailto = '<a href="mailto:' . $email . '"'. $class_name . '>' . $display . '</a>';
113
114 switch( $method ){
115 case 'rot13':
116 $mailto = EEB()->validate->encode_ascii( $mailto, $protection_text );
117 break;
118 case 'escape':
119 $mailto = EEB()->validate->encode_escape( $mailto, $protection_text );
120 break;
121 case 'encode':
122 default:
123 $mailto = '<a href="mailto:' . antispambot( $email ) . '"'. $class_name . '>' . antispambot( $display ) . '</a>';
124 break;
125 }
126
127 echo apply_filters( 'eeb/ajax/encoder_form_response', $mailto );
128 exit;
129 }
130
131 }
132