- if (function_exists('curl_init'))
- { // first check with curl as we can set short timeout;
- $ch = curl_init();
- curl_setopt ($ch, CURLOPT_URL, $ecb_filename);
- curl_setopt ($ch, CURLOPT_COOKIEJAR, "cookie.txt");
- curl_setopt ($ch, CURLOPT_HEADER, 0);
- curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
- curl_setopt ($ch, CURLOPT_TIMEOUT, 5);
- $contents = curl_exec ($ch);
- curl_close($ch);
- } else {
- $handle = @fopen($ecb_filename, 'rb');
- if ($handle) {
- do
- {
- $data = @fread( $handle, 4096 );
- if ( strlen ( $data ) == 0 )
- break;
- $contents .= $data; // with this syntax only text will be translated, whole text with htmlspecialchars($data)
- }
- while (true);
- @fclose( $handle );
- } // end handle
+ if ($date != Today()) // no historical rates available
+ return 0;
+
+ $contents = '';
+ $proto = 'http://';
+ $curr_a = get_company_pref('curr_default');
+ if ($provider == 'ECB')
+ {
+ $filename = "/stats/eurofxref/eurofxref-daily.xml";
+ $site = "www.ecb.europa.eu";
+ $proto = 'https://';
+ $site_ip="172.230.157.137";
+ $contents=file_get_contents($proto.$site.$filename);
+ }
+ elseif ($provider == 'YAHOO')
+ {
+ $filename = "/d/quotes.csv?s={$curr_a}{$curr_b}=X&f=sl1d1t1ba&e=.csv"; // new URL's for YAHOO
+ $site = "download.finance.yahoo.com";
+ $site_ip="203.84.220.151";
+ }
+ elseif ($provider == 'GOOGLE')
+ {
+ $filename = "/search?q={$curr_b}+to+{$curr_a}";
+ $site = "https://www.google.com";
+ $contents = file_get_contents($site.$filename);
+ }
+ elseif ($provider == 'BLOOMBERG')
+ {
+ $filename = "/quote/{$curr_b}{$curr_a}:CUR";
+ $site = "www.bloomberg.com";
+ $proto = 'https://';
+ $contents=file_get_contents($proto.$site.$filename);
+ }
+ elseif ($provider == 'EXCHANGE-RATES.ORG')
+ {
+ $filename = "/converter/{$curr_b}/{$curr_a}/1";
+ $site = "exchange-rates.org";
+ $proto = 'https://';
+ $contents=file_get_contents($proto.$site.$filename);