Plugin Directory

Changeset 1950873


Ignore:
Timestamp:
10/03/2018 01:36:27 PM (7 years ago)
Author:
mantonr
Message:

Updated with version 1.2 changes.

Location:
jsonfeed/trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • jsonfeed/trunk/README.md

    r1661151 r1950873  
    1 # JSON Feed plugin for WordPress
    21
    3 Adds a `/feed/json` URL to your WordPress site. Drop the plugin folder in /wp-content/plugins and activate under WP Admin → Plugins.
     2Adds a feed of recent posts in JSON Feed format.
     3
     4
     5## Description
     6
     7Adds a `/feed/json` URL to your WordPress site.
    48
    59The 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
     141. Upload the plugin files to the `/wp-content/plugins/jsonfeed` directory, or install the plugin through the WordPress plugins screen directly.
     151. Activate the plugin through the 'Plugins' screen in WordPress
     16
     17
     18## Frequently Asked Questions
     19
     20
     21### What is JSONFeed?
     22
     23JSON 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.
     24JSON 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  
    11<?php
    22
    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
     5function 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}
    89
    910function get_attachment_json_info() {
    10     if ( post_password_required() )
     11    if ( post_password_required() ) {
    1112        return null;
     13    }
    1214
    1315    foreach ( (array) get_post_custom() as $key => $val ) {
    14         if ($key == 'enclosure') {
     16        if ( 'enclosure' === $key ) {
    1517            foreach ( (array) $val as $enc ) {
    16                 $enclosure = explode("\n", $enc);
     18                $enclosure = explode( "\n", $enc );
    1719
    1820                // 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] ) );
    2022                $type = $t[0];
    2123
    2224                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],
    2628                );
    2729            }
    2830        }
    2931    }
     32}
     33
     34function 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
     50function 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;
    3064}
    3165
     
    3670
    3771    $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 ) ),
    4683        ),
     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
    4786    );
    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
    4994    $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,
    5398        );
    5499    }
     
    58103
    59104$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,
    67112);
     113
     114$icon = get_site_icon_url();
     115
     116// Only add icon if icon is set
     117if ( $icon ) {
     118    $feed_json['icon'] = $icon;
     119}
    68120
    69121$feed_json = apply_filters( 'json_feed_feed', $feed_json );
    70122
     123// The JSON_PRETTY_PRINT and JSON_UNESCAPED slashes make the minimum version requirement on this PHP5.4
    71124echo wp_json_encode( $feed_json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES );
  • jsonfeed/trunk/jsonfeed-wp.php

    r1679899 r1950873  
    11<?php
    22/*
    3 Plugin Name: JSON Feed (jsonfeed.org)
    4 Plugin URI: http://jsonfeed.org
     3Plugin Name: JSON Feed
     4Plugin URI: https://github.com/manton/jsonfeed-wp/
    55Description: Adds a feed of recent posts in JSON Feed format.
    6 Version: 1.1.2
     6Version: 1.2.0
    77Author: Manton Reece and Daniel Jalkut
    88Text Domain: jsonfeed
    9 License: GPL2+
     9License: GPL2.0+
     10License URI: http://www.gnu.org/licenses/gpl-2.0.txt
    1011*/
    1112
    12 defined( 'ABSPATH' ) or die( "WordPress plugin can't be loaded directly." );
     13defined( 'ABSPATH' ) || die( "WordPress plugin can't be loaded directly." );
    1314
    1415// Flush the rewrite rules to enable the json feed permalink
     
    3940function json_feed_link() {
    4041    printf(
    41         '<link rel="alternate" type="application/json" title="JSON Feed" href="%s" />',
     42        '<link rel="alternate" type="application/json" title="%s &raquo; JSON Feed" href="%s" />',
     43        esc_attr( get_bloginfo( 'name' ) ),
    4244        esc_url( get_feed_link( 'json' ) )
    4345    );
    4446}
     47
     48add_filter( 'pubsubhubbub_feed_urls', 'json_feed_websub' );
     49function json_feed_websub( $feeds ) {
     50    $feeds[] = get_feed_link( 'json' );
     51    return $feeds;
     52}
  • jsonfeed/trunk/readme.txt

    r1679899 r1950873  
    11=== JSON Feed (jsonfeed.org) ===
    2 Contributors: mantonr, redsweater
    3 Plugin Name: JSON Feed (jsonfeed.org)
    4 Plugin URI: https://github.com/manton/jsonfeed-wp
     2Contributors: mantonr, redsweater, dshanske
    53Tags: jsonfeed, json, feed, feeds
    6 Version: 1.1.2
    74Requires at least: 4.0
    8 Tested up to: 4.7.5
    9 Stable tag: trunk
    10 License: GPL2+
     5Tested up to: 4.9.8
     6Requires PHP: 5.4
     7Stable tag: 1.2.0
     8License: GPL-2.0+
     9License URI: http://www.gnu.org/licenses/gpl-2.0.html
    1110
    1211Adds a feed of recent posts in JSON Feed format.
     
    1716
    1817The 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
     211. Upload the plugin files to the `/wp-content/plugins/jsonfeed` directory, or install the plugin through the WordPress plugins screen directly.
     221. Activate the plugin through the 'Plugins' screen in WordPress
     23
     24== Frequently Asked Questions ==
     25
     26= What is JSONFeed? =
     27
     28JSON 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.
     29JSON 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.