PluginProbe ʕ •ᴥ•ʔ
Email Encoder – Protect Email Addresses and Phone Numbers / 0.10
Email Encoder – Protect Email Addresses and Phone Numbers v0.10
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 / email-encoder-bundle.php
email-encoder-bundle Last commit date
js 15 years ago methods 15 years ago GPL-license.txt 15 years ago MIT-license.txt 15 years ago email-encoder-bundle.php 15 years ago lim-email-encoder.php 15 years ago readme.txt 15 years ago screenshot-1.jpg 15 years ago
email-encoder-bundle.php
324 lines
1 <?php
2 /*
3 Plugin Name: Email Encoder Bundle
4 Plugin URI: http://www.freelancephp.net/email-encoder
5 Description: Protecting email-spamming by replacing them with one of the registered encoding-methods
6 Author: Victor Villaverde Laan
7 Version: 0.1
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, child of Lim_Email_Encoder
16 * @package Lim_Email_Encoder
17 * @category WordPress Plugins
18 */
19 class WP_Email_Encoder extends Lim_Email_Encoder {
20
21 /**
22 * Prefix for options entry and being used as text domain (for translations)
23 * @var string
24 */
25 var $prefix = 'wp_esp';
26
27 /**
28 * @var array
29 */
30 var $wp_options = array(
31 'filter_comments' => TRUE,
32 'form_on_site' => FALSE, // set encoder form on the website
33 'powered_by' => TRUE,
34 );
35
36 /**
37 * PHP4 constructor
38 */
39 function WP_Email_Encoder() {
40 $this->__construct();
41 }
42
43 /**
44 * PHP5 constructor
45 */
46 function __construct() {
47 parent::__construct();
48
49 // add all $wp_options to $options
50 $this->options = array_merge( $this->options, $this->wp_options );
51 // set option values
52 $this->_set_options();
53
54 // add filters
55 add_filter( 'the_content', array( &$this, 'encode_filter' ), 100 );
56
57 // also filter comments
58 if ( $this->options['filter_comments'] )
59 add_filter( 'comment_text', array( &$this, 'encode_filter' ), 100 );
60
61 // add actions
62 add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
63 add_action( 'admin_init', array( &$this, 'admin_init' ) );
64
65 if ( $this->options['form_on_site'] )
66 add_action( 'the_posts', array( &$this, 'the_posts' ) );
67
68 // set uninstall hook
69 if ( function_exists( 'register_deactivation_hook' ) )
70 register_deactivation_hook( __FILE__, array( &$this, 'deactivation' ));
71 }
72
73 /**
74 * Callback for the_post action
75 * @param array $posts
76 */
77 function the_posts( $posts ) {
78 if ( empty( $posts ) )
79 return $posts;
80
81 foreach ( $posts as $key => $post ) {
82 if ( stripos( $post->post_content, '[email_encoder_form]' ) > -1 ) {
83 // add style and script for ajax encoder
84 wp_enqueue_script( 'email_encoder', plugins_url( 'js/wp_esp.js', __FILE__ ), array( 'jquery' ) );
85 // replace tag by form
86 $posts[$key]->post_content = str_replace( '[email_encoder_form]', $this->get_encoder_form(), $post->post_content );
87 break;
88 }
89 }
90
91 return $posts;
92 }
93
94 /**
95 * Callback admin_menu
96 */
97 function admin_menu() {
98 if ( function_exists('add_options_page') AND current_user_can('manage_options') ) {
99 // add options page
100 $page = add_options_page( 'Email Encoder Bundle', 'Email Encoder Bundle',
101 'manage_options', __FILE__, array( &$this, 'options_page' ) );
102
103 // add scripts
104 add_action( 'admin_print_scripts-' . $page, array( &$this, 'admin_print_scripts' ) );
105 }
106 }
107
108 /**
109 * Callback admin_init
110 */
111 function admin_init() {
112 // register settings
113 register_setting( $this->prefix, $this->prefix . 'options' );
114 }
115
116 /**
117 * Callback admin_print_scripts
118 */
119 function admin_print_scripts() {
120 // add script for ajax encoder
121 wp_enqueue_script( 'email_encoder', plugins_url( 'js/wp_esp.js', __FILE__ ), array( 'jquery' ) );
122 }
123
124 /**
125 * Admin options page
126 */
127 function options_page() {
128 ?>
129 <div class="wrap">
130 <h2>Email Encoder Bundle</h2>
131
132 <div>
133 <h3>Settings</h3>
134 <form method="post" action="options.php">
135 <?php
136 settings_fields( $this->prefix );
137 $this->_set_options();
138 $options = $this->options;
139 ?>
140 <fieldset class="options">
141 <table class="form-table">
142 <tr>
143 <th><label for="<?php echo $this->prefix ?>options[method]"><?php _e( 'Encoding method', $this->prefix ) ?></label></th>
144 <td><select id="<?php echo $this->prefix ?>options[method]" name="<?php echo $this->prefix ?>options[method]" class="postform">
145 <?php foreach ( $this->methods AS $key => $method ): ?>
146 <option value="<?php echo $key ?>" <?php if ( $options['method'] == $key ) echo 'selected="selected"' ?>><?php _e( $key, $this->prefix ) ?></option>
147 <?php endforeach; ?>
148 <option value="random" <?php if ( $options['method'] == 'random' ) echo 'selected="selected"' ?>><?php _e( 'random', $this->prefix ) ?></option>
149 </select></td>
150 </tr>
151 <tr>
152 <th><label for="<?php echo $this->prefix ?>options[encode_display]"><?php _e( 'Encode email titles (display)', $this->prefix ) ?></label></th>
153 <td><input type="checkbox" id="<?php echo $this->prefix ?>options[encode_display]" name="<?php echo $this->prefix ?>options[encode_display]" value="1" <?php checked('1', (int) $options['encode_display']); ?> /> <span class="description"><?php _e( '(recommended)', $this->prefix ) ?></span></td>
154 </tr>
155 <tr>
156 <th><label for="<?php echo $this->prefix ?>options[encode_mailto]"><?php _e( 'Encode mailto links', $this->prefix ) ?></label></th>
157 <td><input type="checkbox" id="<?php echo $this->prefix ?>options[encode_mailto]" name="<?php echo $this->prefix ?>options[encode_mailto]" value="1" <?php checked('1', (int) $options['encode_mailto']); ?> /> <span class="description"><?php _e( 'encode all mailto links in the content', $this->prefix ) ?></span></td>
158 </tr>
159 <tr>
160 <th><label for="<?php echo $this->prefix ?>options[replace_emails]"><?php _e( 'Replace plain text emails', $this->prefix ) ?></label></th>
161 <td><input type="checkbox" id="<?php echo $this->prefix ?>options[replace_emails]" name="<?php echo $this->prefix ?>options[replace_emails]" value="1" <?php checked('1', (int) $options['replace_emails']); ?> /> <span class="description"><?php _e( 'replacing plain text emails in the content to an encoded mailto link', $this->prefix ) ?></span></td>
162 </tr>
163 <tr>
164 <th><label for="<?php echo $this->prefix ?>options[filter_comments]"><?php _e( 'Also filter comments', $this->prefix ) ?></label></th>
165 <td><input type="checkbox" id="<?php echo $this->prefix ?>options[filter_comments]" name="<?php echo $this->prefix ?>options[filter_comments]" value="1" <?php checked('1', (int) $options['filter_comments']); ?> /> <span class="description"><?php _e( 'also filter all comments for encoding', $this->prefix ) ?></span></td>
166 </tr>
167 <tr>
168 <th style="padding-top:25px"><label for="<?php echo $this->prefix ?>options[form_on_site]"><?php _e( 'Encode form on your site', $this->prefix ) ?></label></th>
169 <td style="padding-top:25px"><input type="checkbox" id="<?php echo $this->prefix ?>options[form_on_site]" name="<?php echo $this->prefix ?>options[form_on_site]" value="1" <?php checked('1', (int) $options['form_on_site']); ?> /> <span class="description"><?php _e( 'put an encode form on your site, use this tag in a post or page:', $this->prefix ) ?></span> <code>[email_encoder_form]</code></td>
170 </tr>
171 <tr>
172 <th><label for="<?php echo $this->prefix ?>options[powered_by]"><?php _e( 'Show powered by link', $this->prefix ) ?></label></th>
173 <td><input type="checkbox" id="<?php echo $this->prefix ?>options[powered_by]" name="<?php echo $this->prefix ?>options[powered_by]" value="1" <?php checked('1', (int) $options['powered_by']); ?> /> <span class="description"><?php _e( 'show the powered by link on bottom of the encode form', $this->prefix ) ?></span></td>
174 </tr>
175 </table>
176 </fieldset>
177 <p class="submit">
178 <input class="button-primary" type="submit" value="<?php _e( 'Save Changes', $this->prefix ) ?>" />
179 </p>
180 </form>
181 </div>
182
183 <div>
184 <h3>How To Use?</h3>
185 <p>Inside a post or page use this code: <code>[encode_email email="info@myemail.com" display="My Email"]</code></p>
186 <p>And for templates use: <code>&lt;?php echo encode_email( 'info@myemail.com', 'My Email' ); ?&gt;</code></p>
187 </div>
188
189 <div>
190 <h3>Encoder Form</h3>
191 <?php echo $this->get_encoder_form(); ?>
192 </div>
193
194 </div>
195 <?php
196 }
197
198 /**
199 * Get the encoder form (to use as a demo, like on the options page)
200 * @return string
201 */
202 function get_encoder_form() {
203 ob_start();
204 ?>
205 <form class="email-encoder-form">
206 <fieldset>
207 <table class="form-table">
208 <tr>
209 <tr>
210 <th><label for="email"><?php _e( 'Email', $this->prefix ) ?></label></th>
211 <td><input type="text" class="regular-text" id="email" name="email" /></td>
212 </tr>
213 <tr>
214 <th><label for="display"><?php _e( 'Display (optional)', $this->prefix ) ?></label></th>
215 <td><input type="text" class="regular-text" id="display" name="display" /></td>
216 </tr>
217 <tr>
218 <th><label for="encode_method"><?php _e( 'Encode method', $this->prefix ) ?></label></th>
219 <td><select id="encode_method" name="encode_method" class="postform">
220 <?php foreach ( $this->methods AS $key => $method ): ?>
221 <option value="<?php echo $key ?>" <?php if ( $this->options['method'] == $key ) echo 'selected="selected"' ?>><?php _e( $key, $this->prefix ) ?></option>
222 <?php endforeach; ?>
223 <option value="random" <?php if ( $this->options['method'] == 'random' ) echo 'selected="selected"' ?>><?php _e( 'random', $this->prefix ) ?></option>
224 </select>
225 <input type="button" id="ajax_encode" value="Encode &gt;" /></td>
226 </tr>
227 </tr>
228 <tr>
229 <tr>
230 <th><?php _e( 'Example', $this->prefix ) ?></th>
231 <td><span id="example"></span></td>
232 </tr>
233 <tr>
234 <th><label for="encoded_output"><?php _e( 'Code', $this->prefix ) ?></label></th>
235 <td><textarea class="large-text node" id="encoded_output" name="encoded_output"></textarea></td>
236 </tr>
237 </tr>
238 </table>
239 <?php if ( $this->options['powered_by'] ): ?>
240 <p class="powered-by">Powered by <a rel="external" href="http://www.freelancephp.net/email-encoder/">Email Encoder Bundle</a></p>
241 <?php endif; ?>
242 </fieldset>
243 </form>
244 <?php
245 $form = ob_get_contents();
246 ob_clean();
247
248 return $form;
249 }
250
251 /**
252 * Deactivation plugin method
253 */
254 function deactivation() {
255 delete_option( $this->prefix . 'options' );
256 unregister_setting( $this->prefix, $this->prefix . 'options' );
257 }
258
259 /**
260 * Set options from save values or defaults
261 */
262 function _set_options() {
263 // set options
264 $saved_options = get_option( $this->prefix . 'options' );
265 if ( empty( $saved_options ) ) {
266 // set defaults
267 $this->options['encode_display'] = (int) $this->options['encode_display'];
268 $this->options['encode_mailto'] = (int) $this->options['encode_mailto'];
269 $this->options['replace_emails'] = (int) $this->options['replace_emails'];
270 $this->options['filter_comments'] = (int) $this->options['filter_comments'];
271 $this->options['form_on_site'] = (int) $this->options['form_on_site'];
272 $this->options['powered_by'] = (int) $this->options['powered_by'];
273 } else {
274 // set saved option values
275 $this->set_method( $saved_options['method'] );
276 $this->options['encode_display'] = ! empty( $saved_options['encode_display'] );
277 $this->options['encode_mailto'] = ! empty( $saved_options['encode_mailto'] );
278 $this->options['replace_emails'] = ! empty( $saved_options['replace_emails'] );
279 $this->options['filter_comments'] = ! empty( $saved_options['filter_comments'] );
280 $this->options['form_on_site'] = ! empty( $saved_options['form_on_site'] );
281 $this->options['powered_by'] = ! empty( $saved_options['powered_by'] );
282 }
283 }
284
285 } // end class WP_Email_Encoder
286
287
288 /**
289 * Create instance
290 */
291 $WP_Email_Encoder = new WP_Email_Encoder;
292
293
294 /**
295 * Ajax request
296 */
297 if ( ! empty( $_GET['ajax'] ) ):
298 // input vars
299 $method = $_GET['method'];
300 $email = $_GET['email'];
301 $display = ( empty( $_GET['display'] ) ) ? $email : $_GET['display'];
302
303 $WP_Email_Encoder->set_method( $method );
304
305 echo $WP_Email_Encoder->encode_email( $email, $display );
306 exit;
307 endif;
308
309
310 /**
311 * Template function for encoding email
312 * @global WP_Email_Encoder $WP_Email_Encoder
313 * @param string $email
314 * @param string $display if non given will be same as email
315 * @return string
316 */
317 if ( ! function_exists( 'encode_email' ) ):
318 function encode_email( $email, $display = NULL ) {
319 global $WP_Email_Encoder;
320 return $WP_Email_Encoder->encode_email( $email, $display );
321 }
322 endif;
323
324 ?>