Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Copyright 2011 Galicia de Moda
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may
- * not use this file except in compliance with the License. You may obtain
- * a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations
- * under the License.
- */
- // Import config
- require 'fakepath/configure.php';
- // Import and Instance Facebook PHP SDK
- require 'fakepath/facebook.php';
- $facebook = new Facebook(array('appId' => APP_ID, 'secret' => APP_PW, 'cookie' => true));
- // Import and Instance resources
- require 'fakepath/resources.php';
- $resources = new Resources();
- // Get Facebook user id
- try {
- $userbook = $facebook->getUser(); }
- catch (Exception $e) {
- $facebook = null; }
- // Join through friend invite or wall link. Not auth?, first require auth
- if ((isset($_GET['request_ids']) or isset($_GET['fwid'])) and ($userbook == 0)) {
- $request = (isset($_GET['request_ids'])) ? 'index (friend-invite '.$_GET['request_ids'].')' : 'index (from '.$_GET['fwid'].')';
- $resources->logwrite($userbook, $request);
- $resources->assign('app-id', APP_ID);
- $resources->assign('query-string', getenv('QUERY_STRING'));
- $resources->display('authorize.html'); }
- // Join through friend invite or wall link. Auth app, continue
- elseif ((isset($_GET['request_ids']) or isset($_GET['fwid'])) and ($userbook)) {
- // Check friend invite
- if (isset($_GET['request_ids'])) {
- // Do an array with request_ids
- $all_request = explode(',', $_GET['request_ids']);
- // Check for registered users.
- $resources->execute(sprintf("SELECT COUNT(facebook) AS participante FROM participantes WHERE facebook='%s'", $userbook), 'check-register');
- $data = mysql_fetch_array($resources->mysql['check-register']);
- // User registered, invalid invites points
- if ($data['participante'] >= 1) {
- $resources->logwrite($userbook, 'index (from invites - ERROR - user exists');
- $resources->logfile[] = 'La invitacion es invalida, el usuario ya esta registrado';
- }
- // User not register, go on.
- else {
- $resources->logwrite($userbook, 'index (from invites '.$_GET['request_ids'].')');
- $resources->logfile[] = 'Procesamos invitaciones';
- $use_request = array_pop($all_request);
- // Check all requests_id from database
- $resources->execute(sprintf("SELECT facebook, request_id, user_invited FROM reg_invite WHERE request_id='%s' AND user_invited='%s'", $use_request, $userbook), 'get-request');
- $data = mysql_fetch_array($resources->mysql['get-request']);
- // Update friend score and delete request_id from database
- $resources->execute(sprintf("UPDATE puntuaciones SET incoming=incoming + 1 WHERE facebook='%s'", $data['facebook']), 'update-profile');
- $resources->execute(sprintf("DELETE FROM reg_invite WHERE request_id='%s' AND user_invited='%s'", $use_request, $userbook), 'drop-request');
- $facebook->api('/' . $use_request, 'DELETE');
- // Store the friend id, for more score if this user wants play with us
- $_SESSION['from-wall-id'] = $data['facebook'];
- }
- // Remove the other request_id
- foreach ($all_request as $request) {
- $resource->execute(sprintf("DELETE FROM reg_invite WHERE request_id='%s' AND user_invited='%s'", $request, $userbook), 'drop-request');
- $facebook->api('/'.$request, 'DELETE');
- }
- } // if (isset($_GET['request_ids'])) {
- // Check the wall link
- elseif (isset($_GET['fwid'])) {
- $_GET['fwid'] = trim($_GET['fwid']);
- // User join throght own wall...
- if ($_GET['fwid'] == $userbook) {
- $resources->logwrite($userbook, 'index (from '.$_GET['fwid'].' - user mismatch)');
- $resources->logfile[] = 'Usuario intenta entrar desde su propio muro'; }
- // User join from other wall
- else {
- $resources->logwrite($userbook, 'index (from '.$_GET['fwid'].')');
- // Flood control, how many times user joins this day?
- $resources->execute(sprintf("SELECT COUNT(id) AS recuento FROM ref_wall WHERE facebook='%s' AND from_wall='%s' AND register='%s'", $userbook, $_GET['fwid'], date('Y-m-d')), 'recuento');
- $data = mysql_fetch_array($resources->mysql['recuento']);
- // Today, not score
- if ($data['recuento'] >= 1) {
- $resources->logwrite($userbook, 'index (from '.$_GET['fwid'].' - wall flood)');
- $resources->logfile[] = 'Usuario ya ha entrado desde este muro'; }
- // Never or yesterday, go on
- elseif ($data['recuento'] == 0) {
- $resources->logfile[] = 'Procesando entrada desde muro';
- $resources->logwrite($userbook, 'index (from '.$_GET['fwid'].' - accept)');
- $resources->execute(sprintf("INSERT INTO ref_wall VALUES('', '%s', '%s', '%s', '%s')", $userbook, $resources->session['address'], $_GET['fwid'], date('Y-m-d')));
- $resources->execute(sprintf("UPDATE puntuaciones SET incoming=incoming + 1 WHERE facebook='%s'", $_GET['fwid']));
- // Store the friend id, for more score if this user wants play with us
- $_SESSION['from-wall-id'] = $_GET['fwid'];
- }
- }
- } // elseif (isset($_GET['fwid'])) {
- }
- // Join through bookmark
- elseif ($_GET['rel'] == 'bookmarks') {
- $resources->logwrite($userbook, 'index (from-bookmark)'); }
- // Join through? ok... he/she joins
- else {
- $resources->logwrite($userbook, 'index'); }
- // Get player numbers
- $resources->execute('SELECT COUNT(facebook) AS recuento FROM participantes', 'users-count');
- $users = mysql_fetch_array($resources->mysql['users-count']);
- $resources->assign('users-count', $users['recuento']);
- // User in database?, show "score" button or "join" button
- $resources->execute(sprintf("SELECT COUNT(facebook) AS participante FROM participantes WHERE facebook='%s'", $userbook), 'is-player');
- $player = mysql_fetch_array($resources->mysql['is-player']);
- if ($player['participante'] >= 1) {
- $resources->assign('action-url', 'puntuacion.php'); $resources->assign('action-msg', 'Tu puntuación'); }
- else {
- $resources->assign('action-url', 'participa.php'); $resources->assign('action-msg', 'Participa'); }
- // Debug, display user and other data
- $resources->assign('user-display', 'ID usuario en facebook '.$userbook);
- //require 'fakepath/debugmode.php';
- // Show site
- $resources->display('index.html');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement