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