示例#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));
    }
}
示例#2
0
文件: operations.php 项目: Klym/flame
<?php

session_start();
require "blocks/autoload.php";
require "blocks/db.php";
require "blocks/user.php";
$data = file_get_contents("php://input");
$data = json_decode($data);
$friend = new Friends($user->id, $db, $data[1]);
if ($data[0] == 0) {
    $friend->delFriend();
} else {
    $result = $friend->addFriend();
    echo $result;
}
示例#3
0
<?php

require_once 'classes/friends.php';
$friends = new Friends();
$action = isset($_GET['action']) ? $_GET['action'] : '';
if ($action == "add") {
    $id = (int) $_GET['friendid'];
    $userid = $_SESSION['userid'];
    $add = $friends->addFriend($id, $userid);
    if ($add < 0) {
        $msg = 'Failed to add this friend to your friends list.';
        return;
    }
    if (empty($add)) {
        event::fire('USER_ADD_FRIEND');
        $msg = "An email has been sent to your friend for confirmation!";
        $friends->sendFriendVerification($userid, $id);
    } else {
        $msg = $add;
    }
    return $msg;
}
if ($action == "remove") {
    $id = (int) $_GET['friendid'];
    $userid = $_SESSION['userid'];
    $add = $friends->removeFriend($id, $userid);
    if ($remove < 0) {
        $msg = 'Failed to remove this friend from your friends list.';
        return;
    }
    if (empty($remove)) {
示例#4
0
/**
 * Posts - comment
 */
$app->get('/post/comments/:post_id/:offset/:limit', function ($post_id, $offset, $limit) use($post) {
    echo json_encode([$post_id => $post->getComments($post_id, $offset, $limit)]);
});
$app->post('/post/comment', function () use($post, $app) {
    $data = json_decode($app->request->getBody());
    echo json_encode($post->publishComment($_SESSION['auth']['user_id'], $data->post_id, $data->content));
});
/**
 * Friends
 */
$app->post('/friend', function () use($friend, $app) {
    $data = json_decode($app->request->getBody());
    echo json_encode($friend->addFriend($_SESSION['auth']['user_id'], $data->friend_id));
});
$app->delete('/friend', function () use($friend, $app) {
    $data = json_decode($app->request->getBody());
    echo json_encode($friend->deleteFriend($_SESSION['auth']['user_id'], $data->friend_id));
});
$app->delete('/friends', function () use($friend, $app) {
    $data = json_decode($app->request->getBody());
    echo json_encode($friend->deleteFriends($_SESSION['auth']['user_id'], $data->friends_to_remove));
});
/**
 * Notifications
 */
$app->get('/notifications/:type/:offset/:limit', function ($type, $offset, $limit) use($friend) {
    echo json_encode($friend->getNotifications($type, $offset, $limit));
});