Email Encoder Bundle – Protect Email Address - Version 0.50

Version Description

  • Added encode method for all kind of contents (template function and shortcode "encode_content")
  • Added extra param for additional html attributes (f.e. target="_blank")
  • Added option to skip certain posts from being automatically encoded
  • Added option custom protection text
  • Removed "method" folder. Not possible to add own methods anymore.
  • Other small changes and some refactoring
Download this release

Release Info

Developer freelancephp
Plugin Icon 128x128 Email Encoder Bundle – Protect Email Address
Version 0.50
Comparing to
See all releases

Code changes from version 0.42 to 0.50

email-encoder-bundle.php CHANGED
@@ -4,7 +4,7 @@ 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.42
8
  Author URI: http://www.freelancephp.net
9
  License: Dual licensed under the MIT and GPL licenses
10
  */
@@ -20,7 +20,7 @@ class WP_Email_Encoder_Bundle {
20
  * Current version
21
  * @var string
22
  */
23
- var $version = '0.42';
24
 
25
  /**
26
  * Used as prefix for options entry and could be used as text domain (for translations)
@@ -40,36 +40,60 @@ class WP_Email_Encoder_Bundle {
40
  var $options = array(
41
  'method' => 'lim_email_ascii',
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
  'widget_logic_filter' => 0,
50
  'powered_by' => 1,
51
  );
52
 
53
  /**
54
- * Regexp
55
  * @var array
56
  */
57
- var $regexp_patterns = array(
58
- 'mailto' => '/<a[^<>]*?href=["\']mailto:(.*?)["\'].*?>(.*?)<\/a[\s+]*>/is',
59
- 'tag' => '/\[encode_email\s+(.*?)\]/is',
60
- 'email' => '/([A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6})/is',
61
- );
62
 
63
  /**
64
- * @var array
65
  */
66
- var $methods = array();
67
 
68
  /**
69
  * @var string
70
  */
71
- var $method = NULL;
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
 
74
  /**
75
  * PHP4 constructor
@@ -82,269 +106,302 @@ class WP_Email_Encoder_Bundle {
82
  * PHP5 constructor
83
  */
84
  function __construct() {
85
- // include all available method files
86
- $this->_load_methods();
87
-
88
- // set method
89
- $this->set_method( $this->options[ 'method' ] );
90
 
91
  // set option values
92
- $this->_set_options();
93
-
94
- // load text domain for translations
95
- load_plugin_textdomain( $this->domain, FALSE, dirname( plugin_basename( __FILE__ ) ) . '/lang/' );
 
 
 
96
 
97
  // set uninstall hook
98
- if ( function_exists( 'register_deactivation_hook' ) )
99
- register_deactivation_hook( __FILE__, array( $this, 'deactivation' ));
 
100
 
101
  // add actions
102
- add_action( 'admin_menu', array( $this, 'admin_menu' ) );
103
- add_action( 'admin_init', array( $this, 'admin_init' ) );
104
- add_action( 'the_posts', array( $this, 'the_posts' ) );
105
-
106
- // set filters
107
- add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ), 10 );
108
  }
109
 
110
  /**
111
- * pre_get_posts filter
112
- * @param object $query
113
  */
114
- function pre_get_posts( $query ) {
115
- if ( is_admin() )
116
- return $query;
117
 
118
  $priority = 100;
119
 
120
- if ( $query->is_feed ) {
 
 
 
 
 
121
  // rss feed
122
- if ( $this->options[ 'filter_rss' ] ) {
123
- add_filter( 'the_title', array( $this, '_filter_rss_callback' ), $priority );
124
- add_filter( 'the_content', array( $this, '_filter_rss_callback' ), $priority );
125
- add_filter( 'the_excerpt', array( $this, '_filter_rss_callback' ), $priority );
126
- add_filter( 'the_title_rss', array( $this, '_filter_rss_callback' ), $priority );
127
- add_filter( 'the_content_rss', array( $this, '_filter_rss_callback' ), $priority );
128
- add_filter( 'the_excerpt_rss', array( $this, '_filter_rss_callback' ), $priority );
129
- add_filter( 'comment_text_rss', array( $this, '_filter_rss_callback' ), $priority );
130
- add_filter( 'comment_author_rss ', array( $this, '_filter_rss_callback' ), $priority );
131
- add_filter( 'the_category_rss ', array( $this, '_filter_rss_callback' ), $priority );
132
- add_filter( 'the_content_feed', array( $this, '_filter_rss_callback' ), $priority );
133
- add_filter( 'author feed link', array( $this, '_filter_rss_callback' ), $priority );
134
- add_filter( 'feed_link', array( $this, '_filter_rss_callback' ), $priority );
135
  }
136
  } else {
 
 
 
 
 
137
  // post content
138
- if ( $this->options[ 'filter_posts' ] ) {
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
  // comments
146
- if ( $this->options[ 'filter_comments' ] ) {
147
- add_filter( 'comment_text', array( $this, '_filter_callback' ), $priority );
148
- add_filter( 'comment_excerpt', array( $this, '_filter_callback' ), $priority );
149
- add_filter( 'comment_url', array( $this, '_filter_callback' ), $priority );
150
- add_filter( 'get_comment_author_url', array( $this, '_filter_callback' ), $priority );
151
- add_filter( 'get_comment_author_link', array( $this, '_filter_callback' ), $priority );
152
- add_filter( 'get_comment_author_url_link', array( $this, '_filter_callback' ), $priority );
153
  }
154
 
155
- // widgets ( only text widgets )
156
- if ( $this->options[ 'filter_widgets' ] ) {
157
- add_filter( 'widget_title', array( $this, '_filter_callback' ), $priority );
158
- add_filter( 'widget_text', array( $this, '_filter_callback' ), $priority );
 
 
 
159
 
160
  // Only if Widget Logic plugin is installed and 'widget_content' option is activated
161
- add_filter( 'widget_content', array( $this, '_filter_callback' ), $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
  // actions
209
- add_action( 'admin_enqueue_scripts', array( $this, 'admin_print_scripts' ) );
210
  }
211
 
212
- function admin_print_scripts( $hook_suffix ) {
213
- if( $hook_suffix == 'settings_page_email-encoder-bundle/email-encoder-bundle' ) {
 
 
 
 
214
  // set dashboard postbox
215
- wp_admin_css( 'dashboard' );
216
- wp_enqueue_script( 'dashboard' );
 
 
 
217
 
218
  // add style and script for ajax encoder
219
- wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ), $this->version );
 
220
  }
221
  }
222
 
 
 
 
 
 
 
 
 
223
  /**
224
  * Admin options page
225
  */
226
  function options_page() {
227
  ?>
228
- <script type="text/javascript">
229
- jQuery(function( $ ){
230
- // remove message
231
- $( '.settings-error' )
232
- .hide()
233
- .slideDown( 600 )
234
- .delay( 3000 )
235
- .slideUp( 600 );
236
-
237
- // set info text for selected encoding method
238
- $( '.method-info-select' ).bind( 'change blur keyup', function(){
239
- var method = $( this ).val(),
240
- $desc = $( this ).parent().find( 'span.description' );
241
-
242
- if ( methodInfo && methodInfo[ method ] ) {
243
- $desc.html( methodInfo[ method ][ 'description' ] || '' );
244
- } else {
245
- $desc.html( '' );
246
- }
247
- })
248
- .blur();
249
-
250
- // "has effect on"
251
- $( 'input#encode_emails' )
252
- .change(function(){
253
- if ( $( this ).attr( 'checked' ) )
254
- $( 'input#encode_mailtos' ).attr( 'checked', true );
255
- })
256
- .change();
257
-
258
- $( 'input#encode_mailtos' )
259
- .change(function(){
260
- if ( ! $( this ).attr( 'checked' ) )
261
- $( 'input#encode_emails' ).attr( 'checked', false );
262
- });
263
-
264
- // add form-table class to Encoder Form tables
265
- $( '.email-encoder-form table' ).addClass( 'form-table' );
266
-
267
- // slide postbox
268
- $( '.postbox' ).find( '.handlediv, .hndle' ).click(function(){
269
- var $inside = $( this ).parent().find( '.inside' );
270
-
271
- if ( $inside.css( 'display' ) == 'block' ) {
272
- $inside.css({ display:'block' }).slideUp();
273
- } else {
274
- $inside.css({ display:'none' }).slideDown();
275
- }
276
- });
277
- });
278
- </script>
279
  <div class="wrap">
280
- <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>
281
  <h2>Email Encoder Bundle</h2>
282
 
283
  <script type="text/javascript">
284
- var methodInfo = <?php echo json_encode( $this->methods ) ?>;
285
  </script>
286
- <div class="postbox-container metabox-holder meta-box-sortables" style="width: 69%">
287
- <div style="margin:0 5px;">
288
  <div class="postbox">
289
- <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
290
- <h3 class="hndle"><?php _e( 'General Settings' ) ?></h3>
291
  <div class="inside">
292
  <form method="post" action="options.php">
293
  <?php
294
- settings_fields( $this->domain );
295
- $this->_set_options();
296
  $options = $this->options;
297
  ?>
298
- <?php if ( is_plugin_active( 'wp-mailto-links/wp-mailto-links.php' ) ): ?>
299
- <p class="description"><?php _e( 'Warning: "WP Mailto Links"-plugin is also activated, which could cause conflicts.', $this->domain ) ?></p>
300
  <?php endif; ?>
301
  <fieldset class="options">
302
  <table class="form-table">
303
  <tr>
304
- <th><?php _e( 'Choose encoding method', $this->domain ) ?></th>
305
  <td><label><select id="<?php echo $this->options_name ?>[method]" name="<?php echo $this->options_name ?>[method]" class="method-info-select postform">
306
- <?php foreach ( $this->methods AS $method => $info ): ?>
307
- <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>
308
  <?php endforeach; ?>
309
- <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php echo __( 'Random', $this->domain ) ?></option>
310
  </select>
311
- <br /><span class="description"></span></label>
312
  </td>
313
  </tr>
314
  <tr>
315
- <th><?php _e( 'Encode emails', $this->domain ) ?></th>
316
  <td>
317
- <label><input type="checkbox" name="<?php echo $this->options_name ?>[encode_tags]" value="1" checked="checked" disabled="disabled" />
318
- <span><?php _e( 'Encode <code>[encode_email]</code> shortcode', $this->domain ) ?></span>
319
- </label>
320
- <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']); ?> />
321
- <span><?php _e( 'Automatically encode mailto-links', $this->domain ) ?></span>
322
  </label>
323
  <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']); ?> />
324
- <span><?php _e( 'Automatically replace plain emailaddresses to encoded mailto-links', $this->domain ) ?></span>
 
 
 
 
 
 
325
  </label>
326
  </td>
327
  </tr>
328
  <tr>
329
- <th><?php _e( 'Set class for mailto-links', $this->domain ) ?></th>
330
  <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']; ?>" />
331
- <span><?php _e( 'Set class-attribute for encoded mailto links (optional)', $this->domain ) ?></span></label></td>
332
  </tr>
333
  <tr>
334
- <th><?php _e( 'Options has effect on', $this->domain ) ?></th>
335
  <td><label><input type="checkbox" name="<?php echo $this->options_name ?>[filter_posts]" value="1" <?php checked('1', (int) $options['filter_posts']); ?> />
336
- <span><?php _e( 'All posts', $this->domain ) ?></span>
337
  </label>
338
  <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']); ?> />
339
- <span><?php _e( 'All comments', $this->domain ) ?></span></label>
340
  <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']); ?> />
341
- <span><?php if ( $this->options[ 'widget_logic_filter' ] ) { _e( 'All widgets (uses the <code>widget_content</code> filter of the Widget Logic plugin)', $this->domain ); } else { _e( 'All text widgets', $this->domain ); } ?></span></label>
342
  </td>
343
  </tr>
344
  <tr>
345
- <th><?php _e( 'Protect RSS feed', $this->domain ) ?></th>
346
- <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']); ?> />
347
- <span><?php _e( 'Replace emails in RSS feed by <code>*protected email*</code>', $this->domain ) ?></span></label>
 
348
  </td>
349
  </tr>
350
  </table>
@@ -353,38 +410,21 @@ jQuery(function( $ ){
353
  <fieldset class="options">
354
  <table class="form-table">
355
  <tr>
356
- <th><?php _e( '"Email Encoder Form" settings', $this->domain ) ?></th>
357
- <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>
358
  </tr>
359
  </table>
360
  </fieldset>
361
  <p class="submit">
362
- <input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" />
363
  </p>
364
  </form>
365
  </div>
366
  </div>
367
 
368
- <div class="postbox closed">
369
- <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
370
- <h3 class="hndle"><?php _e( 'How to use', $this->domain ) ?></h3>
371
- <div class="inside">
372
- <h4><?php _e( 'Tags', $this->domain ) ?></h4>
373
- <ul>
374
- <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>
375
- <li><code>[email_encoder_form]</code> <span class="description"><?php _e( 'Puts an email encoder form in your post', $this->domain ) ?></span></li>
376
- </ul>
377
- <h4><?php _e( 'Template functions' ) ?></h4>
378
- <ul>
379
- <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>
380
- <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>
381
- </ul>
382
- </div>
383
- </div>
384
-
385
  <div class="postbox">
386
- <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
387
- <h3 class="hndle"><?php _e( 'Email Encoder Form', $this->domain ) ?></h3>
388
  <div class="inside">
389
  <?php echo $this->get_encoder_form(); ?>
390
  </div>
@@ -392,48 +432,49 @@ jQuery(function( $ ){
392
  </div>
393
  </div>
394
 
395
- <div class="postbox-container side metabox-holder meta-box-sortables" style="width:29%;">
396
- <div style="margin:0 5px;">
397
  <div class="postbox">
398
- <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
399
- <h3 class="hndle"><?php _e( 'About' ) ?>...</h3>
400
  <div class="inside">
401
- <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>
402
- <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>
403
  <ul>
404
- <li><a href="http://www.freelancephp.net/contact/" target="_blank"><?php _e( 'Questions or suggestions?', $this->domain ) ?></a></li>
405
- <li><?php _e( 'If you like this plugin please send your rating at WordPress.org.' ) ?></li>
 
406
  <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>
407
  </ul>
408
  </div>
409
  </div>
410
 
411
  <div class="postbox">
412
- <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
413
- <h3 class="hndle"><?php _e( 'Other Plugins', $this->domain ) ?></h3>
414
  <div class="inside">
415
- <h4><img src="<?php echo plugins_url( 'images/icon-wp-external-links.png', __FILE__ ) ?>" width="16" height="16" /> WP External Links</h4>
416
- <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>
417
  <ul>
418
- <?php if ( is_plugin_active( 'wp-external-links/wp-external-links.php' ) ): ?>
419
- <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>
420
- <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-external-links/wp-external-links.php' ) ): ?>
421
- <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e( 'Activate this plugin.', $this->domain ) ?></a></li>
422
  <?php else: ?>
423
- <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>
424
  <?php endif; ?>
425
  <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>
426
  </ul>
427
 
428
- <h4><img src="<?php echo plugins_url( 'images/icon-wp-mailto-links.png', __FILE__ ) ?>" width="16" height="16" /> WP Mailto Links</h4>
429
- <p><?php _e( 'Manage mailto links on your site and protect emails from spambots, set mail icon and more.', $this->domain ) ?></p>
430
  <ul>
431
- <?php if ( is_plugin_active( 'wp-mailto-links/wp-mailto-links.php' ) ): ?>
432
- <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>
433
- <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-mailto-links/wp-mailto-links.php' ) ): ?>
434
- <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e( 'Activate this plugin.', $this->domain ) ?></a></li>
435
  <?php else: ?>
436
- <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>
437
  <?php endif; ?>
438
  <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>
439
  </ul>
@@ -460,26 +501,26 @@ jQuery(function( $ ){
460
  <table>
461
  <tr>
462
  <tr>
463
- <th><label for="email"><?php _e( 'Email address', $this->domain ) ?></label></th>
464
  <td><input type="text" class="regular-text" id="email" name="email" /></td>
465
  </tr>
466
  <tr>
467
- <th><label for="display"><?php _e( 'Display', $this->domain ) ?></label></th>
468
  <td><input type="text" class="regular-text" id="display" name="display" /></td>
469
  </tr>
470
  <tr>
471
- <th><?php _e( 'Example', $this->domain ) ?></th>
472
  <td><span id="example"></span></td>
473
  </tr>
474
  <tr>
475
- <th><label for="encode_method"><?php _e( 'Encode method', $this->domain ) ?></label></th>
476
  <td><select id="encode_method" name="encode_method" class="postform">
477
- <?php foreach ( $this->methods AS $method => $info ): ?>
478
- <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ] ?></option>
479
  <?php endforeach; ?>
480
- <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php _e( 'Random', $this->domain ) ?></option>
481
  </select>
482
- <input type="button" id="ajax_encode" value="<?php _e( 'Encode', $this->domain ) ?> &gt;&gt;" />
483
  </td>
484
  </tr>
485
  </tr>
@@ -489,14 +530,14 @@ jQuery(function( $ ){
489
  <table>
490
  <tr>
491
  <tr>
492
- <th><label for="encoded_output"><?php _e( 'Code', $this->domain ) ?></label></th>
493
  <td><textarea class="large-text node" id="encoded_output" name="encoded_output"></textarea></td>
494
  </tr>
495
  </tr>
496
  </table>
497
  </div>
498
- <?php if ( $this->options['powered_by'] ): ?>
499
- <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>
500
  <?php endif; ?>
501
  </fieldset>
502
  </form>
@@ -508,131 +549,127 @@ jQuery(function( $ ){
508
  return $form;
509
  }
510
 
511
- /**
512
- * Encode all emails of the given content
513
- * @param string $content
514
- * @param boolean $enc_tags Optional, default TRUE
515
- * @param boolean $enc_mailtos Optional, default TRUE
516
- * @param boolean $enc_plain_emails Optional, default TRUE
517
- * @return string
518
- */
519
- function filter( $content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE ) {
520
- // encode mailto links
521
- if ( $enc_mailtos )
522
- $content = preg_replace_callback( $this->regexp_patterns[ 'mailto' ], array( $this, '_callback' ), $content );
523
-
524
- // replace content tags [encode_email] to mailto links
525
- if ( $enc_tags )
526
- $content = preg_replace_callback( $this->regexp_patterns[ 'tag' ], array( $this, '_callback_shortcode' ), $content );
527
-
528
- // replace plain emails
529
- if ( $enc_plain_emails )
530
- $content = preg_replace_callback( $this->regexp_patterns[ 'email' ], array( $this, '_callback' ), $content );
531
-
532
- return $content;
533
- }
534
-
535
- /**
536
- * Deactivation plugin method
537
- */
538
- function deactivation() {
539
- delete_option( $this->options_name );
540
- unregister_setting( $this->domain, $this->options_name );
541
- }
542
-
543
  /**
544
  * Set options from save values or defaults
545
  */
546
- function _set_options() {
547
  // set options
548
- $saved_options = get_option( $this->options_name );
549
 
550
  // backwards compatible (old values)
551
- if ( empty( $saved_options ) ) {
552
- $saved_options = get_option( $this->domain . 'options' );
553
  }
 
 
 
 
 
 
 
554
  // upgrade to 0.40
555
- if ( ! isset( $saved_options[ 'class_name' ] ) ) {
 
 
 
 
 
 
 
556
  // set default
557
- $saved_options[ 'class_name' ] = $this->options[ 'class_name' ];
558
- $saved_options[ 'filter_posts' ] = $this->options[ 'filter_posts' ];
559
  }
560
 
561
  // set all options
562
- if ( ! empty( $saved_options ) ) {
563
- foreach ( $this->options AS $key => $option ) {
564
- $this->options[ $key ] = ( empty( $saved_options[ $key ] ) ) ? '' : $saved_options[ $key ];
565
  }
566
  }
567
 
568
  // set encode method
569
- $this->set_method( $this->options['method'] );
570
 
571
  // set widget_content filter of Widget Logic plugin
572
- $widget_logic_opts = get_option( 'widget_logic' );
573
- if ( is_array( $widget_logic_opts ) AND key_exists( 'widget_logic-options-filter', $widget_logic_opts ) ) {
574
- $this->options[ 'widget_logic_filter' ] = ( $widget_logic_opts[ 'widget_logic-options-filter' ] == 'checked' ) ? 1 : 0;
575
  }
576
  }
577
 
578
  /**
579
- * Callback for encoding email
580
- * @param array $match
 
 
 
581
  * @return string
582
  */
583
- function _callback( $match ) {
584
- if ( count( $match ) == 2 )
585
- return $this->encode( $match[1] );
 
 
 
 
 
 
 
586
 
587
- return $this->encode( $match[1], $match[2] );
588
  }
589
 
590
  /**
591
- * Callback shortcode [encode_email ... ] for encoding email
592
  * @param array $match
593
  * @return string
594
  */
595
- function _callback_shortcode( $match ) {
596
- $attrs = shortcode_parse_atts( $match[1] );
597
-
598
- if ( ! key_exists( 'email', $attrs ) )
599
- return '';
600
-
601
- $email = $attrs[ 'email' ];
602
- $display = ( key_exists( 'display', $attrs ) ) ? $attrs[ 'display' ] : $attrs[ 'email' ];
603
- $method = ( key_exists( 'method', $attrs ) ) ? $attrs[ 'method' ] : NULL;
604
 
605
- return $this->encode( $email, $display, $method );
606
  }
607
 
608
  /**
609
- * Callback used for wp filters
 
 
 
610
  */
611
- function _filter_callback( $content ) {
612
- return $this->filter( $content, TRUE, $this->options[ 'encode_mailtos' ], $this->options[ 'encode_emails' ] );
613
- }
614
 
615
- /**
616
- * Callback RSS
617
- */
618
- function _filter_rss_callback( $content ) {
619
- return preg_replace( $this->regexp_patterns, '*protected email*', $content );
620
- }
 
 
621
 
 
 
622
 
623
  /**
624
- * Lim_Email_Encoder Class integrated
 
 
 
625
  */
 
 
 
626
 
627
- /**
628
- * Set the encode method to use
629
- * @param string $method can be the name of the method or 'random'
630
- * @return $this
631
- */
632
- function set_method( $method ) {
633
- $this->method = $this->_get_method( $method );
634
 
635
- return $this;
 
636
  }
637
 
638
  /**
@@ -640,112 +677,145 @@ jQuery(function( $ ){
640
  * @param string $email
641
  * @param string $display Optional, if not set display will be the email
642
  * @param string $method Optional, else the default setted method will; be used
 
643
  * @return string
644
  */
645
- function encode( $email, $display = NULL, $method = NULL ) {
646
  // decode entities
647
- $email = html_entity_decode( $email );
648
 
649
  // set email as display
650
- if ( $display === NULL )
651
  $display = $email;
 
652
 
653
- // set encode method
654
- if ( $method === NULL ) {
655
- $method = $this->method;
656
- } else {
657
- $method = $this->_get_method( $method );
 
658
  }
659
 
 
 
 
 
 
660
  // get encoded email code
661
- return call_user_func( $method, $email, $display, $this );
662
  }
663
 
664
  /**
665
- * Convert randomly chars to htmlentities
666
- * This method is partly taken from WordPress
667
- * @link http://codex.wordpress.org/Function_Reference/antispambot
668
- * @static
669
  * @param string $value
670
  * @return string
671
  */
672
- function get_htmlent( $value ) {
673
- // check if antispambot WordPress function exists
674
- if ( function_exists( 'antispambot' ) ) {
675
- $enc_value = antispambot( $value );
676
- } else {
677
- $enc_value = '';
678
- srand( (float) microtime() * 1000000 );
679
 
680
- for ( $i = 0; $i < strlen( $value ); $i = $i + 1 ) {
681
- $j = floor( rand( 0, 1 ) );
682
 
683
- if ( $j == 0 ) {
684
- $enc_value .= '&#' . ord( substr( $value, $i, 1 ) ).';';
685
- } elseif ( $j == 1 ) {
686
- $enc_value .= substr( $value, $i, 1 );
687
- }
 
 
688
  }
689
  }
690
 
691
- $enc_value = str_replace( '@', '&#64;', $enc_value );
 
692
 
693
- return $enc_value;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
694
  }
695
 
696
  /**
697
- * Load available methods
698
- * @return void
 
 
 
699
  */
700
- function _load_methods() {
701
- $method_dir = dirname(__FILE__) . '/methods';
702
- $handle = opendir( $method_dir );
703
-
704
- // dir not found
705
- if ( ! $handle )
706
- return;
707
-
708
- // include all methods inside the method folder
709
- while ( false !== ($file = readdir($handle)) ) {
710
- if ( '.php' == substr( $file, -4 ) ) {
711
- require_once $method_dir . '/' . $file;
712
 
713
- $name = substr( $file, 0, -4 );
714
- $fn = 'lim_email_' . $name;
 
715
 
716
- if ( function_exists( $fn ) ) {
717
- // set method with info
718
- $this->methods[$fn] = ( isset( ${ $fn } ) )
719
- ? ${ $fn }
720
- : array( 'name' => $name, 'description' => $name );
721
- }
722
  }
723
  }
724
 
725
- closedir( $handle );
726
- }
 
727
 
728
- function _get_method( $method ) {
729
- $method = strtolower( $method );
730
 
731
- if ( 'random' == $method ) {
732
- // set a random method
733
- $method = array_rand( $this->methods );
 
 
 
 
 
 
 
 
 
734
  } else {
735
- // add 'lim_email_' prefix if not already set
736
- $method = ( strpos( $method, 'lim_email_' ) !== FALSE ) ? $method : 'lim_email_' . $method;
737
 
738
- if ( ! key_exists( $method, $this->methods ) )
739
- $method = 'lim_email_html_encode'; // set default method
 
 
 
 
 
 
 
740
  }
741
 
742
- return $method;
743
- }
744
 
 
 
745
 
746
  } // end class WP_Email_Encoder_Bundle
747
 
748
 
 
749
  /**
750
  * Create instance
751
  */
@@ -755,29 +825,43 @@ $WP_Email_Encoder_Bundle = new WP_Email_Encoder_Bundle;
755
  /**
756
  * Ajax Encoding request
757
  */
758
- if ( ! empty( $_GET['ajax'] ) ):
759
  // input vars
760
  $method = $_GET['method'];
761
  $email = $_GET['email'];
762
- $display = ( empty( $_GET['display'] ) ) ? $email : $_GET['display'];
763
 
764
- echo $WP_Email_Encoder_Bundle->encode( $email, $display, $method );
765
  exit;
766
  endif;
767
 
768
-
769
  /**
770
  * Template function for encoding email
771
  * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
772
  * @param string $email
773
  * @param string $display if non given will be same as email
774
  * @param string $method Optional, else the default setted method will; be used
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
775
  * @return string
776
  */
777
- if ( ! function_exists( 'encode_email' ) ):
778
- function encode_email( $email, $display = NULL, $method = NULL ) {
779
  global $WP_Email_Encoder_Bundle;
780
- return $WP_Email_Encoder_Bundle->encode( $email, $display, $method );
781
  }
782
  endif;
783
 
@@ -790,10 +874,10 @@ endif;
790
  * @param boolean $enc_plain_emails Optional, default TRUE
791
  * @return string
792
  */
793
- if ( ! function_exists( 'encode_email_filter' ) ):
794
- function encode_email_filter( $content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE ) {
795
  global $WP_Email_Encoder_Bundle;
796
- return $WP_Email_Encoder_Bundle->filter( $content, $enc_tags, $enc_mailtos, $enc_plain_emails );
797
  }
798
  endif;
799
 
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.50
8
  Author URI: http://www.freelancephp.net
9
  License: Dual licensed under the MIT and GPL licenses
10
  */
20
  * Current version
21
  * @var string
22
  */
23
+ var $version = '0.50';
24
 
25
  /**
26
  * Used as prefix for options entry and could be used as text domain (for translations)
40
  var $options = array(
41
  'method' => 'lim_email_ascii',
42
  'encode_mailtos' => 1,
43
+ 'encode_emails' => 0,
44
+ 'skip_posts' => '',
45
  'class_name' => 'mailto-link',
46
  'filter_posts' => 1,
47
  'filter_widgets' => 1,
48
  'filter_comments' => 1,
49
  'filter_rss' => 1,
50
+ 'protection_text' => '*protected email*',
51
  'widget_logic_filter' => 0,
52
  'powered_by' => 1,
53
  );
54
 
55
  /**
 
56
  * @var array
57
  */
58
+ var $skip_posts = array();
 
 
 
 
59
 
60
  /**
61
+ * @var boolead
62
  */
63
+ var $logged_in = FALSE;
64
 
65
  /**
66
  * @var string
67
  */
68
+ var $method = 'enc_ascii';
69
 
70
+ /**
71
+ * @var array
72
+ */
73
+ var $methods = array(
74
+ 'enc_ascii' => array(
75
+ 'name' => 'JavaScript ASCII',
76
+ 'description' => 'Uses javascript (<a href="http://rumkin.com/tools/mailto_encoder/" target="_blank">original source</a>).',
77
+ ),
78
+ 'enc_escape' => array(
79
+ 'name' => 'JavaScript Escape',
80
+ 'description' => 'Uses javascript eval() function (<a href="http://blueberryware.net/2008/09/14/email-spam-protection/" target="_blank">original source</a>).',
81
+ ),
82
+ 'enc_html' => array(
83
+ 'name' => 'Html Encode',
84
+ 'description' => 'Email encode method using antispambot() built-in WordPress (<a href="http://codex.wordpress.org/Function_Reference/antispambot" target="_blank">more info</a>).',
85
+ ),
86
+ );
87
+
88
+ /**
89
+ * Regexp
90
+ * @var array
91
+ */
92
+ var $regexp_patterns = array(
93
+ 'mailto' => '/<a[^<>]*?href=["\']mailto:(.*?)["\'].*?>(.*?)<\/a[\s+]*>/is',
94
+ 'tag' => '/\[encode_email\s+(.*?)\]/is',
95
+ 'email' => '/([A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6})/is',
96
+ );
97
 
98
  /**
99
  * PHP4 constructor
106
  * PHP5 constructor
107
  */
108
  function __construct() {
109
+ // load text domain for translations
110
+ load_plugin_textdomain($this->domain, FALSE, dirname(plugin_basename(__FILE__)) . '/lang/');
 
 
 
111
 
112
  // set option values
113
+ $this->set_options();
114
+
115
+ // prepare vars
116
+ $skip_posts = $this->options['skip_posts'];
117
+ $skip_posts = str_replace(' ', '', $skip_posts);
118
+ $skip_posts = explode(',', $skip_posts);
119
+ $this->skip_posts = $skip_posts;
120
 
121
  // set uninstall hook
122
+ if (function_exists('register_deactivation_hook')) {
123
+ register_deactivation_hook(__FILE__, array($this, 'deactivation'));
124
+ }
125
 
126
  // add actions
127
+ add_action('wp', array($this, 'wp'));
128
+ add_action('admin_init', array($this, 'admin_init'));
129
+ add_action('admin_menu', array($this, 'admin_menu'));
 
 
 
130
  }
131
 
132
  /**
133
+ * wp action
134
+ * @global type $user_ID
135
  */
136
+ function wp() {
137
+ global $user_ID;
138
+ $this->logged_in = (bool) ($user_ID && current_user_can('level_10'));
139
 
140
  $priority = 100;
141
 
142
+ // shortcodes
143
+ add_shortcode('email_encoder_form', array($this, 'shortcode_email_encoder_form'));
144
+ add_shortcode('encode_email', array($this, 'shortcode_encode_email'));
145
+ add_shortcode('encode_content', array($this, 'shortcode_encode_content'));
146
+
147
+ if (is_feed()) {
148
  // rss feed
149
+ if ($this->options['filter_rss']) {
150
+ add_filter('the_title', array($this, 'filter_rss_callback'), $priority);
151
+ add_filter('the_content', array($this, 'filter_rss_callback'), $priority);
152
+ add_filter('the_excerpt', array($this, 'filter_rss_callback'), $priority);
153
+ add_filter('the_title_rss', array($this, 'filter_rss_callback'), $priority);
154
+ add_filter('the_content_rss', array($this, 'filter_rss_callback'), $priority);
155
+ add_filter('the_excerpt_rss', array($this, 'filter_rss_callback'), $priority);
156
+ add_filter('comment_text_rss', array($this, 'filter_rss_callback'), $priority);
157
+ add_filter('comment_author_rss ', array($this, 'filter_rss_callback'), $priority);
158
+ add_filter('the_category_rss ', array($this, 'filter_rss_callback'), $priority);
159
+ add_filter('the_content_feed', array($this, 'filter_rss_callback'), $priority);
160
+ add_filter('author feed link', array($this, 'filter_rss_callback'), $priority);
161
+ add_filter('feed_link', array($this, 'filter_rss_callback'), $priority);
162
  }
163
  } else {
164
+ // add style when logged in
165
+ if ($this->logged_in) {
166
+ add_action('wp_head', array($this, 'add_style'));
167
+ }
168
+
169
  // post content
170
+ if ($this->options['filter_posts']) {
171
+ add_filter('the_title', array($this, 'filter_callback'), $priority);
172
+ add_filter('the_content', array($this, 'filter_callback'), $priority);
173
+ add_filter('the_excerpt', array($this, 'filter_callback'), $priority);
174
+ add_filter('get_the_excerpt', array($this, 'filter_callback'), $priority);
175
  }
176
 
177
  // comments
178
+ if ($this->options['filter_comments']) {
179
+ add_filter('comment_text', array($this, 'filter_callback'), $priority);
180
+ add_filter('comment_excerpt', array($this, 'filter_callback'), $priority);
181
+ add_filter('comment_url', array($this, 'filter_callback'), $priority);
182
+ add_filter('get_comment_author_url', array($this, 'filter_callback'), $priority);
183
+ add_filter('get_comment_author_link', array($this, 'filter_callback'), $priority);
184
+ add_filter('get_comment_author_url_link', array($this, 'filter_callback'), $priority);
185
  }
186
 
187
+ // widgets
188
+ if ($this->options['filter_widgets']) {
189
+ // Only text widgets
190
+ add_filter('widget_title', array($this, 'filter_callback'), $priority);
191
+ add_filter('widget_text', array($this, 'filter_callback'), $priority);
192
+ // also replace shortcodes
193
+ add_filter('widget_text', 'do_shortcode', $priority);
194
 
195
  // Only if Widget Logic plugin is installed and 'widget_content' option is activated
196
+ add_filter('widget_content', array($this, 'filter_callback'), $priority);
197
+ // also replace shortcodes
198
+ add_filter('widget_content', 'do_shortcode', $priority);
199
  }
200
  }
201
 
 
202
  }
203
 
204
  /**
205
+ * Shortcode showing encoder form
206
+ * @return string
207
  */
208
+ function shortcode_email_encoder_form() {
209
+ // add style and script for ajax encoder
210
+ wp_enqueue_script('email_encoder', plugins_url('js/email-encoder-bundle.js', __FILE__), array('jquery'), $this->version);
211
 
212
+ return $this->get_encoder_form();
213
+ }
 
 
214
 
215
+ /**
216
+ * Shortcode encoding email
217
+ * @param array $attrs
218
+ * @return string
219
+ */
220
+ function shortcode_encode_email($attrs) {
221
+ if (!key_exists('email', $attrs)) {
222
+ return '';
223
+ }
224
+
225
+ $email = $attrs['email'];
226
+ $display = (key_exists('display', $attrs)) ? $attrs['display'] : $attrs['email'];
227
+ $method = (key_exists('method', $attrs)) ? $attrs['method'] : NULL;
228
+ $extra_attrs = (key_exists('extra_attrs', $attrs)) ? $attrs['extra_attrs'] : NULL;
229
+
230
+ return $this->encode_email($email, $display, $method, $extra_attrs);
231
+ }
232
+
233
+ /**
234
+ * Shortcode encoding content
235
+ * @param array $attrs
236
+ * @param string $content Optional
237
+ * @return string
238
+ */
239
+ function shortcode_encode_content($attrs, $content = '') {
240
+ $method = (key_exists('method', $attrs)) ? $attrs['method'] : NULL;
241
+
242
+ return $this->encode($content, $method);
243
+ }
244
+
245
+ /**
246
+ * Add style for encoded mails when logged in
247
+ */
248
+ function add_style() {
249
+ echo '<style type="text/css">' . "\n";
250
+ echo '.' . $this->domain . ' { background: #f00 !important; display: inline !important; }' . "\n";
251
+ echo '</style>' . "\n";
252
+ }
253
+
254
+ /**
255
+ * WP filter
256
+ * @param string $content
257
+ * @return string
258
+ */
259
+ function filter_callback($content) {
260
+ global $post;
261
+
262
+ if (isset($post) && in_array($post->ID, $this->skip_posts)) {
263
+ return $content;
264
  }
265
 
266
+ return $this->filter($content, TRUE, $this->options['encode_mailtos'], $this->options['encode_emails']);
267
+ }
268
+
269
+ /**
270
+ * RSS Filter
271
+ * @param string $content
272
+ * @return string
273
+ */
274
+ function filter_rss_callback($content) {
275
+ return preg_replace($this->regexp_patterns, $this->options['protection_text'], $content);
276
  }
277
 
278
  /**
279
+ * admin_menu action
280
  */
281
  function admin_menu() {
282
+ if (function_exists('add_options_page') AND current_user_can('manage_options')) {
283
  // add options page
284
+ $page = add_options_page('Email Encoder Bundle', 'Email Encoder Bundle',
285
+ 'manage_options', __FILE__, array($this, 'options_page'));
286
  }
287
  }
288
 
289
  /**
290
+ * admin_init action
291
  */
292
  function admin_init() {
293
  // register settings
294
+ register_setting($this->domain, $this->options_name);
295
 
296
  // actions
297
+ add_action('admin_enqueue_scripts', array($this, 'admin_enqueue_scripts'));
298
  }
299
 
300
+ /**
301
+ * admin_enqueue_scripts action
302
+ * @param string $hook_suffix
303
+ */
304
+ function admin_enqueue_scripts($hook_suffix) {
305
+ if($hook_suffix == 'settings_page_email-encoder-bundle/email-encoder-bundle') {
306
  // set dashboard postbox
307
+ wp_enqueue_script('dashboard');
308
+ // set dashboard style for wp < 3.2.0
309
+ if (isset($wp_version ) AND version_compare( preg_replace('/-.*$/', '', $wp_version ), '3.2.0', '<')) {
310
+ wp_admin_css('dashboard');
311
+ }
312
 
313
  // add style and script for ajax encoder
314
+ wp_enqueue_script('email_encoder', plugins_url('js/email-encoder-bundle.js', __FILE__ ), array('jquery'), $this->version);
315
+ wp_enqueue_script('email_encoder_admin', plugins_url('js/email-encoder-bundle-admin.js', __FILE__ ), array('jquery'), $this->version);
316
  }
317
  }
318
 
319
+ /**
320
+ * Deactivation plugin method
321
+ */
322
+ function deactivation() {
323
+ delete_option($this->options_name);
324
+ unregister_setting($this->domain, $this->options_name);
325
+ }
326
+
327
  /**
328
  * Admin options page
329
  */
330
  function options_page() {
331
  ?>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
332
  <div class="wrap">
333
+ <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>
334
  <h2>Email Encoder Bundle</h2>
335
 
336
  <script type="text/javascript">
337
+ var methodInfo = <?php echo json_encode($this->methods) ?>;
338
  </script>
339
+ <div class="postbox-container metabox-holder meta-box-sortables" style="width: 68%">
340
+ <div style="margin:0 2%;">
341
  <div class="postbox">
342
+ <div class="handlediv" title="<?php _e('Click to toggle') ?>"><br/></div>
343
+ <h3 class="hndle"><?php _e('General Settings') ?></h3>
344
  <div class="inside">
345
  <form method="post" action="options.php">
346
  <?php
347
+ settings_fields($this->domain);
348
+ $this->set_options();
349
  $options = $this->options;
350
  ?>
351
+ <?php if (is_plugin_active('wp-mailto-links/wp-mailto-links.php') ): ?>
352
+ <p class="description"><?php _e('Warning: "WP Mailto Links"-plugin is also activated, which could cause conflicts.', $this->domain ) ?></p>
353
  <?php endif; ?>
354
  <fieldset class="options">
355
  <table class="form-table">
356
  <tr>
357
+ <th><?php _e('Choose encoding method', $this->domain ) ?></th>
358
  <td><label><select id="<?php echo $this->options_name ?>[method]" name="<?php echo $this->options_name ?>[method]" class="method-info-select postform">
359
+ <?php foreach ($this->methods AS $method => $info ): ?>
360
+ <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>
361
  <?php endforeach; ?>
362
+ <option value="random" <?php if ($this->method == 'random') echo 'selected="selected"' ?>><?php echo __('Random', $this->domain ) ?></option>
363
  </select>
364
+ <span class="description"></span></label>
365
  </td>
366
  </tr>
367
  <tr>
368
+ <th><?php _e('Automatically encode emails', $this->domain ) ?></th>
369
  <td>
370
+ <label><input type="checkbox" id="encode_mailtos" name="<?php echo $this->options_name ?>[encode_mailtos]" value="1" <?php checked('1', (int) $options['encode_mailtos']); ?> />
371
+ <span><?php _e('Encode mailto-links', $this->domain ) ?></span>
 
 
 
372
  </label>
373
  <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']); ?> />
374
+ <span><?php _e('Replace plain emailaddresses to encoded mailto-links', $this->domain ) ?></span> <span class="description"><?php _e('(NOT recommended)', $this->domain ) ?></span>
375
+ </label>
376
+ <br/>
377
+ <label>
378
+ <span><?php _e('Skip posts with ID:', $this->domain ) ?></span>
379
+ <input type="text" id="<?php echo $this->options_name ?>[skip_posts]" name="<?php echo $this->options_name ?>[skip_posts]" value="<?php echo $options['skip_posts']; ?>" />
380
+ <span class="description"><?php _e('(comma seperated, f.e.: 2, 7, 13, 32)', $this->domain ) ?></span>
381
  </label>
382
  </td>
383
  </tr>
384
  <tr>
385
+ <th><?php _e('Set class for mailto-links', $this->domain ) ?></th>
386
  <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']; ?>" />
387
+ <span class="description"><?php _e('Set class-attribute for encoded mailto links <em>(optional)</em>', $this->domain ) ?></span></label></td>
388
  </tr>
389
  <tr>
390
+ <th><?php _e('Options has effect on', $this->domain ) ?></th>
391
  <td><label><input type="checkbox" name="<?php echo $this->options_name ?>[filter_posts]" value="1" <?php checked('1', (int) $options['filter_posts']); ?> />
392
+ <span><?php _e('All posts', $this->domain ) ?></span>
393
  </label>
394
  <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']); ?> />
395
+ <span><?php _e('All comments', $this->domain ) ?></span></label>
396
  <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']); ?> />
397
+ <span><?php if ($this->options['widget_logic_filter']) { _e('All widgets (uses the <code>widget_content</code> filter of the Widget Logic plugin)', $this->domain); } else { _e('All text widgets', $this->domain); } ?></span></label>
398
  </td>
399
  </tr>
400
  <tr>
401
+ <th><?php _e('Protect RSS feed', $this->domain ) ?></th>
402
+ <td><label><input type="checkbox" id="filter_rss" name="<?php echo $this->options_name ?>[filter_rss]" value="1" <?php checked('1', (int) $options['filter_rss']); ?> />
403
+ <span><?php _e('Replace emails in RSS feed by ', $this->domain ) ?></span></label>
404
+ <label><input type="text" id="protection_text" name="<?php echo $this->options_name ?>[protection_text]" value="<?php echo $options['protection_text']; ?>" />
405
  </td>
406
  </tr>
407
  </table>
410
  <fieldset class="options">
411
  <table class="form-table">
412
  <tr>
413
+ <th><?php _e('"Email Encoder Form" settings', $this->domain ) ?></th>
414
+ <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>
415
  </tr>
416
  </table>
417
  </fieldset>
418
  <p class="submit">
419
+ <input class="button-primary" type="submit" value="<?php _e('Save Changes') ?>" />
420
  </p>
421
  </form>
422
  </div>
423
  </div>
424
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
425
  <div class="postbox">
426
+ <div class="handlediv" title="<?php _e('Click to toggle') ?>"><br/></div>
427
+ <h3 class="hndle"><?php _e('Email Encoder Form', $this->domain ) ?></h3>
428
  <div class="inside">
429
  <?php echo $this->get_encoder_form(); ?>
430
  </div>
432
  </div>
433
  </div>
434
 
435
+ <div class="postbox-container side metabox-holder meta-box-sortables" style="width:28%;">
436
+ <div style="margin:0 2%;">
437
  <div class="postbox">
438
+ <div class="handlediv" title="<?php _e('Click to toggle') ?>"><br/></div>
439
+ <h3 class="hndle"><?php _e('About') ?>...</h3>
440
  <div class="inside">
441
+ <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>
442
+ <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>
443
  <ul>
444
+ <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/faq/" target="_blank"><?php _e('Get Started - FAQ', $this->domain ) ?></a></li>
445
+ <li><a href="http://www.freelancephp.net/contact/" target="_blank"><?php _e('Questions or suggestions?', $this->domain ) ?></a></li>
446
+ <li><?php _e('If you like this plugin please send your rating at WordPress.org.') ?></li>
447
  <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>
448
  </ul>
449
  </div>
450
  </div>
451
 
452
  <div class="postbox">
453
+ <div class="handlediv" title="<?php _e('Click to toggle') ?>"><br/></div>
454
+ <h3 class="hndle"><?php _e('Other Plugins', $this->domain ) ?></h3>
455
  <div class="inside">
456
+ <h4><img src="<?php echo plugins_url('images/icon-wp-external-links.png', __FILE__ ) ?>" width="16" height="16" /> WP External Links</h4>
457
+ <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>
458
  <ul>
459
+ <?php if (is_plugin_active('wp-external-links/wp-external-links.php') ): ?>
460
+ <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>
461
+ <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-external-links/wp-external-links.php') ): ?>
462
+ <li><a href="<?php echo get_bloginfo('url') ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e('Activate this plugin.', $this->domain ) ?></a></li>
463
  <?php else: ?>
464
+ <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>
465
  <?php endif; ?>
466
  <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>
467
  </ul>
468
 
469
+ <h4><img src="<?php echo plugins_url('images/icon-wp-mailto-links.png', __FILE__ ) ?>" width="16" height="16" /> WP Mailto Links</h4>
470
+ <p><?php _e('Manage mailto links on your site and protect emails from spambots, set mail icon and more.', $this->domain ) ?></p>
471
  <ul>
472
+ <?php if (is_plugin_active('wp-mailto-links/wp-mailto-links.php') ): ?>
473
+ <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>
474
+ <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-mailto-links/wp-mailto-links.php') ): ?>
475
+ <li><a href="<?php echo get_bloginfo('url') ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e('Activate this plugin.', $this->domain ) ?></a></li>
476
  <?php else: ?>
477
+ <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>
478
  <?php endif; ?>
479
  <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>
480
  </ul>
501
  <table>
502
  <tr>
503
  <tr>
504
+ <th><label for="email"><?php _e('Email address', $this->domain ) ?></label></th>
505
  <td><input type="text" class="regular-text" id="email" name="email" /></td>
506
  </tr>
507
  <tr>
508
+ <th><label for="display"><?php _e('Display', $this->domain ) ?></label></th>
509
  <td><input type="text" class="regular-text" id="display" name="display" /></td>
510
  </tr>
511
  <tr>
512
+ <th><?php _e('Example', $this->domain ) ?></th>
513
  <td><span id="example"></span></td>
514
  </tr>
515
  <tr>
516
+ <th><label for="encode_method"><?php _e('Encode method', $this->domain ) ?></label></th>
517
  <td><select id="encode_method" name="encode_method" class="postform">
518
+ <?php foreach ($this->methods AS $method => $info ): ?>
519
+ <option value="<?php echo $method ?>" <?php if ($this->method == $method ) echo 'selected="selected"' ?>><?php echo $info['name'] ?></option>
520
  <?php endforeach; ?>
521
+ <option value="random" <?php if ($this->method == 'random') echo 'selected="selected"' ?>><?php _e('Random', $this->domain ) ?></option>
522
  </select>
523
+ <input type="button" id="ajax_encode" value="<?php _e('Encode', $this->domain ) ?> &gt;&gt;" />
524
  </td>
525
  </tr>
526
  </tr>
530
  <table>
531
  <tr>
532
  <tr>
533
+ <th><label for="encoded_output"><?php _e('Code', $this->domain ) ?></label></th>
534
  <td><textarea class="large-text node" id="encoded_output" name="encoded_output"></textarea></td>
535
  </tr>
536
  </tr>
537
  </table>
538
  </div>
539
+ <?php if ($this->options['powered_by'] ): ?>
540
+ <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>
541
  <?php endif; ?>
542
  </fieldset>
543
  </form>
549
  return $form;
550
  }
551
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
552
  /**
553
  * Set options from save values or defaults
554
  */
555
+ function set_options() {
556
  // set options
557
+ $saved_options = get_option($this->options_name);
558
 
559
  // backwards compatible (old values)
560
+ if (empty($saved_options )) {
561
+ $saved_options = get_option($this->domain . 'options');
562
  }
563
+
564
+ if (empty($saved_options)) {
565
+ foreach ($this->options AS $key => $option) {
566
+ $saved_options[$key] = $this->options[$key];
567
+ }
568
+ }
569
+
570
  // upgrade to 0.40
571
+ if (! isset($saved_options['class_name'])) {
572
+ // set default
573
+ $saved_options['class_name'] = $this->options['class_name'];
574
+ $saved_options['filter_posts'] = $this->options['filter_posts'];
575
+ }
576
+
577
+ // upgrade to 0.50
578
+ if (!isset($saved_options['protection_text'])) {
579
  // set default
580
+ $saved_options['protection_text'] = $this->options['protection_text'];
581
+ $saved_options['skip_posts'] = $this->options['skip_posts'];
582
  }
583
 
584
  // set all options
585
+ if (!empty($saved_options)) {
586
+ foreach ($this->options AS $key => $option) {
587
+ $this->options[$key] = (empty($saved_options[$key])) ? '' : $saved_options[$key];
588
  }
589
  }
590
 
591
  // set encode method
592
+ $this->method = $this->get_method($this->options['method']);
593
 
594
  // set widget_content filter of Widget Logic plugin
595
+ $widget_logic_opts = get_option('widget_logic');
596
+ if (is_array($widget_logic_opts ) AND key_exists('widget_logic-options-filter', $widget_logic_opts )) {
597
+ $this->options['widget_logic_filter'] = ($widget_logic_opts['widget_logic-options-filter'] == 'checked') ? 1 : 0;
598
  }
599
  }
600
 
601
  /**
602
+ * Filter content for encoding
603
+ * @param string $content
604
+ * @param boolean $enc_tags Optional, default TRUE
605
+ * @param boolean $enc_mailtos Optional, default TRUE
606
+ * @param boolean $enc_plain_emails Optional, default TRUE
607
  * @return string
608
  */
609
+ function filter($content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE) {
610
+ // encode mailto links
611
+ if ($enc_mailtos) {
612
+ $content = preg_replace_callback($this->regexp_patterns['mailto'], array($this, 'callback_encode_email'), $content);
613
+ }
614
+
615
+ // replace plain emails
616
+ if ($enc_plain_emails) {
617
+ $content = preg_replace_callback($this->regexp_patterns['email'], array($this, 'callback_encode_email'), $content);
618
+ }
619
 
620
+ return $content;
621
  }
622
 
623
  /**
624
+ * Callback for encoding email
625
  * @param array $match
626
  * @return string
627
  */
628
+ function callback_encode_email($match) {
629
+ if (count($match ) == 2) {
630
+ return $this->encode_email($match[1]);
631
+ }
 
 
 
 
 
632
 
633
+ return $this->encode_email($match[1], $match[2]);
634
  }
635
 
636
  /**
637
+ * Get method name
638
+ * @param string $method
639
+ * @param string $defaultMethod Optional, default 'enc_html'
640
+ * @return string
641
  */
642
+ function get_method($method, $defaultMethod = 'enc_html') {
643
+ $method = strtolower($method);
 
644
 
645
+ if ('random' == $method) {
646
+ // set a random method
647
+ $method = array_rand($this->methods);
648
+ } else {
649
+ if (!method_exists($this, $method)) {
650
+ $method = $defaultMethod; // set default method
651
+ }
652
+ }
653
 
654
+ return $method;
655
+ }
656
 
657
  /**
658
+ * Encode the given email into an encoded HTML link
659
+ * @param string $content
660
+ * @param string $method Optional, else the default setted method will; be used
661
+ * @return string
662
  */
663
+ function encode($content, $method = NULL) {
664
+ // get encode method
665
+ $method = $this->get_method($method, $this->method);
666
 
667
+ if ($this->logged_in) {
668
+ $content = '<div class="' . $this->domain . '">' . $content . '</div>';
669
+ }
 
 
 
 
670
 
671
+ // get encoded email code
672
+ return $this->{$method}($content);
673
  }
674
 
675
  /**
677
  * @param string $email
678
  * @param string $display Optional, if not set display will be the email
679
  * @param string $method Optional, else the default setted method will; be used
680
+ * @param string $extra_attrs Optional
681
  * @return string
682
  */
683
+ function encode_email($email, $display = NULL, $method = NULL, $extra_attrs = '') {
684
  // decode entities
685
+ $email = html_entity_decode($email);
686
 
687
  // set email as display
688
+ if ($display === NULL) {
689
  $display = $email;
690
+ }
691
 
692
+ // get encode method
693
+ $method = $this->get_method($method, $this->method);
694
+
695
+ if ($method === 'enc_html') {
696
+ $email = $this->enc_html($email);
697
+ $display = $this->enc_html($display);
698
  }
699
 
700
+ $class = $this->options['class_name'];
701
+ $extra_attrs = ' ' . trim($extra_attrs) . ' title="' . $display . '"';
702
+
703
+ $html = '<a class="'. $class .'" href="mailto:' . $email . '"'. $extra_attrs . '>' . $display . '</a>';
704
+
705
  // get encoded email code
706
+ return ($method === 'enc_html') ? $html : $this->encode($html, $method);
707
  }
708
 
709
  /**
710
+ * ASCII method
711
+ * Based on function from Tyler Akins (http://rumkin.com/tools/mailto_encoder/)
712
+ *
 
713
  * @param string $value
714
  * @return string
715
  */
716
+ function enc_ascii($value) {
717
+ $mail_link = $value;
 
 
 
 
 
718
 
719
+ $mail_letters = '';
 
720
 
721
+ for ($i = 0; $i < strlen($mail_link); $i ++) {
722
+ $l = substr($mail_link, $i, 1);
723
+
724
+ if (strpos($mail_letters, $l) === false) {
725
+ $p = rand(0, strlen($mail_letters));
726
+ $mail_letters = substr($mail_letters, 0, $p) .
727
+ $l . substr($mail_letters, $p, strlen($mail_letters));
728
  }
729
  }
730
 
731
+ $mail_letters_enc = str_replace("\\", "\\\\", $mail_letters);
732
+ $mail_letters_enc = str_replace("\"", "\\\"", $mail_letters_enc);
733
 
734
+ $mail_indices = '';
735
+ for ($i = 0; $i < strlen($mail_link); $i ++) {
736
+ $index = strpos($mail_letters, substr($mail_link, $i, 1));
737
+ $index += 48;
738
+ $mail_indices .= chr($index);
739
+ }
740
+
741
+ $mail_indices = str_replace("\\", "\\\\", $mail_indices);
742
+ $mail_indices = str_replace("\"", "\\\"", $mail_indices);
743
+
744
+ return '<script type="text/javascript">/*<![CDATA[*/'
745
+ . 'ML="'. $mail_letters_enc .'";'
746
+ . 'MI="'. $mail_indices .'";'
747
+ . 'OT="";'
748
+ . 'for(j=0;j<MI.length;j++){'
749
+ . 'OT+=ML.charAt(MI.charCodeAt(j)-48);'
750
+ . '}document.write(OT);/*]]>*/</script><noscript>'
751
+ . $this->options['protection_text']
752
+ . '</noscript>';
753
  }
754
 
755
  /**
756
+ * Escape method
757
+ * Taken from the plugin "Email Spam Protection" by Adam Hunter (http://blueberryware.net/2008/09/14/email-spam-protection/)
758
+ *
759
+ * @param string $value
760
+ * @return string
761
  */
762
+ function enc_escape($value) {
763
+ $string = 'document.write(\'' . $value . '\')';
 
 
 
 
 
 
 
 
 
 
764
 
765
+ /* break string into array of characters, we can't use string_split because its php5 only :( */
766
+ $split = preg_split('||', $string);
767
+ $out = '<script type="text/javascript">/*<![CDATA[*/ ' . "eval(unescape('";
768
 
769
+ foreach ($split as $c) {
770
+ /* preg split will return empty first and last characters, check for them and ignore */
771
+ if (!empty($c)) {
772
+ $out .= '%' . dechex(ord($c));
 
 
773
  }
774
  }
775
 
776
+ $out .= "'))" . '/*]]>*/</script><noscript>'
777
+ . $this->options['protection_text']
778
+ . '</noscript>';
779
 
780
+ return $out;
781
+ }
782
 
783
+ /**
784
+ * Convert randomly chars to htmlentities
785
+ * This method is partly taken from WordPress
786
+ * @link http://codex.wordpress.org/Function_Reference/antispambot
787
+ *
788
+ * @param string $value
789
+ * @return string
790
+ */
791
+ function enc_html($value) {
792
+ // check if antispambot WordPress function exists
793
+ if (function_exists('antispambot')) {
794
+ $enc_value = antispambot($value);
795
  } else {
796
+ $enc_value = '';
797
+ srand( (float) microtime() * 1000000);
798
 
799
+ for ($i = 0; $i < strlen($value); $i = $i + 1) {
800
+ $j = floor( rand( 0, 1 ));
801
+
802
+ if ($j == 0) {
803
+ $enc_value .= '&#' . ord( substr($value, $i, 1 ) ).';';
804
+ } elseif ($j == 1) {
805
+ $enc_value .= substr($value, $i, 1);
806
+ }
807
+ }
808
  }
809
 
810
+ $enc_value = str_replace('@', '&#64;', $enc_value);
 
811
 
812
+ return $enc_value;
813
+ }
814
 
815
  } // end class WP_Email_Encoder_Bundle
816
 
817
 
818
+
819
  /**
820
  * Create instance
821
  */
825
  /**
826
  * Ajax Encoding request
827
  */
828
+ if (!empty($_GET['ajaxEncodeEmail'])):
829
  // input vars
830
  $method = $_GET['method'];
831
  $email = $_GET['email'];
832
+ $display = (empty($_GET['display'])) ? $email : $_GET['display'];
833
 
834
+ echo $WP_Email_Encoder_Bundle->encode_email($email, $display, $method);
835
  exit;
836
  endif;
837
 
 
838
  /**
839
  * Template function for encoding email
840
  * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
841
  * @param string $email
842
  * @param string $display if non given will be same as email
843
  * @param string $method Optional, else the default setted method will; be used
844
+ * @param string $extra_attrs Optional
845
+ * @return string
846
+ */
847
+ if (!function_exists('encode_email')):
848
+ function encode_email($email, $display = NULL, $method = NULL, $extra_attrs = '') {
849
+ global $WP_Email_Encoder_Bundle;
850
+ return $WP_Email_Encoder_Bundle->encode_email($email, $display, $method, $extra_attrs);
851
+ }
852
+ endif;
853
+
854
+ /**
855
+ * Template function for encoding content
856
+ * @global WP_Email_Encoder $WP_Email_Encoder_Bundle
857
+ * @param string $content
858
+ * @param string $method Optional, default NULL
859
  * @return string
860
  */
861
+ if (!function_exists('encode_content')):
862
+ function encode_content($content, $method = NULL) {
863
  global $WP_Email_Encoder_Bundle;
864
+ return $WP_Email_Encoder_Bundle->encode($content, $method);
865
  }
866
  endif;
867
 
874
  * @param boolean $enc_plain_emails Optional, default TRUE
875
  * @return string
876
  */
877
+ if (!function_exists('encode_email_filter')):
878
+ function encode_email_filter($content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE ) {
879
  global $WP_Email_Encoder_Bundle;
880
+ return $WP_Email_Encoder_Bundle->filter($content, $enc_tags, $enc_mailtos, $enc_plain_emails);
881
  }
882
  endif;
883
 
js/email-encoder-bundle-admin.js ADDED
@@ -0,0 +1,65 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*global jQuery*/
2
+ // Email Encoder Bundle Plugin - Admin
3
+ jQuery(function ($) {
4
+ 'use strict';
5
+
6
+ var methodInfo = window.methodInfo;
7
+
8
+ // remove message
9
+ $('.settings-error')
10
+ .hide()
11
+ .slideDown(600)
12
+ .delay(3000)
13
+ .slideUp(600);
14
+
15
+ // set info text for selected encoding method
16
+ $('.method-info-select')
17
+ .bind('change blur keyup', function () {
18
+ var method = $(this).val(),
19
+ $desc = $(this).parent().find('span.description');
20
+
21
+ if (methodInfo && methodInfo[method]) {
22
+ $desc.html(methodInfo[method].description || '');
23
+ } else {
24
+ $desc.html('');
25
+ }
26
+ })
27
+ .blur();
28
+
29
+ // "has effect on"
30
+ $('input#encode_emails')
31
+ .change(function () {
32
+ if ($(this).attr('checked')) {
33
+ $('input#encode_mailtos').attr('checked', true);
34
+ }
35
+ })
36
+ .change();
37
+
38
+ $('input#encode_mailtos')
39
+ .change(function () {
40
+ if (!$(this).attr('checked')) {
41
+ $('input#encode_emails').attr('checked', false);
42
+ }
43
+ });
44
+
45
+ // rss feed
46
+ $('input#filter_rss')
47
+ .change(function () {
48
+ $('input#protection_text').attr('disabled', !$(this).attr('checked'));
49
+ })
50
+ .change();
51
+
52
+ // add form-table class to Encoder Form tables
53
+ $('.email-encoder-form table').addClass('form-table');
54
+
55
+ // slide postbox
56
+ $('.postbox').find('.handlediv, .hndle').click(function () {
57
+ var $inside = $(this).parent().find('.inside');
58
+
59
+ if ($inside.css('display') === 'block') {
60
+ $inside.css({ display:'block' }).slideUp();
61
+ } else {
62
+ $inside.css({ display:'none' }).slideDown();
63
+ }
64
+ });
65
+ });
js/email-encoder-bundle.js CHANGED
@@ -1,63 +1,67 @@
 
1
  // Email Encoder Bundle Plugin
2
- jQuery(function( $ ){
 
3
 
4
- var prevEmail, getEncoded,
5
- $wrap = $( 'div.email-encoder-form' ),
6
- $email = $wrap.find( '#email' ),
7
- $display = $wrap.find( '#display' );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  // hide output
10
- $wrap.find( '.nodis' ).hide();
11
 
12
  // auto-set display field
13
  $email.keyup(function(){
14
  var email = $email.val(),
15
  display = $display.val();
16
 
17
- if ( ! display || display == prevEmail )
18
- $display.val( email );
 
19
 
20
  prevEmail = email;
21
  });
22
 
23
- // get encoded email ( ajax call )
24
- getEncoded = function () {
25
- // stop when email field is empty
26
- if ( ! $email.val() )
27
- return;
28
-
29
- // empty output
30
- $wrap.find( '#encoded_output' ).val( '' );
31
-
32
- // get the encoded email link
33
- $.get( '', {
34
- ajax: true,
35
- email: $email.val(),
36
- display: $display.val() || $email.val(),
37
- method: $wrap.find( '#encode_method' ).val()
38
- },
39
- function(data){
40
- $wrap.find( '#encoded_output' ).val( data );
41
- $wrap.find( '.output' ).slideDown();
42
- });
43
- };
44
-
45
  // get encoded link on these events
46
- $wrap.find( '#email, #display' ).keyup(function(){
47
- // show example how it will appear on the page
48
- $wrap.find( '#example' ).html( '<a href="mailto:'+ $email.val() +'">'+ $display.val() +'</a>' );
 
49
 
50
- // clear code field
51
- $wrap.find( '.output' ).slideUp();
52
- $wrap.find( '#encoded_output' ).val( '' );
53
- })
54
- .keyup();
55
 
56
- $wrap.find( '#encode_method' ).bind( 'change keyup', function(){
57
  getEncoded();
58
  });
59
 
60
- $wrap.find( '#ajax_encode' ).click(function(){
61
  getEncoded();
62
  });
63
 
1
+ /*global jQuery*/
2
  // Email Encoder Bundle Plugin
3
+ jQuery(function($){
4
+ 'use strict';
5
 
6
+ var $wrap = $('div.email-encoder-form'),
7
+ $email = $wrap.find('#email'),
8
+ $display = $wrap.find('#display'),
9
+ prevEmail;
10
+
11
+ // get encoded email ( ajax call )
12
+ var getEncoded = function () {
13
+ // stop when email field is empty
14
+ if (!$email.val()) {
15
+ return;
16
+ }
17
+
18
+ // empty the output field
19
+ $wrap.find('#encoded_output').val('');
20
+
21
+ // get the encoded email link
22
+ $.get('', {
23
+ ajaxEncodeEmail: true,
24
+ email: $email.val(),
25
+ display: $display.val() || $email.val(),
26
+ method: $wrap.find('#encode_method').val()
27
+ }, function (data) {
28
+ $wrap.find('#encoded_output').val(data);
29
+ $wrap.find('.output').slideDown();
30
+ });
31
+ };
32
 
33
  // hide output
34
+ $wrap.find('.nodis').hide();
35
 
36
  // auto-set display field
37
  $email.keyup(function(){
38
  var email = $email.val(),
39
  display = $display.val();
40
 
41
+ if (!display || display === prevEmail) {
42
+ $display.val(email);
43
+ }
44
 
45
  prevEmail = email;
46
  });
47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48
  // get encoded link on these events
49
+ $wrap.find('#email, #display')
50
+ .keyup(function () {
51
+ // show example how it will appear on the page
52
+ $wrap.find('#example').html('<a href="mailto:' + $email.val() + '">' + $display.val() + '</a>');
53
 
54
+ // clear code field
55
+ $wrap.find('.output').slideUp();
56
+ $wrap.find('#encoded_output').val('');
57
+ })
58
+ .keyup();
59
 
60
+ $wrap.find('#encode_method').bind('change keyup', function () {
61
  getEncoded();
62
  });
63
 
64
+ $wrap.find('#ajax_encode').click(function(){
65
  getEncoded();
66
  });
67
 
methods/ascii.php DELETED
@@ -1,60 +0,0 @@
1
- <?php
2
- if ( ! function_exists( 'lim_email_ascii' ) ):
3
-
4
- // Info (optional)
5
- $lim_email_ascii = array(
6
- 'name' => 'JavaScript ASCII',
7
- 'description' => 'Uses javascript (<a href="http://rumkin.com/tools/mailto_encoder/" target="_blank">original source</a>).',
8
- );
9
-
10
- /**
11
- * lim_email_ascii()
12
- * Based on function from Tyler Akins (http://rumkin.com/tools/mailto_encoder/)
13
- *
14
- * @package WP_Email_Encoder_Bundle
15
- * @param string $email the email to encode
16
- * @param string $display the display showing on the page
17
- * @param string $obj WP_Email_Encoder_Bundle object
18
- * @return string
19
- */
20
- function lim_email_ascii( $email, $display, $obj ) {
21
- $MailLink = '<a class="'. $obj->options[ 'class_name' ] .'" href="mailto:' . $email . '">' . $display . '</a>';
22
-
23
- $MailLetters = '';
24
-
25
- for ($i = 0; $i < strlen($MailLink); $i ++)
26
- {
27
- $l = substr($MailLink, $i, 1);
28
- if (strpos($MailLetters, $l) === false)
29
- {
30
- $p = rand(0, strlen($MailLetters));
31
- $MailLetters = substr($MailLetters, 0, $p) .
32
- $l . substr($MailLetters, $p, strlen($MailLetters));
33
- }
34
- }
35
-
36
- $MailLettersEnc = str_replace("\\", "\\\\", $MailLetters);
37
- $MailLettersEnc = str_replace("\"", "\\\"", $MailLettersEnc);
38
-
39
- $MailIndexes = '';
40
- for ($i = 0; $i < strlen($MailLink); $i ++)
41
- {
42
- $index = strpos($MailLetters, substr($MailLink, $i, 1));
43
- $index += 48;
44
- $MailIndexes .= chr($index);
45
- }
46
- $MailIndexes = str_replace("\\", "\\\\", $MailIndexes);
47
- $MailIndexes = str_replace("\"", "\\\"", $MailIndexes);
48
-
49
- return '<script type="text/javascript">/*<![CDATA[*/'
50
- . 'ML="'. $MailLettersEnc .'";'
51
- . 'MI="'. $MailIndexes .'";'
52
- . 'OT="";'
53
- . 'for(j=0;j<MI.length;j++){'
54
- . 'OT+=ML.charAt(MI.charCodeAt(j)-48);'
55
- . '}document.write(OT);/*]]>*/</script><noscript>*protected email*</noscript>';
56
- }
57
-
58
- endif;
59
-
60
- /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
methods/escape.php DELETED
@@ -1,37 +0,0 @@
1
- <?php
2
- if ( ! function_exists( 'lim_email_escape' ) ):
3
-
4
- // Info (optional)
5
- $lim_email_escape = array(
6
- 'name' => 'JavaScript Escape',
7
- 'description' => 'Uses javascript eval() function (<a href="http://blueberryware.net/2008/09/14/email-spam-protection/" target="_blank">original source</a>).',
8
- );
9
-
10
- /**
11
- * lim_email_escape()
12
- * Taken from the plugin "Email Spam Protection" by Adam Hunter (http://blueberryware.net/2008/09/14/email-spam-protection/)
13
- *
14
- * @package WP_Email_Encoder_Bundle
15
- * @param string $email the email to encode
16
- * @param string $display the display showing on the page
17
- * @param string $obj WP_Email_Encoder_Bundle object
18
- * @return string
19
- */
20
- function lim_email_escape( $email, $display, $obj ) {
21
- $string = 'document.write(\'<a class="'. $obj->options[ 'class_name' ] .'" href="mailto:' . $email . '">' . $display . '</a>\')';
22
- /* break string into array of characters, we can't use string_split because its php5 only :( */
23
- $split = preg_split('||', $string);
24
- $out = '<script type="text/javascript">/*<![CDATA[*/ ' . "eval(unescape('";
25
- foreach ( $split as $c ) {
26
- /* preg split will return empty first and last characters, check for them and ignore */
27
- if ( !empty($c) ) {
28
- $out .= '%' . dechex(ord($c));
29
- }
30
- }
31
- $out .= "'))" . '/*]]>*/</script><noscript>*protected email*</noscript>';
32
- return $out;
33
- }
34
-
35
- endif;
36
-
37
- /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
methods/html_encode.php DELETED
@@ -1,30 +0,0 @@
1
- <?php
2
- if ( ! function_exists( 'lim_email_html_encode' ) ):
3
-
4
- // Info (optional)
5
- $lim_email_html_encode = array(
6
- 'name' => 'Html Encode',
7
- 'description' => 'Email encode method using antispambot() built-in WordPress (<a href="http://codex.wordpress.org/Function_Reference/antispambot" target="_blank">more info</a>).',
8
- );
9
-
10
- /**
11
- * lim_email_html_encode()
12
- * Default email encode method converting email to html entities
13
- *
14
- * @package WP_Email_Encoder_Bundle
15
- * @param string $email the email to encode
16
- * @param string $display the display showing on the page
17
- * @param string $obj WP_Email_Encoder_Bundle object
18
- * @return string
19
- */
20
- function lim_email_html_encode( $email, $display, $obj ) {
21
- $email = $obj->get_htmlent( $email );
22
- $display = $obj->get_htmlent( $display );
23
-
24
- // return encode mailto link
25
- return '<a class="'. $obj->options[ 'class_name' ] .'" href="mailto:' . $email . '">' . $display . '</a>';
26
- }
27
-
28
- endif;
29
-
30
- /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -2,8 +2,8 @@
2
  Contributors: freelancephp
3
  Tags: email, hide, mailto, spam, protection, spambots, encoder, encrypt, encode, obfuscate, antispam, spamming
4
  Requires at least: 2.7.0
5
- Tested up to: 3.3.1
6
- Stable tag: 0.42
7
 
8
  Protect email addresses on your site from spambots and being used for spamming. This plugin encodes all email adresses so spambots cannot read them.
9
 
@@ -13,17 +13,23 @@ Protect email addresses on your site from spambots and being used for spamming.
13
 
14
  = Features =
15
  * Protect plain emails and mailto links
 
16
  * Scanning posts, widgets, comments and RSS feeds
17
  * Choose one of the high-quality encoding methods
18
  * Supports querystrings like 'info@myemail.com?subject=Plugin'
 
19
 
20
- * Tag available `[encode_email email="info@myemail.com" display="My Email"]`
21
- * Template function available `<?php echo encode_email( 'info@myemail.com', 'My Email' ); ?>`
 
 
22
 
23
- = Extra =
24
- * Put an Email Encoder Form on your site
25
- * Developers can add their own methods
 
26
 
 
27
  Supports PHP4.3+ and up to latest WP version.
28
 
29
  == Installation ==
@@ -33,48 +39,53 @@ Supports PHP4.3+ and up to latest WP version.
33
  1. Search for `Email Encode Bundle` and click 'Install Now' or click on the `upload` link to upload `email-encode-bundle.zip`
34
  1. Click on `Activate plugin`
35
 
36
- = Tags =
37
- * `[encode_email email="..." display="..."]` Encode the given email, "display" is optional otherwise the email wil be used as display
38
- * `[email_encoder_form]` Puts an encoder form in your post (check if the option is activated on this page)
39
 
40
- = Template functions =
41
- * `<?php echo encode_email( 'info@myemail.com', 'My Email' ); ?>` Encode the given email, the second param is display and optional
42
- * `<?php echo encode_email_filter( $content ); ?>` Filter the given content for emails to encode
43
 
44
- == Frequently Asked Questions ==
 
 
 
 
 
 
 
 
 
45
 
46
  = Which encoding method should I use? =
47
 
48
  The `Html Encode` method uses the built-in function of WordPress and does not use any javascript.
49
  Although JavaScript methods (like `JavaScript ASCII`) are probably better protection against spambots.
50
 
51
- = How to encode emails in ALL widgets? =
52
-
53
- If the option 'All text widgets' is activated, only all widgets will be filtered for encoding.
54
- It's possible to encode emails in all widgets by using the Widget Logic plugin and activate the 'wodget_content' filter.
55
-
56
- = I want to make some adjustment in one of the encoding methods. What is the best way? =
57
 
58
- The best way is to make a copy of that method and make your adjustments in the copy. Give the new method a unique name.
59
- Now you can keep updating this plugin and keep remaining the changes you have made.
60
 
61
- = My self-written method doesn't work after upgrading to v0.2. How to fix this? =
62
 
63
- The has been some changes to the structure of the encoding methods.
64
- The first is the 3rd param `$encode_display` has been removed, because the display should always be encoded.
65
- Second, the methodnames should contain the prefix `lim_email_`.
66
- Optionally you can add a name and description to be showed in the admin panel, like:
67
- `$lim_email_yourmethodname = array( 'name' => 'YourMethodName', 'description' => '....' );`
68
 
69
  [Do you have another question? Please ask me](http://www.freelancephp.net/contact/)
70
 
71
  == Screenshots ==
72
 
73
- 1. Email Encoder Form on the Site
74
  1. Admin Options Page
 
75
 
76
  == Changelog ==
77
 
 
 
 
 
 
 
 
 
78
  = 0.42 =
79
  * Widget Logic options bug
80
 
@@ -147,20 +158,9 @@ Optionally you can add a name and description to be showed in the admin panel, l
147
 
148
  == Upgrade Notice ==
149
 
150
- = 0.41 =
151
- * Solved some issues
152
-
153
- = 0.40 =
154
- * Added option for setting CSS classes
155
- * Improved RSS protection
156
- * And more...
157
-
158
- = 0.32 =
159
- * Fix IE bug
160
- * Bug plain emails
161
- * Optional "method" param for tag and template function
162
- * Small adjustments
163
-
164
- = 0.30 =
165
- * Some bug fixes
166
- * New: email protection for RSS feeds
2
  Contributors: freelancephp
3
  Tags: email, hide, mailto, spam, protection, spambots, encoder, encrypt, encode, obfuscate, antispam, spamming
4
  Requires at least: 2.7.0
5
+ Tested up to: 3.5.0
6
+ Stable tag: 0.50
7
 
8
  Protect email addresses on your site from spambots and being used for spamming. This plugin encodes all email adresses so spambots cannot read them.
9
 
13
 
14
  = Features =
15
  * Protect plain emails and mailto links
16
+ * Encode all kind of content (text and html)
17
  * Scanning posts, widgets, comments and RSS feeds
18
  * Choose one of the high-quality encoding methods
19
  * Supports querystrings like 'info@myemail.com?subject=Plugin'
20
+ * Put an Email Encoder Form on your site
21
 
22
+ = Tags =
23
+ * `[encode_email email="..." display="..." method="..."]` Encode the given email, "display" is optional otherwise the email wil be used as display
24
+ * `[encode_content method="..."]...[/encode_content]` Encode content, "method" is optional otherwise the method set in the admin options page
25
+ * `[email_encoder_form]` Puts an encoder form in your post (check if the option is activated on this page)
26
 
27
+ = Template functions =
28
+ * `<?php echo encode_email( $email, [ $display ], [ $method ], [ $extra_attrs ] ); ?>` Encode the given email, the other params are optional
29
+ * `<?php echo encode_content( $content, [ $method ] ); ?>` Encode the given content for emails to encode
30
+ * `<?php echo encode_email_filter( $content, [ $enc_tags ], [ $enc_mailtos ], [ $enc_plain_emails ] ); ?>` Filter the given content for emails to encode, the other params are optional
31
 
32
+ = Support =
33
  Supports PHP4.3+ and up to latest WP version.
34
 
35
  == Installation ==
39
  1. Search for `Email Encode Bundle` and click 'Install Now' or click on the `upload` link to upload `email-encode-bundle.zip`
40
  1. Click on `Activate plugin`
41
 
42
+ == Frequently Asked Questions ==
 
 
43
 
44
+ = How do I encode my emailaddress(es)? =
 
 
45
 
46
+ By default the option `Encode mailto links` is enabled and the default method is `JavaScript ASCII`. This means the following html snippet:
47
+ `<a href="mailto:myname@test.nl">My Email</a>`
48
+
49
+ Will be encoded, which creates the following output in the source code of your page:
50
+ `<script type="text/javascript">/*<![CDATA[*/ML="mo@k<insc:r.y=-Ehe a\">f/lMt";MI="4CB8HC77=D0C5HJ1>H563DB@:AF=D0C5HJ190<6C0A2JA7J;6HDBBJ5JHA=DI<B?0C5HDEI<B?0C5H4GCE";OT="";for(j=0;j<MI.length;j++){OT+=ML.charAt(MI.charCodeAt(j)-48);}document.write(OT);/*]]>*/</script><noscript>*protected email*</noscript>`
51
+
52
+ Therefore spambots are not able to scan this emailaddress from the site.
53
+
54
+ Within your posts, you can use the shortcode `[email_encode]`, f.e.:
55
+ `[email_encode email="myname@test.nl" display="My Email"]`
56
 
57
  = Which encoding method should I use? =
58
 
59
  The `Html Encode` method uses the built-in function of WordPress and does not use any javascript.
60
  Although JavaScript methods (like `JavaScript ASCII`) are probably better protection against spambots.
61
 
62
+ = How to create mailto links that opens in a new window? =
 
 
 
 
 
63
 
64
+ You could use add extra params to the mailto link and add `target='_blank'`, f.e.:
65
+ `[encode_email email="yourmail@test.nl" display="My Mail" extra_attrs="target='_blank'"]`
66
 
67
+ = How to encode emails in ALL widgets? =
68
 
69
+ If the option 'All text widgets' is activated, only all widgets will be filtered for encoding.
70
+ It's possible to encode emails in all widgets by using the Widget Logic plugin and activate the 'widget_content' filter.
 
 
 
71
 
72
  [Do you have another question? Please ask me](http://www.freelancephp.net/contact/)
73
 
74
  == Screenshots ==
75
 
 
76
  1. Admin Options Page
77
+ 1. Email Encoder Form on the Site
78
 
79
  == Changelog ==
80
 
81
+ = 0.50 =
82
+ * Added encode method for all kind of contents (template function and shortcode "encode_content")
83
+ * Added extra param for additional html attributes (f.e. target="_blank")
84
+ * Added option to skip certain posts from being automatically encoded
85
+ * Added option custom protection text
86
+ * Removed "method" folder. Not possible to add own methods anymore.
87
+ * Other small changes and some refactoring
88
+
89
  = 0.42 =
90
  * Widget Logic options bug
91
 
158
 
159
  == Upgrade Notice ==
160
 
161
+ = 0.50 =
162
+ * Added encode method for all kind of contents
163
+ * Added extra param for additional html attributes
164
+ * Added option to skip certain posts from being automatically encoded
165
+ * Added option custom protection text
166
+ * Notice: not possible to add your own methods anymore.
 
 
 
 
 
 
 
 
 
 
 
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file