ContentShortcode.php
6 months ago
EmailEncoderFormShortcode.php
6 months ago
EmailShortcode.php
6 months ago
MailtoShortcode.php
6 months ago
ProtectContentShortcode.php
6 months ago
ProtectEmailsShortcode.php
6 months ago
Shortcodes.php
6 months ago
MailtoShortcode.php
103 lines
| 1 | <?php |
| 2 | |
| 3 | namespace OnlineOptimisation\EmailEncoderBundle\Front\Shortcodes; |
| 4 | |
| 5 | use OnlineOptimisation\EmailEncoderBundle\Traits\PluginHelper; |
| 6 | |
| 7 | class MailtoShortcode { |
| 8 | |
| 9 | use PluginHelper; |
| 10 | |
| 11 | protected string $tag = 'eeb_mailto'; |
| 12 | |
| 13 | public function tag(): string { |
| 14 | return $this->tag; |
| 15 | } |
| 16 | |
| 17 | |
| 18 | public function handle( array $atts = [], ?string $content = null ): string { |
| 19 | |
| 20 | $allowed_attr_html = $this->getSafeHtmlAttr(); |
| 21 | $show_encoded_check = (bool) $this->getSetting( 'show_encoded_check', true ); |
| 22 | $protection_text = __( $this->getSetting( 'protection_text', true ), 'email-encoder-bundle' ); |
| 23 | |
| 24 | if ( empty( $atts['email'] ) ) { |
| 25 | return ''; |
| 26 | } else { |
| 27 | $email = sanitize_email( $atts['email'] ); |
| 28 | } |
| 29 | |
| 30 | if ( empty( $atts['extra_attrs'] ) ) { |
| 31 | $extra_attrs = ''; |
| 32 | } else { |
| 33 | $extra_attrs = $atts['extra_attrs']; |
| 34 | } |
| 35 | |
| 36 | if ( ! isset( $atts['method'] ) || empty( $atts['method'] ) ) { |
| 37 | $protect_using = (string) $this->getSetting( 'protect_using', true ); |
| 38 | if ( ! empty( $protect_using ) ) { |
| 39 | $method = $protect_using; |
| 40 | } else { |
| 41 | $method = 'rot13'; //keep as fallback |
| 42 | } |
| 43 | } else { |
| 44 | $method = sanitize_title( $atts['method'] ); |
| 45 | } |
| 46 | |
| 47 | $custom_class = (string) $this->getSetting( 'class_name', true ); |
| 48 | |
| 49 | if ( empty( $atts['display'] ) ) { |
| 50 | $display = $email; |
| 51 | } else { |
| 52 | $display = wp_kses( html_entity_decode( $atts['display'] ), $allowed_attr_html ); |
| 53 | $display = str_replace( '\\', '', $display ); //Additionally sanitize unicode |
| 54 | } |
| 55 | |
| 56 | if ( empty( $atts['noscript'] ) ) { |
| 57 | $noscript = $protection_text; |
| 58 | } else { |
| 59 | $noscript = wp_kses( html_entity_decode( $atts['noscript'] ), $allowed_attr_html ); |
| 60 | $noscript = str_replace( '\\', '', $noscript ); //Additionally sanitize unicode |
| 61 | } |
| 62 | |
| 63 | $class_name = ' ' . $this->helper()->sanitize_html_attributes( $extra_attrs ); |
| 64 | $class_name .= ' class="' . esc_attr( $custom_class ) . '"'; |
| 65 | $mailto = '<a href="mailto:' . $email . '"'. $class_name . '>' . $display . '</a>'; |
| 66 | |
| 67 | switch( $method ) { |
| 68 | case 'enc_ascii': |
| 69 | case 'rot13': |
| 70 | $mailto = $this->encodeAscii( $mailto, $noscript ); |
| 71 | break; |
| 72 | case 'enc_escape': |
| 73 | case 'escape': |
| 74 | $mailto = $this->encodeEscape( $mailto, $noscript ); |
| 75 | break; |
| 76 | case 'with_javascript': |
| 77 | $mailto = $this->dynamicJsEmailEncoding( $mailto, $noscript ); |
| 78 | break; |
| 79 | case 'without_javascript': |
| 80 | $mailto = $this->encodeEmailCss( $mailto ); |
| 81 | break; |
| 82 | case 'char_encode': |
| 83 | $mailto = $this->filterPlainEmails( $mailto, null, 'char_encode' ); |
| 84 | break; |
| 85 | case 'strong_method': |
| 86 | $mailto = $this->filterPlainEmails( $mailto ); |
| 87 | break; |
| 88 | case 'enc_html': |
| 89 | case 'encode': |
| 90 | default: |
| 91 | $mailto = '<a href="mailto:' . antispambot( $email ) . '"'. $class_name . '>' . antispambot( $display ) . '</a>'; |
| 92 | break; |
| 93 | } |
| 94 | |
| 95 | // mark link as successfullly encoded (for admin users) |
| 96 | if ( current_user_can( $this->getAdminCap( 'frontend-display-security-check' ) ) && $show_encoded_check ) { |
| 97 | $mailto .= $this->getEncodedEmailIcon(); |
| 98 | } |
| 99 | |
| 100 | return apply_filters( 'eeb/frontend/shortcode/eeb_mailto', $mailto ); |
| 101 | } |
| 102 | |
| 103 | } |