feed-atom-comments.php 5.3 KB

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