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 YOOMEDIA_TEST_CONFIG ($data) {
50 // Transfer config data
51 $_CONFIG = merge_array($_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: ".getConfig('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) {
79 // Init response array
82 // Enougth queries left?
83 if ((getConfig('yoomedia_requests_remain') > 0) || (!$countQuery)) {
84 // Prepare the low-level request
85 $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",
87 bigintval(getConfig('yoomedia_id')),
88 bigintval(getConfig('yoomedia_sid')),
89 getConfig('yoomedia_passwd'),
90 bigintval(getConfig('yoomedia_tm_max_reload')),
91 bigintval(getConfig('yoomedia_tm_min_wait')),
92 bigintval(getConfig('yoomedia_tm_clicks_remain')),
93 bigintval(getConfig('yoomedia_tm_min_pay')),
94 bigintval(getConfig('yoomedia_erotic_allowed'))
98 $response = GET_URL($requestString);
100 // Shall we count the query as used?
102 // Then update the config!
103 UPDATE_CONFIG("yoomedia_requests_remain", 1, "-");
111 // "Getter" for a parsed result for all text mails. This means an array without
112 // the header lines will be returned
113 function YOOMEDIA_GET_PARSED_RESULT_TEXTMAILS () {
114 // Get the raw response
115 $response = YOOMEDIA_QUERY_API("out_textmail.php");
117 // Parse the response
118 $result = YOOMEDIA_PARSE_RESPONSE($response, "textmail");
124 // Parser function for Yoo!Media API responses
125 function YOOMEDIA_PARSE_RESPONSE ($response, $type) {
129 // Cut off the header
131 foreach ($response as $line) {
135 // Is this line empty?
142 // The result is now still raw, so we must split it up and trim spaces away
143 $responseLine = trim(implode("\n", $dummy));
145 // Last line should never be a pipe!
146 if (substr($responseLine, -1, 1) == "|") $responseLine = substr($responseLine, 0, -1);
148 // Now, explode all in one array
149 $dataArray = explode("|", $responseLine);
151 // Now make the result array with two dimensions
152 $cnt = 0; $entry = 0;
153 foreach ($dataArray as $line) {
155 $result[$entry][YOOMEDIA_TRANSLATE_INDEX($type, $cnt)] = $line;
157 // End of data of first entry reached?
159 // Then advance to next entry and reset counter
172 // Prepares a bonus mail for delivery. Works only if extension "bonus" is active
173 function YOOMEDIA_PREPARE_MAIL_DELIVERY ($data) {
178 } elseif (!EXT_IS_ACTIVE("bonus")) {
183 // Is the waiting time below one second? Then fix it to one (zero seconds are not yet supported!)
184 if ($data['wait'] < 1) $data['wait'] = 1;
186 // Half of waiting time is a good reward!
187 $data['reward'] = round($data['wait'] / 2 + 0.4);
189 // Is the reward below one?
190 if ($data['reward'] < 1) $data['reward'] = 1;
193 $data['sid'] = getConfig('yoomedia_sid');
195 // Add total receivers
196 $data['all'] = TRANSLATE_COMMA(GET_TOTAL_RECEIVERS());
199 $data['categories'] = ADD_CATEGORY_OPTIONS("normal");
202 LOAD_TEMPLATE("admin_send_yoomedia", false, $data);
205 // Adds the mail to the bonus mail pool
206 function YOOMEDIA_SEND_BONUS_MAIL ($data, $mode) {
211 } elseif (!EXT_IS_ACTIVE("bonus")) {
216 // Add dummy receiver to avoid notice
217 $data['receiver'] = 0;
219 // HTML or normal? (normal is default...)
221 if (($mode == "html") && (EXT_IS_ACTIVE("html"))) $type = "h";
224 $data['url'] = sprintf("http://www.yoomedia.de/code/%s-mail.php?id=%s&sid=%s",
230 // Lock this mail for new delivery
231 YOOMEDIA_RELOAD_LOCK($data, $mode);
233 // Call the lower function
234 ADD_NEW_BONUS_MAIL($data, $mode);
238 function YOOMEDIA_EXCLUDE_MAIL ($data, $mode) {
239 // Search for the entry
240 if (YOOMEDIA_CHECK_RELOAD($data['id'], $data['reload'], $mode) === false) {
241 // Convert mode for mails
242 $mode = YOOMEDIA_CONVERT_MODE($mode);
245 SQL_QUERY_ESC("INSERT INTO `"._MYSQL_PREFIX."_yoomedia_reload` (`type`,`y_id`,`y_reload`,`inserted`) VALUES ('%s',%s,%s,'0000-00-00 00:00')",
246 array($mode, bigintval($data['id']), bigintval($data['reload'])), __FILE__, __LINE__);
250 // Remove lock of given mail
251 function YOOMEDIA_UNLIST_MAIL ($data, $mode) {
252 // Convert mode for mails
253 $mode = YOOMEDIA_CONVERT_MODE($mode);
256 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `"._MYSQL_PREFIX."_yoomedia_reload` WHERE `type`='%s' AND `y_id`=%s LIMIT 1",
257 array($mode, bigintval($data['id'])), __FILE__, __LINE__);
260 // "Translates" the index number into an assosiative value
261 function YOOMEDIA_TRANSLATE_INDEX ($type, $index) {
262 global $yoomediaTranslationTable;
264 // Default is the index
267 // Is the element there?
268 if (isset($yoomediaTranslationTable[$type][$index])) {
270 $return = $yoomediaTranslationTable[$type][$index];
273 DEBUG_LOG(__FUNCTION__, __LINE__, " type={$type},index={$index} not found.");
280 // "Translate" error code
281 function YOOMEDIA_TRANSLATE_ERROR ($errorCode) {
282 global $yoomediaTranslationTable;
284 // Default is "failed"
287 // Is the entry there?
288 if (isset($yoomediaTranslationTable['error_codes'][$errorCode])) {
290 $return = $yoomediaTranslationTable['error_codes'][$errorCode];
292 // Log missing entries
293 DEBUG_LOG(__FUNCTION__, __LINE__, " errorCode={$errorCode}");
300 // Checks if the mail id is in reload lock
301 function YOOMEDIA_CHECK_RELOAD ($id, $reload, $type) {
302 // Default is not in reload lock
306 $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",
307 array($type, bigintval($id)), __FILE__, __LINE__);
310 if (SQL_NUMROWS($result) == 1) {
312 list($id, $time) = SQL_FETCHROW($result);
314 // Are we ready to sent again?
315 if (((time() - $time) >= ($reload * 60*60)) && ($time > 0)) {
317 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM "._MYSQL_PREFIX."_yoomedia_reload WHERE id=%s LIMIT 1",
318 array($id), __FILE__, __LINE__);
320 // Dont' sent again this mail
326 SQL_FREERESULT($result);
332 // Lock given mail down for reload lock
333 function YOOMEDIA_RELOAD_LOCK ($data, $mode) {
334 // Search for the entry
335 if (YOOMEDIA_CHECK_RELOAD($data['id'], $data['reload'], $mode) === false) {
336 // Convert mode for mails
337 $mode = YOOMEDIA_CONVERT_MODE($mode);
340 SQL_QUERY_ESC("INSERT INTO `"._MYSQL_PREFIX."_yoomedia_reload` (`type`,`y_id`,`y_reload`) VALUES ('%s',%s,%s)",
341 array($mode, bigintval($data['id']), bigintval($data['reload'])), __FILE__, __LINE__);
345 // Convert mode for mails
346 function YOOMEDIA_CONVERT_MODE ($mode) {
347 // Convert mode for normal/html