Skip to content

Commit 7c636e9

Browse files
authored
Merge pull request #17 from indieweb/accept-header
Accept header
2 parents 325df3a + 98e199a commit 7c636e9

File tree

6 files changed

+71
-15
lines changed

6 files changed

+71
-15
lines changed

.travis.yml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cache:
99
directories:
1010
- vendor
1111
- $HOME/.composer/cache
12-
after_success:
12+
after_success:
1313
env:
1414
matrix:
1515
- WP_VERSION=latest WP_MULTISITE=0
@@ -43,13 +43,9 @@ before_script:
4343
echo "Using PHPUnit 6.x"
4444
composer global require "phpunit/phpunit:^6"
4545
;;
46-
5.6|5.5|5.4|5.3)
47-
echo "Using PHPUnit 4.x"
48-
composer global require "phpunit/phpunit:^4"
49-
;;
50-
5.2)
51-
# Do nothing, use default PHPUnit 3.6.x
52-
echo "Using default PHPUnit, hopefully 3.6"
46+
5.6)
47+
echo "Using PHPUnit 5.x"
48+
composer global require "phpunit/phpunit:^5"
5349
;;
5450
*)
5551
echo "No PHPUnit version handling for PHP version $TRAVIS_PHP_VERSION"

includes/class-mf2-feed-entry.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ public function jf2_to_mf2( $entry ) {
127127
$items[] = $this->jf2_to_mf2( $item );
128128
}
129129
$value = $items;
130+
} elseif ( wp_is_numeric_array( $value ) && ! is_array( $value[0] ) ) {
131+
$value = $value;
130132
} elseif ( ! wp_is_numeric_array( $value ) ) {
131133
$value = array( $value );
132134
} else {

languages/mf2-feed.pot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
# This file is distributed under the MIT.
33
msgid ""
44
msgstr ""
5-
"Project-Id-Version: MF2 Feed 3.0.0\n"
5+
"Project-Id-Version: MF2 Feed 3.1.0\n"
66
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/mf2-feed\n"
7-
"POT-Creation-Date: 2020-01-20 08:57:09+00:00\n"
7+
"POT-Creation-Date: 2020-12-09 11:04:57+00:00\n"
88
"MIME-Version: 1.0\n"
99
"Content-Type: text/plain; charset=utf-8\n"
1010
"Content-Transfer-Encoding: 8bit\n"

mf2-feed.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: MF2 Feed
44
* Plugin URI: http://github.com/indieweb/wordpress-mf2-feed/
55
* Description: Adds a Microformats2 JSON feed for every entry
6-
* Version: 3.0.0
6+
* Version: 3.1.0
77
* Author: IndieWeb WordPress Outreach Club
88
* Author URI: https://indieweb.org/WordPress_Outreach_Club
99
* License: MIT
@@ -35,6 +35,8 @@ public static function init() {
3535

3636
add_action( 'wp_head', array( 'Mf2Feed', 'add_html_header' ), 5 );
3737
add_filter( 'feed_content_type', array( 'Mf2Feed', 'feed_content_type' ), 10, 2 );
38+
39+
add_filter( 'template_include', array( 'Mf2Feed', 'render_json_template' ), 100 );
3840
}
3941

4042
public static function activate() {
@@ -92,6 +94,52 @@ public static function do_feed_jf2( $for_comments ) {
9294
}
9395
}
9496

97+
/**
98+
* Return a MF2/JF2 JSON version of an author, post or page.
99+
*
100+
* @param string $template The path to the template object.
101+
*
102+
* @return string The new path to the JSON template.
103+
*/
104+
public static function render_json_template( $template ) {
105+
if ( ! is_singular() ) {
106+
return $template;
107+
}
108+
109+
global $wp_query;
110+
111+
if ( ! isset( $_SERVER['HTTP_ACCEPT'] ) ) {
112+
return $template;
113+
}
114+
115+
$accept_header = $_SERVER['HTTP_ACCEPT'];
116+
117+
if (
118+
stristr( $accept_header, 'application/mf2+json' )
119+
) {
120+
return dirname( __FILE__ ) . '/includes/feed-mf2-comments.php';;
121+
} elseif (
122+
stristr( $accept_header, 'application/jf2+json' )
123+
) {
124+
return dirname( __FILE__ ) . '/includes/feed-jf2-comments.php';
125+
}
126+
127+
// Accept header as an array.
128+
$accept = explode( ',', trim( $accept_header ) );
129+
130+
if (
131+
in_array( 'application/mf2+json', $accept, true )
132+
) {
133+
return dirname( __FILE__ ) . '/includes/feed-mf2-comments.php';;
134+
} elseif (
135+
in_array( 'application/jf2+json', $accept, true )
136+
) {
137+
return dirname( __FILE__ ) . '/includes/feed-jf2-comments.php';
138+
}
139+
140+
return $template;
141+
}
142+
95143
/**
96144
* adds "mf2" content-type
97145
*

readme.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
**Donate link:** https://opencollective.com/indieweb
44
**Tags:** microformats, mf2, jf2, rel-alternate, indieweb
55
**Requires at least:** 5.2
6-
**Tested up to:** 5.3.2
7-
**Stable tag:** 3.0.0
6+
**Tested up to:** 5.6
7+
**Stable tag:** 3.1.0
88
**Requires PHP:** 5.6
99
**License:** MIT
1010
**License URI:** http://opensource.org/licenses/MIT
@@ -80,7 +80,12 @@ To install a WordPress Plugin manually:
8080

8181
Project actively developed on Github at [indieweb/wordpress-mf2-feed](https://github.com/indieweb/wordpress-mf2-feed). Please file support issues there.
8282

83+
### 3.1.0 ###
84+
85+
* Support Content Negotiation
86+
8387
### 3.0.0 ###
88+
8489
* Refactored to match the configuration of feeds built into WordPress
8590
* Bumped PHP Version requirement to PHP5.6 to match WordPress 5.3
8691
* Bumped minimum WordPress version to 5.2 as this allows for the version of get_content that includes a $post parameter

readme.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Contributors: pfefferle, dshanske, indieweb
33
Donate link: https://opencollective.com/indieweb
44
Tags: microformats, mf2, jf2, rel-alternate, indieweb
55
Requires at least: 5.2
6-
Tested up to: 5.3.2
7-
Stable tag: 3.0.0
6+
Tested up to: 5.6
7+
Stable tag: 3.1.0
88
Requires PHP: 5.6
99
License: MIT
1010
License URI: http://opensource.org/licenses/MIT
@@ -80,7 +80,12 @@ To install a WordPress Plugin manually:
8080

8181
Project actively developed on Github at [indieweb/wordpress-mf2-feed](https://github.com/indieweb/wordpress-mf2-feed). Please file support issues there.
8282

83+
= 3.1.0 =
84+
85+
* Support Content Negotiation
86+
8387
= 3.0.0 =
88+
8489
* Refactored to match the configuration of feeds built into WordPress
8590
* Bumped PHP Version requirement to PHP5.6 to match WordPress 5.3
8691
* Bumped minimum WordPress version to 5.2 as this allows for the version of get_content that includes a $post parameter

0 commit comments

Comments
 (0)