escape.php
37 lines
| 1 | <?php |
| 2 | if ( ! function_exists( 'lim_email_escape' ) ): |
| 3 | |
| 4 | // Info (optional) |
| 5 | $lim_email_escape = array( |
| 6 | 'name' => 'JavaScript Escape', |
| 7 | 'description' => 'Uses javascript eval() function (<a href="http://blueberryware.net/2008/09/14/email-spam-protection/" target="_blank">original source</a>).', |
| 8 | ); |
| 9 | |
| 10 | /** |
| 11 | * lim_email_escape() |
| 12 | * Taken from the plugin "Email Spam Protection" by Adam Hunter (http://blueberryware.net/2008/09/14/email-spam-protection/) |
| 13 | * |
| 14 | * @package WP_Email_Encoder_Bundle |
| 15 | * @param string $email the email to encode |
| 16 | * @param string $display the display showing on the page |
| 17 | * @param string $obj WP_Email_Encoder_Bundle object |
| 18 | * @return string |
| 19 | */ |
| 20 | function lim_email_escape( $email, $display, $obj ) { |
| 21 | $string = 'document.write(\'<a class="'. $obj->options[ 'class_name' ] .'" href="mailto:' . $email . '">' . $display . '</a>\')'; |
| 22 | /* break string into array of characters, we can't use string_split because its php5 only :( */ |
| 23 | $split = preg_split('||', $string); |
| 24 | $out = '<script type="text/javascript">/*<![CDATA[*/ ' . "eval(unescape('"; |
| 25 | foreach ( $split as $c ) { |
| 26 | /* preg split will return empty first and last characters, check for them and ignore */ |
| 27 | if ( !empty($c) ) { |
| 28 | $out .= '%' . dechex(ord($c)); |
| 29 | } |
| 30 | } |
| 31 | $out .= "'))" . '/*]]>*/</script><noscript>*protected email*</noscript>'; |
| 32 | return $out; |
| 33 | } |
| 34 | |
| 35 | endif; |
| 36 | |
| 37 | /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */ |