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) {
48 // Transfer config data
51 // Temporary allow maximum
52 setConfigEntry('yoomedia_tm_max_reload' , 1000);
53 setConfigEntry('yoomedia_tm_min_wait' , 0);
54 setConfigEntry('yoomedia_tm_clicks_remain', 10);
55 setConfigEntry('yoomedia_tm_min_pay' , 0);
56 setConfigEntry('yoomedia_erotic_allowed' , 1);
58 // Query the API with a test request without couting it
59 // If zero reply comes back the data is invalid!
60 $response = YOOMEDIA_QUERY_API("out_textmail.php", true); // @TODO Ask Yoo!Media for test script
62 // Log the response if failed
63 if (count($response) == 0) {
64 // Queries depleted (as we count here!)
65 DEBUG_LOG(__FUNCTION__, __LINE__, " Requested depleted. Maxmimum was: ".getConfig('yoomedia_requests_total'));
66 } elseif (count($response) <= 10) {
67 // Log serialized raw response
68 DEBUG_LOG(__FUNCTION__, __LINE__, " Raw response=".base64_encode(serialize($response)));
71 // Do we have some data there?
72 return (count($response) > 10);
75 // Queries the given Yoo!Media API 2.0 script
76 function YOOMEDIA_QUERY_API ($script, $countQuery = true) {
77 // Init response array
80 // Enougth queries left?
81 if ((getConfig('yoomedia_requests_remain') > 0) || (!$countQuery)) {
82 // Prepare the low-level request
83 $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",
85 bigintval(getConfig('yoomedia_id')),
86 bigintval(getConfig('yoomedia_sid')),
87 getConfig('yoomedia_passwd'),
88 bigintval(getConfig('yoomedia_tm_max_reload')),
89 bigintval(getConfig('yoomedia_tm_min_wait')),
90 bigintval(getConfig('yoomedia_tm_clicks_remain')),
91 bigintval(getConfig('yoomedia_tm_min_pay')),
92 bigintval(getConfig('yoomedia_erotic_allowed'))
96 $response = GET_URL($requestString);
98 // Shall we count the query as used?
100 // Then update the config!
101 UPDATE_CONFIG("yoomedia_requests_remain", 1, "-");
109 // "Getter" for a parsed result for all text mails. This means an array without
110 // the header lines will be returned
111 function YOOMEDIA_GET_PARSED_RESULT_TEXTMAILS () {
112 // Get the raw response
113 $response = YOOMEDIA_QUERY_API("out_textmail.php");
115 // Parse the response
116 $result = YOOMEDIA_PARSE_RESPONSE($response, "textmail");
122 // Parser function for Yoo!Media API responses
123 function YOOMEDIA_PARSE_RESPONSE ($response, $type) {
127 // Cut off the header
129 foreach ($response as $line) {
133 // Is this line empty?
140 // The result is now still raw, so we must split it up and trim spaces away
141 $responseLine = trim(implode("\n", $dummy));
143 // Last line should never be a pipe!
144 if (substr($responseLine, -1, 1) == "|") $responseLine = substr($responseLine, 0, -1);
146 // Now, explode all in one array
147 $dataArray = explode("|", $responseLine);
149 // Now make the result array with two dimensions
150 $cnt = 0; $entry = 0;
151 foreach ($dataArray as $line) {
153 $result[$entry][YOOMEDIA_TRANSLATE_INDEX($type, $cnt)] = $line;
155 // End of data of first entry reached?
157 // Then advance to next entry and reset counter
170 // Prepares a bonus mail for delivery. Works only if extension "bonus" is active
171 function YOOMEDIA_PREPARE_MAIL_DELIVERY ($data) {
176 } elseif (!EXT_IS_ACTIVE("bonus")) {
181 // Is the waiting time below one second? Then fix it to one (zero seconds are not yet supported!)
182 if ($data['wait'] < 1) $data['wait'] = 1;
184 // Half of waiting time is a good reward!
185 $data['reward'] = round($data['wait'] / 2 + 0.4);
187 // Is the reward below one?
188 if ($data['reward'] < 1) $data['reward'] = 1;
191 $data['sid'] = getConfig('yoomedia_sid');
193 // Add total receivers
194 $data['all'] = TRANSLATE_COMMA(GET_TOTAL_RECEIVERS());
197 $data['categories'] = ADD_CATEGORY_OPTIONS("normal");
200 LOAD_TEMPLATE("admin_send_yoomedia", false, $data);
203 // Adds the mail to the bonus mail pool
204 function YOOMEDIA_SEND_BONUS_MAIL ($data, $mode) {
209 } elseif (!EXT_IS_ACTIVE("bonus")) {
214 // Add dummy receiver to avoid notice
215 $data['receiver'] = 0;
217 // HTML or normal? (normal is default...)
219 if (($mode == "html") && (EXT_IS_ACTIVE("html"))) $type = "h";
222 $data['url'] = sprintf("http://www.yoomedia.de/code/%s-mail.php?id=%s&sid=%s",
228 // Lock this mail for new delivery
229 YOOMEDIA_RELOAD_LOCK($data, $mode);
231 // Call the lower function
232 ADD_NEW_BONUS_MAIL($data, $mode);
236 function YOOMEDIA_EXCLUDE_MAIL ($data, $mode) {
237 // Search for the entry
238 if (YOOMEDIA_CHECK_RELOAD($data['id'], $data['reload'], $mode) === false) {
239 // Convert mode for mails
240 $mode = YOOMEDIA_CONVERT_MODE($mode);
243 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_yoomedia_reload` (`type`,`y_id`,`y_reload`,`inserted`) VALUES ('%s',%s,%s,'0000-00-00 00:00')",
244 array($mode, bigintval($data['id']), bigintval($data['reload'])), __FUNCTION__, __LINE__);
248 // Remove lock of given mail
249 function YOOMEDIA_UNLIST_MAIL ($data, $mode) {
250 // Convert mode for mails
251 $mode = YOOMEDIA_CONVERT_MODE($mode);
254 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_yoomedia_reload` WHERE `type`='%s' AND `y_id`=%s LIMIT 1",
255 array($mode, bigintval($data['id'])), __FUNCTION__, __LINE__);
258 // "Translates" the index number into an assosiative value
259 function YOOMEDIA_TRANSLATE_INDEX ($type, $index) {
260 global $yoomediaTranslationTable;
262 // Default is the index
265 // Is the element there?
266 if (isset($yoomediaTranslationTable[$type][$index])) {
268 $return = $yoomediaTranslationTable[$type][$index];
271 DEBUG_LOG(__FUNCTION__, __LINE__, " type={$type},index={$index} not found.");
278 // "Translate" error code
279 function YOOMEDIA_TRANSLATE_ERROR ($errorCode) {
280 global $yoomediaTranslationTable;
282 // Default is "failed"
285 // Is the entry there?
286 if (isset($yoomediaTranslationTable['error_codes'][$errorCode])) {
288 $return = $yoomediaTranslationTable['error_codes'][$errorCode];
290 // Log missing entries
291 DEBUG_LOG(__FUNCTION__, __LINE__, " errorCode={$errorCode}");
298 // Checks if the mail id is in reload lock
299 function YOOMEDIA_CHECK_RELOAD ($id, $reload, $type) {
300 // Default is not in reload lock
304 $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",
305 array($type, bigintval($id)), __FUNCTION__, __LINE__);
308 if (SQL_NUMROWS($result) == 1) {
310 list($id, $time) = SQL_FETCHROW($result);
312 // Are we ready to sent again?
313 if (((time() - $time) >= ($reload * 60*60)) && ($time > 0)) {
315 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_yoomedia_reload` WHERE id=%s LIMIT 1",
316 array($id), __FUNCTION__, __LINE__);
318 // Dont' sent again this mail
324 SQL_FREERESULT($result);
330 // Lock given mail down for reload lock
331 function YOOMEDIA_RELOAD_LOCK ($data, $mode) {
332 // Search for the entry
333 if (YOOMEDIA_CHECK_RELOAD($data['id'], $data['reload'], $mode) === false) {
334 // Convert mode for mails
335 $mode = YOOMEDIA_CONVERT_MODE($mode);
338 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_yoomedia_reload` (`type`,`y_id`,`y_reload`) VALUES ('%s',%s,%s)",
339 array($mode, bigintval($data['id']), bigintval($data['reload'])), __FUNCTION__, __LINE__);
343 // Convert mode for mails
344 function YOOMEDIA_CONVERT_MODE ($mode) {
345 // Convert mode for normal/html