Advertisement
tjone270

aliases.php Quake Alias API (Example)

Jul 17th, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.62 KB | None | 0 0
  1. <?php
  2.  
  3.   function quakeColourConvert($var) {
  4.     $var = "^7" . $var;
  5.     while(preg_match('/\^([0-7])/', $var)) {
  6.       foreach(array('black', 'red', 'lightgreen', 'yellow', 'blue', 'cyan', 'deeppink', 'white') as $num_color => $name_color) {
  7.         if (preg_match('/\^([0-7])(.*)\^([0-7])/', $var)) {
  8.           $var = preg_replace("#\^".$num_color."(.*)\^([0-7])#Usi", "<font color=\"".$name_color."\">$1</font>^$2", $var);
  9.         } else {
  10.           $var = preg_replace("#\^".$num_color."(.*)$#Usi", "<font color=\"".$name_color."\">$1</font>", $var);
  11.         }
  12.       }
  13.     }
  14.     return $var;
  15.   }
  16.  
  17.   if ($_SERVER["REQUEST_METHOD"] == "POST") {
  18.     $steam_id = $_POST["steam_id"];
  19.     $json = file_get_contents("http://master.thepurgery.com/api/aliases.php?steam_id=" . $steam_id);
  20.     $lines = explode("\n", $json);
  21.     $status = json_decode($lines[0], true);
  22.     if ($status[$steam_id] == "PRESENT") {
  23.       $aliases = (json_decode($lines[1], true));
  24.       $output = "<p>Aliases for ID " . $steam_id . ":</p><ul>";
  25.       foreach ($aliases as $alias) {
  26.         $output = $output . "<li>" . quakeColourConvert($alias) . "</li>";
  27.       }
  28.       $output = $output . "</ul><br /><br />";
  29.     } elseif ($status[$steam_id] == "ABSENT") {
  30.       $output = "No records found for ID " . $steam_id . ".<br /><br />";
  31.     } elseif ($status[$steam_id] == "PARAMETER INVALID (NOT 17 DIGITS LONG)") {
  32.       $output = "Invalid ID entered, not long enough (17 numbers long).<br /><br />";
  33.     } elseif ($status[$steam_id] == "PARAMETER INVALID (NOT OF TYPE INT)") {
  34.       $output = "Invalid ID entered, you've put letters or non-numbers in it.<br /><br />";
  35.     } elseif ($status[$steam_id] == "DB ERROR") {
  36.       $output = "Sorry, a system error occurred :(.<br /><br />";
  37.     }
  38.   }
  39. ?>
  40.  
  41. <!DOCTYPE html>
  42. <html lang="en">
  43.   <head>
  44.     <title>The Purgery - Aliases</title>
  45.     <style>
  46.       body {
  47.         background-color: grey;
  48.         margin: 0 auto;
  49.         width: 225px;
  50.         color: white;
  51.         text-align: center;
  52.         font-family: Helvetica;
  53.       }
  54.       .output {
  55.         margin-top: 75px;
  56.         padding: 10px;
  57.         border: 1px solid;
  58.         border-radius: 2px;
  59.         text-align: left;
  60.       }
  61.     </style>
  62.   </head>
  63.   <body>
  64.     <h1>The Pur<font color="lightblue">g</font>ery</h1>
  65.     <h2>Player Alias Lookup</h2>
  66.     <form method="post">
  67.       Steam64 ID:  <input type="text" name="steam_id">
  68.       <button type="submit">Submit</button>
  69.     </form>
  70.     <?php if (isset($output)) { ?>
  71.       <div class="output">
  72.         <p><?php echo($output); ?></p>
  73.       </div>
  74.     <?php } ?>
  75.   </body>
  76. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement