PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 0.12
Email Encoder – Protect Email Addresses and Phone Numbers v0.12
2.5.0 2.4.8 trunk 0.10 0.11 0.12 0.20 0.21 0.22 0.30 0.31 0.32 0.40 0.41 0.42 0.50 0.60 0.70 0.71 0.80 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.5 1.5.2 1.51 1.53 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7
email-encoder-bundle / email-encoder-bundle.php
email-encoder-bundle Last commit date
js 16 years ago methods 16 years ago GPL-license.txt 16 years ago MIT-license.txt 16 years ago email-encoder-bundle.php 16 years ago lim-email-encoder.php 16 years ago readme.txt 16 years ago screenshot-1.jpg 16 years ago
email-encoder-bundle.php
335 lines
1 <?php
2 /*
3 Plugin Name: Email Encoder Bundle
4 Plugin URI: http://www.freelancephp.net/email-encoder
5 Description: Protecting email-spamming by replacing them with one of the registered encoding-methods
6 Author: Victor Villaverde Laan
7 Version: 0.12
8 Author URI: http://www.freelancephp.net
9 License: Dual licensed under the MIT and GPL licenses
10 */
11 // include parent class
12 require_once dirname(__FILE__) . '/lim-email-encoder.php';
13
14 /**
15 * Class WP_Email_Encoder, child of Lim_Email_Encoder
16 * @package Lim_Email_Encoder
17 * @category WordPress Plugins
18 */
19 class WP_Email_Encoder extends Lim_Email_Encoder {
20
21 /**
22 * Prefix for options entry and being used as text domain (for translations)
23 * @var string
24 */
25 var $prefix = 'wp_esp';
26
27 /**
28 * @var array
29 */
30 var $wp_options = array(
31 'filter_widgets' => TRUE,
32 'filter_comments' => TRUE,
33 'form_on_site' => FALSE, // set encoder form on the website
34 'powered_by' => TRUE,
35 );
36
37 /**
38 * PHP4 constructor
39 */
40 function WP_Email_Encoder() {
41 $this->__construct();
42 }
43
44 /**
45 * PHP5 constructor
46 */
47 function __construct() {
48 parent::__construct();
49
50 // add all $wp_options to $options
51 $this->options = array_merge( $this->options, $this->wp_options );
52 // set option values
53 $this->_set_options();
54
55 // add filters
56 add_filter( 'the_content', array( &$this, 'encode_filter' ), 100 );
57
58 // also filter comments
59 if ( $this->options['filter_comments'] )
60 add_filter( 'comment_text', array( &$this, 'encode_filter' ), 100 );
61
62 // also filter widgets
63 if ( $this->options['filter_widgets'] )
64 add_filter( 'widget_text', array( &$this, 'encode_filter' ), 100 );
65
66 // add actions
67 add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
68 add_action( 'admin_init', array( &$this, 'admin_init' ) );
69
70 if ( $this->options['form_on_site'] )
71 add_action( 'the_posts', array( &$this, 'the_posts' ) );
72
73 // set uninstall hook
74 if ( function_exists( 'register_deactivation_hook' ) )
75 register_deactivation_hook( __FILE__, array( &$this, 'deactivation' ));
76 }
77
78 /**
79 * Callback for the_post action
80 * @param array $posts
81 */
82 function the_posts( $posts ) {
83 if ( empty( $posts ) )
84 return $posts;
85
86 foreach ( $posts as $key => $post ) {
87 if ( stripos( $post->post_content, '[email_encoder_form]' ) > -1 ) {
88 // add style and script for ajax encoder
89 wp_enqueue_script( 'email_encoder', plugins_url( 'js/wp_esp.js', __FILE__ ), array( 'jquery' ) );
90 // replace tag by form
91 $posts[$key]->post_content = str_replace( '[email_encoder_form]', $this->get_encoder_form(), $post->post_content );
92 break;
93 }
94 }
95
96 return $posts;
97 }
98
99 /**
100 * Callback admin_menu
101 */
102 function admin_menu() {
103 if ( function_exists('add_options_page') AND current_user_can('manage_options') ) {
104 // add options page
105 $page = add_options_page( 'Email Encoder Bundle', 'Email Encoder Bundle',
106 'manage_options', __FILE__, array( &$this, 'options_page' ) );
107
108 // add scripts
109 add_action( 'admin_print_scripts-' . $page, array( &$this, 'admin_print_scripts' ) );
110 }
111 }
112
113 /**
114 * Callback admin_init
115 */
116 function admin_init() {
117 // register settings
118 register_setting( $this->prefix, $this->prefix . 'options' );
119 }
120
121 /**
122 * Callback admin_print_scripts
123 */
124 function admin_print_scripts() {
125 // add script for ajax encoder
126 wp_enqueue_script( 'email_encoder', plugins_url( 'js/wp_esp.js', __FILE__ ), array( 'jquery' ) );
127 }
128
129 /**
130 * Admin options page
131 */
132 function options_page() {
133 ?>
134 <div class="wrap">
135 <h2>Email Encoder Bundle</h2>
136
137 <div>
138 <h3>Settings</h3>
139 <form method="post" action="options.php">
140 <?php
141 settings_fields( $this->prefix );
142 $this->_set_options();
143 $options = $this->options;
144 ?>
145 <fieldset class="options">
146 <table class="form-table">
147 <tr>
148 <th><label for="<?php echo $this->prefix ?>options[method]"><?php _e( 'Encoding method', $this->prefix ) ?></label></th>
149 <td><select id="<?php echo $this->prefix ?>options[method]" name="<?php echo $this->prefix ?>options[method]" class="postform">
150 <?php foreach ( $this->methods AS $key => $method ): ?>
151 <option value="<?php echo $key ?>" <?php if ( $options['method'] == $key ) echo 'selected="selected"' ?>><?php _e( $key, $this->prefix ) ?></option>
152 <?php endforeach; ?>
153 <option value="random" <?php if ( $options['method'] == 'random' ) echo 'selected="selected"' ?>><?php _e( 'random', $this->prefix ) ?></option>
154 </select></td>
155 </tr>
156 <tr>
157 <th><label for="<?php echo $this->prefix ?>options[encode_display]"><?php _e( 'Encode email titles (display)', $this->prefix ) ?></label></th>
158 <td><input type="checkbox" id="<?php echo $this->prefix ?>options[encode_display]" name="<?php echo $this->prefix ?>options[encode_display]" value="1" <?php checked('1', (int) $options['encode_display']); ?> /> <span class="description"><?php _e( '(recommended)', $this->prefix ) ?></span></td>
159 </tr>
160 <tr>
161 <th><label for="<?php echo $this->prefix ?>options[encode_mailto]"><?php _e( 'Encode mailto links', $this->prefix ) ?></label></th>
162 <td><input type="checkbox" id="<?php echo $this->prefix ?>options[encode_mailto]" name="<?php echo $this->prefix ?>options[encode_mailto]" value="1" <?php checked('1', (int) $options['encode_mailto']); ?> /> <span class="description"><?php _e( 'encode all mailto links in the content', $this->prefix ) ?></span></td>
163 </tr>
164 <tr>
165 <th><label for="<?php echo $this->prefix ?>options[replace_emails]"><?php _e( 'Replace plain text emails', $this->prefix ) ?></label></th>
166 <td><input type="checkbox" id="<?php echo $this->prefix ?>options[replace_emails]" name="<?php echo $this->prefix ?>options[replace_emails]" value="1" <?php checked('1', (int) $options['replace_emails']); ?> /> <span class="description"><?php _e( 'replacing plain text emails to an encoded mailto link', $this->prefix ) ?></span></td>
167 </tr>
168 <tr>
169 <th style="padding-top:25px"><label for="<?php echo $this->prefix ?>options[filter_comments]"><?php _e( 'Also filter comments', $this->prefix ) ?></label></th>
170 <td style="padding-top:25px"><input type="checkbox" id="<?php echo $this->prefix ?>options[filter_comments]" name="<?php echo $this->prefix ?>options[filter_comments]" value="1" <?php checked('1', (int) $options['filter_comments']); ?> /> <span class="description"><?php _e( 'also filter all comments for encoding', $this->prefix ) ?></span></td>
171 </tr>
172 <tr>
173 <th><label for="<?php echo $this->prefix ?>options[filter_widgets]"><?php _e( 'Also filter widgets', $this->prefix ) ?></label></th>
174 <td><input type="checkbox" id="<?php echo $this->prefix ?>options[filter_widgets]" name="<?php echo $this->prefix ?>options[filter_widgets]" value="1" <?php checked('1', (int) $options['filter_widgets']); ?> /> <span class="description"><?php _e( 'also filter widgets for encoding', $this->prefix ) ?></span></td>
175 </tr>
176 <tr>
177 <th style="padding-top:25px"><label for="<?php echo $this->prefix ?>options[form_on_site]"><?php _e( 'Encode form on your site', $this->prefix ) ?></label></th>
178 <td style="padding-top:25px"><input type="checkbox" id="<?php echo $this->prefix ?>options[form_on_site]" name="<?php echo $this->prefix ?>options[form_on_site]" value="1" <?php checked('1', (int) $options['form_on_site']); ?> /> <span class="description"><?php _e( 'put an encode form on your site, use this tag in a post or page:', $this->prefix ) ?></span> <code>[email_encoder_form]</code></td>
179 </tr>
180 <tr>
181 <th><label for="<?php echo $this->prefix ?>options[powered_by]"><?php _e( 'Show powered by link', $this->prefix ) ?></label></th>
182 <td><input type="checkbox" id="<?php echo $this->prefix ?>options[powered_by]" name="<?php echo $this->prefix ?>options[powered_by]" value="1" <?php checked('1', (int) $options['powered_by']); ?> /> <span class="description"><?php _e( 'show the powered by link on bottom of the encode form', $this->prefix ) ?></span></td>
183 </tr>
184 </table>
185 </fieldset>
186 <p class="submit">
187 <input class="button-primary" type="submit" value="<?php _e( 'Save Changes', $this->prefix ) ?>" />
188 </p>
189 </form>
190 </div>
191
192 <div>
193 <h3>How To Use?</h3>
194 <p>Inside a post or page use this code: <code>[encode_email email="info@myemail.com" display="My Email"]</code></p>
195 <p>And for templates use: <code>&lt;?php echo encode_email( 'info@myemail.com', 'My Email' ); ?&gt;</code></p>
196 </div>
197
198 <div>
199 <h3>Encoder Form</h3>
200 <?php echo $this->get_encoder_form(); ?>
201 </div>
202
203 </div>
204 <?php
205 }
206
207 /**
208 * Get the encoder form (to use as a demo, like on the options page)
209 * @return string
210 */
211 function get_encoder_form() {
212 ob_start();
213 ?>
214 <form class="email-encoder-form">
215 <fieldset>
216 <table class="form-table">
217 <tr>
218 <tr>
219 <th><label for="email"><?php _e( 'Email', $this->prefix ) ?></label></th>
220 <td><input type="text" class="regular-text" id="email" name="email" /></td>
221 </tr>
222 <tr>
223 <th><label for="display"><?php _e( 'Display (optional)', $this->prefix ) ?></label></th>
224 <td><input type="text" class="regular-text" id="display" name="display" /></td>
225 </tr>
226 <tr>
227 <th><label for="encode_method"><?php _e( 'Encode method', $this->prefix ) ?></label></th>
228 <td><select id="encode_method" name="encode_method" class="postform">
229 <?php foreach ( $this->methods AS $key => $method ): ?>
230 <option value="<?php echo $key ?>" <?php if ( $this->options['method'] == $key ) echo 'selected="selected"' ?>><?php _e( $key, $this->prefix ) ?></option>
231 <?php endforeach; ?>
232 <option value="random" <?php if ( $this->options['method'] == 'random' ) echo 'selected="selected"' ?>><?php _e( 'random', $this->prefix ) ?></option>
233 </select>
234 <input type="button" id="ajax_encode" value="Encode &gt;" /></td>
235 </tr>
236 </tr>
237 <tr>
238 <tr>
239 <th><?php _e( 'Example', $this->prefix ) ?></th>
240 <td><span id="example"></span></td>
241 </tr>
242 <tr>
243 <th><label for="encoded_output"><?php _e( 'Code', $this->prefix ) ?></label></th>
244 <td><textarea class="large-text node" id="encoded_output" name="encoded_output"></textarea></td>
245 </tr>
246 </tr>
247 </table>
248 <?php if ( $this->options['powered_by'] ): ?>
249 <p class="powered-by">Powered by <a rel="external" href="http://www.freelancephp.net/email-encoder/">Email Encoder Bundle</a></p>
250 <?php endif; ?>
251 </fieldset>
252 </form>
253 <?php
254 $form = ob_get_contents();
255 ob_clean();
256
257 return $form;
258 }
259
260 /**
261 * Deactivation plugin method
262 */
263 function deactivation() {
264 delete_option( $this->prefix . 'options' );
265 unregister_setting( $this->prefix, $this->prefix . 'options' );
266 }
267
268 /**
269 * Set options from save values or defaults
270 */
271 function _set_options() {
272 // set options
273 $saved_options = get_option( $this->prefix . 'options' );
274 if ( empty( $saved_options ) ) {
275 // set defaults
276 $this->options['encode_display'] = (int) $this->options['encode_display'];
277 $this->options['encode_mailto'] = (int) $this->options['encode_mailto'];
278 $this->options['replace_emails'] = (int) $this->options['replace_emails'];
279 $this->options['filter_comments'] = (int) $this->options['filter_comments'];
280 $this->options['filter_widgets'] = (int) $this->options['filter_widgets'];
281 $this->options['form_on_site'] = (int) $this->options['form_on_site'];
282 $this->options['powered_by'] = (int) $this->options['powered_by'];
283 } else {
284 // set saved option values
285 $this->set_method( $saved_options['method'] );
286 $this->options['encode_display'] = ! empty( $saved_options['encode_display'] );
287 $this->options['encode_mailto'] = ! empty( $saved_options['encode_mailto'] );
288 $this->options['replace_emails'] = ! empty( $saved_options['replace_emails'] );
289 $this->options['filter_comments'] = ! empty( $saved_options['filter_comments'] );
290 $this->options['filter_widgets'] = ! empty( $saved_options['filter_widgets'] );
291 $this->options['form_on_site'] = ! empty( $saved_options['form_on_site'] );
292 $this->options['powered_by'] = ! empty( $saved_options['powered_by'] );
293 }
294 }
295
296 } // end class WP_Email_Encoder
297
298
299 /**
300 * Create instance
301 */
302 $WP_Email_Encoder = new WP_Email_Encoder;
303
304
305 /**
306 * Ajax request
307 */
308 if ( ! empty( $_GET['ajax'] ) ):
309 // input vars
310 $method = $_GET['method'];
311 $email = $_GET['email'];
312 $display = ( empty( $_GET['display'] ) ) ? $email : $_GET['display'];
313
314 $WP_Email_Encoder->set_method( $method );
315
316 echo $WP_Email_Encoder->encode_email( $email, $display );
317 exit;
318 endif;
319
320
321 /**
322 * Template function for encoding email
323 * @global WP_Email_Encoder $WP_Email_Encoder
324 * @param string $email
325 * @param string $display if non given will be same as email
326 * @return string
327 */
328 if ( ! function_exists( 'encode_email' ) ):
329 function encode_email( $email, $display = NULL ) {
330 global $WP_Email_Encoder;
331 return $WP_Email_Encoder->encode_email( $email, $display );
332 }
333 endif;
334
335 ?>