PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 0.21
Email Encoder – Protect Email Addresses and Phone Numbers v0.21
2.5.0 2.4.8 trunk 0.10 0.11 0.12 0.20 0.21 0.22 0.30 0.31 0.32 0.40 0.41 0.42 0.50 0.60 0.70 0.71 0.80 1.0.0 1.0.1 1.0.2 1.1.0 1.2.0 1.2.1 1.3.0 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.5 1.5.2 1.51 1.53 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 2.1.0 2.1.1 2.1.10 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.3.0 2.3.1 2.3.3 2.3.4 2.3.5 2.3.6 2.3.7 2.3.8 2.3.9 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7
email-encoder-bundle / Lim_Email_Encoder.php
email-encoder-bundle Last commit date
js 15 years ago lang 15 years ago methods 15 years ago GPL-license.txt 15 years ago Lim_Email_Encoder.php 15 years ago MIT-license.txt 15 years ago email-encoder-bundle.php 15 years ago readme.txt 15 years ago screenshot-1.jpg 15 years ago
Lim_Email_Encoder.php
187 lines
1 <?php
2 /**
3 * Lim_Email_Encoder Class
4 *
5 * Protecting email-spamming by replacing them with one of the registered encoding- or javascript-methods
6 *
7 * @package Lim_Email_Encoder
8 * @author Victor Villaverde Laan
9 * @version 0.21
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 if ( 'random' == $method ) {
51 // set a random method
52 $this->method = array_rand( $this->methods );
53 } elseif ( ! key_exists( $method, $this->methods ) ) {
54 // set default method
55 $this->method = 'lim_email_html_encode';
56 } else {
57 // add 'lim_email_' prefix if not already set
58 $this->method = ( strpos( $method, 'lim_email_' ) !== FALSE ) ? $method : 'lim_email_' . $method;
59 }
60
61 return $this;
62 }
63
64 /**
65 * Encode the given email into an encoded HTML link
66 * @param string $email
67 * @param string $display Optional, if not set display will be the email
68 * @return string
69 */
70 function encode( $email, $display = NULL ) {
71 if ( $display === NULL )
72 $display = $email;
73
74 // get encoded email code
75 return call_user_func( $this->method, $email, $display );
76 }
77
78 /**
79 * Encode all emails of the given content
80 * @param string $content
81 * @param boolean $enc_tags Optional, default TRUE
82 * @param boolean $enc_plain_emails Optional, default TRUE
83 * @param boolean $enc_mailtos Optional, default TRUE
84 * @return string
85 */
86 function filter( $content, $enc_tags = TRUE, $enc_plain_emails = TRUE, $enc_mailtos = TRUE ) {
87 // encode mailto links
88 if ( $enc_mailtos ) {
89 $mailto_pattern = '/<a.*?href=["\']mailto:(.*?)["\'].*?>(.*?)<\/a>/i';
90 $content = preg_replace_callback( $mailto_pattern, array( $this, '_callback' ), $content );
91 }
92
93 // replace content tags [encode_email email="?" display="?"] to mailto links
94 // this code is partly taken from the plugin "Fay Emails Encoder"
95 // Credits goes to Faycal Tirich (http://faycaltirich.blogspot.com)
96 if ( $enc_tags ) {
97 $tag_pattern = '/\[encode_email\s+email=["\'](.*?)["\']\s+display=["\'](.*?)["\']]/i';
98 $content = preg_replace_callback( $tag_pattern, array( $this, '_callback' ), $content );
99 }
100
101 // replace plain emails
102 if ( $enc_plain_emails ) {
103 $email_pattern = '/([A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6})/i';
104 $content = preg_replace_callback( $email_pattern, array( $this, '_callback' ), $content );
105 }
106
107 return $content;
108 }
109
110 /**
111 * Convert randomly chars to htmlentities
112 * This method is partly taken from WordPress
113 * @link http://codex.wordpress.org/Function_Reference/antispambot
114 * @static
115 * @param string $value
116 * @return string
117 */
118 function get_htmlent( $value ) {
119 // check if antispambot WordPress function exists
120 if ( ! function_exists( 'antispambot' ) )
121 return antispambot( $value );
122
123 $enc_value = '';
124 srand( (float) microtime() * 1000000 );
125
126 for ( $i = 0; $i < strlen( $value ); $i = $i + 1 ) {
127 $j = floor( rand( 0, 1 ) );
128
129 if ( $j == 0 ) {
130 $enc_value .= '&#' . ord( substr( $value, $i, 1 ) ).';';
131 } elseif ( $j == 1 ) {
132 $enc_value .= substr( $value, $i, 1 );
133 }
134 }
135
136 $enc_value = str_replace( '@', '&#64;', $enc_value );
137
138 return $enc_value;
139 }
140
141 /**
142 * Callback for encoding email
143 * @param array $match
144 * @return string
145 */
146 function _callback( $match ) {
147 if ( count( $match ) == 2 )
148 return $this->encode( $match[1] );
149
150 return $this->encode( $match[1], $match[2] );
151 }
152
153 /**
154 * Load available methods
155 * @return void
156 */
157 function _load_methods() {
158 $method_dir = dirname(__FILE__) . '/methods';
159 $handle = opendir( $method_dir );
160
161 // dir not found
162 if ( ! $handle )
163 return;
164
165 // include all methods inside the method folder
166 while ( false !== ($file = readdir($handle)) ) {
167 if ( '.php' == substr( $file, -4 ) ) {
168 require_once $method_dir . '/' . $file;
169
170 $name = substr( $file, 0, -4 );
171 $fn = 'lim_email_' . $name;
172
173 if ( function_exists( $fn ) ) {
174 // set method with info
175 $this->methods[$fn] = ( isset( ${ $fn } ) )
176 ? ${ $fn }
177 : array( 'name' => $name, 'description' => $name );
178 }
179 }
180 }
181
182 closedir( $handle );
183 }
184
185 } // end class Lim_Email_Encoder
186
187 /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */