Advertisement
hejmus

Untitled

Aug 19th, 2012
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.30 KB | None | 0 0
  1. <?php
  2. require_once('simple_html_dom.php');
  3.  
  4. function getwowcenter($ranking)
  5. {
  6.     $cacheKey="cache/wowcenter-$ranking.cache";
  7.     $elapsed=file_exists($cacheKey)?filemtime($cacheKey):0;
  8.     if (time() - $elapsed < 60*5)
  9.     {
  10.         $guilds=unserialize(file_get_contents($cacheKey));
  11.         return $guilds;
  12.     }
  13.  
  14.     $html=file_get_html("http://wowcenter.pl/Gildie/Ranking/$ranking");
  15.  
  16.     $rows=array_merge($html->find('.horde-row'),$html->find('.alliance-row'));
  17.     foreach ($rows as $row)
  18.     {
  19.         $guild=$row->find('td.guild',0);
  20.         $info=array();
  21.         foreach ($row->find('td') as $td)
  22.             $info[]=trim($td->plaintext);
  23.            
  24.         $row->class='  '.$row->class; //super php nie rozroznia FALSE od 0...
  25.         if (strpos($row->class,"number-1")!=FALSE) $info[0]='1';
  26.         if (strpos($row->class,"number-2")!=FALSE) $info[0]='2';
  27.         if (strpos($row->class,"number-3")!=FALSE) $info[0]='3';
  28.         if (strpos($row->class,"alliance-row")!=FALSE) $info[]='alliance';
  29.         if (strpos($row->class,"horde-row")!=FALSE) $info[]='horde';
  30.         $guilds[]=$info;
  31.     }
  32.     usort($guilds,function($x,$y) { return $x[0]-$y[0]; });
  33.     file_put_contents($cacheKey,serialize($guilds));
  34.     return $guilds;
  35. }
  36.  
  37. var_dump(getwowcenter('Tier-13-25-Man'));
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement