]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/comment-template.php
Wordpress 3.6-scripts
[autoinstalls/wordpress.git] / wp-includes / comment-template.php
index 8be25e10d58c208d4fd00f9f75edde02b6976a64..9a09d28d540eaf0e038cf486e3da9fbbadbb612a 100644 (file)
@@ -393,8 +393,8 @@ function comment_date( $d = '', $comment_ID = 0 ) {
 /**
  * Retrieve the excerpt of the current comment.
  *
- * Will cut each word and only output the first 20 words with '...' at the end.
- * If the word count is less than 20, then no truncating is done and no '...'
+ * Will cut each word and only output the first 20 words with '…' at the end.
+ * If the word count is less than 20, then no truncating is done and no '…'
  * will appear.
  *
  * @since 1.5.0
@@ -419,7 +419,7 @@ function get_comment_excerpt( $comment_ID = 0 ) {
        for ($i=0; $i<$k; $i++) {
                $excerpt .= $blah[$i] . ' ';
        }
-       $excerpt .= ($use_dotdotdot) ? '...' : '';
+       $excerpt .= ($use_dotdotdot) ? '&hellip;' : '';
        return apply_filters('get_comment_excerpt', $excerpt);
 }
 
@@ -516,7 +516,7 @@ function get_comment_link( $comment = null, $args = array() ) {
  * @return string The link to the comments
  */
 function get_comments_link($post_id = 0) {
-       return get_permalink($post_id) . '#comments';
+       return apply_filters( 'get_comments_link', get_permalink( $post_id ) . '#comments', $post_id );
 }
 
 /**
@@ -532,7 +532,7 @@ function comments_link( $deprecated = '', $deprecated_2 = '' ) {
                _deprecated_argument( __FUNCTION__, '0.72' );
        if ( !empty( $deprecated_2 ) )
                _deprecated_argument( __FUNCTION__, '1.3' );
-       echo get_comments_link();
+       echo esc_url( get_comments_link() );
 }
 
 /**
@@ -1244,11 +1244,11 @@ class Walker_Comment extends Walker {
                        case 'div':
                                break;
                        case 'ol':
-                               echo "<ol class='children'>\n";
+                               echo '<ol class="children">' . "\n";
                                break;
                        default:
                        case 'ul':
-                               echo "<ul class='children'>\n";
+                               echo '<ul class="children">' . "\n";
                                break;
                }
        }
@@ -1268,11 +1268,11 @@ class Walker_Comment extends Walker {
                        case 'div':
                                break;
                        case 'ol':
-                               echo "</ol>\n";
+                               echo "</ol><!-- .children -->\n";
                                break;
                        default:
                        case 'ul':
-                               echo "</ul>\n";
+                               echo "</ul><!-- .children -->\n";
                                break;
                }
        }
@@ -1295,7 +1295,7 @@ class Walker_Comment extends Walker {
         *  2.2
         *
         */
-       function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
+       function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
 
                if ( !$element )
                        return;
@@ -1325,18 +1325,72 @@ class Walker_Comment extends Walker {
         * @param int $depth Depth of comment in reference to parents.
         * @param array $args
         */
-       function start_el( &$output, $comment, $depth, $args, $id = 0 ) {
+       function start_el( &$output, $comment, $depth = 0, $args = array(), $id = 0 ) {
                $depth++;
                $GLOBALS['comment_depth'] = $depth;
                $GLOBALS['comment'] = $comment;
 
-               if ( !empty($args['callback']) ) {
-                       call_user_func($args['callback'], $comment, $args, $depth);
+               if ( !empty( $args['callback'] ) ) {
+                       call_user_func( $args['callback'], $comment, $args, $depth );
                        return;
                }
 
-               extract($args, EXTR_SKIP);
+               if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
+                       $this->ping( $comment, $depth, $args );
+               } elseif ( 'html5' === $args['format'] ) {
+                       $this->html5_comment( $comment, $depth, $args );
+               } else {
+                       $this->comment( $comment, $depth, $args );
+               }
+       }
+
+       /**
+        * @see Walker::end_el()
+        * @since 2.7.0
+        *
+        * @param string $output Passed by reference. Used to append additional content.
+        * @param object $comment
+        * @param int $depth Depth of comment.
+        * @param array $args
+        */
+       function end_el( &$output, $comment, $depth = 0, $args = array() ) {
+               if ( !empty( $args['end-callback'] ) ) {
+                       call_user_func( $args['end-callback'], $comment, $args, $depth );
+                       return;
+               }
+               if ( 'div' == $args['style'] )
+                       echo "</div><!-- #comment-## -->\n";
+               else
+                       echo "</li><!-- #comment-## -->\n";
+       }
+
+       /**
+        * @since 3.6
+        * @access protected
+        *
+        * @param object $comment
+        * @param int $depth Depth of comment.
+        * @param array $args
+        */
+       protected function ping( $comment, $depth, $args ) {
+               $tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
+?>
+               <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
+                       <div class="comment-body">
+                               <?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
+                       </div>
+<?php
+       }
 
+       /**
+        * @since 3.6
+        * @access protected
+        *
+        * @param object $comment Comment to display.
+        * @param int $depth Depth of comment.
+        * @param array $args Optional args.
+        */
+       protected function comment( $comment, $depth, $args ) {
                if ( 'div' == $args['style'] ) {
                        $tag = 'div';
                        $add_below = 'comment';
@@ -1345,30 +1399,30 @@ class Walker_Comment extends Walker {
                        $add_below = 'div-comment';
                }
 ?>
-               <<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
+               <<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID(); ?>">
                <?php if ( 'div' != $args['style'] ) : ?>
-               <div id="div-comment-<?php comment_ID() ?>" class="comment-body">
+               <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
                <?php endif; ?>
                <div class="comment-author vcard">
-               <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
-               <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
+                       <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
+                       <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
                </div>
-<?php if ($comment->comment_approved == '0') : ?>
-               <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
+               <?php if ( '0' == $comment->comment_approved ) : ?>
+               <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em>
                <br />
-<?php endif; ?>
+               <?php endif; ?>
 
-               <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
+               <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( 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;','' );
+                               printf( __( '%1$s at %2$s' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), '&nbsp;&nbsp;', '' );
                        ?>
                </div>
 
                <?php comment_text() ?>
 
                <div class="reply">
-               <?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
+                       <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
                </div>
                <?php if ( 'div' != $args['style'] ) : ?>
                </div>
@@ -1377,25 +1431,48 @@ class Walker_Comment extends Walker {
        }
 
        /**
-        * @see Walker::end_el()
-        * @since 2.7.0
+        * @since 3.6
+        * @access protected
         *
-        * @param string $output Passed by reference. Used to append additional content.
-        * @param object $comment
+        * @param object $comment Comment to display.
         * @param int $depth Depth of comment.
-        * @param array $args
+        * @param array $args Optional args.
         */
-       function end_el(&$output, $comment, $depth = 0, $args = array() ) {
-               if ( !empty($args['end-callback']) ) {
-                       call_user_func($args['end-callback'], $comment, $args, $depth);
-                       return;
-               }
-               if ( 'div' == $args['style'] )
-                       echo "</div>\n";
-               else
-                       echo "</li>\n";
+       protected function html5_comment( $comment, $depth, $args ) {
+               $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
+?>
+               <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
+                       <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
+                               <footer class="comment-meta">
+                                       <div class="comment-author vcard">
+                                               <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
+                                               <?php printf( __( '%s <span class="says">says:</span>' ), sprintf( '<b class="fn">%s</b>', get_comment_author_link() ) ); ?>
+                                       </div><!-- .comment-author -->
+
+                                       <div class="comment-metadata">
+                                               <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
+                                                       <time datetime="<?php comment_time( 'c' ); ?>">
+                                                               <?php printf( _x( '%1$s at %2$s', '1: date, 2: time' ), get_comment_date(), get_comment_time() ); ?>
+                                                       </time>
+                                               </a>
+                                               <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
+                                       </div><!-- .comment-metadata -->
+
+                                       <?php if ( '0' == $comment->comment_approved ) : ?>
+                                       <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
+                                       <?php endif; ?>
+                               </footer><!-- .comment-meta -->
+
+                               <div class="comment-content">
+                                       <?php comment_text(); ?>
+                               </div><!-- .comment-content -->
+
+                               <div class="reply">
+                                       <?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
+                               </div><!-- .reply -->
+                       </article><!-- .comment-body -->
+<?php
        }
-
 }
 
 /**
@@ -1417,8 +1494,21 @@ function wp_list_comments($args = array(), $comments = null ) {
        $comment_alt = $comment_thread_alt = 0;
        $comment_depth = 1;
 
-       $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
-               'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '');
+       $defaults = array(
+               'walker'            => null,
+               'max_depth'         => '',
+               'style'             => 'ul',
+               'callback'          => null,
+               'end-callback'      => null,
+               'type'              => 'all',
+               'page'              => '',
+               'per_page'          => '',
+               'avatar_size'       => 32,
+               'reverse_top_level' => null,
+               'reverse_children'  => '',
+               'format'            => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
+               'short_ping'        => false,
+       );
 
        $r = wp_parse_args( $args, $defaults );
 
@@ -1507,10 +1597,8 @@ function wp_list_comments($args = array(), $comments = null ) {
  * @return void
  */
 function comment_form( $args = array(), $post_id = null ) {
-       global $id;
-
        if ( null === $post_id )
-               $post_id = $id;
+               $post_id = get_the_ID();
        else
                $id = $post_id;
 
@@ -1518,21 +1606,25 @@ function comment_form( $args = array(), $post_id = null ) {
        $user = wp_get_current_user();
        $user_identity = $user->exists() ? $user->display_name : '';
 
-       $req = get_option( 'require_name_email' );
+       if ( ! isset( $args['format'] ) )
+               $args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
+
+       $req      = get_option( 'require_name_email' );
        $aria_req = ( $req ? " aria-required='true'" : '' );
-       $fields =  array(
+       $html5    = 'html5' === $args['format'];
+       $fields   =  array(
                'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
                            '<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' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' .
-                           '<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>',
+                           '<input id="email" name="email" ' . ( $html5 ? 'type="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" ' . ( $html5 ? 'type="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>',
+               '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>' ), get_edit_user_link(), $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>',
@@ -1543,6 +1635,7 @@ function comment_form( $args = array(), $post_id = null ) {
                'title_reply_to'       => __( 'Leave a Reply to %s' ),
                'cancel_reply_link'    => __( 'Cancel reply' ),
                'label_submit'         => __( 'Post Comment' ),
+               'format'               => 'xhtml',
        );
 
        $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
@@ -1550,13 +1643,13 @@ function comment_form( $args = array(), $post_id = null ) {
        ?>
                <?php if ( comments_open( $post_id ) ) : ?>
                        <?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>
+                       <div id="respond" class="comment-respond">
+                               <h3 id="reply-title" class="comment-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'] ); ?>">
+                                       <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="comment-form"<?php echo $html5 ? ' novalidate' : ''; ?>>
                                                <?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 ); ?>