<?php require_once 'core/init.php'; $user = new User(); if (!$user->isLoggedIn()) { Redirect::to('index.php'); } if (Input::exists()) { if (isset($_POST['confirm_friend_request'])) { //if(Token::check(Input::get('token'))) { $friend = new User($_POST['friend']); $fid = $friend->data()->id; $friendName = $friend->data()->firstName . ' ' . $friend->data()->middleName . ' ' . $friend->data()->lastName; if (!$user->isFriend($fid) && $user->getFriendRequests($fid)) { try { $user->addFriend($fid); Session::flash('alerts', array('info' => array('type' => 'success', 'title' => 'Request Accepted'), 'alerts' => array("You are now friends with {$friendName}."))); } catch (Exception $e) { die($e->getMessage()); } } //} } else { if (isset($_POST['delete_friend_request'])) { //if(Token::check(Input::get('token'))) { $friend = new User($_POST['friend']); $fid = $friend->data()->id; $friendName = $friend->data()->firstName . ' ' . $friend->data()->middleName . ' ' . $friend->data()->lastName; if (!$user->isFriend($fid) && $user->getFriendRequests($fid)) { try { $request = new Request();
$_SESSION['scripts'] = file_get_contents($app->get_htmlscripts_location()); } else { if ($op == "get app") { // Gets the requested app from the session $json = array(); $json['html'] = $_SESSION['html']; $json['scripts'] = $_SESSION['scripts']; echo json_encode($json); } else { if ($op == "get friends") { $html = ""; $json = build_friend_cards($html, $user->get_friends()); echo json_encode($json); } else { if ($op == "add friend") { $user->addFriend($_GET['name']); echo json_encode($_GET['name']); } else { if ($op == "remove friend") { $user->removeFriend($_GET['name']); echo json_encode($_GET['name']); } else { if ($op == "search users") { $html = ""; if (preg_match('/\\w+/', $_GET['string'])) { $allUsers = $user->get_search_users($_GET['string']); $json = build_friend_cards($html, $allUsers); echo json_encode($json); } else { echo 'false'; }
$request = $app->request(); $body = $request->getBody(); $vo = json_decode($body); $vo->facebook_user_id = $id; $user->update($vo); }); $app->put('/users/:id/score', function ($id) use($user, $app) { $request = $app->request(); $body = $request->getBody(); $vo = json_decode($body); $vo->facebook_user_id = $id; $user->updateScore($vo); $user->updatePlayerRewards($id, $vo->game_score, $vo->score); }); $app->put('/users/:id/friends', function ($id) use($user, $app) { $request = $app->request(); $body = $request->getBody(); $vo = json_decode($body); $vo->facebook_user_id = $id; foreach ($vo->friends as $friend) { if (!$user->playerExists($friend->id)) { continue; } if (!$user->areFriends($id, $friend->id)) { $user->addFriend($id, $friend->id); $user->addFriend($friend->id, $id); } } //TO DO : Check if all db friends still are FB friends }); $app->run();
$response = (object) array('status' => -3, 'status_explanation' => 'Invalid token.'); } header('Content-Type: application/json'); echo json_encode($response); }, $f3->get('route_ttl')); /** * Route: Add friend * * @example /user/add-friend */ $f3->route(array('POST /user/add-friend'), function ($f3, $params) use($db) { // Attempt to sign in if ($sender_id = authenticated()) { $friend_id = $f3->get('POST.friend_id'); $user = new User(null, $sender_id); if ($user->addFriend($friend_id)) { $user->getInfo(true); $potential_friend = new User(null, $friend_id); $potential_friend->getInfo(true); sendPushNotification(sprintf('%s wants to be your friend', $user->getFullName()), $potential_friend->registration_id, '#/friends'); unset($potential_friend); $response = (object) array('status' => 1, 'status_explanation' => 'Success.'); } else { $response = (object) array('status' => -1, 'status_explanation' => 'Could not add friend for unknown reason.'); } } else { $response = (object) array('status' => -3, 'status_explanation' => 'Invalid token.'); } header('Content-Type: application/json'); echo json_encode($response); }, $f3->get('route_ttl'));