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
ProtectContentShortcode.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | namespace OnlineOptimisation\EmailEncoderBundle\Front\Shortcodes; |
| 4 | |
| 5 | use OnlineOptimisation\EmailEncoderBundle\Traits\PluginHelper; |
| 6 | |
| 7 | class ProtectContentShortcode { |
| 8 | |
| 9 | use PluginHelper; |
| 10 | |
| 11 | protected string $tag = 'eeb_protect_content'; |
| 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 | $original_content = $content; |
| 21 | $allowed_attr_html = $this->getSafeHtmlAttr(); |
| 22 | $show_encoded_check = (string) $this->getSetting( 'show_encoded_check', true ); |
| 23 | |
| 24 | if ( ! isset( $atts['protection_text'] ) ) { |
| 25 | $protection_text = __( $this->getSetting( 'protection_text', true ), 'email-protection-text-eeb-content' ); |
| 26 | } else { |
| 27 | $protection_text = wp_kses_post( $atts['protection_text'] ); |
| 28 | } |
| 29 | |
| 30 | if ( isset( $atts['method'] ) ) { |
| 31 | $method = sanitize_title( $atts['method'] ); |
| 32 | } else { |
| 33 | $method = 'rot13'; |
| 34 | } |
| 35 | |
| 36 | $content = wp_kses( html_entity_decode( $content ), $allowed_attr_html ); |
| 37 | |
| 38 | if ( isset( $atts['do_shortcode'] ) && $atts['do_shortcode'] === 'yes' ) { |
| 39 | $content = do_shortcode( $content ); |
| 40 | } |
| 41 | |
| 42 | switch( $method ) { |
| 43 | case 'enc_ascii': |
| 44 | case 'rot13': |
| 45 | $content = $this->encodeAscii( $content, $protection_text ); |
| 46 | break; |
| 47 | case 'enc_escape': |
| 48 | case 'escape': |
| 49 | $content = $this->encodeEscape( $content, $protection_text ); |
| 50 | break; |
| 51 | case 'enc_html': |
| 52 | case 'encode': |
| 53 | default: |
| 54 | $content = antispambot( $content ); |
| 55 | break; |
| 56 | } |
| 57 | |
| 58 | // mark link as successfullly encoded (for admin users) |
| 59 | if ( current_user_can( $this->getAdminCap( 'frontend-display-security-check' ) ) && $show_encoded_check ) { |
| 60 | $content .= $this->getEncodedEmailIcon(); |
| 61 | } |
| 62 | |
| 63 | return apply_filters( 'eeb/frontend/shortcode/eeb_protect_content', $content, $atts, $original_content ); |
| 64 | } |
| 65 | |
| 66 | } |