* [ReleasesSwitch] Switch scene releases (#1694)

Separate bridge from Releases3DS that just has a different URL.
Inherits from Releases3DS so both bridges need to be present.

*  [Releases3DS] Fix PHP notices related to IGN
This commit is contained in:
ORelio 2020-08-31 19:02:25 +02:00 committed by GitHub
parent c21a805cb4
commit e00bbe353f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 43 additions and 15 deletions

View file

@ -5,13 +5,16 @@ class Releases3DSBridge extends BridgeAbstract {
const NAME = '3DS Scene Releases'; const NAME = '3DS Scene Releases';
const URI = 'http://www.3dsdb.com/'; const URI = 'http://www.3dsdb.com/';
const CACHE_TIMEOUT = 10800; // 3h const CACHE_TIMEOUT = 10800; // 3h
const DESCRIPTION = 'Returns the newest scene releases.'; const DESCRIPTION = 'Returns the newest scene releases for Nintendo 3DS.';
public function collectData(){ public function collectData(){
$this->collectDataUrl(self::URI . 'xml.php');
}
protected function collectDataUrl($dataUrl){
$dataUrl = self::URI . 'xml.php';
$xml = getContents($dataUrl) $xml = getContents($dataUrl)
or returnServerError('Could not request 3dsdb: ' . $dataUrl); or returnServerError('Could not request URL: ' . $dataUrl);
$limit = 0; $limit = 0;
foreach(array_reverse(explode('<release>', $xml)) as $element) { foreach(array_reverse(explode('<release>', $xml)) as $element) {
@ -52,18 +55,26 @@ class Releases3DSBridge extends BridgeAbstract {
$ignSearchUrl = 'https://www.ign.com/search?q=' . urlencode($name); $ignSearchUrl = 'https://www.ign.com/search?q=' . urlencode($name);
if($ignResult = getSimpleHTMLDOMCached($ignSearchUrl)) { if($ignResult = getSimpleHTMLDOMCached($ignSearchUrl)) {
$ignCoverArt = $ignResult->find('div.search-item-media', 0)->find('img', 0)->src; $ignCoverArt = $ignResult->find('div.search-item-media', 0);
$ignDesc = $ignResult->find('div.search-item-description', 0)->plaintext; $ignDesc = $ignResult->find('div.search-item-description', 0);
$ignLink = $ignResult->find('div.search-item-sub-title', 0)->find('a', 1)->href; $ignLink = $ignResult->find('div.search-item-sub-title', 0);
$ignDate = strtotime(trim($ignResult->find('span.publish-date', 0)->plaintext)); $ignDate = $ignResult->find('span.publish-date', 0);
if (is_object($ignCoverArt))
$ignCoverArt = $ignCoverArt->find('img', 0);
if (is_object($ignLink))
$ignLink = $ignLink->find('a', 1);
if (is_object($ignDate))
$ignDate = strtotime(trim($ignDate->plaintext));
if (is_object($ignCoverArt) && is_object($ignDesc) && is_object($ignLink)) {
$ignDescription = '<div><img src="' $ignDescription = '<div><img src="'
. $ignCoverArt . $ignCoverArt->src
. '" /></div><div>' . '" /></div><div>'
. $ignDesc . $ignDesc->plaintext
. ' <a href="' . ' <a href="'
. $ignLink . $ignLink->href
. '">More at IGN</a></div>'; . '">More at IGN</a></div>';
} }
}
//Main section : Release description from 3DS database //Main section : Release description from 3DS database
$releaseDescription = '<h3>Release Details</h3><b>Release ID: </b>' . $id $releaseDescription = '<h3>Release Details</h3><b>Release ID: </b>' . $id
@ -111,7 +122,7 @@ class Releases3DSBridge extends BridgeAbstract {
private function typeToString($type){ private function typeToString($type){
switch($type) { switch($type) {
case 1: return '3DS Game'; case 1: return 'Card Game';
case 4: return 'eShop'; case 4: return 'eShop';
default: return '??? (' . $type . ')'; default: return '??? (' . $type . ')';
} }

View file

@ -0,0 +1,17 @@
<?php
// This bridge depends on Releases3DSBridge
if (!class_exists('Releases3DSBridge')){
include('Releases3DSBridge.php');
}
class ReleasesSwitchBridge extends Releases3DSBridge {
const NAME = 'Switch Scene Releases';
const URI = 'http://www.nswdb.com/';
const DESCRIPTION = 'Returns the newest scene releases for Nintendo Switch.';
public function collectData(){
$this->collectDataUrl(self::URI . 'xml.php');
}
}