Advertisement
Guest User

index.php

a guest
Mar 29th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.15 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4.  
  5. ================================================
  6.  
  7. LEFT 4 DEAD AND LEFT 4 DEAD 2 PLAYER RANK
  8.  
  9. Copyright (c) 2010 Mikko Andersson
  10.  
  11. ================================================
  12.  
  13. Index / Players Online page - "index.php"
  14.  
  15. ================================================
  16.  
  17. */
  18.  
  19.  
  20.  
  21. // Include the primary PHP functions file
  22.  
  23. include("./common.php");
  24.  
  25.  
  26.  
  27. // Load outer template
  28.  
  29. $tpl = new Template("./templates/" . $templatefiles['layout.tpl']);
  30.  
  31.  
  32.  
  33. $result = mysql_query("SELECT * FROM " . $mysql_tableprefix . "players WHERE lastontime >= '" . intval(time() - 300) . "' ORDER BY " . $TOTALPOINTS . " DESC");
  34.  
  35. $playercount = number_format(mysql_num_rows($result));
  36.  
  37.  
  38.  
  39. setcommontemplatevariables($tpl);
  40.  
  41.  
  42.  
  43. $tpl->set("title", "Players Online"); // Window title
  44.  
  45. $tpl->set("page_heading", "Players Online - " . $playercount); // Page header
  46.  
  47. if ($stats_refreshinterval > 0)
  48.  
  49.     $tpl->set("statspagemeta", "<meta http-equiv=\"refresh\" content=\"" . $stats_refreshinterval . "\">\n");
  50.  
  51. else
  52.  
  53.     $tpl->set("statspagemeta", "");
  54.  
  55.  
  56.  
  57. if (mysql_error()) {
  58.  
  59.   $output = "<p><b>MySQL Error:</b> " . mysql_error() . "</p>\n";
  60.  
  61.  
  62.  
  63. } else {
  64.  
  65.   $arr_online = array();
  66.  
  67.   $stats = new Template("./templates/" . $templatefiles['online.tpl']);
  68.  
  69.  
  70.  
  71.     $googlemaps = "";
  72.  
  73.     $googlemaps_markercounter = 0;
  74.  
  75.     $googlemaps_servers = 0;
  76.  
  77.     $googlemaps_displayall = $googlemaps_showplayersonlinecount <= 0;
  78.  
  79.  
  80.  
  81.     if ($showplayerflags && $showplayercity && strlen($googlemaps_apikey) > 0)
  82.  
  83.     {
  84.  
  85.         $googlemaps = "http://maps.googleapis.com/maps/api/staticmap?";
  86.  
  87.  
  88.  
  89.         $locations = count($game_locations);
  90.  
  91.         if ($locations == 1)
  92.  
  93.         {
  94.  
  95.             $site_lon = $game_locations[0]["lon"];
  96.  
  97.             $site_lat = $game_locations[0]["lat"];
  98.  
  99.  
  100.  
  101.             if ($site_lon || $site_lat)
  102.  
  103.             {
  104.  
  105.                 $googlemaps_servers = 1;
  106.  
  107.                 $googlemaps .= "&markers=color:red|label:S|" . $site_lat . "," . $site_lon;
  108.  
  109.             }
  110.  
  111.         }
  112.  
  113.         else if ($locations > 1)
  114.  
  115.         {
  116.  
  117.             $servers_counter = 0;
  118.  
  119.  
  120.  
  121.             foreach ($game_locations as $game_location)
  122.  
  123.             {
  124.  
  125.                 $site_lon = $game_location["lon"];
  126.  
  127.                 $site_lat = $game_location["lat"];
  128.  
  129.  
  130.  
  131.                 $servers_counter++;
  132.  
  133.  
  134.  
  135.                 if ($site_lon || $site_lat)
  136.  
  137.                 {
  138.  
  139.                     $googlemaps_servers++;
  140.  
  141.                     $googlemaps .= "&markers=color:red|label:" . ($servers_counter > 9 ? "S" : $servers_counter) . "|" . $site_lat . "," . $site_lon;
  142.  
  143.                 }
  144.  
  145.             }
  146.  
  147.         }
  148.  
  149.     }
  150.  
  151.  
  152.  
  153.   $i = 1;
  154.  
  155.   while ($row = mysql_fetch_array($result)) {
  156.  
  157.     if ($row['lastontime'] > time()) $row['lastontime'] = time();
  158.  
  159.  
  160.  
  161.         $lastgamemode = "Unknown";
  162.  
  163.         switch ($row['lastgamemode'])
  164.  
  165.         {
  166.  
  167.             case 0:
  168.  
  169.                 $lastgamemode = "Coop";
  170.  
  171.                 break;
  172.  
  173.             case 1:
  174.  
  175.                 $lastgamemode = "Versus";
  176.  
  177.                 break;
  178.  
  179.             case 2:
  180.  
  181.                 $lastgamemode = "Realism";
  182.  
  183.                 break;
  184.  
  185.             case 3:
  186.  
  187.                 $lastgamemode = "Survival";
  188.  
  189.                 break;
  190.  
  191.             case 4:
  192.  
  193.                 $lastgamemode = "Scavenge";
  194.  
  195.                 break;
  196.  
  197.             case 5:
  198.  
  199.                 $lastgamemode = "Realism&nbsp;Versus";
  200.  
  201.                 break;
  202.  
  203.             case 6:
  204.  
  205.                 $lastgamemode = "Mutation";
  206.  
  207.                 break;
  208.  
  209.         }
  210.  
  211.  
  212.  
  213.         $player_ip = $row['ip'];
  214.  
  215.  
  216.  
  217.         $avatarimg = "";
  218.  
  219.        
  220.  
  221.         if ($players_avatars_show && $players_online_avatars_show)
  222.  
  223.         {
  224.  
  225.             $avatarimgurl = getplayeravatar($row['steamid'], "icon");
  226.  
  227.            
  228.  
  229.             if($avatarimgurl)
  230.  
  231.             {
  232.  
  233.                 $avatarimg = "<img src=\"" . $avatarimgurl . "\" border=\"0\">";
  234.  
  235.             }
  236.  
  237.         }
  238.  
  239.        
  240.  
  241.         $playername = ($showplayerflags ? $ip2c->get_country_flag($player_ip) : "") . "<a href=\"player.php?steamid=" . $row['steamid']. "\">" . htmlentities($row['name'], ENT_COMPAT, "UTF-8") . "</a>";
  242.  
  243.        
  244.  
  245.         if ($avatarimg)
  246.  
  247.         {
  248.  
  249.             $playername = "<table border=0 cellspacing=0 cellpadding=0><tr><td>" . $avatarimg . "</td><td>&nbsp;" . $playername . "</td></tr></table>";
  250.  
  251.         }
  252.  
  253.  
  254.  
  255.     $line = createtablerowtooltip($row, $i);
  256.  
  257.     $line .= "<td>" . $playername . "</td>";
  258.  
  259.     $line .= "<td>" . gettotalpoints($row) . "</td><td>" . $lastgamemode . "</td><td>" . gettotalplaytime($row) . "</td></tr>\n";
  260.  
  261.  
  262.  
  263.     $arr_online[] = $line;
  264.  
  265.  
  266.  
  267.         if (strlen($googlemaps) > 0 && ($googlemaps_displayall || $googlemaps_markercounter < $googlemaps_showplayersonlinecount))
  268.  
  269.         {
  270.  
  271.             $country_code = strtolower($ip2c->get_country_code($player_ip));
  272.  
  273.  
  274.  
  275.             if (strlen($country_code) > 0 && $country_code != "xx" && $country_code != "int")
  276.  
  277.             {
  278.  
  279.                 $player_lat = $ip2c->get_latitude($player_ip);
  280.  
  281.                 $player_lon = $ip2c->get_longitude($player_ip);
  282.  
  283.  
  284.  
  285.                 $googlemaps_markercounter++;
  286.  
  287.                 $googlemaps .= "&markers=color:blue|label:" . ($i > 9 ? "P" : $i) . "|" . $player_lat . "," . $player_lon;
  288.  
  289.             }
  290.  
  291.         }
  292.  
  293.  
  294.  
  295.     $i++;
  296.  
  297.   }
  298.  
  299.  
  300.  
  301.   if (count($arr_online) == 0) $arr_online[] = "<tr><td colspan=\"4\" align=\"center\">There are no players online</td</tr>\n";
  302.  
  303.  
  304.  
  305.     $stats->set("online", $arr_online);
  306.  
  307.     $output = $stats->fetch("./templates/" . $templatefiles['online.tpl']);
  308.  
  309.  
  310.  
  311.     if (strlen($googlemaps) > 0 && ($googlemaps_markercounter > 0 || $googlemaps_servers > 0))
  312.  
  313.     {
  314.  
  315.         if ($googlemaps_markercounter == 1 && $googlemaps_servers == 0 || $googlemaps_markercounter == 0 && $googlemaps_servers == 1)
  316.  
  317.             $googlemaps .= "&zoom=" . $googlemaps_playersonline_zoom;
  318.  
  319.  
  320.  
  321.         $googlemaps .= $googlemaps_playersonline_addparam;
  322.  
  323.  
  324.  
  325.         $output .= "<br><br><img src=\"" . $googlemaps . "\">";
  326.  
  327.     }
  328.  
  329.    
  330.  
  331.     /*
  332.  
  333.     // This part of the code adds a chatlog window in your "frontpage" (Players Online)
  334.  
  335.     // Download Extended Chat Log from here: http://forums.alliedmods.net/showthread.php?t=91331
  336.  
  337.     // Download Custom Player Stats modified Extended Chat Log PHP -page from here: http://forums.alliedmods.net/showthread.php?p=1365806#post1365806
  338.  
  339.     $output .= "
  340.  
  341.         <br><br>
  342.  
  343.         <iframe src =\"../chatlog/index_stats.php\" width=\"600\" height=\"200\" scrolling=\"no\" style=\"border-width:1px; border-style:solid; border-color:#FFCC33;\">
  344.  
  345.           <p>Your browser does not support iframes.</p>
  346.  
  347.         </iframe>
  348.  
  349.     ";
  350.  
  351.     */
  352.  
  353. }
  354.  
  355.  
  356.  
  357. $tpl->set('body', trim($output));
  358.  
  359.  
  360.  
  361. // Output the top 10
  362.  
  363. $tpl->set("top10", $top10);
  364.  
  365.  
  366.  
  367. // Output the MOTD
  368.  
  369. $tpl->set("motd_message", $layout_motd);
  370.  
  371.  
  372.  
  373. // Print out the page!
  374.  
  375. echo $tpl->fetch("./templates/" . $templatefiles['layout.tpl']);
  376.  
  377. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement