Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class WorldOfTrucks
- {
- private $uid = 0;
- private $url = "https://www.worldoftrucks.com/en/online_profile.php?id=";
- private $wholecontent;
- function __construct( int $id )
- {
- $this->uid = $id;
- $this->wholecontent = file_get_contents( $this->url.$this->uid );
- }
- public function getStats( string $which ): array
- {
- $data = $this->loadStatsTable($which);
- $data = explode("</div>",$data);
- unset($data[13]);
- unset($data[14]);
- $output = [
- "TOTAL_JOBS" => $this->clean($data[0]),
- "TOTAL_TIME" => $this->clean($data[1]),
- "TOTAL_MASS" => $this->clean($data[2]),
- "TOTAL_TRIP" => $this->clean($data[5]),
- "AVG_TRIP" => $this->clean($data[3]),
- "LONGEST_TRIP" => $this->clean($data[4]),
- "DAY_STREAK" => $this->clean( $data[6] ),
- "TOP_CITY" => $this->clean($data[9]),
- "TOP_SOURCE" => $this->clean($data[10]),
- "TOP_SUPPL" => $this->clean($data[11]),
- "TOP_CARGO" => $this->clean($data[12]),
- ];
- return $output;
- }
- public function getTruck( string $game ): array
- {
- $data = $this->loadTruckTable($game);
- $data = explode( "</tr>" , $data);
- unset($data[8]);
- foreach( $data as $item)
- {
- $item = explode( "</td>" , $item);
- unset($item[0]);
- unset($item[2]);
- $temp[] = $this->clean( $item[1] );
- }
- unset($temp[7]);
- $output =[
- "TRUCK" =>$this->getTruckName($game),
- "CABIN" => $temp[0],
- "CHASSIS" => $temp[1],
- "PERFORMANCE" => $temp[2],
- "TORQUE" => $temp[3],
- "ENGINE" => $temp[4],
- "GEARBOX" => $temp[5]
- ];
- return $output;
- }
- private function getTruckName( string $game ): string
- {
- $ets = $this->get_string_between( $this->wholecontent , "Euro Truck Simulator 2" , "</p>");
- $ats = $this->get_string_between( $this->wholecontent , "American Truck Simulator" , "</p>");
- $output = [ "ETS" => $this->clean($ets), "ATS" => $this->clean($ats)];
- return $output[$game];
- }
- public function getDriverName(): string
- {
- $content = $this->get_string_between( $this->wholecontent , "<h2 class=\"orange\">","</h2>");
- $data = $this->get_string_between( $content , "<span>","</span>");
- return $data;
- }
- private function loadTruckTable(string $game ): string
- {
- $data = $this->get_string_between( $this->wholecontent , "<h2>MY CURRENT RIDES</h2>", "<div class=\"cleaner\"></div>" );
- $data = explode("<div class=\"truck-info\">",$data);
- $output = [ "ETS" => $data[1],"ATS"=>$data[2]];
- return $output[$game];
- }
- private function loadStatsTable( string $get ): string
- {
- $data = $this->get_string_between( $this->wholecontent , "<h2>Full statistics</h2>", "<div class=\"cleaner\"></div>" );
- $data = explode("</p>",$data);
- $output = [
- "ETS" => $data[2],
- "ATS" => $data[3],
- "GLOBAL" => $data[4]
- ];
- return $output[$get];
- }
- private function clean( string $string ): string
- {
- return trim( strip_tags( $string ));
- }
- private function get_string_between( string $string , string $start , string $end ): string
- {
- $string = ' ' . $string;
- $ini = strpos($string, $start);
- if ($ini == 0) return '';
- $ini += strlen($start);
- $len = strpos($string, $end, $ini) - $ini;
- return substr($string, $ini, $len);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement