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 * -------------------------------------------------------------------- *
15 * $Tag:: 0.2.1-FINAL $ *
17 * Needs to be in all Files and every File needs "svn propset *
18 * svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
19 * -------------------------------------------------------------------- *
20 * Copyright (c) 2003 - 2008 by Roland Haeder *
21 * For more information visit: http://www.mxchange.org *
23 * This program is free software; you can redistribute it and/or modify *
24 * it under the terms of the GNU General Public License as published by *
25 * the Free Software Foundation; either version 2 of the License, or *
26 * (at your option) any later version. *
28 * This program is distributed in the hope that it will be useful, *
29 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
30 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
31 * GNU General Public License for more details. *
33 * You should have received a copy of the GNU General Public License *
34 * along with this program; if not, write to the Free Software *
35 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, *
37 ************************************************************************/
39 // Some security stuff...
40 if (!defined('__SECURITY')) {
41 $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
45 // Test if the extension settings did work
46 function YOOMEDIA_TEST_CONFIG ($data) {
53 // Transfer config data
56 // Temporary allow maximum
57 setConfigEntry('yoomedia_tm_max_reload' , 1000);
58 setConfigEntry('yoomedia_tm_min_wait' , 0);
59 setConfigEntry('yoomedia_tm_clicks_remain', 10);
60 setConfigEntry('yoomedia_tm_min_pay' , 0);
61 setConfigEntry('yoomedia_erotic_allowed' , 1);
63 // Query the API with a test request without couting it
64 // If zero reply comes back the data is invalid!
65 $response = YOOMEDIA_QUERY_API("out_textmail.php", true); // @TODO Ask Yoo!Media for test script
67 // Log the response if failed
68 if (count($response) == 0) {
69 // Queries depleted (as we count here!)
70 DEBUG_LOG(__FUNCTION__, __LINE__, " Requested depleted. Maxmimum was: ".getConfig('yoomedia_requests_total'));
71 } elseif (count($response) <= 10) {
72 // Log serialized raw response
73 DEBUG_LOG(__FUNCTION__, __LINE__, " Raw response=".base64_encode(serialize($response)));
76 // Do we have some data there?
77 return (count($response) > 10);
80 // Queries the given Yoo!Media API 2.0 script
81 function YOOMEDIA_QUERY_API ($script, $countQuery = true) {
82 // Init response array
85 // Enougth queries left?
86 if ((getConfig('yoomedia_requests_remain') > 0) || (!$countQuery)) {
87 // Prepare the low-level request
88 $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",
90 getConfig(('yoomedia_id')),
91 getConfig(('yoomedia_sid')),
92 getConfig('yoomedia_passwd'),
93 getConfig(('yoomedia_tm_max_reload')),
94 getConfig(('yoomedia_tm_min_wait')),
95 getConfig(('yoomedia_tm_clicks_remain')),
96 getConfig(('yoomedia_tm_min_pay')),
97 getConfig(('yoomedia_erotic_allowed'))
101 $response = sendGetRequest($requestString);
103 // Shall we count the query as used?
105 // Then update the config!
106 updateConfiguration('yoomedia_requests_remain', 1, '-');
114 // "Getter" for a parsed result for all text mails. This means an array without
115 // the header lines will be returned
116 function YOOMEDIA_GET_PARSED_RESULT_TEXTMAILS () {
117 // Get the raw response
118 $response = YOOMEDIA_QUERY_API("out_textmail.php");
120 // Parse the response
121 $result = YOOMEDIA_PARSE_RESPONSE($response, "textmail");
127 // Parser function for Yoo!Media API responses
128 function YOOMEDIA_PARSE_RESPONSE ($response, $type) {
132 // Cut off the header
134 foreach ($response as $line) {
138 // Is this line empty?
145 // The result is now still raw, so we must split it up and trim spaces away
146 $responseLine = trim(implode("\n", $dummy));
148 // Last line should never be a pipe!
149 if (substr($responseLine, -1, 1) == "|") $responseLine = substr($responseLine, 0, -1);
151 // Now, explode all in one array
152 $dataArray = explode("|", $responseLine);
154 // Now make the result array with two dimensions
155 $cnt = 0; $entry = 0;
156 foreach ($dataArray as $line) {
158 $result[$entry][yoomediaTranslateIndex($type, $cnt)] = $line;
160 // End of data of first entry reached?
162 // Then advance to next entry and reset counter
175 // Prepares a bonus mail for delivery. Works only if extension 'bonus' is active
176 function YOOMEDIA_PREPARE_MAIL_DELIVERY ($data) {
181 } elseif (!EXT_IS_ACTIVE('bonus')) {
186 // Is the waiting time below one second? Then fix it to one (zero seconds are not yet supported!)
187 if ($data['wait'] < 1) $data['wait'] = 1;
189 // Half of waiting time is a good reward!
190 $data['reward'] = round($data['wait'] / 2 + 0.4);
192 // Is the reward below one?
193 if ($data['reward'] < 1) $data['reward'] = 1;
196 $data['sid'] = getConfig('yoomedia_sid');
198 // Add total receivers
199 $data['all'] = translateComma(getTotalReceivers());
202 $data['categories'] = generateCategoryOptionsList('normal');
205 LOAD_TEMPLATE("admin_send_yoomedia", false, $data);
208 // Adds the mail to the bonus mail pool
209 function YOOMEDIA_SEND_BONUS_MAIL ($data, $mode) {
214 } elseif (!EXT_IS_ACTIVE('bonus')) {
219 // Add dummy receiver to avoid notice
220 $data['receiver'] = 0;
222 // HTML or normal? (normal is default...)
224 if (($mode == 'html') && (EXT_IS_ACTIVE('html_mail'))) $type = 'h';
227 $data['url'] = sprintf("http://www.yoomedia.de/code/%s-mail.php?id=%s&sid=%s",
233 // Lock this mail for new delivery
234 YOOMEDIA_RELOAD_LOCK($data, $mode);
236 // Call the lower function
237 addNewBonusMail($data, $mode);
241 function YOOMEDIA_EXCLUDE_MAIL ($data, $mode) {
242 // Search for the entry
243 if (YOOMEDIA_CHECK_RELOAD($data['id'], $data['reload'], $mode) === false) {
244 // Convert mode for mails
245 $mode = YOOMEDIA_CONVERT_MODE($mode);
248 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_yoomedia_reload` (`type`,`y_id`,`y_reload`,`inserted`) VALUES ('%s',%s,%s,'0000-00-00 00:00')",
249 array($mode, bigintval($data['id']), bigintval($data['reload'])), __FUNCTION__, __LINE__);
253 // Remove lock of given mail
254 function YOOMEDIA_UNLIST_MAIL ($data, $mode) {
255 // Convert mode for mails
256 $mode = YOOMEDIA_CONVERT_MODE($mode);
259 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_yoomedia_reload` WHERE `type`='%s' AND `y_id`=%s LIMIT 1",
260 array($mode, bigintval($data['id'])), __FUNCTION__, __LINE__);
263 // "Translates" the index number into an assosiative value
264 function yoomediaTranslateIndex ($type, $index) {
265 // Default is the index
268 // Is the element there?
269 if (isset($GLOBALS['translation_tables']['yoomedia'][$type][$index])) {
271 $return = $GLOBALS['translation_tables']['yoomedia'][$type][$index];
274 DEBUG_LOG(__FUNCTION__, __LINE__, " type={$type},index={$index} not found.");
281 // "Translate" error code
282 function yoomediaTranslateError ($errorCode) {
283 // Default is "failed"
286 // Is the entry there?
287 if (isset($GLOBALS['translation_tables']['yoomedia']['error_codes'][$errorCode])) {
289 $return = $GLOBALS['translation_tables']['yoomedia']['error_codes'][$errorCode];
291 // Log missing entries
292 DEBUG_LOG(__FUNCTION__, __LINE__, " errorCode={$errorCode}");
299 // Checks if the mail id is in reload lock
300 function YOOMEDIA_CHECK_RELOAD ($id, $reload, $type) {
301 // Default is not in reload lock
305 $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",
306 array($type, bigintval($id)), __FUNCTION__, __LINE__);
309 if (SQL_NUMROWS($result) == 1) {
311 list($id, $time) = SQL_FETCHROW($result);
313 // Are we ready to sent again?
314 if (((time() - $time) >= ($reload * 60*60)) && ($time > 0)) {
316 SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_yoomedia_reload` WHERE `id`=%s LIMIT 1",
317 array($id), __FUNCTION__, __LINE__);
319 // Dont' sent again this mail
325 SQL_FREERESULT($result);
331 // Lock given mail down for reload lock
332 function YOOMEDIA_RELOAD_LOCK ($data, $mode) {
333 // Search for the entry
334 if (YOOMEDIA_CHECK_RELOAD($data['id'], $data['reload'], $mode) === false) {
335 // Convert mode for mails
336 $mode = YOOMEDIA_CONVERT_MODE($mode);
339 SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_yoomedia_reload` (`type`,`y_id`,`y_reload`) VALUES ('%s',%s,%s)",
340 array($mode, bigintval($data['id']), bigintval($data['reload'])), __FUNCTION__, __LINE__);
344 // Convert mode for mails
345 function YOOMEDIA_CONVERT_MODE ($mode) {
346 // Convert mode for normal/html