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