Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
floviolleau committed Jun 9, 2023
2 parents ce58378 + ca351ed commit 7296672
Show file tree
Hide file tree
Showing 40 changed files with 785 additions and 422 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ Add the bridge name to `whitelist.txt`:

### How to enable debug mode

Create a file named `DEBUG`:
Set in `config.ini.php`:

touch DEBUG
enable_debug_mode = true

Learn more in [debug mode](https://rss-bridge.github.io/rss-bridge/For_Developers/Debug_mode.html).

Expand Down
11 changes: 5 additions & 6 deletions actions/DisplayAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ public function execute(array $request)
$bridge = $bridgeFactory->create($bridgeClassName);
$bridge->loadConfiguration();

$noproxy = array_key_exists('_noproxy', $request)
&& filter_var($request['_noproxy'], FILTER_VALIDATE_BOOLEAN);
$noproxy = array_key_exists('_noproxy', $request) && filter_var($request['_noproxy'], FILTER_VALIDATE_BOOLEAN);

if (Configuration::getConfig('proxy', 'url') && Configuration::getConfig('proxy', 'by_bridge') && $noproxy) {
define('NOPROXY', true);
Expand Down Expand Up @@ -107,7 +106,7 @@ public function execute(array $request)
&& (time() - $cache_timeout < $mtime)
&& !Debug::isEnabled()
) {
// At this point we found the feed in the cache
// At this point we found the feed in the cache and debug mode is disabled

if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE'])) {
// The client wants to know if the feed has changed since its last check
Expand All @@ -118,7 +117,7 @@ public function execute(array $request)
}
}

// Fetch the cached feed from the cache and prepare it
// Load the feed from cache and prepare it
$cached = $cache->loadData();
if (isset($cached['items']) && isset($cached['extraInfos'])) {
foreach ($cached['items'] as $item) {
Expand All @@ -127,7 +126,7 @@ public function execute(array $request)
$infos = $cached['extraInfos'];
}
} else {
// At this point we did NOT find the feed in the cache. So invoke the bridge!
// At this point we did NOT find the feed in the cache or debug mode is enabled.
try {
$bridge->setDatas($bridge_params);
$bridge->collectData();
Expand Down Expand Up @@ -200,7 +199,7 @@ private function createFeedItemFromException($e, BridgeInterface $bridge): FeedI
$item->setURI(get_current_url());
$item->setTimestamp(time());

// Create a item identifier for feed readers e.g. "staysafetv twitch videos_19389"
// Create an item identifier for feed readers e.g. "staysafetv twitch videos_19389"
$item->setUid($bridge->getName() . '_' . $uniqueIdentifier);

$content = render_template(__DIR__ . '/../templates/bridge-error.html.php', [
Expand Down
1 change: 1 addition & 0 deletions actions/FrontpageAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function execute(array $request)
}

return render(__DIR__ . '/../templates/frontpage.html.php', [
'messages' => [],
'admin_email' => Configuration::getConfig('admin', 'email'),
'admin_telegram' => Configuration::getConfig('admin', 'telegram'),
'bridges' => $body,
Expand Down
2 changes: 1 addition & 1 deletion actions/SetBridgeCacheAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function execute(array $request)

$key = $request['key'] or returnClientError('You must specify key!');

$bridgeFactory = new \BridgeFactory();
$bridgeFactory = new BridgeFactory();

$bridgeClassName = null;
if (isset($request['bridge'])) {
Expand Down
85 changes: 85 additions & 0 deletions bridges/AllSidesBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

class AllSidesBridge extends BridgeAbstract
{
const NAME = 'AllSides';
const URI = 'https://www.allsides.com';
const DESCRIPTION = 'Balanced news and media bias ratings.';
const MAINTAINER = 'Oliver Nutter';
const PARAMETERS = [
'global' => [
'limit' => [
'name' => 'Number of posts to return',
'type' => 'number',
'defaultValue' => 10,
'required' => false,
'title' => 'Zero or negative values return all posts (ignored if not fetching full article)',
],
'fetch' => [
'name' => 'Fetch full article content',
'type' => 'checkbox',
'defaultValue' => 'checked',
],
],
'Headline Roundups' => [],
];

private const ROUNDUPS_URI = self::URI . '/headline-roundups';

public function collectData()
{
switch ($this->queriedContext) {
case 'Headline Roundups':
$index = getSimpleHTMLDOM(self::ROUNDUPS_URI);
defaultLinkTo($index, self::ROUNDUPS_URI);
$entries = $index->find('table.views-table > tbody > tr');

$limit = (int) $this->getInput('limit');
$fetch = (bool) $this->getInput('fetch');

if ($limit > 0 && $fetch) {
$entries = array_slice($entries, 0, $limit);
}

foreach ($entries as $entry) {
$item = [
'title' => $entry->find('.views-field-name', 0)->text(),
'uri' => $entry->find('a', 0)->href,
'timestamp' => $entry->find('.date-display-single', 0)->content,
'author' => 'AllSides Staff',
];

if ($fetch) {
$article = getSimpleHTMLDOMCached($item['uri']);
defaultLinkTo($article, $item['uri']);

$item['content'] = $article->find('.story-id-page-description', 0);

foreach ($article->find('.page-tags a') as $tag) {
$item['categories'][] = $tag->text();
}
}

$this->items[] = $item;
}
break;
}
}

public function getName()
{
if ($this->queriedContext) {
return self::NAME . " - {$this->queriedContext}";
}
return self::NAME;
}

public function getURI()
{
switch ($this->queriedContext) {
case 'Headline Roundups':
return self::ROUNDUPS_URI;
}
return self::URI;
}
}
41 changes: 41 additions & 0 deletions bridges/AllocineFRSortiesBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

class AllocineFRSortiesBridge extends BridgeAbstract
{
const MAINTAINER = 'Simounet';
const NAME = 'AlloCiné Sorties Bridge';
const CACHE_TIMEOUT = 25200; // 7h
const BASE_URI = 'https://www.allocine.fr';
const URI = self::BASE_URI . '/film/sorties-semaine/';
const DESCRIPTION = 'Bridge for AlloCiné - Sorties cinéma cette semaine';

public function getName()
{
return self::NAME;
}

public function collectData()
{
$html = getSimpleHTMLDOM($this->getURI());

foreach ($html->find('section.section.section-wrap', 0)->find('li.mdl') as $element) {
$item = [];

$thumb = $element->find('figure.thumbnail', 0);
$meta = $element->find('div.meta-body', 0);
$synopsis = $element->find('div.synopsis', 0);

$title = $element->find('a[class*=meta-title-link]', 0);
$content = trim(defaultLinkTo($thumb->outertext . $meta->outertext . $synopsis->outertext, static::URI));

// Replace image 'src' with the one in 'data-src'
$content = preg_replace('@src="data:image/gif;base64,[A-Za-z0-9=+\/]*"@', '', $content);
$content = preg_replace('@data-src=@', 'src=', $content);

$item['content'] = $content;
$item['title'] = trim($title->innertext);
$item['uri'] = static::BASE_URI . '/' . substr($title->href, 1);
$this->items[] = $item;
}
}
}
5 changes: 5 additions & 0 deletions bridges/FinanzflussBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public function collectData()
$img->srcset = $baseurl . $src;
}

//remove unwanted stuff
foreach ($content->find('div.newsletter-signup') as $element) {
$element->remove();
}

//get author
$author = $domarticle->find('div.author-name', 0);

Expand Down
96 changes: 96 additions & 0 deletions bridges/GameBananaBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

class GameBananaBridge extends BridgeAbstract
{
const NAME = 'GameBanana';
const MAINTAINER = 'phantop';
const URI = 'https://gamebanana.com/';
const DESCRIPTION = 'Returns mods from GameBanana.';
const PARAMETERS = [
'Game' => [
'gid' => [
'name' => 'Game ID',
'required' => true,
// Example: latest mods from Zelda: Tears of the Kingdom
'exampleValue' => '7617',
],
'updates' => [
'name' => 'Get updates',
'type' => 'checkbox',
'required' => false,
'title' => 'Enable game updates in feed'
],
]
];

public function getIcon()
{
return 'https://images.gamebanana.com/static/img/favicon/favicon.ico';
}

public function collectData()
{
$url = 'https://api.gamebanana.com/Core/List/New?itemtype=Mod&page=1&gameid=' . $this->getInput('gid');
if ($this->getInput('updates')) {
$url .= '&include_updated=1';
}
$api_response = getContents($url);
$json_list = json_decode($api_response, true); // Get first page mod list

$url = 'https://api.gamebanana.com/Core/Item/Data?itemtype[]=Game&fields[]=name&itemid[]=' . $this->getInput('gid');
$fields = 'name,Owner().name,text,screenshots,Files().aFiles(),date,Url().sProfileUrl(),udate';
foreach ($json_list as $element) { // Build api request to minimize API calls
$mid = $element[1];
$url .= '&itemtype[]=Mod&fields[]=' . $fields . '&itemid[]=' . $mid;
}
$api_response = getContents($url);
$json_list = json_decode($api_response, true);

$this->title = $json_list[0][0];
array_shift($json_list); // Take title from API request and remove from json

foreach ($json_list as $element) {
$item = [];
$item['uri'] = $element[6];
$item['comments'] = $item['uri'] . '#PostsListModule';
$item['title'] = $element[0];
$item['author'] = $element[1];

$item['timestamp'] = $element[5];
if ($this->getInput('updates')) {
$item['timestamp'] = $element[7];
}

$item['enclosures'] = [];
foreach ($element[4] as $file) { // Place mod downloads in enclosures
array_push($item['enclosures'], 'https://files.gamebanana.com/mods/' . $file['_sFile']);
}

// Get screenshots from element[3]
$img_list = json_decode($element[3], true);
$item['content'] = '';
foreach ($img_list as $img_element) {
$item['content'] .= '<img src="https://images.gamebanana.com/img/ss/mods/' . $img_element['_sFile'] . '"/>';
}
$item['content'] .= '<br>' . $element[2];

$item['uid'] = $item['uri'] . $item['title'] . $item['timestamp'];
$this->items[] = $item;
}
}

public function getName()
{
$name = parent::getName();
if (isset($this->title)) {
$name .= " - $this->title";
}
return $name;
}

public function getURI()
{
$uri = parent::getURI() . 'games/' . $this->getInput('gid');
return $uri;
}
}
38 changes: 38 additions & 0 deletions bridges/GoAccessBridge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

class GoAccessBridge extends BridgeAbstract
{
const MAINTAINER = 'Simounet';
const NAME = 'GoAccess';
const URI_BASE = 'https://goaccess.io';
const URI = self::URI_BASE . '/release-notes';
const CACHE_TIMEOUT = 21600; //6h
const DESCRIPTION = 'GoAccess releases.';

public function collectData()
{
$html = getSimpleHTMLDOM(self::URI);

$container = $html->find('.container.content', 0);
foreach ($container->find('div') as $element) {
$titleEl = $element->find('h2', 0);
$dateEl = $titleEl->find('small', 0);
$date = trim($dateEl->plaintext);
$title = is_object($titleEl) ? str_replace($date, '', $titleEl->plaintext) : '';
$linkEl = $titleEl->find('a', 0);
$link = is_object($linkEl) ? $linkEl->href : '';
$postUrl = self::URI . $link;

$contentEl = $element->find('.dl-horizontal', 0);
$content = '<dl>' . $contentEl->xmltext() . '</dl>';

$item = [];
$item['uri'] = $postUrl;
$item['timestamp'] = strtotime($date);
$item['title'] = $title;
$item['content'] = $content;

$this->items[] = $item;
}
}
}
33 changes: 33 additions & 0 deletions bridges/MangaDexBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ class MangaDexBridge extends BridgeAbstract
'exampleValue' => 'en,jp',
'required' => false
],
'images' => [
'name' => 'Fetch chapter page images',
'type' => 'list',
'title' => 'Places chapter images in feed contents. Entries will consume more bandwidth.',
'defaultValue' => 'no',
'values' => [
'None' => 'no',
'Data Saver' => 'saver',
'Full Quality' => 'yes'
]
]

],
'Title Chapters' => [
'url' => [
Expand Down Expand Up @@ -239,6 +251,27 @@ protected function getChapters($content)
$item['content'] .= '<br>Other Users: ' . implode(', ', $users);
}

// Fetch chapter page images if desired and add to content
if ($this->getInput('images') !== 'no') {
$api_uri = self::API_ROOT . 'at-home/server/' . $item['uid'];
$header = [ 'Content-Type: application/json' ];
$pages = json_decode(getContents($api_uri, $header), true);
if ($pages['result'] != 'ok') {
returnServerError('Could not retrieve API results');
}

if ($this->getInput('images') == 'saver') {
$page_base = $pages['baseUrl'] . '/data-saver/' . $pages['chapter']['hash'] . '/';
foreach ($pages['chapter']['dataSaver'] as $image) {
$item['content'] .= '<br><img src="' . $page_base . $image . '"/>';
}
} else {
$page_base = $pages['baseUrl'] . '/data/' . $pages['chapter']['hash'] . '/';
foreach ($pages['chapter']['data'] as $image) {
$item['content'] .= '<br><img src="' . $page_base . $image . '"/>';
}
}
}
$this->items[] = $item;
}
}
Expand Down
Loading

0 comments on commit 7296672

Please sign in to comment.