X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/11be8dc178e77d0b46189bbd8e33a216a9b90942..9c40b4d36daed9e28e48a5fe9205c32557195a4b:/wp-includes/comment-template.php diff --git a/wp-includes/comment-template.php b/wp-includes/comment-template.php index a4a126bc..2b6b60ac 100644 --- a/wp-includes/comment-template.php +++ b/wp-includes/comment-template.php @@ -193,7 +193,8 @@ function comment_author_IP() { */ function get_comment_author_url() { global $comment; - return apply_filters('get_comment_author_url', $comment->comment_author_url); + $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url; + return apply_filters('get_comment_author_url', $url); } /** @@ -292,7 +293,8 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { // If the comment author has an id (registered), then print the log in name if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) { // For all registered users, 'byuser' - $classes[] = 'byuser comment-author-' . $user->user_nicename; + $classes[] = 'byuser'; + $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id); // For comment authors who are the author of the post if ( $post = get_post($post_id) ) { if ( $comment->user_id === $post->post_author ) @@ -351,7 +353,7 @@ function get_comment_class( $class = '', $comment_id = null, $post_id = null ) { function get_comment_date( $d = '' ) { global $comment; if ( '' == $d ) - $date = mysql2date( get_option('date_format'), $comment->comment_date); + $date = mysql2date(get_option('date_format'), $comment->comment_date); else $date = mysql2date($d, $comment->comment_date); return apply_filters('get_comment_date', $date, $d); @@ -442,7 +444,7 @@ function comment_ID() { * * @param object|string|int $comment Comment to retrieve. * @param array $args Optional args. - * @return string The permalink to the current comment + * @return string The permalink to the given comment. */ function get_comment_link( $comment = null, $args = array() ) { global $wp_rewrite, $in_comment_loop; @@ -472,12 +474,14 @@ function get_comment_link( $comment = null, $args = array() ) { $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args ); if ( $wp_rewrite->using_permalinks() ) - return user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' ) . '#comment-' . $comment->comment_ID; + $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' ); else - return add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ) . '#comment-' . $comment->comment_ID; + $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ); } else { - return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; + $link = get_permalink( $comment->comment_post_ID ); } + + return apply_filters( 'get_comment_link', $link . '#comment-' . $comment->comment_ID, $comment, $args ); } /** @@ -587,15 +591,16 @@ function comment_text() { * * @param string $d Optional. The format of the time (defaults to user's config) * @param bool $gmt Whether to use the GMT date + * @param bool $translate Whether to translate the time (for use in feeds) * @return string The formatted time */ -function get_comment_time( $d = '', $gmt = false ) { +function get_comment_time( $d = '', $gmt = false, $translate = true ) { global $comment; $comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date; if ( '' == $d ) - $date = mysql2date(get_option('time_format'), $comment_date); + $date = mysql2date(get_option('time_format'), $comment_date, $translate); else - $date = mysql2date($d, $comment_date); + $date = mysql2date($d, $comment_date, $translate); return apply_filters('get_comment_time', $date, $d, $gmt); } @@ -637,7 +642,10 @@ function get_comment_type() { * @param string $trackbacktxt The string to display for trackback type * @param string $pingbacktxt The string to display for pingback type */ -function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') { +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' ); $type = get_comment_type(); switch( $type ) { case 'trackback' : @@ -814,11 +822,11 @@ function comments_template( $file = '/comments.php', $separate_comments = false /** @todo Use API instead of SELECTs. */ if ( $user_ID) { - $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) ORDER BY comment_date", $post->ID, $user_ID)); + $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, $user_ID)); } else if ( empty($comment_author) ) { - $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_approved = '1' ORDER BY comment_date", $post->ID)); + $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') ); } else { - $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date", $post->ID, $comment_author, $comment_author_email)); + $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email)); } // keep $comments for legacy's sake @@ -838,7 +846,8 @@ function comments_template( $file = '/comments.php', $separate_comments = false $overridden_cpage = TRUE; } - define('COMMENTS_TEMPLATE', true); + if ( !defined('COMMENTS_TEMPLATE') || !COMMENTS_TEMPLATE) + define('COMMENTS_TEMPLATE', true); $include = apply_filters('comments_template', STYLESHEETPATH . $file ); if ( file_exists( $include ) ) @@ -899,15 +908,17 @@ function comments_popup_script($width=400, $height=400, $file='') { * @param string $none The string to display when comments have been turned off * @return null Returns null on single posts and pages. */ -function comments_popup_link( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $css_class = '', $none = 'Comments Off' ) { +function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) { global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post; - if ( is_single() || is_page() ) - return; + 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 ); - if ( 0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status ) { + if ( 0 == $number && !comments_open() && !pings_open() ) { echo '' . $none . ''; return; } @@ -936,7 +947,7 @@ function comments_popup_link( $zero = 'No Comments', $one = '1 Comment', $more = if ( !empty( $css_class ) ) { echo ' class="'.$css_class.'" '; } - $title = attribute_escape( get_the_title() ); + $title = esc_attr( get_the_title() ); echo apply_filters( 'comments_popup_link_attributes', '' ); @@ -978,15 +989,15 @@ function get_comment_reply_link($args = array(), $comment = null, $post = null) $comment = get_comment($comment); $post = get_post($post); - if ( 'open' != $post->comment_status ) + if ( !comments_open($post->ID) ) return false; $link = ''; if ( get_option('comment_registration') && !$user_ID ) - $link = '' . $login_text . ''; + $link = '' . $login_text . ''; else - $link = "comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text"; + $link = "comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text"; return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post); } @@ -1030,12 +1041,12 @@ function get_post_reply_link($args = array(), $post = null) { $args = wp_parse_args($args, $defaults); extract($args, EXTR_SKIP); $post = get_post($post); - + if ( !comments_open($post->ID) ) return false; if ( get_option('comment_registration') && !$user_ID ) { - $link = '' . $login_text . ''; + $link = '' . $login_text . ''; } else { $link = "$reply_text"; } @@ -1067,7 +1078,7 @@ function get_cancel_comment_reply_link($text = '') { $text = __('Click here to cancel reply.'); $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"'; - $link = wp_specialchars( remove_query_arg('replytocom') ) . '#respond'; + $link = esc_html( remove_query_arg('replytocom') ) . '#respond'; return apply_filters('cancel_comment_reply_link', '' . $text . '', $link, $text); } @@ -1104,9 +1115,12 @@ function comment_id_fields() { * @param string $replytext Optional. Text to display when replying to a comment. Accepts "%s" for the author of the comment being replied to. * @param string $linktoparent Optional. Boolean to control making the author's name a link to their comment. */ -function comment_form_title( $noreplytext = 'Leave a Reply', $replytext = 'Leave a Reply to %s', $linktoparent = TRUE ) { +function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = TRUE ) { global $comment; + if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' ); + if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' ); + $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0; if ( 0 == $replytoid ) @@ -1219,7 +1233,7 @@ class Walker_Comment extends Walker { ?> < id="comment-"> -
+