' . __( 'Artiss Currency Converter Error: ' ) . $result . ''; } } else { return str_replace( $tag, $result, $template ); } } /** * Perform Currency Conversion * * Perform a currency conversion and output the results * * @since 1.0 * * @uses acc_get_options Get the default options * @uses acc_get_rates Get the array of exchange rates * * @param string $number Number to convert * @param string $from Currency code to convert from * @param string $to Currency code to convert to * @param string $dp Number of decimal points * @return string Result */ function acc_perform_conversion( $number = '', $from = '', $to = '', $dp = '' ) { $error = ''; $result = ''; $options = acc_get_options(); // If any of the details are missing, get them from the default options that are set if ( $from == '' ) { $from = $options[ 'from' ]; } if ( $to == '' ) { $to = $options[ 'to' ]; } if ( $dp == '' ) { $dp = $options[ 'dp' ]; } // Get exchange rates from array $rates_array = acc_get_rates( $options[ 'rates_cache' ] ); if ( is_array( $rates_array ) ) { $from = $rates_array[ strtoupper( $from ) ]; $to = $rates_array[ strtoupper( $to ) ]; if ( ( $from == '' ) or ( $to == '' ) ) { $error = __( 'Could not fetch one of the required exchange rates' ); } else { // If the DP parameter is to match then calculcate the number of decimal places that // the passed value is if ( !is_numeric( $dp ) ) { $decimal_pos = strpos( $number, '.' ); if ( !$decimal_pos ) { $dp = 0; } else { $dp = strlen( $number ) - ( $decimal_pos + 1 ); } } // Perform the conversion $result = number_format( round( $number * ( $to * ( 1 / $from ) ), $dp ), $dp ); } } else { $error = $rates_array; } if ( $error != '' ) { $result = $error; } return $result; } ?>