Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.04 KB | None | 0 0
  1. <style>
  2. <?php include 'stasi.css'; ?>
  3. </style>
  4. <?php
  5. require "predis/autoload.php";
  6. Predis\Autoloader::register();
  7.  
  8.  
  9. $MAXTID = 10000;
  10.  
  11. // since we connect to default setting localhost
  12. // and 6379 port there is no need for extra
  13. // configuration. If not then you can specify the
  14. // scheme, host and port to connect as an array
  15. // to the constructor.
  16. try {
  17.     $redis = new Predis\Client();
  18. /*
  19.     $redis = new PredisClient(array(
  20.         "scheme" => "tcp",
  21.         "host" => "127.0.0.1",
  22.         "port" => 6379));
  23. */
  24. //    echo "Successfully connected to Redis";
  25.  
  26. }
  27. catch (Exception $e) {
  28.     echo "Couldn't connected to Redis";
  29.     echo $e->getMessage();
  30. }
  31.  
  32. //stasi.php?uid=15&sortBy=dsc&limit=15
  33. //sortBy=ASC/DSC
  34.  
  35.  
  36. $username = isset($_GET['username']) ? substr($_GET['username'], 0, 32) : '';
  37. if ($username) {
  38.     $uid = intval($redis->zScore('username:uid', $username));
  39.     if (!$uid) {
  40.         header('HTTP/1.1 404 Gibtsnich');
  41.         echo "user $username not found";
  42.         exit;      
  43.     }
  44. }
  45.  
  46.  
  47.  
  48. if (!$uid) {
  49.     $uid = intval(isset($_GET['uid']) ? $_GET['uid'] : null);  
  50. }
  51. if (!$uid){
  52.     header('HTTP/1.1 400 Bad user, bad');
  53.     echo "missing numerical `uid` search parameter or string `username` search parameter";
  54.     exit;
  55. }
  56.  
  57. //Sucht den passenden Username zur uid, irrelevant bei direkter einbindung ins Spiel
  58. //$rqueryParam = "user:".$uid;
  59. //$username = $redis->hget ($rqueryParam, 'username');             
  60.  
  61. $arrayEventKeys = array();
  62. $arrayEventTitles = array();
  63. 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
  64. {
  65.     $rqueryParam = "topic:".+$i.":tags";
  66.     $arrayTags=$redis->SMEMBERS($rqueryParam); 
  67.     if (!empty($arrayTags) && in_array("event", $arrayTags))
  68.     {  
  69.         $arrayEventKeys[]=$i;
  70.         $rqueryParam = "topic:".$i;
  71.         $title = $redis->hget($rqueryParam, 'title');
  72.         $arrayEventTitles[]=$title;
  73.     }
  74. }
  75.  
  76. $arrayEvents= array_combine($arrayEventKeys, $arrayEventTitles);
  77. asort($arrayEvents);
  78.  
  79. $limit = $_GET['limit'];                                //Limitierung der angezeigten Einträge
  80. if (!is_numeric($limit) || $limit < 1)
  81.     $limit = sizeof($arrayEvents);  
  82.  
  83. $arrayEventsAttendance = array();
  84. $firstAttendanceFound = false;
  85.  
  86. foreach ($arrayEvents as $tid=> $title)
  87.     {
  88.         $rqueryParam = "tid:".$tid.":attendance:probability";
  89.         $arrayPlayersAttendance = $redis->ZRANGE($rqueryParam, '0', '100', 'WITHSCORES');
  90.         if (sizeof($arrayPlayersAttendance) <= 0)
  91.             $AttendanceNotProvided = true;
  92.         foreach ($arrayPlayersAttendance as $j => $probability)
  93.             {
  94.                 $AttendanceNotProvided = false;
  95.                 if ($j == $uid)
  96.                 {  
  97.                     $firstAttendanceFound = true;
  98.                     $arrayEventsAttendance[] = $probability;
  99.                     break;
  100.                 }
  101.                 else
  102.                     $AttendanceNotProvided = true;
  103.             }
  104.             if ($AttendanceNotProvided && $firstAttendanceFound)
  105.                 {
  106.                     $arrayEventsAttendance[] = -1;
  107.                 }
  108.             elseif (!$firstAttendanceFound)
  109.                 array_shift($arrayEvents);
  110.     }
  111.  
  112.  
  113. // PRINT AREA
  114.  
  115. $arrayEventsToPrint = array_combine($arrayEvents, $arrayEventsAttendance);
  116.  
  117. $sortBy = $_GET['sortBy']; 
  118. if (strcmp(strtoupper($sortBy),"ASC") == 0 )
  119.         ksort($arrayEventsToPrint);
  120. else
  121.         krsort($arrayEventsToPrint);
  122.  
  123.  
  124. $i = 0;
  125. foreach ($arrayEventsToPrint as $title=> $probability)
  126.     {
  127.         if ($i == $limit)
  128.             break;
  129.  
  130.         switch ($probability)
  131.             {
  132.                 case 0:
  133.                     echo '<div class="container">';
  134.                     echo '<span class="attending_nope">';
  135.                     echo '<i class="fa fa-fw fa-times-circle icon" style="height: 24px; color: rgb(201, 17, 6);"></i>';
  136.                     echo '</span>';
  137.                     echo '<span class="title">';
  138.                     print($title);
  139.                     echo '</span>';
  140.                     echo '</div>';
  141.                     break;
  142.                 case 0.5:
  143.                     echo '<div class="container">';
  144.                     echo '<span class="attending_maybe">';
  145.                     echo '<i class="fa fa-fw fa-question-circle icon" style="height: 24px; color: rgb(209, 141, 31);"></i>';
  146.                     echo '</span>';
  147.                     echo '<span class="title">';
  148.                     print($title);
  149.                     echo '</span>';
  150.                     echo '</div>';
  151.                     break;
  152.                 case 1:
  153.                     echo '<div class="container">';
  154.                     echo '<span class="attending_yes">';
  155.                     echo '<i class="fa fa-fw fa-check-circle icon" style="height: 24px; color: rgb(102, 170, 102);"></i>';
  156.                     echo '</span>';
  157.                     echo '<span class="title">';
  158.                     print($title);
  159.                     echo '</span>';
  160.                     echo '</div>';
  161.                     break;
  162.                 case -1:
  163.                     echo '<div class="container">';
  164.                     echo '<span class="attending_noreaction">';
  165.                     echo '<i class="fa fa-fw fa-circle-o icon" style="height: 24px; color: rgb(238, 238, 238);"></i>';
  166.                     echo '</span>';
  167.                     echo '<span class="title">';
  168.                     print($title);
  169.                     echo '</span>';
  170.                     echo '</div>';
  171.                     break;
  172.             }
  173.         echo "<br />";
  174.         $i++;
  175.     }
  176.  
  177. //DEBUG AREA
  178. //print(sizeof($arrayEvents));
  179. //echo "<br />";
  180. //print(sizeof($arrayEventsAttendance));
  181. //echo "<br />";
  182. //print_r($arrayEventsToPrint);
  183.  
  184.  
  185.  
  186.  
  187.  
  188. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement