示例#1
0
文件: Games.php 项目: nirkbirk/site
 public static function generateUniqueName($title, $year)
 {
     $name_base = str_replace(array_keys(Games::$TRANSLITERATABLE_CHARACTERS), array_values(Games::$TRANSLITERATABLE_CHARACTERS), $title);
     $name_base = strtolower($name_base);
     $name_base = preg_replace("/[']/", '', $name_base);
     $name_base = preg_replace("/[^a-z0-9]/", '_', $name_base);
     $name_base = preg_replace('/_+/', '_', $name_base);
     if (strlen($year) > 4) {
         $year = date_parse($year);
         $year = $year["year"];
     }
     $approved = false;
     $try = 0;
     while (!$approved) {
         $number_length = 0;
         if ($try > 0) {
             $number_length = strlen($try) + 1;
         }
         $name = substr($name_base, 0, 254 - strlen($year) - $number_length);
         $name .= '_' . $year;
         if ($try > 0) {
             $name .= '_' . $try;
         }
         $result = null;
         $query = new GamesQuery();
         $result = $query->findOneByName($name);
         if ($result != null) {
             $try++;
         } else {
             return $name;
         }
     }
 }
示例#2
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;
 }
示例#3
0
<?php

require "res/include.php";
if (!Auth::checkIfAdmin()) {
    header("Location: /");
    /* Redirect browser */
}
$user = Auth::getCurrentUser();
$game = null;
$platform = null;
if (!array_key_exists("game", $_GET) || !array_key_exists("platform", $_GET)) {
    header("Location: /");
    /* Redirect browser */
    exit;
} else {
    $query = new GamesQuery();
    $game = $query->findOneByName($_GET["game"]);
    $query = new PlatformsQuery();
    $platform = $query->findOneByName($_GET["platform"]);
    if ($game == null || $platform == null) {
        header("Location: /");
        /* Redirect browser */
        exit;
    }
}
$header = RatingHeadersQuery::create()->filterByGames($game)->filterByPlatforms($platform)->findOne();
if (array_key_exists("category_options_1", $_POST)) {
    $con = \Propel\Runtime\Propel::getConnection();
    $con->beginTransaction();
    try {
        if (!Auth::checkIfAuthenticated()) {
示例#4
0
文件: index.php 项目: nirkbirk/site
    <?php 
include "res/head.php";
?>
    <title>PC Masterratings</title>

</head>
<body>
<?php 
include "res/nav.php";
?>

<div class="container">
    <div class="col-md-8">
        <h1>Most recent games</h1>
        <?php 
$query = new GamesQuery();
$query->limit(6);
$query->innerJoinRatingHeaders();
$query->orderById("DESC");
$games = $query->find();
$i = 1;
foreach ($games as $game) {
    if ($i % 3 == 0) {
        echo '<div class="row">';
    }
    echo "<div class='col-sm-6 col-md-4'>\n                  <div class='thumbnail'>\n                    <a href='game.php?name={$game->getName()}'>\n                      <img src={$game->getGbThumb()} alt='thumbnail'>\n                        <img class='rating-badge' src='/img/badges/{$game->getRatingForDefaultPlatform()->getInitial()}_tiny.jpg'\n                                    alt='" . strtoupper($game->getRatingForDefaultPlatform()->getTitle()) . "'>\n                          <div class='caption'><h3>{$game->getTitle()}</h3></div>\n                    </a>\n                  </div>\n                </div>";
    if ($i % 3 == 0) {
        echo '</div>';
    }
    $i++;
}