예제 #1
0
파일: GBApi.php 프로젝트: nirkbirk/site
 public static function searchForGames($query, $limit = 10)
 {
     self::validateApiKey();
     //Change these if we need to include more stuff.
     $fieldArr = ['id', 'name', 'original_release_date', 'image', 'api_detail_url', 'deck', 'image', 'platforms'];
     //sanitise query
     $query = trim(preg_replace('/ +/', ' ', preg_replace('/[^A-Za-z0-9 ]/', ' ', urldecode(html_entity_decode(strip_tags($query))))));
     //generate url
     $url = self::$gb . 'games?api_key=' . self::$apikey . '&format=json' . self::formatFieldList($fieldArr) . '&limit=' . $limit . '&filter=platforms:17|94|152,name:' . $query;
     //Limit to Mac, PC, Linux respectively.
     try {
         $json = self::makeApiCall($url);
     } catch (Exception $e) {
         throw new GBApiException('Error contacting Giantbomb. Please try again later.');
     }
     //QueryDb and try to find the object using the giantbomb unique id
     if ($json->results == null || count($json->results) < 1) {
         throw new GBApiException('No results found. Please try another search.');
     }
     $games = [];
     //initialise as empty array
     foreach ($json->results as $result) {
         $game = GamesQuery::create()->findOneByGbId($result->id);
         if ($game == null) {
             if (!isset($result->original_release_date) || $result->original_release_date == null) {
                 continue;
             }
             //skip if not out yet.
             $game = new Games();
             $game->setGbId($result->id);
             $game->setName(Games::generateUniqueName($result->name, $result->original_release_date));
             $game->setGbUrl($result->api_detail_url);
             $game->setTitle($result->name);
             $game->setDescription($result->deck);
             //We don't care if they don't have thumbs. Catch the exceptions and move on
             try {
                 $game->setGbThumb($result->image->screen_url);
             } catch (Exception $e) {
             }
             try {
                 $game->setGbImage($result->image->medium_url);
             } catch (Exception $e) {
             }
             $game->save();
         }
         //append result to list.
         array_push($games, $game);
     }
     return $games;
 }
예제 #2
0
파일: name_test.php 프로젝트: nirkbirk/site
<pre>
<?php 
$start = "It's good to yell at people and tell people that you're from Tennesee, so that way you'll be safe. The best way to communicate is compatible. Compatible communication is listening with open ears and an open mind, and not being fearful or judgemental about what you're hearing.\t";
require_once "res/include.php";
echo "start";
echo "<br/>";
$name = Games::generateUniqueName($start, "2010");
echo $name;
$game = new Games();
$game->setName($name);
$game->save();
echo "<br/>";
$name = Games::generateUniqueName($start, "2010");
echo $name;
echo "<br/>";
echo "end";
?>
</pre>