Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <style>
- <?php include 'stasi.css'; ?>
- </style>
- <?php
- require "predis/autoload.php";
- Predis\Autoloader::register();
- $MAXTID = 10000;
- // since we connect to default setting localhost
- // and 6379 port there is no need for extra
- // configuration. If not then you can specify the
- // scheme, host and port to connect as an array
- // to the constructor.
- try {
- $redis = new Predis\Client();
- /*
- $redis = new PredisClient(array(
- "scheme" => "tcp",
- "host" => "127.0.0.1",
- "port" => 6379));
- */
- // echo "Successfully connected to Redis";
- }
- catch (Exception $e) {
- echo "Couldn't connected to Redis";
- echo $e->getMessage();
- }
- //stasi.php?uid=15&sortBy=dsc&limit=15
- //sortBy=ASC/DSC
- $username = isset($_GET['username']) ? substr($_GET['username'], 0, 32) : '';
- if ($username) {
- $uid = intval($redis->zScore('username:uid', $username));
- if (!$uid) {
- header('HTTP/1.1 404 Gibtsnich');
- echo "user $username not found";
- exit;
- }
- }
- if (!$uid) {
- $uid = intval(isset($_GET['uid']) ? $_GET['uid'] : null);
- }
- if (!$uid){
- header('HTTP/1.1 400 Bad user, bad');
- echo "missing numerical `uid` search parameter or string `username` search parameter";
- exit;
- }
- //Sucht den passenden Username zur uid, irrelevant bei direkter einbindung ins Spiel
- //$rqueryParam = "user:".$uid;
- //$username = $redis->hget ($rqueryParam, 'username');
- $arrayEventKeys = array();
- $arrayEventTitles = array();
- for ($i = $MAXTID; $i >= 0; $i--) //WICHTIG: $i muss ggf. angepasst werden. Script wird nicht mehr zuverlässig funktionieren, wenn es mehr als $i-Threads im Forum gibt; Performancefresser
- {
- $rqueryParam = "topic:".+$i.":tags";
- $arrayTags=$redis->SMEMBERS($rqueryParam);
- if (!empty($arrayTags) && in_array("event", $arrayTags))
- {
- $arrayEventKeys[]=$i;
- $rqueryParam = "topic:".$i;
- $title = $redis->hget($rqueryParam, 'title');
- $arrayEventTitles[]=$title;
- }
- }
- $arrayEvents= array_combine($arrayEventKeys, $arrayEventTitles);
- asort($arrayEvents);
- $limit = $_GET['limit']; //Limitierung der angezeigten Einträge
- if (!is_numeric($limit) || $limit < 1)
- $limit = sizeof($arrayEvents);
- $arrayEventsAttendance = array();
- $firstAttendanceFound = false;
- foreach ($arrayEvents as $tid=> $title)
- {
- $rqueryParam = "tid:".$tid.":attendance:probability";
- $arrayPlayersAttendance = $redis->ZRANGE($rqueryParam, '0', '100', 'WITHSCORES');
- if (sizeof($arrayPlayersAttendance) <= 0)
- $AttendanceNotProvided = true;
- foreach ($arrayPlayersAttendance as $j => $probability)
- {
- $AttendanceNotProvided = false;
- if ($j == $uid)
- {
- $firstAttendanceFound = true;
- $arrayEventsAttendance[] = $probability;
- break;
- }
- else
- $AttendanceNotProvided = true;
- }
- if ($AttendanceNotProvided && $firstAttendanceFound)
- {
- $arrayEventsAttendance[] = -1;
- }
- elseif (!$firstAttendanceFound)
- array_shift($arrayEvents);
- }
- // PRINT AREA
- $arrayEventsToPrint = array_combine($arrayEvents, $arrayEventsAttendance);
- $sortBy = $_GET['sortBy'];
- if (strcmp(strtoupper($sortBy),"ASC") == 0 )
- ksort($arrayEventsToPrint);
- else
- krsort($arrayEventsToPrint);
- $i = 0;
- foreach ($arrayEventsToPrint as $title=> $probability)
- {
- if ($i == $limit)
- break;
- switch ($probability)
- {
- case 0:
- echo '<div class="container">';
- echo '<span class="attending_nope">';
- echo '<i class="fa fa-fw fa-times-circle icon" style="height: 24px; color: rgb(201, 17, 6);"></i>';
- echo '</span>';
- echo '<span class="title">';
- print($title);
- echo '</span>';
- echo '</div>';
- break;
- case 0.5:
- echo '<div class="container">';
- echo '<span class="attending_maybe">';
- echo '<i class="fa fa-fw fa-question-circle icon" style="height: 24px; color: rgb(209, 141, 31);"></i>';
- echo '</span>';
- echo '<span class="title">';
- print($title);
- echo '</span>';
- echo '</div>';
- break;
- case 1:
- echo '<div class="container">';
- echo '<span class="attending_yes">';
- echo '<i class="fa fa-fw fa-check-circle icon" style="height: 24px; color: rgb(102, 170, 102);"></i>';
- echo '</span>';
- echo '<span class="title">';
- print($title);
- echo '</span>';
- echo '</div>';
- break;
- case -1:
- echo '<div class="container">';
- echo '<span class="attending_noreaction">';
- echo '<i class="fa fa-fw fa-circle-o icon" style="height: 24px; color: rgb(238, 238, 238);"></i>';
- echo '</span>';
- echo '<span class="title">';
- print($title);
- echo '</span>';
- echo '</div>';
- break;
- }
- echo "<br />";
- $i++;
- }
- //DEBUG AREA
- //print(sizeof($arrayEvents));
- //echo "<br />";
- //print(sizeof($arrayEventsAttendance));
- //echo "<br />";
- //print_r($arrayEventsToPrint);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement