Moi,
Oanda and XE keeps giving me errors, so I have added one more server and updated my code accordingly.
admin/includes/functions/localization.php
- added new function
admin/currencies.phpCode:function quote_ecb_currency($code, $base = DEFAULT_CURRENCY) { $xml= new SimpleXMLElement(file_get_contents("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml")); # extract default currency's exchange rate. $nzd = $xml->xpath("//*[@currency='".$base."']"); $base_rate = (float)$nzd[0]['rate']; if ($base == 'EUR') {$base_rate=(float)1;} # extract requested currency's exchange rate. $nzd = $xml->xpath("//*[@currency='".$code."']"); $rate = (float)$nzd[0]['rate']; if ($code == 'EUR') {$rate=(float)1;} $new_rate = $rate/$base_rate; if ($new_rate != 0) return $new_rate; else return null; }
- updated the 'update' with completely new code.
admin/includes/languages/english/currencies.phpCode:case 'update': $currency = $db->Execute("select currencies_id, code, title from " . TABLE_CURRENCIES); $servers = array('ecb', 'oanda', 'xe'); zen_set_time_limit(600); while (!$currency->EOF) { foreach($servers as $server_used){ $quote_function = 'quote_' . $server_used . '_currency'; $rate = $quote_function($currency->fields['code']); if (!empty($rate)){ /* Add currency uplift */ if ($rate != 1 && defined('CURRENCY_UPLIFT_RATIO')) {$rate = (string)((float)$rate * (float)CURRENCY_UPLIFT_RATIO);} $db->Execute("update " . TABLE_CURRENCIES . " set value = '" . $rate . "', last_updated = now() where currencies_id = '" . (int)$currency->fields['currencies_id'] . "'"); $messageStack->add_session(sprintf(TEXT_INFO_CURRENCY_UPDATED, $currency->fields['title'], $currency->fields['code'], $server_used), 'success'); break; } else $messageStack->add_session(sprintf(WARNING_SERVER_FAILED, $server_used, $currency->fields['title'], $currency->fields['code']), 'warning'); } $currency->MoveNext(); } zen_redirect(zen_href_link(FILENAME_CURRENCIES, 'page=' . $_GET['page'] . '&cID=' . $_GET['cID'])); break;
- added new definition
I do not have automatic updates, but now I have European Central Bank (ECB) daily rates as a primary exchange rate serverCode:define('WARNING_SERVER_FAILED', 'Warning: The exchange rate server (%s) failed for %s (%s)');![]()


Reply With Quote
