From dacadd8477040d75efdbd7bf5930554728ca357c Mon Sep 17 00:00:00 2001 From: xisi Date: Sat, 18 Jan 2014 14:40:50 -0500 Subject: [PATCH] Fixed bug / undefined index when api settings are empty --- public/include/classes/tools.class.php | 28 ++++++++++++++------------ 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/public/include/classes/tools.class.php b/public/include/classes/tools.class.php index 1cf4f875..7891cb10 100644 --- a/public/include/classes/tools.class.php +++ b/public/include/classes/tools.class.php @@ -70,20 +70,22 @@ class Tools extends Base { // Check the API type for configured URL if (!$strApiType = $this->getApiType($this->config['price']['url'])) return false; - // Extract price depending on API type - switch ($strApiType) { - case 'coinchose': - foreach ($aData as $aItem) { - if($strCurrency == $aItem[0]) - return $aItem['price']; + // if api data is valid, extract price depending on API type + if (is_array($aData)) { + switch ($strApiType) { + case 'coinchose': + foreach ($aData as $aItem) { + if($strCurrency == $aItem[0]) + return $aItem['price']; + } + break; + case 'btce': + return $aData['ticker']['last']; + break; + case 'cryptsy': + return @$aData['return']['markets'][$strCurrency]['lasttradeprice']; + break; } - break; - case 'btce': - return $aData['ticker']['last']; - break; - case 'cryptsy': - return $aData['return']['markets'][$strCurrency]['lasttradeprice']; - break; } // Catchall, we have no data extractor for this API url $this->setErrorMessage("Undefined API to getPrice() on URL " . $this->config['price']['url']);