PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 0.32
Email Encoder – Protect Email Addresses and Phone Numbers v0.32
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
631 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.32
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.32';
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 // @todo Doesn't work and cannot find another way to filter all widget contents
118 //add_filter( 'widget_content', array( $this, 'filter_content' ), $priority );
119 }
120 }
121 }
122
123 /**
124 * pre_get_posts filter
125 * @param object $query
126 */
127 function pre_get_posts( $query ) {
128 $priority = 100;
129
130 if ( $query->is_feed ) {
131 // rss feed
132 if ( $this->options[ 'filter_rss' ] ) {
133 add_filter( 'the_content_rss', array( $this, '_filter_rss_callback' ), $priority );
134 add_filter( 'the_content_feed', array( $this, '_filter_rss_callback' ), $priority );
135 add_filter( 'the_excerpt_rss', array( $this, '_filter_rss_callback' ), $priority );
136 add_filter( 'comment_text_rss', array( $this, '_filter_rss_callback' ), $priority );
137 }
138 } else {
139 // post content
140 add_filter( 'the_title', array( $this, '_filter_callback' ), $priority );
141 add_filter( 'the_content', array( $this, '_filter_callback' ), $priority );
142 add_filter( 'the_excerpt', array( $this, '_filter_callback' ), $priority );
143 add_filter( 'get_the_excerpt', array( $this, '_filter_callback' ), $priority );
144 }
145
146 return $query;
147 }
148
149 /**
150 * Callback for the_post action
151 * @param array $posts
152 */
153 function the_posts( $posts ) {
154 if ( empty( $posts ) )
155 return $posts;
156
157 foreach ( $posts as $key => $post ) {
158 if ( stripos( $post->post_content, '[email_encoder_form]' ) > -1 ) {
159 // add style and script for ajax encoder
160 wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ), $this->version );
161 // replace tag by form
162 $posts[$key]->post_content = str_replace( '[email_encoder_form]', $this->get_encoder_form(), $post->post_content );
163 break;
164 }
165 }
166
167 return $posts;
168 }
169
170 /**
171 * Callback admin_menu
172 */
173 function admin_menu() {
174 if ( function_exists('add_options_page') AND current_user_can('manage_options') ) {
175 // add options page
176 $page = add_options_page( 'Email Encoder Bundle', 'Email Encoder Bundle',
177 'manage_options', __FILE__, array( &$this, 'options_page' ) );
178 }
179 }
180
181 /**
182 * Callback admin_init
183 */
184 function admin_init() {
185 // register settings
186 register_setting( $this->domain, $this->options_name );
187
188 // set dashboard postbox
189 wp_admin_css( 'dashboard' );
190 wp_enqueue_script( 'dashboard' );
191
192 // add style and script for ajax encoder
193 wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ), $this->version );
194 }
195
196 /**
197 * Admin options page
198 */
199 function options_page() {
200 ?>
201 <script language="javascript">
202 jQuery(function( $ ){
203 // remove message
204 $( '.settings-error' )
205 .hide()
206 .slideDown( 600 )
207 .delay( 3000 )
208 .slideUp( 600 );
209
210 // set info text for selected encoding method
211 $( '.method-info-select' ).bind( 'change blur keyup', function(){
212 var method = $( this ).val(),
213 $desc = $( this ).parent().find( 'span.description' );
214
215 if ( methodInfo && methodInfo[ method ] ) {
216 $desc.html( methodInfo[ method ][ 'description' ] || '' );
217 } else {
218 $desc.html( '' );
219 }
220 })
221 .blur();
222
223 // "has effect on"
224 $( 'input#encode_emails' )
225 .change(function(){
226 if ( $( this ).attr( 'checked' ) )
227 $( 'input#encode_mailtos' ).attr( 'checked', true );
228 })
229 .change();
230
231 $( 'input#encode_mailtos' )
232 .change(function(){
233 if ( ! $( this ).attr( 'checked' ) )
234 $( 'input#encode_emails' ).attr( 'checked', false );
235 });
236
237 // add form-table class to Encoder Form tables
238 $( '.email-encoder-form table' ).addClass( 'form-table' );
239
240 // slide postbox
241 $( '.postbox' ).find( '.handlediv, .hndle' ).click(function(){
242 var $inside = $( this ).parent().find( '.inside' );
243
244 if ( $inside.css( 'display' ) == 'block' ) {
245 $inside.css({ display:'block' }).slideUp();
246 } else {
247 $inside.css({ display:'none' }).slideDown();
248 }
249 });
250 });
251 </script>
252 <div class="wrap">
253 <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>
254 <h2>Email Encoder Bundle</h2>
255
256 <script language="javascript">
257 var methodInfo = <?php echo json_encode( $this->methods ) ?>;
258 </script>
259 <div class="postbox-container metabox-holder meta-box-sortables" style="width: 69%">
260 <div style="margin:0 5px;">
261 <div class="postbox">
262 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
263 <h3 class="hndle"><?php _e( 'General Settings' ) ?></h3>
264 <div class="inside">
265 <form method="post" action="options.php">
266 <?php
267 settings_fields( $this->domain );
268 $this->_set_options();
269 $options = $this->options;
270 ?>
271 <?php if ( is_plugin_active( 'wp-mailto-links/wp-mailto-links.php' ) ): ?>
272 <p class="description"><?php _e( 'Warning: "WP Mailto Links"-plugin is also activated, which could cause conflicts.', $this->domain ) ?></p>
273 <?php endif; ?>
274 <fieldset class="options">
275 <table class="form-table">
276 <tr>
277 <th><?php _e( 'Choose encoding method', $this->domain ) ?></th>
278 <td><label><select id="<?php echo $this->options_name ?>[method]" name="<?php echo $this->options_name ?>[method]" class="method-info-select postform">
279 <?php foreach ( $this->methods AS $method => $info ): ?>
280 <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ]; if ( $method == 'lim_email_ascii' ){ echo ' (recommended)'; } ?></option>
281 <?php endforeach; ?>
282 <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php echo __( 'Random', $this->domain ) ?></option>
283 </select>
284 <br /><span class="description"></span></label>
285 </td>
286 </tr>
287 <tr>
288 <th><?php _e( 'Encode emails', $this->domain ) ?></th>
289 <td>
290 <label><input type="checkbox" name="<?php echo $this->options_name ?>[encode_tags]" value="1" checked="checked" disabled="disabled" />
291 <span><?php _e( 'Encode <code>[encode_email]</code> tags', $this->domain ) ?></span>
292 </label>
293 <br/><label><input type="checkbox" id="encode_mailtos" name="<?php echo $this->options_name ?>[encode_mailtos]" value="1" <?php checked('1', (int) $options['encode_mailtos']); ?> />
294 <span><?php _e( 'Encode mailto-links', $this->domain ) ?></span>
295 </label>
296 <br/><label><input type="checkbox" id="encode_emails" name="<?php echo $this->options_name ?>[encode_emails]" value="1" <?php checked('1', (int) $options['encode_emails']); ?> />
297 <span><?php _e( 'Replace plain emailaddresses to encoded mailto-links', $this->domain ) ?></span>
298 </label>
299 </td>
300 </tr>
301 <tr>
302 <th><?php _e( 'Options has effect on', $this->domain ) ?></th>
303 <td><label><input type="checkbox" name="<?php echo $this->options_name ?>[filter_posts]" value="1" checked="checked" disabled="disabled" />
304 <span><?php _e( 'Posts', $this->domain ) ?></span>
305 </label>
306 <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']); ?> />
307 <span><?php _e( 'Comments', $this->domain ) ?></span></label>
308 <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']); ?> />
309 <span><?php _e( 'Text widgets', $this->domain ) ?></span></label>
310 </td>
311 </tr>
312 <tr>
313 <th><?php _e( 'Protect RSS feed', $this->domain ) ?></th>
314 <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']); ?> />
315 <span><?php _e( 'Replace emails in RSS feed by <code>*protected email*</code>', $this->domain ) ?></span></label>
316 </td>
317 </tr>
318 </table>
319 </fieldset>
320
321 <fieldset class="options">
322 <table class="form-table">
323 <tr>
324 <th><?php _e( '"Email Encoder Form" settings', $this->domain ) ?></th>
325 <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>
326 </tr>
327 </table>
328 </fieldset>
329 <p class="submit">
330 <input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" />
331 </p>
332 </form>
333 </div>
334 </div>
335
336 <div class="postbox closed">
337 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
338 <h3 class="hndle"><?php _e( 'How to use', $this->domain ) ?></h3>
339 <div class="inside">
340 <h4><?php _e( 'Tags', $this->domain ) ?></h4>
341 <ul>
342 <li><code>[encode_email email="..." display="..." method="..."]</code> <span class="description"><?php _e( 'Encode the given email<br/>"display" is optional otherwise the email wil be used as display<br/>"method" is optional and can be set to use a different method then the options value', $this->domain ) ?></span></li>
343 <li><code>[email_encoder_form]</code> <span class="description"><?php _e( 'Puts an email encoder form in your post', $this->domain ) ?></span></li>
344 </ul>
345 <h4><?php _e( 'Template functions' ) ?></h4>
346 <ul>
347 <li><code>&lt;?php echo encode_email( 'info@myemail.com', 'My Email' ); ?&gt;</code> <span class="description"><?php _e( 'Encode the given email<br/>the second param is $display and optional<br/>the thrid param is $method and optional', $this->domain ) ?></span></li>
348 <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>
349 </ul>
350 </div>
351 </div>
352
353 <div class="postbox">
354 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
355 <h3 class="hndle"><?php _e( 'Email Encoder Form', $this->domain ) ?></h3>
356 <div class="inside">
357 <?php echo $this->get_encoder_form(); ?>
358 </div>
359 </div>
360 </div>
361 </div>
362
363 <div class="postbox-container side metabox-holder meta-box-sortables" style="width:29%;">
364 <div style="margin:0 5px;">
365 <div class="postbox">
366 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
367 <h3 class="hndle"><?php _e( 'About' ) ?>...</h3>
368 <div class="inside">
369 <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>
370 <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>
371 <ul>
372 <li><a href="http://www.freelancephp.net/contact/" target="_blank"><?php _e( 'Questions or suggestions?', $this->domain ) ?></a></li>
373 <li><?php _e( 'If you like this plugin please send your rating at WordPress.org.' ) ?></li>
374 <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>
375 </ul>
376 </div>
377 </div>
378
379 <div class="postbox">
380 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
381 <h3 class="hndle"><?php _e( 'Other Plugins', $this->domain ) ?></h3>
382 <div class="inside">
383 <h4><img src="<?php echo plugins_url( 'images/icon-wp-external-links.png', __FILE__ ) ?>" width="16" height="16" /> WP External Links</h4>
384 <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>
385 <ul>
386 <?php if ( is_plugin_active( 'wp-external-links/wp-external-links.php' ) ): ?>
387 <li><?php _e( 'This plugin is already activated.', $this->domain ) ?> <a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/options-general.php?page=wp-external-links/wp-external-links.php"><?php _e( 'Settings' ) ?></a></li>
388 <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-external-links/wp-external-links.php' ) ): ?>
389 <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e( 'Activate this plugin.', $this->domain ) ?></a></li>
390 <?php else: ?>
391 <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"><?php _e( 'Get this plugin now', $this->domain ) ?></a></li>
392 <?php endif; ?>
393 <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>
394 </ul>
395
396 <h4><img src="<?php echo plugins_url( 'images/icon-wp-mailto-links.png', __FILE__ ) ?>" width="16" height="16" /> WP Mailto Links</h4>
397 <p><?php _e( 'Manage mailto links on your site and protect emails from spambots, set mail icon and more.', $this->domain ) ?></p>
398 <ul>
399 <?php if ( is_plugin_active( 'wp-mailto-links/wp-mailto-links.php' ) ): ?>
400 <li><?php _e( 'This plugin is already activated.', $this->domain ) ?> <a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/options-general.php?page=wp-mailto-links/wp-mailto-links.php"><?php _e( 'Settings' ) ?></a></li>
401 <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-mailto-links/wp-mailto-links.php' ) ): ?>
402 <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e( 'Activate this plugin.', $this->domain ) ?></a></li>
403 <?php else: ?>
404 <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"><?php _e( 'Get this plugin now', $this->domain ) ?></a></li>
405 <?php endif; ?>
406 <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>
407 </ul>
408 </div>
409 </div>
410 </div>
411 </div>
412 <div class="clear"></div>
413 </div>
414 <?php
415 }
416
417 /**
418 * Get the encoder form (to use as a demo, like on the options page)
419 * @return string
420 */
421 function get_encoder_form() {
422 ob_start();
423 ?>
424 <div class="email-encoder-form">
425 <form>
426 <fieldset>
427 <div class="input">
428 <table>
429 <tr>
430 <tr>
431 <th><label for="email"><?php _e( 'Email address', $this->domain ) ?></label></th>
432 <td><input type="text" class="regular-text" id="email" name="email" /></td>
433 </tr>
434 <tr>
435 <th><label for="display"><?php _e( 'Display', $this->domain ) ?></label></th>
436 <td><input type="text" class="regular-text" id="display" name="display" /></td>
437 </tr>
438 <tr>
439 <th><?php _e( 'Example', $this->domain ) ?></th>
440 <td><span id="example"></span></td>
441 </tr>
442 <tr>
443 <th><label for="encode_method"><?php _e( 'Encode method', $this->domain ) ?></label></th>
444 <td><select id="encode_method" name="encode_method" class="postform">
445 <?php foreach ( $this->methods AS $method => $info ): ?>
446 <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ] ?></option>
447 <?php endforeach; ?>
448 <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php _e( 'Random', $this->domain ) ?></option>
449 </select>
450 <input type="button" id="ajax_encode" value="<?php _e( 'Encode', $this->domain ) ?> &gt;&gt;" />
451 </td>
452 </tr>
453 </tr>
454 </table>
455 </div>
456 <div class="output nodis">
457 <table>
458 <tr>
459 <tr>
460 <th><label for="encoded_output"><?php _e( 'Code', $this->domain ) ?></label></th>
461 <td><textarea class="large-text node" id="encoded_output" name="encoded_output"></textarea></td>
462 </tr>
463 </tr>
464 </table>
465 </div>
466 <?php if ( $this->options['powered_by'] ): ?>
467 <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>
468 <?php endif; ?>
469 </fieldset>
470 </form>
471 </div>
472 <?php
473 $form = ob_get_contents();
474 ob_clean();
475
476 return $form;
477 }
478
479 /**
480 * Encode all emails of the given content
481 * @param string $content
482 * @param boolean $enc_tags Optional, default TRUE
483 * @param boolean $enc_mailtos Optional, default TRUE
484 * @param boolean $enc_plain_emails Optional, default TRUE
485 * @return string
486 */
487 function filter( $content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE ) {
488 // encode mailto links
489 if ( $enc_mailtos )
490 $content = preg_replace_callback( $this->regexp_patterns[ 'mailto' ], array( $this, '_callback' ), $content );
491
492 // replace content tags [encode_email] to mailto links
493 if ( $enc_tags )
494 $content = preg_replace_callback( $this->regexp_patterns[ 'tag' ], array( $this, '_callback_shortcode' ), $content );
495
496 // replace plain emails
497 if ( $enc_plain_emails )
498 $content = preg_replace_callback( $this->regexp_patterns[ 'email' ], array( $this, '_callback' ), $content );
499
500 return $content;
501 }
502
503 /**
504 * Deactivation plugin method
505 */
506 function deactivation() {
507 delete_option( $this->options_name );
508 unregister_setting( $this->domain, $this->options_name );
509 }
510
511 /**
512 * Set options from save values or defaults
513 */
514 function _set_options() {
515 // set options
516 $saved_options = get_option( $this->options_name );
517
518 // backwards compatible (old values)
519 if ( empty( $saved_options ) ) {
520 $saved_options = get_option( $this->domain . 'options' );
521 }
522
523 // set all options
524 if ( ! empty( $saved_options ) ) {
525 foreach ( $this->options AS $key => $option ) {
526 $this->options[ $key ] = $saved_options[ $key ];
527 }
528 }
529
530 $this->set_method( $this->options['method'] );
531 }
532
533 /**
534 * Callback for encoding email
535 * @param array $match
536 * @return string
537 */
538 function _callback( $match ) {
539 if ( count( $match ) == 2 )
540 return $this->encode( $match[1] );
541
542 return $this->encode( $match[1], $match[2] );
543 }
544
545 /**
546 * Callback shortcode [encode_email ... ] for encoding email
547 * @param array $match
548 * @return string
549 */
550 function _callback_shortcode( $match ) {
551 $attrs = shortcode_parse_atts( $match[1] );
552
553 if ( ! key_exists( 'email', $attrs ) )
554 return '';
555
556 $email = $attrs[ 'email' ];
557 $display = ( key_exists( 'display', $attrs ) ) ? $attrs[ 'display' ] : $attrs[ 'email' ];
558 $method = ( key_exists( 'method', $attrs ) ) ? $attrs[ 'method' ] : NULL;
559
560 return $this->encode( $email, $display, $method );
561 }
562
563 /**
564 * Callback used for wp filters
565 */
566 function _filter_callback( $content ) {
567 return $this->filter( $content, TRUE, $this->options[ 'encode_mailtos' ], $this->options[ 'encode_emails' ] );
568 }
569
570 /**
571 * Callback RSS
572 */
573 function _filter_rss_callback( $content ) {
574 return preg_replace( $this->regexp_patterns, '*protected email*', $content );
575 }
576
577 } // end class WP_Email_Encoder_Bundle
578
579
580 /**
581 * Create instance
582 */
583 $WP_Email_Encoder_Bundle = new WP_Email_Encoder_Bundle;
584
585
586 /**
587 * Ajax Encoding request
588 */
589 if ( ! empty( $_GET['ajax'] ) ):
590 // input vars
591 $method = $_GET['method'];
592 $email = $_GET['email'];
593 $display = ( empty( $_GET['display'] ) ) ? $email : $_GET['display'];
594
595 echo $WP_Email_Encoder_Bundle->encode( $email, $display, $method );
596 exit;
597 endif;
598
599
600 /**
601 * Template function for encoding email
602 * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
603 * @param string $email
604 * @param string $display if non given will be same as email
605 * @param string $method Optional, else the default setted method will; be used
606 * @return string
607 */
608 if ( ! function_exists( 'encode_email' ) ):
609 function encode_email( $email, $display = NULL, $method = NULL ) {
610 global $WP_Email_Encoder_Bundle;
611 return $WP_Email_Encoder_Bundle->encode( $email, $display, $method );
612 }
613 endif;
614
615 /**
616 * Template function for encoding emails in the given content
617 * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
618 * @param string $content
619 * @param boolean $enc_tags Optional, default TRUE
620 * @param boolean $enc_mailtos Optional, default TRUE
621 * @param boolean $enc_plain_emails Optional, default TRUE
622 * @return string
623 */
624 if ( ! function_exists( 'encode_email_filter' ) ):
625 function encode_email_filter( $content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE ) {
626 global $WP_Email_Encoder_Bundle;
627 return $WP_Email_Encoder_Bundle->filter( $content, $enc_tags, $enc_mailtos, $enc_plain_emails );
628 }
629 endif;
630
631 ?>