mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-08-29 19:09:56 +02:00
refactor: general code base refactor (#2950)
* refactor * fix: bug in previous refactor * chore: exclude phpcompat sniff due to bug in phpcompat * fix: do not leak absolute paths * refactor/fix: batch extensions checking, fix DOS issue
This commit is contained in:
@@ -43,6 +43,25 @@ class FDroidRepoBridge extends BridgeAbstract
|
||||
// Stores repo information
|
||||
private $repo;
|
||||
|
||||
public function collectData()
|
||||
{
|
||||
if (!extension_loaded('zip')) {
|
||||
throw new \Exception('FDroidRepoBridge requires the php-zip extension');
|
||||
}
|
||||
|
||||
$this->repo = $this->getRepo();
|
||||
switch ($this->queriedContext) {
|
||||
case 'Latest Updates':
|
||||
$this->getAllUpdates();
|
||||
break;
|
||||
case 'Follow Package':
|
||||
$this->getPackage($this->getInput('package'));
|
||||
break;
|
||||
default:
|
||||
returnServerError('Unimplemented Context (collectData)');
|
||||
}
|
||||
}
|
||||
|
||||
public function getURI()
|
||||
{
|
||||
if (empty($this->queriedContext)) {
|
||||
@@ -70,21 +89,6 @@ class FDroidRepoBridge extends BridgeAbstract
|
||||
}
|
||||
}
|
||||
|
||||
public function collectData()
|
||||
{
|
||||
$this->repo = $this->getRepo();
|
||||
switch ($this->queriedContext) {
|
||||
case 'Latest Updates':
|
||||
$this->getAllUpdates();
|
||||
break;
|
||||
case 'Follow Package':
|
||||
$this->getPackage($this->getInput('package'));
|
||||
break;
|
||||
default:
|
||||
returnServerError('Unimplemented Context (collectData)');
|
||||
}
|
||||
}
|
||||
|
||||
private function getRepo()
|
||||
{
|
||||
$url = $this->getURI();
|
||||
@@ -95,9 +99,10 @@ class FDroidRepoBridge extends BridgeAbstract
|
||||
file_put_contents($jar_loc, $jar);
|
||||
|
||||
// JAR files are specially formatted ZIP files
|
||||
$jar = new ZipArchive();
|
||||
$jar = new \ZipArchive();
|
||||
if ($jar->open($jar_loc) !== true) {
|
||||
returnServerError('Failed to extract archive');
|
||||
unlink($jar_loc);
|
||||
throw new \Exception('Failed to extract archive');
|
||||
}
|
||||
|
||||
// Get file pointer to the relevant JSON inside
|
||||
@@ -109,6 +114,7 @@ class FDroidRepoBridge extends BridgeAbstract
|
||||
$data = json_decode(stream_get_contents($fp), true);
|
||||
fclose($fp);
|
||||
$jar->close();
|
||||
unlink($jar_loc);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,9 @@ class PirateCommunityBridge extends BridgeAbstract
|
||||
{
|
||||
$parsed_url = parse_url($url);
|
||||
|
||||
if ($parsed_url['host'] !== 'raymanpc.com') {
|
||||
$host = $parsed_url['host'] ?? null;
|
||||
|
||||
if ($host !== 'raymanpc.com') {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@@ -71,7 +71,9 @@ class RedditBridge extends BridgeAbstract
|
||||
{
|
||||
$parsed_url = parse_url($url);
|
||||
|
||||
if ($parsed_url['host'] != 'www.reddit.com' && $parsed_url['host'] != 'old.reddit.com') {
|
||||
$host = $parsed_url['host'] ?? null;
|
||||
|
||||
if ($host != 'www.reddit.com' && $host != 'old.reddit.com') {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@@ -72,7 +72,7 @@ class WordPressBridge extends FeedExpander
|
||||
} else {
|
||||
$article_image = $article_image->getAttribute('data-lazy-src');
|
||||
}
|
||||
$mime_type = getMimeType($article_image);
|
||||
$mime_type = parse_mime_type($article_image);
|
||||
if (strpos($mime_type, 'image') === false) {
|
||||
$article_image .= '#.image'; // force image
|
||||
}
|
||||
|
Reference in New Issue
Block a user