X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Flibs%2Fyoomedia_functions.php;h=441a008ea4605ba87a356d8e30f7aa91dc1a4a7a;hb=4d64a8575593f7cc8f69aec74d14c29ba6e8ef6c;hp=e236335de6ee403bcc76b168824ebc13e3999e67;hpb=5071030af40e69ca4284642f44758964e18f5be8;p=mailer.git diff --git a/inc/libs/yoomedia_functions.php b/inc/libs/yoomedia_functions.php index e236335de6..441a008ea4 100644 --- a/inc/libs/yoomedia_functions.php +++ b/inc/libs/yoomedia_functions.php @@ -54,7 +54,7 @@ function YOOMEDIA_TEST_CONFIG ($data) { 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); @@ -62,19 +62,34 @@ function YOOMEDIA_TEST_CONFIG ($data) { // 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 @@ -101,7 +116,7 @@ function YOOMEDIA_QUERY_API ($script, $countQuery = true) { $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 @@ -115,10 +130,10 @@ function YOOMEDIA_QUERY_API ($script, $countQuery = true) { // the header lines will be returned function YOOMEDIA_GET_PARSED_RESULT_TEXTMAILS () { // Get the raw response - $response = YOOMEDIA_QUERY_API("out_textmail.php"); + $response = YOOMEDIA_QUERY_API('out_textmail.php'); // Parse the response - $result = YOOMEDIA_PARSE_RESPONSE($response, "textmail"); + $result = YOOMEDIA_PARSE_RESPONSE($response, 'textmail'); // Return result return $result; @@ -280,8 +295,8 @@ function yoomediaTranslateIndex ($type, $index) { // "Translate" error code function yoomediaTranslateError ($errorCode) { - // Default is "failed" - $return = "failed"; + // Default is 'failed' + $return = 'failed'; // Is the entry there? if (isset($GLOBALS['translation_tables']['yoomedia']['error_codes'][$errorCode])) { @@ -289,6 +304,9 @@ function yoomediaTranslateError ($errorCode) { $return = $GLOBALS['translation_tables']['yoomedia']['error_codes'][$errorCode]; } else { // Log missing entries + print '
';
+		debug_print_backtrace();
+		die('
'); DEBUG_LOG(__FUNCTION__, __LINE__, " errorCode={$errorCode}"); } @@ -337,7 +355,7 @@ function YOOMEDIA_RELOAD_LOCK ($data, $mode) { // 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 } @@ -358,5 +376,41 @@ function YOOMEDIA_CONVERT_MODE ($mode) { 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("
", $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("
", $code); + $code = $codeArray[0]; + $codeArray = explode("
", $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] ?>