feed-rss2-comments.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /**
  3. * RSS2 Feed Template for displaying RSS2 Comments feed.
  4. *
  5. * @package WordPress
  6. */
  7. header( 'Content-Type: ' . feed_content_type( 'rss2' ) . '; 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', 'rss2-comments' );
  11. ?>
  12. <rss version="2.0"
  13. xmlns:content="http://purl.org/rss/1.0/modules/content/"
  14. xmlns:dc="http://purl.org/dc/elements/1.1/"
  15. xmlns:atom="http://www.w3.org/2005/Atom"
  16. xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
  17. <?php
  18. /** This action is documented in wp-includes/feed-rss2.php */
  19. do_action( 'rss2_ns' );
  20. ?>
  21. <?php
  22. /**
  23. * Fires at the end of the RSS root to add namespaces.
  24. *
  25. * @since 2.8.0
  26. */
  27. do_action( 'rss2_comments_ns' );
  28. ?>
  29. >
  30. <channel>
  31. <title>
  32. <?php
  33. if ( is_singular() ) {
  34. /* translators: Comments feed title. %s: Post title. */
  35. printf( ent2ncr( __( 'Comments on: %s' ) ), get_the_title_rss() );
  36. } elseif ( is_search() ) {
  37. /* translators: Comments feed title. 1: Site title, 2: Search query. */
  38. printf( ent2ncr( __( 'Comments for %1$s searching on %2$s' ) ), get_bloginfo_rss( 'name' ), get_search_query() );
  39. } else {
  40. /* translators: Comments feed title. %s: Site title. */
  41. printf( ent2ncr( __( 'Comments for %s' ) ), get_wp_title_rss() );
  42. }
  43. ?>
  44. </title>
  45. <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
  46. <link><?php ( is_single() ) ? the_permalink_rss() : bloginfo_rss( 'url' ); ?></link>
  47. <description><?php bloginfo_rss( 'description' ); ?></description>
  48. <lastBuildDate><?php echo get_feed_build_date( 'r' ); ?></lastBuildDate>
  49. <sy:updatePeriod>
  50. <?php
  51. /** This filter is documented in wp-includes/feed-rss2.php */
  52. echo apply_filters( 'rss_update_period', 'hourly' );
  53. ?>
  54. </sy:updatePeriod>
  55. <sy:updateFrequency>
  56. <?php
  57. /** This filter is documented in wp-includes/feed-rss2.php */
  58. echo apply_filters( 'rss_update_frequency', '1' );
  59. ?>
  60. </sy:updateFrequency>
  61. <?php
  62. /**
  63. * Fires at the end of the RSS2 comment feed header.
  64. *
  65. * @since 2.3.0
  66. */
  67. do_action( 'commentsrss2_head' );
  68. while ( have_comments() ) :
  69. the_comment();
  70. $comment_post = get_post( $comment->comment_post_ID );
  71. $GLOBALS['post'] = $comment_post;
  72. ?>
  73. <item>
  74. <title>
  75. <?php
  76. if ( ! is_singular() ) {
  77. $title = get_the_title( $comment_post->ID );
  78. /** This filter is documented in wp-includes/feed.php */
  79. $title = apply_filters( 'the_title_rss', $title );
  80. /* translators: Individual comment title. 1: Post title, 2: Comment author name. */
  81. printf( ent2ncr( __( 'Comment on %1$s by %2$s' ) ), $title, get_comment_author_rss() );
  82. } else {
  83. /* translators: Comment author title. %s: Comment author name. */
  84. printf( ent2ncr( __( 'By: %s' ) ), get_comment_author_rss() );
  85. }
  86. ?>
  87. </title>
  88. <link><?php comment_link(); ?></link>
  89. <dc:creator><![CDATA[<?php echo get_comment_author_rss(); ?>]]></dc:creator>
  90. <pubDate><?php echo mysql2date( 'D, d M Y H:i:s +0000', get_comment_time( 'Y-m-d H:i:s', true, false ), false ); ?></pubDate>
  91. <guid isPermaLink="false"><?php comment_guid(); ?></guid>
  92. <?php if ( post_password_required( $comment_post ) ) : ?>
  93. <description><?php echo ent2ncr( __( 'Protected Comments: Please enter your password to view comments.' ) ); ?></description>
  94. <content:encoded><![CDATA[<?php echo get_the_password_form(); ?>]]></content:encoded>
  95. <?php else : ?>
  96. <description><![CDATA[<?php comment_text_rss(); ?>]]></description>
  97. <content:encoded><![CDATA[<?php comment_text(); ?>]]></content:encoded>
  98. <?php endif; // End if post_password_required(). ?>
  99. <?php
  100. /**
  101. * Fires at the end of each RSS2 comment feed item.
  102. *
  103. * @since 2.1.0
  104. *
  105. * @param int $comment_ID The ID of the comment being displayed.
  106. * @param int $ID The ID of the post the comment is connected to.
  107. */
  108. do_action( 'commentrss2_item', $comment->comment_ID, $comment_post->ID );
  109. ?>
  110. </item>
  111. <?php endwhile; ?>
  112. </channel>
  113. </rss>