case 'month': $time_lower = $now - 30 * 24 * 60 * 60; break; case 'week': $time_lower = $now - 7 * 24 * 60 * 60; break; case 'day': $time_lower = $now - 1 * 24 * 60 * 60; break; default: $time_lower = null; break; } $limit = get_input('limit', 10); $offset = get_input('offset', 0); $leaders = get_leaderboard($time_lower, $now, $limit, $offset); if (sizeof($leaders) > 0) { echo '<ul class="elgg-list">'; foreach ($leaders as $leader) { $icon = elgg_view_entity_icon($leader, 'small'); $link = elgg_view('output/url', array('text' => $leader->name, 'href' => $leader->getURL())); $badges = elgg_list_entities_from_relationship(array('relationship' => HYPEGAMEMECHANICS_CLAIMED_REL, 'relationship_guid' => $leader->guid, 'inverse_relationship' => false, 'limit' => 0, 'full_view' => false, 'list_type' => 'gallery', 'icon_size' => 'small', 'icon_user_status' => false, 'gallery_class' => 'gm-badge-gallery', 'item_class' => 'gm-badge-item')); $score = elgg_get_annotations(array('annotation_calculation' => 'sum', 'annotation_names' => 'gm_score', 'guids' => $leader->guid, 'annotation_created_time_lower' => $time_lower, 'annotation_created_time_upper' => $time_upper)); if ((int) $score < 0) { $score_str = "<span class=\"gm-score-negative\">{$score}</span>"; } else { $score_str = "<span class=\"gm-score-positive\">+{$score}</span>"; } echo '<li class="elgg-item">'; echo elgg_view_image_block($icon, $link . $badges, array('image_alt' => $score_str)); echo '</li>';
?> </a> </div> </body> <?php } else { if ($game_state > 8) { ?> <body style="background-image: url('/img/stars.jpeg'); background-size:cover; background-position: center; color: white;"> <script> var audio = new Audio('audio/end_theme.wav'); audio.play(); </script> <?php require_once 'score.php'; $leaderboard = get_leaderboard($link); $winner_points = reset($leaderboard); $winner_name = array_search($winner_points, $leaderboard); ?> <div class="welcome"> <h1 class="logo animated infinite pulse winner_name"><?php echo $winner_name; ?> </h1> <h2 class="winner_points"><?php echo $winner_points; ?> pts</h2> <a href="/start.php?state=reset" class="button button-white-stroke button-cta">Back to menu</a> </div> </body>
function push_score_update($pusher) { $pusher->trigger("client-channel", "score-update", get_leaderboard()); }
* @copyright 2015 François Allard */ error_reporting(E_ALL); ini_set("display_errors", 1); define("VERSION", 1.5); // The API version require "config.php"; if (isset($_GET['help'])) { // If help is called header("Content-Type: text/plain"); echo file_get_contents("help.txt"); // Show the help file } else { if (isset($_GET['leaderboard'])) { // If leaderboard is called $data = get_leaderboard(); if (isset($_GET['fmt'])) { header("Content-Type: text/plain"); echo json_encode(json_decode($data), JSON_PRETTY_PRINT); } else { header("Content-Type: application/json"); echo $data; } } else { if (isset($_GET['user']) && isset($_GET['console']) && !empty($_GET['user']) && !empty($_GET['console'])) { $hash = md5($_GET['console'] . "-" . $_GET['user']); // Create a unique hash for the entry $cacheFile = "cache/" . $hash; if (file_exists($cacheFile) && abs(filemtime($cacheFile) - time()) < 60 * 60) { // 60 seconds x 60 minutes = 1 hour // If the file exists and hasn't expired, just show the file
function build_individual_table() { $leaderboard_enteries = get_leaderboard(); $leaderboard_enteries_bonus_pts = get_leaderboard_bonus_pts(); $count = 0; // Create the table for individuals $board = '<h3>User Leaderboard</h3>'; $board .= '<table>'; $board .= '<tr><th>Place</th><th>Name</th><th>School</th><th>Score</th>'; // Fill with content foreach ($leaderboard_enteries as $entry) { $total_score = $entry->score; foreach ($leaderboard_enteries_bonus_pts as $bonus_entry) { if ($entry->name == $bonus_entry->name && $entry->school && $bonus_entry->school) { $total_score += $bonus_entry->score; } } $count += 1; $board .= '<tr class"entry">'; $board .= '<td>' . $count . '</td>'; $board .= '<td class"nam">' . $entry->name . '</td>'; $board .= '<td class"school">' . $entry->school . '</td>'; $board .= '<td class"point" id="user' . $entry->id . '_score" data-user-score="' . $total_score . '">' . $total_score . '</td>'; $board .= '</tr>'; } $board .= '</table>'; return $board; }