PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 0.22
Email Encoder – Protect Email Addresses and Phone Numbers v0.22
2.5.2 2.5.1 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 15 years ago lang 15 years ago methods 15 years ago GPL-license.txt 15 years ago Lim_Email_Encoder.php 15 years ago MIT-license.txt 15 years ago email-encoder-bundle.php 15 years ago readme.txt 15 years ago screenshot-1.jpg 15 years ago
email-encoder-bundle.php
450 lines
1 <?php
2 /*
3 Plugin Name: Email Encoder Bundle
4 Plugin URI: http://www.freelancephp.net/email-encoder-php-class-wp-plugin/
5 Description: Protecting email-spamming by replacing them with one of the registered encoding-methods
6 Author: Victor Villaverde Laan
7 Version: 0.22
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 * Used as prefix for options entry and could be used as text domain (for translations)
23 * @var string
24 */
25 var $domain = 'wp_email_enc';
26
27 /**
28 * @var array
29 */
30 var $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 'encode_tags' => TRUE,
36 'encode_mailtos' => TRUE,
37 'encode_emails' => TRUE,
38 );
39
40 /**
41 * PHP4 constructor
42 */
43 function WP_Email_Encoder() {
44 $this->__construct();
45 }
46
47 /**
48 * PHP5 constructor
49 */
50 function __construct() {
51 parent::__construct();
52
53 // set option values
54 $this->_set_options();
55
56 // load text domain for translations
57 load_plugin_textdomain( $this->domain, dirname( __FILE__ ) . '/lang/', basename( dirname(__FILE__) ) . '/lang/' );
58
59 // add filters
60 // set filter priority
61 $priority = 100;
62
63 // content
64 add_filter( 'the_title', array( $this, '_filter_callback' ), $priority );
65 add_filter( 'the_content', array( $this, '_filter_callback' ), $priority );
66 add_filter( 'the_excerpt', array( $this, '_filter_callback' ), $priority );
67 add_filter( 'get_the_excerpt', array( $this, '_filter_callback' ), $priority );
68
69 // comments
70 if ( $this->options[ 'filter_comments' ] ) {
71 add_filter( 'comment_text', array( $this, '_filter_callback' ), $priority );
72 add_filter( 'comment_excerpt', array( $this, '_filter_callback' ), $priority );
73 add_filter( 'get_comment_author_url', array( $this, '_filter_callback' ), $priority );
74 add_filter( 'get_comment_author_link', array( $this, '_filter_callback' ), $priority );
75 add_filter( 'get_comment_author_url_link', array( $this, '_filter_callback' ), $priority );
76 }
77
78 // widgets ( only text widgets )
79 if ( $this->options[ 'filter_widgets' ] ) {
80 add_filter( 'widget_title', array( $this, '_filter_callback' ), $priority );
81 add_filter( 'widget_text', array( $this, '_filter_callback' ), $priority );
82
83 // Only if Widget Logic plugin is installed
84 add_filter( 'widget_content', array( $this, '_filter_callback' ), $priority );
85 }
86
87
88 // add actions
89 add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
90 add_action( 'admin_init', array( &$this, 'admin_init' ) );
91 add_action( 'the_posts', array( &$this, 'the_posts' ) );
92
93 // set uninstall hook
94 if ( function_exists( 'register_deactivation_hook' ) )
95 register_deactivation_hook( __FILE__, array( &$this, 'deactivation' ));
96 }
97
98 /**
99 * Callback for the_post action
100 * @param array $posts
101 */
102 function the_posts( $posts ) {
103 if ( empty( $posts ) OR ! $this->options['form_on_site'] )
104 return $posts;
105
106 foreach ( $posts as $key => $post ) {
107 if ( stripos( $post->post_content, '[email_encoder_form]' ) > -1 ) {
108 // add style and script for ajax encoder
109 wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ) );
110 // replace tag by form
111 $posts[$key]->post_content = str_replace( '[email_encoder_form]', $this->get_encoder_form(), $post->post_content );
112 break;
113 }
114 }
115
116 return $posts;
117 }
118
119 /**
120 * Callback admin_menu
121 */
122 function admin_menu() {
123 if ( function_exists('add_options_page') AND current_user_can('manage_options') ) {
124 // add options page
125 $page = add_options_page( 'Email Encoder Bundle', 'Email Encoder Bundle',
126 'manage_options', __FILE__, array( &$this, 'options_page' ) );
127
128 // add scripts
129 add_action( 'admin_print_scripts-' . $page, array( &$this, 'admin_print_scripts' ) );
130 }
131 }
132
133 /**
134 * Callback admin_init
135 */
136 function admin_init() {
137 // register settings
138 register_setting( $this->domain, $this->domain . 'options' );
139 }
140
141 /**
142 * Callback admin_print_scripts
143 */
144 function admin_print_scripts() {
145 // add script for ajax encoder
146 wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery-ui-sortable' ) );
147 }
148
149 /**
150 * Admin options page
151 */
152 function options_page() {
153 ?>
154 <div class="wrap">
155 <div class="icon32" id="icon-options-general"><br></div>
156 <h2>Email Encoder Bundle</h2>
157
158 <form method="post" action="options.php">
159 <script language="javascript">
160 var methodInfo = <?php echo json_encode( $this->methods ) ?>;
161 </script>
162 <?php
163 settings_fields( $this->domain );
164 $this->_set_options();
165 $options = $this->options;
166 ?>
167 <div class="postbox-container metabox-holder meta-box-sortables" style="width: 69%">
168 <div class="postbox">
169 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
170 <h3 class="hndle"><?php _e( 'Settings' ) ?></h3>
171 <div class="inside">
172 <fieldset class="options">
173 <table class="form-table">
174 <tr>
175 <th><label for="<?php echo $this->domain ?>options[method]"><?php _e( 'Choose encoding method', $this->domain ) ?></label></th>
176 <td><select id="<?php echo $this->domain ?>options[method]" name="<?php echo $this->domain ?>options[method]" class="method-info-select postform">
177 <?php foreach ( $this->methods AS $method => $info ): ?>
178 <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ] ?></option>
179 <?php endforeach; ?>
180 <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php echo __( 'Random', $this->domain ) ?></option>
181 </select>
182 <br /><span class="description"></span>
183 </td>
184 </tr>
185 <tr>
186 <th><label for="<?php echo $this->domain ?>options[encode_tags]"><?php _e( 'Encode tags', $this->domain ) ?></label></th>
187 <td><input type="checkbox" id="<?php echo $this->domain ?>options[encode_tags]" name="<?php echo $this->domain ?>options[encode_tags]" value="1" <?php checked('1', (int) $options['encode_tags']); ?> /> <span class="description"><?php _e( 'Encode <code>[encode_email]</code> tags', $this->domain ) ?></span></td>
188 </tr>
189 <tr>
190 <th><label for="<?php echo $this->domain ?>options[encode_mailtos]"><?php _e( 'Encode mailto-links', $this->domain ) ?></label></th>
191 <td><input type="checkbox" id="<?php echo $this->domain ?>options[encode_mailtos]" name="<?php echo $this->domain ?>options[encode_mailtos]" value="1" <?php checked('1', (int) $options['encode_mailtos']); ?> /> <span class="description"><?php _e( 'Automatically encode all mailto-links', $this->domain ) ?></span></td>
192 </tr>
193 <tr>
194 <th><label for="<?php echo $this->domain ?>options[encode_emails]"><?php _e( 'Encode plain emails', $this->domain ) ?></label></th>
195 <td><input type="checkbox" id="<?php echo $this->domain ?>options[encode_emails]" name="<?php echo $this->domain ?>options[encode_emails]" value="1" <?php checked('1', (int) $options['encode_emails']); ?> /> <span class="description"><?php _e( 'Replace plain emailaddresses to encoded mailto-links', $this->domain ) ?></span></td>
196 </tr>
197 <tr>
198 <th style="padding-top:25px"><label for="<?php echo $this->domain ?>options[filter_comments]"><?php _e( 'Include comments', $this->domain ) ?></label></th>
199 <td style="padding-top:25px"><input type="checkbox" id="<?php echo $this->domain ?>options[filter_comments]" name="<?php echo $this->domain ?>options[filter_comments]" value="1" <?php checked('1', (int) $options['filter_comments']); ?> /> <span class="description"><?php _e( 'Also filter all comments for encoding', $this->domain ) ?></span></td>
200 </tr>
201 <tr>
202 <th><label for="<?php echo $this->domain ?>options[filter_widgets]"><?php _e( 'Include widgets', $this->domain ) ?></label></th>
203 <td><input type="checkbox" id="<?php echo $this->domain ?>options[filter_widgets]" name="<?php echo $this->domain ?>options[filter_widgets]" value="1" <?php checked('1', (int) $options['filter_widgets']); ?> /> <span class="description"><?php _e( 'Also filter widgets for encoding', $this->domain ) ?></span></td>
204 </tr>
205 </table>
206 </fieldset>
207 <p class="submit">
208 <input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" />
209 </p>
210 </div>
211 </div>
212
213 <div class="postbox">
214 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
215 <h3 class="hndle"><?php _e( 'Email Encoder Form', $this->domain ) ?></h3>
216 <div class="inside">
217 <?php echo $this->get_encoder_form(); ?>
218 </div>
219 </div>
220
221 <div class="postbox">
222 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
223 <h3 class="hndle"><?php _e( 'Settings Email Encoder Form', $this->domain ) ?></h3>
224 <div class="inside">
225 <fieldset class="options">
226 <table class="form-table">
227 <tr>
228 <th><label for="<?php echo $this->domain ?>options[form_on_site]"><?php _e( 'Put form on your site', $this->domain ) ?></label></th>
229 <td><input type="checkbox" id="<?php echo $this->domain ?>options[form_on_site]" name="<?php echo $this->domain ?>options[form_on_site]" value="1" <?php checked('1', (int) $options['form_on_site']); ?> /> <span class="description"><?php _e( 'Put the Email Encode Form (like above) on your site by using this tag in a post or page', $this->domain ) ?></span> <code>[email_encoder_form]</code><span class="description"> (<?php _e( 'turn off for when not used', $this->domain ) ?>)</span></td>
230 </tr>
231 <tr>
232 <th><label for="<?php echo $this->domain ?>options[powered_by]"><?php _e( 'Show "powered by"-link', $this->domain ) ?></label></th>
233 <td><input type="checkbox" id="<?php echo $this->domain ?>options[powered_by]" name="<?php echo $this->domain ?>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->domain ) ?></span></td>
234 </tr>
235 </table>
236 </fieldset>
237 <p class="submit">
238 <input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" />
239 </p>
240 </div>
241 </div>
242 </div>
243
244 <div class="postbox-container side metabox-holder meta-box-sortables" style="width: 29%">
245 <div class="postbox">
246 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
247 <h3 class="hndle"><?php _e( 'How to use', $this->domain ) ?></h3>
248 <div class="inside">
249 <h4><?php _e( 'Tags', $this->domain ) ?></h4>
250 <ul>
251 <li><code>[encode_email email="..." display="..."]</code><br/><span class="description"><?php _e( 'Encode the given email, "display" is optional otherwise the email wil be used as display', $this->domain ) ?></span></li>
252 <li><code>[email_encoder_form]</code><br/><span class="description"><?php _e( 'Puts an email encoder form in your post (check if the option is activated on this page)', $this->domain ) ?></span></li>
253 </ul>
254 <h4><?php _e( 'Template functions' ) ?></h4>
255 <ul>
256 <li><code>&lt;?php echo encode_email( 'info@myemail.com', 'My Email' ); ?&gt;</code><br/><span class="description"><?php _e( 'Encode the given email, the second param is display and optional', $this->domain ) ?></span></li>
257 <li><code>&lt;?php echo encode_email_filter( $content ); ?&gt;</code><br/><span class="description"><?php _e( 'Filter the given content for emails to encode', $this->domain ) ?></span></li>
258 </ul>
259 </div>
260 </div>
261
262 <div class="postbox">
263 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
264 <h3 class="hndle"><?php _e( 'About this plugin', $this->domain ) ?></h3>
265 <div class="inside">
266 <h4>FreelancePHP.net</h4>
267 <ul>
268 <li><a href="http://www.freelancephp.net/email-encoder-php-class-wp-plugin/" target="_blank">WP Email Encoder Bundle</a></li>
269 </ul>
270
271 <h4>WordPress Plugin Directory</h4>
272 <ul>
273 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/" target="_blank"><?php _e( 'Description', $this->domain ) ?></a></li>
274 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/installation/" target="_blank"><?php _e( 'Installation', $this->domain ) ?></a></li>
275 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/faq/" target="_blank"><?php _e( 'FAQ', $this->domain ) ?></a></li>
276 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/screenshots/" target="_blank"><?php _e( 'Screenshot', $this->domain ) ?></a></li>
277 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/other_notes/" target="_blank"><?php _e( 'Other Notes', $this->domain ) ?></a></li>
278 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/changelog/" target="_blank"><?php _e( 'Changelog', $this->domain ) ?></a></li>
279 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/stats/" target="_blank"><?php _e( 'Stats', $this->domain ) ?></a></li>
280 </ul>
281 </div>
282 </div>
283 </div>
284 </form>
285 <div class="clear"></div>
286 </div>
287 <?php
288 }
289
290 /**
291 * Get the encoder form (to use as a demo, like on the options page)
292 * @return string
293 */
294 function get_encoder_form() {
295 ob_start();
296 ?>
297 <div class="email-encoder-form">
298 <form>
299 <fieldset>
300 <div class="input">
301 <table>
302 <tr>
303 <tr>
304 <th><label for="email"><?php _e( 'Email address', $this->domain ) ?></label></th>
305 <td><input type="text" class="regular-text" id="email" name="email" /></td>
306 </tr>
307 <tr>
308 <th><label for="display"><?php _e( 'Display', $this->domain ) ?></label></th>
309 <td><input type="text" class="regular-text" id="display" name="display" /></td>
310 </tr>
311 <tr>
312 <th><?php _e( 'Example', $this->domain ) ?></th>
313 <td><span id="example"></span></td>
314 </tr>
315 <tr>
316 <th><label for="encode_method"><?php _e( 'Encode method', $this->domain ) ?></label></th>
317 <td><select id="encode_method" name="encode_method" class="postform">
318 <?php foreach ( $this->methods AS $method => $info ): ?>
319 <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ] ?></option>
320 <?php endforeach; ?>
321 <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php _e( 'Random', $this->domain ) ?></option>
322 </select>
323 <input type="button" id="ajax_encode" value="<?php _e( 'Encode', $this->domain ) ?> &gt;&gt;" />
324 </td>
325 </tr>
326 </tr>
327 </table>
328 </div>
329 <div class="output nodis">
330 <table>
331 <tr>
332 <tr>
333 <th><label for="encoded_output"><?php _e( 'Code', $this->domain ) ?></label></th>
334 <td><textarea class="large-text node" id="encoded_output" name="encoded_output"></textarea></td>
335 </tr>
336 </tr>
337 </table>
338 </div>
339 <?php if ( $this->options['powered_by'] ): ?>
340 <p class="powered-by"><?php _e( 'Powered by', $this->domain ) ?> <a rel="external" href="http://www.freelancephp.net/email-encoder-php-class-wp-plugin/">Email Encoder Bundle</a></p>
341 <?php endif; ?>
342 </fieldset>
343 </form>
344 </div>
345 <?php
346 $form = ob_get_contents();
347 ob_clean();
348
349 return $form;
350 }
351
352 /**
353 * Deactivation plugin method
354 */
355 function deactivation() {
356 delete_option( $this->domain . 'options' );
357 unregister_setting( $this->domain, $this->domain . 'options' );
358 }
359
360 /**
361 * Set options from save values or defaults
362 */
363 function _set_options() {
364 // set options
365 $saved_options = get_option( $this->domain . 'options' );
366 if ( empty( $saved_options ) ) {
367 // set defaults
368 $this->options['encode_tags'] = (int) $this->options['encode_tags'];
369 $this->options['encode_mailtos'] = (int) $this->options['encode_mailtos'];
370 $this->options['encode_emails'] = (int) $this->options['encode_emails'];
371 $this->options['filter_comments'] = (int) $this->options['filter_comments'];
372 $this->options['filter_widgets'] = (int) $this->options['filter_widgets'];
373 $this->options['form_on_site'] = (int) $this->options['form_on_site'];
374 $this->options['powered_by'] = (int) $this->options['powered_by'];
375 } else {
376 // set saved option values
377 $this->set_method( $saved_options['method'] );
378 $this->options['encode_tags'] = ! empty( $saved_options['encode_tags'] );
379 $this->options['encode_mailtos'] = ! empty( $saved_options['encode_mailtos'] );
380 $this->options['encode_emails'] = ! empty( $saved_options['encode_emails'] );
381 $this->options['filter_comments'] = ! empty( $saved_options['filter_comments'] );
382 $this->options['filter_widgets'] = ! empty( $saved_options['filter_widgets'] );
383 $this->options['form_on_site'] = ! empty( $saved_options['form_on_site'] );
384 $this->options['powered_by'] = ! empty( $saved_options['powered_by'] );
385 }
386 }
387
388 /**
389 * Callback used for wp filters
390 */
391 function _filter_callback( $content ) {
392 return $this->filter( $content, $this->options[ 'encode_tags' ], $this->options[ 'encode_mailtos' ], $this->options[ 'encode_emails' ] );
393 }
394
395 } // end class WP_Email_Encoder
396
397
398 /**
399 * Create instance
400 */
401 $WP_Email_Encoder = new WP_Email_Encoder;
402
403
404 /**
405 * Ajax Encoding request
406 */
407 if ( ! empty( $_GET['ajax'] ) ):
408 // input vars
409 $method = $_GET['method'];
410 $email = $_GET['email'];
411 $display = ( empty( $_GET['display'] ) ) ? $email : $_GET['display'];
412
413 $WP_Email_Encoder->set_method( $method );
414
415 echo $WP_Email_Encoder->encode( $email, $display );
416 exit;
417 endif;
418
419
420 /**
421 * Template function for encoding email
422 * @global WP_Email_Encoder $WP_Email_Encoder
423 * @param string $email
424 * @param string $display if non given will be same as email
425 * @return string
426 */
427 if ( ! function_exists( 'encode_email' ) ):
428 function encode_email( $email, $display = NULL ) {
429 global $WP_Email_Encoder;
430 return $WP_Email_Encoder->encode( $email, $display );
431 }
432 endif;
433
434 /**
435 * Template function for encoding emails in the given content
436 * @global WP_Email_Encoder $WP_Email_Encoder
437 * @param string $content
438 * @param boolean $enc_tags Optional, default TRUE
439 * @param boolean $enc_plain_emails Optional, default TRUE
440 * @param boolean $enc_mailtos Optional, default TRUE
441 * @return string
442 */
443 if ( ! function_exists( 'encode_email_filter' ) ):
444 function encode_email_filter( $content, $enc_tags = TRUE, $enc_plain_emails = TRUE, $enc_mailtos = TRUE ) {
445 global $WP_Email_Encoder;
446 return $WP_Email_Encoder->filter( $content, $enc_tags, $enc_plain_emails, $enc_mailtos );
447 }
448 endif;
449
450 ?>