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 'src/Controllers/configure.php';
- // Import and Instance Facebook PHP SDK
- require 'src/Controllers/facebook.php';
- $facebook = new Facebook(array('appId' => APP_ID, 'secret' => APP_PW, 'cookie' => true));
- // Import and Instance resources
- require 'src/Controllers/resources.php';
- $resources = new Resources();
- // Get Facebook user id
- try {
- $userbook = $facebook->getUser();
- // User in database?
- $resources->execute(sprintf("SELECT COUNT(facebook) AS participante FROM participantes WHERE facebook='%s'", $userbook), 'is-player');
- $data = mysql_fetch_array($resources->mysql['is-player']);
- if ($data['participante'] == 0) {
- $resources->logwrite($userbook, 'puntuacion => REJECT (not found user in mysql)');
- header('Location: index.php'); }
- $profile = $facebook->api('/'.$userbook.'?fields=username,picture');
- }
- catch (Exception $e) {
- $resources->logwrite($userbook, 'puntuacion => REJECT (not found user)');
- header('Location: index.php'); }
- // log user into accesslog
- $resources->logwrite($userbook, 'puntuacion');
- // Get user scores
- $resources->execute(sprintf("SELECT * FROM puntuaciones WHERE facebook='%s'", $userbook), 'user-scores');
- $scores = mysql_fetch_array($resources->mysql['user-scores']);
- $resources->assign('define-default', (int) SCORE_DEFAULT);
- $resources->assign('score-publish', $scores['publish']);
- $resources->assign('define-publish', (int) SCORE_PUBLISH);
- $resources->assign('score-incoming', $scores['incoming']);
- $resources->assign('define-incoming', (int) SCORE_FROM_WALL);
- $resources->assign('score-joined', $scores['joined']);
- $resources->assign('define-joined', (int) SCORE_JOINED);
- $score['total'] = ($scores['publish'] * (int) SCORE_PUBLISH) + ($scores['incoming'] * (int) SCORE_FROM_WALL) + ($scores['joined'] * (int) SCORE_JOINED) + (int) SCORE_DEFAULT;
- $resources->assign('score-total', $score['total']);
- $score['value'] = (($score['total'] / (int) SCORE_JUMPS) > (int) LIMIT_USER_SCORE) ? (int) LIMIT_USER_SCORE : ($score['total'] / (int) SCORE_JUMPS);
- $resources->assign('score-value', intval($score['value']));
- // Assign vars in template
- $resources->assign('user-picture', $profile['picture']['data']['url']);
- $resources->assign('user-name', $profile['username']);
- $resources->assign('userbook', $userbook);
- $resources->assign('app-id', APP_ID);
- $resources->assign('limit-publish', LIMIT_PUBLISH);
- $resources->assign('limit-invite', LIMIT_INVITES);
- // Enable or disable invite and publish buttons?
- $resources->execute(sprintf("SELECT COUNT(id) AS contador FROM ref_publish WHERE facebook='%s' AND register='%s'", $userbook, date('Y-m-d')), 'check-publish');
- $data = mysql_fetch_array($resources->mysql['check-publish']);
- if ($data['contador'] < (int) LIMIT_PUBLISH) {
- $resources->assign('publish-button', '<a href="'.FACEBOOK_URL.'" id="publish_on_wall" onclick="return publish_on_wall();">Publicar en muro</a>'); }
- else {
- $resources->assign('publish-button', ''); }
- $resources->execute(sprintf("SELECT COUNT(id) as contador FROM ref_invite WHERE facebook='%s' AND register='%s'", $userbook, date('Y-m-d')), 'check-invites');
- $data = mysql_fetch_array($resources->mysql['check-invites']);
- if ($data['contador'] < (int) LIMIT_INVITES) {
- $resources->assign('invite-button', '<a href="'.FACEBOOK_URL.'" id="invite_friends" onclick="return invite_friends();">Invitar amigos</a>'); }
- else {
- $resources->assign('invite-button', ''); }
- // Enable rank in config? Show then
- if (SHOW_RANK_PROFILE) {
- $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');
- while ($row = mysql_fetch_array($resources->mysql['ranking'])) {
- $top[] = '<tr><td><img src="" alt="'.$row['first_name'].'"></td><td>'.$row['first_name'].' '.$row['last_name'].'</td><td>'.$row['puntuacion'].'</td></tr>';
- }
- $resources->assign('top-ten-button', '<a href="'.FACEBOOK_URL.'" class="cicle">Ver ranking</a>');
- $resources->assign('top-ten-start', '');
- $resources->assign('top-ten', '<table>'.implode('', $top).'</table>');
- $resources->assign('top-ten-ends', '');
- }
- else {
- $resources->assign('top-ten-button', '');
- $resources->assign('top-ten-start', '<!--');
- $resources->assign('top-ten', '');
- $resources->assign('top-ten-ends', '-->');
- }
- // Show site
- $resources->display('puntuacion.html');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement