PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 0.40
Email Encoder – Protect Email Addresses and Phone Numbers v0.40
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 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
786 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.40
8 Author URI: http://www.freelancephp.net
9 License: Dual licensed under the MIT and GPL licenses
10 */
11
12 /**
13 * Class WP_Email_Encoder_Bundle
14 * @package WP_Email_Encoder_Bundle
15 * @category WordPress Plugins
16 */
17 class WP_Email_Encoder_Bundle {
18
19 /**
20 * Current version
21 * @var string
22 */
23 var $version = '0.40';
24
25 /**
26 * Used as prefix for options entry and could be used as text domain (for translations)
27 * @var string
28 */
29 var $domain = 'WP_Email_Encoder_Bundle';
30
31 /**
32 * Name of the options
33 * @var string
34 */
35 var $options_name = 'WP_Email_Encoder_Bundle_options';
36
37 /**
38 * @var array
39 */
40 var $options = array(
41 'method' => NULL,
42 'encode_mailtos' => 1,
43 'encode_emails' => 1,
44 'class_name' => 'mailto-link',
45 'filter_posts' => 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+]*>/is',
58 'tag' => '/\[encode_email\s+(.*?)\]/is',
59 'email' => '/([A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6})/is',
60 );
61
62 /**
63 * @var array
64 */
65 var $methods = array();
66
67 /**
68 * @var string
69 */
70 var $method = NULL;
71
72
73 /**
74 * PHP4 constructor
75 */
76 function WP_Email_Encoder_Bundle() {
77 $this->__construct();
78 }
79
80 /**
81 * PHP5 constructor
82 */
83 function __construct() {
84 // include all available method files
85 $this->_load_methods();
86
87 // set method
88 $this->set_method( $this->options[ 'method' ] );
89
90 // set option values
91 $this->_set_options();
92
93 // load text domain for translations
94 load_plugin_textdomain( $this->domain, dirname( __FILE__ ) . '/lang/', basename( dirname(__FILE__) ) . '/lang/' );
95
96 // set uninstall hook
97 if ( function_exists( 'register_deactivation_hook' ) )
98 register_deactivation_hook( __FILE__, array( $this, 'deactivation' ));
99
100 // add actions
101 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
102 add_action( 'admin_init', array( $this, 'admin_init' ) );
103 add_action( 'the_posts', array( $this, 'the_posts' ) );
104
105 // set filters
106 add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ), $priority );
107 }
108
109 /**
110 * pre_get_posts filter
111 * @param object $query
112 */
113 function pre_get_posts( $query ) {
114 if ( is_admin() )
115 return $query;
116
117 $priority = 100;
118
119 if ( $query->is_feed ) {
120 // rss feed
121 if ( $this->options[ 'filter_rss' ] ) {
122 add_filter( 'the_title', array( $this, '_filter_rss_callback' ), $priority );
123 add_filter( 'the_content', array( $this, '_filter_rss_callback' ), $priority );
124 add_filter( 'the_excerpt', array( $this, '_filter_rss_callback' ), $priority );
125 add_filter( 'the_title_rss', array( $this, '_filter_rss_callback' ), $priority );
126 add_filter( 'the_content_rss', array( $this, '_filter_rss_callback' ), $priority );
127 add_filter( 'the_excerpt_rss', array( $this, '_filter_rss_callback' ), $priority );
128 add_filter( 'comment_text_rss', array( $this, '_filter_rss_callback' ), $priority );
129 add_filter( 'comment_author_rss ', array( $this, '_filter_rss_callback' ), $priority );
130 add_filter( 'the_category_rss ', array( $this, '_filter_rss_callback' ), $priority );
131 add_filter( 'the_content_feed', array( $this, '_filter_rss_callback' ), $priority );
132 add_filter( 'author feed link', array( $this, '_filter_rss_callback' ), $priority );
133 add_filter( 'feed_link', array( $this, '_filter_rss_callback' ), $priority );
134 }
135 } else {
136 // post content
137 if ( $this->options[ 'filter_posts' ] ) {
138 add_filter( 'the_title', array( $this, '_filter_callback' ), $priority );
139 add_filter( 'the_content', array( $this, '_filter_callback' ), $priority );
140 add_filter( 'the_excerpt', array( $this, '_filter_callback' ), $priority );
141 add_filter( 'get_the_excerpt', array( $this, '_filter_callback' ), $priority );
142 }
143
144 // comments
145 if ( $this->options[ 'filter_comments' ] ) {
146 add_filter( 'comment_text', array( $this, '_filter_callback' ), $priority );
147 add_filter( 'comment_excerpt', array( $this, '_filter_callback' ), $priority );
148 add_filter( 'comment_url', array( $this, '_filter_callback' ), $priority );
149 add_filter( 'get_comment_author_url', array( $this, '_filter_callback' ), $priority );
150 add_filter( 'get_comment_author_link', array( $this, '_filter_callback' ), $priority );
151 add_filter( 'get_comment_author_url_link', array( $this, '_filter_callback' ), $priority );
152 }
153
154 // widgets ( only text widgets )
155 if ( $this->options[ 'filter_widgets' ] ) {
156 add_filter( 'widget_title', array( $this, '_filter_callback' ), $priority );
157 add_filter( 'widget_text', array( $this, '_filter_callback' ), $priority );
158
159 // Only if Widget Logic plugin is installed
160 // @todo Doesn't work and cannot find another way to filter all widget contents
161 //add_filter( 'widget_content', array( $this, 'filter_content' ), $priority );
162 }
163 }
164
165 return $query;
166 }
167
168 /**
169 * Callback for the_post action
170 * @param array $posts
171 */
172 function the_posts( $posts ) {
173 if ( empty( $posts ) )
174 return $posts;
175
176 foreach ( $posts as $key => $post ) {
177 if ( stripos( $post->post_content, '[email_encoder_form]' ) > -1 ) {
178 // add style and script for ajax encoder
179 wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ), $this->version );
180
181 // replace tag by form
182 $posts[$key]->post_content = str_replace( '[email_encoder_form]', $this->get_encoder_form(), $post->post_content );
183 break;
184 }
185 }
186
187 return $posts;
188 }
189
190 /**
191 * Callback admin_menu
192 */
193 function admin_menu() {
194 if ( function_exists('add_options_page') AND current_user_can('manage_options') ) {
195 // add options page
196 $page = add_options_page( 'Email Encoder Bundle', 'Email Encoder Bundle',
197 'manage_options', __FILE__, array( $this, 'options_page' ) );
198 }
199 }
200
201 /**
202 * Callback admin_init
203 */
204 function admin_init() {
205 // register settings
206 register_setting( $this->domain, $this->options_name );
207
208 // set dashboard postbox
209 wp_admin_css( 'dashboard' );
210 wp_enqueue_script( 'dashboard' );
211
212 // add style and script for ajax encoder
213 wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ), $this->version );
214 }
215
216 /**
217 * Admin options page
218 */
219 function options_page() {
220 ?>
221 <script language="javascript">
222 jQuery(function( $ ){
223 // remove message
224 $( '.settings-error' )
225 .hide()
226 .slideDown( 600 )
227 .delay( 3000 )
228 .slideUp( 600 );
229
230 // set info text for selected encoding method
231 $( '.method-info-select' ).bind( 'change blur keyup', function(){
232 var method = $( this ).val(),
233 $desc = $( this ).parent().find( 'span.description' );
234
235 if ( methodInfo && methodInfo[ method ] ) {
236 $desc.html( methodInfo[ method ][ 'description' ] || '' );
237 } else {
238 $desc.html( '' );
239 }
240 })
241 .blur();
242
243 // "has effect on"
244 $( 'input#encode_emails' )
245 .change(function(){
246 if ( $( this ).attr( 'checked' ) )
247 $( 'input#encode_mailtos' ).attr( 'checked', true );
248 })
249 .change();
250
251 $( 'input#encode_mailtos' )
252 .change(function(){
253 if ( ! $( this ).attr( 'checked' ) )
254 $( 'input#encode_emails' ).attr( 'checked', false );
255 });
256
257 // add form-table class to Encoder Form tables
258 $( '.email-encoder-form table' ).addClass( 'form-table' );
259
260 // slide postbox
261 $( '.postbox' ).find( '.handlediv, .hndle' ).click(function(){
262 var $inside = $( this ).parent().find( '.inside' );
263
264 if ( $inside.css( 'display' ) == 'block' ) {
265 $inside.css({ display:'block' }).slideUp();
266 } else {
267 $inside.css({ display:'none' }).slideDown();
268 }
269 });
270 });
271 </script>
272 <div class="wrap">
273 <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>
274 <h2>Email Encoder Bundle</h2>
275
276 <script language="javascript">
277 var methodInfo = <?php echo json_encode( $this->methods ) ?>;
278 </script>
279 <div class="postbox-container metabox-holder meta-box-sortables" style="width: 69%">
280 <div style="margin:0 5px;">
281 <div class="postbox">
282 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
283 <h3 class="hndle"><?php _e( 'General Settings' ) ?></h3>
284 <div class="inside">
285 <form method="post" action="options.php">
286 <?php
287 settings_fields( $this->domain );
288 $this->_set_options();
289 $options = $this->options;
290 ?>
291 <?php if ( is_plugin_active( 'wp-mailto-links/wp-mailto-links.php' ) ): ?>
292 <p class="description"><?php _e( 'Warning: "WP Mailto Links"-plugin is also activated, which could cause conflicts.', $this->domain ) ?></p>
293 <?php endif; ?>
294 <fieldset class="options">
295 <table class="form-table">
296 <tr>
297 <th><?php _e( 'Choose encoding method', $this->domain ) ?></th>
298 <td><label><select id="<?php echo $this->options_name ?>[method]" name="<?php echo $this->options_name ?>[method]" class="method-info-select postform">
299 <?php foreach ( $this->methods AS $method => $info ): ?>
300 <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>
301 <?php endforeach; ?>
302 <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php echo __( 'Random', $this->domain ) ?></option>
303 </select>
304 <br /><span class="description"></span></label>
305 </td>
306 </tr>
307 <tr>
308 <th><?php _e( 'Encode emails', $this->domain ) ?></th>
309 <td>
310 <label><input type="checkbox" name="<?php echo $this->options_name ?>[encode_tags]" value="1" checked="checked" disabled="disabled" />
311 <span><?php _e( 'Encode <code>[encode_email]</code> tags', $this->domain ) ?></span>
312 </label>
313 <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']); ?> />
314 <span><?php _e( 'Encode mailto-links', $this->domain ) ?></span>
315 </label>
316 <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']); ?> />
317 <span><?php _e( 'Replace plain emailaddresses to encoded mailto-links', $this->domain ) ?></span>
318 </label>
319 </td>
320 </tr>
321 <tr>
322 <th><?php _e( 'Set class for mailto-links', $this->domain ) ?></th>
323 <td><label><input type="text" id="<?php echo $this->options_name ?>[class_name]" name="<?php echo $this->options_name ?>[class_name]" value="<?php echo $options['class_name']; ?>" />
324 <span><?php _e( 'Set class-attribute for encoded mailto links (optional)', $this->domain ) ?></span></label></td>
325 </tr>
326 <tr>
327 <th><?php _e( 'Options has effect on', $this->domain ) ?></th>
328 <td><label><input type="checkbox" name="<?php echo $this->options_name ?>[filter_posts]" value="1" <?php checked('1', (int) $options['filter_posts']); ?> />
329 <span><?php _e( 'Posts', $this->domain ) ?></span>
330 </label>
331 <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']); ?> />
332 <span><?php _e( 'Comments', $this->domain ) ?></span></label>
333 <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']); ?> />
334 <span><?php _e( 'Text widgets', $this->domain ) ?></span></label>
335 </td>
336 </tr>
337 <tr>
338 <th><?php _e( 'Protect RSS feed', $this->domain ) ?></th>
339 <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']); ?> />
340 <span><?php _e( 'Replace emails in RSS feed by <code>*protected email*</code>', $this->domain ) ?></span></label>
341 </td>
342 </tr>
343 </table>
344 </fieldset>
345
346 <fieldset class="options">
347 <table class="form-table">
348 <tr>
349 <th><?php _e( '"Email Encoder Form" settings', $this->domain ) ?></th>
350 <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>
351 </tr>
352 </table>
353 </fieldset>
354 <p class="submit">
355 <input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" />
356 </p>
357 </form>
358 </div>
359 </div>
360
361 <div class="postbox closed">
362 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
363 <h3 class="hndle"><?php _e( 'How to use', $this->domain ) ?></h3>
364 <div class="inside">
365 <h4><?php _e( 'Tags', $this->domain ) ?></h4>
366 <ul>
367 <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>
368 <li><code>[email_encoder_form]</code> <span class="description"><?php _e( 'Puts an email encoder form in your post', $this->domain ) ?></span></li>
369 </ul>
370 <h4><?php _e( 'Template functions' ) ?></h4>
371 <ul>
372 <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>
373 <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>
374 </ul>
375 </div>
376 </div>
377
378 <div class="postbox">
379 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
380 <h3 class="hndle"><?php _e( 'Email Encoder Form', $this->domain ) ?></h3>
381 <div class="inside">
382 <?php echo $this->get_encoder_form(); ?>
383 </div>
384 </div>
385 </div>
386 </div>
387
388 <div class="postbox-container side metabox-holder meta-box-sortables" style="width:29%;">
389 <div style="margin:0 5px;">
390 <div class="postbox">
391 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
392 <h3 class="hndle"><?php _e( 'About' ) ?>...</h3>
393 <div class="inside">
394 <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>
395 <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>
396 <ul>
397 <li><a href="http://www.freelancephp.net/contact/" target="_blank"><?php _e( 'Questions or suggestions?', $this->domain ) ?></a></li>
398 <li><?php _e( 'If you like this plugin please send your rating at WordPress.org.' ) ?></li>
399 <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>
400 </ul>
401 </div>
402 </div>
403
404 <div class="postbox">
405 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
406 <h3 class="hndle"><?php _e( 'Other Plugins', $this->domain ) ?></h3>
407 <div class="inside">
408 <h4><img src="<?php echo plugins_url( 'images/icon-wp-external-links.png', __FILE__ ) ?>" width="16" height="16" /> WP External Links</h4>
409 <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>
410 <ul>
411 <?php if ( is_plugin_active( 'wp-external-links/wp-external-links.php' ) ): ?>
412 <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>
413 <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-external-links/wp-external-links.php' ) ): ?>
414 <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e( 'Activate this plugin.', $this->domain ) ?></a></li>
415 <?php else: ?>
416 <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>
417 <?php endif; ?>
418 <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>
419 </ul>
420
421 <h4><img src="<?php echo plugins_url( 'images/icon-wp-mailto-links.png', __FILE__ ) ?>" width="16" height="16" /> WP Mailto Links</h4>
422 <p><?php _e( 'Manage mailto links on your site and protect emails from spambots, set mail icon and more.', $this->domain ) ?></p>
423 <ul>
424 <?php if ( is_plugin_active( 'wp-mailto-links/wp-mailto-links.php' ) ): ?>
425 <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>
426 <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-mailto-links/wp-mailto-links.php' ) ): ?>
427 <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e( 'Activate this plugin.', $this->domain ) ?></a></li>
428 <?php else: ?>
429 <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>
430 <?php endif; ?>
431 <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>
432 </ul>
433 </div>
434 </div>
435 </div>
436 </div>
437 <div class="clear"></div>
438 </div>
439 <?php
440 }
441
442 /**
443 * Get the encoder form (to use as a demo, like on the options page)
444 * @return string
445 */
446 function get_encoder_form() {
447 ob_start();
448 ?>
449 <div class="email-encoder-form">
450 <form>
451 <fieldset>
452 <div class="input">
453 <table>
454 <tr>
455 <tr>
456 <th><label for="email"><?php _e( 'Email address', $this->domain ) ?></label></th>
457 <td><input type="text" class="regular-text" id="email" name="email" /></td>
458 </tr>
459 <tr>
460 <th><label for="display"><?php _e( 'Display', $this->domain ) ?></label></th>
461 <td><input type="text" class="regular-text" id="display" name="display" /></td>
462 </tr>
463 <tr>
464 <th><?php _e( 'Example', $this->domain ) ?></th>
465 <td><span id="example"></span></td>
466 </tr>
467 <tr>
468 <th><label for="encode_method"><?php _e( 'Encode method', $this->domain ) ?></label></th>
469 <td><select id="encode_method" name="encode_method" class="postform">
470 <?php foreach ( $this->methods AS $method => $info ): ?>
471 <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ] ?></option>
472 <?php endforeach; ?>
473 <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php _e( 'Random', $this->domain ) ?></option>
474 </select>
475 <input type="button" id="ajax_encode" value="<?php _e( 'Encode', $this->domain ) ?> &gt;&gt;" />
476 </td>
477 </tr>
478 </tr>
479 </table>
480 </div>
481 <div class="output nodis">
482 <table>
483 <tr>
484 <tr>
485 <th><label for="encoded_output"><?php _e( 'Code', $this->domain ) ?></label></th>
486 <td><textarea class="large-text node" id="encoded_output" name="encoded_output"></textarea></td>
487 </tr>
488 </tr>
489 </table>
490 </div>
491 <?php if ( $this->options['powered_by'] ): ?>
492 <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>
493 <?php endif; ?>
494 </fieldset>
495 </form>
496 </div>
497 <?php
498 $form = ob_get_contents();
499 ob_clean();
500
501 return $form;
502 }
503
504 /**
505 * Encode all emails of the given content
506 * @param string $content
507 * @param boolean $enc_tags Optional, default TRUE
508 * @param boolean $enc_mailtos Optional, default TRUE
509 * @param boolean $enc_plain_emails Optional, default TRUE
510 * @return string
511 */
512 function filter( $content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE ) {
513 // encode mailto links
514 if ( $enc_mailtos )
515 $content = preg_replace_callback( $this->regexp_patterns[ 'mailto' ], array( $this, '_callback' ), $content );
516
517 // replace content tags [encode_email] to mailto links
518 if ( $enc_tags )
519 $content = preg_replace_callback( $this->regexp_patterns[ 'tag' ], array( $this, '_callback_shortcode' ), $content );
520
521 // replace plain emails
522 if ( $enc_plain_emails )
523 $content = preg_replace_callback( $this->regexp_patterns[ 'email' ], array( $this, '_callback' ), $content );
524
525 return $content;
526 }
527
528 /**
529 * Deactivation plugin method
530 */
531 function deactivation() {
532 delete_option( $this->options_name );
533 unregister_setting( $this->domain, $this->options_name );
534 }
535
536 /**
537 * Set options from save values or defaults
538 */
539 function _set_options() {
540 // set options
541 $saved_options = get_option( $this->options_name );
542
543 // backwards compatible (old values)
544 if ( empty( $saved_options ) ) {
545 $saved_options = get_option( $this->domain . 'options' );
546 }
547 // upgrade to 0.40
548 if ( ! isset( $saved_options[ 'class_name' ] ) ) {
549 // set default
550 $saved_options[ 'class_name' ] = $this->options[ 'class_name' ];
551 $saved_options[ 'filter_posts' ] = $this->options[ 'filter_posts' ];
552 }
553
554 // set all options
555 if ( ! empty( $saved_options ) ) {
556 foreach ( $this->options AS $key => $option ) {
557 $this->options[ $key ] = ( empty( $saved_options[ $key ] ) ) ? '' : $saved_options[ $key ];
558 }
559 }
560
561 $this->set_method( $this->options['method'] );
562 }
563
564 /**
565 * Callback for encoding email
566 * @param array $match
567 * @return string
568 */
569 function _callback( $match ) {
570 if ( count( $match ) == 2 )
571 return $this->encode( $match[1] );
572
573 return $this->encode( $match[1], $match[2] );
574 }
575
576 /**
577 * Callback shortcode [encode_email ... ] for encoding email
578 * @param array $match
579 * @return string
580 */
581 function _callback_shortcode( $match ) {
582 $attrs = shortcode_parse_atts( $match[1] );
583
584 if ( ! key_exists( 'email', $attrs ) )
585 return '';
586
587 $email = $attrs[ 'email' ];
588 $display = ( key_exists( 'display', $attrs ) ) ? $attrs[ 'display' ] : $attrs[ 'email' ];
589 $method = ( key_exists( 'method', $attrs ) ) ? $attrs[ 'method' ] : NULL;
590
591 return $this->encode( $email, $display, $method );
592 }
593
594 /**
595 * Callback used for wp filters
596 */
597 function _filter_callback( $content ) {
598 return $this->filter( $content, TRUE, $this->options[ 'encode_mailtos' ], $this->options[ 'encode_emails' ] );
599 }
600
601 /**
602 * Callback RSS
603 */
604 function _filter_rss_callback( $content ) {
605 return preg_replace( $this->regexp_patterns, '*protected email*', $content );
606 }
607
608
609 /**
610 * Lim_Email_Encoder Class integrated
611 */
612
613 /**
614 * Set the encode method to use
615 * @param string $method can be the name of the method or 'random'
616 * @return $this
617 */
618 function set_method( $method ) {
619 $this->method = $this->_get_method( $method );
620
621 return $this;
622 }
623
624 /**
625 * Encode the given email into an encoded HTML link
626 * @param string $email
627 * @param string $display Optional, if not set display will be the email
628 * @param string $method Optional, else the default setted method will; be used
629 * @return string
630 */
631 function encode( $email, $display = NULL, $method = NULL ) {
632 // decode entities
633 $email = html_entity_decode( $email );
634
635 // set email as display
636 if ( $display === NULL )
637 $display = $email;
638
639 // set encode method
640 if ( $method === NULL ) {
641 $method = $this->method;
642 } else {
643 $method = $this->_get_method( $method );
644 }
645
646 // get encoded email code
647 return call_user_func( $method, $email, $display, $this );
648 }
649
650 /**
651 * Convert randomly chars to htmlentities
652 * This method is partly taken from WordPress
653 * @link http://codex.wordpress.org/Function_Reference/antispambot
654 * @static
655 * @param string $value
656 * @return string
657 */
658 function get_htmlent( $value ) {
659 // check if antispambot WordPress function exists
660 if ( function_exists( 'antispambot' ) ) {
661 $enc_value = antispambot( $value );
662 } else {
663 $enc_value = '';
664 srand( (float) microtime() * 1000000 );
665
666 for ( $i = 0; $i < strlen( $value ); $i = $i + 1 ) {
667 $j = floor( rand( 0, 1 ) );
668
669 if ( $j == 0 ) {
670 $enc_value .= '&#' . ord( substr( $value, $i, 1 ) ).';';
671 } elseif ( $j == 1 ) {
672 $enc_value .= substr( $value, $i, 1 );
673 }
674 }
675 }
676
677 $enc_value = str_replace( '@', '&#64;', $enc_value );
678
679 return $enc_value;
680 }
681
682 /**
683 * Load available methods
684 * @return void
685 */
686 function _load_methods() {
687 $method_dir = dirname(__FILE__) . '/methods';
688 $handle = opendir( $method_dir );
689
690 // dir not found
691 if ( ! $handle )
692 return;
693
694 // include all methods inside the method folder
695 while ( false !== ($file = readdir($handle)) ) {
696 if ( '.php' == substr( $file, -4 ) ) {
697 require_once $method_dir . '/' . $file;
698
699 $name = substr( $file, 0, -4 );
700 $fn = 'lim_email_' . $name;
701
702 if ( function_exists( $fn ) ) {
703 // set method with info
704 $this->methods[$fn] = ( isset( ${ $fn } ) )
705 ? ${ $fn }
706 : array( 'name' => $name, 'description' => $name );
707 }
708 }
709 }
710
711 closedir( $handle );
712 }
713
714 function _get_method( $method ) {
715 $method = strtolower( $method );
716
717 if ( 'random' == $method ) {
718 // set a random method
719 $method = array_rand( $this->methods );
720 } else {
721 // add 'lim_email_' prefix if not already set
722 $method = ( strpos( $method, 'lim_email_' ) !== FALSE ) ? $method : 'lim_email_' . $method;
723
724 if ( ! key_exists( $method, $this->methods ) )
725 $method = 'lim_email_html_encode'; // set default method
726 }
727
728 return $method;
729 }
730
731
732 } // end class WP_Email_Encoder_Bundle
733
734
735 /**
736 * Create instance
737 */
738 $WP_Email_Encoder_Bundle = new WP_Email_Encoder_Bundle;
739
740
741 /**
742 * Ajax Encoding request
743 */
744 if ( ! empty( $_GET['ajax'] ) ):
745 // input vars
746 $method = $_GET['method'];
747 $email = $_GET['email'];
748 $display = ( empty( $_GET['display'] ) ) ? $email : $_GET['display'];
749
750 echo $WP_Email_Encoder_Bundle->encode( $email, $display, $method );
751 exit;
752 endif;
753
754
755 /**
756 * Template function for encoding email
757 * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
758 * @param string $email
759 * @param string $display if non given will be same as email
760 * @param string $method Optional, else the default setted method will; be used
761 * @return string
762 */
763 if ( ! function_exists( 'encode_email' ) ):
764 function encode_email( $email, $display = NULL, $method = NULL ) {
765 global $WP_Email_Encoder_Bundle;
766 return $WP_Email_Encoder_Bundle->encode( $email, $display, $method );
767 }
768 endif;
769
770 /**
771 * Template function for encoding emails in the given content
772 * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
773 * @param string $content
774 * @param boolean $enc_tags Optional, default TRUE
775 * @param boolean $enc_mailtos Optional, default TRUE
776 * @param boolean $enc_plain_emails Optional, default TRUE
777 * @return string
778 */
779 if ( ! function_exists( 'encode_email_filter' ) ):
780 function encode_email_filter( $content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE ) {
781 global $WP_Email_Encoder_Bundle;
782 return $WP_Email_Encoder_Bundle->filter( $content, $enc_tags, $enc_mailtos, $enc_plain_emails );
783 }
784 endif;
785
786 /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */