Changeset 1950873
- Timestamp:
- 10/03/2018 01:36:27 PM (7 years ago)
- Location:
- jsonfeed/trunk
- Files:
-
- 3 added
- 4 edited
-
LICENSE (added)
-
README.md (modified) (1 diff)
-
composer.json (added)
-
feed-template.php (modified) (3 diffs)
-
jsonfeed-wp.php (modified) (2 diffs)
-
phpcs.xml (added)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
jsonfeed/trunk/README.md
r1661151 r1950873 1 # JSON Feed plugin for WordPress2 1 3 Adds a `/feed/json` URL to your WordPress site. Drop the plugin folder in /wp-content/plugins and activate under WP Admin → Plugins. 2 Adds a feed of recent posts in JSON Feed format. 3 4 5 ## Description 6 7 Adds a `/feed/json` URL to your WordPress site. 4 8 5 9 The JSON Feed format is a pragmatic syndication format, like RSS and Atom, but with one big difference: it's JSON instead of XML. Learn more at [jsonfeed.org](http://jsonfeed.org/). 10 11 12 ## Installation 13 14 1. Upload the plugin files to the `/wp-content/plugins/jsonfeed` directory, or install the plugin through the WordPress plugins screen directly. 15 1. Activate the plugin through the 'Plugins' screen in WordPress 16 17 18 ## Frequently Asked Questions 19 20 21 ### What is JSONFeed? 22 23 JSON Feed, a format similar to RSS and Atom but in JSON. JSON has become the developers’ choice for APIs, and that developers will often go out of their way to avoid XML. 24 JSON is simpler to read and write, and it’s less prone to bugs. 25 26 27 ## Changelog 28 29 30 ### 1.2.0 31 * dshanske added as a contributor/maintainer 32 * Add featured image if set 33 * Add site icon if set 34 * home_page_url now actually returns the correct URL instead of always returning the homepage of the site 35 * Add avatar and URL to author 36 * Include site name in feed name in the discovery title 37 * Fix issue with timezone not reflecting on date 38 39 40 ### 1.1.2 41 42 43 ### 1.1.1 44 45 46 ### 1.0 47 * Initial release 48 -
jsonfeed/trunk/feed-template.php
r1679899 r1950873 1 1 <?php 2 2 3 //via http://www.tequilafish.com/2009/02/10/php-how-to-capture-output-of-echo-into-a-local-variable/ 4 ob_start(); 5 self_link(); 6 $self_link = ob_get_contents(); 7 ob_end_clean(); 3 4 // Reproduction of self_link with a return and without URL escaping 5 function get_json_self_link() { 6 $host = wp_parse_url( home_url() ); 7 return apply_filters( 'self_link', set_url_scheme( 'http://' . $host['host'] . wp_unslash( $_SERVER['REQUEST_URI'] ) ) ); 8 } 8 9 9 10 function get_attachment_json_info() { 10 if ( post_password_required() ) 11 if ( post_password_required() ) { 11 12 return null; 13 } 12 14 13 15 foreach ( (array) get_post_custom() as $key => $val ) { 14 if ( $key == 'enclosure') {16 if ( 'enclosure' === $key ) { 15 17 foreach ( (array) $val as $enc ) { 16 $enclosure = explode( "\n", $enc);18 $enclosure = explode( "\n", $enc ); 17 19 18 20 // only get the first element, e.g. audio/mpeg from 'audio/mpeg mpga mp2 mp3' 19 $t = preg_split('/[ \t]/', trim($enclosure[2]) );21 $t = preg_split( '/[ \t]/', trim( $enclosure[2] ) ); 20 22 $type = $t[0]; 21 23 22 24 return array( 23 'url' => trim( $enclosure[0] ),24 'mime_type' => $type,25 'size_in_bytes' => (int) $enclosure[1]25 'url' => trim( $enclosure[0] ), 26 'mime_type' => $type, 27 'size_in_bytes' => (int) $enclosure[1], 26 28 ); 27 29 } 28 30 } 29 31 } 32 } 33 34 function get_link_from_json_feed( $link ) { 35 global $wp_rewrite; 36 $arg = $wp_rewrite->get_feed_permastruct(); 37 // If empty this site does not have pretty permalinks enabled 38 if ( empty( $arg ) ) { 39 wp_parse_str( wp_parse_url( $link, PHP_URL_QUERY ), $query_args ); 40 unset( $query_args['feed'] ); 41 return add_query_arg( $query_args, home_url( '/' ) ); 42 } else { 43 $arg = str_replace( '%feed%', 'json', $arg ); 44 $arg = preg_replace( '#/+#', '/', "/$arg" ); 45 $link = str_replace( $arg, '', $link ); 46 } 47 return $link; 48 } 49 50 function json_get_merged_tags( $post_id = null ) { 51 $post = get_post( $post_id ); 52 $tags = get_the_terms( $post, 'post_tag' ); 53 $categories = get_the_terms( $post, 'category' ); 54 $tags = is_array( $tags ) ? $tags : array(); 55 $categories = is_array( $categories ) ? $categories : array(); 56 // $tags = array_merge( $tags, $categories ); 57 $return = array(); 58 foreach ( $tags as $tag ) { 59 if ( 'uncategorized' !== $tag->slug ) { 60 $return[] = $tag->name; 61 } 62 } 63 return $return; 30 64 } 31 65 … … 36 70 37 71 $feed_item = array( 38 'id' => get_permalink(), 39 'url' => get_permalink(), 40 'title' => get_the_title(), 41 'content_html' => get_the_content_feed( 'json' ), 42 'date_published' => get_gmt_from_date( get_the_date( 'Y-m-d H:i:s' ), 'c' ), 43 'date_modified' => get_gmt_from_date( get_the_modified_date( 'Y-m-d H:i:s' ), 'c' ), 44 'author' => array( 45 'name' => get_the_author(), 72 'id' => get_permalink(), 73 'url' => get_permalink(), 74 'title' => html_entity_decode( get_the_title() ), 75 'content_html' => get_the_content_feed( 'json' ), 76 'content_text' => wp_strip_all_tags( get_the_content_feed( 'json' ) ), 77 'date_published' => get_the_date( 'Y-m-d\TH:i:sP' ), 78 'date_modified' => get_the_modified_date( 'Y-m-d\TH:i:sP' ), 79 'author' => array( 80 'name' => get_the_author(), 81 'url' => get_author_posts_url( get_the_author_meta( 'ID' ) ), 82 'avatar' => get_avatar_url( get_the_author_meta( 'ID' ), array( 'size' => 512 ) ), 46 83 ), 84 'image' => get_the_post_thumbnail_url( null, 'full' ), // If there is a set featured image 85 'tags' => json_get_merged_tags(), // Tags is a merge of the category and the tags names 47 86 ); 48 87 // Only add custom excerpts not generated ones 88 if ( has_excerpt() ) { 89 $feed_item['summary'] = get_the_excerpt(); 90 } 91 // If anything is an empty string or null then remove it 92 $feed_item = array_filter( $feed_item ); 93 49 94 $attachment = get_attachment_json_info(); 50 if ( $attachment != null) {51 $feed_item[ "attachments"] = array(52 $attachment 95 if ( null !== $attachment ) { 96 $feed_item['attachments'] = array( 97 $attachment, 53 98 ); 54 99 } … … 58 103 59 104 $feed_json = array( 60 'version' => 'https://jsonfeed.org/version/1',61 'user_comment' => 'This feed allows you to read the posts from this site in any feed reader that supports the JSON Feed format. To add this feed to your reader, copy the following URL -- ' . $self_link. ' -- and add it your reader.',62 'home_page_url' => get_ home_url(),63 'feed_url' => $self_link,64 'title' => get_bloginfo( 'name' ),65 'description' => get_bloginfo( 'description' ),66 'items' => $feed_items,105 'version' => 'https://jsonfeed.org/version/1', 106 'user_comment' => 'This feed allows you to read the posts from this site in any feed reader that supports the JSON Feed format. To add this feed to your reader, copy the following URL -- ' . get_json_self_link() . ' -- and add it your reader.', 107 'home_page_url' => get_link_from_json_feed( get_json_self_link() ), 108 'feed_url' => get_json_self_link(), 109 'title' => get_bloginfo( 'name' ), 110 'description' => get_bloginfo( 'description' ), 111 'items' => $feed_items, 67 112 ); 113 114 $icon = get_site_icon_url(); 115 116 // Only add icon if icon is set 117 if ( $icon ) { 118 $feed_json['icon'] = $icon; 119 } 68 120 69 121 $feed_json = apply_filters( 'json_feed_feed', $feed_json ); 70 122 123 // The JSON_PRETTY_PRINT and JSON_UNESCAPED slashes make the minimum version requirement on this PHP5.4 71 124 echo wp_json_encode( $feed_json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ); -
jsonfeed/trunk/jsonfeed-wp.php
r1679899 r1950873 1 1 <?php 2 2 /* 3 Plugin Name: JSON Feed (jsonfeed.org)4 Plugin URI: http ://jsonfeed.org3 Plugin Name: JSON Feed 4 Plugin URI: https://github.com/manton/jsonfeed-wp/ 5 5 Description: Adds a feed of recent posts in JSON Feed format. 6 Version: 1. 1.26 Version: 1.2.0 7 7 Author: Manton Reece and Daniel Jalkut 8 8 Text Domain: jsonfeed 9 License: GPL2+ 9 License: GPL2.0+ 10 License URI: http://www.gnu.org/licenses/gpl-2.0.txt 10 11 */ 11 12 12 defined( 'ABSPATH' ) ordie( "WordPress plugin can't be loaded directly." );13 defined( 'ABSPATH' ) || die( "WordPress plugin can't be loaded directly." ); 13 14 14 15 // Flush the rewrite rules to enable the json feed permalink … … 39 40 function json_feed_link() { 40 41 printf( 41 '<link rel="alternate" type="application/json" title="JSON Feed" href="%s" />', 42 '<link rel="alternate" type="application/json" title="%s » JSON Feed" href="%s" />', 43 esc_attr( get_bloginfo( 'name' ) ), 42 44 esc_url( get_feed_link( 'json' ) ) 43 45 ); 44 46 } 47 48 add_filter( 'pubsubhubbub_feed_urls', 'json_feed_websub' ); 49 function json_feed_websub( $feeds ) { 50 $feeds[] = get_feed_link( 'json' ); 51 return $feeds; 52 } -
jsonfeed/trunk/readme.txt
r1679899 r1950873 1 1 === JSON Feed (jsonfeed.org) === 2 Contributors: mantonr, redsweater 3 Plugin Name: JSON Feed (jsonfeed.org) 4 Plugin URI: https://github.com/manton/jsonfeed-wp 2 Contributors: mantonr, redsweater, dshanske 5 3 Tags: jsonfeed, json, feed, feeds 6 Version: 1.1.27 4 Requires at least: 4.0 8 Tested up to: 4.7.5 9 Stable tag: trunk 10 License: GPL2+ 5 Tested up to: 4.9.8 6 Requires PHP: 5.4 7 Stable tag: 1.2.0 8 License: GPL-2.0+ 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html 11 10 12 11 Adds a feed of recent posts in JSON Feed format. … … 17 16 18 17 The JSON Feed format is a pragmatic syndication format, like RSS and Atom, but with one big difference: it's JSON instead of XML. Learn more at [jsonfeed.org](http://jsonfeed.org/). 18 19 == Installation == 20 21 1. Upload the plugin files to the `/wp-content/plugins/jsonfeed` directory, or install the plugin through the WordPress plugins screen directly. 22 1. Activate the plugin through the 'Plugins' screen in WordPress 23 24 == Frequently Asked Questions == 25 26 = What is JSONFeed? = 27 28 JSON Feed, a format similar to RSS and Atom but in JSON. JSON has become the developers’ choice for APIs, and that developers will often go out of their way to avoid XML. 29 JSON is simpler to read and write, and it’s less prone to bugs. 30 31 == Changelog == 32 33 = 1.2.0 = 34 * dshanske added as a contributor/maintainer 35 * Add featured image if set 36 * Add site icon if set 37 * home_page_url now actually returns the correct URL instead of always returning the homepage of the site 38 * Add avatar and URL to author 39 * Include site name in feed name in the discovery title 40 * Fix issue with timezone not reflecting on date 41 42 = 1.1.2 = 43 44 = 1.1.1 = 45 46 = 1.0 = 47 * Initial release
Note: See TracChangeset
for help on using the changeset viewer.