Browse Source

switch to fork of picofeed with authorUrl support

* adds test of instagram-atom feed with individual authors per item
* dedupes atom/rss title if it's a prefix of the content
pull/49/head
Aaron Parecki 3 years ago
parent
commit
a9b1001e62
No known key found for this signature in database GPG Key ID: 276C2817346D6056
5 changed files with 1127 additions and 15 deletions
  1. +9
    -2
      composer.json
  2. +10
    -9
      composer.lock
  3. +22
    -4
      lib/XRay/Formats/XML.php
  4. +19
    -0
      tests/FeedTest.php
  5. +1067
    -0
      tests/data/feed.example.com/instagram-atom

+ 9
- 2
composer.json View File

@ -12,7 +12,7 @@
"p3k/timezone": "*",
"p3k/http": "0.1.*",
"cebe/markdown": "1.1.*",
"miniflux/picofeed": "^0.1.37",
"miniflux/picofeed": "dev-master",
"facebook/graph-sdk": "^5.5"
},
"autoload": {
@ -38,5 +38,12 @@
"controllers/Feeds.php",
"controllers/Certbot.php"
]
}
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/aaronpk/picoFeed.git",
"no-api": true
}
]
}

+ 10
- 9
composer.lock View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "a1330f39bf5204a5cc6bdd1222915639",
"content-hash": "c61ccebf0105e57a0a60f431a95fcaed",
"packages": [
{
"name": "cebe/markdown",
@ -316,16 +316,16 @@
},
{
"name": "miniflux/picofeed",
"version": "v0.1.37",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/miniflux/picoFeed.git",
"reference": "402b7f07629577e7929625e78bc88d3d5831a22d"
"url": "https://github.com/aaronpk/picoFeed.git",
"reference": "989c0bcf2eac016a4104abce1aadff791fc287ab"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/miniflux/picoFeed/zipball/402b7f07629577e7929625e78bc88d3d5831a22d",
"reference": "402b7f07629577e7929625e78bc88d3d5831a22d",
"url": "https://api.github.com/repos/aaronpk/picoFeed/zipball/989c0bcf2eac016a4104abce1aadff791fc287ab",
"reference": "989c0bcf2eac016a4104abce1aadff791fc287ab",
"shasum": ""
},
"require": {
@ -354,7 +354,6 @@
"PicoFeed": "lib/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
@ -365,7 +364,7 @@
],
"description": "Modern library to handle RSS/Atom feeds",
"homepage": "https://github.com/miniflux/picoFeed",
"time": "2017-11-02T03:20:36+00:00"
"time": "2017-11-30T00:16:58+00:00"
},
{
"name": "p3k/http",
@ -2090,7 +2089,9 @@
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": [],
"stability-flags": {
"miniflux/picofeed": 20
},
"prefer-stable": false,
"prefer-lowest": false,
"platform": [],

+ 22
- 4
lib/XRay/Formats/XML.php View File

@ -60,20 +60,38 @@ class XML extends Format {
if($item->getPublishedDate())
$entry['published'] = $item->getPublishedDate()->format('c');
if($item->getTitle() && $item->getTitle() != $item->getUrl())
$entry['name'] = $item->getTitle();
if($item->getContent())
$entry['content'] = [
'html' => self::sanitizeHTML($item->getContent()),
'text' => self::stripHTML($item->getContent())
];
if($item->getTitle() && $item->getTitle() != $item->getUrl()) {
$title = $item->getTitle();
$entry['name'] = $title;
// Check if the title is a prefix of the content and drop if so
if(isset($entry['content'])) {
if(substr($title, -3) == '...' || substr($title, -1) == '…') {
if(substr($title, -3) == '...') {
$trimmedTitle = substr($title, 0, -3);
} else {
$trimmedTitle = substr($title, 0, -1);
}
if(substr($entry['content']['text'], 0, strlen($trimmedTitle)) == $trimmedTitle) {
unset($entry['name']);
}
}
}
}
if($item->getAuthor()) {
$entry['author']['name'] = $item->getAuthor();
}
if($feed->siteUrl) {
if($item->getAuthorUrl()) {
$entry['author']['url'] = $item->getAuthorUrl();
} else if($feed->siteUrl) {
$entry['author']['url'] = $feed->siteUrl;
}

+ 19
- 0
tests/FeedTest.php View File

@ -295,4 +295,23 @@ class FeedTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('feed', $data->type);
}
public function testInstagramAtomFeed() {
$url = 'http://feed.example.com/instagram-atom';
$response = $this->parse(['url' => $url, 'expect' => 'feed']);
$body = $response->getContent();
$this->assertEquals(200, $response->getStatusCode());
$data = json_decode($body)->data;
$this->assertEquals(12, count($data->items));
$this->assertEquals('Marshall Kirkpatrick', $data->items[11]->author->name);
$this->assertEquals('https://www.instagram.com/marshallk/', $data->items[11]->author->url);
$this->assertEquals('https://www.instagram.com/p/BcFjw9SHYql/', $data->items[11]->url);
$this->assertEquals('2017-11-29T17:04:00+00:00', $data->items[11]->published);
// Should remove the "name" since it's a prefix of the content
$this->assertObjectNotHasAttribute('name', $data->items[11]);
$this->assertEquals('Sometimes my job requires me to listen to 55 minutes of an hour long phone call while I go for a long walk on a sunny morning and wait for my turn to give an update. Pretty nice!', $data->items[11]->content->text);
}
}

+ 1067
- 0
tests/data/feed.example.com/instagram-atom
File diff suppressed because it is too large
View File


Loading…
Cancel
Save