wp/wp-includes/feed-atom-comments.php
changeset 9 177826044cd9
parent 7 cf61fcea0001
child 16 a86126ab1dd4
equal deleted inserted replaced
8:c7c34916027a 9:177826044cd9
     3  * Atom Feed Template for displaying Atom Comments feed.
     3  * Atom Feed Template for displaying Atom Comments feed.
     4  *
     4  *
     5  * @package WordPress
     5  * @package WordPress
     6  */
     6  */
     7 
     7 
     8 header('Content-Type: ' . feed_content_type('atom') . '; charset=' . get_option('blog_charset'), true);
     8 header( 'Content-Type: ' . feed_content_type( 'atom' ) . '; charset=' . get_option( 'blog_charset' ), true );
     9 echo '<?xml version="1.0" encoding="' . get_option('blog_charset') . '" ?' . '>';
     9 echo '<?xml version="1.0" encoding="' . get_option( 'blog_charset' ) . '" ?' . '>';
    10 
    10 
    11 /** This action is documented in wp-includes/feed-rss2.php */
    11 /** This action is documented in wp-includes/feed-rss2.php */
    12 do_action( 'rss_tag_pre', 'atom-comments' );
    12 do_action( 'rss_tag_pre', 'atom-comments' );
    13 ?>
    13 ?>
    14 <feed
    14 <feed
    25 		 * @since 2.8.0
    25 		 * @since 2.8.0
    26 		 */
    26 		 */
    27 		do_action( 'atom_comments_ns' );
    27 		do_action( 'atom_comments_ns' );
    28 	?>
    28 	?>
    29 >
    29 >
    30 	<title type="text"><?php
    30 	<title type="text">
    31 		if ( is_singular() ) {
    31 	<?php
    32 			/* translators: Comments feed title. 1: Post title */
    32 	if ( is_singular() ) {
    33 			printf( ent2ncr( __( 'Comments on %s' ) ), get_the_title_rss() );
    33 		/* translators: Comments feed title. %s: Post title */
    34 		} elseif ( is_search() ) {
    34 		printf( ent2ncr( __( 'Comments on %s' ) ), get_the_title_rss() );
    35 			/* translators: Comments feed title. 1: Site name, 2: Search query */
    35 	} elseif ( is_search() ) {
    36 			printf( ent2ncr( __( 'Comments for %1$s searching on %2$s' ) ), get_bloginfo_rss( 'name' ), get_search_query() );
    36 		/* translators: Comments feed title. 1: Site name, 2: Search query */
    37 		} else {
    37 		printf( ent2ncr( __( 'Comments for %1$s searching on %2$s' ) ), get_bloginfo_rss( 'name' ), get_search_query() );
    38 			/* translators: Comments feed title. 1: Site name */
    38 	} else {
    39 			printf( ent2ncr( __( 'Comments for %s' ) ), get_wp_title_rss() );
    39 		/* translators: Comments feed title. %s: Site name */
    40 		}
    40 		printf( ent2ncr( __( 'Comments for %s' ) ), get_wp_title_rss() );
    41 	?></title>
    41 	}
    42 	<subtitle type="text"><?php bloginfo_rss('description'); ?></subtitle>
    42 	?>
       
    43 	</title>
       
    44 	<subtitle type="text"><?php bloginfo_rss( 'description' ); ?></subtitle>
    43 
    45 
    44 	<updated><?php
    46 	<updated><?php echo get_feed_build_date( 'Y-m-d\TH:i:s\Z' ); ?></updated>
    45 		$date = get_lastcommentmodified( 'GMT' );
       
    46 		echo $date ? mysql2date( 'Y-m-d\TH:i:s\Z', $date, false ) : date( 'Y-m-d\TH:i:s\Z' );
       
    47 	?></updated>
       
    48 
    47 
    49 <?php if ( is_singular() ) { ?>
    48 <?php if ( is_singular() ) { ?>
    50 	<link rel="alternate" type="<?php bloginfo_rss('html_type'); ?>" href="<?php comments_link_feed(); ?>" />
    49 	<link rel="alternate" type="<?php bloginfo_rss( 'html_type' ); ?>" href="<?php comments_link_feed(); ?>" />
    51 	<link rel="self" type="application/atom+xml" href="<?php echo esc_url( get_post_comments_feed_link('', 'atom') ); ?>" />
    50 	<link rel="self" type="application/atom+xml" href="<?php echo esc_url( get_post_comments_feed_link( '', 'atom' ) ); ?>" />
    52 	<id><?php echo esc_url( get_post_comments_feed_link('', 'atom') ); ?></id>
    51 	<id><?php echo esc_url( get_post_comments_feed_link( '', 'atom' ) ); ?></id>
    53 <?php } elseif (is_search()) { ?>
    52 <?php } elseif ( is_search() ) { ?>
    54 	<link rel="alternate" type="<?php bloginfo_rss('html_type'); ?>" href="<?php echo home_url() . '?s=' . get_search_query(); ?>" />
    53 	<link rel="alternate" type="<?php bloginfo_rss( 'html_type' ); ?>" href="<?php echo home_url() . '?s=' . get_search_query(); ?>" />
    55 	<link rel="self" type="application/atom+xml" href="<?php echo get_search_comments_feed_link('', 'atom'); ?>" />
    54 	<link rel="self" type="application/atom+xml" href="<?php echo get_search_comments_feed_link( '', 'atom' ); ?>" />
    56 	<id><?php echo get_search_comments_feed_link('', 'atom'); ?></id>
    55 	<id><?php echo get_search_comments_feed_link( '', 'atom' ); ?></id>
    57 <?php } else { ?>
    56 <?php } else { ?>
    58 	<link rel="alternate" type="<?php bloginfo_rss('html_type'); ?>" href="<?php bloginfo_rss('url'); ?>" />
    57 	<link rel="alternate" type="<?php bloginfo_rss( 'html_type' ); ?>" href="<?php bloginfo_rss( 'url' ); ?>" />
    59 	<link rel="self" type="application/atom+xml" href="<?php bloginfo_rss('comments_atom_url'); ?>" />
    58 	<link rel="self" type="application/atom+xml" href="<?php bloginfo_rss( 'comments_atom_url' ); ?>" />
    60 	<id><?php bloginfo_rss('comments_atom_url'); ?></id>
    59 	<id><?php bloginfo_rss( 'comments_atom_url' ); ?></id>
    61 <?php } ?>
    60 <?php } ?>
    62 <?php
    61 <?php
    63 	/**
    62 	/**
    64 	 * Fires at the end of the Atom comment feed header.
    63 	 * Fires at the end of the Atom comment feed header.
    65 	 *
    64 	 *
    66 	 * @since 2.8.0
    65 	 * @since 2.8.0
    67 	 */
    66 	 */
    68 	do_action( 'comments_atom_head' );
    67 	do_action( 'comments_atom_head' );
    69 ?>
    68 ?>
    70 <?php
    69 <?php
    71 if ( have_comments() ) : while ( have_comments() ) : the_comment();
    70 if ( have_comments() ) :
    72 	$comment_post = $GLOBALS['post'] = get_post( $comment->comment_post_ID );
    71 	while ( have_comments() ) :
    73 ?>
    72 		the_comment();
       
    73 		$comment_post = $GLOBALS['post'] = get_post( $comment->comment_post_ID );
       
    74 		?>
    74 	<entry>
    75 	<entry>
    75 		<title><?php
    76 		<title>
    76 			if ( !is_singular() ) {
    77 		<?php
    77 				$title = get_the_title($comment_post->ID);
    78 		if ( ! is_singular() ) {
    78 				/** This filter is documented in wp-includes/feed.php */
    79 			$title = get_the_title( $comment_post->ID );
    79 				$title = apply_filters( 'the_title_rss', $title );
    80 			/** This filter is documented in wp-includes/feed.php */
    80 				/* translators: Individual comment title. 1: Post title, 2: Comment author name */
    81 			$title = apply_filters( 'the_title_rss', $title );
    81 				printf(ent2ncr(__('Comment on %1$s by %2$s')), $title, get_comment_author_rss());
    82 			/* translators: Individual comment title. 1: Post title, 2: Comment author name */
    82 			} else {
    83 			printf( ent2ncr( __( 'Comment on %1$s by %2$s' ) ), $title, get_comment_author_rss() );
    83 				/* translators: Comment author title. 1: Comment author name */
    84 		} else {
    84 				printf(ent2ncr(__('By: %s')), get_comment_author_rss());
    85 			/* translators: Comment author title. %s: Comment author name */
    85 			}
    86 			printf( ent2ncr( __( 'By: %s' ) ), get_comment_author_rss() );
    86 		?></title>
    87 		}
    87 		<link rel="alternate" href="<?php comment_link(); ?>" type="<?php bloginfo_rss('html_type'); ?>" />
    88 		?>
       
    89 			</title>
       
    90 			<link rel="alternate" href="<?php comment_link(); ?>" type="<?php bloginfo_rss( 'html_type' ); ?>" />
    88 
    91 
    89 		<author>
    92 		<author>
    90 			<name><?php comment_author_rss(); ?></name>
    93 			<name><?php comment_author_rss(); ?></name>
    91 			<?php if (get_comment_author_url()) echo '<uri>' . get_comment_author_url() . '</uri>'; ?>
    94 			<?php
       
    95 			if ( get_comment_author_url() ) {
       
    96 				echo '<uri>' . get_comment_author_url() . '</uri>';}
       
    97 			?>
    92 
    98 
    93 		</author>
    99 		</author>
    94 
   100 
    95 		<id><?php comment_guid(); ?></id>
   101 		<id><?php comment_guid(); ?></id>
    96 		<updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_comment_time('Y-m-d H:i:s', true, false), false); ?></updated>
   102 		<updated><?php echo mysql2date( 'Y-m-d\TH:i:s\Z', get_comment_time( 'Y-m-d H:i:s', true, false ), false ); ?></updated>
    97 		<published><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_comment_time('Y-m-d H:i:s', true, false), false); ?></published>
   103 		<published><?php echo mysql2date( 'Y-m-d\TH:i:s\Z', get_comment_time( 'Y-m-d H:i:s', true, false ), false ); ?></published>
    98 <?php if ( post_password_required($comment_post) ) : ?>
   104 		<?php if ( post_password_required( $comment_post ) ) : ?>
    99 		<content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php echo get_the_password_form(); ?>]]></content>
   105 		<content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php echo get_the_password_form(); ?>]]></content>
   100 <?php else : // post pass ?>
   106 	<?php else : // post pass ?>
   101 		<content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php comment_text(); ?>]]></content>
   107 		<content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php comment_text(); ?>]]></content>
   102 <?php endif; // post pass
   108 		<?php
       
   109 	endif; // post pass
   103 	// Return comment threading information (https://www.ietf.org/rfc/rfc4685.txt)
   110 	// Return comment threading information (https://www.ietf.org/rfc/rfc4685.txt)
   104 	if ( $comment->comment_parent == 0 ) : // This comment is top level ?>
   111 	if ( $comment->comment_parent == 0 ) : // This comment is top level
   105 		<thr:in-reply-to ref="<?php the_guid(); ?>" href="<?php the_permalink_rss() ?>" type="<?php bloginfo_rss('html_type'); ?>" />
   112 		?>
   106 <?php else : // This comment is in reply to another comment
   113 	<thr:in-reply-to ref="<?php the_guid(); ?>" href="<?php the_permalink_rss(); ?>" type="<?php bloginfo_rss( 'html_type' ); ?>" />
   107 	$parent_comment = get_comment($comment->comment_parent);
   114 		<?php
   108 	// The rel attribute below and the id tag above should be GUIDs, but WP doesn't create them for comments (unlike posts). Either way, it's more important that they both use the same system
   115 	else : // This comment is in reply to another comment
   109 ?>
   116 		$parent_comment = get_comment( $comment->comment_parent );
   110 		<thr:in-reply-to ref="<?php comment_guid($parent_comment) ?>" href="<?php echo get_comment_link($parent_comment) ?>" type="<?php bloginfo_rss('html_type'); ?>" />
   117 		// The rel attribute below and the id tag above should be GUIDs, but WP doesn't create them for comments (unlike posts). Either way, it's more important that they both use the same system
   111 <?php endif;
   118 		?>
       
   119 		<thr:in-reply-to ref="<?php comment_guid( $parent_comment ); ?>" href="<?php echo get_comment_link( $parent_comment ); ?>" type="<?php bloginfo_rss( 'html_type' ); ?>" />
       
   120 		<?php
       
   121 endif;
   112 	/**
   122 	/**
   113 	 * Fires at the end of each Atom comment feed item.
   123 	 * Fires at the end of each Atom comment feed item.
   114 	 *
   124 	 *
   115 	 * @since 2.2.0
   125 	 * @since 2.2.0
   116 	 *
   126 	 *
   117 	 * @param int $comment_id      ID of the current comment.
   127 	 * @param int $comment_id      ID of the current comment.
   118 	 * @param int $comment_post_id ID of the post the current comment is connected to.
   128 	 * @param int $comment_post_id ID of the post the current comment is connected to.
   119 	 */
   129 	 */
   120 	do_action( 'comment_atom_entry', $comment->comment_ID, $comment_post->ID );
   130 	do_action( 'comment_atom_entry', $comment->comment_ID, $comment_post->ID );
       
   131 	?>
       
   132 	</entry>
       
   133 		<?php
       
   134 	endwhile;
       
   135 endif;
   121 ?>
   136 ?>
   122 	</entry>
       
   123 <?php endwhile; endif; ?>
       
   124 </feed>
   137 </feed>