Browse Source

update jsonfeed detection

pull/49/head v1.4.4
Aaron Parecki 3 years ago
parent
commit
70e9f60c42
No known key found for this signature in database GPG Key ID: 276C2817346D6056
3 changed files with 14 additions and 11 deletions
  1. +8
    -6
      lib/XRay/Feeds.php
  2. +1
    -3
      lib/XRay/Formats/JSONFeed.php
  3. +5
    -2
      lib/XRay/Parser.php

+ 8
- 6
lib/XRay/Feeds.php View File

@ -55,12 +55,14 @@ class Feeds {
'url' => $result['url'],
'type' => 'rss'
];
} elseif(strpos($contentType, 'application/json') !== false
&& substr($body, 0, 1) == '{' && strpos(substr($body, 0, 100), 'https://jsonfeed.org/version/1')) {
$feeds[] = [
'url' => $result['url'],
'type' => 'jsonfeed'
];
} elseif(strpos($contentType, 'application/json') !== false && substr($body, 0, 1) == '{') {
$feeddata = json_decode($body, true);
if($feeddata && isset($feeddata['version']) && $feeddata['version'] == 'https://jsonfeed.org/version/1') {
$feeds[] = [
'url' => $result['url'],
'type' => 'jsonfeed'
];
}
} else {
// Some other document was returned, parse the HTML and look for rel alternates and Microformats

+ 1
- 3
lib/XRay/Formats/JSONFeed.php View File

@ -10,7 +10,7 @@ class JSONFeed extends Format {
public static function matches_host($url) { return true; }
public static function matches($url) { return true; }
public static function parse($json, $url) {
public static function parse($feed, $url) {
$result = [
'data' => [
'type' => 'unknown',
@ -18,8 +18,6 @@ class JSONFeed extends Format {
'url' => $url,
];
$feed = json_decode($json, true);
if($feed) {
$result['data']['type'] = 'feed';

+ 5
- 2
lib/XRay/Parser.php View File

@ -46,8 +46,11 @@ class Parser {
return Formats\XML::parse($body, $url);
}
if(substr($body, 0, 1) == '{' && strpos(substr($body, 0, 100), 'https://jsonfeed.org/version/1')) {
return Formats\JSONFeed::parse($body, $url);
if(substr($body, 0, 1) == '{') {
$feeddata = json_decode($body, true);
if($feeddata && isset($feeddata['version']) && $feeddata['version'] == 'https://jsonfeed.org/version/1') {
return Formats\JSONFeed::parse($feeddata, $url);
}
}
// No special parsers matched, parse for Microformats now

Loading…
Cancel
Save