PageRenderTime 53ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/page/SpotPage_newznabapi.php

https://github.com/elstenaar86/spotweb
PHP | 765 lines | 614 code | 127 blank | 24 comment | 98 complexity | 7f33683a78ec1b8074657e5f9cdae496 MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0, MPL-2.0-no-copyleft-exception, 0BSD, Apache-2.0
  1. <?php
  2. class SpotPage_newznabapi extends SpotPage_Abs {
  3. private $_params;
  4. function __construct(SpotDb $db, SpotSettings $settings, $currentSession, $params) {
  5. parent::__construct($db, $settings, $currentSession);
  6. $this->_params = $params;
  7. } # __construct
  8. function render() {
  9. # we willen niet dat de API output gecached wordt
  10. $this->sendExpireHeaders(true);
  11. # CAPS function is used to query the server for supported features and the protocol version and other
  12. # meta data relevant to the implementation. This function doesn't require the client to provide any
  13. # login information but can be executed out of "login session".
  14. if ($this->_params['t'] == "caps" || $this->_params['t'] == "c") {
  15. $this->caps();
  16. return ;
  17. } # if
  18. # Controleer de users' rechten
  19. $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spots_index, '');
  20. $outputtype = ($this->_params['o'] == "json") ? "json" : "xml";
  21. switch ($this->_params['t']) {
  22. case "" : $this->showApiError(200); break;
  23. case "search" :
  24. case "s" :
  25. case "tvsearch" :
  26. case "t" :
  27. case "music" :
  28. case "movie" :
  29. case "m" : $this->search($outputtype); break;
  30. case "d" :
  31. case "details" : $this->spotDetails($outputtype); break;
  32. case "g" :
  33. case "get" : $this->getNzb(); break;
  34. default : $this->showApiError(202);
  35. } # switch
  36. } # render()
  37. function search($outputtype) {
  38. # Controleer de users' rechten
  39. $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_perform_search, '');
  40. $spotsOverview = new SpotsOverview($this->_db, $this->_settings);
  41. $search = array();
  42. if (($this->_params['t'] == "t" || $this->_params['t'] == "tvsearch") && $this->_params['rid'] != "") {
  43. # validate input
  44. if (!preg_match('/^[0-9]{1,6}$/', $this->_params['rid'])) {
  45. $this->showApiError(201);
  46. return ;
  47. } # if
  48. # fetch remote content
  49. $dom = new DomDocument();
  50. $dom->prevservWhiteSpace = false;
  51. if (!@list($http_code, $tvrage) = $spotsOverview->getFromWeb('http://services.tvrage.com/feeds/showinfo.php?sid=' . $this->_params['rid'], false, 24*60*60)) {
  52. $this->showApiError(300);
  53. return ;
  54. } # if
  55. $dom->loadXML($tvrage['content']);
  56. $showTitle = $dom->getElementsByTagName('showname');
  57. # TVRage geeft geen 404 indien niet gevonden, dus vangen we dat zelf netjes op
  58. if (!@$showTitle->item(0)->nodeValue) {
  59. $this->showApiError(300);
  60. return ;
  61. } # if
  62. $tvSearch = $showTitle->item(0)->nodeValue;
  63. $epSearch = '';
  64. if (preg_match('/^[sS][0-9]{1,2}$/', $this->_params['season']) || preg_match('/^[0-9]{1,4}$/', $this->_params['season'])) {
  65. if (strlen($this->_params['season']) < 3) {
  66. $epSearch = (is_numeric($this->_params['season'])) ? 'S' . str_pad($this->_params['season'], 2, "0", STR_PAD_LEFT) : $this->_params['season'];
  67. } else {
  68. $epSearch = $this->_params['season'] . ' ';
  69. } # else
  70. } elseif ($this->_params['season'] != "") {
  71. $this->showApiError(201);
  72. return ;
  73. } # if
  74. if (preg_match('/^[eE][0-9]{1,2}$/', $this->_params['ep']) || preg_match('/^[0-9]{1,2}$/', $this->_params['ep']) || preg_match('/^[0-9]{1,2}\/[0-9]{1,2}$/', $this->_params['ep'])) {
  75. $epSearch .= (is_numeric($this->_params['ep'])) ? 'E' . str_pad($this->_params['ep'], 2, "0", STR_PAD_LEFT) : $this->_params['ep'];
  76. } elseif ($this->_params['ep'] != "") {
  77. $this->showApiError(201);
  78. return ;
  79. } # if
  80. # The + operator is supported both by PostgreSQL and MySQL's FTS
  81. $search['value'][] = "Titel:=:+\"" . trim($tvSearch) . "\" +" . $epSearch;
  82. } elseif ($this->_params['t'] == "music") {
  83. if (empty($this->_params['artist']) && empty($this->_params['cat'])) {
  84. $this->_params['cat'] = 3000;
  85. } else {
  86. $search['value'][] = "Titel:=:\"" . $this->_params['artist'] . "\"";
  87. } # if
  88. } elseif ($this->_params['t'] == "m" || $this->_params['t'] == "movie") {
  89. # validate input
  90. if ($this->_params['imdbid'] == "") {
  91. $this->showApiError(200);
  92. return ;
  93. } elseif (!preg_match('/^[0-9]{1,8}$/', $this->_params['imdbid'])) {
  94. $this->showApiError(201);
  95. return ;
  96. } # if
  97. # fetch remote content
  98. if (!@list($http_code, $imdb) = $spotsOverview->getFromWeb('http://uk.imdb.com/title/tt' . $this->_params['imdbid'] . '/', false, 24*60*60)) {
  99. $this->showApiError(300);
  100. return ;
  101. } # if
  102. preg_match('/<h1 class="header"> <span class="itemprop" itemprop="name">([^\<]*)<\/span/ms', $imdb['content'], $movieTitle);
  103. /* Extract the release date from the IMDB info page */
  104. if (preg_match('/\<a href="\/year\/([0-9]{4})/ms', $imdb['content'], $movieReleaseDate)) {
  105. $movieReleaseDate = '"+(' . $movieReleaseDate[1] . ')"';
  106. } else {
  107. $movieReleaseDate = '';
  108. } # else
  109. $search['value'][] = "Titel:=:+\"" . trim($movieTitle[1]) . "\" " . $movieReleaseDate;
  110. // imdb sometimes returns the title translated, if so, pass the original title as well
  111. preg_match('/<span class="title-extra" itemprop="name">([^\<]*)<i>/ms', $imdb['content'], $originalTitle);
  112. if ((!empty($originalTitle)) && ($originalTitle[1] != $movieTitle[1])) {
  113. $search['value'][] = "Titel:=:+\"" . trim($originalTitle[1]) . "\" " . $movieReleasedate;
  114. } elseif (!empty($this->_params['q'])) {
  115. $searchTerm = str_replace(" ", " +", $this->_params['q']);
  116. $search['value'][] = "Titel:=:+" . $searchTerm;
  117. } # elseif
  118. if ($this->_params['maxage'] != "" && is_numeric($this->_params['maxage']))
  119. $search['value'][] = "date:>:-" . $this->_params['maxage'] . "days";
  120. $tmpCat = array();
  121. foreach (explode(",", $this->_params['cat']) as $category) {
  122. $tmpCat[] = $this->nabcat2spotcat($category);
  123. } # foreach
  124. $search['tree'] = implode(",", $tmpCat);
  125. # Spots met een filesize 0 niet opvragen
  126. $search['value'][] = "filesize:>:0";
  127. $limit = $this->_currentSession['user']['prefs']['perpage'];
  128. if ($this->_params['limit'] != "" && is_numeric($this->_params['limit']) && $this->_params['limit'] < 500)
  129. $limit = $this->_params['limit'];
  130. $pageNr = ($this->_params['offset'] != "" && is_numeric($this->_params['offset'])) ? $this->_params['offset'] : 0;
  131. $offset = $pageNr*$limit;
  132. $spotUserSystem = new SpotUserSystem($this->_db, $this->_settings);
  133. $parsedSearch = $spotsOverview->filterToQuery($search, array('field' => 'stamp', 'direction' => 'DESC'), $this->_currentSession,
  134. $spotUserSystem->getIndexFilter($this->_currentSession['user']['userid']));
  135. $spots = $spotsOverview->loadSpots($this->_currentSession['user']['userid'],
  136. $pageNr,
  137. $limit,
  138. $parsedSearch);
  139. $this->showResults($spots, $offset, $outputtype);
  140. } # search
  141. function showResults($spots, $offset, $outputtype) {
  142. $nzbhandling = $this->_currentSession['user']['prefs']['nzbhandling'];
  143. if ($outputtype == "json") {
  144. $doc = array();
  145. foreach($spots['list'] as $spot) {
  146. $data = array();
  147. $data['ID'] = $spot['messageid'];
  148. $data['name'] = $spot['title'];
  149. $data['size'] = $spot['filesize'];
  150. $data['adddate'] = date('Y-m-d H:i:s', $spot['stamp']);
  151. $data['guid'] = $spot['messageid'];
  152. $data['fromname'] = $spot['poster'];
  153. $data['completion'] = 100;
  154. $nabCat = explode("|", $this->Cat2NewznabCat($spot['category'], $spot['subcata']));
  155. if ($nabCat[0] != "" && is_numeric($nabCat[0])) {
  156. $data['categoryID'] = $nabCat[0];
  157. $cat = implode(",", $nabCat);
  158. } # if
  159. $nabCat = explode("|", $this->Cat2NewznabCat($spot['category'], $spot['subcatb']));
  160. if ($nabCat[0] != "" && is_numeric($nabCat[0])) {
  161. $cat .= "," . $nabCat[0];
  162. } # if
  163. $data['comments'] = $spot['commentcount'];
  164. $data['category_name'] = SpotCategories::HeadCat2Desc($spot['category']) . ': ' . SpotCategories::Cat2ShortDesc($spot['category'], $spot['subcata']);
  165. $data['category_ids'] = $cat;
  166. if (empty($doc)) {
  167. $data['_totalrows'] = count($spots['list']);
  168. }
  169. $doc[] = $data;
  170. } # foreach
  171. echo json_encode($doc);
  172. } else {
  173. # Opbouwen XML
  174. $doc = new DOMDocument('1.0', 'utf-8');
  175. $doc->formatOutput = true;
  176. $rss = $doc->createElement('rss');
  177. $rss->setAttribute('version', '2.0');
  178. $rss->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
  179. $rss->setAttribute('xmlns:newznab', 'http://www.newznab.com/DTD/2010/feeds/attributes/');
  180. $doc->appendChild($rss);
  181. $atomSelfLink = $doc->createElement('atom:link');
  182. $atomSelfLink->setAttribute('href', $this->_settings->get('spotweburl') . 'api');
  183. $atomSelfLink->setAttribute('rel', 'self');
  184. $atomSelfLink->setAttribute('type', 'application/rss+xml');
  185. $channel = $doc->createElement('channel');
  186. $channel->appendChild($atomSelfLink);
  187. $channel->appendChild($doc->createElement('title', 'Spotweb Index'));
  188. $channel->appendChild($doc->createElement('description', 'Spotweb Index API Results'));
  189. $channel->appendChild($doc->createElement('link', $this->_settings->get('spotweburl')));
  190. $channel->appendChild($doc->createElement('language', 'en-gb'));
  191. $channel->appendChild($doc->createElement('webMaster', $this->_currentSession['user']['mail'] . ' (' . $this->_currentSession['user']['firstname'] . ' ' . $this->_currentSession['user']['lastname'] . ')'));
  192. $channel->appendChild($doc->createElement('category', ''));
  193. $rss->appendChild($channel);
  194. $image = $doc->createElement('image');
  195. $image->appendChild($doc->createElement('url', $this->_settings->get('spotweburl') . 'images/spotnet.gif'));
  196. $image->appendChild($doc->createElement('title', 'Spotweb Index'));
  197. $image->appendChild($doc->createElement('link', $this->_settings->get('spotweburl')));
  198. $image->appendChild($doc->createElement('description', 'SpotWeb Index API Results'));
  199. $channel->appendChild($image);
  200. $newznabResponse = $doc->createElement('newznab:response');
  201. $newznabResponse->setAttribute('offset', $offset);
  202. $newznabResponse->setAttribute('total', count($spots['list']));
  203. $channel->appendChild($newznabResponse);
  204. foreach($spots['list'] as $spot) {
  205. $spot = $this->_tplHelper->formatSpotHeader($spot);
  206. $nzbUrl = $this->_tplHelper->makeBaseUrl("full") . 'api?t=g&amp;id=' . $spot['messageid'] . $this->_tplHelper->makeApiRequestString();
  207. if ($this->_params['del'] == "1" && $this->_spotSec->allowed(SpotSecurity::spotsec_keep_own_watchlist, '')) {
  208. $nzbUrl .= '&amp;del=1';
  209. } # if
  210. $guid = $doc->createElement('guid', $spot['messageid']);
  211. $guid->setAttribute('isPermaLink', 'false');
  212. $item = $doc->createElement('item');
  213. $item->appendChild($doc->createElement('title', htmlspecialchars($spot['title'], ENT_QUOTES, "UTF-8")));
  214. $item->appendChild($guid);
  215. $item->appendChild($doc->createElement('link', $nzbUrl));
  216. $item->appendChild($doc->createElement('pubDate', date('r', $spot['stamp'])));
  217. $item->appendChild($doc->createElement('category', SpotCategories::HeadCat2Desc($spot['category']) . " > " . SpotCategories::Cat2ShortDesc($spot['category'], $spot['subcata'])));
  218. $channel->appendChild($item);
  219. $enclosure = $doc->createElement('enclosure');
  220. $enclosure->setAttribute('url', html_entity_decode($nzbUrl));
  221. $enclosure->setAttribute('length', $spot['filesize']);
  222. switch ($nzbhandling['prepare_action']) {
  223. case 'zip' : $enclosure->setAttribute('type', 'application/zip'); break;
  224. default : $enclosure->setAttribute('type', 'application/x-nzb');
  225. } # switch
  226. $item->appendChild($enclosure);
  227. $nabCat = explode("|", $this->Cat2NewznabCat($spot['category'], $spot['subcata']));
  228. if ($nabCat[0] != "" && is_numeric($nabCat[0])) {
  229. $attr = $doc->createElement('newznab:attr');
  230. $attr->setAttribute('name', 'category');
  231. $attr->setAttribute('value', $nabCat[0]);
  232. $item->appendChild($attr);
  233. $attr = $doc->createElement('newznab:attr');
  234. $attr->setAttribute('name', 'category');
  235. $attr->setAttribute('value', $nabCat[1]);
  236. $item->appendChild($attr);
  237. } # if
  238. $nabCat = explode("|", $this->Cat2NewznabCat($spot['category'], $spot['subcatb']));
  239. if ($nabCat[0] != "" && is_numeric($nabCat[0])) {
  240. $attr = $doc->createElement('newznab:attr');
  241. $attr->setAttribute('name', 'category');
  242. $attr->setAttribute('value', $nabCat[0]);
  243. $item->appendChild($attr);
  244. } # if
  245. $attr = $doc->createElement('newznab:attr');
  246. $attr->setAttribute('name', 'size');
  247. $attr->setAttribute('value', $spot['filesize']);
  248. $item->appendChild($attr);
  249. if ($this->_params['extended'] != "0") {
  250. $attr = $doc->createElement('newznab:attr');
  251. $attr->setAttribute('name', 'poster');
  252. $attr->setAttribute('value', $spot['poster'] . '@spot.net');
  253. $item->appendChild($attr);
  254. $attr = $doc->createElement('newznab:attr');
  255. $attr->setAttribute('name', 'comments');
  256. $attr->setAttribute('value', $spot['commentcount']);
  257. $item->appendChild($attr);
  258. } # if
  259. } # foreach
  260. $this->sendContentTypeHeader('xml');
  261. echo $doc->saveXML();
  262. }
  263. } # showResults
  264. function spotDetails($outputtype) {
  265. if (empty($this->_params['messageid'])) {
  266. $this->showApiError(200);
  267. return ;
  268. } # if
  269. # Controleer de users' rechten
  270. $this->_spotSec->fatalPermCheck(SpotSecurity::spotsec_view_spotdetail, '');
  271. # spot ophalen
  272. try {
  273. $fullSpot = $this->_tplHelper->getFullSpot($this->_params['messageid'], true);
  274. }
  275. catch(Exception $x) {
  276. $this->showApiError(300);
  277. return ;
  278. } # catch
  279. $nzbhandling = $this->_currentSession['user']['prefs']['nzbhandling'];
  280. # Normaal is fouten oplossen een beter idee, maar in dit geval is het een bug in de library (?)
  281. # Dit voorkomt Notice: Uninitialized string offset: 0 in lib/ubb/TagHandler.inc.php on line 142
  282. # wat een onbruikbaar resultaat oplevert
  283. $spot = @$this->_tplHelper->formatSpot($fullSpot);
  284. if ($outputtype == "json") {
  285. $doc = array();
  286. $doc['ID'] = $spot['id'];
  287. $doc['name'] = $spot['title'];
  288. $doc['size'] = $spot['filesize'];
  289. $doc['adddate'] = date('Y-m-d H:i:s', $spot['stamp']);
  290. $doc['guid'] = $spot['messageid'];
  291. $doc['fromname'] = $spot['poster'];
  292. $doc['completion'] = 100;
  293. $nabCat = explode("|", $this->Cat2NewznabCat($spot['category'], $spot['subcata']));
  294. if ($nabCat[0] != "" && is_numeric($nabCat[0])) {
  295. $doc['categoryID'] = $nabCat[0];
  296. $cat = implode(",", $nabCat);
  297. } # if
  298. $nabCat = explode("|", $this->Cat2NewznabCat($spot['category'], $spot['subcatb']));
  299. if ($nabCat[0] != "" && is_numeric($nabCat[0])) {
  300. $cat .= "," . $nabCat[0];
  301. } # if
  302. $doc['comments'] = $spot['commentcount'];
  303. $doc['category_name'] = SpotCategories::HeadCat2Desc($spot['category']) . ': ' . SpotCategories::Cat2ShortDesc($spot['category'], $spot['subcata']);
  304. $doc['category_ids'] = $cat;
  305. echo json_encode($doc);
  306. } else {
  307. $nzbUrl = $this->_tplHelper->makeBaseUrl("full") . 'api?t=g&amp;id=' . $spot['messageid'] . $this->_tplHelper->makeApiRequestString();
  308. # Opbouwen XML
  309. $doc = new DOMDocument('1.0', 'utf-8');
  310. $doc->formatOutput = true;
  311. $rss = $doc->createElement('rss');
  312. $rss->setAttribute('version', '2.0');
  313. $rss->setAttribute('xmlns:atom', 'http://www.w3.org/2005/Atom');
  314. $rss->setAttribute('xmlns:newznab', 'http://www.newznab.com/DTD/2010/feeds/attributes/');
  315. $rss->setAttribute('encoding', 'utf-8');
  316. $doc->appendChild($rss);
  317. $channel = $doc->createElement('channel');
  318. $channel->appendChild($doc->createElement('title', 'Spotweb'));
  319. $channel->appendChild($doc->createElement('language', 'nl'));
  320. $channel->appendChild($doc->createElement('description', 'Spotweb Index Api Detail'));
  321. $channel->appendChild($doc->createElement('link', $this->_settings->get('spotweburl')));
  322. $channel->appendChild($doc->createElement('webMaster', $this->_currentSession['user']['mail'] . ' (' . $this->_currentSession['user']['firstname'] . ' ' . $this->_currentSession['user']['lastname'] . ')'));
  323. $channel->appendChild($doc->createElement('category', ''));
  324. $rss->appendChild($channel);
  325. $image = $doc->createElement('image');
  326. $image->appendChild($doc->createElement('url', $this->_tplHelper->makeImageUrl($spot, 300, 300)));
  327. $image->appendChild($doc->createElement('title', 'Spotweb Index'));
  328. $image->appendChild($doc->createElement('link', $this->_settings->get('spotweburl')));
  329. $image->appendChild($doc->createElement('description', 'Visit Spotweb Index'));
  330. $channel->appendChild($image);
  331. $poster = (empty($spot['spotterid'])) ? $spot['poster'] : $spot['poster'] . " (" . $spot['spotterid'] . ")";
  332. $guid = $doc->createElement('guid', $spot['messageid']);
  333. $guid->setAttribute('isPermaLink', 'false');
  334. $description = $doc->createElement('description');
  335. $descriptionCdata = $doc->createCDATASection($spot['description'] . '<br /><font color="#ca0000">Door: ' . $poster . '</font>');
  336. $description->appendChild($descriptionCdata);
  337. $item = $doc->createElement('item');
  338. $item->appendChild($doc->createElement('title', htmlspecialchars($spot['title'], ENT_QUOTES, "UTF-8")));
  339. $item->appendChild($guid);
  340. $item->appendChild($doc->createElement('link', $nzbUrl));
  341. $item->appendChild($doc->createElement('pubDate', date('r', $spot['stamp'])));
  342. $item->appendChild($doc->createElement('category', SpotCategories::HeadCat2Desc($spot['category']) . " > " . SpotCategories::Cat2ShortDesc($spot['category'], $spot['subcata'])));
  343. $item->appendChild($description);
  344. $channel->appendChild($item);
  345. $enclosure = $doc->createElement('enclosure');
  346. $enclosure->setAttribute('url', html_entity_decode($nzbUrl));
  347. $enclosure->setAttribute('length', $spot['filesize']);
  348. switch ($nzbhandling['prepare_action']) {
  349. case 'zip' : $enclosure->setAttribute('type', 'application/zip'); break;
  350. default : $enclosure->setAttribute('type', 'application/x-nzb');
  351. } # switch
  352. $item->appendChild($enclosure);
  353. $nabCat = explode("|", $this->Cat2NewznabCat($spot['category'], $spot['subcata']));
  354. if ($nabCat[0] != "" && is_numeric($nabCat[0])) {
  355. $attr = $doc->createElement('newznab:attr');
  356. $attr->setAttribute('name', 'category');
  357. $attr->setAttribute('value', $nabCat[0]);
  358. $item->appendChild($attr);
  359. $attr = $doc->createElement('newznab:attr');
  360. $attr->setAttribute('name', 'category');
  361. $attr->setAttribute('value', $nabCat[1]);
  362. $item->appendChild($attr);
  363. } # if
  364. $nabCat = explode("|", $this->Cat2NewznabCat($spot['category'], $spot['subcatb']));
  365. if ($nabCat[0] != "" && is_numeric($nabCat[0])) {
  366. $attr = $doc->createElement('newznab:attr');
  367. $attr->setAttribute('name', 'category');
  368. $attr->setAttribute('value', $nabCat[0]);
  369. $item->appendChild($attr);
  370. } # if
  371. $attr = $doc->createElement('newznab:attr');
  372. $attr->setAttribute('name', 'size');
  373. $attr->setAttribute('value', $spot['filesize']);
  374. $item->appendChild($attr);
  375. $attr = $doc->createElement('newznab:attr');
  376. $attr->setAttribute('name', 'poster');
  377. $attr->setAttribute('value', $spot['poster'] . '@spot.net (' . $spot['poster'] . ')');
  378. $item->appendChild($attr);
  379. $attr = $doc->createElement('newznab:attr');
  380. $attr->setAttribute('name', 'comments');
  381. $attr->setAttribute('value', $spot['commentcount']);
  382. $item->appendChild($attr);
  383. $this->sendContentTypeHeader('xml');
  384. echo $doc->saveXML();
  385. } # if
  386. } # spotDetails
  387. function getNzb() {
  388. if ($this->_params['del'] == "1" && $this->_spotSec->allowed(SpotSecurity::spotsec_keep_own_watchlist, '')) {
  389. $spot = $this->_db->getFullSpot($this->_params['messageid'], $this->_currentSession['user']['userid']);
  390. if ($spot['watchstamp'] !== NULL) {
  391. $this->_db->removeFromWatchList($this->_params['messageid'], $this->_currentSession['user']['userid']);
  392. $spotsNotifications = new SpotNotifications($this->_db, $this->_settings, $this->_currentSession);
  393. $spotsNotifications->sendWatchlistHandled('remove', $this->_params['messageid']);
  394. } # if
  395. } # if
  396. header('Location: ' . $this->_tplHelper->makeBaseUrl("full") . '?page=getnzb&action=display&messageid=' . $this->_params['messageid'] . html_entity_decode($this->_tplHelper->makeApiRequestString()));
  397. } # getNzb
  398. function caps() {
  399. $doc = new DOMDocument('1.0', 'utf-8');
  400. $doc->formatOutput = true;
  401. $caps = $doc->createElement('caps');
  402. $doc->appendChild($caps);
  403. $server = $doc->createElement('server');
  404. $server->setAttribute('version', '0.1');
  405. $server->setAttribute('title', 'Spotweb');
  406. $server->setAttribute('strapline', 'Spotweb API Index');
  407. $server->setAttribute('email', $this->_currentSession['user']['mail'] . ' (' . $this->_currentSession['user']['firstname'] . ' ' . $this->_currentSession['user']['lastname'] . ')');
  408. $server->setAttribute('url', $this->_settings->get('spotweburl'));
  409. $server->setAttribute('image', $this->_settings->get('spotweburl') . 'images/spotnet.gif');
  410. $caps->appendChild($server);
  411. $limits = $doc->createElement('limits');
  412. $limits->setAttribute('max', '500');
  413. $limits->setAttribute('default', $this->_currentSession['user']['prefs']['perpage']);
  414. $caps->appendChild($limits);
  415. if (($this->_settings->get('retention') > 0) && ($this->_settings->get('retentiontype') == 'everything')) {
  416. $ret = $doc->createElement('retention');
  417. $ret->setAttribute('days', $this->_settings->get('retention'));
  418. $caps->appendChild($ret);
  419. } # if
  420. $reg = $doc->createElement('registration');
  421. $reg->setAttribute('available', 'no');
  422. $reg->setAttribute('open', 'no');
  423. $caps->appendChild($reg);
  424. $searching = $doc->createElement('searching');
  425. $caps->appendChild($searching);
  426. $search = $doc->createElement('search');
  427. $search->setAttribute('available', 'yes');
  428. $searching->appendChild($search);
  429. $tvsearch = $doc->createElement('tv-search');
  430. $tvsearch->setAttribute('available', 'yes');
  431. $searching->appendChild($tvsearch);
  432. $moviesearch = $doc->createElement('movie-search');
  433. $moviesearch->setAttribute('available', 'yes');
  434. $searching->appendChild($moviesearch);
  435. $audiosearch = $doc->createElement('audio-search');
  436. $audiosearch->setAttribute('available', 'yes');
  437. $searching->appendChild($audiosearch);
  438. $categories = $doc->createElement('categories');
  439. $caps->appendChild($categories);
  440. foreach($this->categories() as $category) {
  441. $cat = $doc->createElement('category');
  442. $cat->setAttribute('id', $category['cat']);
  443. $cat->setAttribute('name', $category['name']);
  444. $categories->appendChild($cat);
  445. foreach($category['subcata'] as $name => $subcata) {
  446. $subCat = $doc->createElement('subcat');
  447. $subCat->setAttribute('id', $subcata);
  448. $subCat->setAttribute('name', $name);
  449. $cat->appendChild($subCat);
  450. } # foreach
  451. } # foreach
  452. $this->sendContentTypeHeader('xml');
  453. echo $doc->saveXML();
  454. } # caps
  455. function Cat2NewznabCat($hcat, $cat) {
  456. $result = "-";
  457. $catList = explode("|", $cat);
  458. $cat = $catList[0];
  459. $nr = substr($cat, 1);
  460. # Als $nr niet gevonden kan worden is dat niet erg, het mag echter
  461. # geen Notice veroorzaken.
  462. if (!empty($cat[0])) {
  463. switch ($cat[0]) {
  464. case "a" : $newznabcat = $this->spotAcat2nabcat(); return @$newznabcat[$hcat][$nr]; break;
  465. case "b" : $newznabcat = $this->spotBcat2nabcat(); return @$newznabcat[$nr]; break;
  466. } # switch
  467. } # if
  468. } # Cat2NewznabCat
  469. function showApiError($errcode=42) {
  470. switch ($errcode) {
  471. case 100: $errtext = "Incorrect user credentials"; break;
  472. case 101: $errtext = "Account suspended"; break;
  473. case 102: $errtext = "Insufficient priviledges/not authorized"; break;
  474. case 103: $errtext = "Registration denied"; break;
  475. case 104: $errtext = "Registrations are closed"; break;
  476. case 105: $errtext = "Invalid registration (Email Address Taken)"; break;
  477. case 106: $errtext = "Invalid registration (Email Address Bad Format)"; break;
  478. case 107: $errtext = "Registration Failed (Data error)"; break;
  479. case 200: $errtext = "Missing parameter"; break;
  480. case 201: $errtext = "Incorrect parameter"; break;
  481. case 202: $errtext = "No such function"; break;
  482. case 203: $errtext = "Function not available"; break;
  483. case 300: $errtext = "No such item"; break;
  484. case 500: $errtext = "Request limit reached"; break;
  485. case 501: $errtext = "Download limit reached"; break;
  486. default: $errtext = "Unknown error"; break;
  487. } # switch
  488. $doc = new DOMDocument('1.0', 'utf-8');
  489. $doc->formatOutput = true;
  490. $error = $doc->createElement('error');
  491. $error->setAttribute('code', $errcode);
  492. $error->setAttribute('description', $errtext);
  493. $doc->appendChild($error);
  494. $this->sendContentTypeHeader('xml');
  495. echo $doc->saveXML();
  496. } # showApiError
  497. function categories() {
  498. return array(
  499. array('name' => 'Console',
  500. 'cat' => '1000',
  501. 'subcata' => array('NDS' => '1010',
  502. 'PSP' => '1020',
  503. 'Wii' => '1030',
  504. 'Xbox' => '1040',
  505. 'Xbox 360' => '1050',
  506. 'PS3' => '1080')
  507. ), array('name' => 'Movies',
  508. 'cat' => '2000',
  509. 'subcata' => array('SD' => '2030',
  510. 'HD' => '2040',
  511. 'Sport' => '2060')
  512. ), array('name' => 'Audio',
  513. 'cat' => '3000',
  514. 'subcata' => array('MP3' => '3010',
  515. 'Video' => '3020',
  516. 'Lossless' => '3040')
  517. ), array('name' => 'PC',
  518. 'cat' => '4000',
  519. 'subcata' => array('Mac' => '4030',
  520. 'Phone' => '4040',
  521. 'Games' => '4050')
  522. ), array('name' => 'TV',
  523. 'cat' => '5000',
  524. 'subcata' => array('SD' => '5030',
  525. 'HD' => '5040',
  526. 'Sport' => '5060')
  527. ), array('name' => 'XXX',
  528. 'cat' => '6000',
  529. 'subcata' => array('DVD' => '6010',
  530. 'WMV' => '6020',
  531. 'XviD' => '6030',
  532. 'x264' => '6040')
  533. ), array('name' => 'Other',
  534. 'cat' => '7000',
  535. 'subcata' => array('Ebook' => '7020')
  536. )
  537. );
  538. } # categories
  539. function nabcat2spotcat($cat) {
  540. switch ($cat) {
  541. case 1000: return 'cat2_a3,cat2_a4,cat2_a5,cat2_a6,cat2_a7,cat2_a8,cat2_a9,cat2_a10,cat2_a11,cat2_a12';
  542. case 1010: return 'cat2_a10';
  543. case 1020: return 'cat2_a5';
  544. case 1030: return 'cat2_a11';
  545. case 1040: return 'cat2_a6';
  546. case 1050: return 'cat2_a7';
  547. case 1060: return 'cat2_a7';
  548. case 2000: return 'cat0_z0';
  549. case 2010:
  550. case 2030: return 'cat0_a0,cat0_a1,cat0_a2,cat0_a3,cat0_a10,~cat0_z1,~cat0_z2,~cat0_z3';
  551. case 2040: return 'cat0_a4,cat0_a6,cat0_a7,cat0_a8,cat0_a9,~cat0_z1,~cat0_z2,~cat0_z3';
  552. case 2060: return 'cat0_d18';
  553. case 3000: return 'cat1_a';
  554. case 3010: return 'cat1_a0';
  555. case 3020: return 'cat0_d13';
  556. case 3040: return 'cat1_a2,cat1_a4,cat1_a7,cat1_a8';
  557. case 4000: return 'cat3_a0';
  558. case 4030: return 'cat3_a1';
  559. case 4040: return 'cat3_a4,cat3_a5,cat3_a6,cat3_a7';
  560. case 4050: return 'cat2_a0,cat2_a1,cat2_a2';
  561. case 5000: return 'cat0_z1';
  562. case 5030: return 'cat0_z1,cat0_a0,cat0_a1,cat0_a2,cat0_a3,cat0_a10';
  563. case 5040: return 'cat0_z1,cat0_a4,cat0_a6,cat0_a7,cat0_a8,cat0_a9';
  564. case 5060: return 'cat0_z1,cat0_d18';
  565. case 6000: return 'cat0_z3';
  566. case 6010: return 'cat0_a3,cat0_a10,~cat0_z0,~cat0_z1,~cat0_z2';
  567. case 6020: return 'cat0_a1,cat0_a8,~cat0_z1,~cat0_z0,~cat0_z1,~cat0_z2';
  568. case 6030: return 'cat0_a0,~cat0_z0,~cat0_z1,~cat0_z2';
  569. case 6040: return 'cat0_a4,cat0_a6,cat0_a7,cat0_a8,cat0_a9,~cat0_z0,~cat0_z1,~cat0_z2';
  570. case 7020: return 'cat0_z2';
  571. }
  572. } # nabcat2spotcat
  573. function spotAcat2nabcat() {
  574. return Array(0 =>
  575. Array(0 => "2000|2030",
  576. 1 => "2000|2030",
  577. 2 => "2000|2030",
  578. 3 => "2000|2030",
  579. 4 => "2000|2040",
  580. 5 => "7000|7020",
  581. 6 => "2000|2040",
  582. 7 => "2000|2040",
  583. 8 => "2000|2040",
  584. 9 => "2000|2040",
  585. 10 => "2000|2030"),
  586. 1 =>
  587. Array(0 => "3000|3010",
  588. 1 => "3000|3010",
  589. 2 => "3000|3040",
  590. 3 => "3000|3010",
  591. 4 => "3000|3040",
  592. 5 => "3000|3040",
  593. 6 => "3000|3010",
  594. 7 => "3000|3040",
  595. 8 => "3000|3040"),
  596. 2 =>
  597. Array(0 => "4000|4050",
  598. 1 => "4000|4030",
  599. 2 => "TUX",
  600. 3 => "PS",
  601. 4 => "PS2",
  602. 5 => "1000|1020",
  603. 6 => "1000|1040",
  604. 7 => "1000|1050",
  605. 8 => "GBA",
  606. 9 => "GC",
  607. 10 => "1000|1010",
  608. 11 => "1000|1030",
  609. 12 => "1000|1080",
  610. 13 => "4000|4040",
  611. 14 => "4000|4040",
  612. 15 => "4000|4040",
  613. 16 => "3DS"),
  614. 3 =>
  615. Array(0 => "4000|4020",
  616. 1 => "4000|4030",
  617. 2 => "TUX",
  618. 3 => "OS/2",
  619. 4 => "4000|4040",
  620. 5 => "NAV",
  621. 6 => "4000|4040",
  622. 7 => "4000|4040")
  623. );
  624. } # spotAcat2nabcat
  625. function spotBcat2nabcat() {
  626. return Array(0 => "",
  627. 1 => "",
  628. 2 => "",
  629. 3 => "",
  630. 4 => "5000",
  631. 5 => "",
  632. 6 => "5000",
  633. 7 => "",
  634. 8 => "",
  635. 9 => "",
  636. 10 => "");
  637. } # spotBcat2nabcat
  638. } # class SpotPage_api