Skip to content

Commit

Permalink
Enable support for threaded comments and comment reply on index page,…
Browse files Browse the repository at this point in the history
… props yoavf, fixes #8550

git-svn-id: http://svn.automattic.com/wordpress/trunk@10169 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
azaozz committed Dec 10, 2008
1 parent 04c819f commit 1dca6a9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
58 changes: 54 additions & 4 deletions wp-includes/comment-template.php
Expand Up @@ -986,8 +986,7 @@ function get_comment_reply_link($args = array(), $comment = null, $post = null)
if ( get_option('comment_registration') && !$user_ID )
$link = '<a rel="nofollow" href="' . site_url('wp-login.php?redirect_to=' . get_permalink()) . '">' . $login_text . '</a>';
else
$link = "<a rel='nofollow' href='" . wp_specialchars( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\")'>$reply_text</a>";

$link = "<a rel='nofollow' href='" . wp_specialchars( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post);
}

Expand All @@ -1005,6 +1004,57 @@ function get_comment_reply_link($args = array(), $comment = null, $post = null)
function comment_reply_link($args = array(), $comment = null, $post = null) {
echo get_comment_reply_link($args, $comment, $post);
}
/**
* Retrieve HTML content for reply to post link.
*
* The default arguments that can be override are 'add_below', 'respond_id',
* 'reply_text', 'login_text', and 'depth'. The 'login_text' argument will be
* used, if the user must log in or register first before posting a comment. The
* 'reply_text' will be used, if they can post a reply. The 'add_below' and
* 'respond_id' arguments are for the JavaScript moveAddCommentForm() function
* parameters.
*
* @since 2.7.0
*
* @param array $args Optional. Override default options.
* @param int $post Optional. Post that the comment is going to be displayed on.
* @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
*/


function get_post_comments_link($args = array(), $comment = null, $post = null) {
global $user_ID;

$defaults = array('add_below' => 'prologue', 'respond_id' => 'respond', 'reply_text' => __('Leave a Comment'),
'login_text' => __('Log in to leave a Comment'), 'before' => '', 'after' => '');

$args = wp_parse_args($args, $defaults);
extract($args, EXTR_SKIP);
$post = get_post($post);

if ( 'open' != $post->comment_status )
return false;

if ( get_option('comment_registration') && !$user_ID ) {
$link = '<a rel="nofollow" href="' . site_url('wp-login.php?redirect_to=' . get_permalink()) . '">' . $login_text . '</a>';
} else {
$link = "<a rel='nofollow' href='" . get_permalink($post->ID) . "#$respond_id' onclick='return addComment.moveForm(\"$add_below-$post->ID\", \"0\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
}
return apply_filters('post_comments_link', $before . $link . $after, $post);
}

/**
* Displays the HTML content for reply to post link.
* @since 2.7.0
* @see get_post_comments_link() Echoes result
*
* @param array $args Optional. Override default options.
* @param int $post Optional. Post that the comment is going to be displayed on.
* @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
*/
function post_comments_link ($args = array(), $post = null) {
echo get_post_comments_link($args, $post);
}

/**
* Retrieve HTML content for cancel comment reply link.
Expand Down Expand Up @@ -1042,7 +1092,7 @@ function comment_id_fields() {
global $id;

$replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
echo "<input type='hidden' name='comment_post_ID' value='$id' />\n";
echo "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
echo "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
}

Expand Down Expand Up @@ -1310,4 +1360,4 @@ function wp_list_comments($args = array(), $comments = null ) {
$in_comment_loop = false;
}

?>
?>
7 changes: 5 additions & 2 deletions wp-includes/js/comment-reply.js
@@ -1,12 +1,13 @@

addComment = {
moveForm : function(commId, parentId, respondId) {
var t = this, div, comm = t.I(commId), respond = t.I(respondId), cancel = t.I('cancel-comment-reply-link'), parent = t.I('comment_parent');
moveForm : function(commId, parentId, respondId, postId) {
var t = this, div, comm = t.I(commId), respond = t.I(respondId), cancel = t.I('cancel-comment-reply-link'), parent = t.I('comment_parent'), post = t.I('comment_post_ID');

if ( ! comm || ! respond || ! cancel || ! parent )
return;

t.respondId = respondId;
postId = postId || false;

if ( ! t.I('wp-temp-form-div') ) {
div = document.createElement('div');
Expand All @@ -16,6 +17,8 @@ addComment = {
}

comm.parentNode.insertBefore(respond, comm.nextSibling);
if ( post && postId )
post.value = postId;
parent.value = parentId;
cancel.style.display = '';

Expand Down
2 changes: 1 addition & 1 deletion wp-includes/script-loader.php
Expand Up @@ -140,7 +140,7 @@ function mce_version() {
$scripts->add( 'jquery-ui-resizable', '/wp-includes/js/jquery/ui.resizable.js', array('jquery-ui-core'), '1.5.2' );
$scripts->add( 'jquery-ui-dialog', '/wp-includes/js/jquery/ui.dialog.js', array('jquery-ui-resizable', 'jquery-ui-draggable'), '1.5.2' );

$scripts->add( 'comment-reply', '/wp-includes/js/comment-reply.js', false, '20081009');
$scripts->add( 'comment-reply', '/wp-includes/js/comment-reply.js', false, '20081210');

if ( is_admin() ) {
$scripts->add( 'ajaxcat', '/wp-admin/js/cat.js', array( 'wp-lists' ), '20071101' );
Expand Down

0 comments on commit 1dca6a9

Please sign in to comment.