Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for o=json on t=caps for newznab api #281

Merged
merged 1 commit into from
Mar 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -14,7 +14,8 @@
"gdwebs/nntp": "^1.0.0",
"ext-mbstring": "*",
"php": ">=5.3.0",
"uskr/nma-php": "^0.0.4"
"uskr/nma-php": "^0.0.4",
"zendframework/zend-xml2json": "^3.0"
},
"require-dev": {
"phpunit/phpunit": "^5.6.2"
Expand Down
145 changes: 144 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 18 additions & 14 deletions lib/page/SpotPage_newznabapi.php
Expand Up @@ -17,28 +17,28 @@ function render() {
# Don't let this output be cached
$this->sendExpireHeaders(true);

/*
* Determine the output type
*/
if ($this->_params['o'] == 'json') {
$outputtype = 'json';
} else {
$outputtype = 'xml';
} # else

/*
* CAPS function is used to query the server for supported features and the protocol version and other
* meta data relevant to the implementation. This function doesn't require the client to provide any
* login information but can be executed out of "login session".
*/
if ($this->_params['t'] == "caps" || $this->_params['t'] == "c") {
$this->caps();
$this->caps($outputtype);
return ;
} # if

# Make sure the user has permissions to retrieve the index
$this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spots_index, '');

/*
* Determine the output type
*/
if ($this->_params['o'] == 'json') {
$outputtype = 'json';
} else {
$outputtype = 'xml';
} # else

/*
* Main switch statement, determines what actually has to be done
*/
Expand Down Expand Up @@ -664,7 +664,7 @@ function getNzb() {
header('Location: ' . $this->_tplHelper->makeBaseUrl("full") . '?page=getnzb&action=display&messageid=' . $this->_params['messageid'] . html_entity_decode($this->_tplHelper->makeApiRequestString()));
} # getNzb

function caps() {
function caps($outputtype) {
$doc = new DOMDocument('1.0', 'utf-8');
$doc->formatOutput = true;

Expand Down Expand Up @@ -733,9 +733,13 @@ function caps() {
$cat->appendChild($subCat);
} # foreach
} # foreach

$this->sendContentTypeHeader('xml');
echo $doc->saveXML();
if ($outputtype == 'json') {
$this->sendContentTypeHeader('json');
echo Zend\Xml2Json\Xml2Json::fromXml($doc->saveXML(),false);
} else {
$this->sendContentTypeHeader('xml');
echo $doc->saveXML();
}
} # caps

function Cat2NewznabCat($hcat, $cat, $catZ) {
Expand Down
1 change: 1 addition & 0 deletions vendor/composer/autoload_namespaces.php
Expand Up @@ -6,6 +6,7 @@
$baseDir = dirname($vendorDir);

return array(
'ZendXml\\' => array($vendorDir . '/zendframework/zendxml/library'),
'Prowl' => array($vendorDir . '/xenji/prowlphp/src'),
'Detection' => array($vendorDir . '/mobiledetect/mobiledetectlib/namespaced'),
);
2 changes: 2 additions & 0 deletions vendor/composer/autoload_psr4.php
Expand Up @@ -7,5 +7,7 @@

return array(
'phpseclib\\' => array($vendorDir . '/phpseclib/phpseclib/phpseclib'),
'Zend\\Xml2Json\\' => array($vendorDir . '/zendframework/zend-xml2json/src'),
'Zend\\Json\\' => array($vendorDir . '/zendframework/zend-json/src'),
'Abraham\\TwitterOAuth\\' => array($vendorDir . '/abraham/twitteroauth/src'),
);
20 changes: 20 additions & 0 deletions vendor/composer/autoload_static.php
Expand Up @@ -18,6 +18,11 @@ class ComposerStaticInit9a4f7282bbaf2b68b9b71f801741479a
array (
'phpseclib\\' => 10,
),
'Z' =>
array (
'Zend\\Xml2Json\\' => 14,
'Zend\\Json\\' => 10,
),
'A' =>
array (
'Abraham\\TwitterOAuth\\' => 21,
Expand All @@ -29,13 +34,28 @@ class ComposerStaticInit9a4f7282bbaf2b68b9b71f801741479a
array (
0 => __DIR__ . '/..' . '/phpseclib/phpseclib/phpseclib',
),
'Zend\\Xml2Json\\' =>
array (
0 => __DIR__ . '/..' . '/zendframework/zend-xml2json/src',
),
'Zend\\Json\\' =>
array (
0 => __DIR__ . '/..' . '/zendframework/zend-json/src',
),
'Abraham\\TwitterOAuth\\' =>
array (
0 => __DIR__ . '/..' . '/abraham/twitteroauth/src',
),
);

public static $prefixesPsr0 = array (
'Z' =>
array (
'ZendXml\\' =>
array (
0 => __DIR__ . '/..' . '/zendframework/zendxml/library',
),
),
'P' =>
array (
'Prowl' =>
Expand Down