Browse Source

Fix adding a feed

Also start on handling the v1-2 API
microsub
J. King 7 years ago
parent
commit
dc9f5e545e
  1. 13
      lib/Database.php
  2. 15
      lib/Feed.php
  3. 1
      lib/REST.php
  4. 20
      lib/REST/NextCloudNews/V1_2.php

13
lib/Database.php

@ -435,7 +435,7 @@ class Database {
// Add each of the articles to the database.
foreach($feed->data->items as $i) {
$this->articleAdd($i);
$this->articleAdd($feedID, $i);
}
}
@ -450,10 +450,10 @@ class Database {
return (bool) $this->db->prepare("DELETE from arsse_subscriptions where owner is ? and id is ?", "str", "int")->run($user, $id)->changes();
}
public function articleAdd(PicoFeed\Parser\Item $article): int {
public function articleAdd(int $feedID, \PicoFeed\Parser\Item $article): int {
$this->db->begin();
$articleId = $this->db->prepare('INSERT INTO arsse_articles(feed,url,title,author,published,edited,guid,content,url_title_hash,url_content_hash,title_content_hash)
$articleID = $this->db->prepare('INSERT INTO arsse_articles(feed,url,title,author,published,edited,guid,content,url_title_hash,url_content_hash,title_content_hash)
values(?,?,?,?,?,?,?,?,?,?,?)',
'int', 'str', 'str', 'str', 'datetime', 'datetime', 'str', 'str', 'str', 'str', 'str')->run(
$feedID,
@ -470,23 +470,24 @@ class Database {
)->lastId();
// If the article has categories add them into the categories database.
$this->categoriesAdd($article, $articleID);
$this->categoriesAdd($articleID, $article);
$this->db->commit();
return 1;
}
public function categoriesAdd(PicoFeed\Parser\Item $article, int $id): int {
public function categoriesAdd(int $articleID, \PicoFeed\Parser\Item $article): int {
$this->db->begin();
$categories = $article->getTag('category');
if(count($categories) > 0) {
foreach($categories as $c) {
$this->db->prepare('INSERT INTO arsse_categories(article,name) values(?,?)', 'int', 'str')->run($id, $c);
$this->db->prepare('INSERT INTO arsse_categories(article,name) values(?,?)', 'int', 'str')->run($articleID, $c);
}
}
$this->db->commit();
return count($categories);
}
public function updateFeeds(): int {

15
lib/Feed.php

@ -20,7 +20,7 @@ class Feed {
$config->setGrabberUserAgent(Data::$conf->userAgentString);
$this->reader = new Reader($config);
$this->resource = $reader->download($url, $lastModified, $etag, $username, $password);
$this->resource = $this->reader->download($url, $lastModified, $etag, $username, $password);
// Grab the favicon for the feed; returns an empty string if it cannot find one.
$this->favicon = (new Favicon)->find($url);
} catch (PicoFeedException $e) {
@ -31,11 +31,10 @@ class Feed {
public function parse(): bool {
try {
$this->parser = $this->reader->getParser(
$resource->getUrl(),
$resource->getContent(),
$resource->getEncoding()
$this->resource->getUrl(),
$this->resource->getContent(),
$this->resource->getEncoding()
);
$feed = $this->parser->execute();
} catch (PicoFeedException $e) {
throw new Feed\Exception($url, $e);
@ -51,9 +50,9 @@ class Feed {
foreach ($feed->items as &$f) {
// Hashes used for comparison to check for updates and also to identify when an
// id doesn't exist.
$f->urlTitleHash = hash('sha256', $i->url.$i->title);
$f->urlContentHash = hash('sha256', $i->url.$i->content.$i->enclosureUrl.$i->enclosureType);
$f->titleContentHash = hash('sha256', $i->title.$i->content.$i->enclosureUrl.$i->enclosureType);
$f->urlTitleHash = hash('sha256', $f->url.$f->title);
$f->urlContentHash = hash('sha256', $f->url.$f->content.$f->enclosureUrl.$f->enclosureType);
$f->titleContentHash = hash('sha256', $f->title.$f->content.$f->enclosureUrl.$f->enclosureType);
// If there is an id element then continue. The id is used already.
$id = (string)$f->xml->id;

1
lib/REST.php

@ -24,7 +24,6 @@ class REST {
// Fever https://feedafever.com/api
// NewsBlur http://www.newsblur.com/api
];
protected $data;
function __construct() {
}

20
lib/REST/NextCloudNews/V1_2.php

@ -0,0 +1,20 @@
<?php
declare(strict_types=1);
namespace JKingWeb\Arsse\REST\NextCloudNews;
use JKingWeb\Arsse\REST\Response;
class V1_2 extends \JKingWeb\Arsse\REST\AbstractHandler {
function __construct() {
}
function dispatch(\JKingWeb\Arsse\REST\Request $req): \JKingWeb\Arsse\REST\Response {
// parse the URL and populate $path and $query
extract($this->parseURL($req->url));
if(preg_match("<^/(items|folders|feeds|cleanup|version|status|user)(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?/?$>", $path, $matches)) {
$scope = $matches[1];
var_export($scope);
} else {
return new Response(404);
}
}
}
Loading…
Cancel
Save