web/wp-content/plugins/wptouch/themes/default/comments-ajax.php
branchwordpress
changeset 123 561aa6d282f6
equal deleted inserted replaced
112:fb7cd02b9848 123:561aa6d282f6
       
     1 <?php
       
     2 // This relative path will find what we need... kinda dirty, but it's a failsafe
       
     3 require_once( dirname(__FILE__) . '../../../../../../wp-load.php' ); 
       
     4 // Make sure the server returns the fact that this is a real file and it exists, even though its outside WordPress
       
     5 header("HTTP/1.1 200 OK");
       
     6 
       
     7 // AJAX COMMENTS
       
     8 //No need to modify this file, it works under all installations
       
     9 
       
    10 global $comment, $comments, $post, $wpdb, $user_ID, $user_identity, $user_email, $user_url;
       
    11 function fail($s) {
       
    12 	header('HTTP/1.0 500 Internal Server Error');
       
    13 	echo $s;
       
    14 	exit;
       
    15   }
       
    16 foreach ($_GET as $k => $v) {
       
    17 	$_GET[$k] = urldecode($v);
       
    18   }
       
    19 
       
    20 $comment_post_ID = (int)$_GET['comment_post_ID'];
       
    21 $post_status = $wpdb->get_var("SELECT comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'");
       
    22 if (empty($post_status)) {
       
    23 	do_action('comment_id_not_found', $comment_post_ID);
       
    24 	fail( __('The post you are trying to comment on does not curently exist in the database.', 'wptouch') );
       
    25   } elseif ('closed' == $post_status) {
       
    26 	do_action('comment_closed', $comment_post_ID);
       
    27 	fail(__('Sorry, comments are closed for this item.', 'wptouch'));
       
    28   }
       
    29 
       
    30 $comment_author = trim($_GET['author']);
       
    31 $comment_author_email = trim($_GET['email']);
       
    32 $comment_author_url = trim($_GET['url']);
       
    33 $comment_content = trim($_GET['comment']);
       
    34 
       
    35 // If the user is logged in
       
    36 get_currentuserinfo();
       
    37 	if ($user_ID) : 
       
    38 		$comment_author = addslashes($user_identity);
       
    39 		$comment_author_email = addslashes($user_email);
       
    40 		$comment_author_url = addslashes($user_url);
       
    41 	else : if 
       
    42 		(get_option('comment_registration'))
       
    43 		fail(__('Sorry, you must be logged in to post a comment.', 'wptouch'));
       
    44 	endif;
       
    45 
       
    46 $comment_type = '';
       
    47 if (get_settings('require_name_email') && !$user_ID) {
       
    48 	if (6 > strlen($comment_author_email) || '' == $comment_author)
       
    49 		fail(__('Error: please fill in the required fields', 'wptouch'));
       
    50 	elseif (!is_email($comment_author_email))
       
    51 		fail(__('Error: please enter a valid email address.', 'wptouch')); }
       
    52 	if ('' == $comment_content)
       
    53 		fail(__('Error: please type something in the comment area.', 'wptouch'));
       
    54 	$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID');
       
    55 	$new_comment_ID = wp_new_comment($commentdata);
       
    56 	if (!$user_ID) : 
       
    57 		setcookie('comment_author_' . COOKIEHASH, stripslashes($comment_author), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
       
    58 		setcookie('comment_author_email_' . COOKIEHASH, stripslashes($comment_author_email), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
       
    59 		setcookie('comment_author_url_' . COOKIEHASH, stripslashes($comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN);
       
    60 	endif;
       
    61 
       
    62 $comment = $wpdb->get_row("SELECT * FROM {$wpdb->comments} WHERE comment_ID = " . $new_comment_ID);
       
    63 $post->comment_status = $wpdb->get_var("SELECT comment_status FROM {$wpdb->posts} WHERE ID = {$comment_post_ID}");
       
    64 	ob_start();
       
    65 		$comments = array($comment);
       
    66 			include(TEMPLATEPATH . '/comments.php');
       
    67 		$commentout = ob_get_clean();
       
    68 			preg_match('#<li(.*?)>(.*)</li>#ims', $commentout, $matches);
       
    69 		echo "<li id=\"the-new-comment\" style=\"display:none\"" . $matches[1] . ">" . $matches[2] . "</li>";
       
    70 ?>