Changeset 500 for tags/2.1.8/lib/Currency.inc.php
- Timestamp:
- Nov 15, 2014 9:34:39 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tags/2.1.8/lib/Currency.inc.php
r484 r500 4 4 * For details visit the project site: <http://trac.strangecode.com/codebase/> 5 5 * Copyright 2001-2012 Strangecode, LLC 6 * 6 * 7 7 * This file is part of The Strangecode Codebase. 8 8 * … … 11 11 * Free Software Foundation, either version 3 of the License, or (at your option) 12 12 * any later version. 13 * 13 * 14 14 * The Strangecode Codebase is distributed in the hope that it will be useful, but 15 15 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 17 * details. 18 * 18 * 19 19 * You should have received a copy of the GNU General Public License along with 20 20 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>. … … 28 28 * @author Quinn Comendant <quinn@strangecode.com> 29 29 * @version 1.5 30 * 30 * 31 31 * Example of use: 32 32 --------------------------------------------------------------------- … … 37 37 --------------------------------------------------------------------- 38 38 */ 39 39 40 40 class Currency { 41 41 … … 48 48 'api_key' => '', // Used only by xurrency API. 49 49 ); 50 50 51 51 /** 52 52 * Cart constructor. … … 58 58 // Set custom parameters. 59 59 $this->setParam($params); 60 60 61 61 // Setup cache directory. 62 62 if ($this->getParam('cache_result')) { … … 66 66 } 67 67 if (!is_dir($this->getParam('cache_dir'))) { 68 $app->logMsg(sprintf('Creating cache_dir: %s', $this->getParam('cache_dir')), LOG_INFO, __FILE__, __LINE__); 68 $app->logMsg(sprintf('Creating cache_dir: %s', $this->getParam('cache_dir')), LOG_INFO, __FILE__, __LINE__); 69 69 if (!mkdir($this->getParam('cache_dir'))) { 70 $app->logMsg(sprintf('Could not create cache_dir: %s', $this->getParam('cache_dir')), LOG_WARNING, __FILE__, __LINE__); 70 $app->logMsg(sprintf('Could not create cache_dir: %s', $this->getParam('cache_dir')), LOG_WARNING, __FILE__, __LINE__); 71 71 } 72 72 } … … 97 97 { 98 98 $app =& App::getInstance(); 99 99 100 100 if (array_key_exists($param, $this->_params)) { 101 101 return $this->_params[$param]; … … 105 105 } 106 106 } 107 107 108 108 /* 109 109 * Return the exchange value between the two given currencies for given amount. … … 113 113 * @param string $base 3-letter currency code to convert from. 114 114 * @param string $target 3-letter currency code to convert to. 115 * @return mixed Float converted currency value, or false on error. 115 * @return mixed Float converted currency value, or false on error. 116 116 * @author Quinn Comendant <quinn@strangecode.com> 117 117 * @version 1.0 … … 121 121 { 122 122 if (false !== $rate = $this->getRate($base, $target)) { 123 return abs($rate * $amount); 123 return abs($rate * $amount); 124 124 } else { 125 125 return false; 126 126 } 127 127 } 128 128 129 129 /* 130 130 * Return the currency conversion rate as a ratio. … … 133 133 * @param string $base 3-letter currency code to convert from. 134 134 * @param string $target 3-letter currency code to convert to. 135 * @return mixed Float exchange rate value, or false on error. 135 * @return mixed Float exchange rate value, or false on error. 136 136 * @author Quinn Comendant <quinn@strangecode.com> 137 137 * @version 1.0 … … 173 173 return trim($value); 174 174 } 175 175 176 176 /** 177 177 * @param string … … 215 215 $api_url = 'http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml'; 216 216 if (false === $sXML = file_get_contents($api_url)) { 217 $app->logMsg(sprintf('Failed to load ECB XML data from 217 $app->logMsg(sprintf('Failed to load ECB XML data from: %s', $api_url), LOG_WARNING, __FILE__, __LINE__); 218 218 return false; 219 219 } 220 220 if (false === $oXML = simplexml_load_string($sXML)) { 221 $app->logMsg(sprintf('Failed to decode ECB XML data: ', truncate($sXML, 200, 'end')), LOG_WARNING, __FILE__, __LINE__);221 $app->logMsg(sprintf('Failed to decode ECB XML data: %s', truncate($sXML, 200, 'end')), LOG_WARNING, __FILE__, __LINE__); 222 222 return false; 223 223 }
Note: See TracChangeset
for help on using the changeset viewer.