EncoderForm.php
3 months ago
Encoding.php
3 months ago
Filters.php
3 months ago
Validate.php
5 months ago
EncoderForm.php
198 lines
| 1 | <?php |
| 2 | |
| 3 | namespace OnlineOptimisation\EmailEncoderBundle\Validate; |
| 4 | |
| 5 | use OnlineOptimisation\EmailEncoderBundle\Traits\PluginHelper; |
| 6 | |
| 7 | class EncoderForm |
| 8 | { |
| 9 | use PluginHelper; |
| 10 | |
| 11 | public function boot(): void |
| 12 | { |
| 13 | } |
| 14 | |
| 15 | |
| 16 | /** |
| 17 | * ###################### |
| 18 | * ### |
| 19 | * #### ENCODER FORM |
| 20 | * ### |
| 21 | * ###################### |
| 22 | */ |
| 23 | |
| 24 | /** |
| 25 | * Get the encoder form (to use as a demo, like on the options page) |
| 26 | * @return string |
| 27 | */ |
| 28 | public function get_encoder_form() |
| 29 | { |
| 30 | $powered_by_setting = (bool) $this->getSetting( 'powered_by', true, 'encoder_form' ); |
| 31 | |
| 32 | //shorten circle |
| 33 | if ( |
| 34 | ! $this->helper()->is_page( $this->getPageName() ) |
| 35 | && ! (bool) $this->getSetting( 'encoder_form_frontend', true, 'encoder_form' ) |
| 36 | ) { |
| 37 | return (string) apply_filters('eeb_form_content_inactive', '' ); |
| 38 | } |
| 39 | |
| 40 | $powered_by = ''; |
| 41 | if ($powered_by_setting) { |
| 42 | $powered_by .= '<p class="powered-by">' . __('Powered by free', 'email-encoder-bundle') . ' <a rel="external" href="https://wordpress.org/plugins/email-encoder-bundle/">Email Encoder</a></p>'; |
| 43 | } |
| 44 | |
| 45 | $smethods = array( |
| 46 | 'rot13' => __( 'Rot13 (Javascript)', 'email-encoder-bundle' ), |
| 47 | 'escape' => __( 'Escape (Javascript)', 'email-encoder-bundle' ), |
| 48 | 'encode' => __( 'Encode (HTML)', 'email-encoder-bundle' ), |
| 49 | ); |
| 50 | $method_options = ''; |
| 51 | $selected = false; |
| 52 | foreach ( $smethods as $method_name => $name ) { |
| 53 | $method_options .= '<option value="' . $method_name . '"' . ( ($selected === false ) ? ' selected="selected"' : '') . '>' . $name . '</option>'; |
| 54 | $selected = true; |
| 55 | } |
| 56 | |
| 57 | $labels = array( |
| 58 | 'email' => __( 'Email Address:', 'email-encoder-bundle' ), |
| 59 | 'display' => __( 'Display Text:', 'email-encoder-bundle' ), |
| 60 | 'mailto' => __( 'Mailto Link:', 'email-encoder-bundle' ), |
| 61 | 'method' => __( 'Encoding Method:', 'email-encoder-bundle' ), |
| 62 | 'create_link' => __( 'Create Protected Mail Link >>', 'email-encoder-bundle' ), |
| 63 | 'output' => __( 'Protected Mail Link (code):', 'email-encoder-bundle' ), |
| 64 | 'powered_by' => $powered_by, |
| 65 | ); |
| 66 | |
| 67 | extract( $labels ); |
| 68 | |
| 69 | $form = '<div class="eeb-form">' |
| 70 | . '<form>' |
| 71 | . '<fieldset>' |
| 72 | . '<div class="input">' |
| 73 | . '<table>' |
| 74 | . '<tbody>' |
| 75 | . '<tr>' |
| 76 | . '<th><label for="eeb-email">' . $email . '</label></th>' |
| 77 | . '<td><input type="text" class="regular-text" id="eeb-email" name="eeb-email" /></td>' |
| 78 | . '</tr>' |
| 79 | . '<tr>' |
| 80 | . '<th><label for="eeb-display">' . $display . '</label></th>' |
| 81 | . '<td><input type="text" class="regular-text" id="eeb-display" name="eeb-display" /></td>' |
| 82 | . '</tr>' |
| 83 | . '<tr>' |
| 84 | . '<th>' . $mailto . '</th>' |
| 85 | . '<td><span class="eeb-example"></span></td>' |
| 86 | . '</tr>' |
| 87 | . '<tr>' |
| 88 | . '<th><label for="eeb-encode-method">' . $method . '</label></th>' |
| 89 | . '<td><select id="eeb-encode-method" name="eeb-encode-method" class="postform">' |
| 90 | . $method_options |
| 91 | . '</select>' |
| 92 | . '<input type="button" id="eeb-ajax-encode" name="eeb-ajax-encode" value="' . $create_link . '" />' |
| 93 | . '</td>' |
| 94 | . '</tr>' |
| 95 | . '</tbody>' |
| 96 | . '</table>' |
| 97 | . '</div>' |
| 98 | . '<div class="eeb-output">' |
| 99 | . '<table>' |
| 100 | . '<tbody>' |
| 101 | . '<tr>' |
| 102 | . '<th><label for="eeb-encoded-output">' . $output . '</label></th>' |
| 103 | . '<td><textarea class="large-text node" id="eeb-encoded-output" name="eeb-encoded-output" cols="50" rows="4"></textarea></td>' |
| 104 | . '</tr>' |
| 105 | . '</tbody>' |
| 106 | . '</table>' |
| 107 | . '</div>' |
| 108 | . $powered_by |
| 109 | . '</fieldset>' |
| 110 | . '</form>' |
| 111 | . '</div>'; |
| 112 | |
| 113 | // apply filters |
| 114 | $form = apply_filters('eeb_form_content', $form, $labels, $powered_by_setting ); |
| 115 | |
| 116 | return $form; |
| 117 | } |
| 118 | |
| 119 | |
| 120 | /** |
| 121 | * @param int $post_id |
| 122 | * @return bool |
| 123 | */ |
| 124 | public function is_post_excluded( ?int $post_id = null ) |
| 125 | { |
| 126 | |
| 127 | $return = false; |
| 128 | $skip_posts = (string) $this->getSetting( 'skip_posts', true ); |
| 129 | if ( ! empty( $skip_posts ) ) { |
| 130 | |
| 131 | if ( empty( $post_id ) ) { |
| 132 | global $post; |
| 133 | if ( ! empty( $post ) ) { |
| 134 | $post_id = $post->ID; |
| 135 | } |
| 136 | } else { |
| 137 | $post_id = intval( $post_id ); |
| 138 | } |
| 139 | |
| 140 | $exclude_pages = explode( ',', $skip_posts ); |
| 141 | |
| 142 | $exclude_pages_validated = []; |
| 143 | |
| 144 | foreach ( $exclude_pages as $spost_id ) { |
| 145 | $spost_id = trim( $spost_id ); |
| 146 | if ( is_numeric( $spost_id ) ) { |
| 147 | $exclude_pages_validated[] = intval( $spost_id ); |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | if ( in_array( $post_id, $exclude_pages_validated ) ) { |
| 152 | $return = true; |
| 153 | } |
| 154 | |
| 155 | } |
| 156 | |
| 157 | return (bool) apply_filters( 'eeb/validate/is_post_excluded', $return, $post_id, $skip_posts ); |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Filter if to exclude specific URL parameters from filtering |
| 162 | * |
| 163 | * @since 2.2.0 |
| 164 | * @param array< string > $parameters |
| 165 | * @return boolean |
| 166 | */ |
| 167 | public function is_query_parameter_excluded( $parameters = null ) |
| 168 | { |
| 169 | |
| 170 | if ( $parameters === null ) { |
| 171 | $parameters = $_GET; |
| 172 | } |
| 173 | |
| 174 | $return = false; |
| 175 | $skip_query_parameters = (string) $this->getSetting( 'skip_query_parameters', true ); |
| 176 | if ( ! empty( $skip_query_parameters ) && ! empty( $parameters ) ) { |
| 177 | |
| 178 | $excluded_parameters = explode( ',', $skip_query_parameters ); |
| 179 | |
| 180 | // if ( is_array( $excluded_parameters ) ) { |
| 181 | |
| 182 | foreach ( $excluded_parameters as $param ) { |
| 183 | $param = trim($param); |
| 184 | |
| 185 | if ( isset( $parameters[ $param ] ) ) { |
| 186 | $return = true; |
| 187 | break; |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // } |
| 192 | |
| 193 | } |
| 194 | |
| 195 | return (bool) apply_filters( 'eeb/validate/is_query_parameter_excluded', $return, $parameters ); |
| 196 | } |
| 197 | } |
| 198 |