Email Encoder Bundle – Protect Email Address - Version 0.40

Version Description

  • Added option for setting CSS classes
  • Improved RSS protection
  • Removed Lim_Email_Encoder class (now all handled by the main class)
  • Enabled setting checkbox for filtering posts
  • Fixed PHP / WP notices
  • Added param for encode methods: $obj
Download this release

Release Info

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

Code changes from version 0.32 to 0.40

Lim_Email_Encoder.php DELETED
@@ -1,164 +0,0 @@
1
- <?php
2
- /**
3
- * Lim_Email_Encoder Class
4
- *
5
- * Protecting email-spamming by replacing them with one of the registered encoding-methods
6
- *
7
- * @package Lim_Email_Encoder
8
- * @author Victor Villaverde Laan
9
- * @version 0.32
10
- * @link http://www.freelancephp.net/email-encoder-php-class/
11
- * @license MIT license
12
- */
13
- class Lim_Email_Encoder {
14
-
15
- /**
16
- * @var array
17
- */
18
- var $methods = array();
19
-
20
- /**
21
- * @var string
22
- */
23
- var $method = NULL;
24
-
25
-
26
- /**
27
- * PHP4 constructor
28
- */
29
- function Lim_Email_Encoder() {
30
- $this->__construct();
31
- }
32
-
33
- /**
34
- * PHP5 constructor
35
- */
36
- function __construct( $method = NULL ) {
37
- // include all available method files
38
- $this->_load_methods();
39
-
40
- // set method
41
- $this->set_method( $method );
42
- }
43
-
44
- /**
45
- * Set the encode method to use
46
- * @param string $method can be the name of the method or 'random'
47
- * @return $this
48
- */
49
- function set_method( $method ) {
50
- $this->method = $this->_get_method( $method );
51
-
52
- return $this;
53
- }
54
-
55
- /**
56
- * Encode the given email into an encoded HTML link
57
- * @param string $email
58
- * @param string $display Optional, if not set display will be the email
59
- * @param string $method Optional, else the default setted method will; be used
60
- * @return string
61
- */
62
- function encode( $email, $display = NULL, $method = NULL ) {
63
- // decode entities
64
- $email = html_entity_decode( $email );
65
-
66
- // set email as display
67
- if ( $display === NULL )
68
- $display = $email;
69
-
70
- // set encode method
71
- if ( $method === NULL ) {
72
- $method = $this->method;
73
- } else {
74
- $method = $this->_get_method( $method );
75
- }
76
-
77
- // get encoded email code
78
- return call_user_func( $method, $email, $display );
79
- }
80
-
81
- /**
82
- * Convert randomly chars to htmlentities
83
- * This method is partly taken from WordPress
84
- * @link http://codex.wordpress.org/Function_Reference/antispambot
85
- * @static
86
- * @param string $value
87
- * @return string
88
- */
89
- function get_htmlent( $value ) {
90
- // check if antispambot WordPress function exists
91
- if ( function_exists( 'antispambot' ) ) {
92
- $enc_value = antispambot( $value );
93
- } else {
94
- $enc_value = '';
95
- srand( (float) microtime() * 1000000 );
96
-
97
- for ( $i = 0; $i < strlen( $value ); $i = $i + 1 ) {
98
- $j = floor( rand( 0, 1 ) );
99
-
100
- if ( $j == 0 ) {
101
- $enc_value .= '&#' . ord( substr( $value, $i, 1 ) ).';';
102
- } elseif ( $j == 1 ) {
103
- $enc_value .= substr( $value, $i, 1 );
104
- }
105
- }
106
- }
107
-
108
- $enc_value = str_replace( '@', '&#64;', $enc_value );
109
-
110
- return $enc_value;
111
- }
112
-
113
- /**
114
- * Load available methods
115
- * @return void
116
- */
117
- function _load_methods() {
118
- $method_dir = dirname(__FILE__) . '/methods';
119
- $handle = opendir( $method_dir );
120
-
121
- // dir not found
122
- if ( ! $handle )
123
- return;
124
-
125
- // include all methods inside the method folder
126
- while ( false !== ($file = readdir($handle)) ) {
127
- if ( '.php' == substr( $file, -4 ) ) {
128
- require_once $method_dir . '/' . $file;
129
-
130
- $name = substr( $file, 0, -4 );
131
- $fn = 'lim_email_' . $name;
132
-
133
- if ( function_exists( $fn ) ) {
134
- // set method with info
135
- $this->methods[$fn] = ( isset( ${ $fn } ) )
136
- ? ${ $fn }
137
- : array( 'name' => $name, 'description' => $name );
138
- }
139
- }
140
- }
141
-
142
- closedir( $handle );
143
- }
144
-
145
- function _get_method( $method ) {
146
- $method = strtolower( $method );
147
-
148
- if ( 'random' == $method ) {
149
- // set a random method
150
- $method = array_rand( $this->methods );
151
- } else {
152
- // add 'lim_email_' prefix if not already set
153
- $method = ( strpos( $method, 'lim_email_' ) !== FALSE ) ? $method : 'lim_email_' . $method;
154
-
155
- if ( ! key_exists( $method, $this->methods ) )
156
- $method = 'lim_email_html_encode'; // set default method
157
- }
158
-
159
- return $method;
160
- }
161
-
162
- } // end class Lim_Email_Encoder
163
-
164
- /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
email-encoder-bundle.php CHANGED
@@ -4,25 +4,23 @@ Plugin Name: Email Encoder Bundle
4
  Plugin URI: http://www.freelancephp.net/email-encoder-php-class-wp-plugin/
5
  Description: Protect email addresses on your site from spambots and being used for spamming by using one of the encoding methods.
6
  Author: Victor Villaverde Laan
7
- Version: 0.32
8
  Author URI: http://www.freelancephp.net
9
  License: Dual licensed under the MIT and GPL licenses
10
  */
11
- // include parent class
12
- require_once dirname( __FILE__ ) . '/Lim_Email_Encoder.php';
13
 
14
  /**
15
- * Class WP_Email_Encoder_Bundle, child of Lim_Email_Encoder
16
- * @package Lim_Email_Encoder
17
  * @category WordPress Plugins
18
  */
19
- class WP_Email_Encoder_Bundle extends Lim_Email_Encoder {
20
 
21
  /**
22
  * Current version
23
  * @var string
24
  */
25
- var $version = '0.32';
26
 
27
  /**
28
  * Used as prefix for options entry and could be used as text domain (for translations)
@@ -43,6 +41,8 @@ class WP_Email_Encoder_Bundle extends Lim_Email_Encoder {
43
  'method' => NULL,
44
  'encode_mailtos' => 1,
45
  'encode_emails' => 1,
 
 
46
  'filter_widgets' => 1,
47
  'filter_comments' => 1,
48
  'filter_rss' => 1,
@@ -54,11 +54,22 @@ class WP_Email_Encoder_Bundle extends Lim_Email_Encoder {
54
  * @var array
55
  */
56
  var $regexp_patterns = array(
57
- 'mailto' => '/<a.*?href=["\']mailto:(.*?)["\'].*?>(.*?)<\/a[\s+]*>/i',
58
- 'tag' => '/\[encode_email\s+(.*?)\]/i',
59
- 'email' => '/([A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6})/i',
60
  );
61
 
 
 
 
 
 
 
 
 
 
 
 
62
  /**
63
  * PHP4 constructor
64
  */
@@ -70,7 +81,11 @@ class WP_Email_Encoder_Bundle extends Lim_Email_Encoder {
70
  * PHP5 constructor
71
  */
72
  function __construct() {
73
- parent::__construct();
 
 
 
 
74
 
75
  // set option values
76
  $this->_set_options();
@@ -78,31 +93,59 @@ class WP_Email_Encoder_Bundle extends Lim_Email_Encoder {
78
  // load text domain for translations
79
  load_plugin_textdomain( $this->domain, dirname( __FILE__ ) . '/lang/', basename( dirname(__FILE__) ) . '/lang/' );
80
 
 
 
 
 
81
  // add actions
82
- add_action( 'init', array( $this, 'init' ) );
83
- add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
84
- add_action( 'admin_init', array( &$this, 'admin_init' ) );
85
- add_action( 'the_posts', array( &$this, 'the_posts' ) );
 
 
86
  }
87
 
88
  /**
89
- * Callback init
 
90
  */
91
- function init() {
92
- if ( is_admin() ) {
93
- // set uninstall hook
94
- if ( function_exists( 'register_deactivation_hook' ) )
95
- register_deactivation_hook( __FILE__, array( &$this, 'deactivation' ));
96
- } else {
97
- $priority = 100;
98
 
99
- // set content filters
100
- add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ), $priority );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
  // comments
103
  if ( $this->options[ 'filter_comments' ] ) {
104
  add_filter( 'comment_text', array( $this, '_filter_callback' ), $priority );
105
  add_filter( 'comment_excerpt', array( $this, '_filter_callback' ), $priority );
 
106
  add_filter( 'get_comment_author_url', array( $this, '_filter_callback' ), $priority );
107
  add_filter( 'get_comment_author_link', array( $this, '_filter_callback' ), $priority );
108
  add_filter( 'get_comment_author_url_link', array( $this, '_filter_callback' ), $priority );
@@ -118,30 +161,6 @@ class WP_Email_Encoder_Bundle extends Lim_Email_Encoder {
118
  //add_filter( 'widget_content', array( $this, 'filter_content' ), $priority );
119
  }
120
  }
121
- }
122
-
123
- /**
124
- * pre_get_posts filter
125
- * @param object $query
126
- */
127
- function pre_get_posts( $query ) {
128
- $priority = 100;
129
-
130
- if ( $query->is_feed ) {
131
- // rss feed
132
- if ( $this->options[ 'filter_rss' ] ) {
133
- add_filter( 'the_content_rss', array( $this, '_filter_rss_callback' ), $priority );
134
- add_filter( 'the_content_feed', array( $this, '_filter_rss_callback' ), $priority );
135
- add_filter( 'the_excerpt_rss', array( $this, '_filter_rss_callback' ), $priority );
136
- add_filter( 'comment_text_rss', array( $this, '_filter_rss_callback' ), $priority );
137
- }
138
- } else {
139
- // post content
140
- add_filter( 'the_title', array( $this, '_filter_callback' ), $priority );
141
- add_filter( 'the_content', array( $this, '_filter_callback' ), $priority );
142
- add_filter( 'the_excerpt', array( $this, '_filter_callback' ), $priority );
143
- add_filter( 'get_the_excerpt', array( $this, '_filter_callback' ), $priority );
144
- }
145
 
146
  return $query;
147
  }
@@ -158,6 +177,7 @@ class WP_Email_Encoder_Bundle extends Lim_Email_Encoder {
158
  if ( stripos( $post->post_content, '[email_encoder_form]' ) > -1 ) {
159
  // add style and script for ajax encoder
160
  wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ), $this->version );
 
161
  // replace tag by form
162
  $posts[$key]->post_content = str_replace( '[email_encoder_form]', $this->get_encoder_form(), $post->post_content );
163
  break;
@@ -174,7 +194,7 @@ class WP_Email_Encoder_Bundle extends Lim_Email_Encoder {
174
  if ( function_exists('add_options_page') AND current_user_can('manage_options') ) {
175
  // add options page
176
  $page = add_options_page( 'Email Encoder Bundle', 'Email Encoder Bundle',
177
- 'manage_options', __FILE__, array( &$this, 'options_page' ) );
178
  }
179
  }
180
 
@@ -298,9 +318,14 @@ jQuery(function( $ ){
298
  </label>
299
  </td>
300
  </tr>
 
 
 
 
 
301
  <tr>
302
  <th><?php _e( 'Options has effect on', $this->domain ) ?></th>
303
- <td><label><input type="checkbox" name="<?php echo $this->options_name ?>[filter_posts]" value="1" checked="checked" disabled="disabled" />
304
  <span><?php _e( 'Posts', $this->domain ) ?></span>
305
  </label>
306
  <br/><label><input type="checkbox" id="<?php echo $this->options_name ?>[filter_comments]" name="<?php echo $this->options_name ?>[filter_comments]" value="1" <?php checked('1', (int) $options['filter_comments']); ?> />
@@ -519,11 +544,17 @@ jQuery(function( $ ){
519
  if ( empty( $saved_options ) ) {
520
  $saved_options = get_option( $this->domain . 'options' );
521
  }
 
 
 
 
 
 
522
 
523
  // set all options
524
  if ( ! empty( $saved_options ) ) {
525
  foreach ( $this->options AS $key => $option ) {
526
- $this->options[ $key ] = $saved_options[ $key ];
527
  }
528
  }
529
 
@@ -574,6 +605,130 @@ jQuery(function( $ ){
574
  return preg_replace( $this->regexp_patterns, '*protected email*', $content );
575
  }
576
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
577
  } // end class WP_Email_Encoder_Bundle
578
 
579
 
@@ -628,4 +783,4 @@ if ( ! function_exists( 'encode_email_filter' ) ):
628
  }
629
  endif;
630
 
631
- ?>
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)
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,
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
  */
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();
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 );
161
  //add_filter( 'widget_content', array( $this, 'filter_content' ), $priority );
162
  }
163
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
  return $query;
166
  }
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;
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
 
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']); ?> />
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
 
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
 
783
  }
784
  endif;
785
 
786
+ /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */
methods/ascii.php CHANGED
@@ -11,13 +11,14 @@ $lim_email_ascii = array(
11
  * lim_email_ascii()
12
  * Based on function from Tyler Akins (http://rumkin.com/tools/mailto_encoder/)
13
  *
14
- * @package Lim_Email_Encoder
15
  * @param string $email the email to encode
16
  * @param string $display the display showing on the page
 
17
  * @return string
18
  */
19
- function lim_email_ascii( $email, $display ) {
20
- $MailLink = '<a href="mailto:' . $email . '">' . $display . '</a>';
21
 
22
  $MailLetters = '';
23
 
@@ -55,4 +56,5 @@ function lim_email_ascii( $email, $display ) {
55
  }
56
 
57
  endif;
58
- ?>
 
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
 
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 CHANGED
@@ -11,13 +11,14 @@ $lim_email_escape = array(
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 Lim_Email_Encoder
15
  * @param string $email the email to encode
16
  * @param string $display the display showing on the page
 
17
  * @return string
18
  */
19
- function lim_email_escape( $email, $display ) {
20
- $string = 'document.write(\'<a href="mailto:' . $email . '">' . $display . '</a>\')';
21
  /* break string into array of characters, we can't use string_split because its php5 only :( */
22
  $split = preg_split('||', $string);
23
  $out = '<script type="text/javascript">/*<![CDATA[*/ ' . "eval(unescape('";
@@ -32,4 +33,5 @@ function lim_email_escape( $email, $display ) {
32
  }
33
 
34
  endif;
35
- ?>
 
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('";
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 CHANGED
@@ -11,19 +11,20 @@ $lim_email_html_encode = array(
11
  * lim_email_html_encode()
12
  * Default email encode method converting email to html entities
13
  *
14
- * @package Lim_Email_Encoder
15
  * @param string $email the email to encode
16
  * @param string $display the display showing on the page
 
17
  * @return string
18
  */
19
- function lim_email_html_encode( $email, $display ) {
20
- $email = Lim_Email_Encoder::get_htmlent( $email );
21
- $display = Lim_Email_Encoder::get_htmlent( $display );
22
 
23
  // return encode mailto link
24
- return '<a href="mailto:' . $email . '">' . $display . '</a>';
25
  }
26
 
27
  endif;
28
 
29
- ?>
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
@@ -3,7 +3,7 @@ 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.1
6
- Stable tag: 0.32
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
 
@@ -65,11 +65,19 @@ Optionally you can add a name and description to be showed in the admin panel, l
65
 
66
  == Screenshots ==
67
 
68
- 1. Admin Options Page
69
  1. Email Encoder Form on the Site
 
70
 
71
  == Changelog ==
72
 
 
 
 
 
 
 
 
 
73
  = 0.32 =
74
  * Fix IE bug
75
  * Bug plain emails
@@ -125,6 +133,11 @@ Optionally you can add a name and description to be showed in the admin panel, l
125
 
126
  == Upgrade Notice ==
127
 
 
 
 
 
 
128
  = 0.32 =
129
  * Fix IE bug
130
  * Bug plain emails
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.1
6
+ Stable tag: 0.40
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
 
65
 
66
  == Screenshots ==
67
 
 
68
  1. Email Encoder Form on the Site
69
+ 1. Admin Options Page
70
 
71
  == Changelog ==
72
 
73
+ = 0.40 =
74
+ * Added option for setting CSS classes
75
+ * Improved RSS protection
76
+ * Removed Lim_Email_Encoder class (now all handled by the main class)
77
+ * Enabled setting checkbox for filtering posts
78
+ * Fixed PHP / WP notices
79
+ * Added param for encode methods: $obj
80
+
81
  = 0.32 =
82
  * Fix IE bug
83
  * Bug plain emails
133
 
134
  == Upgrade Notice ==
135
 
136
+ = 0.40 =
137
+ * Added option for setting CSS classes
138
+ * Improved RSS protection
139
+ * And more...
140
+
141
  = 0.32 =
142
  * Fix IE bug
143
  * Bug plain emails
screenshot-1.png CHANGED
Binary file
screenshot-2.png CHANGED
Binary file