Don't like ads? PRO users don't see any ads ;-)
Guest

Viper007Bond

By: a guest on Nov 21st, 2009  |  syntax: PHP  |  size: 3.12 KB  |  hits: 152  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php /*
  2.  
  3. **************************************************************************
  4.  
  5. Plugin Name:  In Reply To
  6. Plugin URI:   http://www.viper007bond.com/wordpress-plugins/in-reply-to/
  7. Description:  Flat but threaded comments.
  8. Version:      1.0.0
  9. Author:       Viper007Bond
  10. Author URI:   http://www.viper007bond.com/
  11.  
  12. **************************************************************************
  13.  
  14. Copyright (C) 2008 Viper007Bond
  15.  
  16. This program is free software: you can redistribute it and/or modify
  17. it under the terms of the GNU General Public License as published by
  18. the Free Software Foundation, either version 3 of the License, or
  19. (at your option) any later version.
  20.  
  21. This program is distributed in the hope that it will be useful,
  22. but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  24. GNU General Public License for more details.
  25.  
  26. You should have received a copy of the GNU General Public License
  27. along with this program.  If not, see <http://www.gnu.org/licenses/>.
  28.  
  29. **************************************************************************/
  30.  
  31. class InReplyTo {
  32.  
  33.         // Plugin initialization
  34.         function InReplyTo() {
  35.                 if ( is_admin() || !class_exists('WP_Embed') )
  36.                         return;
  37.  
  38.                 add_filter( 'comment_text', array(&$this, 'add_inreplyto_text'), 7 );
  39.  
  40.                 add_filter( 'wp_parse_args_wp_list_comments', array(&$this, 'modify_wp_list_comments'), 10, 3 );
  41.                 add_filter( 'wp_parse_args_get_comment_reply_link', array(&$this, 'modify_get_comment_reply_link'), 10, 3 );
  42.         }
  43.  
  44.  
  45.         // Adds some text saying what comment the current one is in reply to
  46.         function add_inreplyto_text( $content ) {
  47.                 global $comment;
  48.  
  49.                 if ( empty($comment->comment_ID) || 0 == $comment->comment_parent || !$parent = get_comment( $comment->comment_parent ) )
  50.                         return $content;
  51.  
  52.                 if ( empty($parent->comment_author) )
  53.                         $author = __('Anonymous');
  54.                 else
  55.                         $author = $parent->comment_author;
  56.  
  57.                 $author = apply_filters( 'comment_author', $author );
  58.  
  59.                 return '<a href="' . get_comment_link( $parent->comment_ID ) . '">In Reply To &quot;' . esc_html( $author ) . "&quot;:</a>\n\n" . $content;
  60.         }
  61.  
  62.  
  63.         function modify_wp_list_comments( $args, $passed, $defaults ) {
  64.                 $args['max_depth'] = -1;
  65.  
  66.                 return $args;
  67.         }
  68.  
  69.  
  70.         function modify_get_comment_reply_link( $args, $passed, $defaults ) {
  71.                 global $comment;
  72.  
  73.                 $args['depth'] = $this->get_comment_depth( $comment );
  74.                 $args['max_depth'] = 10000000000; // Since they aren't displayed threaded, we don't care how deep they go
  75.  
  76.                 return $args;
  77.         }
  78.  
  79.  
  80.         // Returns the depth of the given comment object
  81.         function get_comment_depth( $comment, $existing_depth = 0 ) {
  82.                 if ( !is_object($comment) || 0 == $comment->comment_parent )
  83.                         return $existing_depth + 1;
  84.  
  85.                 $parent = get_comment( $comment->comment_parent );
  86.  
  87.                 return ( 0 == $parent->comment_parent ) ? $existing_depth + 2 : $this->get_comment_depth( $parent, $existing_depth + 1 );
  88.         }
  89. }
  90.  
  91. // Start this plugin once all other plugins are fully loaded
  92. add_action( 'init', 'InReplyTo', 7 );
  93. function InReplyTo() {
  94.         global $InReplyTo;
  95.         $InReplyTo = new InReplyTo();
  96. }
  97.  
  98. ?>