2 /************************************************************************
3 * MXChange v0.2.1 Start: 10/10/2008 *
4 * =============== Last change: 10/10/2008 *
6 * -------------------------------------------------------------------- *
7 * File : yoomedia_functions.php *
8 * -------------------------------------------------------------------- *
9 * Short description : Special functions for yoomedia extension *
10 * -------------------------------------------------------------------- *
11 * Kurzbeschreibung : Spezielle Funktion fuer Yoo!Media-Erweiterung *
12 * -------------------------------------------------------------------- *
14 * -------------------------------------------------------------------- *
15 * Copyright (c) 2003 - 2008 by Roland Haeder *
16 * For more information visit: http://www.mxchange.org *
18 * This program is free software; you can redistribute it and/or modify *
19 * it under the terms of the GNU General Public License as published by *
20 * the Free Software Foundation; either version 2 of the License, or *
21 * (at your option) any later version. *
23 * This program is distributed in the hope that it will be useful, *
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
26 * GNU General Public License for more details. *
28 * You should have received a copy of the GNU General Public License *
29 * along with this program; if not, write to the Free Software *
30 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
32 ************************************************************************/
34 // Some security stuff...
35 if (!defined('__SECURITY')) {
36 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), "/inc") + 4) . "/security.php";
40 // Test if the extension settings did work
41 function YOOMEDIDA_TEST_CONFIG ($data) {
50 // Transfer config data
51 $_CONFIG = array_merge($_CONFIG, $data);
53 // Temporary allow maximum
54 $_CONFIG['yoomedia_tm_max_reload'] = 1000;
55 $_CONFIG['yoomedia_tm_min_wait'] = 0;
56 $_CONFIG['yoomedia_tm_clicks_remain'] = 10;
57 $_CONFIG['yoomedia_tm_min_pay'] = 0;
58 $_CONFIG['yoomedia_erotic_allowed'] = 1;
60 // Query the API with a test request without couting it
61 // If zero reply comes back the data is invalid!
62 $response = YOOMEDIA_QUERY_API("out_textmail.php", true); // TODO Ask Yoo!Media for test script
64 // Log the response if failed
65 if (count($response) == 0) {
66 // Queries depleted (as we count here!)
67 DEBUG_LOG(__FUNCTION__, __LINE__, " Requested depleted. Maxmimum was: ".$_CONFIG['yoomedia_requests_total']);
68 } elseif (count($response) <= 10) {
69 // Log serialized raw response
70 DEBUG_LOG(__FUNCTION__, __LINE__, " Raw response=".base64_encode(serialize($response)));
73 // Do we have some data there?
74 return (count($response) > 10);
77 // Queries the given Yoo!Media API 2.0 script
78 function YOOMEDIA_QUERY_API ($script, $countQuery = true) {
81 // Init response array
84 // Enougth queries left?
85 if (($_CONFIG['yoomedia_requests_remain'] > 0) || (!$countQuery)) {
86 // Prepare the low-level request
87 $requestString = sprintf("http://www.yoomedia.de/interface_2.0/%s?id=%s&sid=%s&pw=%s&reload=%s&ma=%s&uebrig=%s&verguetung=%s&erotik=%s",
89 bigintval($_CONFIG['yoomedia_id']),
90 bigintval($_CONFIG['yoomedia_sid']),
91 $_CONFIG['yoomedia_passwd'],
92 bigintval($_CONFIG['yoomedia_tm_max_reload']),
93 bigintval($_CONFIG['yoomedia_tm_min_wait']),
94 bigintval($_CONFIG['yoomedia_tm_clicks_remain']),
95 bigintval($_CONFIG['yoomedia_tm_min_pay']),
96 bigintval($_CONFIG['yoomedia_erotic_allowed'])
100 $response = GET_URL($requestString);
102 // Shall we count the query as used?
104 // Then update the config!
105 UPDATE_CONFIG("yoomedia_requests_remain", 1, "-");
113 // "Getter" for a parsed result for all text mails. This means an array without
114 // the header lines will be returned
115 function YOOMEDIA_GET_PARSED_RESULT_TEXTMAILS () {
116 // Get the raw response
117 $response = YOOMEDIA_QUERY_API("out_textmail.php");
119 // Parse the response
120 $result = YOOMEDIA_PARSE_RESPONSE($response, "textmail");
126 // Parser function for Yoo!Media API responses
127 function YOOMEDIA_PARSE_RESPONSE ($response, $type) {
131 // Cut off the header
133 foreach ($response as $line) {
137 // Is this line empty?
144 // The result is now still raw, so we must split it up and trim spaces away
145 $responseLine = trim(implode("\n", $dummy));
147 // Last line should never be a pipe!
148 if (substr($responseLine, -1, 1) == "|") $responseLine = substr($responseLine, 0, -1);
150 // Now, explode all in one array
151 $dataArray = explode("|", $responseLine);
153 // Now make the result array with two dimensions
154 $cnt = 0; $entry = 0;
155 foreach ($dataArray as $line) {
157 $result[$entry][YOOMEDIA_TRANSLATE_INDEX($type, $cnt)] = $line;
159 // End of data of first entry reached?
161 // Then advance to next entry and reset counter
174 // Prepares a bonus mail for delivery. Works only if extension "bonus" is active
175 function YOOMEDIA_PREPARE_MAIL_DELIVERY ($data) {
182 } elseif (!EXT_IS_ACTIVE("bonus")) {
187 // Is the waiting time below one second? Then fix it to one (zero seconds are not yet supported!)
188 if ($data['wait'] < 1) $data['wait'] = 1;
190 // Half of waiting time is a good reward!
191 $data['reward'] = round($data['wait'] / 2 + 0.4);
193 // Is the reward below one?
194 if ($data['reward'] < 1) $data['reward'] = 1;
197 $data['sid'] = $_CONFIG['yoomedia_sid'];
199 // Add total receivers
200 $data['all'] = TRANSLATE_COMMA(GET_TOTAL_RECEIVERS());
203 $data['categories'] = ADD_CATEGORY_OPTIONS("normal");
206 LOAD_TEMPLATE("admin_send_yoomedia", false, $data);
209 // Adds the mail to the bonus mail pool
210 function YOOMEDIA_SEND_BONUS_MAIL ($data, $mode) {
217 } elseif (!EXT_IS_ACTIVE("bonus")) {
222 // Add dummy receiver to avoid notice
223 $data['receiver'] = 0;
225 // HTML or normal? (normal is default...)
227 if (($mode == "html") && (EXT_IS_ACTIVE("html"))) $type = "h";
230 $data['url'] = sprintf("http://www.yoomedia.de/code/%s-mail.php?id=%s&sid=%s",
236 // Lock this mail for new delivery
237 YOOMEDIA_RELOAD_LOCK($data, $mode);
239 // Call the lower function
240 ADD_NEW_BONUS_MAIL($data, $mode);
244 function YOOMEDIA_EXCLUDE_MAIL ($data, $mode) {
245 // Search for the entry
246 if (YOOMEDIA_CHECK_RELOAD($data['id'], $data['reload'], $mode) === false) {
247 // Convert mode for mails
248 $mode = YOOMEDIA_CONVERT_MODE($mode);
251 $result = SQL_QUERY_ESC("INSERT INTO `"._MYSQL_PREFIX."_yoomedia_reload` (`type`,`y_id`,`y_reload`,`inserted`) VALUES ('%s',%s,%s,'0000-00-00 00:00')",
252 array($mode, bigintval($data['id']), bigintval($data['reload'])), __FILE__, __LINE__);
256 // Remove lock of given mail
257 function YOOMEDIA_UNLIST_MAIL ($data, $mode) {
258 // Convert mode for mails
259 $mode = YOOMEDIA_CONVERT_MODE($mode);
262 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_yoomedia_reload` WHERE `type`='%s' AND `y_id`=%s LIMIT 1",
263 array($mode, bigintval($data['id'])), __FILE__, __LINE__);
266 // "Translates" the index number into an assosiative value
267 function YOOMEDIA_TRANSLATE_INDEX ($type, $index) {
268 global $yoomediaTranslationTable;
270 // Default is the index
273 // Is the element there?
274 if (isset($yoomediaTranslationTable[$type][$index])) {
276 $return = $yoomediaTranslationTable[$type][$index];
279 DEBUG_LOG(__FUNCTION__, __LINE__, " type={$type},index={$index} not found.");
286 // "Translate" error code
287 function YOOMEDIA_TRANSLATE_ERROR ($errorCode) {
288 global $yoomediaTranslationTable;
290 // Default is "failed"
293 // Is the entry there?
294 if (isset($yoomediaTranslationTable['error_codes'][$errorCode])) {
296 $return = $yoomediaTranslationTable['error_codes'][$errorCode];
298 // Log missing entries
299 DEBUG_LOG(__FUNCTION__, __LINE__, " errorCode={$errorCode}");
306 // Checks if the mail id is in reload lock
307 function YOOMEDIA_CHECK_RELOAD ($id, $reload, $type) {
308 // Default is not in reload lock
312 $result = SQL_QUERY_ESC("SELECT `id`, UNIX_TIMESTAMP(`inserted`) AS inserted FROM `"._MYSQL_PREFIX."_yoomedia_reload` WHERE `type`='%s' AND `y_id`=%s LIMIT 1",
313 array($type, bigintval($id)), __FILE__, __LINE__);
316 if (SQL_NUMROWS($result) == 1) {
318 list($id, $time) = SQL_FETCHROW($result);
320 // Are we ready to sent again?
321 if (((time() - $time) >= ($reload * 60*60)) && ($time > 0)) {
323 $result = SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_yoomedia_reload WHERE id=%s LIMIT 1",
324 array($id), __FILE__, __LINE__);
326 // Dont' sent again this mail
332 SQL_FREERESULT($result);
338 // Lock given mail down for reload lock
339 function YOOMEDIA_RELOAD_LOCK ($data, $mode) {
340 // Search for the entry
341 if (YOOMEDIA_CHECK_RELOAD($data['id'], $data['reload'], $mode) === false) {
342 // Convert mode for mails
343 $mode = YOOMEDIA_CONVERT_MODE($mode);
346 $result = SQL_QUERY_ESC("INSERT INTO `"._MYSQL_PREFIX."_yoomedia_reload` (`type`,`y_id`,`y_reload`) VALUES ('%s',%s,%s)",
347 array($mode, bigintval($data['id']), bigintval($data['reload'])), __FILE__, __LINE__);
351 // Convert mode for mails
352 function YOOMEDIA_CONVERT_MODE ($mode) {
353 // Convert mode for normal/html