Advertisement
Worked

index.php

Nov 9th, 2012
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.58 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * Copyright 2011 Galicia de Moda
  5.  *
  6.  * Licensed under the Apache License, Version 2.0 (the "License"); you may
  7.  * not use this file except in compliance with the License. You may obtain
  8.  * a copy of the License at
  9.  *
  10.  *     http://www.apache.org/licenses/LICENSE-2.0
  11.  *
  12.  * Unless required by applicable law or agreed to in writing, software
  13.  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14.  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  15.  * License for the specific language governing permissions and limitations
  16.  * under the License.
  17.  */
  18.  
  19. // Import config
  20. require 'fakepath/configure.php';
  21.  
  22. // Import and Instance Facebook PHP SDK
  23. require 'fakepath/facebook.php';
  24. $facebook = new Facebook(array('appId' => APP_ID, 'secret' => APP_PW, 'cookie' => true));
  25.  
  26. // Import and Instance resources
  27. require 'fakepath/resources.php';
  28. $resources = new Resources();
  29.  
  30. // Get Facebook user id
  31. try {
  32.   $userbook = $facebook->getUser(); }
  33. catch (Exception $e) {
  34.   $facebook = null; }
  35.  
  36. // Join through friend invite or wall link. Not auth?, first require auth
  37. if ((isset($_GET['request_ids']) or isset($_GET['fwid'])) and ($userbook == 0)) {
  38.   $request = (isset($_GET['request_ids'])) ? 'index (friend-invite '.$_GET['request_ids'].')' : 'index (from '.$_GET['fwid'].')';
  39.   $resources->logwrite($userbook, $request);
  40.   $resources->assign('app-id', APP_ID);
  41.   $resources->assign('query-string', getenv('QUERY_STRING'));
  42.   $resources->display('authorize.html'); }
  43.  
  44. // Join through friend invite or wall link. Auth app, continue
  45. elseif ((isset($_GET['request_ids']) or isset($_GET['fwid'])) and ($userbook)) {
  46.     // Check friend invite
  47.   if (isset($_GET['request_ids'])) {
  48.       // Do an array with request_ids
  49.     $all_request = explode(',', $_GET['request_ids']);
  50.       // Check for registered users.
  51.     $resources->execute(sprintf("SELECT COUNT(facebook) AS participante FROM participantes WHERE facebook='%s'", $userbook), 'check-register');
  52.     $data = mysql_fetch_array($resources->mysql['check-register']);
  53.       // User registered, invalid invites points
  54.     if ($data['participante'] >= 1) {
  55.       $resources->logwrite($userbook, 'index (from invites - ERROR - user exists');
  56.       $resources->logfile[] = 'La invitacion es invalida, el usuario ya esta registrado';
  57.     }
  58.       // User not register, go on.
  59.     else {
  60.       $resources->logwrite($userbook, 'index (from invites '.$_GET['request_ids'].')');
  61.       $resources->logfile[] = 'Procesamos invitaciones';
  62.       $use_request = array_pop($all_request);
  63.         // Check all requests_id from database
  64.       $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');
  65.       $data = mysql_fetch_array($resources->mysql['get-request']);
  66.         // Update friend score and delete request_id from database
  67.       $resources->execute(sprintf("UPDATE puntuaciones SET incoming=incoming + 1 WHERE facebook='%s'", $data['facebook']), 'update-profile');
  68.       $resources->execute(sprintf("DELETE FROM reg_invite WHERE request_id='%s' AND user_invited='%s'", $use_request, $userbook), 'drop-request');
  69.       $facebook->api('/' . $use_request, 'DELETE');
  70.         // Store the friend id, for more score if this user wants play with us
  71.       $_SESSION['from-wall-id'] = $data['facebook'];
  72.     }
  73.       // Remove the other request_id
  74.     foreach ($all_request as $request) {
  75.       $resource->execute(sprintf("DELETE FROM reg_invite WHERE request_id='%s' AND user_invited='%s'", $request, $userbook), 'drop-request');
  76.       $facebook->api('/'.$request, 'DELETE');
  77.     }
  78.   } // if (isset($_GET['request_ids'])) {
  79.  
  80.     // Check the wall link
  81.   elseif (isset($_GET['fwid'])) {
  82.     $_GET['fwid'] = trim($_GET['fwid']);
  83.       // User join throght own wall...
  84.     if ($_GET['fwid'] == $userbook) {
  85.       $resources->logwrite($userbook, 'index (from '.$_GET['fwid'].' - user mismatch)');
  86.       $resources->logfile[] = 'Usuario intenta entrar desde su propio muro'; }
  87.       // User join from other wall
  88.     else {
  89.       $resources->logwrite($userbook, 'index (from '.$_GET['fwid'].')');
  90.         // Flood control, how many times user joins this day?
  91.       $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');
  92.       $data = mysql_fetch_array($resources->mysql['recuento']);
  93.         // Today, not score
  94.       if ($data['recuento'] >= 1) {
  95.         $resources->logwrite($userbook, 'index (from '.$_GET['fwid'].' - wall flood)');
  96.         $resources->logfile[] = 'Usuario ya ha entrado desde este muro'; }
  97.         // Never or yesterday, go on
  98.       elseif ($data['recuento'] == 0) {
  99.         $resources->logfile[] = 'Procesando entrada desde muro';
  100.         $resources->logwrite($userbook, 'index (from '.$_GET['fwid'].' - accept)');
  101.         $resources->execute(sprintf("INSERT INTO ref_wall VALUES('', '%s', '%s', '%s', '%s')", $userbook, $resources->session['address'], $_GET['fwid'], date('Y-m-d')));
  102.         $resources->execute(sprintf("UPDATE puntuaciones SET incoming=incoming + 1 WHERE facebook='%s'", $_GET['fwid']));
  103.         // Store the friend id, for more score if this user wants play with us
  104.         $_SESSION['from-wall-id'] = $_GET['fwid'];
  105.       }
  106.     }
  107.   } // elseif (isset($_GET['fwid'])) {
  108. }
  109.  
  110. // Join through bookmark
  111. elseif ($_GET['rel'] == 'bookmarks') {
  112.   $resources->logwrite($userbook, 'index (from-bookmark)'); }
  113.  
  114. // Join through? ok... he/she joins
  115. else {
  116.   $resources->logwrite($userbook, 'index'); }
  117.  
  118. // Get player numbers
  119. $resources->execute('SELECT COUNT(facebook) AS recuento FROM participantes', 'users-count');
  120. $users = mysql_fetch_array($resources->mysql['users-count']);
  121. $resources->assign('users-count', $users['recuento']);
  122.  
  123. // User in database?, show "score" button or "join" button
  124. $resources->execute(sprintf("SELECT COUNT(facebook) AS participante FROM participantes WHERE facebook='%s'", $userbook), 'is-player');
  125. $player = mysql_fetch_array($resources->mysql['is-player']);
  126. if ($player['participante'] >= 1) {
  127.   $resources->assign('action-url', 'puntuacion.php'); $resources->assign('action-msg', 'Tu puntuaci&#243;n'); }
  128. else {
  129.   $resources->assign('action-url', 'participa.php'); $resources->assign('action-msg', 'Participa'); }
  130.  
  131. // Debug, display user and other data
  132. $resources->assign('user-display', 'ID usuario en facebook '.$userbook);
  133. //require 'fakepath/debugmode.php';
  134.  
  135. // Show site
  136. $resources->display('index.html');
  137.  
  138. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement