Plugin Directory

Changeset 1664371


Ignore:
Timestamp:
05/24/2017 10:56:24 PM (9 years ago)
Author:
signalfade
Message:

Improvements and cleanup of feed

Location:
json-feeder/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • json-feeder/trunk/json-feeder.php

    r1664279 r1664371  
    55Description: Adds a new type of feed you can subscribe to. http://example.com/feed/json or http://example.com/?feed=json to anywhere you get a JSON form.
    66Author: signalfade
    7 Version: 1.0.3
     7Version: 1.0.4
    88
    99License:
  • json-feeder/trunk/readme.txt

    r1664279 r1664371  
    44Requires at least: 4.0
    55Tested up to: 4.7.5
    6 Stable tag: 1.0.3
     6Stable tag: 1.0.4
    77
    88Adds a feed based on the jsonfeed.org standard that one can subscribe to or parse.
     
    1919
    2020== Changelog ==
     21
     22**1.0.4 May 24, 2017**
     23
     24Improvements and cleanup for template of feed.
    2125
    2226**1.0.3 May 24, 2017**
  • json-feeder/trunk/template/json-feeder.php

    r1664279 r1664371  
    55 */
    66$callback = trim(esc_html(get_query_var('callback')));
    7 $charset  = get_option('charset');
     7$charset  = get_option('blog_charset');
    88if(strpos($_SERVER['REQUEST_URI'], 'feed/json')!==false) {
    99    query_posts('posts_per_page=10');
     
    1515    // Make sure query args are always in the same order
    1616    ksort( $query_array );
     17    $site_description = get_bloginfo('description');
    1718
    1819    $json = array(
    1920        'version'           => 'https://jsonfeed.org/version/1',
    2021        'title'                 => get_bloginfo('name'),
    21         'description'   => get_bloginfo('description'),
    2222        'home_page_url' => home_url(),
    2323        'feed_url'          => get_bloginfo('rss2_url').'json',
    24         'items'                 => array(),
    25         // 'favicon'                => site_url().'/favicon.ico',
    26         // 'icon'                   => '',
     24        'author'            => array(
     25            'name' => 'nextSTL'
     26        ),
     27        'items'                 => array()
    2728    );
     29
     30    if(!empty($site_description)) {
     31        $json['description'] = $site_description;
     32    }
    2833
    2934    while ( have_posts() ) {
     
    3237
    3338        $single = array(
    34             'id'                    => $id,
     39            'id'                    => get_permalink(),
    3540            'title'                 => get_the_title(),
    3641            'url'                       => get_permalink(),
    37             'date_published'    => get_the_date(),
    38             'content_text'      => get_the_content(),
     42            'date_published'    => get_the_date('Y-m-dTH:i:s', $id).'Z',
     43            'content_html'      => get_the_content(),
    3944            'summary'               => get_the_excerpt(),
    40             'date'                  => get_the_date('Y-m-d H:i:s','','',false),
    4145            'author'                => array(
    4246                'name'      => get_the_author(),
     
    4852        // thumbnail
    4953        if (function_exists('has_post_thumbnail') && has_post_thumbnail($id)) {
    50             $single["image"] = get_the_post_thumbnail_url($id);
     54            $single['image'] = get_the_post_thumbnail_url($id);
    5155        }
    5256
    5357        // category  -- not difference between this and tags in JSON Feed.
    54         $single["tags"] = array();
     58        $single['tags'] = array();
    5559        $categories = get_the_category();
    5660        $categories_arr = array();
    5761        if ( ! empty( $categories ) ) {
    58             $categories_arr = wp_list_pluck( $categories, 'cat_name' );
     62            $categories_arr = wp_list_pluck( $categories, 'slug' );
    5963        }
    6064
     
    7175        $json['items'][] = $single;
    7276    }
    73 
    7477    $json = json_encode($json);
    7578
    7679    nocache_headers();
    77     if (!empty($callback)) {
    78         header("Content-Type: application/x-javascript; charset={$charset}");
    79         echo "{$callback}({$json});";
    80     } else {
    81         header("Content-Type: application/json; charset={$charset}");
    82         echo $json;
    83     }
    84 
     80    header("Content-Type: application/json; charset={$charset}");
     81    echo $json;
     82    exit();
    8583} else {
    8684    status_header('404');
Note: See TracChangeset for help on using the changeset viewer.