Advertisement
Guest User

Untitled

a guest
May 3rd, 2012
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.22 KB | None | 0 0
  1. <html xmlns="http://www.w3.org/1999/xhtml" lang="pl" >
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  3. <head>
  4. <title>GE Extractor</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6.  
  7. <script type="text/javascript">
  8.  
  9.    function myFocus(element) {
  10.      if (element.value == element.defaultValue) {
  11.        element.value = '';
  12.      }
  13.    }
  14.    
  15.    function myBlur(element) {
  16.      if (element.value == '') {
  17.        element.value = element.defaultValue;
  18.      }
  19.    }
  20. </script>
  21. <style type="text/css">
  22. .error {
  23.     color:#FF0000;
  24.     font-weight:bold;
  25. }
  26. small {
  27.     color:#666666;
  28. }
  29. .parsedItemIconUrl {
  30.     float:left;
  31. }
  32. </style>
  33. </head>
  34. <body>
  35. <form name="myForm" action="" method="post" id="myForm">
  36.   <table cellpadding="2" border="1">
  37.     <tr>
  38.       <td width="250" rowspan="3" valign="top">
  39.  
  40. <?php
  41.   function transformHTML($string)
  42.   {
  43.       $string = trim($string);
  44.       $string = utf8_decode($string);
  45.       $string = htmlentities($string, ENT_NOQUOTES);
  46.       $string = str_replace("#", "&#35;", $string);
  47.       $string = str_replace("%", "&#37;", $string);
  48.  
  49.       return $string;
  50.   }
  51.  
  52.   function get_string_between($string, $start, $end){
  53.       $string = " ".$string;
  54.       $ini = strpos($string,$start);
  55.       if ($ini == 0) return "";
  56.       $ini += strlen($start);
  57.       $len = strpos($string,$end,$ini) - $ini;
  58.       return substr($string,$ini,$len);
  59.   }
  60.  
  61.   function echoObjectIdStuff($objectId) {
  62.  
  63.       $error_A = "<p><small class=error>Error #1: Give the ID!</small></p>";
  64.       $error_B = "<p><small class=error>Error #2: Item ID " . $objectId . " not found</small></p>";
  65.          
  66.           $lines = file('http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=' . $objectId);
  67.           foreach ($lines as $line_num => $line) {
  68.               $lineCrawl = htmlspecialchars($line);
  69.               $StringSum = "$StringSum$lineCrawl";
  70.           }
  71.           $parsedGuidePrice = get_string_between($StringSum, "Current guide price", "Today");
  72.           $parsedItemName = get_string_between($StringSum, "&lt;title&gt;", " - Grand Exchange - RuneScape&lt;/title&gt;");
  73.           $parsedItemIconUrl  = get_string_between($StringSum, '&lt;meta property=&quot;og:image&quot; content=&quot;', '&quot; /&gt;');
  74.      
  75.           $guideprice = preg_replace("/[^\.kbm0-9]/", "", $parsedGuidePrice);
  76.      
  77.           if (strpos($guideprice,'k') !== false) {
  78.               $guideprice = preg_replace("/[^0-9]/", "", $parsedGuidePrice);
  79.               $guideprice *= 100;
  80.           } else if (strpos($guideprice,'m') !== false) {
  81.               $guideprice = preg_replace("/[^0-9]/", "", $parsedGuidePrice);
  82.               $guideprice *= 100000;
  83.           } else if (strpos($guideprice,'b') !== false) {
  84.               $guideprice = preg_replace("/[^0-9]/", "", $parsedGuidePrice);
  85.               $guideprice *= 100000000;
  86.           } if ($guideprice == "") {
  87.               echo $error_B;
  88.           } else {
  89.               echo "<img src='" . $parsedItemIconUrl . "' class='parsedItemIconUrl'>";
  90.               echo "<br>";
  91.               echo "<br>";
  92.               echo "<strong>" . $parsedItemName . "</strong>: " . $guideprice;
  93.               echo "<br>";
  94.               echo "<small>(Item ID: " . $objectId . ")</small><br><br>";
  95.           }
  96.   }
  97.  
  98.   if($_POST['submit']) {
  99.     $objectId = transformHTML($_POST['objectId']);
  100.     $objectRange = transformHTML($_POST['objectRange']);
  101.  
  102.           $objectRange += $objectId - 1;
  103.           for($i = $objectId;  $i <= $objectRange; $i++) {
  104.             echoObjectIdStuff($i);
  105.           }
  106.   }
  107. ?>
  108.        </td>
  109.       <td width="79">Item ID:</td>
  110.       <td width="260"><input name="objectId" value="Type the ID here" onfocus="myFocus(this);" onblur="myBlur(this);" /></td>
  111.       <td width="79"><input type="submit" name="submit" alt="Get yesterday's averge market price" title="Get yesterday's averge market price" /></td>
  112.     </tr>
  113.     <tr valign="top">
  114.       <td>Range:</td>
  115.       <td><input name="objectRange" value="1" onfocus="myFocus(this);" onblur="myBlur(this);" /></td>
  116.       <td>&nbsp;</td>
  117.     </tr>
  118.     <tr valign="top">
  119.       <td>&nbsp;</td>
  120.       <td>
  121.       <small>ex. Gold Bar ID = 2357<br />
  122.       ex. Range = 9 with ID 1038 is: 1038, 1039, ... 1047</small>
  123.       </td>
  124.       <td><input value="Reset" type="button" name="reset" alt="Reset the form" title="Reset the form" onclick="javascript:window.location = '';" /></td>
  125.     </tr>
  126.   </table>
  127. </form>
  128. </body>
  129. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement