Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comment form is now a dialog with AJAX post support
- Loading branch information
Showing
8 changed files
with
419 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php if ('open' == $post->comment_status) : ?> | ||
|
||
<div id="respond"> | ||
|
||
<h3 class="title"><?php comment_form_title( 'Leave a Reply', 'Leave a Reply to %s' ); ?></h3> | ||
|
||
<div class="cancel-comment-reply"> | ||
<small><?php cancel_comment_reply_link(); ?></small> | ||
</div> | ||
|
||
<?php if ( get_option('comment_registration') && !$user_ID ) : ?> | ||
<p>You must be <a href="<?php echo get_option('siteurl'); ?>/wp-login.php?redirect_to=<?php echo urlencode(get_permalink()); ?>">logged in</a> to post a comment.</p> | ||
<?php else : ?> | ||
|
||
<form action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform"> | ||
|
||
<?php if ( $user_ID ) : ?> | ||
|
||
<p>Logged in as <a href="<?php echo get_option('siteurl'); ?>/wp-admin/profile.php"><?php echo $user_identity; ?></a>. <a href="<?php echo wp_logout_url(get_permalink()); ?>" title="Log out of this account">Log out »</a></p> | ||
|
||
<?php else : ?> | ||
|
||
<div class="status"></div> | ||
|
||
<p><input type="text" name="author" id="author" value="<?php echo $comment_author; ?>" size="22" tabindex="1" <?php if ($req) echo "aria-required='true'"; ?> /> | ||
<label for="author"><small>Name <?php if ($req) echo "(required)"; ?></small></label></p> | ||
|
||
<p><input type="text" name="email" id="email" value="<?php echo $comment_author_email; ?>" size="22" tabindex="2" <?php if ($req) echo "aria-required='true'"; ?> /> | ||
<label for="email"><small>Mail (will not be published) <?php if ($req) echo "(required)"; ?></small></label></p> | ||
|
||
<p><input type="text" name="url" id="url" value="<?php echo $comment_author_url; ?>" size="22" tabindex="3" /> | ||
<label for="url"><small>Website</small></label></p> | ||
|
||
<?php endif; ?> | ||
|
||
<!--<p><small><strong>XHTML:</strong> You can use these tags: <code><?php echo allowed_tags(); ?></code></small></p>--> | ||
|
||
<p><textarea name="comment" id="comment" cols="100%" rows="10" tabindex="4"></textarea></p> | ||
|
||
<p><input name="submit" type="submit" id="submit" tabindex="5" value="Submit Comment" /> | ||
<?php comment_id_fields(); ?> | ||
</p> | ||
<?php do_action('comment_form', $post->ID); ?> | ||
|
||
</form> | ||
|
||
<?php endif; // If registration required and not logged in ?> | ||
</div> | ||
|
||
<?php endif; // if you delete this the sky will fall on your head ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?php | ||
require_once('../../../wp-config.php'); | ||
|
||
global $comment, $comments, $post, $wpdb, $user_ID, $user_identity, $user_email, $user_url; | ||
|
||
function fail($s) { | ||
header('HTTP/1.0 500 Internal Server Error'); | ||
echo $s; | ||
exit; | ||
} | ||
|
||
foreach($_POST as $k=>$v) { | ||
$_POST[$k] = urldecode($v); | ||
} | ||
|
||
$comment_post_ID = (int) $_POST['comment_post_ID']; | ||
|
||
$post_status = $wpdb->get_var("SELECT comment_status FROM $wpdb->posts WHERE ID = '$comment_post_ID'"); | ||
|
||
if ( empty($post_status) ) { | ||
do_action('comment_id_not_found', $comment_post_ID); | ||
fail('The post you are trying to comment on does not curently exist in the database.'); | ||
} elseif ( 'closed' == $post_status ) { | ||
do_action('comment_closed', $comment_post_ID); | ||
fail(__('Sorry, comments are closed for this item.')); | ||
} | ||
|
||
$comment_author = trim($_POST['author']); | ||
$comment_author_email = trim($_POST['email']); | ||
$comment_author_url = trim($_POST['url']); | ||
$comment_content = trim($_POST['comment']); | ||
|
||
// If the user is logged in | ||
get_currentuserinfo(); | ||
if ( $user_ID ) : | ||
$comment_author = addslashes($user_identity); | ||
$comment_author_email = addslashes($user_email); | ||
$comment_author_url = addslashes($user_url); | ||
else : | ||
if ( get_option('comment_registration') ) | ||
fail(__('Sorry, you must be logged in to post a comment.')); | ||
endif; | ||
|
||
$comment_type = ''; | ||
|
||
if ( get_settings('require_name_email') && !$user_ID ) { | ||
if ( 6 > strlen($comment_author_email) || '' == $comment_author ) | ||
fail(__('Error: please fill the required fields (name, email).')); | ||
elseif ( !is_email($comment_author_email)) | ||
fail(__('Error: please enter a valid email address.')); | ||
} | ||
|
||
if ( '' == $comment_content ) | ||
fail(__('Error: please type a comment.')); | ||
|
||
$dupe = "SELECT comment_ID FROM $wpdb->comments WHERE comment_post_ID = '$comment_post_ID' AND ( comment_author = '$comment_author' "; | ||
if ( $comment_author_email ) | ||
$dupe .= "OR comment_author_email = '$comment_author_email' "; | ||
$dupe .= ") AND comment_content = '$comment_content' LIMIT 1"; | ||
if ( $wpdb->get_var($dupe) ) | ||
fail( __('Duplicate comment detected; it looks as though you\'ve already said that!') ); | ||
|
||
$commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_content', 'comment_type', 'user_ID'); | ||
|
||
$new_comment_ID = wp_new_comment($commentdata); | ||
|
||
if ( !$user_ID ) : | ||
setcookie('comment_author_' . COOKIEHASH, stripslashes($comment_author), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); | ||
setcookie('comment_author_email_' . COOKIEHASH, stripslashes($comment_author_email), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); | ||
setcookie('comment_author_url_' . COOKIEHASH, stripslashes($comment_author_url), time() + 30000000, COOKIEPATH, COOKIE_DOMAIN); | ||
endif; | ||
|
||
$comment = $wpdb->get_row("SELECT * FROM {$wpdb->comments} WHERE comment_ID = " . $new_comment_ID); | ||
|
||
$post->comment_status = $wpdb->get_var("SELECT comment_status FROM {$wpdb->posts} WHERE ID = {$comment_post_ID}"); | ||
|
||
ob_start(); | ||
$comments = array($comment); | ||
include(TEMPLATEPATH . '/comments.php'); | ||
$commentout = ob_get_clean(); | ||
preg_match('#<li(.*?)>(.*)</li>#ims', $commentout, $matches); | ||
echo "<li style=\"display:none\"".$matches[1].">".$matches[2]."</li>"; | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,15 @@ | ||
<?php if ( have_comments() ) : ?> | ||
<a name="comments"></a> | ||
<div class="comments"> | ||
<h3 class="title">Comments</h3> | ||
<?php while(have_comments()):the_comment();?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php include('comment.php');?> | ||
<?php endwhile;?> | ||
<h3 class="title">Comments (<a id="comment-add" href="#commentsform">Add</a>)</h3> | ||
<?php if ( have_comments() ) : ?> | ||
<?php while(have_comments()):the_comment();?> | ||
<?php include('comment.php');?> | ||
<?php endwhile;?> | ||
<?php else: ?> | ||
<p>There are no comments yet!</p> | ||
<?php endif; ?> | ||
</div> | ||
<a name="commentsform"></a> | ||
<div id="comment-form" class="comment-form"> | ||
<?php include('comment-form.php'); ?> | ||
</div> | ||
<?php endif; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.