<?php /*
**************************************************************************
Plugin Name: In Reply To
Plugin URI: http://www.viper007bond.com/wordpress-plugins/in-reply-to/
Description: Flat but threaded comments.
Version: 1.0.0
Author: Viper007Bond
Author URI: http://www.viper007bond.com/
**************************************************************************
Copyright (C) 2008 Viper007Bond
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**************************************************************************/
class InReplyTo {
// Plugin initialization
function InReplyTo() {
return;
add_filter
( 'comment_text', array(&$this, 'add_inreplyto_text'), 7
);
add_filter
( 'wp_parse_args_wp_list_comments', array(&$this, 'modify_wp_list_comments'), 10
, 3
);
add_filter
( 'wp_parse_args_get_comment_reply_link', array(&$this, 'modify_get_comment_reply_link'), 10
, 3
);
}
// Adds some text saying what comment the current one is in reply to
function add_inreplyto_text( $content ) {
global $comment;
if ( empty($comment->comment_ID) || 0
== $comment->comment_parent || !$parent = get_comment
( $comment->comment_parent ) )
return $content;
if ( empty($parent->comment_author) )
$author = __('Anonymous');
else
$author = $parent->comment_author;
$author = apply_filters( 'comment_author', $author );
return '<a href="' . get_comment_link( $parent->comment_ID ) . '">In Reply To "' . esc_html( $author ) . "":</a>\n\n" . $content;
}
function modify_wp_list_comments( $args, $passed, $defaults ) {
$args['max_depth'] = -1;
return $args;
}
function modify_get_comment_reply_link( $args, $passed, $defaults ) {
global $comment;
$args['depth'] = $this->get_comment_depth( $comment );
$args['max_depth'] = 10000000000; // Since they aren't displayed threaded, we don't care how deep they go
return $args;
}
// Returns the depth of the given comment object
function get_comment_depth( $comment, $existing_depth = 0 ) {
if ( !is_object($comment) || 0
== $comment->comment_parent )
return $existing_depth + 1;
$parent = get_comment( $comment->comment_parent );
return ( 0 == $parent->comment_parent ) ? $existing_depth + 2 : $this->get_comment_depth( $parent, $existing_depth + 1 );
}
}
// Start this plugin once all other plugins are fully loaded
add_action( 'init', 'InReplyTo', 7 );
function InReplyTo() {
global $InReplyTo;
$InReplyTo = new InReplyTo();
}
?>