You are here

function _currency_filter_currency_exchange_process in Currency 7.2

Implements preg_replace_callback() callback.

1 string reference to '_currency_filter_currency_exchange_process'
currency_filter_currency_exchange_process in currency/currency.module
Implements hook_filter_info()'s process callback.

File

currency/currency.module, line 610
Provides currency information and allows users to add custom currencies.

Code

function _currency_filter_currency_exchange_process(array $matches) {
  $currency_code_from = $matches[1];
  $currency_code_to = $matches[2];
  $amount = str_replace(':', '', $matches[3]);
  if (strlen($amount) !== 0) {
    try {
      $amount = Input::parseAmount($amount);
    } catch (Exception $e) {
      return $matches[0];
    }
  }
  else {
    $amount = 1;
  }
  if ($rate = CurrencyExchanger::load($currency_code_from, $currency_code_to)) {
    return currency_multiply($amount, $rate);
  }

  // The filter failed, so return the token.
  return $matches[0];
}