/** * PAGE: index * This method handles what happens when you move to http://yourproject/home/index (which is the default page btw) */ public function index() { $redirected = false; //check if there is an error if ($_GET['error'] != '') { //load error page! die("<h1>Whoops, something went wrong, you can refresh to see if it fixes it otherwise check back later.</h1>"); } if (isset($_GET['appSource'])) { $redirected = true; $appSource = (int) $_GET['appSource']; } if (!$redirected) { if (isset($_GET['id']) && $_GET['id'] != "") { $extraParameters['id'] = $_GET['id']; } if (isset($_GET['fbSource'])) { $extraParameters['appSource'] = $_GET['appSource']; } if (isset($_GET['traffic_source']) && $_GET['traffic_source'] != '') { $extraParameters['traffic_source'] = $_GET['traffic_source']; } } $signedRequest = null; if (isset($_POST['signed_request'])) { $signedRequest = self::parseSignedRequest($_POST['signed_request']); } Log::add('Signed request: ' . $signedRequest); //check if user_id if ($signedRequest === null) { //we need to get one! $url = Config::get('facebook.appurl') . "?" . http_build_query($_GET); header("location: " . $url); exit; } if (!isset($signedRequest['user_id']) || $signedRequest['user_id'] == '') { $redirectUrl = self::buildUrl($extraParameters); $oAuthUrl = "https://www.facebook.com/dialog/oauth?"; $oAuthUrl .= http_build_query(array_filter(array('client_id' => Config::Get('facebook.appid'), 'redirect_uri' => self::buildUrl($extraParameters), 'scope' => 'user_friends,email'))); die("<script>top.location.href = '" . $oAuthUrl . "';</script>"); } $fbCurlReq = new Curl(); $fbCurlReq->setOpt(CURLOPT_SSL_VERIFYPEER, false); $fbCurlReq->get('https://graph.facebook.com/me?access_token=' . $signedRequest['oauth_token']); if ($fbCurlReq->error) { Log::add('Error fb user profile ' . $fbCurlReq->error_code . ': ' . $fbCurlReq->error_message); } else { $dataArray = $fbCurlReq->response; } Log::add('dataArray = ' . print_r($dataArray, true)); //check too see if this is a post :) $game = new Game(); $game->loadGame((array) $dataArray, 'facebook', $extraParameters); }
public function index() { list($loggedIn, $userData) = self::isSignedIn($_GET); //load! else redir. if ($loggedIn) { $dataArray['first_name'] = $userData['gamerName']; $dataArray['platform'] = 'yahoo'; $dataArray['last_name'] = ''; $dataArray['profileImg'] = $userData['userAvatar']; $dataArray['id'] = $userData['userId']; $dataArray['apiToken'] = $userData['apiToken']; $dataArray['userToken'] = $_GET['usertoken']; $game = new Game(); $game->loadGame($dataArray, 'yahoo', $_GET); } else { $getParams = http_build_query($_GET); //well lets log them in. include APP_PATH . 'views/yahoo-login.php'; die; } }
<?php require_once "lib/load.php"; if (!require_params("id", "action")) { die; } $action = $_REQUEST["action"]; $game = Game::loadGame($_REQUEST["id"]); switch ($action) { case 'up': case 'down': case 'left': case 'right': echo json_encode($game->move($action)); break; default: throw new Exception("Unknown action."); break; }