Ejemplo n.º 1
0
function render($twig, $sdata = array())
{
    if (!isset($_GET['steamid'])) {
        // no steamid given, f**k off
        echo $twig->render('404.php', $sdata);
        return false;
    }
    if ($_GET['steamid'] == $_SESSION['steamid'] || $_SESSION['admin'] === true) {
        // if you're looking at yourself you get your full history
        // same goes for admins
        $player = new Player(array('search' => $_GET['steamid'], 'fullhistory' => true));
    } else {
        // otherwise it's just the latest 10 runs
        $player = new Player(array('search' => $_GET['steamid']));
    }
    if ($player->steamid == false) {
        // no player found
        echo $twig->render('404.php', $sdata);
        return false;
    }
    // is this player our friend?
    $f = new Friends();
    $is_friend = $f->checkFriend($_SESSION['steamid'], $player->steamid);
    // add or remove him from our friends list
    if (isset($_GET['friend']) && !$is_friend) {
        $f->addFriend($_SESSION['steamid'], $player->steamid);
        $is_friend = !$is_friend;
        header("Location: /player/" . $player->steamid);
    } elseif (isset($_GET['friend']) && $is_friend) {
        $f->removeFriend($_SESSION['steamid'], $player->steamid);
        $is_friend = !$is_friend;
        header("Location: /player/" . $player->steamid);
    }
    // get followers
    $followers = $f->getFollowersForSteamId($player->steamid);
    // send out to render
    $data = array('player' => $player, 'is_friend' => $is_friend, 'followers' => $followers, 'stats' => $player->stats);
    if (isset($_GET['json'])) {
        print json_encode($data);
    } else {
        echo $twig->render('player.php', array_merge($sdata, $data));
    }
}