web/wp-content/themes/selecta/functions/ocmx_comment_post.php
changeset 1 0d28b7c10758
equal deleted inserted replaced
0:0d9a58d2c515 1:0d28b7c10758
       
     1 <?php
       
     2 /**
       
     3  * Handles Comment Post to WordPress and prevents duplicate comment posting.
       
     4  *
       
     5  * @package WordPress
       
     6  */
       
     7 
       
     8 if ( 'POST' != $_SERVER['REQUEST_METHOD'] ) {
       
     9 	header('Allow: POST');
       
    10 	header('HTTP/1.1 405 Method Not Allowed');
       
    11 	header('Content-Type: text/plain');
       
    12 	exit;
       
    13 }
       
    14 
       
    15 /** Sets up the WordPress Environment. I hate using the ../ 's but it seems they have to be used :( */
       
    16 require("../../../../wp-load.php");
       
    17 
       
    18 nocache_headers();
       
    19 
       
    20 $comment_post_ID = (int) $_REQUEST['comment_post_id'];
       
    21 
       
    22 $status = $wpdb->get_row( $wpdb->prepare("SELECT post_status, comment_status FROM $wpdb->posts WHERE ID = %d", $comment_post_ID) );
       
    23 if ( empty($status->comment_status) ) :
       
    24 ?>
       
    25    <div class="dynamic-header"><div class="right"></div></div>
       
    26    <div class="dynamic-content">
       
    27         <div class="comment clearfix">
       
    28             <div class="comment-post">
       
    29             	<p>Comment I.D. not found.</p>
       
    30             </div>
       
    31         </div>
       
    32 	</div>
       
    33     <div class="dynamic-footer"><div class="left"></div><div class="right"></div></div>
       
    34 <?php
       
    35 	exit;
       
    36 elseif ( !comments_open($comment_post_ID) ) :
       
    37 ?>
       
    38    <div class="dynamic-header"><div class="right"></div></div>
       
    39    <div class="dynamic-content">
       
    40         <div class="comment clearfix">
       
    41             <div class="comment-post">
       
    42             	<p class="error">Sorry, comments are closed for this item.</p>
       
    43        		</div>
       
    44         </div>
       
    45 	</div>
       
    46     <div class="dynamic-footer"><div class="left"></div><div class="right"></div></div>
       
    47 <?php
       
    48 	exit;
       
    49 
       
    50 elseif ( in_array($status->post_status, array('draft', 'pending') ) ) :
       
    51 ?>
       
    52    <div class="dynamic-header"><div class="right"></div></div>
       
    53    <div class="dynamic-content">
       
    54         <div class="comment clearfix">
       
    55             <div class="comment-post">
       
    56             	<p class="error">Comment on Draft</p>
       
    57        		</div>
       
    58         </div>
       
    59 	</div>
       
    60     <div class="dynamic-footer"><div class="left"></div><div class="right"></div></div>
       
    61 <?php 
       
    62 	exit;
       
    63 endif;
       
    64 global $comment_twitter , $comment_subscribe;
       
    65 $comment_author       = ( isset($_POST['author']) )  ? trim(strip_tags($_POST['author'])) : null;
       
    66 $comment_author_email = ( isset($_POST['email']) )   ? trim($_POST['email']) : null;
       
    67 $comment_author_url   = ( isset($_POST['url']) )     ? trim($_POST['url']) : null;
       
    68 $comment_content      = ( isset($_POST['comment']) ) ? trim($_POST['comment']) : null;
       
    69 $comment_twitter      = ( isset($_POST['twitter']) ) ? trim($_POST['twitter']) : null;
       
    70 $comment_subscribe      = ( isset($_POST['email_subscribe']) ) ? trim($_POST['email_subscribe']) : null;
       
    71 
       
    72 $comment_meta_table = $wpdb->prefix . "ocmx_comment_meta";	
       
    73 
       
    74 $check_blocked = $wpdb->get_row( $wpdb->prepare("SELECT $wpdb->comments.*, $comment_meta_table.* FROM $wpdb->comments INNER JOIN $comment_meta_table ON $wpdb->comments.comment_ID = $comment_meta_table.commentId WHERE $wpdb->comments.comment_author_email = %s AND $comment_meta_table.block_user = 1", $comment_author_email) );
       
    75 
       
    76 if(count($check_blocked) !== 0) :
       
    77 ?>
       
    78   	<div class="dynamic-header"><div class="right"></div></div>
       
    79 	<div class="dynamic-content">
       
    80 		<div class="comment clearfix">
       
    81             <div class="comment-post">
       
    82                 <p class="error">Your email address has been blocked from commenting on this blog.</p>
       
    83             </div>
       
    84         </div>
       
    85     </div>
       
    86     <div class="dynamic-footer"><div class="left"></div><div class="right"></div></div>
       
    87 <?php 
       
    88 	exit;
       
    89 endif;
       
    90 // If the user is logged in
       
    91 $user = wp_get_current_user();
       
    92 if ( $user->ID ) {
       
    93 	if ( empty( $user->display_name ) )
       
    94 		$user->display_name=$user->user_login;
       
    95 	$comment_author       = $wpdb->escape($user->display_name);
       
    96 	$comment_author_email = $wpdb->escape($user->user_email);
       
    97 	$comment_author_url   = $wpdb->escape($user->user_url);
       
    98 	if ( current_user_can('unfiltered_html') ) {
       
    99 		if ( wp_create_nonce('unfiltered-html-comment_' . $comment_post_ID) != $_POST['_wp_unfiltered_html_comment'] ) {
       
   100 			kses_remove_filters(); // start with a clean slate
       
   101 			kses_init_filters(); // set up the filters
       
   102 		}
       
   103 	}
       
   104 } else {
       
   105 	if ( get_option('comment_registration') )
       
   106 		wp_die( __('Sorry, you must be logged in to post a comment.') );
       
   107 }
       
   108 
       
   109 $comment_type = '';
       
   110 
       
   111 if ( get_option('require_name_email') && !$user->ID ) {
       
   112 	if ( 6 > strlen($comment_author_email) || '' == $comment_author )
       
   113 		wp_die( __('Error: please fill the required fields (name, email).') );
       
   114 	elseif ( !is_email($comment_author_email))
       
   115 		wp_die( __('Error: please enter a valid email address.') );
       
   116 }
       
   117 
       
   118 if ( '' == $comment_content )
       
   119 	wp_die( __('Error: please type a comment.') );
       
   120 
       
   121 $comment_parent = isset($_POST['comment_parent']) ? absint($_POST['comment_parent']) : 0;
       
   122 
       
   123 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'comment_parent', 'user_ID');
       
   124 
       
   125 $comment_id = wp_new_comment( $commentdata );
       
   126 /* $ocmx_add_comment_meta($comment_id, $comment_post_ID) */
       
   127 
       
   128 $comment = get_comment($comment_id);
       
   129 if ( !$user->ID ) {
       
   130 	setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
       
   131 	setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
       
   132 	setcookie('comment_author_url_' . COOKIEHASH, clean_url($comment->comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
       
   133 }
       
   134 // Adjust the classes according to whether or not we're replying to another comment
       
   135 global $header_class, $main_class, $footer_class;
       
   136 $comment_table = $wpdb->prefix . "ocmx_comment_meta";
       
   137 $comment_meta_sql = "SELECT * FROM $comment_table WHERE commentId = ".$comment->comment_ID." LIMIT 1";
       
   138 $comment_count = $wpdb->get_row( $wpdb->prepare("SELECT comment_count FROM $wpdb->posts WHERE ID = %d", $comment_post_ID) );
       
   139 $comment_meta = $wpdb->get_row($comment_meta_sql);
       
   140 
       
   141 ?>
       
   142 <?php if(isset($_POST['comment_parent']) && $_POST['comment_parent'] !== "0" && $_POST['comment_parent'] !== "") : ?>
       
   143 	<div class="threaded-comments">
       
   144 		<div class="thread-comment">
       
   145 <?php else: ?>
       
   146 	<?php if($comment_count == "1") : ?>
       
   147 		<h1 class="header-comments"><?php  echo $post->comment_count; ?> Comments <a name="#comments"></a></h1>
       
   148 	<?php endif; ?>
       
   149 	<div class="comment clearfix">
       
   150 <?php endif; ?>
       
   151 
       
   152 	<div class="comment clearfix">
       
   153         <div class="user">
       
   154             <?php echo get_avatar($comment, 40 ); ?>                
       
   155         </div>
       
   156         <div class="comment-post">
       
   157             <div class="container-header-light-normal"><span></span></div>
       
   158             <div class="comment-content clearfix">
       
   159                 <h3>
       
   160                     <?php if($comment->comment_author_url !== "http://" && $comment->comment_author_url !== "") : ?>
       
   161                        <a href="<?php echo $comment->comment_author_url; ?>" class="commentor_url" name="comment-<?php echo $comment->comment_ID; ?>" rel="nofollow"> <?php echo $comment->comment_author; ?></a>
       
   162                     <?php else : ?>
       
   163                          <?php echo $comment->comment_author; ?>
       
   164                     <?php endif; ?>
       
   165                     <?php if($comment_meta->twitter !== "") : ?><span class="twitter-link"><a href="http://twitter.com/<?php echo $comment_meta->twitter; ?>" class="commentor_url" rel="nofollow">@<?php echo $comment_meta->twitter; ?></a></span><?php endif; ?>
       
   166                     <?php comment_author(); ?></a><span class="comment-date"><?php echo date('F d Y', strtotime($comment->comment_date)); ?> <?php echo date("H\:i a", strtotime($comment->comment_date)); ?></span>
       
   167                 </h3>
       
   168                 <?php if ($comment->comment_approved == '0') : ?>
       
   169                     <p>Comment is awaiting moderation.</p>
       
   170                 <?php else :
       
   171                     $use_comment = apply_filters('wp_texturize', $comment->comment_content);
       
   172                     $use_comment = str_replace("\n", "<br>", $use_comment);
       
   173                     echo "<p>".$use_comment."</p>";
       
   174                 endif; ?>
       
   175             </div>
       
   176             <div class="container-footer-light-normal"><span></span></div>
       
   177         </div>
       
   178 	</div>
       
   179 <?php if(isset($_POST['comment_parent']) && $_POST['comment_parent'] !== "0" && $_POST['comment_parent'] !== "") : ?>
       
   180         </div>
       
   181     </div>
       
   182 <?php else : ?>
       
   183 	</div>
       
   184 <?php endif; ?>
       
   185 
       
   186 
       
   187