-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGetBoard.php
More file actions
68 lines (61 loc) · 2.86 KB
/
GetBoard.php
File metadata and controls
68 lines (61 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
// Manialink called script - Get the players list to display on board
require(__DIR__."/includes/functions.php");
require(__DIR__."/class/class.cacheManager.php");
$cacheManager = new cacheManager();
// Check if client is maniaplanet
if(isClientName('maniaplanet')) {
// Get vars
$QuestId = intval(filter_input(INPUT_GET, 'QuestId'));
// Select players & quest info from cache if available and not expired, or db //
// Quest info is cached for 1h
$cacheId = "tm2ml_board_q".$QuestId."_info";
$QuestInfo = $cacheManager->get($cacheId);
$cacheHit = $cacheManager->getCacheHit();
if ($cacheManager->getCacheHit() == false) {
// Include database info
require(__DIR__."/includes/dbConfig.php");
$dbh = databaseConnect($dbHost, $dbUser, $dbPwd, $dbName); // Database Handler
$sql = "SELECT * FROM quests WHERE id = :questid"; // Single row res
$params = array(":questid" => $QuestId);
$qh = $dbh->prepare($sql);
$qexec = $qh->execute($params);
$QuestInfo = $qh->fetch(PDO::FETCH_ASSOC);
$qh = null;
$cacheManager->set($cacheId, $QuestInfo, 3600);
}
// Players list is cached 10 min.
$cacheId = "tm2ml_board_q".$QuestId."_players_list";
$playersList = $cacheManager->get($cacheId);
if ($cacheManager->getCacheHit() == false) {
if (!isset($dbh)) {
// Include database info
require(__DIR__."/includes/dbConfig.php");
$dbh = databaseConnect($dbHost, $dbUser, $dbPwd, $dbName); // Database Handler
}
$sql = "SELECT login, nickname, completion_time_best as bestTime, completion_time_first as firstTime FROM players WHERE quest_id = :questid AND status = 1 ORDER BY completion_date_first ASC";
$params = array(":questid" => $QuestId);
$qh = $dbh->prepare($sql);
$qexec = $qh->execute($params);
$players = $qh->fetchAll(PDO::FETCH_ASSOC);
$qh = null;
// Format the players' times
foreach ($players as $key => $player) {
$players[$key]["I_firstTime"] = $player["firstTime"];
$players[$key]["I_bestTime"] = $player["bestTime"];
$players[$key]["firstTime"] = gameTimeFormatted($player["firstTime"]);
$players[$key]["bestTime"] = gameTimeFormatted($player["bestTime"]);
}
// Return the results
$playersList = array("Players" => $players,
"QuestShortDesc" => ($QuestInfo["description_short"] != null) ? htmlentities($QuestInfo["description_short"], ENT_XML1) : "",
"QuestFullDesc" => ($QuestInfo["description_full"] != null) ? htmlentities($QuestInfo["description_full"], ENT_XML1) : "",
"QuestTitleList" => ($QuestInfo["board_head_sentence"] != null) ? htmlentities($QuestInfo["board_head_sentence"], ENT_XML1) : "",
"QuestTitleEmptyList" => ($QuestInfo["board_head_sentence_empty"] != null) ? htmlentities($QuestInfo["board_head_sentence_empty"], ENT_XML1) : ""
);
$cacheManager->set($cacheId, $playersList, 600);
}
echo json_encode($playersList);
} else {
echo "Sorry, something went wrong.";
}