Skip to content

Commit

Permalink
* [ReleasesSwitch] Switch scene releases (#1694)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ORelio authored Aug 31, 2020
1 parent c21a805 commit e00bbe3
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 15 deletions.
41 changes: 26 additions & 15 deletions bridges/Releases3DSBridge.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ class Releases3DSBridge extends BridgeAbstract {
const NAME = '3DS Scene Releases';
const URI = 'http://www.3dsdb.com/';
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(){
$this->collectDataUrl(self::URI . 'xml.php');
}

protected function collectDataUrl($dataUrl){

$dataUrl = self::URI . 'xml.php';
$xml = getContents($dataUrl)
or returnServerError('Could not request 3dsdb: ' . $dataUrl);
or returnServerError('Could not request URL: ' . $dataUrl);
$limit = 0;

foreach(array_reverse(explode('<release>', $xml)) as $element) {
Expand Down Expand Up @@ -52,17 +55,25 @@ public function collectData(){

$ignSearchUrl = 'https://www.ign.com/search?q=' . urlencode($name);
if($ignResult = getSimpleHTMLDOMCached($ignSearchUrl)) {
$ignCoverArt = $ignResult->find('div.search-item-media', 0)->find('img', 0)->src;
$ignDesc = $ignResult->find('div.search-item-description', 0)->plaintext;
$ignLink = $ignResult->find('div.search-item-sub-title', 0)->find('a', 1)->href;
$ignDate = strtotime(trim($ignResult->find('span.publish-date', 0)->plaintext));
$ignDescription = '<div><img src="'
. $ignCoverArt
. '" /></div><div>'
. $ignDesc
. ' <a href="'
. $ignLink
. '">More at IGN</a></div>';
$ignCoverArt = $ignResult->find('div.search-item-media', 0);
$ignDesc = $ignResult->find('div.search-item-description', 0);
$ignLink = $ignResult->find('div.search-item-sub-title', 0);
$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="'
. $ignCoverArt->src
. '" /></div><div>'
. $ignDesc->plaintext
. ' <a href="'
. $ignLink->href
. '">More at IGN</a></div>';
}
}

//Main section : Release description from 3DS database
Expand Down Expand Up @@ -111,7 +122,7 @@ public function collectData(){

private function typeToString($type){
switch($type) {
case 1: return '3DS Game';
case 1: return 'Card Game';
case 4: return 'eShop';
default: return '??? (' . $type . ')';
}
Expand Down
17 changes: 17 additions & 0 deletions bridges/ReleasesSwitchBridge.php
Original file line number Diff line number Diff line change
@@ -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');
}
}

0 comments on commit e00bbe3

Please sign in to comment.