mirror of
https://github.com/NNTmux/newznab-tmux.git
synced 2026-08-29 01:08:56 +00:00
Fix API/RSS feeds
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
2017-08-11 DariusIII
|
||||
* Fix: Fix API/RSS feeds
|
||||
* Chg: Update API/RSS related classes
|
||||
* Chg: Revert inserting apikey into old behavior
|
||||
* Chg: Change the length of rsstoken (api key)
|
||||
|
||||
@@ -127,7 +127,7 @@ abstract class Capabilities
|
||||
if (isset($_SERVER['SERVER_NAME'])) {
|
||||
$serverroot = (
|
||||
($https === true ? 'https://' : 'http://') . $_SERVER['SERVER_NAME'] .
|
||||
(($_SERVER['SERVER_PORT'] !== '80' && $_SERVER['SERVER_PORT'] !== '443') ? ':' . $_SERVER['SERVER_PORT'] : '') .
|
||||
(((int)$_SERVER['SERVER_PORT'] !== 80 && (int)$_SERVER['SERVER_PORT'] !== 443) ? ':' . $_SERVER['SERVER_PORT'] : '') .
|
||||
WWW_TOP . '/'
|
||||
);
|
||||
}
|
||||
|
||||
+8
-15
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace nntmux\http;
|
||||
|
||||
use nntmux\db\DB;
|
||||
use nntmux\Releases;
|
||||
use nntmux\Category;
|
||||
use nntmux\NZB;
|
||||
@@ -19,11 +18,6 @@ Class RSS extends Capabilities
|
||||
*/
|
||||
public $releases;
|
||||
|
||||
/** DB class
|
||||
* @var \nntmux\db\Settings
|
||||
*/
|
||||
public $pdo;
|
||||
|
||||
/**
|
||||
* @param array $options
|
||||
*
|
||||
@@ -38,7 +32,6 @@ Class RSS extends Capabilities
|
||||
];
|
||||
$options += $defaults;
|
||||
|
||||
$this->pdo = ($options['Settings'] instanceof DB ? $options['Settings'] : new DB());
|
||||
$this->releases = ($options['Releases'] instanceof Releases ? $options['Releases'] : new Releases(['Settings' => $this->pdo]));
|
||||
}
|
||||
|
||||
@@ -109,7 +102,7 @@ Class RSS extends Capabilities
|
||||
($videosId > 0 ? sprintf('AND r.videos_id = %d %s', $videosId, ($catSearch === '' ? $catLimit : '')) : ''),
|
||||
($aniDbID > 0 ? sprintf('AND r.anidbid = %d %s', $aniDbID, ($catSearch === '' ? $catLimit : '')) : ''),
|
||||
($airDate > -1 ? sprintf('AND tve.firstaired >= DATE_SUB(CURDATE(), INTERVAL %d DAY)', $airDate) : ''),
|
||||
' LIMIT 0,' . ($offset > 100 ? 100 : $offset)
|
||||
(' LIMIT 0,' . ($offset > 100 ? 100 : $offset))
|
||||
), true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
return $sql;
|
||||
@@ -163,7 +156,7 @@ Class RSS extends Capabilities
|
||||
Category::TV_ROOT,
|
||||
Category::TV_OTHER,
|
||||
$this->releases->showPasswords,
|
||||
' LIMIT ' . ($limit > 100 ? 100 : $limit) . ' OFFSET 0'
|
||||
(' LIMIT ' . ($limit > 100 ? 100 : $limit) . ' OFFSET 0')
|
||||
), true, NN_CACHE_EXPIRY_MEDIUM
|
||||
);
|
||||
}
|
||||
@@ -213,7 +206,7 @@ Class RSS extends Capabilities
|
||||
Category::MOVIE_ROOT,
|
||||
Category::MOVIE_OTHER,
|
||||
$this->releases->showPasswords,
|
||||
' LIMIT ' . ($limit > 100 ? 100 : $limit) . ' OFFSET 0'
|
||||
(' LIMIT ' . ($limit > 100 ? 100 : $limit) . ' OFFSET 0')
|
||||
),
|
||||
true,
|
||||
NN_CACHE_EXPIRY_MEDIUM
|
||||
@@ -231,11 +224,11 @@ Class RSS extends Capabilities
|
||||
public function getFirstInstance($column, $table, $order)
|
||||
{
|
||||
return $this->pdo->queryOneRow(
|
||||
sprintf("
|
||||
SELECT %1\$s
|
||||
FROM %2\$s
|
||||
WHERE %1\$s > 0
|
||||
ORDER BY %3\$s ASC",
|
||||
sprintf('
|
||||
SELECT %1$s
|
||||
FROM %2$s
|
||||
WHERE %1$s > 0
|
||||
ORDER BY %3$s ASC',
|
||||
$column,
|
||||
$table,
|
||||
$order
|
||||
|
||||
@@ -86,17 +86,12 @@ class XML_Response
|
||||
*/
|
||||
protected $xml;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected $offset;
|
||||
|
||||
/**
|
||||
* XMLReturn constructor.
|
||||
*
|
||||
* @param array $options
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
public function __construct($options = [])
|
||||
{
|
||||
$defaults = [
|
||||
'Parameters' => null,
|
||||
@@ -119,9 +114,9 @@ class XML_Response
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
* @return bool|void
|
||||
*/
|
||||
public function returnXML(): bool
|
||||
public function returnXML()
|
||||
{
|
||||
if ($this->xml) {
|
||||
switch ($this->type) {
|
||||
@@ -152,7 +147,7 @@ class XML_Response
|
||||
*
|
||||
* @return string The XML Formatted string data
|
||||
*/
|
||||
protected function returnCaps(): string
|
||||
protected function returnCaps()
|
||||
{
|
||||
$w = $this->xml;
|
||||
$s = $this->server;
|
||||
@@ -175,7 +170,7 @@ class XML_Response
|
||||
*
|
||||
* @return string The XML Formatted string data
|
||||
*/
|
||||
protected function returnApiRss(): string
|
||||
protected function returnApiRss()
|
||||
{
|
||||
$w = $this->xml;
|
||||
$this->xml->startDocument('1.0', 'UTF-8');
|
||||
@@ -196,7 +191,7 @@ class XML_Response
|
||||
/**
|
||||
* @return string The XML formatted registration information
|
||||
*/
|
||||
protected function returnReg(): string
|
||||
protected function returnReg()
|
||||
{
|
||||
$this->xml->startDocument('1.0', 'UTF-8');
|
||||
$this->xml->startElement('register');
|
||||
@@ -214,7 +209,7 @@ class XML_Response
|
||||
*
|
||||
* @param array $element An array with the name of the element and the attribute data
|
||||
*/
|
||||
protected function addNode($element): void
|
||||
protected function addNode($element)
|
||||
{
|
||||
$this->xml->startElement($element['name']);
|
||||
foreach ($element['data'] AS $attr => $val) {
|
||||
@@ -228,7 +223,7 @@ class XML_Response
|
||||
*
|
||||
* @param array $element An array with the name of the element and the attribute data
|
||||
*/
|
||||
protected function addNodes($element): void
|
||||
protected function addNodes($element)
|
||||
{
|
||||
$this->xml->startElement($element['name']);
|
||||
foreach ($element['data'] AS $elem => $value) {
|
||||
@@ -242,21 +237,21 @@ class XML_Response
|
||||
/**
|
||||
* Adds the site category listing to the XML feed
|
||||
*/
|
||||
protected function writeCategoryListing(): void
|
||||
protected function writeCategoryListing()
|
||||
{
|
||||
$this->xml->startElement('categories');
|
||||
foreach ($this->server['categories'] AS $p) {
|
||||
$this->xml->startElement('category');
|
||||
$this->xml->writeAttribute('id', $p['id']);
|
||||
$this->xml->writeAttribute('name', html_entity_decode($p['title']));
|
||||
if ($p['description'] !== '') {
|
||||
if ($p['description'] != '') {
|
||||
$this->xml->writeAttribute('description', html_entity_decode($p['description']));
|
||||
}
|
||||
foreach ($p['subcatlist'] AS $c) {
|
||||
$this->xml->startElement('subcat');
|
||||
$this->xml->writeAttribute('id', $c['id']);
|
||||
$this->xml->writeAttribute('name', html_entity_decode($c['title']));
|
||||
if ($c['description'] !== '') {
|
||||
if ($c['description'] != '') {
|
||||
$this->xml->writeAttribute('description', html_entity_decode($c['description']));
|
||||
}
|
||||
$this->xml->endElement();
|
||||
@@ -269,7 +264,7 @@ class XML_Response
|
||||
* Adds RSS Atom information to the XML
|
||||
*
|
||||
*/
|
||||
protected function includeRssAtom(): void
|
||||
protected function includeRssAtom()
|
||||
{
|
||||
switch ($this->namespace) {
|
||||
case 'newznab':
|
||||
@@ -290,7 +285,7 @@ class XML_Response
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function includeRssAtomLink(): void
|
||||
protected function includeRssAtomLink()
|
||||
{
|
||||
$this->xml->startElement('atom:link');
|
||||
$this->xml->startAttribute('href');
|
||||
@@ -308,7 +303,7 @@ class XML_Response
|
||||
/**
|
||||
* Writes the channel information for the feed
|
||||
*/
|
||||
protected function includeMetaInfo(): void
|
||||
protected function includeMetaInfo()
|
||||
{
|
||||
$server = $this->server['server'];
|
||||
|
||||
@@ -337,7 +332,7 @@ class XML_Response
|
||||
/**
|
||||
* Adds nntmux logo data to the XML
|
||||
*/
|
||||
protected function includeImage(): void
|
||||
protected function includeImage()
|
||||
{
|
||||
$this->xml->startElement('image');
|
||||
$this->xml->writeAttribute('url', $this->server['server']['url'] . 'themes/shared/images/logo.png');
|
||||
@@ -350,18 +345,18 @@ class XML_Response
|
||||
$this->xml->endElement();
|
||||
}
|
||||
|
||||
public function includeTotalRows(): void
|
||||
public function includeTotalRows()
|
||||
{
|
||||
$this->xml->startElement($this->namespace . ":response");
|
||||
$this->xml->writeAttribute('offset', $this->offset);
|
||||
$this->xml->writeAttribute('total', $this->releases[0]['_totalrows'] ?? 0);
|
||||
$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
|
||||
*/
|
||||
public function includeReleases(): void
|
||||
public function includeReleases()
|
||||
{
|
||||
if (is_array($this->releases) && !empty($this->releases)) {
|
||||
foreach ($this->releases AS $this->release) {
|
||||
@@ -376,7 +371,7 @@ class XML_Response
|
||||
/**
|
||||
* Writes the primary release information
|
||||
*/
|
||||
public function includeReleaseMain(): void
|
||||
public function includeReleaseMain()
|
||||
{
|
||||
$this->xml->writeElement('title', $this->release['searchname']);
|
||||
$this->xml->startElement('guid');
|
||||
@@ -387,7 +382,7 @@ class XML_Response
|
||||
'link',
|
||||
"{$this->server['server']['url']}getnzb/{$this->release['guid']}.nzb" .
|
||||
"&i={$this->parameters['uid']}" . "&r={$this->parameters['token']}" .
|
||||
((int)$this->parameters['del'] === 1 ? '&del=1' : '')
|
||||
($this->parameters['del'] == '1' ? "&del=1" : '')
|
||||
);
|
||||
$this->xml->writeElement('comments', "{$this->server['server']['url']}details/{$this->release['guid']}#comments");
|
||||
$this->xml->writeElement('pubDate', date(DATE_RSS, strtotime($this->release['adddate'])));
|
||||
@@ -403,7 +398,7 @@ class XML_Response
|
||||
'url',
|
||||
"{$this->server['server']['url']}getnzb/{$this->release['guid']}.nzb" .
|
||||
"&i={$this->parameters['uid']}" . "&r={$this->parameters['token']}" .
|
||||
((int)$this->parameters['del'] === 1 ? '&del=1' : '')
|
||||
($this->parameters['del'] == '1' ? "&del=1" : '')
|
||||
);
|
||||
$this->xml->writeAttribute('length', $this->release['size']);
|
||||
$this->xml->writeAttribute('type', 'application/x-nzb');
|
||||
@@ -414,7 +409,7 @@ class XML_Response
|
||||
/**
|
||||
* Writes the Zed (newznab) specific attributes
|
||||
*/
|
||||
protected function setZedAttributes(): void
|
||||
protected function setZedAttributes()
|
||||
{
|
||||
$this->writeZedAttr('category', $this->release['categories_id']);
|
||||
$this->writeZedAttr('size', $this->release['size']);
|
||||
@@ -425,10 +420,10 @@ class XML_Response
|
||||
);
|
||||
}
|
||||
|
||||
if ((int)$this->parameters['extended'] === 1) {
|
||||
if ($this->parameters['extended'] == 1) {
|
||||
$this->writeZedAttr('files', $this->release['totalpart']);
|
||||
$this->writeZedAttr('poster', $this->release['fromname']);
|
||||
if ($this->namespace === 'newznab' && ($this->release['videos_id'] > 0 || $this->release['tv_episodes_id'] > 0)) {
|
||||
if (($this->release['videos_id'] > 0 || $this->release['tv_episodes_id'] > 0) && $this->namespace === 'newznab') {
|
||||
$this->setTvAttr();
|
||||
}
|
||||
|
||||
@@ -441,7 +436,7 @@ class XML_Response
|
||||
if (isset($this->release['predb_id']) && $this->release['predb_id'] > 0) {
|
||||
$this->writeZedAttr('prematch', 1);
|
||||
}
|
||||
if (isset($this->release['nfostatus']) && (int)$this->release['nfostatus'] === 1) {
|
||||
if (isset($this->release['nfostatus']) && $this->release['nfostatus'] == 1) {
|
||||
$this->writeZedAttr(
|
||||
'info',
|
||||
$this->server['server']['url'] .
|
||||
@@ -462,7 +457,7 @@ class XML_Response
|
||||
/**
|
||||
* Writes the TV Specific attributes
|
||||
*/
|
||||
protected function setTvAttr(): void
|
||||
protected function setTvAttr()
|
||||
{
|
||||
if (!empty($this->release['title'])) {
|
||||
$this->writeZedAttr('title', $this->release['title']);
|
||||
@@ -505,7 +500,7 @@ class XML_Response
|
||||
*/
|
||||
protected function writeZedAttr($name, $value)
|
||||
{
|
||||
$this->xml->startElement($this->namespace . ':attr');
|
||||
$this->xml->startElement($this->namespace . ":attr");
|
||||
$this->xml->writeAttribute('name', $name);
|
||||
$this->xml->writeAttribute('value', $value);
|
||||
$this->xml->endElement();
|
||||
@@ -515,7 +510,7 @@ class XML_Response
|
||||
* Writes the cData (HTML format) for the RSS feed
|
||||
* Also calls supplementary cData writes depending upon post process
|
||||
*/
|
||||
protected function writeRssCdata(): void
|
||||
protected function writeRssCdata()
|
||||
{
|
||||
$this->cdata = '';
|
||||
|
||||
@@ -543,7 +538,7 @@ class XML_Response
|
||||
$column = 'bookinfo_id';
|
||||
break;
|
||||
}
|
||||
if (isset($dir, $column)) {
|
||||
if (isset($dir) && isset($column)) {
|
||||
$dcov = ($dir === 'movies' ? '-cover' : '');
|
||||
$this->cdata .=
|
||||
"\t<img style=\"margin-left:10px;margin-bottom:10px;float:right;\" " .
|
||||
@@ -584,22 +579,22 @@ class XML_Response
|
||||
"{$r['searchname']}.nfo</a></li>\n";
|
||||
}
|
||||
|
||||
if ((int)$r['parentid'] === (int)Category::MOVIE_ROOT && $r['imdbid'] !== '') {
|
||||
if ($r['parentid'] == Category::MOVIE_ROOT && $r['imdbid'] != '') {
|
||||
$this->writeRssMovieInfo();
|
||||
} else if ((int)$r['parentid'] === (int)Category::MUSIC_ROOT && $r['musicinfo_id'] > 0) {
|
||||
} else if ($r['parentid'] == Category::MUSIC_ROOT && $r['musicinfo_id'] > 0) {
|
||||
$this->writeRssMusicInfo();
|
||||
} else if ((int)$r['parentid'] === (int)Category::GAME_ROOT && $r['consoleinfo_id'] > 0) {
|
||||
} else if ($r['parentid'] == Category::GAME_ROOT && $r['consoleinfo_id'] > 0) {
|
||||
$this->writeRssConsoleInfo();
|
||||
}
|
||||
$w->startElement('description');
|
||||
$w->writeCData($this->cdata . "\t</div>");
|
||||
$w->writeCdata($this->cdata . "\t</div>");
|
||||
$w->endElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the Movie Info for the RSS feed cData
|
||||
*/
|
||||
protected function writeRssMovieInfo(): void
|
||||
protected function writeRssMovieInfo()
|
||||
{
|
||||
$r = $this->release;
|
||||
|
||||
@@ -620,7 +615,7 @@ class XML_Response
|
||||
/**
|
||||
* Writes the Music Info for the RSS feed cData
|
||||
*/
|
||||
protected function writeRssMusicInfo(): void
|
||||
protected function writeRssMusicInfo()
|
||||
{
|
||||
$r = $this->release;
|
||||
$tData = $cDataUrl = '';
|
||||
@@ -640,7 +635,7 @@ class XML_Response
|
||||
{$cData}
|
||||
</ul>
|
||||
</li>\n";
|
||||
if ($r['mu_tracks'] !== '') {
|
||||
if ($r['mu_tracks'] != '') {
|
||||
$tracks = explode('|', $r['mu_tracks']);
|
||||
if (count($tracks) > 0) {
|
||||
foreach ($tracks AS $track) {
|
||||
@@ -660,7 +655,7 @@ class XML_Response
|
||||
/**
|
||||
* Writes the Console Info for the RSS feed cData
|
||||
*/
|
||||
protected function writeRssConsoleInfo(): void
|
||||
protected function writeRssConsoleInfo()
|
||||
{
|
||||
$r = $this->release;
|
||||
$gamesCol = ['co_genre', 'co_publisher', 'year', 'co_review'];
|
||||
@@ -683,7 +678,7 @@ class XML_Response
|
||||
*
|
||||
* @return string The HTML format cData
|
||||
*/
|
||||
protected function buildCdata($columns): string
|
||||
protected function buildCdata($columns)
|
||||
{
|
||||
$r = $this->release;
|
||||
|
||||
@@ -691,7 +686,7 @@ class XML_Response
|
||||
|
||||
foreach ($columns AS $info) {
|
||||
if (!empty($r[$info])) {
|
||||
if ($info === 'mu_releasedate') {
|
||||
if ($info == 'mu_releasedate') {
|
||||
$ucInfo = 'Released';
|
||||
$rDate = date('Y-m-d', strtotime($r[$info]));
|
||||
$cData .= "<li>{$ucInfo}: {$rDate}</li>\n";
|
||||
|
||||
Reference in New Issue
Block a user