daily pastebin goal
71%
SHARE
TWEET

score.php

Worked Nov 9th, 2012 23 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 'src/Controllers/configure.php';
  21.  
  22. // Import and Instance Facebook PHP SDK
  23. require 'src/Controllers/facebook.php';
  24. $facebook = new Facebook(array('appId' => APP_ID, 'secret' => APP_PW, 'cookie' => true));
  25.  
  26. // Import and Instance resources
  27. require 'src/Controllers/resources.php';
  28. $resources = new Resources();
  29.  
  30. // Get Facebook user id
  31. try {
  32.   $userbook = $facebook->getUser();
  33.     // User in database?
  34.   $resources->execute(sprintf("SELECT COUNT(facebook) AS participante FROM participantes WHERE facebook='%s'", $userbook), 'is-player');
  35.   $data = mysql_fetch_array($resources->mysql['is-player']);
  36.  
  37.   if ($data['participante'] == 0) {
  38.     $resources->logwrite($userbook, 'puntuacion => REJECT (not found user in mysql)');
  39.     header('Location: index.php'); }
  40.  
  41.   $profile = $facebook->api('/'.$userbook.'?fields=username,picture');
  42. }
  43. catch (Exception $e) {
  44.   $resources->logwrite($userbook, 'puntuacion => REJECT (not found user)');
  45.   header('Location: index.php'); }
  46.  
  47. // log user into accesslog
  48. $resources->logwrite($userbook, 'puntuacion');
  49.  
  50. // Get user scores
  51. $resources->execute(sprintf("SELECT * FROM puntuaciones WHERE facebook='%s'", $userbook), 'user-scores');
  52. $scores = mysql_fetch_array($resources->mysql['user-scores']);
  53. $resources->assign('define-default', (int) SCORE_DEFAULT);
  54. $resources->assign('score-publish', $scores['publish']);
  55. $resources->assign('define-publish', (int) SCORE_PUBLISH);
  56. $resources->assign('score-incoming', $scores['incoming']);
  57. $resources->assign('define-incoming', (int) SCORE_FROM_WALL);
  58. $resources->assign('score-joined', $scores['joined']);
  59. $resources->assign('define-joined', (int) SCORE_JOINED);
  60. $score['total'] = ($scores['publish'] * (int) SCORE_PUBLISH) + ($scores['incoming'] * (int) SCORE_FROM_WALL) + ($scores['joined'] * (int) SCORE_JOINED) + (int) SCORE_DEFAULT;
  61. $resources->assign('score-total', $score['total']);
  62. $score['value'] = (($score['total'] / (int) SCORE_JUMPS) > (int) LIMIT_USER_SCORE) ? (int) LIMIT_USER_SCORE : ($score['total'] / (int) SCORE_JUMPS);
  63. $resources->assign('score-value', intval($score['value']));
  64.  
  65. // Assign vars in template
  66. $resources->assign('user-picture', $profile['picture']['data']['url']);
  67. $resources->assign('user-name', $profile['username']);
  68. $resources->assign('userbook', $userbook);
  69. $resources->assign('app-id', APP_ID);
  70. $resources->assign('limit-publish', LIMIT_PUBLISH);
  71. $resources->assign('limit-invite', LIMIT_INVITES);
  72.  
  73. // Enable or disable invite and publish buttons?
  74. $resources->execute(sprintf("SELECT COUNT(id) AS contador FROM ref_publish WHERE facebook='%s' AND register='%s'", $userbook, date('Y-m-d')), 'check-publish');
  75. $data = mysql_fetch_array($resources->mysql['check-publish']);
  76. if ($data['contador'] < (int) LIMIT_PUBLISH) {
  77.   $resources->assign('publish-button', '<a href="'.FACEBOOK_URL.'" id="publish_on_wall" onclick="return publish_on_wall();">Publicar en muro</a>'); }
  78. else {
  79.   $resources->assign('publish-button', ''); }
  80.  
  81. $resources->execute(sprintf("SELECT COUNT(id) as contador FROM ref_invite WHERE facebook='%s' AND register='%s'", $userbook, date('Y-m-d')), 'check-invites');
  82. $data = mysql_fetch_array($resources->mysql['check-invites']);
  83. if ($data['contador'] < (int) LIMIT_INVITES) {
  84.   $resources->assign('invite-button', '<a href="'.FACEBOOK_URL.'" id="invite_friends" onclick="return invite_friends();">Invitar amigos</a>'); }
  85. else {
  86.   $resources->assign('invite-button', ''); }
  87.  
  88. // Enable rank in config? Show then
  89. if (SHOW_RANK_PROFILE) {
  90.   $resources->execute('SELECT puntuaciones.facebook, SUM(puntuaciones.publish + puntuaciones.incoming + puntuaciones.joined + '.(int) SCORE_DEFAULT.') AS puntuacion, participantes.facebook, participantes.first_name, participantes.last_name FROM puntuaciones, participantes WHERE puntuaciones.facebook = participantes.facebook ORDER BY puntuacion LIMIT 0, 10', 'ranking');
  91.   while ($row = mysql_fetch_array($resources->mysql['ranking'])) {
  92.     $top[] = '<tr><td><img src="" alt="'.$row['first_name'].'"></td><td>'.$row['first_name'].' '.$row['last_name'].'</td><td>'.$row['puntuacion'].'</td></tr>';
  93.   }
  94.   $resources->assign('top-ten-button', '<a href="'.FACEBOOK_URL.'" class="cicle">Ver ranking</a>');
  95.   $resources->assign('top-ten-start', '');
  96.   $resources->assign('top-ten', '<table>'.implode('', $top).'</table>');
  97.   $resources->assign('top-ten-ends', '');
  98. }
  99. else {
  100.   $resources->assign('top-ten-button', '');
  101.   $resources->assign('top-ten-start', '<!--');
  102.   $resources->assign('top-ten', '');
  103.   $resources->assign('top-ten-ends', '-->');
  104. }
  105.  
  106. // Show site
  107. $resources->display('puntuacion.html');
  108.  
  109. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top