Guest User

Untitled

a guest
Sep 28th, 2014
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.28 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <title>Backpack.tf Pricelist</title>
  5.         <meta charset="UTF-8">
  6.         <style type="text/css">
  7.             td {
  8.                 border: 1px solid #000;
  9.             }
  10.         </style>
  11.     </head>
  12.     <body>
  13.         <table>
  14.             <thead>
  15.                 <tr>
  16.                     <th>Item name</th>
  17.                     <th>Defindex</th>
  18.                     <th>Quality</th>
  19.                     <th>Tradable</th>
  20.                     <th>Craftable</th>
  21.                     <th>Priceindex</th>
  22.                     <th>Value</th>
  23.                 </tr>
  24.             </thead>
  25.            
  26.             <tbody>
  27.                 <?php
  28.                     $bptf_data = file_get_contents ('./bptf_api.json');
  29.                     $bptf_api = json_decode($bptf_data, true);
  30.                     $bptf_items = $bptf_api['response']['items'];
  31.                    
  32.                     foreach ($bptf_items as $item_name => $bptf_item) {
  33.                            
  34.                         /* Loop through the defindices for item, some items such
  35.                          * as the Shotgun and Rocket Launcher have multiple defindices */
  36.                         foreach ($bptf_item['defindex'] as $defindex) {
  37.                            
  38.                             // Loop through the qualities in the price
  39.                             foreach ($bptf_item['prices'] as $quality => $quality_price) {
  40.                            
  41.                                 // Loop through tradable/untradable values
  42.                                 foreach ($quality_price as $tradable => $tradable_price) {
  43.                                    
  44.                                     // Convert the tradable/untradable string to a boolean
  45.                                     $item_tradable = ($tradable == 'Tradable');
  46.                                    
  47.                                     // Loop through craftable/uncraftable values
  48.                                     foreach ($tradable_price as $craftable => $craftable_price) {
  49.                                        
  50.                                         // Convert the craftable/uncraftable string to a boolean
  51.                                         $item_craftable = ($craftable == 'Craftable');
  52.                                        
  53.                                         /* Loop through price indices. The price index is used for
  54.                                          * particle effects, and crate series number. In most cases
  55.                                          * this will be 0. */
  56.                                         foreach ($craftable_price as $priceindex => $item_price) {
  57.                                            
  58.                                             /* Finally we've looped through all the attributes!
  59.                                              * This is where price values and currencies are stored. */
  60.                                            
  61.                                             $currency = $item_price['currency'];
  62.                                             $value = $item_price['value'];
  63.                                             $value_high = $item_price['value_high'];
  64.                                            
  65.                                             echo "<tr>";
  66.                                             echo "<td>$item_name</td>";
  67.                                             echo "<td>$defindex</td>";
  68.                                             echo "<td>$quality</td>";
  69.                                             echo "<td>$item_tradable</td>";
  70.                                             echo "<td>$item_craftable</td>";
  71.                                             echo "<td>$priceindex</td>";
  72.                                             echo "<td>$value";
  73.                                             if ($value_high) { echo "-$value_high"; }
  74.                                             echo " $currency</td>";
  75.                                             echo "</tr>";
  76.                                         }
  77.                                     }
  78.                                 }
  79.                             }
  80.                         }
  81.                     }
  82.                 ?>
  83.             </tbody>
  84.         </table>
  85.     </body>
  86. </html>
Advertisement
Add Comment
Please, Sign In to add comment