ak47suk1

patch for com_tienda currency helper getExchangeRateYahoo()

Apr 18th, 2012
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.93 KB | None | 0 0
  1. function getExchangeRateYahoo( $currencyFrom, $currencyTo)
  2.     {
  3.         static $has_run;
  4.        
  5.         // if refresh = true
  6.         // query yahoo for exchange rate
  7.         if (!empty($has_run)) { sleep(1); }
  8.        
  9.         //$url = "http://quote.yahoo.com/d/quotes.csv?s={$currencyFrom}{$currencyTo}=X&f=l1&e=.csv";
  10.  
  11.  
  12.        
  13.         // $handle = @fopen($url, 'r');
  14.        
  15.         // if ($handle) {
  16.             // $result = fgets($handle, 4096);
  17.             // fclose($handle);
  18.         // }
  19.         /*
  20. Display current exchange rate requested by user.
  21.  
  22. Copyleft ak47suk1(http://kaibathelegacy.blogspot.com)
  23. */
  24.  
  25.         $exchange_rates = json_decode(file_get_contents("http://openexchangerates.org/latest.json"));
  26.        
  27.         $result=$exchange_rates->rates->$currencyTo/$exchange_rates->rates->$currencyFrom;
  28.        
  29.         $rate = (float) $result * 1.0;
  30.        
  31.         $has_run = true;
  32.        
  33.         return $rate;
  34.     }
Add Comment
Please, Sign In to add comment