|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * rss.js Feed Template for displaying rss.js Comments feed. |
| 4 | + * |
| 5 | + * @package WordPress |
| 6 | + * @subpackage Feed |
| 7 | + * @since 3.8.0 |
| 8 | + */ |
| 9 | + |
| 10 | +$json = new stdClass(); |
| 11 | +$json->rss = new stdClass(); |
| 12 | + |
| 13 | +$json->rss->version = "2.0"; |
| 14 | +$json->rss->channel = new stdClass(); |
| 15 | + |
| 16 | +if ( is_singular() ) |
| 17 | + $json->rss->channel->title = sprintf( __( 'Comments on: %s' ), get_the_title() ); |
| 18 | +elseif ( is_search() ) |
| 19 | + $json->rss->channel->title = sprintf( __( 'Comments for %1$s searching on %2$s' ), get_bloginfo( 'name' ), get_search_query() ); |
| 20 | +else |
| 21 | + $json->rss->channel->title = sprintf( __( 'Comments for %s' ), get_bloginfo( 'name' ) . get_the_title() ); |
| 22 | + |
| 23 | +$json->rss->channel->link = get_bloginfo( 'url' ); |
| 24 | +$json->rss->channel->description = get_bloginfo( 'description' ); |
| 25 | +$json->rss->channel->language = get_bloginfo( 'language' ); |
| 26 | +$json->rss->channel->lastBuildDate = mysql2date( 'D, d M Y H:i:s +0000', get_lastcommentmodified( 'GMT' ), false ); |
| 27 | +$json->rss->channel->docs = "http://cyber.law.harvard.edu/rss/rss.html"; |
| 28 | +$json->rss->channel->generator = 'WordPress ' . get_bloginfo( 'version' ); |
| 29 | +$json->rss->channel->ttl = 15; |
| 30 | + |
| 31 | +$json->rss->channel->item = array(); |
| 32 | + |
| 33 | +header( 'Content-Type: ' . feed_content_type( 'rssjs' ) . '; charset=' . get_option( 'blog_charset' ), true ); |
| 34 | + |
| 35 | +/* |
| 36 | + * The JSONP callback function to add to the JSON feed |
| 37 | + * |
| 38 | + * @since 3.8.0 |
| 39 | + * |
| 40 | + * @param string $callback The JSONP callback function name |
| 41 | + */ |
| 42 | +$callback = apply_filters( 'json_feed_callback', get_query_var( 'callback' ) ); |
| 43 | + |
| 44 | +if ( ! empty( $callback ) && ! apply_filters( 'json_jsonp_enabled', true ) ) { |
| 45 | + status_header( 400 ); |
| 46 | + echo json_encode( array( |
| 47 | + 'code' => 'json_callback_disabled', |
| 48 | + 'message' => 'JSONP support is disabled on this site.' |
| 49 | + ) ); |
| 50 | + exit; |
| 51 | +} |
| 52 | + |
| 53 | +if ( preg_match( '/\W/', $callback ) ) { |
| 54 | + status_header( 400 ); |
| 55 | + echo json_encode( array( |
| 56 | + 'code' => 'json_callback_invalid', |
| 57 | + 'message' => 'The JSONP callback function is invalid.' |
| 58 | + ) ); |
| 59 | + exit; |
| 60 | +} |
| 61 | + |
| 62 | +/* |
| 63 | + * Action triggerd prior to the JSON feed being created and sent to the client |
| 64 | + * |
| 65 | + * @since 3.8.0 |
| 66 | + */ |
| 67 | +do_action( 'json_feed_pre' ); |
| 68 | + |
| 69 | +while( have_comments() ) { |
| 70 | + the_comment(); |
| 71 | + |
| 72 | + $comment_post = $GLOBALS['post'] = get_post( $comment->comment_post_ID ); |
| 73 | + |
| 74 | + $item = new stdClass(); |
| 75 | + |
| 76 | + if ( !is_singular() ) { |
| 77 | + $title = get_the_title( $comment_post->ID ); |
| 78 | + $item->title = sprintf( __('Comment on %1$s by %2$s') , $title, get_comment_author() ); |
| 79 | + } else { |
| 80 | + $item->title = sprintf( __('By: %s'), get_comment_author() ); |
| 81 | + } |
| 82 | + |
| 83 | + $item->link = get_comment_link(); |
| 84 | + $item->guid = get_comment_guid(); |
| 85 | + $item->pubDate = mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false ); |
| 86 | + |
| 87 | + if ( post_password_required( $comment_post ) ) { |
| 88 | + $item->description = __( 'Protected Comments: Please enter your password to view comments.' ); |
| 89 | + } else { |
| 90 | + $item->description = get_comment_text(); |
| 91 | + } |
| 92 | + |
| 93 | + /* |
| 94 | + * The item to be added to the rss.js Comment feed |
| 95 | + * |
| 96 | + * @since 3.8.0 |
| 97 | + * |
| 98 | + * @param object $item The rss.js Comment item |
| 99 | + */ |
| 100 | + $item = apply_filters( 'comment_rssjs_feed_item', $item ); |
| 101 | + |
| 102 | + $json->rss->channel->item[] = $item; |
| 103 | +} |
| 104 | + |
| 105 | +/* |
| 106 | + * The data to be sent to the user as JSON |
| 107 | + * |
| 108 | + * @since 3.8.0 |
| 109 | + * |
| 110 | + * @param object $json The JSON data object |
| 111 | + */ |
| 112 | +$json = apply_filters( 'comment_rssjs_feed', $json ); |
| 113 | + |
| 114 | +$json_str = json_encode( $json ); |
| 115 | + |
| 116 | +if ( ! empty( $callback ) ) { |
| 117 | + echo "$callback( $json_str );"; |
| 118 | +} else { |
| 119 | + echo $json_str; |
| 120 | +} |
| 121 | + |
| 122 | +/* |
| 123 | + * Action triggerd after the JSON feed has been created and sent to the client |
| 124 | + * |
| 125 | + * @since 3.8.0 |
| 126 | + */ |
| 127 | +do_action( 'json_feed_post' ); |
0 commit comments