Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.44 KB | None | 0 0
  1. <?php
  2.     error_reporting(E_ALL ^ E_WARNING);
  3.     header("Content-Type: image/png");
  4.     function saveUserData($user) {
  5.         $dom = new DOMDocument();
  6.         $html = file_get_contents('http://folding.extremeoverclocking.com/user_summary.php?s=&u='.$user);
  7.         $dom->loadHTML($html);
  8.         $h1s = $dom->getElementsByTagName('h1');
  9.         $tables = $dom->getElementsByTagName('table');
  10.         $trs = $tables->item(6)->getElementsByTagName('tr');
  11.         $tds = $trs->item(1)->getElementsByTagName('td');
  12.         $json = array(
  13.             "userName"=>$h1s->item(0)->textContent,
  14.             "userTeamRank"=>$tds->item(0)->textContent,
  15.             "userOverallRank"=>$tds->item(1)->textContent,
  16.             "userPoints"=>$tds->item(6)->textContent,
  17.             "userPPD"=>$tds->item(3)->textContent,
  18.         );
  19.         $json['date'] = date("Y-m-d G:i:s");
  20.         $usersInfo = fopen("scripts/users.json","r");
  21.         $usersInfo = fread($usersInfo,filesize("scripts/users.json"));
  22.        
  23.         $usersInfoArr = json_decode($usersInfo);
  24.         $json = json_encode($json);
  25.         $json = json_decode($json);
  26.         $usersInfoArr->{$user} = $json;
  27.         $usersInfoArr = json_encode($usersInfoArr);
  28.         $usersInfo = fopen("scripts/users.json","w");
  29.         fwrite($usersInfo,$usersInfoArr);
  30.         fclose($usersInfo);
  31.         return json_decode($usersInfoArr);
  32.     }
  33.     function saveTeamData($team) {
  34.         $dom = new DOMDocument();
  35.         $html = file_get_contents('http://folding.extremeoverclocking.com/team_summary.php?s=&t='.$team);
  36.         $dom->loadHTML($html);
  37.         $h1s = $dom->getElementsByTagName('h1');
  38.         $tables = $dom->getElementsByTagName('table');
  39.         $trs = $tables->item(6)->getElementsByTagName('tr');
  40.         $tds = $trs->item(1)->getElementsByTagName('td');
  41.         $json = array(
  42.             "teamName"=>$h1s->item(0)->textContent,
  43.             "teamRank"=>$tds->item(0)->textContent,
  44.             "teamPoints"=>$tds->item(9)->textContent,
  45.             "teamPPD"=>$tds->item(3)->textContent,
  46.             "teamToday"=>$tds->item(7)->textContent,
  47.         );
  48.         $json['date'] = date("Y-m-d G:i:s");
  49.         $teamInfo = fopen("scripts/teams.json","r");
  50.         $teamInfo = fread($teamInfo,filesize("scripts/teams.json"));
  51.         $teamInfoArr = json_decode($teamInfo);
  52.         $json = json_encode($json);
  53.         $json = json_decode($json);
  54.         $teamInfoArr->{$team} = $json;
  55.         $teamInfoArr = json_encode($teamInfoArr);
  56.         $teamInfo = fopen("scripts/teams.json","w");
  57.         fwrite($teamInfo,$teamInfoArr);
  58.         fclose($teamInfo);
  59.         return json_decode($teamInfoArr);
  60.     }
  61.     if(isset($_GET['u']) && isset($_GET['t'])) {   
  62.         $userInfoFile = fopen('scripts/users.json','r');
  63.         $userInfo = fread($userInfoFile,filesize('scripts/users.json'));
  64.         fclose($userInfoFile);
  65.         $userInfo = json_decode($userInfo);
  66.         if(isset($userInfo->{$_GET['u']})) {
  67.             $user = $userInfo->{$_GET['u']};
  68.         } else {
  69.             $userInfo = saveUserData($_GET['u']);
  70.             $user = $userInfo->{$_GET['u']};
  71.         }
  72.         $lastDate = $user->date;
  73.         $now = date("Y-m-d G:i:s");
  74.         $hours = (strtotime($now) - strtotime($lastDate)) / 3600;
  75.         if($hours >= 1) {
  76.             saveUserData($_GET['u']);
  77.         }
  78.         $user = $userInfo->{$_GET['u']};
  79.         $teamInfoFile = fopen('scripts/teams.json','r');
  80.         $teamInfo = fread($teamInfoFile,filesize('scripts/teams.json'));
  81.         fclose($teamInfoFile);
  82.         $teamInfo = json_decode($teamInfo);
  83.         if(isset($teamInfo->{$_GET['t']})) {
  84.             $team = $teamInfo->{$_GET['t']};
  85.         } else {
  86.             $teamInfo = saveTeamData($_GET['t']);
  87.             $team = $teamInfo->{$_GET['t']};
  88.         }
  89.         $lastDate = $team->date;
  90.         $now = date("Y-m-d G:i:s");
  91.         $hours = (strtotime($now) - strtotime($lastDate)) / 3600;
  92.         if($hours >= 1) {
  93.             saveTeamData($_GET['t']);
  94.         }
  95.         if(isset($_GET['b']) && file_exists("images/sigimages/".$_GET['b'].".png")) {
  96.             $template = imagecreatefrompng("images/sigimages/".$_GET['b'].'.png');
  97.         } else {
  98.             $template = imagecreatefrompng('images/sigimages/luna1.png');
  99.         }
  100.         $white = imagecolorallocate($template, 255, 255, 255);
  101.         $yellow = imagecolorallocate($template, 255, 255, 0);
  102.         $font = 'images/fonts/UbuntuMono-R.ttf';
  103.         if(strlen($user->userName) > 14) {
  104.             $username = substr($user->userName,0,14)."...";
  105.         } else {
  106.             $username = $user->userName;
  107.         }
  108.         if(strlen($team->teamName) > 13) {
  109.             $teamname = substr($team->teamName,0,13)."...";
  110.         } else {
  111.             $teamname = $team->teamName;
  112.         }
  113.         imagettftext($template,10,0,69,25,$white,$font,'User:');
  114.         imagettftext($template,10,0,105,25,$yellow,$font,$username);
  115.         imagettftext($template,10,0,15,37,$white,$font,'Rank on Team:');
  116.         imagettftext($template,10,0,105,37,$yellow,$font,$user->userTeamRank);
  117.         imagettftext($template,10,0,15,49,$white,$font,'Overall Rank:');
  118.         imagettftext($template,10,0,105,49,$yellow,$font,$user->userOverallRank);
  119.         imagettftext($template,10,0,22,61,$white,$font,'User Points:');
  120.         imagettftext($template,10,0,105,61,$yellow,$font,$user->userPoints);
  121.         imagettftext($template,10,0,42,73,$white,$font,'User PPD:');
  122.         imagettftext($template,10,0,105,73,$yellow,$font,$user->userPPD);
  123.         imagettftext($template,10,0,219,25,$white,$font,'Team Name:');
  124.         imagettftext($template,10,0,289,25,$yellow,$font,$teamname);
  125.         imagettftext($template,10,0,199,37,$white,$font,'Rank of Team:');
  126.         imagettftext($template,10,0,289,37,$yellow,$font,$team->teamRank);
  127.         imagettftext($template,10,0,206,49,$white,$font,'Team Points:');
  128.         imagettftext($template,10,0,289,49,$yellow,$font,$team->teamPoints);
  129.         imagettftext($template,10,0,226,61,$white,$font,'Team PPD:');
  130.         imagettftext($template,10,0,289,61,$yellow,$font,$team->teamPPD);
  131.         imagettftext($template,10,0,199,73,$white,$font,'Points Today:');
  132.         imagettftext($template,10,0,289,73,$yellow,$font,$team->teamToday);
  133.         imagepng($template);
  134.     }
  135. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement