mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 21:22:40 +00:00
Fix adding a feed
Also start on handling the v1-2 API
This commit is contained in:
parent
718c5a04dd
commit
dc9f5e545e
4 changed files with 34 additions and 15 deletions
|
@ -435,7 +435,7 @@ class Database {
|
||||||
|
|
||||||
// Add each of the articles to the database.
|
// Add each of the articles to the database.
|
||||||
foreach($feed->data->items as $i) {
|
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();
|
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();
|
$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(?,?,?,?,?,?,?,?,?,?,?)',
|
values(?,?,?,?,?,?,?,?,?,?,?)',
|
||||||
'int', 'str', 'str', 'str', 'datetime', 'datetime', 'str', 'str', 'str', 'str', 'str')->run(
|
'int', 'str', 'str', 'str', 'datetime', 'datetime', 'str', 'str', 'str', 'str', 'str')->run(
|
||||||
$feedID,
|
$feedID,
|
||||||
|
@ -470,23 +470,24 @@ class Database {
|
||||||
)->lastId();
|
)->lastId();
|
||||||
|
|
||||||
// If the article has categories add them into the categories database.
|
// If the article has categories add them into the categories database.
|
||||||
$this->categoriesAdd($article, $articleID);
|
$this->categoriesAdd($articleID, $article);
|
||||||
|
|
||||||
$this->db->commit();
|
$this->db->commit();
|
||||||
return 1;
|
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();
|
$this->db->begin();
|
||||||
|
|
||||||
$categories = $article->getTag('category');
|
$categories = $article->getTag('category');
|
||||||
if(count($categories) > 0) {
|
if(count($categories) > 0) {
|
||||||
foreach($categories as $c) {
|
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();
|
$this->db->commit();
|
||||||
|
return count($categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateFeeds(): int {
|
public function updateFeeds(): int {
|
||||||
|
|
15
lib/Feed.php
15
lib/Feed.php
|
@ -20,7 +20,7 @@ class Feed {
|
||||||
$config->setGrabberUserAgent(Data::$conf->userAgentString);
|
$config->setGrabberUserAgent(Data::$conf->userAgentString);
|
||||||
|
|
||||||
$this->reader = new Reader($config);
|
$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.
|
// Grab the favicon for the feed; returns an empty string if it cannot find one.
|
||||||
$this->favicon = (new Favicon)->find($url);
|
$this->favicon = (new Favicon)->find($url);
|
||||||
} catch (PicoFeedException $e) {
|
} catch (PicoFeedException $e) {
|
||||||
|
@ -31,11 +31,10 @@ class Feed {
|
||||||
public function parse(): bool {
|
public function parse(): bool {
|
||||||
try {
|
try {
|
||||||
$this->parser = $this->reader->getParser(
|
$this->parser = $this->reader->getParser(
|
||||||
$resource->getUrl(),
|
$this->resource->getUrl(),
|
||||||
$resource->getContent(),
|
$this->resource->getContent(),
|
||||||
$resource->getEncoding()
|
$this->resource->getEncoding()
|
||||||
);
|
);
|
||||||
|
|
||||||
$feed = $this->parser->execute();
|
$feed = $this->parser->execute();
|
||||||
} catch (PicoFeedException $e) {
|
} catch (PicoFeedException $e) {
|
||||||
throw new Feed\Exception($url, $e);
|
throw new Feed\Exception($url, $e);
|
||||||
|
@ -51,9 +50,9 @@ class Feed {
|
||||||
foreach ($feed->items as &$f) {
|
foreach ($feed->items as &$f) {
|
||||||
// Hashes used for comparison to check for updates and also to identify when an
|
// Hashes used for comparison to check for updates and also to identify when an
|
||||||
// id doesn't exist.
|
// id doesn't exist.
|
||||||
$f->urlTitleHash = hash('sha256', $i->url.$i->title);
|
$f->urlTitleHash = hash('sha256', $f->url.$f->title);
|
||||||
$f->urlContentHash = hash('sha256', $i->url.$i->content.$i->enclosureUrl.$i->enclosureType);
|
$f->urlContentHash = hash('sha256', $f->url.$f->content.$f->enclosureUrl.$f->enclosureType);
|
||||||
$f->titleContentHash = hash('sha256', $i->title.$i->content.$i->enclosureUrl.$i->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.
|
// If there is an id element then continue. The id is used already.
|
||||||
$id = (string)$f->xml->id;
|
$id = (string)$f->xml->id;
|
||||||
|
|
|
@ -24,7 +24,6 @@ class REST {
|
||||||
// Fever https://feedafever.com/api
|
// Fever https://feedafever.com/api
|
||||||
// NewsBlur http://www.newsblur.com/api
|
// NewsBlur http://www.newsblur.com/api
|
||||||
];
|
];
|
||||||
protected $data;
|
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
}
|
}
|
||||||
|
|
20
lib/REST/NextCloudNews/V1_2.php
Normal file
20
lib/REST/NextCloudNews/V1_2.php
Normal file
|
@ -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…
Reference in a new issue