]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/comment-template.php
WordPress 3.3.2-scripts
[autoinstalls/wordpress.git] / wp-includes / comment-template.php
index 321080afbf0844da9eb995f302dbc472f988c071..25f73c3d9004920ee7627e6dd3be5e70aa6937d6 100644 (file)
  * @since 1.5.0
  * @uses apply_filters() Calls 'get_comment_author' hook on the comment author
  *
+ * @param int $comment_ID The ID of the comment for which to retrieve the author. Optional.
  * @return string The comment author
  */
-function get_comment_author() {
-       global $comment;
+function get_comment_author( $comment_ID = 0 ) {
+       $comment = get_comment( $comment_ID );
        if ( empty($comment->comment_author) ) {
                if (!empty($comment->user_id)){
                        $user=get_userdata($comment->user_id);
@@ -39,9 +40,11 @@ function get_comment_author() {
  *
  * @since 0.71
  * @uses apply_filters() Calls 'comment_author' on comment author before displaying
+ *
+ * @param int $comment_ID The ID of the comment for which to print the author. Optional.
  */
-function comment_author() {
-       $author = apply_filters('comment_author', get_comment_author() );
+function comment_author( $comment_ID = 0 ) {
+       $author = apply_filters('comment_author', get_comment_author( $comment_ID ) );
        echo $author;
 }
 
@@ -52,10 +55,11 @@ function comment_author() {
  * @uses apply_filters() Calls the 'get_comment_author_email' hook on the comment author email
  * @uses $comment
  *
+ * @param int $comment_ID The ID of the comment for which to get the author's email.  Optional.
  * @return string The current comment author's email
  */
-function get_comment_author_email() {
-       global $comment;
+function get_comment_author_email( $comment_ID = 0 ) {
+       $comment = get_comment( $comment_ID );
        return apply_filters('get_comment_author_email', $comment->comment_author_email);
 }
 
@@ -70,9 +74,11 @@ function get_comment_author_email() {
  *
  * @since 0.71
  * @uses apply_filters() Calls 'author_email' hook on the author email
+ *
+ * @param int $comment_ID The ID of the comment for which to print the author's email. Optional.
  */
-function comment_author_email() {
-       echo apply_filters('author_email', get_comment_author_email() );
+function comment_author_email( $comment_ID = 0 ) {
+       echo apply_filters('author_email', get_comment_author_email( $comment_ID ) );
 }
 
 /**
@@ -135,12 +141,13 @@ function get_comment_author_email_link($linktext='', $before='', $after='') {
  * @since 1.5.0
  * @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
  *
+ * @param int $comment_ID The ID of the comment for which to get the author's link.  Optional.
  * @return string Comment Author name or HTML link for author's URL
  */
-function get_comment_author_link() {
+function get_comment_author_link( $comment_ID = 0 ) {
        /** @todo Only call these functions when they are needed. Include in if... else blocks */
-       $url    = get_comment_author_url();
-       $author = get_comment_author();
+       $url    = get_comment_author_url( $comment_ID );
+       $author = get_comment_author( $comment_ID );
 
        if ( empty( $url ) || 'http://' == $url )
                $return = $author;
@@ -153,10 +160,12 @@ function get_comment_author_link() {
  * Display the html link to the url of the author of the current comment.
  *
  * @since 0.71
- * @see get_comment_author_link() Echos result
+ * @see get_comment_author_link() Echoes result
+ *
+ * @param int $comment_ID The ID of the comment for which to print the author's link. Optional.
  */
-function comment_author_link() {
-       echo get_comment_author_link();
+function comment_author_link( $comment_ID = 0 ) {
+       echo get_comment_author_link( $comment_ID );
 }
 
 /**
@@ -166,10 +175,11 @@ function comment_author_link() {
  * @uses $comment
  * @uses apply_filters()
  *
- * @return unknown
+ * @param int $comment_ID The ID of the comment for which to get the author's IP address. Optional.
+ * @return string The comment author's IP address.
  */
-function get_comment_author_IP() {
-       global $comment;
+function get_comment_author_IP( $comment_ID = 0 ) {
+       $comment = get_comment( $comment_ID );
        return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
 }
 
@@ -177,10 +187,12 @@ function get_comment_author_IP() {
  * Display the IP address of the author of the current comment.
  *
  * @since 0.71
- * @see get_comment_author_IP() Echos Result
+ * @see get_comment_author_IP() Echoes Result
+ *
+ * @param int $comment_ID The ID of the comment for which to print the author's IP address.  Optional.
  */
-function comment_author_IP() {
-       echo get_comment_author_IP();
+function comment_author_IP( $comment_ID = 0 ) {
+       echo get_comment_author_IP( $comment_ID );
 }
 
 /**
@@ -189,10 +201,11 @@ function comment_author_IP() {
  * @since 1.5.0
  * @uses apply_filters() Calls 'get_comment_author_url' hook on the comment author's URL
  *
+ * @param int $comment_ID The ID of the comment for which to get the author's URL.  Optional.
  * @return string
  */
-function get_comment_author_url() {
-       global $comment;
+function get_comment_author_url( $comment_ID = 0 ) {
+       $comment = get_comment( $comment_ID );
        $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;
        $url = esc_url( $url, array('http', 'https') );
        return apply_filters('get_comment_author_url', $url);
@@ -204,9 +217,11 @@ function get_comment_author_url() {
  * @since 0.71
  * @uses apply_filters()
  * @uses get_comment_author_url() Retrieves the comment author's URL
+ *
+ * @param int $comment_ID The ID of the comment for which to print the author's URL. Optional.
  */
-function comment_author_url() {
-       echo apply_filters('comment_url', get_comment_author_url());
+function comment_author_url( $comment_ID = 0 ) {
+       echo apply_filters('comment_url', get_comment_author_url( $comment_ID ));
 }
 
 /**
@@ -242,7 +257,7 @@ function get_comment_author_url_link( $linktext = '', $before = '', $after = ''
  * Displays the HTML link of the url of the author of the current comment.
  *
  * @since 0.71
- * @see get_comment_author_url_link() Echos result
+ * @see get_comment_author_url_link() Echoes result
  *
  * @param string $linktext The text to display instead of the comment author's email address
  * @param string $before The text or HTML to display before the email link.
@@ -347,14 +362,15 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
  * Retrieve the comment date of the current comment.
  *
  * @since 1.5.0
- * @uses apply_filters() Calls 'get_comment_date' hook with the formated date and the $d parameter respectively
+ * @uses apply_filters() Calls 'get_comment_date' hook with the formatted date and the $d parameter respectively
  * @uses $comment
  *
  * @param string $d The format of the date (defaults to user's config)
+ * @param int $comment_ID The ID of the comment for which to get the date. Optional.
  * @return string The comment's date
  */
-function get_comment_date( $d = '' ) {
-       global $comment;
+function get_comment_date( $d = '', $comment_ID = 0 ) {
+       $comment = get_comment( $comment_ID );
        if ( '' == $d )
                $date = mysql2date(get_option('date_format'), $comment->comment_date);
        else
@@ -368,9 +384,10 @@ function get_comment_date( $d = '' ) {
  * @since 0.71
  *
  * @param string $d The format of the date (defaults to user's config)
+ * @param int $comment_ID The ID of the comment for which to print the date.  Optional.
  */
-function comment_date( $d = '' ) {
-       echo get_comment_date( $d );
+function comment_date( $d = '', $comment_ID = 0 ) {
+       echo get_comment_date( $d, $comment_ID );
 }
 
 /**
@@ -384,10 +401,11 @@ function comment_date( $d = '' ) {
  * @uses $comment
  * @uses apply_filters() Calls 'get_comment_excerpt' on truncated comment
  *
+ * @param int $comment_ID The ID of the comment for which to get the excerpt. Optional.
  * @return string The maybe truncated comment with 20 words or less
  */
-function get_comment_excerpt() {
-       global $comment;
+function get_comment_excerpt( $comment_ID = 0 ) {
+       $comment = get_comment( $comment_ID );
        $comment_text = strip_tags($comment->comment_content);
        $blah = explode(' ', $comment_text);
        if (count($blah) > 20) {
@@ -410,9 +428,11 @@ function get_comment_excerpt() {
  *
  * @since 1.2.0
  * @uses apply_filters() Calls 'comment_excerpt' hook before displaying excerpt
+ *
+ * @param int $comment_ID The ID of the comment for which to print the excerpt. Optional.
  */
-function comment_excerpt() {
-       echo apply_filters('comment_excerpt', get_comment_excerpt() );
+function comment_excerpt( $comment_ID = 0 ) {
+       echo apply_filters('comment_excerpt', get_comment_excerpt($comment_ID) );
 }
 
 /**
@@ -433,7 +453,7 @@ function get_comment_ID() {
  * Displays the comment id of the current comment.
  *
  * @since 0.71
- * @see get_comment_ID() Echos Result
+ * @see get_comment_ID() Echoes Result
  */
 function comment_ID() {
        echo get_comment_ID();
@@ -492,10 +512,11 @@ function get_comment_link( $comment = null, $args = array() ) {
  *
  * @since 1.5.0
  *
+ * @param int $post_id Optional post id
  * @return string The link to the comments
  */
-function get_comments_link() {
-       return get_permalink() . '#comments';
+function get_comments_link($post_id = 0) {
+       return get_permalink($post_id) . '#comments';
 }
 
 /**
@@ -504,9 +525,13 @@ function get_comments_link() {
  * @since 0.71
  *
  * @param string $deprecated Not Used
- * @param bool $deprecated Not Used
+ * @param bool $deprecated_2 Not Used
  */
-function comments_link( $deprecated = '', $deprecated = '' ) {
+function comments_link( $deprecated = '', $deprecated_2 = '' ) {
+       if ( !empty( $deprecated ) )
+               _deprecated_argument( __FUNCTION__, '0.72' );
+       if ( !empty( $deprecated_2 ) )
+               _deprecated_argument( __FUNCTION__, '1.3' );
        echo get_comments_link();
 }
 
@@ -520,11 +545,10 @@ function comments_link( $deprecated = '', $deprecated = '' ) {
  * @return int The number of comments a post has
  */
 function get_comments_number( $post_id = 0 ) {
-       global $id;
-       $post_id = (int) $post_id;
+       $post_id = absint( $post_id );
 
        if ( !$post_id )
-               $post_id = (int) $id;
+               $post_id = get_the_ID();
 
        $post = get_post($post_id);
        if ( ! isset($post->comment_count) )
@@ -539,7 +563,6 @@ function get_comments_number( $post_id = 0 ) {
  * Display the language string for the number of comments the current post has.
  *
  * @since 0.71
- * @uses $id
  * @uses apply_filters() Calls the 'comments_number' hook on the output and number of comments respectively.
  *
  * @param string $zero Text for no comments
@@ -548,8 +571,10 @@ function get_comments_number( $post_id = 0 ) {
  * @param string $deprecated Not used.
  */
 function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
-       global $id;
-       $number = get_comments_number($id);
+       if ( !empty( $deprecated ) )
+               _deprecated_argument( __FUNCTION__, '1.3' );
+
+       $number = get_comments_number();
 
        if ( $number > 1 )
                $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
@@ -567,11 +592,12 @@ function comments_number( $zero = false, $one = false, $more = false, $deprecate
  * @since 1.5.0
  * @uses $comment
  *
+ * @param int $comment_ID The ID of the comment for which to get the text. Optional.
  * @return string The comment content
  */
-function get_comment_text() {
-       global $comment;
-       return apply_filters('get_comment_text', $comment->comment_content);
+function get_comment_text( $comment_ID = 0 ) {
+       $comment = get_comment( $comment_ID );
+       return apply_filters( 'get_comment_text', $comment->comment_content, $comment );
 }
 
 /**
@@ -580,9 +606,12 @@ function get_comment_text() {
  * @since 0.71
  * @uses apply_filters() Passes the comment content through the 'comment_text' hook before display
  * @uses get_comment_text() Gets the comment content
+ *
+ * @param int $comment_ID The ID of the comment for which to print the text. Optional.
  */
-function comment_text() {
-       echo apply_filters('comment_text', get_comment_text() );
+function comment_text( $comment_ID = 0 ) {
+       $comment = get_comment( $comment_ID );
+       echo apply_filters( 'comment_text', get_comment_text( $comment_ID ), $comment );
 }
 
 /**
@@ -625,11 +654,11 @@ function comment_time( $d = '' ) {
  * @uses $comment
  * @uses apply_filters() Calls the 'get_comment_type' hook on the comment type
  *
+ * @param int $comment_ID The ID of the comment for which to get the type. Optional.
  * @return string The comment type
  */
-function get_comment_type() {
-       global $comment;
-
+function get_comment_type( $comment_ID = 0 ) {
+       $comment = get_comment( $comment_ID );
        if ( '' == $comment->comment_type )
                $comment->comment_type = 'comment';
 
@@ -646,9 +675,9 @@ function get_comment_type() {
  * @param string $pingbacktxt The string to display for pingback type
  */
 function comment_type($commenttxt = false, $trackbacktxt = false, $pingbacktxt = false) {
-    if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
-    if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
-    if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
+       if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
+       if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
+       if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
        $type = get_comment_type();
        switch( $type ) {
                case 'trackback' :
@@ -671,16 +700,14 @@ function comment_type($commenttxt = false, $trackbacktxt = false, $pingbacktxt =
  *
  * @since 1.5.0
  * @uses apply_filters() Calls 'trackback_url' on the resulting trackback URL
- * @uses $id
  *
  * @return string The trackback URL after being filtered
  */
 function get_trackback_url() {
-       global $id;
        if ( '' != get_option('permalink_structure') ) {
                $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
        } else {
-               $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . $id;
+               $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
        }
        return apply_filters('trackback_url', $tb_url);
 }
@@ -691,36 +718,46 @@ function get_trackback_url() {
  * @since 0.71
  * @uses get_trackback_url() Gets the trackback url for the current post
  *
- * @param bool $deprecated Remove backwards compat in 2.5
+ * @param bool $deprecated_echo Remove backwards compat in 2.5
  * @return void|string Should only be used to echo the trackback URL, use get_trackback_url() for the result instead.
  */
-function trackback_url($deprecated = true) {
-       if ($deprecated) echo get_trackback_url();
-       else return get_trackback_url();
+function trackback_url( $deprecated_echo = true ) {
+       if ( $deprecated_echo !== true )
+               _deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') );
+       if ( $deprecated_echo )
+               echo get_trackback_url();
+       else
+               return get_trackback_url();
 }
 
 /**
  * Generates and displays the RDF for the trackback information of current post.
  *
+ * Deprecated in 3.0.0, and restored in 3.0.1.
+ *
  * @since 0.71
  *
  * @param int $deprecated Not used (Was $timezone = 0)
  */
-function trackback_rdf($deprecated = '') {
-       if (stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') === false) {
-               echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-                               xmlns:dc="http://purl.org/dc/elements/1.1/"
-                               xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
-                       <rdf:Description rdf:about="';
-               the_permalink();
-               echo '"'."\n";
-               echo '    dc:identifier="';
-               the_permalink();
-               echo '"'."\n";
-               echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
-               echo '    trackback:ping="'.get_trackback_url().'"'." />\n";
-               echo '</rdf:RDF>';
-       }
+function trackback_rdf( $deprecated = '' ) {
+       if ( !empty( $deprecated ) )
+               _deprecated_argument( __FUNCTION__, '2.5' );
+
+       if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') )
+               return;
+
+       echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+                       xmlns:dc="http://purl.org/dc/elements/1.1/"
+                       xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
+               <rdf:Description rdf:about="';
+       the_permalink();
+       echo '"'."\n";
+       echo '    dc:identifier="';
+       the_permalink();
+       echo '"'."\n";
+       echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
+       echo '    trackback:ping="'.get_trackback_url().'"'." />\n";
+       echo '</rdf:RDF>';
 }
 
 /**
@@ -795,14 +832,13 @@ function wp_comment_form_unfiltered_html_nonce() {
  *
  * The $file path is passed through a filter hook called, 'comments_template'
  * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
- * first and if it fails it will require the default comment themplate from the
+ * first and if it fails it will require the default comment template from the
  * default theme. If either does not exist, then the WordPress process will be
  * halted. It is advised for that reason, that the default theme is not deleted.
  *
  * @since 1.5.0
  * @global array $comment List of comment objects for the current post
  * @uses $wpdb
- * @uses $id
  * @uses $post
  * @uses $withcomments Will not try to get the comments if the post has none.
  *
@@ -877,8 +913,8 @@ function comments_template( $file = '/comments.php', $separate_comments = false
                require( $include );
        elseif ( file_exists( TEMPLATEPATH . $file ) )
                require( TEMPLATEPATH .  $file );
-       else
-               require( get_theme_root() . '/default/comments.php');
+       else // Backward compat code will be removed in a future release
+               require( ABSPATH . WPINC . '/theme-compat/comments.php');
 }
 
 /**
@@ -892,7 +928,7 @@ function comments_template( $file = '/comments.php', $separate_comments = false
  *
  * @since 0.71
  * @global string $wpcommentspopupfile The URL to use for the popup window
- * @global int $wpcommentsjavascript Whether to use JavaScript or not. Set when function is called
+ * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called
  *
  * @param int $width Optional. The width of the popup window
  * @param int $height Optional. The height of the popup window
@@ -919,7 +955,6 @@ function comments_popup_script($width=400, $height=400, $file='') {
  * lists of posts
  *
  * @since 0.71
- * @uses $id
  * @uses $wpcommentspopupfile
  * @uses $wpcommentsjavascript
  * @uses $post
@@ -932,12 +967,14 @@ function comments_popup_script($width=400, $height=400, $file='') {
  * @return null Returns null on single posts and pages.
  */
 function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
-       global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post;
+       global $wpcommentspopupfile, $wpcommentsjavascript;
+
+       $id = get_the_ID();
 
-    if ( false === $zero ) $zero = __( 'No Comments' );
-    if ( false === $one ) $one = __( '1 Comment' );
-    if ( false === $more ) $more = __( '% Comments' );
-    if ( false === $none ) $none = __( 'Comments Off' );
+       if ( false === $zero ) $zero = __( 'No Comments' );
+       if ( false === $one ) $one = __( '1 Comment' );
+       if ( false === $more ) $more = __( '% Comments' );
+       if ( false === $none ) $none = __( 'Comments Off' );
 
        $number = get_comments_number( $id );
 
@@ -947,14 +984,14 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
        }
 
        if ( post_password_required() ) {
-               echo __('Enter your password to view comments');
+               echo __('Enter your password to view comments.');
                return;
        }
 
        echo '<a href="';
        if ( $wpcommentsjavascript ) {
                if ( empty( $wpcommentspopupfile ) )
-                       $home = get_option('home');
+                       $home = home_url();
                else
                        $home = get_option('siteurl');
                echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
@@ -970,12 +1007,12 @@ function comments_popup_link( $zero = false, $one = false, $more = false, $css_c
        if ( !empty( $css_class ) ) {
                echo ' class="'.$css_class.'" ';
        }
-       $title = the_title_attribute( 'echo=0' );
+       $title = the_title_attribute( array('echo' => 0 ) );
 
        echo apply_filters( 'comments_popup_link_attributes', '' );
 
        echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
-       comments_number( $zero, $one, $more, $number );
+       comments_number( $zero, $one, $more );
        echo '</a>';
 }
 
@@ -1010,6 +1047,8 @@ function get_comment_reply_link($args = array(), $comment = null, $post = null)
        extract($args, EXTR_SKIP);
 
        $comment = get_comment($comment);
+       if ( empty($post) )
+               $post = $comment->comment_post_ID;
        $post = get_post($post);
 
        if ( !comments_open($post->ID) )
@@ -1020,7 +1059,7 @@ function get_comment_reply_link($args = array(), $comment = null, $post = null)
        if ( get_option('comment_registration') && !$user_ID )
                $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>';
        else
-               $link = "<a rel='nofollow' class='comment-reply-link' href='" . esc_url( 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>";
+               $link = "<a class='comment-reply-link' href='" . esc_url( 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);
 }
 
@@ -1117,16 +1156,30 @@ function cancel_comment_reply_link($text = '') {
 }
 
 /**
- * Output hidden input HTML for replying to comments.
+ * Retrieve hidden input HTML for replying to comments.
  *
- * @since 2.7.0
+ * @since 3.0.0
+ *
+ * @return string Hidden input HTML for replying to comments
  */
-function comment_id_fields() {
-       global $id;
+function get_comment_id_fields( $id = 0 ) {
+       if ( empty( $id ) )
+               $id = get_the_ID();
 
        $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
-       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";
+       $result  = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
+       $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
+       return apply_filters('comment_id_fields', $result, $id, $replytoid);
+}
+
+/**
+ * Output hidden input HTML for replying to comments.
+ *
+ * @since 2.7.0
+ * @see get_comment_id_fields() Echoes result
+ */
+function comment_id_fields( $id = 0 ) {
+       echo get_comment_id_fields( $id );
 }
 
 /**
@@ -1160,26 +1213,26 @@ function comment_form_title( $noreplytext = false, $replytext = false, $linktopa
  *
  * @package WordPress
  * @uses Walker
- * @since unknown
+ * @since 2.7.0
  */
 class Walker_Comment extends Walker {
        /**
         * @see Walker::$tree_type
-        * @since unknown
+        * @since 2.7.0
         * @var string
         */
        var $tree_type = 'comment';
 
        /**
         * @see Walker::$db_fields
-        * @since unknown
+        * @since 2.7.0
         * @var array
         */
        var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
 
        /**
         * @see Walker::start_lvl()
-        * @since unknown
+        * @since 2.7.0
         *
         * @param string $output Passed by reference. Used to append additional content.
         * @param int $depth Depth of comment.
@@ -1203,7 +1256,7 @@ class Walker_Comment extends Walker {
 
        /**
         * @see Walker::end_lvl()
-        * @since unknown
+        * @since 2.7.0
         *
         * @param string $output Passed by reference. Used to append additional content.
         * @param int $depth Depth of comment.
@@ -1225,9 +1278,48 @@ class Walker_Comment extends Walker {
                }
        }
 
+       /**
+        * This function is designed to enhance Walker::display_element() to
+        * display children of higher nesting levels than selected inline on
+        * the highest depth level displayed. This prevents them being orphaned
+        * at the end of the comment list.
+        *
+        * Example: max_depth = 2, with 5 levels of nested content.
+        * 1
+        *  1.1
+        *    1.1.1
+        *    1.1.1.1
+        *    1.1.1.1.1
+        *    1.1.2
+        *    1.1.2.1
+        * 2
+        *  2.2
+        *
+        */
+       function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
+
+               if ( !$element )
+                       return;
+
+               $id_field = $this->db_fields['id'];
+               $id = $element->$id_field;
+
+               parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
+
+               // If we're at the max depth, and the current element still has children, loop over those and display them at this level
+               // This is to prevent them being orphaned to the end of the list.
+               if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
+                       foreach ( $children_elements[ $id ] as $child )
+                               $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
+
+                       unset( $children_elements[ $id ] );
+               }
+
+       }
+
        /**
         * @see Walker::start_el()
-        * @since unknown
+        * @since 2.7.0
         *
         * @param string $output Passed by reference. Used to append additional content.
         * @param object $comment Comment data object.
@@ -1263,11 +1355,16 @@ class Walker_Comment extends Walker {
                <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
                </div>
 <?php if ($comment->comment_approved == '0') : ?>
-               <em><?php _e('Your comment is awaiting moderation.') ?></em>
+               <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
                <br />
 <?php endif; ?>
 
-               <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'&nbsp;&nbsp;','') ?></div>
+               <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
+                       <?php
+                               /* translators: 1: date, 2: time */
+                               printf( __('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'&nbsp;&nbsp;','' );
+                       ?>
+               </div>
 
                <?php comment_text() ?>
 
@@ -1282,7 +1379,7 @@ class Walker_Comment extends Walker {
 
        /**
         * @see Walker::end_el()
-        * @since unknown
+        * @since 2.7.0
         *
         * @param string $output Passed by reference. Used to append additional content.
         * @param object $comment
@@ -1372,7 +1469,7 @@ function wp_list_comments($args = array(), $comments = null ) {
                if ( empty($overridden_cpage) ) {
                        $r['page'] = get_query_var('cpage');
                } else {
-                       $threaded = ( -1 == $r['max_depth'] ) ? false : true;
+                       $threaded = ( -1 != $r['max_depth'] );
                        $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
                        set_query_var( 'cpage', $r['page'] );
                }
@@ -1383,7 +1480,7 @@ function wp_list_comments($args = array(), $comments = null ) {
                $r['page'] = 1;
 
        if ( null === $r['reverse_top_level'] )
-               $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') ) ? TRUE : FALSE;
+               $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );
 
        extract( $r, EXTR_SKIP );
 
@@ -1396,4 +1493,100 @@ function wp_list_comments($args = array(), $comments = null ) {
        $in_comment_loop = false;
 }
 
+/**
+ * Outputs a complete commenting form for use within a template.
+ * Most strings and form fields may be controlled through the $args array passed
+ * into the function, while you may also choose to use the comment_form_default_fields
+ * filter to modify the array of default fields if you'd just like to add a new
+ * one or remove a single field. All fields are also individually passed through
+ * a filter of the form comment_form_field_$name where $name is the key used
+ * in the array of fields.
+ *
+ * @since 3.0.0
+ * @param array $args Options for strings, fields etc in the form
+ * @param mixed $post_id Post ID to generate the form for, uses the current post if null
+ * @return void
+ */
+function comment_form( $args = array(), $post_id = null ) {
+       global $id;
+
+       if ( null === $post_id )
+               $post_id = $id;
+       else
+               $id = $post_id;
+
+       $commenter = wp_get_current_commenter();
+       $user = wp_get_current_user();
+       $user_identity = ! empty( $user->ID ) ? $user->display_name : '';
+
+       $req = get_option( 'require_name_email' );
+       $aria_req = ( $req ? " aria-required='true'" : '' );
+       $fields =  array(
+               'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
+                           '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30"' . $aria_req . ' /></p>',
+               'email'  => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . '</label> ' . ( $req ? '<span class="required">*</span>' : '' ) .
+                           '<input id="email" name="email" type="text" value="' . esc_attr(  $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></p>',
+               'url'    => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label>' .
+                           '<input id="url" name="url" type="text" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',
+       );
+
+       $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' );
+       $defaults = array(
+               'fields'               => apply_filters( 'comment_form_default_fields', $fields ),
+               'comment_field'        => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label><textarea id="comment" name="comment" cols="45" rows="8" aria-required="true"></textarea></p>',
+               'must_log_in'          => '<p class="must-log-in">' .  sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
+               'logged_in_as'         => '<p class="logged-in-as">' . sprintf( __( 'Logged in as <a href="%1$s">%2$s</a>. <a href="%3$s" title="Log out of this account">Log out?</a>' ), admin_url( 'profile.php' ), $user_identity, wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>',
+               'comment_notes_before' => '<p class="comment-notes">' . __( 'Your email address will not be published.' ) . ( $req ? $required_text : '' ) . '</p>',
+               'comment_notes_after'  => '<p class="form-allowed-tags">' . sprintf( __( 'You may use these <abbr title="HyperText Markup Language">HTML</abbr> tags and attributes: %s' ), ' <code>' . allowed_tags() . '</code>' ) . '</p>',
+               'id_form'              => 'commentform',
+               'id_submit'            => 'submit',
+               'title_reply'          => __( 'Leave a Reply' ),
+               'title_reply_to'       => __( 'Leave a Reply to %s' ),
+               'cancel_reply_link'    => __( 'Cancel reply' ),
+               'label_submit'         => __( 'Post Comment' ),
+       );
+
+       $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
+
+       ?>
+               <?php if ( comments_open() ) : ?>
+                       <?php do_action( 'comment_form_before' ); ?>
+                       <div id="respond">
+                               <h3 id="reply-title"><?php comment_form_title( $args['title_reply'], $args['title_reply_to'] ); ?> <small><?php cancel_comment_reply_link( $args['cancel_reply_link'] ); ?></small></h3>
+                               <?php if ( get_option( 'comment_registration' ) && !is_user_logged_in() ) : ?>
+                                       <?php echo $args['must_log_in']; ?>
+                                       <?php do_action( 'comment_form_must_log_in_after' ); ?>
+                               <?php else : ?>
+                                       <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>">
+                                               <?php do_action( 'comment_form_top' ); ?>
+                                               <?php if ( is_user_logged_in() ) : ?>
+                                                       <?php echo apply_filters( 'comment_form_logged_in', $args['logged_in_as'], $commenter, $user_identity ); ?>
+                                                       <?php do_action( 'comment_form_logged_in_after', $commenter, $user_identity ); ?>
+                                               <?php else : ?>
+                                                       <?php echo $args['comment_notes_before']; ?>
+                                                       <?php
+                                                       do_action( 'comment_form_before_fields' );
+                                                       foreach ( (array) $args['fields'] as $name => $field ) {
+                                                               echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
+                                                       }
+                                                       do_action( 'comment_form_after_fields' );
+                                                       ?>
+                                               <?php endif; ?>
+                                               <?php echo apply_filters( 'comment_form_field_comment', $args['comment_field'] ); ?>
+                                               <?php echo $args['comment_notes_after']; ?>
+                                               <p class="form-submit">
+                                                       <input name="submit" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
+                                                       <?php comment_id_fields( $post_id ); ?>
+                                               </p>
+                                               <?php do_action( 'comment_form', $post_id ); ?>
+                                       </form>
+                               <?php endif; ?>
+                       </div><!-- #respond -->
+                       <?php do_action( 'comment_form_after' ); ?>
+               <?php else : ?>
+                       <?php do_action( 'comment_form_comments_closed' ); ?>
+               <?php endif; ?>
+       <?php
+}
+
 ?>