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