<?php
 
    include('bt-common.php');
 
    
 
    if (bt_get_config('comments') && isset($_POST['bt_submit'])) {
 
        if (isset($_POST['bt_id'])) $bt_content_identifier['id'] = (int) $_POST['bt_id'];
 
 
        $bt_posts = new bt_posts();
 
        $bt_post_array = $bt_posts->get_posts($bt_content_identifier);
 
        
 
        if (count($bt_post_array) == 1) {
 
            $bt_post = $bt_post_array[0];
 
            if ($bt_post['post_comments']) {
 
                if (isset($_POST['bt_comment_body']) && !empty($_POST['bt_comment_body'])) {
 
                    
 
                    $bt_comments = new bt_comments();
 
                    $bt_spam = new bt_spam();
 
                    
 
                    /*
 
                    Post comment here
 
                    */
 
                    $bt_comment_post = array();
 
                    
 
                    if (bt_is_logged_in()) {
 
                        $bt_comment_post['user_id'] = (int) bt_get_user_data('user_id');
 
                        
 
                        //needed for akismet
 
                        $bt_comment_post['comment_display_name'] = bt_get_user_data('display_name');
 
                        $bt_comment_post['comment_email'] = bt_get_user_data('email');
 
                        $bt_comment_post['comment_website'] = bt_get_user_data('website');
 
                        $bt_comment_post['comment_allow_contact_form'] = 0;
 
                    }
 
                    else {
 
                        if (isset($_POST['bt_comment_display_name'])) {
 
                            $bt_comment_post['comment_display_name'] = $_POST['bt_comment_display_name'];
 
                        }
 
                        else {
 
                            $bt_comment_post['comment_display_name']  = '';
 
                        }
 
                        if (isset($_POST['bt_comment_email'])) {
 
                            $bt_comment_post['comment_email'] = $_POST['bt_comment_email'];
 
                        }
 
                        else {
 
                            $bt_comment_post['comment_email']  = '';
 
                        }
 
                        if (isset($_POST['bt_comment_website'])) {
 
                            $bt_comment_post['comment_website'] = $_POST['bt_comment_website'];
 
                        }
 
                        else {
 
                            $bt_comment_post['comment_website'] = '';
 
                        }
 
                        if (isset($_POST['bt_comment_contact_form'])) {
 
                            $bt_comment_post['comment_allow_contact_form'] = 1;
 
                        }
 
                        else {
 
                            $bt_comment_post['comment_allow_contact_form'] = 0;
 
                        }
 
                        $bt_comment_post['user_id'] = 0;
 
                        
 
                        if (isset($_POST['bt_comment_remember_details'])) {
 
                            $bt_comment_post['bt_comment_remember_details'] = 1;
 
                        }
 
                        else {
 
                            $bt_comment_post['bt_comment_remember_details'] = 0;
 
                        }
 
                        
 
                        if ($bt_comment_post['bt_comment_remember_details']) {
 
                            $bt_cookie_array = bt_get_cookie_array();
 
                            
 
                            $bt_cookie_array['comment_website'] = bt_htmlentities($bt_comment_post['comment_website']);
 
                            $bt_cookie_array['comment_display_name'] = bt_htmlentities($bt_comment_post['comment_display_name']);
 
                            $bt_cookie_array['comment_email'] =    bt_htmlentities($bt_comment_post['comment_email']);
 
                            $bt_cookie_array['comment_allow_contact_form'] = (int) $bt_comment_post['comment_allow_contact_form'];
 
                            $bt_cookie_array['comment_remember_details'] = (int) $bt_comment_post['bt_comment_remember_details'];
 
                            
 
                            bt_set_cookie_array($bt_cookie_array);
 
                        }
 
                        else {
 
                            $bt_cookie_array = bt_get_cookie_array();
 
                            
 
                            if (isset($bt_cookie_array['comment_remember_details']) && $bt_cookie_array['comment_remember_details']) {
 
                                
 
                                unset($bt_cookie_array['comment_website']);
 
                                unset($bt_cookie_array['comment_display_name']);
 
                                unset($bt_cookie_array['comment_email']);
 
                                unset($bt_cookie_array['comment_allow_contact_form']);
 
                                unset($bt_cookie_array['comment_remember_details']);
 
                            
 
                                bt_set_cookie_array($bt_cookie_array);
 
                            }
 
                        }
 
                    }
 
 
                    $bt_comment_post['comment_body'] = $_POST['bt_comment_body'];
 
                    $bt_comment_post['comment_date'] = bt_datetime();
 
                    $bt_comment_post['comment_date_utc'] = bt_datetime_utc();
 
                    $bt_comment_post['post_id'] = (int) $bt_post['post_id'];
 
                    $bt_comment_post['comment_ip_address'] = bt_ip_address();
 
                    $bt_comment_post['comment_approved'] = 1;
 
                    $bt_comment_post['comment_type'] = 'comment';
 
                    
 
                    //spam filtering happens here
 
                    $bt_spam->set_comment($bt_comment_post);
 
                    $bt_processed_comment = $bt_spam->get_comment();
 
                    
 
                    //echo '<pre>';
 
                    //print_r($bt_processed_comment);
 
                    //echo '</pre>';
 
                    
 
                    if ($bt_processed_comment['comment_approved'] == 0) {
 
                        $bt_input_error = '<strong>Your message has been sent to the moderation queue.</strong>';
 
                        $_SESSION['bt_input_error'] = $bt_input_error;
 
                    }
 
                    
 
                    $bt_comments->add_comment($bt_processed_comment);
 
                    
 
                    bt_set_header('Location: ' . bt_post_permalink() . '#posted');
 
                }
 
                else {
 
                    $bt_input_error = '<strong>Your comment cannot be empty.</strong>';
 
                    $_SESSION['bt_input_error'] = $bt_input_error;
 
                    bt_set_header('Location: ' . bt_post_permalink() . '#posted');
 
                }
 
                
 
            }
 
            else {
 
                $bt_input_error = '<strong>Commenting is not enabled for this post.</strong>';
 
                $_SESSION['bt_input_error'] = $bt_input_error;
 
                bt_set_header('Location: ' . bt_post_permalink() . '#posted');
 
            }
 
        }
 
        else {
 
            bt_set_header('Location: ' . bt_get_config('address') . '/');
 
        }
 
        
 
    }
 
    else {
 
        bt_set_header('Location: ' . bt_get_config('address')  . '/');
 
    }
 
    bt_send_headers();
 
?>
 
 |