From e956a7f65347ffa8466b7557e179d428f8580817 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Tue, 27 Dec 2022 22:30:20 +0100 Subject: [PATCH] Stop adding audio language to release searchnames in API response --- Blacklight/http/API.php | 6 +- Blacklight/http/Capabilities.php | 22 ++--- Blacklight/http/XML_Response.php | 73 ++++++--------- app/Http/Controllers/Api/ApiController.php | 1 - composer.lock | 102 ++++++++++----------- 5 files changed, 94 insertions(+), 110 deletions(-) diff --git a/Blacklight/http/API.php b/Blacklight/http/API.php index 906365dff..dd0ef39f3 100755 --- a/Blacklight/http/API.php +++ b/Blacklight/http/API.php @@ -36,7 +36,7 @@ class API extends Capabilities /** * @var array The get request from the web server */ - public $getRequest; + public mixed $getRequest; /** * @param array $options @@ -58,9 +58,9 @@ class API extends Capabilities /** * Add language from media info XML to release search names (Used by API). * - * @param array $releases + * @param array $releases */ - public function addLanguage(&$releases): void + public function addLanguage(array &$releases): void { if ($releases && \count($releases)) { foreach ($releases as $key => $release) { diff --git a/Blacklight/http/Capabilities.php b/Blacklight/http/Capabilities.php index 74b44e7de..8c7e8372c 100755 --- a/Blacklight/http/Capabilities.php +++ b/Blacklight/http/Capabilities.php @@ -25,6 +25,7 @@ namespace Blacklight\http; use App\Models\Category; use App\Models\Settings; use Blacklight\utility\Utility; +use JetBrains\PhpStorm\ArrayShape; /** * Class Output -- abstract class for printing web requests outside of Smarty. @@ -34,12 +35,12 @@ abstract class Capabilities /** * @var \PDO */ - public $pdo; + public \PDO $pdo; /** * @var string The type of Capabilities request */ - protected $type; + protected string $type; /** * Construct. @@ -59,15 +60,15 @@ abstract class Capabilities /** * Print XML or JSON output. * - * @param array|\Illuminate\Database\Eloquent\Collection $data Data to print. - * @param array $params Additional request parameters - * @param bool $xml True: Print as XML False: Print as JSON. - * @param int $offset How much releases to skip - * @param string $type What type of API query to format if XML + * @param \Illuminate\Database\Eloquent\Collection|array $data Data to print. + * @param array $params Additional request parameters + * @param bool $xml True: Print as XML False: Print as JSON. + * @param int $offset How much releases to skip + * @param string $type What type of API query to format if XML * * @throws \Exception */ - public function output($data, $params, $xml = true, $offset, $type = ''): void + public function output(\Illuminate\Database\Eloquent\Collection|array $data, array $params, bool $xml = true, int $offset, string $type = ''): void { $this->type = $type; @@ -87,10 +88,7 @@ abstract class Capabilities } else { // JSON encode the XMLWriter response $response = json_encode( - // Convert SimpleXMLElement response from XMLWriter - //into array with namespace preservation Utility::xmlToArray( - // Load the XMLWriter response @simplexml_load_string($response), [ 'attributePrefix' => '_', @@ -119,7 +117,7 @@ abstract class Capabilities * * @throws \Exception */ - public function getForMenu(): array + public function getForMenu(): array { $serverroot = url('/'); diff --git a/Blacklight/http/XML_Response.php b/Blacklight/http/XML_Response.php index e804d4bc8..58d4ab0a5 100755 --- a/Blacklight/http/XML_Response.php +++ b/Blacklight/http/XML_Response.php @@ -34,61 +34,61 @@ class XML_Response /** * @var string The buffered cData before final write */ - protected $cdata; + protected string $cdata; /** * The RSS namespace used for the output. * * @var string */ - protected $namespace; + protected string $namespace; /** * The trailing URL parameters on the request. * * @var mixed */ - protected $parameters; + protected mixed $parameters; /** * The release we are adding to the stream. * * @var mixed */ - protected $release; + protected mixed $release; /** * The retrieved releases we are returning from the API call. * * @var mixed */ - protected $releases; + protected mixed $releases; /** * The various server variables and active categories. * * @var mixed */ - protected $server; + protected mixed $server; /** * The XML formatting operation we are returning. * * @var mixed */ - protected $type; + protected mixed $type; /** * The XMLWriter Class. * * @var \XMLWriter */ - protected $xml; + protected \XMLWriter $xml; /** * @var mixed */ - protected $offset; + protected mixed $offset; /** * XMLReturn constructor. @@ -120,7 +120,7 @@ class XML_Response /** * @return bool|string */ - public function returnXML() + public function returnXML(): bool|string { if ($this->xml) { switch ($this->type) { @@ -208,9 +208,9 @@ class XML_Response /** * Starts a new element, loops through the attribute data and ends the element. * - * @param array $element An array with the name of the element and the attribute data + * @param array $element An array with the name of the element and the attribute data */ - protected function addNode($element): void + protected function addNode(array $element): void { $this->xml->startElement($element['name']); foreach ($element['data'] as $attr => $val) { @@ -222,9 +222,9 @@ class XML_Response /** * Starts a new element, loops through the attribute data and ends the element. * - * @param array $element An array with the name of the element and the attribute data + * @param array $element An array with the name of the element and the attribute data */ - protected function addNodes($element): void + protected function addNodes(array $element): void { $this->xml->startElement($element['name']); foreach ($element['data'] as $elem => $value) { @@ -266,14 +266,10 @@ class XML_Response */ protected function includeRssAtom(): void { - switch ($this->namespace) { - case 'newznab': - $url = 'http://www.newznab.com/DTD/2010/feeds/attributes/'; - break; - case 'nntmux': - default: - $url = $this->server['server']['url'].'/rss-info/'; - } + $url = match ($this->namespace) { + 'newznab' => 'http://www.newznab.com/DTD/2010/feeds/attributes/', + default => $this->server['server']['url'].'/rss-info/', + }; $this->xml->startElement('rss'); $this->xml->writeAttribute('version', '2.0'); @@ -379,7 +375,7 @@ class XML_Response $this->setZedAttributes(); $this->xml->endElement(); } - } elseif ($this->releases instanceof Release) { + } else { $this->release = $this->releases; $this->xml->startElement('item'); $this->includeReleaseMain(); @@ -434,7 +430,7 @@ class XML_Response { $this->writeZedAttr('category', $this->release->categories_id); $this->writeZedAttr('size', $this->release->size); - if (isset($this->release->coverurl) && ! empty($this->release->coverurl)) { + if (! empty($this->release->coverurl)) { $this->writeZedAttr( 'coverurl', $this->server['server']['url']."/covers/{$this->release->coverurl}" @@ -516,10 +512,10 @@ class XML_Response /** * Writes individual zed (newznab) type attributes. * - * @param string $name The namespaced attribute name tag - * @param string $value The namespaced attribute value + * @param string $name The namespaced attribute name tag + * @param string $value The namespaced attribute value */ - protected function writeZedAttr($name, $value): void + protected function writeZedAttr(string $name, string $value): void { $this->xml->startElement($this->namespace.':attr'); $this->xml->writeAttribute('name', $name); @@ -569,22 +565,13 @@ class XML_Response "\t
  • Poster: {$this->release->fromname}
  • \n". "\t
  • Posted: {$this->release->postdate}
  • \n"; - switch ($this->release->passwordstatus) { - case 0: - $pstatus = 'None'; - break; - case 1: - $pstatus = 'Possibly Passworded'; - break; - case 2: - $pstatus = 'Probably not viable'; - break; - case 10: - $pstatus = 'Passworded'; - break; - default: - $pstatus = 'Unknown'; - } + $pstatus = match ($this->release->passwordstatus) { + 0 => 'None', + 1 => 'Possibly Passworded', + 2 => 'Probably not viable', + 10 => 'Passworded', + default => 'Unknown', + }; $this->cdata .= "\t
  • Password: {$pstatus}
  • \n"; if ($this->release->nfostatus === 1) { $this->cdata .= diff --git a/app/Http/Controllers/Api/ApiController.php b/app/Http/Controllers/Api/ApiController.php index 6ee5e3a21..015678b02 100644 --- a/app/Http/Controllers/Api/ApiController.php +++ b/app/Http/Controllers/Api/ApiController.php @@ -224,7 +224,6 @@ class ApiController extends BasePageController $catExclusions ); - $api->addLanguage($relData); $api->output($relData, $params, $outputXML, $offset, 'api'); break; diff --git a/composer.lock b/composer.lock index 2b6193899..480d6a6ab 100644 --- a/composer.lock +++ b/composer.lock @@ -1392,16 +1392,16 @@ }, { "name": "doctrine/dbal", - "version": "3.5.1", + "version": "3.5.2", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "f38ee8aaca2d58ee88653cb34a6a3880c23f38a5" + "reference": "63e513cebbbaf96a6795e5c5ee34d205831bfc85" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/f38ee8aaca2d58ee88653cb34a6a3880c23f38a5", - "reference": "f38ee8aaca2d58ee88653cb34a6a3880c23f38a5", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/63e513cebbbaf96a6795e5c5ee34d205831bfc85", + "reference": "63e513cebbbaf96a6795e5c5ee34d205831bfc85", "shasum": "" }, "require": { @@ -1414,16 +1414,16 @@ "psr/log": "^1|^2|^3" }, "require-dev": { - "doctrine/coding-standard": "10.0.0", - "jetbrains/phpstorm-stubs": "2022.2", - "phpstan/phpstan": "1.8.10", + "doctrine/coding-standard": "11.0.0", + "jetbrains/phpstorm-stubs": "2022.3", + "phpstan/phpstan": "1.9.2", "phpstan/phpstan-strict-rules": "^1.4", - "phpunit/phpunit": "9.5.25", - "psalm/plugin-phpunit": "0.17.0", + "phpunit/phpunit": "9.5.27", + "psalm/plugin-phpunit": "0.18.4", "squizlabs/php_codesniffer": "3.7.1", "symfony/cache": "^5.4|^6.0", "symfony/console": "^4.4|^5.4|^6.0", - "vimeo/psalm": "4.29.0" + "vimeo/psalm": "4.30.0" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." @@ -1483,7 +1483,7 @@ ], "support": { "issues": "https://github.com/doctrine/dbal/issues", - "source": "https://github.com/doctrine/dbal/tree/3.5.1" + "source": "https://github.com/doctrine/dbal/tree/3.5.2" }, "funding": [ { @@ -1499,7 +1499,7 @@ "type": "tidelift" } ], - "time": "2022-10-24T07:26:18+00:00" + "time": "2022-12-19T08:17:34+00:00" }, { "name": "doctrine/deprecations", @@ -3637,16 +3637,16 @@ }, { "name": "laravel/framework", - "version": "v9.44.0", + "version": "v9.45.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "60808a7d9acd53461fd69634c08fc7e0a99fbf98" + "reference": "f2c51fdfcb0c50c19cdc49c2e82690ad1a21eafe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/60808a7d9acd53461fd69634c08fc7e0a99fbf98", - "reference": "60808a7d9acd53461fd69634c08fc7e0a99fbf98", + "url": "https://api.github.com/repos/laravel/framework/zipball/f2c51fdfcb0c50c19cdc49c2e82690ad1a21eafe", + "reference": "f2c51fdfcb0c50c19cdc49c2e82690ad1a21eafe", "shasum": "" }, "require": { @@ -3657,7 +3657,7 @@ "ext-openssl": "*", "fruitcake/php-cors": "^1.2", "laravel/serializable-closure": "^1.2.2", - "league/commonmark": "^2.2", + "league/commonmark": "^2.2.1", "league/flysystem": "^3.8.0", "monolog/monolog": "^2.0", "nesbot/carbon": "^2.62.1", @@ -3666,7 +3666,7 @@ "psr/container": "^1.1.1|^2.0.1", "psr/log": "^1.0|^2.0|^3.0", "psr/simple-cache": "^1.0|^2.0|^3.0", - "ramsey/uuid": "^4.2.2", + "ramsey/uuid": "^4.7", "symfony/console": "^6.0.9", "symfony/error-handler": "^6.0", "symfony/finder": "^6.0", @@ -3727,7 +3727,7 @@ "ably/ably-php": "^1.0", "aws/aws-sdk-php": "^3.235.5", "doctrine/dbal": "^2.13.3|^3.1.4", - "fakerphp/faker": "^1.9.2", + "fakerphp/faker": "^1.21", "guzzlehttp/guzzle": "^7.5", "league/flysystem-aws-s3-v3": "^3.0", "league/flysystem-ftp": "^3.0", @@ -3735,7 +3735,7 @@ "league/flysystem-read-only": "^3.3", "league/flysystem-sftp-v3": "^3.0", "mockery/mockery": "^1.5.1", - "orchestra/testbench-core": "^7.11", + "orchestra/testbench-core": "^7.16", "pda/pheanstalk": "^4.0", "phpstan/phpstan": "^1.4.7", "phpunit/phpunit": "^9.5.8", @@ -3819,7 +3819,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2022-12-15T14:56:36+00:00" + "time": "2022-12-20T14:16:06+00:00" }, { "name": "laravel/horizon", @@ -3900,16 +3900,16 @@ }, { "name": "laravel/scout", - "version": "v9.6.0", + "version": "v9.6.1", "source": { "type": "git", "url": "https://github.com/laravel/scout.git", - "reference": "3abf3026d43bfaae9cf4e82be84cdb9b12816edc" + "reference": "feb8cdca5ea15ff7ce8b5a3fd3b6b93c360e7e38" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/scout/zipball/3abf3026d43bfaae9cf4e82be84cdb9b12816edc", - "reference": "3abf3026d43bfaae9cf4e82be84cdb9b12816edc", + "url": "https://api.github.com/repos/laravel/scout/zipball/feb8cdca5ea15ff7ce8b5a3fd3b6b93c360e7e38", + "reference": "feb8cdca5ea15ff7ce8b5a3fd3b6b93c360e7e38", "shasum": "" }, "require": { @@ -3968,7 +3968,7 @@ "issues": "https://github.com/laravel/scout/issues", "source": "https://github.com/laravel/scout" }, - "time": "2022-12-15T14:20:38+00:00" + "time": "2022-12-20T17:18:18+00:00" }, { "name": "laravel/serializable-closure", @@ -4032,16 +4032,16 @@ }, { "name": "laravel/telescope", - "version": "v4.10.1", + "version": "v4.10.2", "source": { "type": "git", "url": "https://github.com/laravel/telescope.git", - "reference": "fcf4d360c003a1d27e2c1b298691645f8942943b" + "reference": "3b1220b71ee08ac7be6be074635df50c2b83ab51" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/telescope/zipball/fcf4d360c003a1d27e2c1b298691645f8942943b", - "reference": "fcf4d360c003a1d27e2c1b298691645f8942943b", + "url": "https://api.github.com/repos/laravel/telescope/zipball/3b1220b71ee08ac7be6be074635df50c2b83ab51", + "reference": "3b1220b71ee08ac7be6be074635df50c2b83ab51", "shasum": "" }, "require": { @@ -4094,9 +4094,9 @@ ], "support": { "issues": "https://github.com/laravel/telescope/issues", - "source": "https://github.com/laravel/telescope/tree/v4.10.1" + "source": "https://github.com/laravel/telescope/tree/v4.10.2" }, - "time": "2022-12-14T15:00:00+00:00" + "time": "2022-12-19T11:20:10+00:00" }, { "name": "laravel/tinker", @@ -5781,16 +5781,16 @@ }, { "name": "nunomaduro/termwind", - "version": "v1.14.2", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/nunomaduro/termwind.git", - "reference": "9a8218511eb1a0965629ff820dda25985440aefc" + "reference": "594ab862396c16ead000de0c3c38f4a5cbe1938d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/termwind/zipball/9a8218511eb1a0965629ff820dda25985440aefc", - "reference": "9a8218511eb1a0965629ff820dda25985440aefc", + "url": "https://api.github.com/repos/nunomaduro/termwind/zipball/594ab862396c16ead000de0c3c38f4a5cbe1938d", + "reference": "594ab862396c16ead000de0c3c38f4a5cbe1938d", "shasum": "" }, "require": { @@ -5847,7 +5847,7 @@ ], "support": { "issues": "https://github.com/nunomaduro/termwind/issues", - "source": "https://github.com/nunomaduro/termwind/tree/v1.14.2" + "source": "https://github.com/nunomaduro/termwind/tree/v1.15.0" }, "funding": [ { @@ -5863,7 +5863,7 @@ "type": "github" } ], - "time": "2022-10-28T22:51:32+00:00" + "time": "2022-12-20T19:00:15+00:00" }, { "name": "nyholm/psr7", @@ -8268,23 +8268,23 @@ }, { "name": "ramsey/uuid", - "version": "4.6.0", + "version": "4.7.0", "source": { "type": "git", "url": "https://github.com/ramsey/uuid.git", - "reference": "ad63bc700e7d021039e30ce464eba384c4a1d40f" + "reference": "5ed9ad582647bbc3864ef78db34bdc1afdcf9b49" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/ad63bc700e7d021039e30ce464eba384c4a1d40f", - "reference": "ad63bc700e7d021039e30ce464eba384c4a1d40f", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/5ed9ad582647bbc3864ef78db34bdc1afdcf9b49", + "reference": "5ed9ad582647bbc3864ef78db34bdc1afdcf9b49", "shasum": "" }, "require": { "brick/math": "^0.8.8 || ^0.9 || ^0.10", "ext-json": "*", "php": "^8.0", - "ramsey/collection": "^1.0" + "ramsey/collection": "^1.2" }, "replace": { "rhumsaa/uuid": "self.version" @@ -8344,7 +8344,7 @@ ], "support": { "issues": "https://github.com/ramsey/uuid/issues", - "source": "https://github.com/ramsey/uuid/tree/4.6.0" + "source": "https://github.com/ramsey/uuid/tree/4.7.0" }, "funding": [ { @@ -8356,7 +8356,7 @@ "type": "tidelift" } ], - "time": "2022-11-05T23:03:38+00:00" + "time": "2022-12-19T22:30:49+00:00" }, { "name": "react/promise", @@ -9314,16 +9314,16 @@ }, { "name": "spatie/laravel-package-tools", - "version": "1.13.7", + "version": "1.13.8", "source": { "type": "git", "url": "https://github.com/spatie/laravel-package-tools.git", - "reference": "4af8e608184471b5568af6265ebb0ca0025c131a" + "reference": "781a2f637237e69c277eb401063acf15e2b4156b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/4af8e608184471b5568af6265ebb0ca0025c131a", - "reference": "4af8e608184471b5568af6265ebb0ca0025c131a", + "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/781a2f637237e69c277eb401063acf15e2b4156b", + "reference": "781a2f637237e69c277eb401063acf15e2b4156b", "shasum": "" }, "require": { @@ -9362,7 +9362,7 @@ ], "support": { "issues": "https://github.com/spatie/laravel-package-tools/issues", - "source": "https://github.com/spatie/laravel-package-tools/tree/1.13.7" + "source": "https://github.com/spatie/laravel-package-tools/tree/1.13.8" }, "funding": [ { @@ -9370,7 +9370,7 @@ "type": "github" } ], - "time": "2022-11-15T09:10:09+00:00" + "time": "2022-12-20T14:09:05+00:00" }, { "name": "spatie/laravel-permission",