mergeConfig($data);
// Temporary allow maximum
- setConfigEntry('yoomedia_tm_max_reload' , 1000);
+ setConfigEntry('yoomedia_tm_max_reload' , 100000);
setConfigEntry('yoomedia_tm_min_wait' , 0);
setConfigEntry('yoomedia_tm_clicks_remain', 10);
setConfigEntry('yoomedia_tm_min_pay' , 0);
// Query the API with a test request without couting it
// If zero reply comes back the data is invalid!
- $response = YOOMEDIA_QUERY_API("out_textmail.php", true); // @TODO Ask Yoo!Media for test script
+ $response = YOOMEDIA_QUERY_API('out_textmail.php', true); // @TODO Ask Yoo!Media for test script
+
+ // Default error code is 0 = all fine!
+ $errorCode = YOOMEDIA_GET_ERRORCODE_FROM_RESULT($response);
// Log the response if failed
if (count($response) == 0) {
// Queries depleted (as we count here!)
- DEBUG_LOG(__FUNCTION__, __LINE__, " Requested depleted. Maxmimum was: ".getConfig('yoomedia_requests_total'));
- } elseif (count($response) <= 10) {
+ DEBUG_LOG(__FUNCTION__, __LINE__, "Requested depleted. Maxmimum was: " . getConfig('yoomedia_requests_total'));
+ $errorCode = -1;
+ } elseif (!isset($response[8])) {
+ // Invalid response
+ DEBUG_LOG(__FUNCTION__, __LINE__, "Missing response line [8]. Raw response=" . base64_encode(serialize($response)));
+ $errorCode = -1;
+ } elseif ((($errorCode <= 4) && ($errorCode > 0)) || ($errorCode >= 8)) {
+ // An error has returned from the account
+ DEBUG_LOG(__FUNCTION__, __LINE__, "Unexpected error code " . $errorCode . " received.");
+ } elseif (count($response) < 9) {
// Log serialized raw response
- DEBUG_LOG(__FUNCTION__, __LINE__, " Raw response=".base64_encode(serialize($response)));
- } // END - if
+ DEBUG_LOG(__FUNCTION__, __LINE__, "Raw response=" . base64_encode(serialize($response)));
+ $errorCode = -1;
+ } else {
+ // This is fine, because the result array is okay and the response code on element 8 is fine
+ $errorCode = 0;
+ }
// Do we have some data there?
- return (count($response) > 10);
+ return ($errorCode == 0);
}
// Queries the given Yoo!Media API 2.0 script
$response = sendGetRequest($requestString);
// Shall we count the query as used?
- if ($countQuery) {
+ if ($countQuery === true) {
// Then update the config!
updateConfiguration('yoomedia_requests_remain', 1, '-');
} // END - if
// Add the entry
SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_yoomedia_reload` (`type`,`y_id`,`y_reload`) VALUES ('%s',%s,%s)",
- array($mode, bigintval($data['id']), bigintval($data['reload'])), __FUNCTION__, __LINE__);
+ array($mode, bigintval($data['id']), bigintval($data['reload'])), __FUNCTION__, __LINE__);
} // END - if
}
return $mode;
}
-//
+// Extract code from response
+function YOOMEDIA_GET_ERRORCODE_FROM_RESULT (array $response) {
+ // Bad code as default
+ $code = -999;
+
+ // Which response should we parse?
+ if (isset($response[8])) {
+ // Use error code from element 8 (mostly API errors)
+ $codeArray = explode("<br>", $response[8]);
+
+ // Use only the first element
+ $code = bigintval($codeArray[0]);
+ } elseif (isset($response[0]['id'])) {
+ // Begin with extraction
+ $codeArray = explode(" ", $response[0]['id']);
+ $code = $codeArray[0];
+ $codeArray = explode("<br />", $code);
+ $code = $codeArray[0];
+ $codeArray = explode("<br>", $code);
+ $code = $codeArray[0];
+
+ // Remove all new-line characters
+ $codeArray = explode("\n", $code);
+ $code = $codeArray[0];
+
+ // Remove carrige-return
+ $code = str_replace("\n", '', $code);
+ } else {
+ // Should not happen!
+ DEBUG_LOG(__FUNCTION__, __LINE__, "Cannot parse response. Raw response=" . base64_encode(serialize($response)));
+ }
+
+ // Return error code
+ return $code;
+}
+
+// [EOF]
?>