From 75a6f8af8ad116e3ba5d8cb9c54d72bf2468d47d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20Mazi=C3=A8re?= Date: Mon, 29 Aug 2016 22:22:33 +0200 Subject: [PATCH] [Releases3DSBridge] code simplification MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre Mazière --- bridges/Releases3DSBridge.php | 150 +++++++++++++++++----------------- 1 file changed, 77 insertions(+), 73 deletions(-) diff --git a/bridges/Releases3DSBridge.php b/bridges/Releases3DSBridge.php index 25ba50be..3e4ccaea 100644 --- a/bridges/Releases3DSBridge.php +++ b/bridges/Releases3DSBridge.php @@ -32,84 +32,88 @@ class Releases3DSBridge extends BridgeAbstract { } } - $dataUrl = 'http://3dsdb.com/xml.php'; + $dataUrl = $this->uri.'xml.php'; $xml = $this->getContents($dataUrl) or $this->returnServerError('Could not request 3dsdb: '.$dataUrl); $limit = 0; foreach (array_reverse(explode('', $xml)) as $element) { - if ($limit < 5) { - if (strpos($element, '') !== false) { - - $id = ExtractFromDelimiters($element, '', ''); - $name = ExtractFromDelimiters($element, '', ''); - $publisher = ExtractFromDelimiters($element, '', ''); - $region = ExtractFromDelimiters($element, '', ''); - $group = ExtractFromDelimiters($element, '', ''); - $imagesize = ExtractFromDelimiters($element, '', ''); - $serial = ExtractFromDelimiters($element, '', ''); - $titleid = ExtractFromDelimiters($element, '', ''); - $imgcrc = ExtractFromDelimiters($element, '', ''); - $filename = ExtractFromDelimiters($element, '', ''); - $releasename = ExtractFromDelimiters($element, '', ''); - $trimmedsize = ExtractFromDelimiters($element, '', ''); - $firmware = ExtractFromDelimiters($element, '', ''); - $type = ExtractFromDelimiters($element, '', ''); - $card = ExtractFromDelimiters($element, '', ''); - - if (!empty($releasename)) { - - //Retrieve cover art and short desc from IGN? - $ignResult = false; $ignDescription = ''; $ignLink = ''; $ignDate = time(); $ignCoverArt = ''; - $ignSearchUrl = 'http://www.ign.com/search?q='.urlencode($name); - if ($ignResult = $this->getSimpleHTMLDOM($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 = '
'.$ignDesc.' More at IGN
'; - } - - //Main section : Release description from 3DS database - $releaseDescription = '

Release Details

' - .'Release ID: '.$id.'
' - .'Game Name: '.$name.'
' - .'Publisher: '.$publisher.'
' - .'Region: '.$region.'
' - .'Group: '.$group.'
' - .'Image size: '.(intval($imagesize)/8).'MB
' - .'Serial: '.$serial.'
' - .'Title ID: '.$titleid.'
' - .'Image CRC: '.$imgcrc.'
' - .'File Name: '.$filename.'
' - .'Release Name: '.$releasename.'
' - .'Trimmed size: '.intval(intval($trimmedsize)/1048576).'MB
' - .'Firmware: '.$firmware.'
' - .'Type: '.TypeToString($type).'
' - .'Card: '.CardToString($card).'
'; - - //Build search links section to facilitate release search using search engines - $releaseNameEncoded = urlencode(str_replace(' ', '+', $releasename)); - $searchLinkGoogle = 'https://google.com/?q='.$releaseNameEncoded; - $searchLinkDuckDuckGo = 'https://duckduckgo.com/?q='.$releaseNameEncoded; - $searchLinkQwant = 'https://lite.qwant.com/?q='.$releaseNameEncoded.'&t=web'; - $releaseSearchLinks = '

Search this release

'; - - //Build and add final item with the above three sections - $item = array(); - $item['title'] = $name; - $item['author'] = $publisher; - $item['timestamp'] = $ignDate; - $item['uri'] = empty($ignLink) ? $searchLinkDuckDuckGo : $ignLink; - $item['content'] = $ignDescription.$releaseDescription.$releaseSearchLinks; - $this->items[] = $item; - $limit++; - } - } + if ($limit >= 5) { + break; } + + if (strpos($element, '') === false) { + continue; + } + + $releasename = ExtractFromDelimiters($element, '', ''); + if (empty($releasename)) { + continue; + } + + $id = ExtractFromDelimiters($element, '', ''); + $name = ExtractFromDelimiters($element, '', ''); + $publisher = ExtractFromDelimiters($element, '', ''); + $region = ExtractFromDelimiters($element, '', ''); + $group = ExtractFromDelimiters($element, '', ''); + $imagesize = ExtractFromDelimiters($element, '', ''); + $serial = ExtractFromDelimiters($element, '', ''); + $titleid = ExtractFromDelimiters($element, '', ''); + $imgcrc = ExtractFromDelimiters($element, '', ''); + $filename = ExtractFromDelimiters($element, '', ''); + $trimmedsize = ExtractFromDelimiters($element, '', ''); + $firmware = ExtractFromDelimiters($element, '', ''); + $type = ExtractFromDelimiters($element, '', ''); + $card = ExtractFromDelimiters($element, '', ''); + + //Retrieve cover art and short desc from IGN? + $ignResult = false; $ignDescription = ''; $ignLink = ''; $ignDate = time(); $ignCoverArt = ''; + $ignSearchUrl = 'http://www.ign.com/search?q='.urlencode($name); + if ($ignResult = $this->getSimpleHTMLDOM($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 = '
'.$ignDesc.' More at IGN
'; + } + + //Main section : Release description from 3DS database + $releaseDescription = '

Release Details

' + .'Release ID: '.$id.'
' + .'Game Name: '.$name.'
' + .'Publisher: '.$publisher.'
' + .'Region: '.$region.'
' + .'Group: '.$group.'
' + .'Image size: '.(intval($imagesize)/8).'MB
' + .'Serial: '.$serial.'
' + .'Title ID: '.$titleid.'
' + .'Image CRC: '.$imgcrc.'
' + .'File Name: '.$filename.'
' + .'Release Name: '.$releasename.'
' + .'Trimmed size: '.intval(intval($trimmedsize)/1048576).'MB
' + .'Firmware: '.$firmware.'
' + .'Type: '.TypeToString($type).'
' + .'Card: '.CardToString($card).'
'; + + //Build search links section to facilitate release search using search engines + $releaseNameEncoded = urlencode(str_replace(' ', '+', $releasename)); + $searchLinkGoogle = 'https://google.com/?q='.$releaseNameEncoded; + $searchLinkDuckDuckGo = 'https://duckduckgo.com/?q='.$releaseNameEncoded; + $searchLinkQwant = 'https://lite.qwant.com/?q='.$releaseNameEncoded.'&t=web'; + $releaseSearchLinks = '

Search this release

'; + + //Build and add final item with the above three sections + $item = array(); + $item['title'] = $name; + $item['author'] = $publisher; + $item['timestamp'] = $ignDate; + $item['uri'] = empty($ignLink) ? $searchLinkDuckDuckGo : $ignLink; + $item['content'] = $ignDescription.$releaseDescription.$releaseSearchLinks; + $this->items[] = $item; + $limit++; } }