PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 0.31
Email Encoder – Protect Email Addresses and Phone Numbers v0.31
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
148 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.22
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 // decode entities
72 $email = html_entity_decode( $email );
73
74 // set email as display
75 if ( $display === NULL )
76 $display = $email;
77
78 // get encoded email code
79 return call_user_func( $this->method, $email, $display );
80 }
81
82 /**
83 * Convert randomly chars to htmlentities
84 * This method is partly taken from WordPress
85 * @link http://codex.wordpress.org/Function_Reference/antispambot
86 * @static
87 * @param string $value
88 * @return string
89 */
90 function get_htmlent( $value ) {
91 // check if antispambot WordPress function exists
92 if ( function_exists( 'antispambot' ) ) {
93 $enc_value = antispambot( $value );
94 } else {
95 $enc_value = '';
96 srand( (float) microtime() * 1000000 );
97
98 for ( $i = 0; $i < strlen( $value ); $i = $i + 1 ) {
99 $j = floor( rand( 0, 1 ) );
100
101 if ( $j == 0 ) {
102 $enc_value .= '&#' . ord( substr( $value, $i, 1 ) ).';';
103 } elseif ( $j == 1 ) {
104 $enc_value .= substr( $value, $i, 1 );
105 }
106 }
107 }
108
109 $enc_value = str_replace( '@', '&#64;', $enc_value );
110
111 return $enc_value;
112 }
113
114 /**
115 * Load available methods
116 * @return void
117 */
118 function _load_methods() {
119 $method_dir = dirname(__FILE__) . '/methods';
120 $handle = opendir( $method_dir );
121
122 // dir not found
123 if ( ! $handle )
124 return;
125
126 // include all methods inside the method folder
127 while ( false !== ($file = readdir($handle)) ) {
128 if ( '.php' == substr( $file, -4 ) ) {
129 require_once $method_dir . '/' . $file;
130
131 $name = substr( $file, 0, -4 );
132 $fn = 'lim_email_' . $name;
133
134 if ( function_exists( $fn ) ) {
135 // set method with info
136 $this->methods[$fn] = ( isset( ${ $fn } ) )
137 ? ${ $fn }
138 : array( 'name' => $name, 'description' => $name );
139 }
140 }
141 }
142
143 closedir( $handle );
144 }
145
146 } // end class Lim_Email_Encoder
147
148 /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */