PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 0.32
Email Encoder – Protect Email Addresses and Phone Numbers v0.32
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
images 15 years ago js 15 years ago lang 15 years ago methods 15 years ago Lim_Email_Encoder.php 15 years ago email-encoder-bundle.php 15 years ago readme.txt 15 years ago screenshot-1.png 15 years ago screenshot-2.png 15 years ago
Lim_Email_Encoder.php
164 lines
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 */