email-encoder-bundle
Last commit date
images
15 years ago
js
15 years ago
lang
15 years ago
methods
15 years ago
email-encoder-bundle.php
15 years ago
readme.txt
14 years ago
screenshot-1.png
15 years ago
screenshot-2.png
15 years ago
email-encoder-bundle.php
800 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: Protect email addresses on your site from spambots and being used for spamming by using one of the encoding methods. |
| 6 | Author: Victor Villaverde Laan |
| 7 | Version: 0.42 |
| 8 | Author URI: http://www.freelancephp.net |
| 9 | License: Dual licensed under the MIT and GPL licenses |
| 10 | */ |
| 11 | |
| 12 | /** |
| 13 | * Class WP_Email_Encoder_Bundle |
| 14 | * @package WP_Email_Encoder_Bundle |
| 15 | * @category WordPress Plugins |
| 16 | */ |
| 17 | class WP_Email_Encoder_Bundle { |
| 18 | |
| 19 | /** |
| 20 | * Current version |
| 21 | * @var string |
| 22 | */ |
| 23 | var $version = '0.42'; |
| 24 | |
| 25 | /** |
| 26 | * Used as prefix for options entry and could be used as text domain (for translations) |
| 27 | * @var string |
| 28 | */ |
| 29 | var $domain = 'WP_Email_Encoder_Bundle'; |
| 30 | |
| 31 | /** |
| 32 | * Name of the options |
| 33 | * @var string |
| 34 | */ |
| 35 | var $options_name = 'WP_Email_Encoder_Bundle_options'; |
| 36 | |
| 37 | /** |
| 38 | * @var array |
| 39 | */ |
| 40 | var $options = array( |
| 41 | 'method' => 'lim_email_ascii', |
| 42 | 'encode_mailtos' => 1, |
| 43 | 'encode_emails' => 1, |
| 44 | 'class_name' => 'mailto-link', |
| 45 | 'filter_posts' => 1, |
| 46 | 'filter_widgets' => 1, |
| 47 | 'filter_comments' => 1, |
| 48 | 'filter_rss' => 1, |
| 49 | 'widget_logic_filter' => 0, |
| 50 | 'powered_by' => 1, |
| 51 | ); |
| 52 | |
| 53 | /** |
| 54 | * Regexp |
| 55 | * @var array |
| 56 | */ |
| 57 | var $regexp_patterns = array( |
| 58 | 'mailto' => '/<a[^<>]*?href=["\']mailto:(.*?)["\'].*?>(.*?)<\/a[\s+]*>/is', |
| 59 | 'tag' => '/\[encode_email\s+(.*?)\]/is', |
| 60 | 'email' => '/([A-Z0-9._-]+@[A-Z0-9][A-Z0-9.-]{0,61}[A-Z0-9]\.[A-Z.]{2,6})/is', |
| 61 | ); |
| 62 | |
| 63 | /** |
| 64 | * @var array |
| 65 | */ |
| 66 | var $methods = array(); |
| 67 | |
| 68 | /** |
| 69 | * @var string |
| 70 | */ |
| 71 | var $method = NULL; |
| 72 | |
| 73 | |
| 74 | /** |
| 75 | * PHP4 constructor |
| 76 | */ |
| 77 | function WP_Email_Encoder_Bundle() { |
| 78 | $this->__construct(); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * PHP5 constructor |
| 83 | */ |
| 84 | function __construct() { |
| 85 | // include all available method files |
| 86 | $this->_load_methods(); |
| 87 | |
| 88 | // set method |
| 89 | $this->set_method( $this->options[ 'method' ] ); |
| 90 | |
| 91 | // set option values |
| 92 | $this->_set_options(); |
| 93 | |
| 94 | // load text domain for translations |
| 95 | load_plugin_textdomain( $this->domain, FALSE, dirname( plugin_basename( __FILE__ ) ) . '/lang/' ); |
| 96 | |
| 97 | // set uninstall hook |
| 98 | if ( function_exists( 'register_deactivation_hook' ) ) |
| 99 | register_deactivation_hook( __FILE__, array( $this, 'deactivation' )); |
| 100 | |
| 101 | // add actions |
| 102 | add_action( 'admin_menu', array( $this, 'admin_menu' ) ); |
| 103 | add_action( 'admin_init', array( $this, 'admin_init' ) ); |
| 104 | add_action( 'the_posts', array( $this, 'the_posts' ) ); |
| 105 | |
| 106 | // set filters |
| 107 | add_filter( 'pre_get_posts', array( $this, 'pre_get_posts' ), 10 ); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * pre_get_posts filter |
| 112 | * @param object $query |
| 113 | */ |
| 114 | function pre_get_posts( $query ) { |
| 115 | if ( is_admin() ) |
| 116 | return $query; |
| 117 | |
| 118 | $priority = 100; |
| 119 | |
| 120 | if ( $query->is_feed ) { |
| 121 | // rss feed |
| 122 | if ( $this->options[ 'filter_rss' ] ) { |
| 123 | add_filter( 'the_title', array( $this, '_filter_rss_callback' ), $priority ); |
| 124 | add_filter( 'the_content', array( $this, '_filter_rss_callback' ), $priority ); |
| 125 | add_filter( 'the_excerpt', array( $this, '_filter_rss_callback' ), $priority ); |
| 126 | add_filter( 'the_title_rss', array( $this, '_filter_rss_callback' ), $priority ); |
| 127 | add_filter( 'the_content_rss', array( $this, '_filter_rss_callback' ), $priority ); |
| 128 | add_filter( 'the_excerpt_rss', array( $this, '_filter_rss_callback' ), $priority ); |
| 129 | add_filter( 'comment_text_rss', array( $this, '_filter_rss_callback' ), $priority ); |
| 130 | add_filter( 'comment_author_rss ', array( $this, '_filter_rss_callback' ), $priority ); |
| 131 | add_filter( 'the_category_rss ', array( $this, '_filter_rss_callback' ), $priority ); |
| 132 | add_filter( 'the_content_feed', array( $this, '_filter_rss_callback' ), $priority ); |
| 133 | add_filter( 'author feed link', array( $this, '_filter_rss_callback' ), $priority ); |
| 134 | add_filter( 'feed_link', array( $this, '_filter_rss_callback' ), $priority ); |
| 135 | } |
| 136 | } else { |
| 137 | // post content |
| 138 | if ( $this->options[ 'filter_posts' ] ) { |
| 139 | add_filter( 'the_title', array( $this, '_filter_callback' ), $priority ); |
| 140 | add_filter( 'the_content', array( $this, '_filter_callback' ), $priority ); |
| 141 | add_filter( 'the_excerpt', array( $this, '_filter_callback' ), $priority ); |
| 142 | add_filter( 'get_the_excerpt', array( $this, '_filter_callback' ), $priority ); |
| 143 | } |
| 144 | |
| 145 | // comments |
| 146 | if ( $this->options[ 'filter_comments' ] ) { |
| 147 | add_filter( 'comment_text', array( $this, '_filter_callback' ), $priority ); |
| 148 | add_filter( 'comment_excerpt', array( $this, '_filter_callback' ), $priority ); |
| 149 | add_filter( 'comment_url', array( $this, '_filter_callback' ), $priority ); |
| 150 | add_filter( 'get_comment_author_url', array( $this, '_filter_callback' ), $priority ); |
| 151 | add_filter( 'get_comment_author_link', array( $this, '_filter_callback' ), $priority ); |
| 152 | add_filter( 'get_comment_author_url_link', array( $this, '_filter_callback' ), $priority ); |
| 153 | } |
| 154 | |
| 155 | // widgets ( only text widgets ) |
| 156 | if ( $this->options[ 'filter_widgets' ] ) { |
| 157 | add_filter( 'widget_title', array( $this, '_filter_callback' ), $priority ); |
| 158 | add_filter( 'widget_text', array( $this, '_filter_callback' ), $priority ); |
| 159 | |
| 160 | // Only if Widget Logic plugin is installed and 'widget_content' option is activated |
| 161 | add_filter( 'widget_content', array( $this, '_filter_callback' ), $priority ); |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | return $query; |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Callback for the_post action |
| 170 | * @param array $posts |
| 171 | */ |
| 172 | function the_posts( $posts ) { |
| 173 | if ( empty( $posts ) ) |
| 174 | return $posts; |
| 175 | |
| 176 | foreach ( $posts as $key => $post ) { |
| 177 | if ( stripos( $post->post_content, '[email_encoder_form]' ) > -1 ) { |
| 178 | // add style and script for ajax encoder |
| 179 | wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ), $this->version ); |
| 180 | |
| 181 | // replace tag by form |
| 182 | $posts[$key]->post_content = str_replace( '[email_encoder_form]', $this->get_encoder_form(), $post->post_content ); |
| 183 | break; |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | return $posts; |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * Callback admin_menu |
| 192 | */ |
| 193 | function admin_menu() { |
| 194 | if ( function_exists( 'add_options_page' ) AND current_user_can( 'manage_options' ) ) { |
| 195 | // add options page |
| 196 | $page = add_options_page( 'Email Encoder Bundle', 'Email Encoder Bundle', |
| 197 | 'manage_options', __FILE__, array( $this, 'options_page' ) ); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | /** |
| 202 | * Callback admin_init |
| 203 | */ |
| 204 | function admin_init() { |
| 205 | // register settings |
| 206 | register_setting( $this->domain, $this->options_name ); |
| 207 | |
| 208 | // actions |
| 209 | add_action( 'admin_enqueue_scripts', array( $this, 'admin_print_scripts' ) ); |
| 210 | } |
| 211 | |
| 212 | function admin_print_scripts( $hook_suffix ) { |
| 213 | if( $hook_suffix == 'settings_page_email-encoder-bundle/email-encoder-bundle' ) { |
| 214 | // set dashboard postbox |
| 215 | wp_admin_css( 'dashboard' ); |
| 216 | wp_enqueue_script( 'dashboard' ); |
| 217 | |
| 218 | // add style and script for ajax encoder |
| 219 | wp_enqueue_script( 'email_encoder', plugins_url( 'js/email-encoder-bundle.js', __FILE__ ), array( 'jquery' ), $this->version ); |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | /** |
| 224 | * Admin options page |
| 225 | */ |
| 226 | function options_page() { |
| 227 | ?> |
| 228 | <script type="text/javascript"> |
| 229 | jQuery(function( $ ){ |
| 230 | // remove message |
| 231 | $( '.settings-error' ) |
| 232 | .hide() |
| 233 | .slideDown( 600 ) |
| 234 | .delay( 3000 ) |
| 235 | .slideUp( 600 ); |
| 236 | |
| 237 | // set info text for selected encoding method |
| 238 | $( '.method-info-select' ).bind( 'change blur keyup', function(){ |
| 239 | var method = $( this ).val(), |
| 240 | $desc = $( this ).parent().find( 'span.description' ); |
| 241 | |
| 242 | if ( methodInfo && methodInfo[ method ] ) { |
| 243 | $desc.html( methodInfo[ method ][ 'description' ] || '' ); |
| 244 | } else { |
| 245 | $desc.html( '' ); |
| 246 | } |
| 247 | }) |
| 248 | .blur(); |
| 249 | |
| 250 | // "has effect on" |
| 251 | $( 'input#encode_emails' ) |
| 252 | .change(function(){ |
| 253 | if ( $( this ).attr( 'checked' ) ) |
| 254 | $( 'input#encode_mailtos' ).attr( 'checked', true ); |
| 255 | }) |
| 256 | .change(); |
| 257 | |
| 258 | $( 'input#encode_mailtos' ) |
| 259 | .change(function(){ |
| 260 | if ( ! $( this ).attr( 'checked' ) ) |
| 261 | $( 'input#encode_emails' ).attr( 'checked', false ); |
| 262 | }); |
| 263 | |
| 264 | // add form-table class to Encoder Form tables |
| 265 | $( '.email-encoder-form table' ).addClass( 'form-table' ); |
| 266 | |
| 267 | // slide postbox |
| 268 | $( '.postbox' ).find( '.handlediv, .hndle' ).click(function(){ |
| 269 | var $inside = $( this ).parent().find( '.inside' ); |
| 270 | |
| 271 | if ( $inside.css( 'display' ) == 'block' ) { |
| 272 | $inside.css({ display:'block' }).slideUp(); |
| 273 | } else { |
| 274 | $inside.css({ display:'none' }).slideDown(); |
| 275 | } |
| 276 | }); |
| 277 | }); |
| 278 | </script> |
| 279 | <div class="wrap"> |
| 280 | <div class="icon32" id="icon-options-custom" style="background:url( <?php echo plugins_url( 'images/icon-email-encoder-bundle.png', __FILE__ ) ?> ) no-repeat 50% 50%"><br></div> |
| 281 | <h2>Email Encoder Bundle</h2> |
| 282 | |
| 283 | <script type="text/javascript"> |
| 284 | var methodInfo = <?php echo json_encode( $this->methods ) ?>; |
| 285 | </script> |
| 286 | <div class="postbox-container metabox-holder meta-box-sortables" style="width: 69%"> |
| 287 | <div style="margin:0 5px;"> |
| 288 | <div class="postbox"> |
| 289 | <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div> |
| 290 | <h3 class="hndle"><?php _e( 'General Settings' ) ?></h3> |
| 291 | <div class="inside"> |
| 292 | <form method="post" action="options.php"> |
| 293 | <?php |
| 294 | settings_fields( $this->domain ); |
| 295 | $this->_set_options(); |
| 296 | $options = $this->options; |
| 297 | ?> |
| 298 | <?php if ( is_plugin_active( 'wp-mailto-links/wp-mailto-links.php' ) ): ?> |
| 299 | <p class="description"><?php _e( 'Warning: "WP Mailto Links"-plugin is also activated, which could cause conflicts.', $this->domain ) ?></p> |
| 300 | <?php endif; ?> |
| 301 | <fieldset class="options"> |
| 302 | <table class="form-table"> |
| 303 | <tr> |
| 304 | <th><?php _e( 'Choose encoding method', $this->domain ) ?></th> |
| 305 | <td><label><select id="<?php echo $this->options_name ?>[method]" name="<?php echo $this->options_name ?>[method]" class="method-info-select postform"> |
| 306 | <?php foreach ( $this->methods AS $method => $info ): ?> |
| 307 | <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ]; if ( $method == 'lim_email_ascii' ){ echo ' (recommended)'; } ?></option> |
| 308 | <?php endforeach; ?> |
| 309 | <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php echo __( 'Random', $this->domain ) ?></option> |
| 310 | </select> |
| 311 | <br /><span class="description"></span></label> |
| 312 | </td> |
| 313 | </tr> |
| 314 | <tr> |
| 315 | <th><?php _e( 'Encode emails', $this->domain ) ?></th> |
| 316 | <td> |
| 317 | <label><input type="checkbox" name="<?php echo $this->options_name ?>[encode_tags]" value="1" checked="checked" disabled="disabled" /> |
| 318 | <span><?php _e( 'Encode <code>[encode_email]</code> shortcode', $this->domain ) ?></span> |
| 319 | </label> |
| 320 | <br/><label><input type="checkbox" id="encode_mailtos" name="<?php echo $this->options_name ?>[encode_mailtos]" value="1" <?php checked('1', (int) $options['encode_mailtos']); ?> /> |
| 321 | <span><?php _e( 'Automatically encode mailto-links', $this->domain ) ?></span> |
| 322 | </label> |
| 323 | <br/><label><input type="checkbox" id="encode_emails" name="<?php echo $this->options_name ?>[encode_emails]" value="1" <?php checked('1', (int) $options['encode_emails']); ?> /> |
| 324 | <span><?php _e( 'Automatically replace plain emailaddresses to encoded mailto-links', $this->domain ) ?></span> |
| 325 | </label> |
| 326 | </td> |
| 327 | </tr> |
| 328 | <tr> |
| 329 | <th><?php _e( 'Set class for mailto-links', $this->domain ) ?></th> |
| 330 | <td><label><input type="text" id="<?php echo $this->options_name ?>[class_name]" name="<?php echo $this->options_name ?>[class_name]" value="<?php echo $options['class_name']; ?>" /> |
| 331 | <span><?php _e( 'Set class-attribute for encoded mailto links (optional)', $this->domain ) ?></span></label></td> |
| 332 | </tr> |
| 333 | <tr> |
| 334 | <th><?php _e( 'Options has effect on', $this->domain ) ?></th> |
| 335 | <td><label><input type="checkbox" name="<?php echo $this->options_name ?>[filter_posts]" value="1" <?php checked('1', (int) $options['filter_posts']); ?> /> |
| 336 | <span><?php _e( 'All posts', $this->domain ) ?></span> |
| 337 | </label> |
| 338 | <br/><label><input type="checkbox" id="<?php echo $this->options_name ?>[filter_comments]" name="<?php echo $this->options_name ?>[filter_comments]" value="1" <?php checked('1', (int) $options['filter_comments']); ?> /> |
| 339 | <span><?php _e( 'All comments', $this->domain ) ?></span></label> |
| 340 | <br/><label><input type="checkbox" id="<?php echo $this->options_name ?>[filter_widgets]" name="<?php echo $this->options_name ?>[filter_widgets]" value="1" <?php checked('1', (int) $options['filter_widgets']); ?> /> |
| 341 | <span><?php if ( $this->options[ 'widget_logic_filter' ] ) { _e( 'All widgets (uses the <code>widget_content</code> filter of the Widget Logic plugin)', $this->domain ); } else { _e( 'All text widgets', $this->domain ); } ?></span></label> |
| 342 | </td> |
| 343 | </tr> |
| 344 | <tr> |
| 345 | <th><?php _e( 'Protect RSS feed', $this->domain ) ?></th> |
| 346 | <td><label><input type="checkbox" id="<?php echo $this->options_name ?>[filter_rss]" name="<?php echo $this->options_name ?>[filter_rss]" value="1" <?php checked('1', (int) $options['filter_rss']); ?> /> |
| 347 | <span><?php _e( 'Replace emails in RSS feed by <code>*protected email*</code>', $this->domain ) ?></span></label> |
| 348 | </td> |
| 349 | </tr> |
| 350 | </table> |
| 351 | </fieldset> |
| 352 | |
| 353 | <fieldset class="options"> |
| 354 | <table class="form-table"> |
| 355 | <tr> |
| 356 | <th><?php _e( '"Email Encoder Form" settings', $this->domain ) ?></th> |
| 357 | <td><label><input type="checkbox" id="<?php echo $this->options_name ?>[powered_by]" name="<?php echo $this->options_name ?>[powered_by]" value="1" <?php checked('1', (int) $options['powered_by']); ?> /> <span><?php _e( 'Show the "powered by"-link on bottom of the encode form', $this->domain ) ?></span></label></td> |
| 358 | </tr> |
| 359 | </table> |
| 360 | </fieldset> |
| 361 | <p class="submit"> |
| 362 | <input class="button-primary" type="submit" value="<?php _e( 'Save Changes' ) ?>" /> |
| 363 | </p> |
| 364 | </form> |
| 365 | </div> |
| 366 | </div> |
| 367 | |
| 368 | <div class="postbox closed"> |
| 369 | <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div> |
| 370 | <h3 class="hndle"><?php _e( 'How to use', $this->domain ) ?></h3> |
| 371 | <div class="inside"> |
| 372 | <h4><?php _e( 'Tags', $this->domain ) ?></h4> |
| 373 | <ul> |
| 374 | <li><code>[encode_email email="..." display="..." method="..."]</code> <span class="description"><?php _e( 'Encode the given email<br/>"display" is optional otherwise the email wil be used as display<br/>"method" is optional and can be set to use a different method then the options value', $this->domain ) ?></span></li> |
| 375 | <li><code>[email_encoder_form]</code> <span class="description"><?php _e( 'Puts an email encoder form in your post', $this->domain ) ?></span></li> |
| 376 | </ul> |
| 377 | <h4><?php _e( 'Template functions' ) ?></h4> |
| 378 | <ul> |
| 379 | <li><code><?php echo encode_email( 'info@myemail.com', 'My Email' ); ?></code> <span class="description"><?php _e( 'Encode the given email<br/>the second param is $display and optional<br/>the thrid param is $method and optional', $this->domain ) ?></span></li> |
| 380 | <li><code><?php echo encode_email_filter( $content ); ?></code> <span class="description"><?php _e( 'Filter the given content for emails to encode', $this->domain ) ?></span></li> |
| 381 | </ul> |
| 382 | </div> |
| 383 | </div> |
| 384 | |
| 385 | <div class="postbox"> |
| 386 | <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div> |
| 387 | <h3 class="hndle"><?php _e( 'Email Encoder Form', $this->domain ) ?></h3> |
| 388 | <div class="inside"> |
| 389 | <?php echo $this->get_encoder_form(); ?> |
| 390 | </div> |
| 391 | </div> |
| 392 | </div> |
| 393 | </div> |
| 394 | |
| 395 | <div class="postbox-container side metabox-holder meta-box-sortables" style="width:29%;"> |
| 396 | <div style="margin:0 5px;"> |
| 397 | <div class="postbox"> |
| 398 | <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div> |
| 399 | <h3 class="hndle"><?php _e( 'About' ) ?>...</h3> |
| 400 | <div class="inside"> |
| 401 | <h4><img src="<?php echo plugins_url( 'images/icon-email-encoder-bundle.png', __FILE__ ) ?>" width="16" height="16" /> Email Encoder Bundle (v<?php echo $this->version ?>)</h4> |
| 402 | <p><?php _e( 'Protect email addresses on your site from spambots and being used for spamming by using one of the encoding methods.', $this->domain ) ?></p> |
| 403 | <ul> |
| 404 | <li><a href="http://www.freelancephp.net/contact/" target="_blank"><?php _e( 'Questions or suggestions?', $this->domain ) ?></a></li> |
| 405 | <li><?php _e( 'If you like this plugin please send your rating at WordPress.org.' ) ?></li> |
| 406 | <li><a href="http://wordpress.org/extend/plugins/email-encoder-bundle/" target="_blank">WordPress.org</a> | <a href="http://www.freelancephp.net/email-encoder-php-class-wp-plugin/" target="_blank">FreelancePHP.net</a></li> |
| 407 | </ul> |
| 408 | </div> |
| 409 | </div> |
| 410 | |
| 411 | <div class="postbox"> |
| 412 | <div class="handlediv" title="<?php _e( 'Click to toggle' ) ?>"><br/></div> |
| 413 | <h3 class="hndle"><?php _e( 'Other Plugins', $this->domain ) ?></h3> |
| 414 | <div class="inside"> |
| 415 | <h4><img src="<?php echo plugins_url( 'images/icon-wp-external-links.png', __FILE__ ) ?>" width="16" height="16" /> WP External Links</h4> |
| 416 | <p><?php _e( 'Manage external links on your site: open in new window/tab, set icon, add "external", add "nofollow" and more.', $this->domain ) ?></p> |
| 417 | <ul> |
| 418 | <?php if ( is_plugin_active( 'wp-external-links/wp-external-links.php' ) ): ?> |
| 419 | <li><?php _e( 'This plugin is already activated.', $this->domain ) ?> <a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/options-general.php?page=wp-external-links/wp-external-links.php"><?php _e( 'Settings' ) ?></a></li> |
| 420 | <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-external-links/wp-external-links.php' ) ): ?> |
| 421 | <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e( 'Activate this plugin.', $this->domain ) ?></a></li> |
| 422 | <?php else: ?> |
| 423 | <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugin-install.php?tab=search&type=term&s=WP+External+Links+freelancephp&plugin-search-input=Search+Plugins"><?php _e( 'Get this plugin now', $this->domain ) ?></a></li> |
| 424 | <?php endif; ?> |
| 425 | <li><a href="http://wordpress.org/extend/plugins/wp-external-links/" target="_blank">WordPress.org</a> | <a href="http://www.freelancephp.net/wp-external-links-plugin/" target="_blank">FreelancePHP.net</a></li> |
| 426 | </ul> |
| 427 | |
| 428 | <h4><img src="<?php echo plugins_url( 'images/icon-wp-mailto-links.png', __FILE__ ) ?>" width="16" height="16" /> WP Mailto Links</h4> |
| 429 | <p><?php _e( 'Manage mailto links on your site and protect emails from spambots, set mail icon and more.', $this->domain ) ?></p> |
| 430 | <ul> |
| 431 | <?php if ( is_plugin_active( 'wp-mailto-links/wp-mailto-links.php' ) ): ?> |
| 432 | <li><?php _e( 'This plugin is already activated.', $this->domain ) ?> <a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/options-general.php?page=wp-mailto-links/wp-mailto-links.php"><?php _e( 'Settings' ) ?></a></li> |
| 433 | <?php elseif( file_exists( WP_PLUGIN_DIR . '/wp-mailto-links/wp-mailto-links.php' ) ): ?> |
| 434 | <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugins.php?plugin_status=inactive"><?php _e( 'Activate this plugin.', $this->domain ) ?></a></li> |
| 435 | <?php else: ?> |
| 436 | <li><a href="<?php echo get_bloginfo( 'url' ) ?>/wp-admin/plugin-install.php?tab=search&type=term&s=WP+Mailto+Links+freelancephp&plugin-search-input=Search+Plugins"><?php _e( 'Get this plugin now', $this->domain ) ?></a></li> |
| 437 | <?php endif; ?> |
| 438 | <li><a href="http://wordpress.org/extend/plugins/wp-mailto-links/" target="_blank">WordPress.org</a> | <a href="http://www.freelancephp.net/wp-mailto-links-plugin/" target="_blank">FreelancePHP.net</a></li> |
| 439 | </ul> |
| 440 | </div> |
| 441 | </div> |
| 442 | </div> |
| 443 | </div> |
| 444 | <div class="clear"></div> |
| 445 | </div> |
| 446 | <?php |
| 447 | } |
| 448 | |
| 449 | /** |
| 450 | * Get the encoder form (to use as a demo, like on the options page) |
| 451 | * @return string |
| 452 | */ |
| 453 | function get_encoder_form() { |
| 454 | ob_start(); |
| 455 | ?> |
| 456 | <div class="email-encoder-form"> |
| 457 | <form> |
| 458 | <fieldset> |
| 459 | <div class="input"> |
| 460 | <table> |
| 461 | <tr> |
| 462 | <tr> |
| 463 | <th><label for="email"><?php _e( 'Email address', $this->domain ) ?></label></th> |
| 464 | <td><input type="text" class="regular-text" id="email" name="email" /></td> |
| 465 | </tr> |
| 466 | <tr> |
| 467 | <th><label for="display"><?php _e( 'Display', $this->domain ) ?></label></th> |
| 468 | <td><input type="text" class="regular-text" id="display" name="display" /></td> |
| 469 | </tr> |
| 470 | <tr> |
| 471 | <th><?php _e( 'Example', $this->domain ) ?></th> |
| 472 | <td><span id="example"></span></td> |
| 473 | </tr> |
| 474 | <tr> |
| 475 | <th><label for="encode_method"><?php _e( 'Encode method', $this->domain ) ?></label></th> |
| 476 | <td><select id="encode_method" name="encode_method" class="postform"> |
| 477 | <?php foreach ( $this->methods AS $method => $info ): ?> |
| 478 | <option value="<?php echo $method ?>" <?php if ( $this->method == $method ) echo 'selected="selected"' ?>><?php echo $info[ 'name' ] ?></option> |
| 479 | <?php endforeach; ?> |
| 480 | <option value="random" <?php if ( $this->method == 'random' ) echo 'selected="selected"' ?>><?php _e( 'Random', $this->domain ) ?></option> |
| 481 | </select> |
| 482 | <input type="button" id="ajax_encode" value="<?php _e( 'Encode', $this->domain ) ?> >>" /> |
| 483 | </td> |
| 484 | </tr> |
| 485 | </tr> |
| 486 | </table> |
| 487 | </div> |
| 488 | <div class="output nodis"> |
| 489 | <table> |
| 490 | <tr> |
| 491 | <tr> |
| 492 | <th><label for="encoded_output"><?php _e( 'Code', $this->domain ) ?></label></th> |
| 493 | <td><textarea class="large-text node" id="encoded_output" name="encoded_output"></textarea></td> |
| 494 | </tr> |
| 495 | </tr> |
| 496 | </table> |
| 497 | </div> |
| 498 | <?php if ( $this->options['powered_by'] ): ?> |
| 499 | <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> |
| 500 | <?php endif; ?> |
| 501 | </fieldset> |
| 502 | </form> |
| 503 | </div> |
| 504 | <?php |
| 505 | $form = ob_get_contents(); |
| 506 | ob_clean(); |
| 507 | |
| 508 | return $form; |
| 509 | } |
| 510 | |
| 511 | /** |
| 512 | * Encode all emails of the given content |
| 513 | * @param string $content |
| 514 | * @param boolean $enc_tags Optional, default TRUE |
| 515 | * @param boolean $enc_mailtos Optional, default TRUE |
| 516 | * @param boolean $enc_plain_emails Optional, default TRUE |
| 517 | * @return string |
| 518 | */ |
| 519 | function filter( $content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE ) { |
| 520 | // encode mailto links |
| 521 | if ( $enc_mailtos ) |
| 522 | $content = preg_replace_callback( $this->regexp_patterns[ 'mailto' ], array( $this, '_callback' ), $content ); |
| 523 | |
| 524 | // replace content tags [encode_email] to mailto links |
| 525 | if ( $enc_tags ) |
| 526 | $content = preg_replace_callback( $this->regexp_patterns[ 'tag' ], array( $this, '_callback_shortcode' ), $content ); |
| 527 | |
| 528 | // replace plain emails |
| 529 | if ( $enc_plain_emails ) |
| 530 | $content = preg_replace_callback( $this->regexp_patterns[ 'email' ], array( $this, '_callback' ), $content ); |
| 531 | |
| 532 | return $content; |
| 533 | } |
| 534 | |
| 535 | /** |
| 536 | * Deactivation plugin method |
| 537 | */ |
| 538 | function deactivation() { |
| 539 | delete_option( $this->options_name ); |
| 540 | unregister_setting( $this->domain, $this->options_name ); |
| 541 | } |
| 542 | |
| 543 | /** |
| 544 | * Set options from save values or defaults |
| 545 | */ |
| 546 | function _set_options() { |
| 547 | // set options |
| 548 | $saved_options = get_option( $this->options_name ); |
| 549 | |
| 550 | // backwards compatible (old values) |
| 551 | if ( empty( $saved_options ) ) { |
| 552 | $saved_options = get_option( $this->domain . 'options' ); |
| 553 | } |
| 554 | // upgrade to 0.40 |
| 555 | if ( ! isset( $saved_options[ 'class_name' ] ) ) { |
| 556 | // set default |
| 557 | $saved_options[ 'class_name' ] = $this->options[ 'class_name' ]; |
| 558 | $saved_options[ 'filter_posts' ] = $this->options[ 'filter_posts' ]; |
| 559 | } |
| 560 | |
| 561 | // set all options |
| 562 | if ( ! empty( $saved_options ) ) { |
| 563 | foreach ( $this->options AS $key => $option ) { |
| 564 | $this->options[ $key ] = ( empty( $saved_options[ $key ] ) ) ? '' : $saved_options[ $key ]; |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | // set encode method |
| 569 | $this->set_method( $this->options['method'] ); |
| 570 | |
| 571 | // set widget_content filter of Widget Logic plugin |
| 572 | $widget_logic_opts = get_option( 'widget_logic' ); |
| 573 | if ( is_array( $widget_logic_opts ) AND key_exists( 'widget_logic-options-filter', $widget_logic_opts ) ) { |
| 574 | $this->options[ 'widget_logic_filter' ] = ( $widget_logic_opts[ 'widget_logic-options-filter' ] == 'checked' ) ? 1 : 0; |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | /** |
| 579 | * Callback for encoding email |
| 580 | * @param array $match |
| 581 | * @return string |
| 582 | */ |
| 583 | function _callback( $match ) { |
| 584 | if ( count( $match ) == 2 ) |
| 585 | return $this->encode( $match[1] ); |
| 586 | |
| 587 | return $this->encode( $match[1], $match[2] ); |
| 588 | } |
| 589 | |
| 590 | /** |
| 591 | * Callback shortcode [encode_email ... ] for encoding email |
| 592 | * @param array $match |
| 593 | * @return string |
| 594 | */ |
| 595 | function _callback_shortcode( $match ) { |
| 596 | $attrs = shortcode_parse_atts( $match[1] ); |
| 597 | |
| 598 | if ( ! key_exists( 'email', $attrs ) ) |
| 599 | return ''; |
| 600 | |
| 601 | $email = $attrs[ 'email' ]; |
| 602 | $display = ( key_exists( 'display', $attrs ) ) ? $attrs[ 'display' ] : $attrs[ 'email' ]; |
| 603 | $method = ( key_exists( 'method', $attrs ) ) ? $attrs[ 'method' ] : NULL; |
| 604 | |
| 605 | return $this->encode( $email, $display, $method ); |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * Callback used for wp filters |
| 610 | */ |
| 611 | function _filter_callback( $content ) { |
| 612 | return $this->filter( $content, TRUE, $this->options[ 'encode_mailtos' ], $this->options[ 'encode_emails' ] ); |
| 613 | } |
| 614 | |
| 615 | /** |
| 616 | * Callback RSS |
| 617 | */ |
| 618 | function _filter_rss_callback( $content ) { |
| 619 | return preg_replace( $this->regexp_patterns, '*protected email*', $content ); |
| 620 | } |
| 621 | |
| 622 | |
| 623 | /** |
| 624 | * Lim_Email_Encoder Class integrated |
| 625 | */ |
| 626 | |
| 627 | /** |
| 628 | * Set the encode method to use |
| 629 | * @param string $method can be the name of the method or 'random' |
| 630 | * @return $this |
| 631 | */ |
| 632 | function set_method( $method ) { |
| 633 | $this->method = $this->_get_method( $method ); |
| 634 | |
| 635 | return $this; |
| 636 | } |
| 637 | |
| 638 | /** |
| 639 | * Encode the given email into an encoded HTML link |
| 640 | * @param string $email |
| 641 | * @param string $display Optional, if not set display will be the email |
| 642 | * @param string $method Optional, else the default setted method will; be used |
| 643 | * @return string |
| 644 | */ |
| 645 | function encode( $email, $display = NULL, $method = NULL ) { |
| 646 | // decode entities |
| 647 | $email = html_entity_decode( $email ); |
| 648 | |
| 649 | // set email as display |
| 650 | if ( $display === NULL ) |
| 651 | $display = $email; |
| 652 | |
| 653 | // set encode method |
| 654 | if ( $method === NULL ) { |
| 655 | $method = $this->method; |
| 656 | } else { |
| 657 | $method = $this->_get_method( $method ); |
| 658 | } |
| 659 | |
| 660 | // get encoded email code |
| 661 | return call_user_func( $method, $email, $display, $this ); |
| 662 | } |
| 663 | |
| 664 | /** |
| 665 | * Convert randomly chars to htmlentities |
| 666 | * This method is partly taken from WordPress |
| 667 | * @link http://codex.wordpress.org/Function_Reference/antispambot |
| 668 | * @static |
| 669 | * @param string $value |
| 670 | * @return string |
| 671 | */ |
| 672 | function get_htmlent( $value ) { |
| 673 | // check if antispambot WordPress function exists |
| 674 | if ( function_exists( 'antispambot' ) ) { |
| 675 | $enc_value = antispambot( $value ); |
| 676 | } else { |
| 677 | $enc_value = ''; |
| 678 | srand( (float) microtime() * 1000000 ); |
| 679 | |
| 680 | for ( $i = 0; $i < strlen( $value ); $i = $i + 1 ) { |
| 681 | $j = floor( rand( 0, 1 ) ); |
| 682 | |
| 683 | if ( $j == 0 ) { |
| 684 | $enc_value .= '&#' . ord( substr( $value, $i, 1 ) ).';'; |
| 685 | } elseif ( $j == 1 ) { |
| 686 | $enc_value .= substr( $value, $i, 1 ); |
| 687 | } |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | $enc_value = str_replace( '@', '@', $enc_value ); |
| 692 | |
| 693 | return $enc_value; |
| 694 | } |
| 695 | |
| 696 | /** |
| 697 | * Load available methods |
| 698 | * @return void |
| 699 | */ |
| 700 | function _load_methods() { |
| 701 | $method_dir = dirname(__FILE__) . '/methods'; |
| 702 | $handle = opendir( $method_dir ); |
| 703 | |
| 704 | // dir not found |
| 705 | if ( ! $handle ) |
| 706 | return; |
| 707 | |
| 708 | // include all methods inside the method folder |
| 709 | while ( false !== ($file = readdir($handle)) ) { |
| 710 | if ( '.php' == substr( $file, -4 ) ) { |
| 711 | require_once $method_dir . '/' . $file; |
| 712 | |
| 713 | $name = substr( $file, 0, -4 ); |
| 714 | $fn = 'lim_email_' . $name; |
| 715 | |
| 716 | if ( function_exists( $fn ) ) { |
| 717 | // set method with info |
| 718 | $this->methods[$fn] = ( isset( ${ $fn } ) ) |
| 719 | ? ${ $fn } |
| 720 | : array( 'name' => $name, 'description' => $name ); |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | closedir( $handle ); |
| 726 | } |
| 727 | |
| 728 | function _get_method( $method ) { |
| 729 | $method = strtolower( $method ); |
| 730 | |
| 731 | if ( 'random' == $method ) { |
| 732 | // set a random method |
| 733 | $method = array_rand( $this->methods ); |
| 734 | } else { |
| 735 | // add 'lim_email_' prefix if not already set |
| 736 | $method = ( strpos( $method, 'lim_email_' ) !== FALSE ) ? $method : 'lim_email_' . $method; |
| 737 | |
| 738 | if ( ! key_exists( $method, $this->methods ) ) |
| 739 | $method = 'lim_email_html_encode'; // set default method |
| 740 | } |
| 741 | |
| 742 | return $method; |
| 743 | } |
| 744 | |
| 745 | |
| 746 | } // end class WP_Email_Encoder_Bundle |
| 747 | |
| 748 | |
| 749 | /** |
| 750 | * Create instance |
| 751 | */ |
| 752 | $WP_Email_Encoder_Bundle = new WP_Email_Encoder_Bundle; |
| 753 | |
| 754 | |
| 755 | /** |
| 756 | * Ajax Encoding request |
| 757 | */ |
| 758 | if ( ! empty( $_GET['ajax'] ) ): |
| 759 | // input vars |
| 760 | $method = $_GET['method']; |
| 761 | $email = $_GET['email']; |
| 762 | $display = ( empty( $_GET['display'] ) ) ? $email : $_GET['display']; |
| 763 | |
| 764 | echo $WP_Email_Encoder_Bundle->encode( $email, $display, $method ); |
| 765 | exit; |
| 766 | endif; |
| 767 | |
| 768 | |
| 769 | /** |
| 770 | * Template function for encoding email |
| 771 | * @global WP_Email_Encoder $WP_Email_Encoder_Bundle |
| 772 | * @param string $email |
| 773 | * @param string $display if non given will be same as email |
| 774 | * @param string $method Optional, else the default setted method will; be used |
| 775 | * @return string |
| 776 | */ |
| 777 | if ( ! function_exists( 'encode_email' ) ): |
| 778 | function encode_email( $email, $display = NULL, $method = NULL ) { |
| 779 | global $WP_Email_Encoder_Bundle; |
| 780 | return $WP_Email_Encoder_Bundle->encode( $email, $display, $method ); |
| 781 | } |
| 782 | endif; |
| 783 | |
| 784 | /** |
| 785 | * Template function for encoding emails in the given content |
| 786 | * @global WP_Email_Encoder $WP_Email_Encoder_Bundle |
| 787 | * @param string $content |
| 788 | * @param boolean $enc_tags Optional, default TRUE |
| 789 | * @param boolean $enc_mailtos Optional, default TRUE |
| 790 | * @param boolean $enc_plain_emails Optional, default TRUE |
| 791 | * @return string |
| 792 | */ |
| 793 | if ( ! function_exists( 'encode_email_filter' ) ): |
| 794 | function encode_email_filter( $content, $enc_tags = TRUE, $enc_mailtos = TRUE, $enc_plain_emails = TRUE ) { |
| 795 | global $WP_Email_Encoder_Bundle; |
| 796 | return $WP_Email_Encoder_Bundle->filter( $content, $enc_tags, $enc_mailtos, $enc_plain_emails ); |
| 797 | } |
| 798 | endif; |
| 799 | |
| 800 | /*?> // ommit closing tag, to prevent unwanted whitespace at the end of the parts generated by the included files */ |