PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 0.20
Email Encoder – Protect Email Addresses and Phone Numbers v0.20
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
185 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.2
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 } else if ( ! key_exists( $method, $this->methods ) ) {
54 // set default method
55 $this->method = 'lim_email_html_encode';
56 } else {
57 $this->method = $method;
58 }
59
60 return $this;
61 }
62
63 /**
64 * Encode the given email into an encoded HTML link
65 * @param string $email
66 * @param string $display Optional, if not set display will be the email
67 * @return string
68 */
69 function encode( $email, $display = NULL ) {
70 if ( $display === NULL )
71 $display = $email;
72
73 // get encoded email code
74 return call_user_func( $this->method, $email, $display );
75 }
76
77 /**
78 * Encode all emails of the given content
79 * @param string $content
80 * @param boolean $enc_tags Optional, default TRUE
81 * @param boolean $enc_plain_emails Optional, default TRUE
82 * @param boolean $enc_mailtos Optional, default TRUE
83 * @return string
84 */
85 function filter( $content, $enc_tags = TRUE, $enc_plain_emails = TRUE, $enc_mailtos = TRUE ) {
86 // encode mailto links
87 if ( $enc_mailtos ) {
88 $mailto_pattern = '/<a.*?href=["\']mailto:(.*?)["\'].*?>(.*?)<\/a>/i';
89 $content = preg_replace_callback( $mailto_pattern, array( $this, '_callback' ), $content );
90 }
91
92 // replace content tags [encode_email email="?" display="?"] to mailto links
93 // this code is partly taken from the plugin "Fay Emails Encoder"
94 // Credits goes to Faycal Tirich (http://faycaltirich.blogspot.com)
95 if ( $enc_tags ) {
96 $tag_pattern = '/\[encode_email\s+email=["\'](.*?)["\']\s+display=["\'](.*?)["\']]/i';
97 $content = preg_replace_callback( $tag_pattern, array( $this, '_callback' ), $content );
98 }
99
100 // replace plain emails
101 if ( $enc_plain_emails ) {
102 $email_pattern = '/([A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6})/i';
103 $content = preg_replace_callback( $email_pattern, array( $this, '_callback' ), $content );
104 }
105
106 return $content;
107 }
108
109 /**
110 * Convert randomly chars to htmlentities
111 * This method is partly taken from WordPress
112 * @link http://codex.wordpress.org/Function_Reference/antispambot
113 * @static
114 * @param string $value
115 * @return string
116 */
117 function get_htmlent( $value ) {
118 // check if antispambot WordPress function exists
119 if ( ! function_exists( 'antispambot' ) )
120 return antispambot( $value );
121
122 $enc_value = '';
123 srand( (float) microtime() * 1000000 );
124
125 for ( $i = 0; $i < strlen( $value ); $i = $i + 1 ) {
126 $j = floor( rand( 0, 1 ) );
127
128 if ( $j == 0 ) {
129 $enc_value .= '&#' . ord( substr( $value, $i, 1 ) ).';';
130 } elseif ( $j == 1 ) {
131 $enc_value .= substr( $value, $i, 1 );
132 }
133 }
134
135 $enc_value = str_replace( '@', '&#64;', $enc_value );
136
137 return $enc_value;
138 }
139
140 /**
141 * Callback for encoding email
142 * @param array $match
143 * @return string
144 */
145 function _callback( $match ) {
146 if ( count( $match ) == 2 )
147 return $this->encode( $match[1] );
148
149 return $this->encode( $match[1], $match[2] );
150 }
151
152 /**
153 * Load available methods
154 * @return void
155 */
156 function _load_methods() {
157 $method_dir = dirname(__FILE__) . '/methods';
158 $handle = opendir( $method_dir );
159
160 // dir not found
161 if ( ! $handle )
162 return;
163
164 // include all methods inside the method folder
165 while ( false !== ($file = readdir($handle)) ) {
166 if ( '.php' == substr( $file, -4 ) ) {
167 require_once $method_dir . '/' . $file;
168
169 $fn = 'lim_email_' . substr( $file, 0, -4 );
170
171 if ( function_exists( $fn ) ) {
172 // set method with info
173 $this->methods[$fn] = ( isset( ${ $fn } ) )
174 ? ${ $fn }
175 : array( 'name' => NULL, 'description' => NULL );
176 }
177 }
178 }
179
180 closedir( $handle );
181 }
182
183 } // end class Lim_Email_Encoder
184
185 /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */