PageRenderTime 55ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/www/lib/console.php

https://github.com/vikjon0/newznab
PHP | 677 lines | 562 code | 84 blank | 31 comment | 95 complexity | a218add52f412fe6c9d9823b8242d7cf MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. require_once(WWW_DIR."/lib/framework/db.php");
  3. require_once(WWW_DIR."/lib/amazon.php");
  4. require_once(WWW_DIR."/lib/category.php");
  5. require_once(WWW_DIR."/lib/genres.php");
  6. require_once(WWW_DIR."/lib/site.php");
  7. require_once(WWW_DIR."/lib/util.php");
  8. require_once(WWW_DIR."/lib/releaseimage.php");
  9. class Console
  10. {
  11. const NUMTOPROCESSPERTIME = 125;
  12. function Console($echooutput=false)
  13. {
  14. $this->echooutput = $echooutput;
  15. $s = new Sites();
  16. $site = $s->get();
  17. $this->pubkey = $site->amazonpubkey;
  18. $this->privkey = $site->amazonprivkey;
  19. $this->imgSavePath = WWW_DIR.'covers/console/';
  20. }
  21. public function getConsoleInfo($id)
  22. {
  23. $db = new DB();
  24. return $db->queryOneRow(sprintf("SELECT consoleinfo.*, genres.title as genres FROM consoleinfo left outer join genres on genres.ID = consoleinfo.genreID where consoleinfo.ID = %d ", $id));
  25. }
  26. public function getConsoleInfoByName($title, $platform)
  27. {
  28. $db = new DB();
  29. return $db->queryOneRow(sprintf("SELECT * FROM consoleinfo where title like %s and platform like %s", $db->escapeString("%".$title."%"), $db->escapeString("%".$platform."%")));
  30. }
  31. public function getRange($start, $num)
  32. {
  33. $db = new DB();
  34. if ($start === false)
  35. $limit = "";
  36. else
  37. $limit = " LIMIT ".$start.",".$num;
  38. return $db->query(" SELECT * FROM consoleinfo ORDER BY createddate DESC".$limit);
  39. }
  40. public function getCount()
  41. {
  42. $db = new DB();
  43. $res = $db->queryOneRow("select count(ID) as num from consoleinfo");
  44. return $res["num"];
  45. }
  46. public function getConsoleCount($cat, $maxage=-1, $excludedcats=array())
  47. {
  48. $db = new DB();
  49. $browseby = $this->getBrowseBy();
  50. $catsrch = "";
  51. if (count($cat) > 0 && $cat[0] != -1)
  52. {
  53. $catsrch = " (";
  54. foreach ($cat as $category)
  55. {
  56. if ($category != -1)
  57. {
  58. $categ = new Category();
  59. if ($categ->isParent($category))
  60. {
  61. $children = $categ->getChildren($category);
  62. $chlist = "-99";
  63. foreach ($children as $child)
  64. $chlist.=", ".$child["ID"];
  65. if ($chlist != "-99")
  66. $catsrch .= " r.categoryID in (".$chlist.") or ";
  67. }
  68. else
  69. {
  70. $catsrch .= sprintf(" r.categoryID = %d or ", $category);
  71. }
  72. }
  73. }
  74. $catsrch.= "1=2 )";
  75. }
  76. if ($maxage > 0)
  77. $maxage = sprintf(" and r.postdate > now() - interval %d day ", $maxage);
  78. else
  79. $maxage = "";
  80. $exccatlist = "";
  81. if (count($excludedcats) > 0)
  82. $exccatlist = " and r.categoryID not in (".implode(",", $excludedcats).")";
  83. $sql = sprintf("select count(r.ID) as num from releases r inner join consoleinfo c on c.ID = r.consoleinfoID and c.title != '' where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and %s %s %s %s", $browseby, $catsrch, $maxage, $exccatlist);
  84. $res = $db->queryOneRow($sql);
  85. return $res["num"];
  86. }
  87. public function getConsoleRange($cat, $start, $num, $orderby, $maxage=-1, $excludedcats=array())
  88. {
  89. $db = new DB();
  90. $browseby = $this->getBrowseBy();
  91. if ($start === false)
  92. $limit = "";
  93. else
  94. $limit = " LIMIT ".$start.",".$num;
  95. $catsrch = "";
  96. if (count($cat) > 0 && $cat[0] != -1)
  97. {
  98. $catsrch = " (";
  99. foreach ($cat as $category)
  100. {
  101. if ($category != -1)
  102. {
  103. $categ = new Category();
  104. if ($categ->isParent($category))
  105. {
  106. $children = $categ->getChildren($category);
  107. $chlist = "-99";
  108. foreach ($children as $child)
  109. $chlist.=", ".$child["ID"];
  110. if ($chlist != "-99")
  111. $catsrch .= " r.categoryID in (".$chlist.") or ";
  112. }
  113. else
  114. {
  115. $catsrch .= sprintf(" r.categoryID = %d or ", $category);
  116. }
  117. }
  118. }
  119. $catsrch.= "1=2 )";
  120. }
  121. $maxage = "";
  122. if ($maxage > 0)
  123. $maxage = sprintf(" and r.postdate > now() - interval %d day ", $maxage);
  124. $exccatlist = "";
  125. if (count($excludedcats) > 0)
  126. $exccatlist = " and r.categoryID not in (".implode(",", $excludedcats).")";
  127. $order = $this->getConsoleOrder($orderby);
  128. $sql = sprintf(" SELECT r.*, r.ID as releaseID, con.*, g.title as genre, groups.name as group_name, concat(cp.title, ' > ', c.title) as category_name, concat(cp.ID, ',', c.ID) as category_ids, rn.ID as nfoID from releases r left outer join groups on groups.ID = r.groupID inner join consoleinfo con on con.ID = r.consoleinfoID left outer join releasenfo rn on rn.releaseID = r.ID and rn.nfo is not null left outer join category c on c.ID = r.categoryID left outer join category cp on cp.ID = c.parentID left outer join genres g on g.ID = con.genreID where r.passwordstatus <= (select value from site where setting='showpasswordedrelease') and %s %s %s %s order by %s %s".$limit, $browseby, $catsrch, $maxage, $exccatlist, $order[0], $order[1]);
  129. return $db->query($sql);
  130. }
  131. public function getConsoleOrder($orderby)
  132. {
  133. $order = ($orderby == '') ? 'r.postdate' : $orderby;
  134. $orderArr = explode("_", $order);
  135. switch($orderArr[0]) {
  136. case 'title':
  137. $orderfield = 'con.title';
  138. break;
  139. case 'platform':
  140. $orderfield = 'con.platform';
  141. break;
  142. case 'releasedate':
  143. $orderfield = 'con.releasedate';
  144. break;
  145. case 'genre':
  146. $orderfield = 'con.genreID';
  147. break;
  148. case 'size':
  149. $orderfield = 'r.size';
  150. break;
  151. case 'files':
  152. $orderfield = 'r.totalpart';
  153. break;
  154. case 'stats':
  155. $orderfield = 'r.grabs';
  156. break;
  157. case 'posted':
  158. default:
  159. $orderfield = 'r.postdate';
  160. break;
  161. }
  162. $ordersort = (isset($orderArr[1]) && preg_match('/^asc|desc$/i', $orderArr[1])) ? $orderArr[1] : 'desc';
  163. return array($orderfield, $ordersort);
  164. }
  165. public function getConsoleOrdering()
  166. {
  167. return array('title_asc', 'title_desc', 'posted_asc', 'posted_desc', 'size_asc', 'size_desc', 'files_asc', 'files_desc', 'stats_asc', 'stats_desc', 'platform_asc', 'platform_desc', 'releasedate_asc', 'releasedate_desc', 'genre_asc', 'genre_desc');
  168. }
  169. public function getBrowseByOptions()
  170. {
  171. return array('platform'=>'platform', 'title'=>'title', 'genre'=>'genreID');
  172. }
  173. public function getBrowseBy()
  174. {
  175. $db = new Db;
  176. $browseby = ' ';
  177. $browsebyArr = $this->getBrowseByOptions();
  178. foreach ($browsebyArr as $bbk=>$bbv) {
  179. if (isset($_REQUEST[$bbk]) && !empty($_REQUEST[$bbk])) {
  180. $bbs = stripslashes($_REQUEST[$bbk]);
  181. $browseby .= "con.$bbv LIKE(".$db->escapeString('%'.$bbs.'%').") AND ";
  182. }
  183. }
  184. return $browseby;
  185. }
  186. public function makeFieldLinks($data, $field)
  187. {
  188. $tmpArr = explode(', ',$data[$field]);
  189. $newArr = array();
  190. $i = 0;
  191. foreach($tmpArr as $ta) {
  192. if ($i > 5) { break; } //only use first 6
  193. $newArr[] = '<a href="'.WWW_TOP.'/console?'.$field.'='.urlencode($ta).'" title="'.$ta.'">'.$ta.'</a>';
  194. $i++;
  195. }
  196. return implode(', ', $newArr);
  197. }
  198. public function update($id, $title, $asin, $url, $salesrank, $platform, $publisher, $releasedate, $esrb, $cover, $genreID)
  199. {
  200. $db = new DB();
  201. $db->query(sprintf("UPDATE consoleinfo SET title=%s, asin=%s, url=%s, salesrank=%s, platform=%s, publisher=%s, releasedate='%s', esrb=%s, cover=%d, genreID=%d, updateddate=NOW() WHERE ID = %d",
  202. $db->escapeString($title), $db->escapeString($asin), $db->escapeString($url), $salesrank, $db->escapeString($platform), $db->escapeString($publisher), $releasedate, $db->escapeString($esrb), $cover, $genreID, $id));
  203. }
  204. public function updateConsoleInfo($gameInfo)
  205. {
  206. $db = new DB();
  207. $gen = new Genres();
  208. $ri = new ReleaseImage();
  209. $con = array();
  210. $amaz = $this->fetchAmazonProperties($gameInfo['title'], $gameInfo['node']);
  211. if (!$amaz)
  212. return false;
  213. //load genres
  214. $defaultGenres = $gen->getGenres(Genres::CONSOLE_TYPE);
  215. $genreassoc = array();
  216. foreach($defaultGenres as $dg) {
  217. $genreassoc[$dg['ID']] = strtolower($dg['title']);
  218. }
  219. //
  220. // get game properties
  221. //
  222. $con['coverurl'] = (string) $amaz->Items->Item->LargeImage->URL;
  223. if ($con['coverurl'] != "")
  224. $con['cover'] = 1;
  225. else
  226. $con['cover'] = 0;
  227. $con['title'] = (string) $amaz->Items->Item->ItemAttributes->Title;
  228. if (empty($con['title']))
  229. $con['title'] = $gameInfo['title'];
  230. $con['platform'] = (string) $amaz->Items->Item->ItemAttributes->Platform;
  231. if (empty($con['platform']))
  232. $con['platform'] = $gameInfo['platform'];
  233. //Beginning of Recheck Code
  234. //This is to verify the result back from amazon was at least somewhat related to what was intended.
  235. //Some of the Platforms don't match Amazon's exactly. This code is needed to facilitate rechecking.
  236. if (preg_match('/^X360$/i', $gameInfo['platform']))
  237. {
  238. $gameInfo['platform'] = str_replace('X360', 'Xbox 360', $gameInfo['platform']); // baseline single quote
  239. }
  240. if (preg_match('/^XBOX360$/i', $gameInfo['platform']))
  241. {
  242. $gameInfo['platform'] = str_replace('XBOX360', 'Xbox 360', $gameInfo['platform']); // baseline single quote
  243. }
  244. if (preg_match('/^NDS$/i', $gameInfo['platform']))
  245. {
  246. $gameInfo['platform'] = str_replace('NDS', 'Nintendo DS', $gameInfo['platform']); // baseline single quote
  247. }
  248. if (preg_match('/^PS3$/i', $gameInfo['platform']))
  249. {
  250. $gameInfo['platform'] = str_replace('PS3', 'PlayStation 3', $gameInfo['platform']); // baseline single quote
  251. }
  252. if (preg_match('/^PSP$/i', $gameInfo['platform']))
  253. {
  254. $gameInfo['platform'] = str_replace('PSP', 'Sony PSP', $gameInfo['platform']); // baseline single quote
  255. }
  256. if (preg_match('/^Wii$/i', $gameInfo['platform']))
  257. {
  258. $gameInfo['platform'] = str_replace('Wii', 'Nintendo Wii', $gameInfo['platform']); // baseline single quote
  259. $gameInfo['platform'] = str_replace('WII', 'Nintendo Wii', $gameInfo['platform']); // baseline single quote
  260. }
  261. if (preg_match('/^N64$/i', $gameInfo['platform']))
  262. {
  263. $gameInfo['platform'] = str_replace('N64', 'Nintendo 64', $gameInfo['platform']); // baseline single quote
  264. }
  265. if (preg_match('/^NES$/i', $gameInfo['platform']))
  266. {
  267. $gameInfo['platform'] = str_replace('NES', 'Nintendo NES', $gameInfo['platform']); // baseline single quote
  268. }
  269. if (preg_match('/Super/i', $con['platform']))
  270. {
  271. $con['platform'] = str_replace('Super Nintendo', 'SNES', $con['platform']); // baseline single quote
  272. $con['platform'] = str_replace('Nintendo Super NES', 'SNES', $con['platform']); // baseline single quote
  273. }
  274. //Remove Online Game Code So Titles Match Properly.
  275. if (preg_match('/\[Online Game Code\]/i', $con['title']))
  276. {
  277. $con['title'] = str_replace(' [Online Game Code]', '', $con['title']); // baseline single quote
  278. }
  279. //Basically the XBLA names contain crap, this is to reduce the title down far enough to be usable
  280. if (preg_match('/xbla/i', $gameInfo['platform']))
  281. {
  282. $gameInfo['title'] = substr($gameInfo['title'],0,10);
  283. $con['substr'] = $gameInfo['title'];
  284. }
  285. //This actual compares the two strings and outputs a percentage value.
  286. $titlepercent ='';
  287. $platformpercent ='';
  288. similar_text(strtolower($gameInfo['title']), strtolower($con['title']), $titlepercent);
  289. similar_text(strtolower($gameInfo['platform']), strtolower($con['platform']), $platformpercent);
  290. //Since Wii Ware games and XBLA have inconsistent original platforms, as long as title is 50% its ok.
  291. if (preg_match('/(wiiware|xbla)/i', $gameInfo['platform']))
  292. {
  293. if ($titlepercent >= 50)
  294. {
  295. $platformpercent = 100;
  296. }
  297. }
  298. //If the release is DLC matching sucks, so assume anything over 50% is legit.
  299. if (isset($gameInfo['dlc']) && $gameInfo['dlc'] == 1)
  300. {
  301. if ($titlepercent >= 50)
  302. {
  303. $titlepercent = 100;
  304. $platformpercent = 100;
  305. }
  306. }
  307. //Show the Percentages
  308. //echo("Matched: Title Percentage: $titlepercent%");
  309. //echo("Matched: Platform Percentage: $platformpercent%");
  310. //If the Title is less than 80% Platform must be 100% unless it is XBLA
  311. if ($titlepercent < 70)
  312. {
  313. if ($platformpercent != 100)
  314. {
  315. return false;
  316. }
  317. }
  318. //If title is less than 80% then its most likely not a match
  319. if ($titlepercent < 70)
  320. return false;
  321. //Platform must equal 100%
  322. if ($platformpercent != 100)
  323. return false;
  324. $con['asin'] = (string) $amaz->Items->Item->ASIN;
  325. $con['url'] = (string) $amaz->Items->Item->DetailPageURL;
  326. $con['url'] = str_replace("%26tag%3Dws", "%26tag%3Dopensourceins%2D21", $con['url']);
  327. $con['salesrank'] = (string) $amaz->Items->Item->SalesRank;
  328. if ($con['salesrank'] == "")
  329. $con['salesrank'] = 'null';
  330. $con['publisher'] = (string) $amaz->Items->Item->ItemAttributes->Publisher;
  331. $con['esrb'] = (string) $amaz->Items->Item->ItemAttributes->ESRBAgeRating;
  332. $con['releasedate'] = $db->escapeString((string) $amaz->Items->Item->ItemAttributes->ReleaseDate);
  333. if ($con['releasedate'] == "''")
  334. $con['releasedate'] = 'null';
  335. $con['review'] = "";
  336. if (isset($amaz->Items->Item->EditorialReviews))
  337. $con['review'] = trim(strip_tags((string) $amaz->Items->Item->EditorialReviews->EditorialReview->Content));
  338. $genreKey = -1;
  339. $genreName = '';
  340. if (isset($amaz->Items->Item->BrowseNodes) || isset($amaz->Items->Item->ItemAttributes->Genre))
  341. {
  342. if (isset($amaz->Items->Item->BrowseNodes))
  343. {
  344. //had issues getting this out of the browsenodes obj
  345. //workaround is to get the xml and load that into its own obj
  346. $amazGenresXml = $amaz->Items->Item->BrowseNodes->asXml();
  347. $amazGenresObj = simplexml_load_string($amazGenresXml);
  348. $amazGenres = $amazGenresObj->xpath("//Name");
  349. foreach($amazGenres as $amazGenre)
  350. {
  351. $currName = trim($amazGenre[0]);
  352. if (empty($genreName))
  353. {
  354. $genreMatch = $this->matchBrowseNode($currName);
  355. if ($genreMatch !== false)
  356. {
  357. $genreName = $genreMatch;
  358. break;
  359. }
  360. }
  361. }
  362. }
  363. if (empty($genreName) && isset($amaz->Items->Item->ItemAttributes->Genre))
  364. {
  365. $tmpGenre = (string) $amaz->Items->Item->ItemAttributes->Genre;
  366. $tmpGenre = str_replace('-', ' ', $tmpGenre);
  367. $tmpGenre = explode(' ', $tmpGenre);
  368. foreach($tmpGenre as $tg)
  369. {
  370. $genreMatch = $this->matchBrowseNode(ucwords($tg));
  371. if ($genreMatch !== false)
  372. {
  373. $genreName = $genreMatch;
  374. break;
  375. }
  376. }
  377. }
  378. }
  379. if (empty($genreName))
  380. {
  381. $genreName = 'Unknown';
  382. }
  383. if (in_array(strtolower($genreName), $genreassoc)) {
  384. $genreKey = array_search(strtolower($genreName), $genreassoc);
  385. } else {
  386. $genreKey = $db->queryInsert(sprintf("INSERT INTO genres (`title`, `type`) VALUES (%s, %d)", $db->escapeString($genreName), Genres::CONSOLE_TYPE));
  387. }
  388. $con['consolegenre'] = $genreName;
  389. $con['consolegenreID'] = $genreKey;
  390. $query = sprintf("
  391. INSERT INTO consoleinfo (`title`, `asin`, `url`, `salesrank`, `platform`, `publisher`, `genreID`, `esrb`, `releasedate`, `review`, `cover`, `createddate`, `updateddate`)
  392. VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %d, now(), now())
  393. ON DUPLICATE KEY UPDATE `title` = %s, `asin` = %s, `url` = %s, `salesrank` = %s, `platform` = %s, `publisher` = %s, `genreID` = %s, `esrb` = %s, `releasedate` = %s, `review` = %s, `cover` = %d, createddate = now(), updateddate = now()",
  394. $db->escapeString($con['title']), $db->escapeString($con['asin']), $db->escapeString($con['url']),
  395. $con['salesrank'], $db->escapeString($con['platform']), $db->escapeString($con['publisher']), ($con['consolegenreID']==-1?"null":$con['consolegenreID']), $db->escapeString($con['esrb']),
  396. $con['releasedate'], $db->escapeString($con['review']), $con['cover'],
  397. $db->escapeString($con['title']), $db->escapeString($con['asin']), $db->escapeString($con['url']),
  398. $con['salesrank'], $db->escapeString($con['platform']), $db->escapeString($con['publisher']), ($con['consolegenreID']==-1?"null":$con['consolegenreID']), $db->escapeString($con['esrb']),
  399. $con['releasedate'], $db->escapeString($con['review']), $con['cover'] );
  400. $consoleId = $db->queryInsert($query);
  401. if ($consoleId)
  402. {
  403. if ($this->echooutput)
  404. echo "added/updated game: ".$con['title']." ".$con['platform']."\n";
  405. $con['cover'] = $ri->saveImage($consoleId, $con['coverurl'], $this->imgSavePath, 250, 250);
  406. }
  407. else
  408. {
  409. if ($this->echooutput)
  410. echo "nothing to update: ".$con['title']." (".$con['platform'].")\n";
  411. }
  412. return $consoleId;
  413. }
  414. public function fetchAmazonProperties($title, $node)
  415. {
  416. $obj = new AmazonProductAPI($this->pubkey, $this->privkey);
  417. try
  418. {
  419. $result = $obj->searchProducts($title, AmazonProductAPI::GAMES, "NODE", $node);
  420. }
  421. catch(Exception $e)
  422. {
  423. $result = false;
  424. }
  425. return $result;
  426. }
  427. public function processConsoleReleases()
  428. {
  429. $ret = 0;
  430. $db = new DB();
  431. $res = $db->queryDirect(sprintf("SELECT searchname, ID from releases where consoleinfoID IS NULL and categoryID in ( select ID from category where parentID = %d ) ORDER BY id DESC LIMIT %d", Category::CAT_PARENT_GAME, Console::NUMTOPROCESSPERTIME));
  432. if (mysql_num_rows($res) > 0)
  433. {
  434. if ($this->echooutput)
  435. echo "\nProcessing ".mysql_num_rows($res)." console releases\n";
  436. while ($arr = mysql_fetch_assoc($res))
  437. {
  438. $gameInfo = $this->parseTitle($arr['searchname']);
  439. if ($gameInfo !== false)
  440. {
  441. if ($this->echooutput)
  442. echo 'Looking up: '.$gameInfo["title"].' ('.$gameInfo["platform"].') ['.$arr['searchname'].']'."\n";
  443. //check for existing console entry
  444. $gameCheck = $this->getConsoleInfoByName($gameInfo["title"], $gameInfo["platform"]);
  445. if ($gameCheck === false)
  446. {
  447. $gameId = $this->updateConsoleInfo($gameInfo);
  448. if ($gameId === false)
  449. {
  450. $gameId = -2;
  451. }
  452. }
  453. else
  454. {
  455. $gameId = $gameCheck["ID"];
  456. }
  457. //update release
  458. $db->query(sprintf("UPDATE releases SET consoleinfoID = %d WHERE ID = %d", $gameId, $arr["ID"]));
  459. }
  460. else {
  461. //could not parse release title
  462. $db->query(sprintf("UPDATE releases SET consoleinfoID = %d WHERE ID = %d", -2, $arr["ID"]));
  463. }
  464. }
  465. }
  466. }
  467. function parseTitle($releasename)
  468. {
  469. $result = array();
  470. //get name of the game from name of release
  471. preg_match('/^(?P<title>.*?)[\.\-_ ](v\.?\d\.\d|PAL|NTSC|EUR|USA|JP|ASIA|JAP|JPN|AUS|MULTI\.?5|MULTI\.?4|MULTI\.?3|PATCHED|FULLDVD|DVD5|DVD9|DVDRIP|PROPER|REPACK|RETAIL|DEMO|DISTRIBUTION|REGIONFREE|READ\.?NFO|NFOFIX|PS2|PS3|PSP|WII|X\-?BOX|XBLA|X360|NDS|N64|NGC)/i', $releasename, $matches);
  472. if (isset($matches['title']))
  473. {
  474. $title = $matches['title'];
  475. //replace dots or underscores with spaces
  476. $result['title'] = preg_replace('/(\.|_|\%20)/', ' ', $title);
  477. //Needed to add code to handle DLC Properly
  478. if (preg_match('/dlc/i', $result['title']))
  479. {
  480. $result['dlc'] = '1';
  481. if (preg_match('/Rock Band Network/i', $result['title']))
  482. {
  483. $result['title'] = 'Rock Band';
  484. }
  485. Else if (preg_match('/\-/i', $result['title']))
  486. {
  487. $dlc = explode("-", $result['title']);
  488. $result['title'] = $dlc[0];
  489. }
  490. Else
  491. {
  492. preg_match('/(.*? .*?) /i', $result['title'], $dlc);
  493. $result['title'] = $dlc[0];
  494. }
  495. }
  496. }
  497. //get the platform of the release
  498. preg_match('/[\.\-_ ](?P<platform>XBLA|WiiWARE|N64|SNES|NES|PS2|PS3|PS 3|PSP|WII|XBOX360|X\-?BOX|X360|NDS|NGC)/i', $releasename, $matches);
  499. if (isset($matches['platform']))
  500. {
  501. $platform = $matches['platform'];
  502. if (preg_match('/^(XBLA)$/i', $platform))
  503. {
  504. if (preg_match('/DLC/i', $title))
  505. {
  506. $platform = str_replace('XBLA', 'XBOX360', $platform); // baseline single quote
  507. }
  508. }
  509. $browseNode = $this->getBrowseNode($platform);
  510. $result['platform'] = $platform;
  511. $result['node'] = $browseNode;
  512. }
  513. $result['release'] = $releasename;
  514. array_map("trim", $result);
  515. //make sure we got a title and platform otherwise the resulting lookup will probably be shit
  516. //other option is to pass the $release->categoryID here if we dont find a platform but that would require an extra lookup to determine the name
  517. //in either case we should have a title at the minimum
  518. return (isset($result['title']) && !empty($result['title']) && isset($result['platform'])) ? $result : false;
  519. }
  520. function getBrowseNode($platform)
  521. {
  522. switch($platform)
  523. {
  524. case 'PS2':
  525. $nodeId = '301712';
  526. break;
  527. case 'PS3':
  528. $nodeId = '14210751';
  529. break;
  530. case 'PSP':
  531. $nodeId = '11075221';
  532. break;
  533. case 'WII':
  534. case 'Wii':
  535. $nodeId = '14218901';
  536. break;
  537. case 'XBOX360':
  538. case 'X360':
  539. $nodeId = '14220161';
  540. break;
  541. case 'XBOX':
  542. case 'X-BOX':
  543. $nodeId = '537504';
  544. break;
  545. case 'NDS':
  546. $nodeId = '11075831';
  547. break;
  548. case 'N64':
  549. $nodeId = '229763';
  550. break;
  551. case 'SNES':
  552. $nodeId = '294945';
  553. break;
  554. case 'NES':
  555. $nodeId = '566458';
  556. break;
  557. case 'NGC':
  558. $nodeId = '541022';
  559. break;
  560. default:
  561. $nodeId = '468642';
  562. break;
  563. }
  564. return $nodeId;
  565. }
  566. public function matchBrowseNode($nodeName)
  567. {
  568. $str = '';
  569. //music nodes above mp3 download nodes
  570. switch($nodeName)
  571. {
  572. case 'Action':
  573. case 'Adventure':
  574. case 'Arcade':
  575. case 'Board Games':
  576. case 'Cards':
  577. case 'Casino':
  578. case 'Flying':
  579. case 'Puzzle':
  580. case 'Racing':
  581. case 'Rhythm':
  582. case 'Role-Playing':
  583. case 'Simulation':
  584. case 'Sports':
  585. case 'Strategy':
  586. case 'Trivia':
  587. $str = $nodeName;
  588. break;
  589. }
  590. return ($str != '') ? $str : false;
  591. }
  592. }
  593. ?>