public function prepare()
 {
     global $schema;
     $this->template = "all_items";
     $this->tab = "all_items";
     $this->title = "All TF2 Items";
     $this->head = '<script>(function($){$.fn.unveil=function(threshold,callback){var $w=$(window),th=threshold||0,retina=window.devicePixelRatio>1,attrib=retina?"data-src-retina":"data-src",images=this,loaded;this.one("unveil",function(){var source=this.getAttribute(attrib);source=source||this.getAttribute("data-src");if(source){this.setAttribute("src",source);if(typeof callback==="function")callback.call(this);}});function unveil(){var inview=images.filter(function(){var $e=$(this),wt=$w.scrollTop(),wb=wt+$w.height(),et=$e.offset().top,eb=et+$e.height();return eb>=wt-th&&et<=wb+th;});loaded=inview.trigger("unveil");images=images.not(loaded);}$w.scroll(unveil);$w.resize(unveil);unveil();return this;};})(window.jQuery);$(document).ready(function(){$("img").unveil(166);});</script>';
     $b = new backpack(false);
     foreach ($schema['items'] as $i) {
         $items[] = $b->get_item($i);
     }
     $this->params['items'] = $items;
 }
 public function prepare()
 {
     $this->template = "usercp";
     $this->title = "User control panel";
     $admin = IsUserAdmin();
     if ($admin) {
         global $db;
         if ($this->request[0] == 'update_schema') {
             require_once 'classes/backpack.php';
             backpack::update_schema();
             $this->params['success'] = 'Schema updated! Have a nice day <3';
         } else {
             if ($this->request[0] == 'purge_cache') {
                 require_once 'classes/cache.php';
                 cache::clean();
                 $this->params['success'] = 'Memcached cache purged! Have a nice day <3';
             }
         }
         /*else if($this->request[0] == 'valve_maps')
         		{
         			global $list;
         			$maps = explode("\n",$list);
         			foreach($maps as $map)
         			{
         				
         				list($m, $ext) = explode(".",trim($map));
         				//echo $m;
         				$db->query("UPDATE tf2_maps SET official=1 where name=%s",array($m));
         			}
         			$this->params['success'] = 'Maps valveified!';
         		
         		}*/
     }
     $this->params['admin'] = $admin;
 }
 public function prepare()
 {
     global $schema, $settings;
     $this->template = "paints";
     $this->tab = 'item';
     $this->title = "Paint statistics";
     $sort_table = array('total' => 'painted', 'owned' => 'owned', 'used' => 'usage');
     $b = new backpack(false);
     $sortkey = 'painted';
     if ($this->request['sort'] && array_key_exists($this->request['sort'], $sort_table)) {
         $sortkey = $sort_table[$this->request['sort']];
         $this->params['sort'][$this->request['sort']] = 'selected';
     } else {
         $this->params['sort']['total'] = 'selected';
     }
     $item_stats = cache::Memcached()->get('item_stats');
     if ($item_stats === false) {
         $json = file_get_contents($settings['cache']['folder'] . 'item_stats.json');
         $item_stats = json_decode($json, true);
         cache::Memcached()->set('item_stats', $item_stats, time() + 60 * 15);
     }
     $total_paints = $item_stats['total_colors'];
     $total_items = $item_stats['total_items'];
     foreach ($item_stats['colors'] as $c => $p) {
         $id = get_paint_by_color($c);
         if (!$id) {
             continue;
         }
         //printf("Color: %s, id: %s <br />",$c, $id);
         $s = $item_stats['items'][$id];
         $si = $schema['items'][$id];
         $i = $b->get_item($si);
         $owned = $s['total'] / $item_stats['total_players'];
         //printf("Owned: %s, Total: %s<br>", $s['total'], $item_stats['total_players']);
         $paint = array('total' => $p, 'color' => $c, 'painted' => $p / $total_paints, 'owned' => ($s['total'] + $p) / $item_stats['total_players'], 'usage' => $p / ($s['total'] + $p));
         $key = (string) intval($paint[$sortkey] * 10000);
         while ($paints[$key] > 0) {
             $key++;
         }
         //printf("%s -> %s: %s<br />",$paint[$sortkey], $key, $i['name']);
         $paints[$key] = array_merge($paint, $i);
     }
     $this->params['paints'] = $paints;
     krsort($this->params['paints']);
     $this->params['profiles'] = $item_stats['total_players'];
     $this->params['time'] = cache::date('item_stats.json');
 }
 public function prepare()
 {
     global $schema;
     $this->template = "crates";
     $this->tab = 'item';
     $b = new backpack(false);
     $json = cache::read('item_stats_luigi.json');
     $crate_stats = json_decode($json, true);
     foreach ($crate_stats['crate_items'] as $series => $items) {
         foreach ($items as $defindex => $drops) {
             $si = $schema['items'][$defindex];
             $i = $b->get_item($si);
             //var_dump($i);
             $i['drop_rate'] = $drops / $crate_stats['crate_totals'][$series];
             $crates[$series]['items'][] = $i;
             $crates[$series]['series'] = $series;
             $crates[$series]['sample'] = $crate_stats['crate_totals'][$series];
         }
     }
     $this->title = "Crate statistics";
     $this->params['crates'] = $crates;
     $this->params['stats'] = $s;
 }
 public function prepare()
 {
     global $schema, $base_weapons, $slot_order, $settings;
     $this->template = "weapons";
     $this->tab = 'item';
     $this->title = 'Weapon statistics';
     $this->canonical = 'http://tf2stats.net/weapons/';
     $sort_table = array('owned' => 'owned', 'equipped' => 'equipped', 'own_equip' => 'owned_equipped_key');
     $b = new backpack(false);
     $sortkey = 'owned';
     if ($this->request['sort'] && array_key_exists($this->request['sort'], $sort_table)) {
         $sortkey = $sort_table[$this->request['sort']];
         $this->params['sort'][$this->request['sort']] = 'selected';
     } else {
         $this->params['sort']['owned'] = 'selected';
     }
     $item_stats = cache::Memcached()->get('item_stats');
     if ($item_stats === false) {
         $json = file_get_contents($settings['cache']['folder'] . 'item_stats.json');
         $item_stats = json_decode($json, true);
         cache::Memcached()->set('item_stats', $item_stats, time() + 60 * 15);
     }
     // First. build a class->slot->items[] array for our stats
     foreach ($item_stats['items'] as $defindex => $s) {
         // Skip tokens
         if ($defindex > 5000) {
             continue;
         }
         $si = $schema['items'][$defindex];
         if (in_array($si['item_slot'], array('primary', 'secondary', 'melee', 'pda', 'pda2'))) {
             $i = $b->get_item($si);
             $i['owned'] = $s['unique_total'] / $item_stats['total_players'];
             //if($i['owned'] > 1)
             //	$i['owned'] = 1;
             if (!empty($i['used_by_classes'])) {
                 foreach ($i['used_by_classes'] as $c) {
                     $ci = class_to_int($c);
                     $i['equipped'] = $s['equipped'][$ci] / $item_stats['total_players'];
                     $i['owned_equipped'] = $s['equipped'][$ci] / $s['unique_total'];
                     $i['owned_equipped_key'] = $i['owned_equipped'] * 1000;
                     $key = $i[$sortkey];
                     while ($weapons[$c][$si['item_slot']][(string) $key] > 0) {
                         $key += 0.001;
                     }
                     $weapons[$c][$si['item_slot']][(string) $key] = $i;
                     $weapon_totals[$c][$si['item_slot']] += $i['equipped'];
                 }
             }
         }
     }
     // Now go through and combine the cosmetics defined above, as well as determine
     // stats for the 'base' weapon since valve's solution is to leave the slot
     // blank if we're using one
     foreach ($base_weapons as $class => $slots) {
         foreach ($slots as $slot => $s) {
             $si = $schema['items'][$s['base']];
             $i = $b->get_item($si);
             //$i['owned'] = ($s['total'] / $item_stats['total_players']);
             //if($i['owned'] > 1)
             //	$i['owned'] = 1;
             //$i['equipped'] = ($s['total_equipped'] / $item_stats['total_players']);
             //$i['owned_equipped'] = ($s['total_equipped'] / $s['total']);
             $i['equipped'] = 1 - $weapon_totals[$class][$slot];
             $i['owned'] = 1;
             //echo $i['equipped'];
             if (!$s['add']) {
                 continue;
             }
             foreach ($s['add'] as $a) {
                 foreach ($weapons[$class] as $csl => $t) {
                     foreach ($weapons[$class][$csl] as $k => $w) {
                         if ($w['defindex'] == $a) {
                             $sl = $csl;
                             $other = $w;
                             $key = $k;
                             break;
                         }
                     }
                 }
                 $i['equipped'] += $other['equipped'];
                 // Fix that silly rounding error causing the
                 // pipe launcher to be used by 100.01%
                 if ($i['equipped'] > 1) {
                     $i['equipped'] = 1;
                 }
                 $weapons[$class][$sl][$key]['hide'] = true;
             }
             $i['owned_equipped'] = $i['equipped'];
             $i['owned_equipped_key'] = $i['owned_equipped'] * 1000;
             $key = $i[$sortkey];
             while ($weapons[$class][$slot][(string) $key]) {
                 $key += 0.001;
             }
             $weapons[$class][$slot][(string) $key] = $i;
             unset($key);
         }
     }
     // finally, sort the results
     // Instead of wasting time sorting arrays and subarrays we can just
     // reconstruct a new array in the order of the slot array above
     // and only sort the bits that really need it.
     foreach ($base_weapons as $class => $slots) {
         foreach ($slots as $slot => $info) {
             $out[$class][$slot] = $weapons[$class][$slot];
             krsort($out[$class][$slot]);
         }
     }
     $this->params['profiles'] = $item_stats['total_players'];
     $this->params['time'] = cache::date('item_stats.json');
     $this->params['weapons'] = $out;
 }
 public function prepare()
 {
     global $schema, $settings;
     $this->template = "cosmetic";
     $this->tab = 'item';
     $this->title = 'Cosmetic item statistics';
     $this->canonical = 'http://tf2stats.net/misc_items/';
     $sort_table = array('owned' => 'total', 'equipped' => 'total_equipped', 'own_equip' => 'owned_equipped');
     $b = new backpack(false);
     $sortkey = 'total';
     if ($this->request['sort'] && array_key_exists($this->request['sort'], $sort_table)) {
         $sortkey = $sort_table[$this->request['sort']];
         $this->params['sort'][$this->request['sort']] = 'selected';
     } else {
         $this->params['sort']['owned'] = 'selected';
     }
     $item_stats = cache::Memcached()->get('item_stats');
     if ($item_stats === false) {
         $json = file_get_contents($settings['cache']['folder'] . 'item_stats.json');
         $item_stats = json_decode($json, true);
         cache::Memcached()->set('item_stats', $item_stats, time() + 60 * 15);
     }
     foreach ($item_stats['items'] as $defindex => $s) {
         if (in_array($defindex, $settings['items']['ignore'])) {
             continue;
         }
         $si = $schema['items'][$defindex];
         if ($si['item_slot'] == 'misc') {
             $i = $b->get_item($si);
             $i['owned'] = $s['total'] / $item_stats['total_players'];
             if ($i['owned'] > 1) {
                 $i['owned'] = 1;
             }
             $i['equipped'] = $s['total_equipped'] / $item_stats['total_players'];
             $i['owned_equipped'] = $s['total_equipped'] / $s['total'];
             $s['owned_equipped'] = intval($s['total_equipped'] / $s['total'] * 1000);
             // Colors
             arsort($s['colors']);
             foreach ($s['colors'] as $c => $num) {
                 $html = dechex($c);
                 if ($html === '0') {
                     continue;
                 }
                 //$html = '914c3f';
                 $key = $num;
                 while ($i['colors'][$key] > 0) {
                     $key++;
                 }
                 $i['colors'][$key] = array('color' => $html, 'num' => $num / $s['total_colored']);
             }
             if (count($i['used_by_classes']['class']) < 1) {
                 for ($c = 1; $c <= 9; $c++) {
                     $num = $s['equipped'][$c];
                     if ($s['total_equipped'] > 0) {
                         $i['classes'][] = array('class' => int_to_class($c), 'id' => $c, 'num' => $num / $s['total_equipped']);
                     }
                 }
             }
             $key = $s[$sortkey];
             while ($this->params['hats'][$key] > 0) {
                 $key++;
             }
             $this->params['hats'][$key] = $i;
         }
     }
     krsort($this->params['hats']);
 }
예제 #7
0
 public function prepare()
 {
     global $schema, $asset_info, $settings;
     $this->template = "item";
     $this->tab = 'item';
     $b = new backpack(false);
     $item_stats = cache::Memcached()->get('item_stats');
     if ($item_stats === false) {
         $json = file_get_contents($settings['cache']['folder'] . 'item_stats.json');
         $item_stats = json_decode($json, true);
         cache::Memcached()->set('item_stats', $item_stats, time() + 60 * 15);
     }
     cache::inc('tf2_item_info.php');
     $defindex = $this->request[1];
     $url_name = $this->request[0];
     $s = $item_stats['items'][$defindex];
     $si = $schema['items'][$defindex];
     $info = $asset_info[$defindex];
     //var_dump($info);
     $i = $b->get_item($si);
     $this->canonical = sprintf('http://tf2stats.net/item/%s/%s/', $i['name_url'], $i['defindex']);
     $i['owned'] = $s['unique_total'] / $item_stats['total_players'];
     $i['equipped'] = $s['total_equipped'] / $item_stats['total_players'];
     $i['owned_equipped'] = $s['unique_total'] > 0 ? $s['total_equipped'] / $s['unique_total'] : 0;
     // Colors
     if (!empty($s['colors'])) {
         arsort($s['colors']);
         foreach ($s['colors'] as $c => $num) {
             $id = get_paint_by_color($c);
             $si = $schema['items'][$id];
             $it = $b->get_item($si);
             $name = $it['name'];
             if (strlen($name) > 25) {
                 $name = substr($name, 0, 25) . "...";
             }
             //var_dump($it);
             $html = dechex($c);
             if ($html === '0') {
                 continue;
             }
             //$html = '914c3f';
             $key = $num;
             while ($i['colors'][$key] > 0) {
                 $key++;
             }
             $i['colors'][$key] = array('name' => $name, 'color' => $html, 'num' => $num / $s['total_colored']);
         }
     }
     // qualities
     if (!empty($s['qualities'])) {
         arsort($s['qualities']);
         foreach ($s['qualities'] as $c => $num) {
             $key = $num;
             while ($i['qualities'][$key] > 0) {
                 $key++;
             }
             $quality = int_to_quality($c);
             $label = quality_to_label($quality);
             //$color = quality_to_color($quality);
             $i['qualities'][$key] = array('color' => $color, 'num' => $num / $s['total'], 'label' => $label, 'quality' => $quality);
         }
     }
     // Origins
     if (!empty($s['origins'])) {
         arsort($s['origins']);
         foreach ($s['origins'] as $c => $num) {
             $key = $num;
             while ($i['origins'][$key] > 0) {
                 $key++;
             }
             $label = int_to_origin($c);
             //$color = quality_to_color($quality);
             $i['origins'][$key] = array('num' => $num / $s['total'], 'label' => $label);
         }
         arsort($s['effects']);
     }
     // effects
     if (!empty($s['effects'])) {
         $total_effects = 0;
         foreach ($s['effects'] as $c => $num) {
             $total_effects += $num;
         }
         foreach ($s['effects'] as $c => $num) {
             $t = $s['total_effect'] - $s['effects']['-1'];
             if ($c == -1) {
                 continue;
             }
             $key = $num;
             while ($i['effects'][$key] > 0) {
                 $key++;
             }
             $label = int_to_effect($c);
             $i['effects'][$key] = array('color' => $color, 'num' => $num / $total_effects, 'label' => $label);
         }
     }
     if (!empty($i['used_by_classes'])) {
         if (count($i['used_by_classes']['class']) < 1) {
             for ($c = 0; $c < 9; $c++) {
                 $num = $s['equipped'][$c];
                 if ($s['total_equipped'] > 0) {
                     $i['classes'][] = array('class' => int_to_class($c), 'id' => $c, 'num' => $num / $s['total_equipped']);
                 }
             }
         }
     }
     $this->title = sprintf("%s statistics", htmlspecialchars($i['name']));
     $this->params['item'] = $i;
     $this->params['url_name'] = $url_name;
     $this->params['stats'] = $s;
     $this->params['total'] = $item_stats['total_players'];
     $this->params['info'] = $info;
     $this->params['debug'] = $debug;
 }
예제 #8
0
 function update_schema()
 {
     global $db, $settings;
     $response = cache::get(sprintf('http://api.steampowered.com/IEconItems_440/GetSchema/v0001/?key=%s&format=json&language=en', $settings['api_key']), 60);
     $json = json_decode($response, true);
     $s = $json['result'];
     //print $response;
     $s['items'] = $s['items'];
     $s['attributes'] = $s['attributes'];
     if (!isset($s['items'])) {
         die("FAILED" . PHP_EOL . $response);
     }
     foreach ($s['items'] as $k => $i) {
         //$bits = explode('/',$i['image_url']);
         //$im = $bits[count($bits)-1];
         $s['items'][$k]['quality'] = $i['item_quality'];
         //$s['items'][$k]['image'] = basename($i['image_inventory']).'.png';
         //$s['items'][$k]['image_url'] = sprintf('http://media.steampowered.com/apps/440/icons/%s',$s['items'][$k]['image']);
         //$img = $settings['upload']['folder']['items'].basename($i['image_inventory']).'.png';
         if ($i['image_inventory'] == 'backpack/player/items/crafting/paintcan') {
             $s['items'][$k]['image'] = 'paintcan.png';
             $s['items'][$k]['image_url'] = 'http://media.steampowered.com/apps/440/icons/paintcan.png';
             continue;
         }
         $url = $i['image_url'];
         $name = basename($url);
         if (!strlen($url)) {
             cache::log(sprintf("<i>(ID: %d)</i> <b>%s</b> — no image!", $i['defindex'], substr($i['item_name'], 0, 60)));
             $s['items'][$k]['image_url'] = 'http://tf2stats.net/images/unknown.png';
             $s['items'][$k]['image'] = 'unknown.png';
             continue;
         }
         $s['items'][$k]['image'] = $name;
         $img = $settings['upload']['folder']['items'] . $name;
         if (!file_exists($img)) {
             //printf("<br><b>%s</b> <i>(ID: %d)</i> - Fetching image at %s", $i[ 'item_name' ], $i[ 'defindex' ], $url);
             cache::log(sprintf("<i>(ID: %d)</i> <b>%s</b> — fetching image at \"%s\"", $i['defindex'], $i['item_name'], $url));
             $idata = file_get_contents($url);
             if (!$idata) {
                 cache::log(sprintf("<b>File not found.</b> (<a href=\"%s\">check</a>)\n", $url));
                 //printf('- <b>File not found on server.</b> (<a href="%s">check</a>)', $url);
             } else {
                 file_put_contents($img, $idata);
             }
         }
         if (filesize($img) == 0) {
             cache::log("<b>" . $img . ".</b> failed\n");
             @unlink($img);
         }
         if (!file_exists($img) || filesize($img) == 0) {
             $s['items'][$k]['image_url'] = 'http://tf2stats.net/images/unknown.png';
             $s['items'][$k]['image'] = 'unknown.png';
         }
     }
     foreach ($s['attribute_controlled_attached_particles'] as $i) {
         if (!file_exists($settings['upload']['folder']['effects'] . $i['id'] . '.png')) {
             cache::log("<b>" . $i['name'] . "</b> - particle image doesn't exist! (ID: " . $i['id'] . ")");
         }
     }
     foreach ($s['items'] as $i) {
         $o['items'][$i['defindex']] = $i;
     }
     foreach ($s['attributes'] as $a) {
         $o['attributes'][$a['defindex']] = $a;
     }
     $o['qualities'] = $s['qualities'];
     $o['origins'] = $s['originNames'];
     $o['particles'] = $s['attribute_controlled_attached_particles'];
     $o['kill_eater_ranks'] = $s['kill_eater_ranks'];
     $php = var_export($o, true);
     cache::writeFile('tf2_items_schema.php', sprintf('<?php global $schema; $schema = %s ?>', $php));
     backpack::update_asset_info();
     backpack::update_valve_employees();
 }