function queryItem($search_attributes_r, $s_item_type) { $pageBuffer = $this->fetchURI("http://www.mobygames.com/game/" . $search_attributes_r['mgpltfrmid'] . "/" . $search_attributes_r['mobygameid']); // no sense going any further here. if (strlen($pageBuffer) > 0) { //<div id="gameTitle"><a href="/game/windows/counter-strike-source">Counter-Strike: Source</a></div> if (preg_match("!<div id=\"gameTitle\"><a href=\"[^\"]*\">([^<]*)</a>!", $pageBuffer, $matches)) { $this->addItemAttribute('title', $matches[1]); } $this->addItemAttribute('publisher', $this->parse_game_value($pageBuffer, 'published by')); $this->addItemAttribute('developer', $this->parse_game_value($pageBuffer, 'developed by')); $this->addItemAttribute('genre', $this->parse_game_value($pageBuffer, 'genre')); $this->addItemAttribute('platform', $this->parse_game_value($pageBuffer, 'platform')); $this->addItemAttribute('perspective', $this->parse_game_value($pageBuffer, 'perspective')); $this->addItemAttribute('non-sport', $this->parse_game_value($pageBuffer, 'non-sport')); $release_date = $this->parse_game_value($pageBuffer, 'released'); $date = parse_mobygames_release_date($release_date); $this->addItemAttribute('gamepbdate', $date); // Get Description if (preg_match(";<h2 class=\"m5\">Description</h2>" . "(.*?)<div" . ";si", $pageBuffer, $matches)) { $description = $matches[1]; $description = preg_replace(":\\s*<br>\\s*\$:si", "", $description); $description = preg_replace(":\\s*<br>\\s*:si", "\n", $description); $description = preg_replace(":<p>\\s*(.*?)\\s*</p>:si", "\\1\n", $description); $description = preg_replace(":\\s*<p>\\s*:si", "\n", $description); $description = trim($description); $this->addItemAttribute('description', $description); } $coverImages = $this->fetchURI("http://www.mobygames.com/game/covers/p," . $search_attributes_r['mgpltfrmid'] . "/gameId," . $search_attributes_r['mobygameid']); //game/genesis/phantasy-star-iii-generations-of-doom/cover-art/gameCoverId,22908/ if (preg_match_all("!<a href=\"/game/" . $search_attributes_r['mgpltfrmid'] . "/" . $search_attributes_r['mobygameid'] . "/cover-art/gameCoverId,([0-9]+)/\">!", $coverImages, $matches)) { for ($i = 0; $i < count($matches[1]); $i++) { // http://www.mobygames.com/game/dos/spear-of-destiny/cover-art/gameCoverId,12676/ $coverImage = $this->fetchURI("http://www.mobygames.com/game/" . $search_attributes_r['mgpltfrmid'] . "/" . $search_attributes_r['mobygameid'] . "/cover-art/gameCoverId," . $matches[1][$i] . "/"); //<img alt="DOS Front Cover" border="0" src="http://www.mobygames.com/images/covers/large/1021808019-00.jpg" height="767" width="640" > if (preg_match("!src=\"http://www.mobygames.com/images/covers/large/([^\"]+)\"!", $coverImage, $matches2)) { $this->addItemAttribute('imageurl', "http://www.mobygames.com/images/covers/large/" . $matches2[1]); } } } if (preg_match_all("!src=\"(http://www.mobygames.com/images/covers/small/[^\"]+)\"!", $coverImages, $matches)) { $this->addItemAttribute('imageurl', $matches[1]); } $techInfoPage = $this->fetchURI("http://www.mobygames.com/game/" . $search_attributes_r['mgpltfrmid'] . "/" . $search_attributes_r['mobygameid'] . "/techinfo"); if ($techInfoPage !== FALSE) { //<table SUMMARY="Tech-Info Notes" border=0 cellpadding=0 cellspacing=0> if (preg_match(":<table SUMMARY=\"Tech-Info Notes\".*?</table>:si", $techInfoPage, $matches)) { $techInfoPage = $matches[0]; if (preg_match_all(";<tr.*?</tr>;si", $techInfoPage, $matches, PREG_PATTERN_ORDER)) { for ($i = 0; $i < count($matches[0]); $i++) { $row = $matches[0][$i]; //<tr valign="middle"> //<td width="40%">Business Model</td> //<td width="60%"><a href="/attribute/sheet/attributeId,124/p,2/">Commercial</a></td> //</tr> if (preg_match("!<tr.*?<td.*?>(.*?)</td.*?<td.*?>(.*?)</td.*?</tr>!si", $row, $row_matches)) { $key = strtolower(preg_replace("/[\\s]+/i", "_", trim($row_matches[1]))); $value = $row_matches[2]; //<a href="/attribute/sheet/attributeId,65/p,2/"> if (preg_match_all("!<a href=\"/attribute/sheet/attributeId,([0-9]+)/p,([0-9]+)/\">!si", $value, $value_matches)) { $value = $value_matches[1]; $this->addItemAttribute($key, $value); } } } } } } //http://www.mobygames.com/game/rise-of-the-robots/rating-systems $ratingPage = $this->fetchURI("http://www.mobygames.com/game/" . $search_attributes_r['mgpltfrmid'] . "/" . $search_attributes_r['mobygameid'] . "/rating-systems"); if ($ratingPage !== FALSE) { //<table SUMMARY="Rating Categories and Descriptors" border=0 cellpadding=2 cellspacing=0> if (preg_match(":<table SUMMARY=\"Rating Categories and Descriptors\".*?</table>:si", $ratingPage, $matches)) { $ratingPage = $matches[0]; if (preg_match_all(";<tr.*?</tr>;si", $ratingPage, $matches, PREG_PATTERN_ORDER)) { for ($i = 0; $i < count($matches[0]); $i++) { $row = $matches[0][$i]; //<tr><td>ELSPA Rating</td><td> : </td><td><em>unknown</em></td></tr> //<tr><td>OFLC Rating</td><td> : </td><td><img alt="MA15+" border="0" src="/images/i/11/26/50726.gif" height="20" width="20" > <a href="/attribute/sheet/attributeId,419/">MA15+</a></td></tr> if (preg_match("!<tr><td>(.*)</td><td>[\\s]*:[\\s]*</td><td>(.*)</td></tr>!i", $row, $row_matches)) { $field = $row_matches[1]; $value = $row_matches[2]; // Some interesting ratings: ESRB, USK, ELSPA, OFLC Rating if (preg_match("/rating\$/i", $field)) { $rating_name = strtolower(preg_replace("/[\\s]+/i", "_", trim($field))); //<a href="/attribute/sheet/attributeId,92/">Teen</a> if (preg_match("!<a href=\"/attribute/sheet/attributeId,([0-9]+)/\">!si", $value, $rating_matches)) { $rating = $rating_matches[1]; $this->addItemAttribute($rating_name, $rating); } } } } } } } return TRUE; } else { return FALSE; } }
function testParseReleaseDate() { $this->assertEquals('12/11/2007', parse_mobygames_release_date("Nov 12, 2007")); $this->assertEquals('01/10/1985', parse_mobygames_release_date("Oct, 1985")); $this->assertEquals('01/01/1983', parse_mobygames_release_date("1983")); }