ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/functions/localization.php
Go to the documentation of this file.
00001 <?php
00010 function quote_ecb_currency($currencyCode = '', $base = DEFAULT_CURRENCY)
00011 {
00012   $requested = $currencyCode;
00013   $url = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml';
00014   $data = '';
00015   // check via file() ... may fail if php file Wrapper disabled.
00016   $XMLContent = @file($url);
00017   if (! is_object($XMLContent) && function_exists('curl_init')) {
00018     // check via CURL instead.
00019     $XMLContent = doCurlCurrencyRequest('POST', $url, $data);
00020     $XMLContent = explode("\n", $XMLContent);
00021   }
00022   $currencyArray = array();
00023   $rate = 1;
00024   $line = '';
00025 //  $currencyCode = '';
00026   $currencyArray['EUR'] = 1;
00027   foreach ($XMLContent as $line) {
00028     if (preg_match("/currency='([[:alpha:]]+)'/", $line, $currencyCode)) {
00029       if (preg_match("/rate='([[:graph:]]+)'/", $line, $rate)) {
00030         $currencyArray[$currencyCode[1]] = (float)$rate[1];
00031       }
00032     }
00033   }
00034   if ($requested == $base) {
00035     $rate = 1;
00036   } else {
00037     $rate = (string)((float)$currencyArray[$requested] / $currencyArray[DEFAULT_CURRENCY]);
00038   }
00039   return $rate;
00040 }
00041 
00042 function quote_boc_currency($currencyCode = '', $base = DEFAULT_CURRENCY)
00043 {
00044   static $CSVContent;
00045   $requested = $currencyCode;
00046   $url = 'http://www.bankofcanada.ca/en/markets/csv/exchange_eng.csv';
00047   $currencyArray = array();
00048   $currencyArray['CAD'] = 1;
00049   if (!isset($CSVContent) || $CSVContent == '') {
00050     $CSVContent = @file($url);
00051     if (! is_object($CSVContent) && function_exists('curl_init')) {
00052       $CSVContent = doCurlCurrencyRequest('POST', $url, '');
00053       $CSVContent = explode("\n", $CSVContent);
00054     }
00055   }
00056 
00057   $bocList = array();
00058   $bocList['U.S. Dollar (Noon)'] = 'USD';
00059   $bocList['Argentina Peso (Floating Rate)'] = 'aaa';
00060   $bocList['Australian Dollar'] = 'AUD';
00061   $bocList['Bahamian Dollar'] = 'aaa';
00062   $bocList['Brazilian Real'] = 'aaa';
00063   $bocList['Chilean Peso'] = 'aaa';
00064   $bocList['Chinese Renminbi'] = 'aaa';
00065   $bocList['Colombian Peso'] = 'aaa';
00066   $bocList['Croatian Kuna'] = 'aaa';
00067   $bocList['Czech Republic Koruna'] = 'aaa';
00068   $bocList['Danish Krone'] = 'aaa';
00069   $bocList['East Caribbean Dollar'] = 'aaa';
00070   $bocList['European Euro'] = 'aaa';
00071   $bocList['Fiji Dollar'] = 'aaa';
00072   $bocList['CFA Franc (African Financial Community)'] = 'aaa';
00073   $bocList['CFP Franc (Pacific Financial Community)'] = 'aaa';
00074   $bocList['Ghanaian Cedi (new)'] = 'aaa';
00075   $bocList['Guatemalan Quetzal'] = 'aaa';
00076   $bocList['Honduran Lempira'] = 'aaa';
00077   $bocList['Hong Kong Dollar'] = 'aaa';
00078   $bocList['Hungarian Forint'] = 'aaa';
00079   $bocList['Icelandic Krona'] = 'aaa';
00080   $bocList['Indian Rupee'] = 'aaa';
00081   $bocList['Indonesian Rupiah'] = 'aaa';
00082   $bocList['Israeli New Shekel'] = 'aaa';
00083   $bocList['Jamaican Dollar'] = 'aaa';
00084   $bocList['Japanese Yen'] = 'aaa';
00085   $bocList['Malaysian Ringgit'] = 'aaa';
00086   $bocList['Mexican Peso'] = 'aaa';
00087   $bocList['Moroccan dirham'] = 'aaa';
00088   $bocList['Myanmar (Burma) Kyat'] = 'aaa';
00089   $bocList['Neth. Antilles Guilder'] = 'aaa';
00090   $bocList['New Zealand Dollar'] = 'aaa';
00091   $bocList['Norwegian Krone'] = 'aaa';
00092   $bocList['Pakistan rupee'] = 'aaa';
00093   $bocList['Panamanian Balboa'] = 'aaa';
00094   $bocList['Peruvian New Sol'] = 'aaa';
00095   $bocList['Philippine Peso'] = 'aaa';
00096   $bocList['Polish Zloty'] = 'aaa';
00097   $bocList['Romanian New Leu'] = 'aaa';
00098   $bocList['Russian Rouble'] = 'aaa';
00099   $bocList['Serbian Dinar'] = 'aaa';
00100   $bocList['Singapore Dollar'] = 'aaa';
00101   $bocList['South African Rand'] = 'aaa';
00102   $bocList['South Korean Won'] = 'aaa';
00103   $bocList['Sri Lanka Rupee'] = 'aaa';
00104   $bocList['Swedish Krona'] = 'aaa';
00105   $bocList['Swiss Franc'] = 'aaa';
00106   $bocList['Taiwanese New Dollar'] = 'aaa';
00107   $bocList['Thai Baht'] = 'aaa';
00108   $bocList['Trinidad & Tobago Dollar'] = 'aaa';
00109   $bocList['Tunisian Dinar'] = 'aaa';
00110   $bocList['New Turkish Lira'] = 'aaa';
00111   $bocList['UAE Dirham'] = 'aaa';
00112   $bocList['U.K. Pound Sterling'] = 'GBP';
00113   $bocList['Venezuelan Bolivar Fuerte'] = 'aaa';
00114   $bocList['Vietnamese Dong'] = 'aaa';
00115 
00116   foreach ($CSVContent as $line) {
00117     if (substr($line, 0, 1) == '#' || substr($line, 0, 4) == 'Date') continue;
00118     $data = explode(',', $line);
00119     $curName = $data[0];
00120     $curRate = $data[sizeof($data)-1];
00121     if ($currencyCode == $bocList[$curName]) {
00122       $currencyArray[$currencyCode] = (float)$curRate;
00123     }
00124   }
00125   if ($requested == $base) {
00126     $rate = 1;
00127   } else {
00128     $rate = (string)((float)$currencyArray[$requested] / $currencyArray[DEFAULT_CURRENCY]);
00129   }
00130   return $rate;
00131 }
00132 
00133   function quote_oanda_currency($code, $base = DEFAULT_CURRENCY) {
00134     $url = 'http://www.oanda.com/convert/fxdaily';
00135     $data = 'value=1&redirected=1&exch=' . $code .  '&format=CSV&dest=Get+Table&sel_list=' . $base;
00136     // check via file() ... may fail if php file Wrapper disabled.
00137     $page = @file($url . '?' . $data);
00138     if (!is_object($page) && function_exists('curl_init')) {
00139       // check via cURL instead.  May fail if proxy not set, esp with GoDaddy.
00140       $page = doCurlCurrencyRequest('POST', $url, $data) ;
00141       $page = explode("\n", $page);
00142     }
00143     if (is_object($page) || $page !='') {
00144       $match = array();
00145 
00146       preg_match('/(.+),(\w{3}),([0-9.]+),([0-9.]+)/i', implode('', $page), $match);
00147 
00148       if (sizeof($match) > 0) {
00149         return $match[3];
00150       } else {
00151         return false;
00152       }
00153     }
00154   }
00155 
00156   function quote_xe_currency($to, $from = DEFAULT_CURRENCY) {
00157     $url = 'http://www.xe.net/ucc/convert.cgi';
00158     $data = 'Amount=1&From=' . $from . '&To=' . $to;
00159     // check via file() ... may fail if php file Wrapper disabled.
00160     $page = @file($url . '?' . $data);
00161     if (!is_object($page) && function_exists('curl_init')) {
00162       // check via cURL instead.  May fail if proxy not set, esp with GoDaddy.
00163       $page = doCurlCurrencyRequest('POST', $url, $data) ;
00164       $page = explode("\n", $page);
00165     }
00166     if (is_object($page) || $page !='') {
00167       $match = array();
00168 
00169       preg_match('/[0-9.]+\s*' . $from . '\s*=\s*([0-9.]+)\s*' . $to . '/', implode('', $page), $match);
00170       if (sizeof($match) > 0) {
00171         return $match[1];
00172       } else {
00173         return false;
00174       }
00175     }
00176   }
00177 
00178   function doCurlCurrencyRequest($method, $url, $vars = '') {
00179     //echo '-----------------<br />';
00180     //echo 'URL: ' . $url . ' VARS: ' . $vars . '<br />';
00181     $ch = curl_init();
00182     curl_setopt($ch, CURLOPT_URL,$url);
00183     curl_setopt($ch, CURLOPT_VERBOSE, 0);
00184     curl_setopt($ch, CURLOPT_HEADER, false);
00185     curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
00186     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
00187     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
00188 //  curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
00189 //  curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
00190     if (strtoupper($method) == 'POST' && $vars != '') {
00191       curl_setopt($ch, CURLOPT_POST, true);
00192       curl_setopt($ch, CURLOPT_POSTFIELDS, $vars);
00193     }
00194     if (CURL_PROXY_REQUIRED == 'True') {
00195       $proxy_tunnel_flag = (defined('CURL_PROXY_TUNNEL_FLAG') && strtoupper(CURL_PROXY_TUNNEL_FLAG) == 'FALSE') ? false : true;
00196       curl_setopt ($ch, CURLOPT_HTTPPROXYTUNNEL, $proxy_tunnel_flag);
00197       curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
00198       curl_setopt ($ch, CURLOPT_PROXY, CURL_PROXY_SERVER_DETAILS);
00199     }
00200     $data = curl_exec($ch);
00201     $error = curl_error($ch);
00202     //$info=curl_getinfo($ch);
00203     curl_close($ch);
00204 
00205     if ($error != '') {
00206       global $messageStack;
00207       $messageStack->add_session('cURL communication ERROR: ' . $error, 'error');
00208     }
00209     //echo 'INFO: <pre>'; print_r($info); echo '</pre><br />';
00210     //echo 'ERROR: ' . $error . '<br />';
00211     //print_r($data) ;
00212 
00213     if ($data != '') {
00214       return $data;
00215     } else {
00216       return $error;
00217     }
00218   }
 All Data Structures Namespaces Files Functions Variables Enumerations