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 / 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
427 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.2
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 all tags like', $this->domain ) ?></span> <code>[encode_email email="info@myemail.com" display="My Email"]</code></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( 'Also encode 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( 'Replacing plain text emails to an encoded mailto link', $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( '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 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( 'Encode 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 an 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 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 <form class="email-encoder-form">
280 <fieldset>
281 <table class="form-table">
282 <tr>
283 <tr>
284 <th><label for="email"><?php _e( 'Email', $this->domain ) ?></label></th>
285 <td><input type="text" class="regular-text" id="email" name="email" /></td>
286 </tr>
287 <tr>
288 <th><label for="display"><?php _e( 'Display (optional)', $this->domain ) ?></label></th>
289 <td><input type="text" class="regular-text" id="display" name="display" /></td>
290 </tr>
291 <tr>
292 <th><label for="encode_method"><?php _e( 'Encode method', $this->domain ) ?></label></th>
293 <td><select id="encode_method" name="encode_method" class="postform">
294 <?php foreach ( $this->methods AS $method => $info ): ?>
295 <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ] ?></option>
296 <?php endforeach; ?>
297 <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php _e( 'Random', $this->domain ) ?></option>
298 </select>
299 <input type="button" id="ajax_encode" value="<?php _e( 'Encode', $this->domain ) ?> &gt;&gt;" />
300 </td>
301 </tr>
302 </tr>
303 </table>
304 <hr />
305 <table class="form-table">
306 <tr>
307 <tr>
308 <th><?php _e( 'Link', $this->domain ) ?></th>
309 <td><span id="example"></span></td>
310 </tr>
311 <tr>
312 <th><label for="encoded_output"><?php _e( 'Code', $this->domain ) ?></label></th>
313 <td><textarea class="large-text node" id="encoded_output" name="encoded_output"></textarea></td>
314 </tr>
315 </tr>
316 </table>
317 <?php if ( $this->options['powered_by'] ): ?>
318 <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>
319 <?php endif; ?>
320 </fieldset>
321 </form>
322 <?php
323 $form = ob_get_contents();
324 ob_clean();
325
326 return $form;
327 }
328
329 /**
330 * Deactivation plugin method
331 */
332 function deactivation() {
333 delete_option( $this->domain . 'options' );
334 unregister_setting( $this->domain, $this->domain . 'options' );
335 }
336
337 /**
338 * Set options from save values or defaults
339 */
340 function _set_options() {
341 // set options
342 $saved_options = get_option( $this->domain . 'options' );
343 if ( empty( $saved_options ) ) {
344 // set defaults
345 $this->options['encode_tags'] = (int) $this->options['encode_tags'];
346 $this->options['encode_mailtos'] = (int) $this->options['encode_mailtos'];
347 $this->options['encode_emails'] = (int) $this->options['encode_emails'];
348 $this->options['filter_comments'] = (int) $this->options['filter_comments'];
349 $this->options['filter_widgets'] = (int) $this->options['filter_widgets'];
350 $this->options['form_on_site'] = (int) $this->options['form_on_site'];
351 $this->options['powered_by'] = (int) $this->options['powered_by'];
352 } else {
353 // set saved option values
354 $this->set_method( $saved_options['method'] );
355 $this->options['encode_tags'] = ! empty( $saved_options['encode_tags'] );
356 $this->options['encode_mailtos'] = ! empty( $saved_options['encode_mailtos'] );
357 $this->options['encode_emails'] = ! empty( $saved_options['encode_emails'] );
358 $this->options['filter_comments'] = ! empty( $saved_options['filter_comments'] );
359 $this->options['filter_widgets'] = ! empty( $saved_options['filter_widgets'] );
360 $this->options['form_on_site'] = ! empty( $saved_options['form_on_site'] );
361 $this->options['powered_by'] = ! empty( $saved_options['powered_by'] );
362 }
363 }
364
365 /**
366 * Callback used for wp filters
367 */
368 function _filter_callback( $content ) {
369 return $this->filter( $content, $this->options[ 'encode_tags' ], $this->options[ 'encode_mailtos' ], $this->options[ 'encode_emails' ] );
370 }
371
372 } // end class WP_Email_Encoder
373
374
375 /**
376 * Create instance
377 */
378 $WP_Email_Encoder = new WP_Email_Encoder;
379
380
381 /**
382 * Ajax Encoding request
383 */
384 if ( ! empty( $_GET['ajax'] ) ):
385 // input vars
386 $method = $_GET['method'];
387 $email = $_GET['email'];
388 $display = ( empty( $_GET['display'] ) ) ? $email : $_GET['display'];
389
390 $WP_Email_Encoder->set_method( $method );
391
392 echo $WP_Email_Encoder->encode( $email, $display );
393 exit;
394 endif;
395
396
397 /**
398 * Template function for encoding email
399 * @global WP_Email_Encoder $WP_Email_Encoder
400 * @param string $email
401 * @param string $display if non given will be same as email
402 * @return string
403 */
404 if ( ! function_exists( 'encode_email' ) ):
405 function encode_email( $email, $display = NULL ) {
406 global $WP_Email_Encoder;
407 return $WP_Email_Encoder->encode( $email, $display );
408 }
409 endif;
410
411 /**
412 * Template function for encoding emails in the given content
413 * @global WP_Email_Encoder $WP_Email_Encoder
414 * @param string $content
415 * @param boolean $enc_tags Optional, default TRUE
416 * @param boolean $enc_plain_emails Optional, default TRUE
417 * @param boolean $enc_mailtos Optional, default TRUE
418 * @return string
419 */
420 if ( ! function_exists( 'encode_email_filter' ) ):
421 function encode_email_filter( $content, $enc_tags = TRUE, $enc_plain_emails = TRUE, $enc_mailtos = TRUE ) {
422 global $WP_Email_Encoder;
423 return $WP_Email_Encoder->filter( $content, $enc_tags, $enc_plain_emails, $enc_mailtos );
424 }
425 endif;
426
427 ?>