Skip to content

Commit 555703d

Browse files
committed
Add an experimental rssjs feed based on the experimental rss.js spec.
This is simply a JSON representation of the RSS 2.0 feed, accessible at /feed/rssjs/ anywhere. props pento. see #25639. git-svn-id: https://develop.svn.wordpress.org/trunk@26294 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9df3f0f commit 555703d

8 files changed

Lines changed: 258 additions & 5 deletions

File tree

src/wp-includes/class-wp.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class WP {
1515
* @access public
1616
* @var array
1717
*/
18-
var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type');
18+
var $public_query_vars = array('m', 'p', 'posts', 'w', 'cat', 'withcomments', 'withoutcomments', 's', 'search', 'exact', 'sentence', 'calendar', 'page', 'paged', 'more', 'tb', 'pb', 'author', 'order', 'orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'tag', 'feed', 'author_name', 'static', 'pagename', 'page_id', 'error', 'comments_popup', 'attachment', 'attachment_id', 'subpost', 'subpost_id', 'preview', 'robots', 'taxonomy', 'term', 'cpage', 'post_type', 'callback');
1919

2020
/**
2121
* Private query variables.

src/wp-includes/default-filters.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
add_action( 'do_feed_rss', 'do_feed_rss', 10, 1 );
238238
add_action( 'do_feed_rss2', 'do_feed_rss2', 10, 1 );
239239
add_action( 'do_feed_atom', 'do_feed_atom', 10, 1 );
240+
add_action( 'do_feed_rssjs', 'do_feed_rssjs', 10, 1 );
240241
add_action( 'do_pings', 'do_all_pings', 10, 1 );
241242
add_action( 'do_robots', 'do_robots' );
242243
add_action( 'set_comment_cookies', 'wp_set_comment_cookies', 10, 2 );
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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' );

src/wp-includes/feed-rssjs.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
/**
3+
* rss.js Feed Template for displaying rss.js Posts 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+
$json->rss->channel->title = get_bloginfo( 'name' );
17+
$json->rss->channel->link = get_bloginfo( 'url' );
18+
$json->rss->channel->description = get_bloginfo( 'description' );
19+
$json->rss->channel->language = get_bloginfo( 'language' );
20+
$json->rss->channel->lastBuildDate = mysql2date( 'D, d M Y H:i:s +0000', get_lastpostmodified( 'GMT' ), false );
21+
$json->rss->channel->docs = "http://cyber.law.harvard.edu/rss/rss.html";
22+
$json->rss->channel->generator = 'WordPress ' . get_bloginfo( 'version' );
23+
$json->rss->channel->ttl = 15;
24+
25+
$json->rss->channel->item = array();
26+
27+
header( 'Content-Type: ' . feed_content_type( 'rssjs' ) . '; charset=' . get_option( 'blog_charset' ), true );
28+
29+
/*
30+
* The JSONP callback function to add to the JSON feed
31+
*
32+
* @since 3.8.0
33+
*
34+
* @param string $callback The JSONP callback function name
35+
*/
36+
$callback = apply_filters( 'json_feed_callback', get_query_var( 'callback' ) );
37+
38+
if ( ! empty( $callback ) && ! apply_filters( 'json_jsonp_enabled', true ) ) {
39+
status_header( 400 );
40+
echo json_encode( array(
41+
'code' => 'json_callback_disabled',
42+
'message' => 'JSONP support is disabled on this site.'
43+
) );
44+
exit;
45+
}
46+
47+
if ( preg_match( '/\W/', $callback ) ) {
48+
status_header( 400 );
49+
echo json_encode( array(
50+
'code' => 'json_callback_invalid',
51+
'message' => 'The JSONP callback function is invalid.'
52+
) );
53+
exit;
54+
}
55+
56+
/*
57+
* Action triggerd prior to the JSON feed being created and sent to the client
58+
*
59+
* @since 3.8.0
60+
*/
61+
do_action( 'json_feed_pre' );
62+
63+
while( have_posts() ) {
64+
the_post();
65+
66+
$item = new stdClass();
67+
68+
$item->title = get_the_title();
69+
$item->link = get_permalink();
70+
$item->guid = get_the_guid();
71+
$item->description = get_the_content();
72+
$item->pubDate = mysql2date( 'D, d M Y H:i:s +0000', get_post_time( 'Y-m-d H:i:s', true ), false );
73+
74+
/*
75+
* The item to be added to the rss.js Post feed
76+
*
77+
* @since 3.8.0
78+
*
79+
* @param object $item The rss.js Post item
80+
*/
81+
$item = apply_filters( 'rssjs_feed_item', $item );
82+
83+
$json->rss->channel->item[] = $item;
84+
}
85+
86+
/*
87+
* The data to be sent to the user as JSON
88+
*
89+
* @since 3.8.0
90+
*
91+
* @param object $json The JSON data object
92+
*/
93+
$json = apply_filters( 'rssjs_feed', $json );
94+
95+
96+
$json_str = json_encode( $json );
97+
98+
if ( ! empty( $callback ) ) {
99+
echo "$callback( $json_str );";
100+
} else {
101+
echo $json_str;
102+
}
103+
104+
/*
105+
* Action triggerd after the JSON feed has been created and sent to the client
106+
*
107+
* @since 3.8.0
108+
*/
109+
do_action( 'json_feed_post' );

src/wp-includes/feed.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,8 @@ function feed_content_type( $type = '' ) {
507507
'rss2' => 'application/rss+xml',
508508
'rss-http' => 'text/xml',
509509
'atom' => 'application/atom+xml',
510-
'rdf' => 'application/rdf+xml'
510+
'rdf' => 'application/rdf+xml',
511+
'rssjs' => 'application/json',
511512
);
512513

513514
$content_type = ( !empty($types[$type]) ) ? $types[$type] : 'application/octet-stream';

src/wp-includes/functions.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,21 @@ function do_feed_atom( $for_comments ) {
10821082
load_template( ABSPATH . WPINC . '/feed-atom.php' );
10831083
}
10841084

1085+
/**
1086+
* Load either rssjs comment feed or rssjs posts feed.
1087+
*
1088+
* @since 3.8.0
1089+
*
1090+
* @param bool $for_comments True for the comment feed, false for normal feed.
1091+
*/
1092+
function do_feed_rssjs( $for_comments ) {
1093+
if ( $for_comments ) {
1094+
load_template( ABSPATH . WPINC . '/feed-rssjs-comments.php' );
1095+
} else {
1096+
load_template( ABSPATH . WPINC . '/feed-rssjs.php' );
1097+
}
1098+
}
1099+
10851100
/**
10861101
* Display the robots.txt file content.
10871102
*

src/wp-includes/rewrite.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ class WP_Rewrite {
743743
* @access private
744744
* @var array
745745
*/
746-
var $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom' );
746+
var $feeds = array( 'feed', 'rdf', 'rss', 'rss2', 'atom', 'rssjs' );
747747

748748
/**
749749
* Whether permalinks are being used.

src/wp-includes/version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
*
55
* @global string $wp_version
66
*/
7-
$wp_version = '3.8-alpha-26127-src';
7+
$wp_version = '3.8-alpha-26294-src';
88

99
/**
1010
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
1111
*
1212
* @global int $wp_db_version
1313
*/
14-
$wp_db_version = 26148;
14+
$wp_db_version = 26294;
1515

1616
/**
1717
* Holds the TinyMCE version

0 commit comments

Comments
 (0)