WordPress.org

Plugin Directory

Changeset 759528


Ignore:
Timestamp:
08/20/13 20:53:37 (8 months ago)
Author:
joedolson
Message:

Update trunk.

Location:
botsmasher/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • botsmasher/trunk/botsmasher.php

    r756856 r759528  
    44Plugin URI: http://www.joedolson.com/articles/botsmasher/ 
    55Description: BotSmasher smashes bots.  
    6 Version: 1.0.3 
     6Version: 1.0.4 
    77Author: Joe Dolson 
    88Author URI: http://www.joedolson.com/ 
     
    3535 
    3636$bs_api_url = 'https://www.botsmasher.com/api/index.php'; 
    37 $bs_version = '1.0.3';  
     37$bs_version = '1.0.4';  
    3838 
    3939if ( !class_exists('botsmasherClient') ) { 
     
    158158            $bs_filter_comments = ( isset( $_POST['bs_filter_comments'] ) )?'on':''; 
    159159            $bs_filter_registrations = ( isset( $_POST['bs_filter_registrations'] ) )?'on':''; 
    160             $options = array_merge( $opts, array( 'bs_api_key'=> $bs_api_key, 'bs_required_label'=>$bs_required_label, 'bs_html_email', $bs_html_email, 'bs_filter_comments'=>$bs_filter_comments, 'bs_filter_registrations'=>$bs_filter_registrations ) ); 
     160            $options = array_merge( $opts, array( 'bs_api_key'=> $bs_api_key, 'bs_required_label'=>$bs_required_label, 'bs_html_email'=>$bs_html_email, 'bs_filter_comments'=>$bs_filter_comments, 'bs_filter_registrations'=>$bs_filter_registrations ) ); 
    161161            update_option( 'bs_options', $options ); 
    162162             
     
    293293                <h3><?php _e('Your API Usage','botsmasher'); ?></h3> 
    294294                <?php 
    295                     $day_count = "<strong>".$bs_options['bs_daily_api_queries']."</strong>"; 
     295                    $day_count = $bs_options['bs_daily_api_queries']; 
    296296                    $total_count = "<strong>".( $bs_options['bs_total_api_queries'] + $day_count )."</strong>"; 
     297                    $day_count = ( $day_count != '' )?"<strong>$day_count</strong>":"<strong>0</strong>"; 
    297298                    $thwart_count = "<strong>".$bs_options['bs_total_thwarts']."</strong>"; 
    298299                ?> 
  • botsmasher/trunk/bs-contacts.php

    r756856 r759528  
    1616        ), $atts) ); 
    1717        $template = $content;  
    18     return bs_contact_form( $recipient, $submit, $fields, $labels, $required, $subject, $thanks, $template ); 
     18    return bs_contact_form( $recipient, $submit, $fields, $labels, $required, $subject, $thanks, $template, $recipientname ); 
    1919} 
    2020 
     
    2929} 
    3030 
    31 function bs_contact_form( $recipient, $submit, $fields, $labels, $required, $subject, $thanks, $template ) { 
     31function bs_contact_form( $recipient, $submit, $fields, $labels, $required, $subject, $thanks, $template, $recipientname ) { 
    3232    $return = $status = ''; 
    3333    $errors = array(); 
     
    4444    $return = bs_submit_form( $_POST, $recipient, $fields, $labels, $required, $subject, $thanks, $template ); 
    4545    $message = $return['message']; 
    46     $message = ( $message ) ? "<p class='bs-notice'>$message</p>" : ''; 
     46    $message = ( $message ) ? "<div class='bs-notice'>$message</div>" : ''; 
    4747    $hash = md5( $recipient.$fields.$labels.$required.$subject.$thanks.$template ); 
    4848    if ( is_array( $return['post'] ) ) { 
     
    179179} 
    180180 
    181 function bs_submit_form( $pd, $recipient, $fields, $labels, $required, $subject, $thanks, $template ) { 
     181function bs_submit_form( $pd, $recipient, $fields, $labels, $required, $subject, $thanks, $template, $recipientname ) { 
    182182    // hash ensures that forms are unique (widget won't submit main, etc.) 
    183     $hash = md5( $recipient.$fields.$labels.$required.$subject.$thanks.$template ); 
    184     $return = ''; 
    185     $post = array( 'status'=>'', 'name'=>'', 'email'=>'', 'message'=>'' ); 
    186     if ( isset($pd['bs_contact_form']) && $pd['bs_contact_form'] == $hash ) { 
    187         if ( !wp_verify_nonce($pd['bs_contact_form_nonce'],'bs_contact_form') ) { wp_die(); } 
    188         do_action( 'bs_pre_filter_contact', $pd, $recipient, $submit, $fields, $labels, $required, $thanks ); 
    189         $post['email'] = sanitize_email( $pd['bs_email'] ); 
    190         $post['name'] = stripslashes( sanitize_text_field( $pd['bs_name'] ) ); 
    191         $ip = $_SERVER['REMOTE_ADDR']; 
    192         $result = bs_checker( array( 'ip'=>$ip, 'email'=>$post['email'], 'name'=>$post['name'], 'action'=>'check' ) ); 
    193         do_action( 'bs_post_filter_contact', $pd, $recipient, $submit, $fields, $labels, $required, $thanks ); 
    194         if ( $result ) { // this is spam! 
    195             return array( 'message'=>__( 'BotSmasher thinks you\'re a spammer. Please contact us if you\'re a real person!', 'botsmasher' ) ); 
    196         } else { 
    197             foreach ( $fields as $value ) { 
    198                 switch ($value) { 
    199                     case 'name': 
    200                         $default_template .= "{name}"; 
    201                         if ( empty( $_POST['bs_name'] ) ) { 
    202                             $errors['name'] = array( 'label'=>$labels[$value], 'name'=>'name', 'post'=>'' ); 
    203                         } 
    204                         break; 
    205                     case 'email': 
    206                         $default_template .= "\n{email}"; 
    207                         if ( empty( $_POST['bs_email'] ) ) { 
    208                             $errors['email'] = array( 'label'=>$labels[$value], 'name'=>'email', 'post'=>'' ); 
    209                         }                        
    210                         break; 
    211                     case 'number': 
    212                         $val = ( is_numeric( $_POST["bs_$value"] ) )?$_POST["bs_$value"]:false; 
    213                         $val = apply_filters( "bs_sanitize_$value", $val, $labels[$value] ); 
    214                         if ( $val ) { 
    215                             $post[$value] = $val; 
    216                             $default_template .= "\n{".$value."}"; 
    217                         } else { 
    218                             if ( in_array( $value, $required ) ) { 
    219                                 $is_error = true;  
    220                                 $errors[$value] = array( 'label'=>$labels[$value], 'name'=>$value, 'post'=>$_POST["bs_$value"] ); 
     183    if ( isset( $pd['bs_contact_form'] ) ) { 
     184        $hash = md5( $recipient.$fields.$labels.$required.$subject.$thanks.$template ); 
     185        $return = $default_template = ''; 
     186        $is_error = false; 
     187        $post = array( 'status'=>'', 'name'=>'', 'email'=>'', 'message'=>'' ); 
     188        if ( isset($pd['bs_contact_form']) && $pd['bs_contact_form'] == $hash ) { 
     189            if ( !wp_verify_nonce($pd['bs_contact_form_nonce'],'bs_contact_form') ) { wp_die(); } 
     190            do_action( 'bs_pre_filter_contact', $pd, $recipient, $fields, $labels, $required, $subject, $thanks ); 
     191            $post['email'] = sanitize_email( $pd['bs_email'] ); 
     192            $post['name'] = stripslashes( sanitize_text_field( $pd['bs_name'] ) ); 
     193            $ip = $_SERVER['REMOTE_ADDR']; 
     194            $result = bs_checker( array( 'ip'=>$ip, 'email'=>$post['email'], 'name'=>$post['name'], 'action'=>'check' ) ); 
     195            do_action( 'bs_post_filter_contact', $pd, $recipient, $fields, $labels, $required, $subject, $thanks ); 
     196            if ( $result ) { // this is spam! 
     197                return array( 'message'=>__( 'BotSmasher thinks you\'re a spammer. Please contact us if you\'re a real person!', 'botsmasher' ) ); 
     198            } else { 
     199                foreach ( $fields as $value ) { 
     200                    switch ($value) { 
     201                        case 'name': 
     202                            $default_template .= "{name}"; 
     203                            if ( empty( $_POST['bs_name'] ) ) { 
     204                                $errors['name'] = array( 'label'=>$labels[$value], 'name'=>'name', 'post'=>'' ); 
    221205                            } 
    222                         } 
    223                         break;                   
    224                     default: 
    225                         $val = apply_filters( "bs_sanitize_$value", sanitize_text_field( $_POST["bs_$value"] ), $labels[$value] ); 
    226                         if ( $val ) { 
    227                             $post[$value] = $val; 
    228                             $default_template .= "\n{".$value."}"; 
    229                         } else { 
    230                             if ( in_array( $value, $required ) ) { 
    231                                 $is_error = true;  
    232                                 $errors[$value] = array( 'label'=>$labels[$value], 'name'=>$value, 'post'=>$_POST["bs_$value"] ); 
     206                            break; 
     207                        case 'email': 
     208                            $default_template .= "\n{email}"; 
     209                            if ( empty( $_POST['bs_email'] ) ) { 
     210                                $errors['email'] = array( 'label'=>$labels[$value], 'name'=>'email', 'post'=>'' ); 
     211                            }                        
     212                            break; 
     213                        case 'number': 
     214                            $val = ( is_numeric( $_POST["bs_$value"] ) )?$_POST["bs_$value"]:false; 
     215                            $val = apply_filters( "bs_sanitize_$value", $val, $labels[$value] ); 
     216                            if ( $val ) { 
     217                                $post[$value] = $val; 
     218                                $default_template .= "\n{".$value."}"; 
     219                            } else { 
     220                                if ( in_array( $value, $required ) ) { 
     221                                    $is_error = true;  
     222                                    $errors[$value] = array( 'label'=>$labels[$value], 'name'=>$value, 'post'=>$_POST["bs_$value"] ); 
     223                                } 
    233224                            } 
    234                         } 
    235                         break; 
     225                            break;                   
     226                        default: 
     227                            $val = apply_filters( "bs_sanitize_$value", sanitize_text_field( $_POST["bs_$value"] ), $labels[$value] ); 
     228                            if ( $val ) { 
     229                                $post[$value] = $val; 
     230                                $default_template .= "\n{".$value."}"; 
     231                            } else { 
     232                                if ( in_array( $value, $required ) ) { 
     233                                    $is_error = true;  
     234                                    $errors[$value] = array( 'label'=>$labels[$value], 'name'=>$value, 'post'=>$_POST["bs_$value"] ); 
     235                                } 
     236                            } 
     237                            break; 
     238                    } 
    236239                } 
     240                do_action( 'bs_post_sanitize_contact', $post, $recipient, $fields, $labels, $required, $subject, $thanks ); 
     241                 
     242                if ( $is_error ) { 
     243                    $post['status'] = ' errors'; 
     244                    $post['errors'] = $errors; 
     245                } else { 
     246                    $post['status'] = ' submitted'; 
     247                    $post['errors'] = ''; 
     248                } 
     249                 
     250                if ( !$template ) { $template = apply_filters( 'bs_custom_template', $default_template, $post, $recipient ); } 
     251                 
     252                $message = bs_draw_template( $post, $template ); 
     253                $subject = bs_draw_template( $post, $subject ); 
     254                $senderfrom = "From: \"$recipientname\" <$recipient>"; 
     255                $recipientfrom = "From: \"$post[name]\" <$post[email]>"; 
     256                if ( get_option( 'bs_html_email' ) == 'true' ) { 
     257                    add_filter('wp_mail_content_type',create_function('', 'return "text/html";')); 
     258                } 
     259                wp_mail( $post['email'], $subject, $message, $senderfrom ); 
     260                wp_mail( $recipient, $subject, $message, $recipientfrom ); 
     261                if ( get_option( 'bs_html_email' ) == 'true' ) { 
     262                    remove_filter('wp_mail_content_type',create_function('', 'return "text/html";')); 
     263                }            
     264                $return = "<div class='bs-thanks'>".wpautop( stripslashes( $thanks ) )."</div>"; 
    237265            } 
    238             do_action( 'bs_post_sanitize_contact', $post, $recipient, $submit, $fields, $labels, $required, $thanks ); 
    239              
    240             if ( $is_error ) { 
    241                 $post['status'] = ' errors'; 
    242                 $post['errors'] = $errors; 
    243             } else { 
    244                 $post['status'] = ' submitted'; 
    245                 $post['errors'] = ''; 
    246             } 
    247              
    248             if ( !$template ) { $template = apply_filters( 'bs_custom_template', $default_template, $post, $recipient ); } 
    249              
    250             $message = bs_draw_template( $post, $template ); 
    251             $subject = bs_draw_template( $post, $subject ); 
    252             $senderfrom = "From: \"$recipientname\" <$recipient>"; 
    253             $recipientfrom = "From: \"$post[name]\" <$post[email]>"; 
    254             if ( get_option( 'bs_html_email' ) == 'true' ) { 
    255                 add_filter('wp_mail_content_type',create_function('', 'return "text/html";')); 
    256             } 
    257             wp_mail( $post['email'], $subject, $message, $senderfrom ); 
    258             wp_mail( $recipient, $subject, $message, $recipientfrom ); 
    259             if ( get_option( 'bs_html_email' ) == 'true' ) { 
    260                 remove_filter('wp_mail_content_type',create_function('', 'return "text/html";')); 
    261             }            
    262             $return = "<div class='bs-thanks'>".wpautop( stripslashes( $thanks ) )."</div>"; 
    263         } 
    264     } 
    265     return array( 'message'=>$return, 'post'=>$post ); 
     266        } 
     267        return array( 'message'=>$return, 'post'=>$post ); 
     268    } else { 
     269        return false; 
     270    } 
    266271} 
    267272 
     
    282287    $fields[] = 'name';  
    283288    $fields[] = 'email'; 
    284     $labels[] = $instance['name_label']; 
    285     $labels[] = $instance['email_label']; 
     289    $labels[] = ( isset( $instance['name_label'] ) )?$instance['name_label']:''; 
     290    $labels[] = ( isset( $instance['email_label'] ) )?$instance['email_label']:''; 
    286291     
    287292    foreach ( $the_fields as $field => $value  ) { 
     
    325330        $after_widget = apply_filters( 'bs_widget_after', $after_widget ); 
    326331        $before_widget = apply_filters( 'bs_widget_before', $before_widget ); 
    327  
     332        $recipientname = apply_filters( 'bs_recipient_name', get_option( 'blogname' ) ); 
    328333        extract( $params ); 
    329334         
    330335        echo $before_widget; 
    331336        echo $widget_title; 
    332         echo bs_contact_form( $recipient, $submit, $fields, $labels, $required, $subject, $thanks, $template ); 
     337        echo bs_contact_form( $recipient, $submit, $fields, $labels, $required, $subject, $thanks, $template, $recipientname ); 
    333338        echo $after_widget; 
    334339    } 
     
    359364        } 
    360365        $tags = "<code>".implode( '</code>, <code>',$tags )."</code>"; 
     366        $title = ( isset( $instance['title'] ) )?$instance['title']:''; 
     367        $recipient = ( isset( $instance['recipient'] ) )?$instance['recipient']:''; 
     368        $submit = ( isset( $instance['submit'] ) )?$instance['submit']:''; 
     369        $subject = ( isset( $instance['subject'] ) )?$instance['subject']:''; 
     370        $thanks = ( isset( $instance['thanks'] ) )?$instance['thanks']:''; 
     371        $template = ( isset( $instance['template'] ) )?$instance['template']:''; 
     372        $name_label = ( isset( $instance['name_label'] ) )?$instance['name_label']:''; 
     373        $email_label = ( isset( $instance['email_label'] ) )?$instance['email_label']:''; 
     374 
    361375        echo $shortcode; 
    362376?> 
     
    365379<p> 
    366380<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title', 'botsmasher' ); ?>:</label> 
    367 <input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $instance['title'] ); ?>" class="widefat" /> 
     381<input type="text" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" value="<?php echo esc_attr( $title ); ?>" class="widefat" /> 
    368382</p> 
    369383<p> 
    370384<label for="<?php echo $this->get_field_id( 'recipient' ); ?>"><?php _e( 'Recipient', 'botsmasher' ); ?>:</label> 
    371 <input type="text" id="<?php echo $this->get_field_id( 'recipient' ); ?>" name="<?php echo $this->get_field_name( 'recipient' ); ?>" value="<?php echo esc_attr( $instance['recipient'] ); ?>" class="widefat" /> 
     385<input type="text" id="<?php echo $this->get_field_id( 'recipient' ); ?>" name="<?php echo $this->get_field_name( 'recipient' ); ?>" value="<?php echo esc_attr( $recipient ); ?>" class="widefat" /> 
    372386</p> 
    373387<p> 
    374388<label for="<?php echo $this->get_field_id( 'submit' ); ?>"><?php _e( 'Submit Text', 'botsmasher' ); ?>:</label> 
    375 <input type="text" id="<?php echo $this->get_field_id( 'submit' ); ?>" name="<?php echo $this->get_field_name( 'submit' ); ?>" value="<?php echo esc_attr( $instance['submit'] ); ?>" class="widefat" /> 
     389<input type="text" id="<?php echo $this->get_field_id( 'submit' ); ?>" name="<?php echo $this->get_field_name( 'submit' ); ?>" value="<?php echo esc_attr( $submit ); ?>" class="widefat" /> 
    376390</p> 
    377391<p> 
    378392<label for="<?php echo $this->get_field_id( 'subject' ); ?>"><?php _e( 'Email Subject', 'botsmasher' ); ?>:</label> 
    379 <input type="text" id="<?php echo $this->get_field_id( 'subject' ); ?>" name="<?php echo $this->get_field_name( 'subject' ); ?>" value="<?php echo esc_attr( $instance['subject'] ); ?>" class="widefat" aria-labelledby="<?php  echo $this->get_field_id( 'subject' ); echo $this->get_field_id( 'subject' ); ?>_label" /> 
     393<input type="text" id="<?php echo $this->get_field_id( 'subject' ); ?>" name="<?php echo $this->get_field_name( 'subject' ); ?>" value="<?php echo esc_attr( $subject ); ?>" class="widefat" aria-labelledby="<?php  echo $this->get_field_id( 'subject' ); echo $this->get_field_id( 'subject' ); ?>_label" /> 
    380394<span id="<?php echo $this->get_field_id( 'subject' ); ?>_label"><?php _e('Available template tags: ', 'botsmasher' ); echo $tags; ?></span> 
    381395</p> 
     
    383397<p> 
    384398<label for="<?php echo $this->get_field_id( 'thanks' ); ?>"><?php _e( 'Thank you message', 'botsmasher' ); ?>:</label> 
    385 <textarea cols="40" rows="2" id="<?php echo $this->get_field_id( 'thanks' ); ?>" name="<?php echo $this->get_field_name( 'thanks' ); ?>" class="widefat"><?php echo esc_attr( $instance['thanks'] ); ?></textarea> 
     399<textarea cols="40" rows="2" id="<?php echo $this->get_field_id( 'thanks' ); ?>" name="<?php echo $this->get_field_name( 'thanks' ); ?>" class="widefat"><?php echo esc_attr( $thanks ); ?></textarea> 
    386400</p> 
    387401<p> 
    388402<label for="<?php echo $this->get_field_id( 'template' ); ?>"><?php _e( 'Message Template', 'botsmasher' ); ?>:</label> 
    389 <textarea cols="40" rows="4" id="<?php echo $this->get_field_id( 'template' ); ?>" name="<?php echo $this->get_field_name( 'template' ); ?>" class="widefat" aria-labelledby="<?php  echo $this->get_field_id( 'template' ); echo $this->get_field_id( 'subject' ); ?>_label" ><?php echo esc_attr( $instance['template'] ); ?></textarea> 
     403<textarea cols="40" rows="4" id="<?php echo $this->get_field_id( 'template' ); ?>" name="<?php echo $this->get_field_name( 'template' ); ?>" class="widefat" aria-labelledby="<?php  echo $this->get_field_id( 'template' ); echo $this->get_field_id( 'subject' ); ?>_label" ><?php echo esc_attr( $template ); ?></textarea> 
    390404<span id="<?php echo $this->get_field_id( 'template' ); ?>_label"><?php _e('Available template tags: ', 'botsmasher' ); echo $tags; ?></span> 
    391405</p> 
     
    395409<p> 
    396410<label for="<?php echo $this->get_field_id( 'name_label' ); ?>"><?php _e( 'Name field label', 'botsmasher' ); ?>:</label> 
    397 <input type="text" id="<?php echo $this->get_field_id( 'name_label' ); ?>" name="<?php echo $this->get_field_name( 'name_label' ); ?>" value="<?php echo esc_attr( $instance['name_label'] ); ?>" class="widefat" /> 
     411<input type="text" id="<?php echo $this->get_field_id( 'name_label' ); ?>" name="<?php echo $this->get_field_name( 'name_label' ); ?>" value="<?php echo esc_attr( $name_label ); ?>" class="widefat" /> 
    398412</p> 
    399413<p> 
    400414<label for="<?php echo $this->get_field_id( 'email_label' ); ?>"><?php _e( 'Email field label', 'botsmasher' ); ?>:</label> 
    401 <input type="text" id="<?php echo $this->get_field_id( 'email_label' ); ?>" name="<?php echo $this->get_field_name( 'email_label' ); ?>" value="<?php echo esc_attr( $instance['email_label'] ); ?>" class="widefat" /> 
     415<input type="text" id="<?php echo $this->get_field_id( 'email_label' ); ?>" name="<?php echo $this->get_field_name( 'email_label' ); ?>" value="<?php echo esc_attr( $email_label ); ?>" class="widefat" /> 
    402416</p> 
    403417</div> 
  • botsmasher/trunk/readme.txt

    r756856 r759528  
    55Requires at least: 3.4.2 
    66Tested up to: 3.6.0 
    7 Stable tag: 1.0.3 
     7Stable tag: 1.0.4 
    88License: GPLv2 or later 
    99 
     
    5353 
    5454* Miscellaneous warnings and notices in contact form submission. 
    55 * Big fixes in local spam registry pre-check. 
     55* Bug fixes in local spam registry pre-check. 
     56* Bug fix in saving option to send HTML email. 
    5657 
    5758= 1.0.3 = 
Note: See TracChangeset for help on using the changeset viewer.