0
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-27 13:55:45 +00:00

[CybernewsBridge] final

This commit is contained in:
tillcash 2025-08-14 17:54:27 +05:30 committed by GitHub
parent 3c8d9d7b9b
commit c916be53e1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,46 +1,51 @@
<?php <?php
declare(strict_types=1);
class CybernewsBridge extends BridgeAbstract class CybernewsBridge extends BridgeAbstract
{ {
const NAME = 'Cybernews'; const NAME = 'Cybernews';
const URI = 'https://cybernews.com'; const URI = 'https://cybernews.com';
const DESCRIPTION = 'Fetches the latest news from Cybernews'; const DESCRIPTION = 'Fetches the latest news from Cybernews';
const MAINTAINER = 'tillcash'; const MAINTAINER = 'tillcash';
const CACHE_TIMEOUT = 3600; // 1 hour const CACHE_TIMEOUT = 3600; // 1 hour
const MAX_ARTICLES = 5; const MAX_ARTICLES = 5;
public function collectData() public function collectData()
{ {
$sitemapXml = getContents(self::URI . '/news-sitemap.xml'); $sitemapXml = getContents(self::URI . '/news-sitemap.xml');
if (!$sitemapXml) { if (!$sitemapXml) {
throwServerException('Could not retrieve Cybernews sitemap'); throwServerException('Unable to retrieve Cybernews sitemap');
} }
$sitemap = simplexml_load_string($sitemapXml, null, LIBXML_NOCDATA); $sitemap = simplexml_load_string($sitemapXml, null, LIBXML_NOCDATA);
if (!$sitemap) { if (!$sitemap) {
throwServerException('Failed to parse Cybernews sitemap'); throwServerException('Unable to parse Cybernews sitemap');
} }
foreach ($sitemap->url as $entry) { foreach ($sitemap->url as $entry) {
$url = trim((string) $entry->loc); $url = trim((string) $entry->loc);
$lastmod = trim((string) $entry->lastmod); $lastmod = trim((string) $entry->lastmod);
if (!$url) { if (!$url) {
continue; continue;
} }
$pathParts = explode('/', trim(parse_url($url, PHP_URL_PATH), '/')); $pathParts = explode('/', trim(parse_url($url, PHP_URL_PATH), '/'));
$category = isset($pathParts[0]) && $pathParts[0] !== '' ? $pathParts[0] : ''; $category = isset($pathParts[0]) && $pathParts[0] !== '' ? $pathParts[0] : '';
// Skip non-English versions of articles? // Skip non-English versions
if (in_array($category, ['nl', 'de'])) { if (in_array($category, ['nl', 'de'], true)) {
continue; continue;
} }
$namespaces = $entry->getNamespaces(true); $namespaces = $entry->getNamespaces(true);
$title = ''; $title = '';
if (isset($namespaces['news'])) { if (isset($namespaces['news'])) {
$news = $entry->children($namespaces['news'])->news; $news = $entry->children($namespaces['news'])->news;
if ($news) { if ($news) {
$title = trim((string) $news->title); $title = trim((string) $news->title);
} }
@ -65,16 +70,18 @@ class CybernewsBridge extends BridgeAbstract
} }
} }
private function fetchFullArticle($url) private function fetchFullArticle(string $url): string
{ {
$html = getSimpleHTMLDOMCached($url); $html = getSimpleHTMLDOMCached($url);
if (!$html) { if (!$html) {
return 'Failed to fetch article content'; return 'Unable to fetch article content';
} }
$article = $html->find('article', 0); $article = $html->find('article', 0);
if (!$article) { if (!$article) {
return 'Failed to parse article content'; return 'Unable to parse article content';
} }
// Remove unnecessary elements // Remove unnecessary elements
@ -86,6 +93,7 @@ class CybernewsBridge extends BridgeAbstract
'div.a-wrapper', 'div.a-wrapper',
'div.embed_youtube', 'div.embed_youtube',
]; ];
foreach ($removeSelectors as $selector) { foreach ($removeSelectors as $selector) {
foreach ($article->find($selector) as $element) { foreach ($article->find($selector) as $element) {
$element->outertext = ''; $element->outertext = '';