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 / email-encoder-bundle.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
email-encoder-bundle.php
432 lines
1 <?php
2 /*
3 Plugin Name: Email Encoder Bundle
4 Plugin URI: http://www.freelancephp.net/email-encoder-php-class-wp-plugin/
5 Description: Protecting email-spamming by replacing them with one of the registered encoding-methods
6 Author: Victor Villaverde Laan
7 Version: 0.21
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 * Used as prefix for options entry and could be used as text domain (for translations)
23 * @var string
24 */
25 var $domain = 'wp_email_enc';
26
27 /**
28 * @var array
29 */
30 var $options = array(
31 'filter_widgets' => TRUE,
32 'filter_comments' => TRUE,
33 'form_on_site' => FALSE, // set encoder form on the website
34 'powered_by' => TRUE,
35 'encode_tags' => TRUE,
36 'encode_mailtos' => TRUE,
37 'encode_emails' => TRUE,
38 );
39
40 /**
41 * PHP4 constructor
42 */
43 function WP_Email_Encoder() {
44 $this->__construct();
45 }
46
47 /**
48 * PHP5 constructor
49 */
50 function __construct() {
51 parent::__construct();
52
53 // set option values
54 $this->_set_options();
55
56 // load text domain for translations
57 load_plugin_textdomain( $this->domain, dirname( __FILE__ ) . '/lang/', basename( dirname(__FILE__) ) . '/lang/' );
58
59 // add filters
60 add_filter( 'the_content', array( &$this, '_filter_callback' ), 100 );
61
62 // also filter comments
63 if ( $this->options['filter_comments'] )
64 add_filter( 'comment_text', array( &$this, '_filter_callback' ), 100 );
65
66 // also filter widgets
67 if ( $this->options['filter_widgets'] )
68 add_filter( 'widget_text', array( &$this, '_filter_callback' ), 100 );
69
70 // add actions
71 add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
72 add_action( 'admin_init', array( &$this, 'admin_init' ) );
73 add_action( 'the_posts', array( &$this, 'the_posts' ) );
74
75 // set uninstall hook
76 if ( function_exists( 'register_deactivation_hook' ) )
77 register_deactivation_hook( __FILE__, array( &$this, 'deactivation' ));
78 }
79
80 /**
81 * Callback for the_post action
82 * @param array $posts
83 */
84 function the_posts( $posts ) {
85 if ( empty( $posts ) OR ! $this->options['form_on_site'] )
86 return $posts;
87
88 foreach ( $posts as $key => $post ) {
89 if ( stripos( $post->post_content, '[email_encoder_form]' ) > -1 ) {
90 // add style and script for ajax encoder
91 wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ) );
92 // replace tag by form
93 $posts[$key]->post_content = str_replace( '[email_encoder_form]', $this->get_encoder_form(), $post->post_content );
94 break;
95 }
96 }
97
98 return $posts;
99 }
100
101 /**
102 * Callback admin_menu
103 */
104 function admin_menu() {
105 if ( function_exists('add_options_page') AND current_user_can('manage_options') ) {
106 // add options page
107 $page = add_options_page( 'Email Encoder Bundle', 'Email Encoder Bundle',
108 'manage_options', __FILE__, array( &$this, 'options_page' ) );
109
110 // add scripts
111 add_action( 'admin_print_scripts-' . $page, array( &$this, 'admin_print_scripts' ) );
112 }
113 }
114
115 /**
116 * Callback admin_init
117 */
118 function admin_init() {
119 // register settings
120 register_setting( $this->domain, $this->domain . 'options' );
121 }
122
123 /**
124 * Callback admin_print_scripts
125 */
126 function admin_print_scripts() {
127 // add script for ajax encoder
128 wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery-ui-sortable' ) );
129 }
130
131 /**
132 * Admin options page
133 */
134 function options_page() {
135 ?>
136 <div class="wrap">
137 <div class="icon32" id="icon-options-general"><br></div>
138 <h2>Email Encoder Bundle</h2>
139
140 <form method="post" action="options.php">
141 <script language="javascript">
142 var methodInfo = <?php echo json_encode( $this->methods ) ?>;
143 </script>
144 <?php
145 settings_fields( $this->domain );
146 $this->_set_options();
147 $options = $this->options;
148 ?>
149 <div class="postbox-container metabox-holder meta-box-sortables" style="width: 69%">
150 <div class="postbox">
151 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
152 <h3 class="hndle"><?php _e( 'Settings' ) ?></h3>
153 <div class="inside">
154 <fieldset class="options">
155 <table class="form-table">
156 <tr>
157 <th><label for="<?php echo $this->domain ?>options[method]"><?php _e( 'Choose encoding method', $this->domain ) ?></label></th>
158 <td><select id="<?php echo $this->domain ?>options[method]" name="<?php echo $this->domain ?>options[method]" class="method-info-select postform">
159 <?php foreach ( $this->methods AS $method => $info ): ?>
160 <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ] ?></option>
161 <?php endforeach; ?>
162 <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php echo __( 'Random', $this->domain ) ?></option>
163 </select>
164 <br /><span class="description"></span>
165 </td>
166 </tr>
167 <tr>
168 <th><label for="<?php echo $this->domain ?>options[encode_tags]"><?php _e( 'Encode tags', $this->domain ) ?></label></th>
169 <td><input type="checkbox" id="<?php echo $this->domain ?>options[encode_tags]" name="<?php echo $this->domain ?>options[encode_tags]" value="1" <?php checked('1', (int) $options['encode_tags']); ?> /> <span class="description"><?php _e( 'Encode <code>[encode_email]</code> tags', $this->domain ) ?></span></td>
170 </tr>
171 <tr>
172 <th><label for="<?php echo $this->domain ?>options[encode_mailtos]"><?php _e( 'Encode mailto-links', $this->domain ) ?></label></th>
173 <td><input type="checkbox" id="<?php echo $this->domain ?>options[encode_mailtos]" name="<?php echo $this->domain ?>options[encode_mailtos]" value="1" <?php checked('1', (int) $options['encode_mailtos']); ?> /> <span class="description"><?php _e( 'Automatically encode all mailto-links', $this->domain ) ?></span></td>
174 </tr>
175 <tr>
176 <th><label for="<?php echo $this->domain ?>options[encode_emails]"><?php _e( 'Encode plain emails', $this->domain ) ?></label></th>
177 <td><input type="checkbox" id="<?php echo $this->domain ?>options[encode_emails]" name="<?php echo $this->domain ?>options[encode_emails]" value="1" <?php checked('1', (int) $options['encode_emails']); ?> /> <span class="description"><?php _e( 'Replace plain emailaddresses to encoded mailto-links', $this->domain ) ?></span></td>
178 </tr>
179 <tr>
180 <th style="padding-top:25px"><label for="<?php echo $this->domain ?>options[filter_comments]"><?php _e( 'Include comments', $this->domain ) ?></label></th>
181 <td style="padding-top:25px"><input type="checkbox" id="<?php echo $this->domain ?>options[filter_comments]" name="<?php echo $this->domain ?>options[filter_comments]" value="1" <?php checked('1', (int) $options['filter_comments']); ?> /> <span class="description"><?php _e( 'Also filter all comments for encoding', $this->domain ) ?></span></td>
182 </tr>
183 <tr>
184 <th><label for="<?php echo $this->domain ?>options[filter_widgets]"><?php _e( 'Include widgets', $this->domain ) ?></label></th>
185 <td><input type="checkbox" id="<?php echo $this->domain ?>options[filter_widgets]" name="<?php echo $this->domain ?>options[filter_widgets]" value="1" <?php checked('1', (int) $options['filter_widgets']); ?> /> <span class="description"><?php _e( 'Also filter widgets for encoding', $this->domain ) ?></span></td>
186 </tr>
187 </table>
188 </fieldset>
189 <p class="submit">
190 <input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" />
191 </p>
192 </div>
193 </div>
194
195 <div class="postbox">
196 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
197 <h3 class="hndle"><?php _e( 'Email Encoder Form', $this->domain ) ?></h3>
198 <div class="inside">
199 <?php echo $this->get_encoder_form(); ?>
200 </div>
201 </div>
202
203 <div class="postbox">
204 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
205 <h3 class="hndle"><?php _e( 'Settings Email Encoder Form', $this->domain ) ?></h3>
206 <div class="inside">
207 <fieldset class="options">
208 <table class="form-table">
209 <tr>
210 <th><label for="<?php echo $this->domain ?>options[form_on_site]"><?php _e( 'Put form on your site', $this->domain ) ?></label></th>
211 <td><input type="checkbox" id="<?php echo $this->domain ?>options[form_on_site]" name="<?php echo $this->domain ?>options[form_on_site]" value="1" <?php checked('1', (int) $options['form_on_site']); ?> /> <span class="description"><?php _e( 'Put the Email Encode Form (like above) on your site by using this tag in a post or page', $this->domain ) ?></span> <code>[email_encoder_form]</code><span class="description"> (<?php _e( 'turn off for when not used', $this->domain ) ?>)</span></td>
212 </tr>
213 <tr>
214 <th><label for="<?php echo $this->domain ?>options[powered_by]"><?php _e( 'Show "powered by"-link', $this->domain ) ?></label></th>
215 <td><input type="checkbox" id="<?php echo $this->domain ?>options[powered_by]" name="<?php echo $this->domain ?>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->domain ) ?></span></td>
216 </tr>
217 </table>
218 </fieldset>
219 <p class="submit">
220 <input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" />
221 </p>
222 </div>
223 </div>
224 </div>
225
226 <div class="postbox-container side metabox-holder meta-box-sortables" style="width: 29%">
227 <div class="postbox">
228 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
229 <h3 class="hndle"><?php _e( 'How to use', $this->domain ) ?></h3>
230 <div class="inside">
231 <h4><?php _e( 'Tags', $this->domain ) ?></h4>
232 <ul>
233 <li><code>[encode_email email="..." display="..."]</code><br/><span class="description"><?php _e( 'Encode the given email, "display" is optional otherwise the email wil be used as display', $this->domain ) ?></span></li>
234 <li><code>[email_encoder_form]</code><br/><span class="description"><?php _e( 'Puts an email encoder form in your post (check if the option is activated on this page)', $this->domain ) ?></span></li>
235 </ul>
236 <h4><?php _e( 'Template functions' ) ?></h4>
237 <ul>
238 <li><code>&lt;?php echo encode_email( 'info@myemail.com', 'My Email' ); ?&gt;</code><br/><span class="description"><?php _e( 'Encode the given email, the second param is display and optional', $this->domain ) ?></span></li>
239 <li><code>&lt;?php echo encode_email_filter( $content ); ?&gt;</code><br/><span class="description"><?php _e( 'Filter the given content for emails to encode', $this->domain ) ?></span></li>
240 </ul>
241 </div>
242 </div>
243
244 <div class="postbox">
245 <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div>
246 <h3 class="hndle"><?php _e( 'About this plugin', $this->domain ) ?></h3>
247 <div class="inside">
248 <h4>FreelancePHP.net</h4>
249 <ul>
250 <li><a href="http://www.freelancephp.net/email-encoder-php-class-wp-plugin/" target="_blank">WP Email Encoder Bundle</a></li>
251 </ul>
252
253 <h4>WordPress Plugin Directory</h4>
254 <ul>
255 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/" target="_blank"><?php _e( 'Description', $this->domain ) ?></a></li>
256 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/installation/" target="_blank"><?php _e( 'Installation', $this->domain ) ?></a></li>
257 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/faq/" target="_blank"><?php _e( 'FAQ', $this->domain ) ?></a></li>
258 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/screenshots/" target="_blank"><?php _e( 'Screenshot', $this->domain ) ?></a></li>
259 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/other_notes/" target="_blank"><?php _e( 'Other Notes', $this->domain ) ?></a></li>
260 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/changelog/" target="_blank"><?php _e( 'Changelog', $this->domain ) ?></a></li>
261 <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/stats/" target="_blank"><?php _e( 'Stats', $this->domain ) ?></a></li>
262 </ul>
263 </div>
264 </div>
265 </div>
266 </form>
267 <div class="clear"></div>
268 </div>
269 <?php
270 }
271
272 /**
273 * Get the encoder form (to use as a demo, like on the options page)
274 * @return string
275 */
276 function get_encoder_form() {
277 ob_start();
278 ?>
279 <div class="email-encoder-form">
280 <form>
281 <fieldset>
282 <div class="input">
283 <table>
284 <tr>
285 <tr>
286 <th><label for="email"><?php _e( 'Email address', $this->domain ) ?></label></th>
287 <td><input type="text" class="regular-text" id="email" name="email" /></td>
288 </tr>
289 <tr>
290 <th><label for="display"><?php _e( 'Display', $this->domain ) ?></label></th>
291 <td><input type="text" class="regular-text" id="display" name="display" /></td>
292 </tr>
293 <tr>
294 <th><?php _e( 'Example', $this->domain ) ?></th>
295 <td><span id="example"></span></td>
296 </tr>
297 <tr>
298 <th><label for="encode_method"><?php _e( 'Encode method', $this->domain ) ?></label></th>
299 <td><select id="encode_method" name="encode_method" class="postform">
300 <?php foreach ( $this->methods AS $method => $info ): ?>
301 <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ] ?></option>
302 <?php endforeach; ?>
303 <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php _e( 'Random', $this->domain ) ?></option>
304 </select>
305 <input type="button" id="ajax_encode" value="<?php _e( 'Encode', $this->domain ) ?> &gt;&gt;" />
306 </td>
307 </tr>
308 </tr>
309 </table>
310 </div>
311 <div class="output nodis">
312 <table>
313 <tr>
314 <tr>
315 <th><label for="encoded_output"><?php _e( 'Code', $this->domain ) ?></label></th>
316 <td><textarea class="large-text node" id="encoded_output" name="encoded_output"></textarea></td>
317 </tr>
318 </tr>
319 </table>
320 </div>
321 <?php if ( $this->options['powered_by'] ): ?>
322 <p class="powered-by"><?php _e( 'Powered by', $this->domain ) ?> <a rel="external" href="http://www.freelancephp.net/email-encoder-php-class-wp-plugin/">Email Encoder Bundle</a></p>
323 <?php endif; ?>
324 </fieldset>
325 </form>
326 </div>
327 <?php
328 $form = ob_get_contents();
329 ob_clean();
330
331 return $form;
332 }
333
334 /**
335 * Deactivation plugin method
336 */
337 function deactivation() {
338 delete_option( $this->domain . 'options' );
339 unregister_setting( $this->domain, $this->domain . 'options' );
340 }
341
342 /**
343 * Set options from save values or defaults
344 */
345 function _set_options() {
346 // set options
347 $saved_options = get_option( $this->domain . 'options' );
348 if ( empty( $saved_options ) ) {
349 // set defaults
350 $this->options['encode_tags'] = (int) $this->options['encode_tags'];
351 $this->options['encode_mailtos'] = (int) $this->options['encode_mailtos'];
352 $this->options['encode_emails'] = (int) $this->options['encode_emails'];
353 $this->options['filter_comments'] = (int) $this->options['filter_comments'];
354 $this->options['filter_widgets'] = (int) $this->options['filter_widgets'];
355 $this->options['form_on_site'] = (int) $this->options['form_on_site'];
356 $this->options['powered_by'] = (int) $this->options['powered_by'];
357 } else {
358 // set saved option values
359 $this->set_method( $saved_options['method'] );
360 $this->options['encode_tags'] = ! empty( $saved_options['encode_tags'] );
361 $this->options['encode_mailtos'] = ! empty( $saved_options['encode_mailtos'] );
362 $this->options['encode_emails'] = ! empty( $saved_options['encode_emails'] );
363 $this->options['filter_comments'] = ! empty( $saved_options['filter_comments'] );
364 $this->options['filter_widgets'] = ! empty( $saved_options['filter_widgets'] );
365 $this->options['form_on_site'] = ! empty( $saved_options['form_on_site'] );
366 $this->options['powered_by'] = ! empty( $saved_options['powered_by'] );
367 }
368 }
369
370 /**
371 * Callback used for wp filters
372 */
373 function _filter_callback( $content ) {
374 return $this->filter( $content, $this->options[ 'encode_tags' ], $this->options[ 'encode_mailtos' ], $this->options[ 'encode_emails' ] );
375 }
376
377 } // end class WP_Email_Encoder
378
379
380 /**
381 * Create instance
382 */
383 $WP_Email_Encoder = new WP_Email_Encoder;
384
385
386 /**
387 * Ajax Encoding request
388 */
389 if ( ! empty( $_GET['ajax'] ) ):
390 // input vars
391 $method = $_GET['method'];
392 $email = $_GET['email'];
393 $display = ( empty( $_GET['display'] ) ) ? $email : $_GET['display'];
394
395 $WP_Email_Encoder->set_method( $method );
396
397 echo $WP_Email_Encoder->encode( $email, $display );
398 exit;
399 endif;
400
401
402 /**
403 * Template function for encoding email
404 * @global WP_Email_Encoder $WP_Email_Encoder
405 * @param string $email
406 * @param string $display if non given will be same as email
407 * @return string
408 */
409 if ( ! function_exists( 'encode_email' ) ):
410 function encode_email( $email, $display = NULL ) {
411 global $WP_Email_Encoder;
412 return $WP_Email_Encoder->encode( $email, $display );
413 }
414 endif;
415
416 /**
417 * Template function for encoding emails in the given content
418 * @global WP_Email_Encoder $WP_Email_Encoder
419 * @param string $content
420 * @param boolean $enc_tags Optional, default TRUE
421 * @param boolean $enc_plain_emails Optional, default TRUE
422 * @param boolean $enc_mailtos Optional, default TRUE
423 * @return string
424 */
425 if ( ! function_exists( 'encode_email_filter' ) ):
426 function encode_email_filter( $content, $enc_tags = TRUE, $enc_plain_emails = TRUE, $enc_mailtos = TRUE ) {
427 global $WP_Email_Encoder;
428 return $WP_Email_Encoder->filter( $content, $enc_tags, $enc_plain_emails, $enc_mailtos );
429 }
430 endif;
431
432 ?>