From ac0e4667b6f052d868c9ca0bd6f71d672155713f Mon Sep 17 00:00:00 2001 From: DariusIII Date: Fri, 16 Sep 2016 14:11:52 +0200 Subject: [PATCH] Add back reporting of total releases to api response --- Changelog | 1 + nntmux/Releases.php | 9 +++++++++ nntmux/http/Capabilities.php | 4 +++- nntmux/http/XML_Response.php | 11 +++++++++++ www/pages/api.php | 16 ++++++++++------ 5 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Changelog b/Changelog index 30175f9f8..1265c086e 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2016-09-16 DariusIII + * Chg: Add back reporting of total releases to api response * Chg: Group music releases in Gamma theme. 2016-09-15 DariusIII * Chg: Update yenc decode handling for new php-yenc module diff --git a/nntmux/Releases.php b/nntmux/Releases.php index 3a023fb7d..b728c2d90 100755 --- a/nntmux/Releases.php +++ b/nntmux/Releases.php @@ -1118,6 +1118,9 @@ class Releases ); $releases = $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM); + if (!empty($releases) && count($releases)) { + $releases[0]['_totalrows'] = $this->getPagerCount($baseSql); + } return $releases; } @@ -1175,6 +1178,9 @@ class Releases ); $releases = $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM); + if (!empty($releases) && count($releases)) { + $releases[0]['_totalrows'] = $this->getPagerCount($baseSql); + } return $releases; } @@ -1232,6 +1238,9 @@ class Releases ); $releases = $this->pdo->query($sql, true, NN_CACHE_EXPIRY_MEDIUM); + if (!empty($releases) && count($releases)) { + $releases[0]['_totalrows'] = $this->getPagerCount($baseSql); + } return $releases; } diff --git a/nntmux/http/Capabilities.php b/nntmux/http/Capabilities.php index 6a375574c..d40b01206 100755 --- a/nntmux/http/Capabilities.php +++ b/nntmux/http/Capabilities.php @@ -63,9 +63,10 @@ abstract class Capabilities * @param array $data Data to print. * @param array $params Additional request parameters * @param bool $xml True: Print as XML False: Print as JSON. + * @param $offset * @param string $type What type of API query to format if XML */ - public function output($data, $params, $xml = true, $type = '') + public function output($data, $params, $xml = true, $offset, $type = '') { $this->type = $type; @@ -73,6 +74,7 @@ abstract class Capabilities 'Parameters' => $params, 'Data' => $data, 'Server' => $this->getForMenu(), + 'Offset' => $offset, 'Type' => $type ]; diff --git a/nntmux/http/XML_Response.php b/nntmux/http/XML_Response.php index b77b95aec..e21d9b147 100755 --- a/nntmux/http/XML_Response.php +++ b/nntmux/http/XML_Response.php @@ -95,6 +95,7 @@ class XML_Response 'Parameters' => null, 'Data' => null, 'Server' => null, + 'Offset' => null, 'Type' => null, ]; $options += $defaults; @@ -102,6 +103,7 @@ class XML_Response $this->parameters = $options['Parameters']; $this->releases = $options['Data']; $this->server = $options['Server']; + $this->offset = $options['Offset']; $this->type = $options['Type']; $this->xml = new \XMLWriter(); @@ -172,6 +174,7 @@ class XML_Response $this->includeRssAtomLink(); $this->includeMetaInfo(); $this->includeImage(); + $this->includeTotalRows(); $this->includeReleases(); $w->endElement(); // End channel $w->endElement(); // End RSS @@ -335,6 +338,14 @@ class XML_Response $this->xml->endElement(); } + public function includeTotalRows() + { + $this->xml->startElement($this->namespace.":response"); + $this->xml->writeAttribute('offset', $this->offset); + $this->xml->writeAttribute('total', isset($this->releases[0]['_totalrows']) ? $this->releases[0]['_totalrows'] : 0); + $this->xml->endElement(); + } + /** * Loop through the releases and add their info to the XML stream */ diff --git a/www/pages/api.php b/www/pages/api.php index 6ba78a9a5..196c2740b 100644 --- a/www/pages/api.php +++ b/www/pages/api.php @@ -125,11 +125,15 @@ switch ($function) { "basic", $categoryID, $minSize ); } else { + $totalRows = $releases->getBrowseCount($categoryID, $maxAge, $catExclusions); $relData = $releases->getBrowseRange( $categoryID, $offset, $limit, '', $maxAge, $catExclusions, $groupName, $minSize ); + if ($totalRows > 0 && count($relData) > 0) { + $relData[0]['_totalrows'] = $totalRows; + } } - $api->output($relData, $params, $outputXML, 'api'); + $api->output($relData, $params, $outputXML, $offset, 'api'); break; // Search tv releases. case 'tv': @@ -183,7 +187,7 @@ switch ($function) { ); $api->addLanguage($relData); - $api->output($relData, $params, $outputXML, 'api'); + $api->output($relData, $params, $outputXML, $offset, 'api'); break; // Search movie releases. @@ -212,7 +216,7 @@ switch ($function) { ); $api->addLanguage($relData); - $api->output($relData, $params, $outputXML, 'api'); + $api->output($relData, $params, $outputXML, $offset, 'api'); break; // Get NZB. @@ -250,7 +254,7 @@ switch ($function) { if ($data) { $relData[] = $data; } - $api->output($relData, $params, $outputXML, 'api'); + $api->output($relData, $params, $outputXML, $offset, 'api'); break; // Get an NFO file for an individual release. @@ -282,7 +286,7 @@ switch ($function) { // Capabilities request. case 'c': - $api->output('', $params, $outputXML, 'caps'); + $api->output('', $params, $outputXML, $offset, 'caps'); break; // Register request. case 'r': @@ -318,6 +322,6 @@ switch ($function) { $params['password'] = $password; $params['token'] = $userData['rsstoken']; - $api->output('', $params, true, 'reg'); + $api->output('', $params, true, $offset, 'reg'); break; }