PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 0.31
Email Encoder – Protect Email Addresses and Phone Numbers v0.31
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
images 15 years ago js 15 years ago lang 15 years ago methods 15 years ago Lim_Email_Encoder.php 15 years ago email-encoder-bundle.php 15 years ago readme.txt 15 years ago screenshot-1.png 15 years ago screenshot-2.png 15 years ago
email-encoder-bundle.php
599 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: Protect email addresses on your site from spambots and being used for spamming by using one of the encoding methods.
6 Author: Victor Villaverde Laan
7 Version: 0.31
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_Bundle, child of Lim_Email_Encoder
16 * @package Lim_Email_Encoder
17 * @category WordPress Plugins
18 */
19 class WP_Email_Encoder_Bundle extends Lim_Email_Encoder {
20
21 /**
22 * Current version
23 * @var string
24 */
25 var $version = '0.31';
26
27 /**
28 * Used as prefix for options entry and could be used as text domain (for translations)
29 * @var string
30 */
31 var $domain = 'WP_Email_Encoder_Bundle';
32
33 /**
34 * Name of the options
35 * @var string
36 */
37 var $options_name = 'WP_Email_Encoder_Bundle_options';
38
39 /**
40 * @var array
41 */
42 var $options = array(
43 'method' => NULL,
44 'encode_mailtos' => 1,
45 'encode_emails' => 1,
46 'filter_widgets' => 1,
47 'filter_comments' => 1,
48 'filter_rss' => 1,
49 'powered_by' => 1,
50 );
51
52 /**
53 * Regexp
54 * @var array
55 */
56 var $regexp_patterns = array(
57 'mailto' => '/<a.*?href=["\']mailto:(.*?)["\'].*?>(.*?)<\/a[\s+]*>/i',
58 'tag' => '/\[encode_email\s+(.*?)\]/i',
59 'email' => '/([A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6})/i',
60 );
61
62 /**
63 * PHP4 constructor
64 */
65 function WP_Email_Encoder_Bundle() {
66 $this->__construct();
67 }
68
69 /**
70 * PHP5 constructor
71 */
72 function __construct() {
73 parent::__construct();
74
75 // set option values
76 $this->_set_options();
77
78 // load text domain for translations
79 load_plugin_textdomain( $this->domain, dirname( __FILE__ ) . '/lang/', basename( dirname(__FILE__) ) . '/lang/' );
80
81 // add actions
82 add_action( 'init', array( $this, 'init' ) );
83 add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
84 add_action( 'admin_init', array( &$this, 'admin_init' ) );
85 add_action( 'the_posts', array( &$this, 'the_posts' ) );
86 }
87
88 /**
89 * Callback init
90 */
91 function init() {
92 if ( is_admin() ) {
93 // set uninstall hook
94 if ( function_exists( 'register_deactivation_hook' ) )
95 register_deactivation_hook( __FILE__, array( &$this, 'deactivation' ));
96 } else {
97 $priority = 100;
98
99 // set content filters
100 add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ), $priority );
101
102 // comments
103 if ( $this->options[ 'filter_comments' ] ) {
104 add_filter( 'comment_text', array( $this, '_filter_callback' ), $priority );
105 add_filter( 'comment_excerpt', array( $this, '_filter_callback' ), $priority );
106 add_filter( 'get_comment_author_url', array( $this, '_filter_callback' ), $priority );
107 add_filter( 'get_comment_author_link', array( $this, '_filter_callback' ), $priority );
108 add_filter( 'get_comment_author_url_link', array( $this, '_filter_callback' ), $priority );
109 }
110
111 // widgets ( only text widgets )
112 if ( $this->options[ 'filter_widgets' ] ) {
113 add_filter( 'widget_title', array( $this, '_filter_callback' ), $priority );
114 add_filter( 'widget_text', array( $this, '_filter_callback' ), $priority );
115
116 // Only if Widget Logic plugin is installed
117 add_filter( 'widget_content', array( $this, '_filter_callback' ), $priority );
118 }
119 }
120 }
121
122 /**
123 * pre_get_posts filter
124 * @param object $query
125 */
126 function pre_get_posts( $query ) {
127 $priority = 100;
128
129 if ( $query->is_feed ) {
130 // rss feed
131 if ( $this->options[ 'filter_rss' ] ) {
132 add_filter( 'the_content_rss', array( $this, '_filter_rss_callback' ), $priority );
133 add_filter( 'the_content_feed', array( $this, '_filter_rss_callback' ), $priority );
134 add_filter( 'the_excerpt_rss', array( $this, '_filter_rss_callback' ), $priority );
135 add_filter( 'comment_text_rss', array( $this, '_filter_rss_callback' ), $priority );
136 }
137 } else {
138 // post content
139 add_filter( 'the_title', array( $this, '_filter_callback' ), $priority );
140 add_filter( 'the_content', array( $this, '_filter_callback' ), $priority );
141 add_filter( 'the_excerpt', array( $this, '_filter_callback' ), $priority );
142 add_filter( 'get_the_excerpt', array( $this, '_filter_callback' ), $priority );
143 }
144
145 return $query;
146 }
147
148 /**
149 * Callback for the_post action
150 * @param array $posts
151 */
152 function the_posts( $posts ) {
153 if ( empty( $posts ) )
154 return $posts;
155
156 foreach ( $posts as $key => $post ) {
157 if ( stripos( $post->post_content, '[email_encoder_form]' ) > -1 ) {
158 // add style and script for ajax encoder
159 wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ), $this->version );
160 // replace tag by form
161 $posts[$key]->post_content = str_replace( '[email_encoder_form]', $this->get_encoder_form(), $post->post_content );
162 break;
163 }
164 }
165
166 return $posts;
167 }
168
169 /**
170 * Callback admin_menu
171 */
172 function admin_menu() {
173 if ( function_exists('add_options_page') AND current_user_can('manage_options') ) {
174 // add options page
175 $page = add_options_page( 'Email Encoder Bundle', 'Email Encoder Bundle',
176 'manage_options', __FILE__, array( &$this, 'options_page' ) );
177 }
178 }
179
180 /**
181 * Callback admin_init
182 */
183 function admin_init() {
184 // register settings
185 register_setting( $this->domain, $this->options_name );
186
187 // set dashboard postbox
188 wp_admin_css( 'dashboard' );
189 wp_enqueue_script( 'dashboard' );
190
191 // add style and script for ajax encoder
192 wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ), $this->version );
193 }
194
195 /**
196 * Admin options page
197 */
198 function options_page() {
199 ?>
200 <script language="javascript">
201 jQuery(function( $ ){
202 // remove message
203 $( '.settings-error' )
204 .hide()
205 .slideDown( 600 )
206 .delay( 3000 )
207 .slideUp( 600 );
208
209 // set info text for selected encoding method
210 $( '.method-info-select' ).bind( 'change blur keyup', function(){
211 var method = $( this ).val(),
212 $desc = $( this ).parent().find( 'span.description' );
213
214 if ( methodInfo && methodInfo[ method ] ) {
215 $desc.html( methodInfo[ method ][ 'description' ] || '' );
216 } else {
217 $desc.html( '' );
218 }
219 })
220 .blur();
221
222 // add form-table class to Encoder Form tables
223 $( '.email-encoder-form table' ).addClass( 'form-table' );
224 });
225 </script>
226 <div class="wrap">
227 <div class="icon32" id="icon-options-custom" style="background:url( <?php echo plugins_url( 'images/icon-email-encoder-bundle.png', __FILE__ ) ?> ) no-repeat 50% 50%"><br></div>
228 <h2>Email Encoder Bundle</h2>
229
230 <form method="post" action="options.php">
231 <script language="javascript">
232 var methodInfo = <?php echo json_encode( $this->methods ) ?>;
233 </script>
234 <?php
235 settings_fields( $this->domain );
236 $this->_set_options();
237 $options = $this->options;
238 ?>
239 <div class="postbox-container metabox-holder meta-box-sortables" style="width: 69%">
240 <div style="margin:0 5px;">
241 <div class="postbox">
242 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
243 <h3 class="hndle"><?php _e( 'General Settings' ) ?></h3>
244 <div class="inside">
245 <fieldset class="options">
246 <table class="form-table">
247 <tr>
248 <th><?php _e( 'Choose encoding method', $this->domain ) ?></th>
249 <td><label><select id="<?php echo $this->options_name ?>[method]" name="<?php echo $this->options_name ?>[method]" class="method-info-select postform">
250 <?php foreach ( $this->methods AS $method => $info ): ?>
251 <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ] ?></option>
252 <?php endforeach; ?>
253 <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php echo __( 'Random', $this->domain ) ?></option>
254 </select>
255 <br /><span class="description"></span></label>
256 </td>
257 </tr>
258 <tr>
259 <th><?php _e( 'Encode emails', $this->domain ) ?></th>
260 <td>
261 <label><input type="checkbox" name="<?php echo $this->options_name ?>[encode_tags]" value="1" checked="checked" disabled="disabled" />
262 <span><?php _e( 'Encode <code>[encode_email]</code> tags', $this->domain ) ?></span>
263 </label>
264 <br/><label><input type="checkbox" id="<?php echo $this->options_name ?>[encode_mailtos]" name="<?php echo $this->options_name ?>[encode_mailtos]" value="1" <?php checked('1', (int) $options['encode_mailtos']); ?> />
265 <span><?php _e( 'Encode mailto-links', $this->domain ) ?></span>
266 </label>
267 <br/><label><input type="checkbox" id="<?php echo $this->options_name ?>[encode_emails]" name="<?php echo $this->options_name ?>[encode_emails]" value="1" <?php checked('1', (int) $options['encode_emails']); ?> />
268 <span><?php _e( 'Replace plain emailaddresses to encoded mailto-links', $this->domain ) ?></span>
269 </label>
270 <?php if ( $enc_conflict ): ?>
271 <br/><span class="description"><?php _e( 'Warning: "WP Mailto Links Plugin" is activated, turn off this option when a conflict occures.', $this->domain ) ?></span>
272 <?php endif; ?>
273 </td>
274 </tr>
275 <tr>
276 <th><?php _e( 'Options has effect on', $this->domain ) ?></th>
277 <td><label><input type="checkbox" name="<?php echo $this->options_name ?>[filter_posts]" value="1" checked="checked" disabled="disabled" />
278 <span><?php _e( 'Posts', $this->domain ) ?></span>
279 </label>
280 <br/><label><input type="checkbox" id="<?php echo $this->options_name ?>[filter_comments]" name="<?php echo $this->options_name ?>[filter_comments]" value="1" <?php checked('1', (int) $options['filter_comments']); ?> />
281 <span><?php _e( 'Comments', $this->domain ) ?></span></label>
282 <br/><label><input type="checkbox" id="<?php echo $this->options_name ?>[filter_widgets]" name="<?php echo $this->options_name ?>[filter_widgets]" value="1" <?php checked('1', (int) $options['filter_widgets']); ?> />
283 <span><?php _e( 'Text widgets', $this->domain ) ?></span></label>
284 </td>
285 </tr>
286 <tr>
287 <th><?php _e( 'Protect RSS feed', $this->domain ) ?></th>
288 <td><label><input type="checkbox" id="<?php echo $this->options_name ?>[filter_rss]" name="<?php echo $this->options_name ?>[filter_rss]" value="1" <?php checked('1', (int) $options['filter_rss']); ?> />
289 <span><?php _e( 'Replace emails in RSS feed by <code>*protected email*</code>', $this->domain ) ?></span></label>
290 </td>
291 </tr>
292 </table>
293 </fieldset>
294 <p class="submit">
295 <input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" />
296 </p>
297 </div>
298 </div>
299
300 <div class="postbox closed">
301 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
302 <h3 class="hndle"><?php _e( 'How to use', $this->domain ) ?></h3>
303 <div class="inside">
304 <h4><?php _e( 'Tags', $this->domain ) ?></h4>
305 <ul>
306 <li><code>[encode_email email="..." display="..."]</code> <span class="description"><?php _e( 'Encode the given email, "display" is optional otherwise the email wil be used as display', $this->domain ) ?></span></li>
307 <li><code>[email_encoder_form]</code> <span class="description"><?php _e( 'Puts an email encoder form in your post', $this->domain ) ?></span></li>
308 </ul>
309 <h4><?php _e( 'Template functions' ) ?></h4>
310 <ul>
311 <li><code>&lt;?php echo encode_email( 'info@myemail.com', 'My Email' ); ?&gt;</code> <span class="description"><?php _e( 'Encode the given email, the second param is display and optional', $this->domain ) ?></span></li>
312 <li><code>&lt;?php echo encode_email_filter( $content ); ?&gt;</code> <span class="description"><?php _e( 'Filter the given content for emails to encode', $this->domain ) ?></span></li>
313 </ul>
314 </div>
315 </div>
316
317 <div class="postbox">
318 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
319 <h3 class="hndle"><?php _e( 'Email Encoder Form', $this->domain ) ?></h3>
320 <div class="inside">
321 <?php echo $this->get_encoder_form(); ?>
322
323 <fieldset class="options">
324 <table class="form-table">
325 <tr>
326 <th><?php _e( 'Show "powered by"-link', $this->domain ) ?></th>
327 <td><label><input type="checkbox" id="<?php echo $this->options_name ?>[powered_by]" name="<?php echo $this->options_name ?>[powered_by]" value="1" <?php checked('1', (int) $options['powered_by']); ?> /> <span><?php _e( 'Show the "powered by"-link on bottom of the encode form', $this->domain ) ?></span></label></td>
328 </tr>
329 </table>
330 </fieldset>
331 <p class="submit">
332 <input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" />
333 </p>
334 </div>
335 </div>
336 </div>
337 </div>
338
339 <div class="postbox-container side metabox-holder meta-box-sortables" style="width:29%;">
340 <div style="margin:0 5px;">
341 <div class="postbox">
342 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
343 <h3 class="hndle"><?php _e( 'About' ) ?>...</h3>
344 <div class="inside">
345 <h4><img src="<?php echo plugins_url( 'images/icon-email-encoder-bundle.png', __FILE__ ) ?>" width="16" height="16" /> Email Encoder Bundle (v<?php echo $this->version ?>)</h4>
346 <p><?php _e( 'Protect email addresses on your site from spambots and being used for spamming by using one of the encoding methods.', $this->domain ) ?></p>
347 <ul>
348 <li><a href="http://www.freelancephp.net/contact/" target="_blank"><?php _e( 'Questions or suggestions?', $this->domain ) ?></a></li>
349 <li><?php _e( 'If you like this plugin please send your rating at WordPress.org.' ) ?></li>
350 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/" target="_blank">WordPress.org</a> | <a href="http://www.freelancephp.net/email-encoder-php-class-wp-plugin/" target="_blank">FreelancePHP.net</a></li>
351 </ul>
352 </div>
353 </div>
354
355 <div class="postbox">
356 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
357 <h3 class="hndle"><?php _e( 'Other Plugins', $this->domain ) ?></h3>
358 <div class="inside">
359 <h4><img src="<?php echo plugins_url( 'images/icon-wp-external-links.png', __FILE__ ) ?>" width="16" height="16" /> WP External Links</h4>
360 <p><?php _e( 'Manage external links on your site: open in new window/tab, set icon, add "external", add "nofollow" and more.', $this->domain ) ?></p>
361 <ul>
362 <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugin-install.php?tab=search&type=term&s=WP+External+Links+freelancephp&plugin-search-input=Search+Plugins" target="_blank"><?php _e( 'Get this plugin now' ) ?></a></li>
363 <li><a href="http://wordpress.org/extend/plugins/wp-external-links/" target="_blank">WordPress.org</a> | <a href="http://www.freelancephp.net/wp-external-links-plugin/" target="_blank">FreelancePHP.net</a></li>
364 </ul>
365
366 <h4><img src="<?php echo plugins_url( 'images/icon-wp-mailto-links.png', __FILE__ ) ?>" width="16" height="16" /> WP Mailto Links</h4>
367 <p><?php _e( 'Manage mailto links on your site and protect emails from spambots, set mail icon and more.', $this->domain ) ?></p>
368 <ul>
369 <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugin-install.php?tab=search&type=term&s=WP+Mailto+Links+freelancephp&plugin-search-input=Search+Plugins" target="_blank"><?php _e( 'Get this plugin now' ) ?></a></li>
370 <li><a href="http://wordpress.org/extend/plugins/wp-mailto-links/" target="_blank">WordPress.org</a> | <a href="http://www.freelancephp.net/wp-mailto-links-plugin/" target="_blank">FreelancePHP.net</a></li>
371 </ul>
372 </div>
373 </div>
374 </div>
375 </div>
376 </form>
377 <div class="clear"></div>
378 </div>
379 <?php
380 }
381
382 /**
383 * Get the encoder form (to use as a demo, like on the options page)
384 * @return string
385 */
386 function get_encoder_form() {
387 ob_start();
388 ?>
389 <div class="email-encoder-form">
390 <form>
391 <fieldset>
392 <div class="input">
393 <table>
394 <tr>
395 <tr>
396 <th><label for="email"><?php _e( 'Email address', $this->domain ) ?></label></th>
397 <td><input type="text" class="regular-text" id="email" name="email" /></td>
398 </tr>
399 <tr>
400 <th><label for="display"><?php _e( 'Display', $this->domain ) ?></label></th>
401 <td><input type="text" class="regular-text" id="display" name="display" /></td>
402 </tr>
403 <tr>
404 <th><?php _e( 'Example', $this->domain ) ?></th>
405 <td><span id="example"></span></td>
406 </tr>
407 <tr>
408 <th><label for="encode_method"><?php _e( 'Encode method', $this->domain ) ?></label></th>
409 <td><select id="encode_method" name="encode_method" class="postform">
410 <?php foreach ( $this->methods AS $method => $info ): ?>
411 <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ] ?></option>
412 <?php endforeach; ?>
413 <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php _e( 'Random', $this->domain ) ?></option>
414 </select>
415 <input type="button" id="ajax_encode" value="<?php _e( 'Encode', $this->domain ) ?> &gt;&gt;" />
416 </td>
417 </tr>
418 </tr>
419 </table>
420 </div>
421 <div class="output nodis">
422 <table>
423 <tr>
424 <tr>
425 <th><label for="encoded_output"><?php _e( 'Code', $this->domain ) ?></label></th>
426 <td><textarea class="large-text node" id="encoded_output" name="encoded_output"></textarea></td>
427 </tr>
428 </tr>
429 </table>
430 </div>
431 <?php if ( $this->options['powered_by'] ): ?>
432 <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>
433 <?php endif; ?>
434 </fieldset>
435 </form>
436 </div>
437 <?php
438 $form = ob_get_contents();
439 ob_clean();
440
441 return $form;
442 }
443
444 /**
445 * Encode all emails of the given content
446 * @param string $content
447 * @param boolean $enc_tags Optional, default TRUE
448 * @param boolean $enc_mailtos Optional, default TRUE
449 * @param boolean $enc_plain_emails Optional, default TRUE
450 * @return string
451 */
452 function filter( $content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE ) {
453 // encode mailto links
454 if ( $enc_mailtos )
455 $content = preg_replace_callback( $this->regexp_patterns[ 'mailto' ], array( $this, '_callback' ), $content );
456
457 // replace content tags [encode_email] to mailto links
458 if ( $enc_tags )
459 $content = preg_replace_callback( $this->regexp_patterns[ 'tag' ], array( $this, '_callback_shortcode' ), $content );
460
461 // replace plain emails
462 if ( $enc_plain_emails )
463 $content = preg_replace_callback( $this->regexp_patterns[ 'email' ], array( $this, '_callback' ), $content );
464
465 return $content;
466 }
467
468 /**
469 * Deactivation plugin method
470 */
471 function deactivation() {
472 delete_option( $this->options_name );
473 unregister_setting( $this->domain, $this->options_name );
474 }
475
476 /**
477 * Set options from save values or defaults
478 */
479 function _set_options() {
480 // set options
481 $saved_options = get_option( $this->options_name );
482
483 // backwards compatible (old values)
484 if ( empty( $saved_options ) ) {
485 $saved_options = get_option( $this->domain . 'options' );
486 }
487
488 // set all options
489 if ( ! empty( $saved_options ) ) {
490 foreach ( $this->options AS $key => $option ) {
491 $this->options[ $key ] = $saved_options[ $key ];
492 }
493 }
494
495 $this->set_method( $this->options['method'] );
496 }
497
498 /**
499 * Callback for encoding email
500 * @param array $match
501 * @return string
502 */
503 function _callback( $match ) {
504 if ( count( $match ) == 2 )
505 return $this->encode( $match[1] );
506
507 return $this->encode( $match[1], $match[2] );
508 }
509
510 /**
511 * Callback shortcode [encode_email ... ] for encoding email
512 * @param array $match
513 * @return string
514 */
515 function _callback_shortcode( $match ) {
516 $attrs = shortcode_parse_atts( $match[1] );
517
518 if ( key_exists( 'email', $attrs ) )
519 $email = $attrs[ 'email' ];
520
521 if ( key_exists( 'display', $attrs ) ) {
522 $display = $attrs[ 'display' ];
523 } else {
524 $display = $attrs[ 'email' ];
525 }
526
527 return $this->encode( $email, $display );
528 }
529
530 /**
531 * Callback used for wp filters
532 */
533 function _filter_callback( $content ) {
534 return $this->filter( $content, TRUE, $this->options[ 'encode_mailtos' ], $this->options[ 'encode_emails' ] );
535 }
536
537 /**
538 * Callback RSS
539 */
540 function _filter_rss_callback( $content ) {
541 return preg_replace( $this->regexp_patterns, '*protected email*', $content );
542 }
543
544 } // end class WP_Email_Encoder_Bundle
545
546
547 /**
548 * Create instance
549 */
550 $WP_Email_Encoder_Bundle = new WP_Email_Encoder_Bundle;
551
552
553 /**
554 * Ajax Encoding request
555 */
556 if ( ! empty( $_GET['ajax'] ) ):
557 // input vars
558 $method = $_GET['method'];
559 $email = $_GET['email'];
560 $display = ( empty( $_GET['display'] ) ) ? $email : $_GET['display'];
561
562 $WP_Email_Encoder_Bundle->set_method( $method );
563
564 echo $WP_Email_Encoder_Bundle->encode( $email, $display );
565 exit;
566 endif;
567
568
569 /**
570 * Template function for encoding email
571 * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
572 * @param string $email
573 * @param string $display if non given will be same as email
574 * @return string
575 */
576 if ( ! function_exists( 'encode_email' ) ):
577 function encode_email( $email, $display = NULL ) {
578 global $WP_Email_Encoder_Bundle;
579 return $WP_Email_Encoder_Bundle->encode( $email, $display );
580 }
581 endif;
582
583 /**
584 * Template function for encoding emails in the given content
585 * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
586 * @param string $content
587 * @param boolean $enc_tags Optional, default TRUE
588 * @param boolean $enc_mailtos Optional, default TRUE
589 * @param boolean $enc_plain_emails Optional, default TRUE
590 * @return string
591 */
592 if ( ! function_exists( 'encode_email_filter' ) ):
593 function encode_email_filter( $content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE ) {
594 global $WP_Email_Encoder_Bundle;
595 return $WP_Email_Encoder_Bundle->filter( $content, $enc_tags, $enc_mailtos, $enc_plain_emails );
596 }
597 endif;
598
599 ?>