]> git.mxchange.org Git - mailer.git/blobdiff - inc/pool/pool-bonus.php
Caching of expensive PHP functions:
[mailer.git] / inc / pool / pool-bonus.php
index 5c39bca3c0602ad20fdfc886641405e705ff9671..c213c83e659721d5a9efbbff98924be00b4d758e 100644 (file)
@@ -18,6 +18,7 @@
  * svn:keywords Date Revision" (autoprobset!) at least!!!!!!            *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
+ * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -71,25 +72,25 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) {
                                array(bigintval($DATA['id'])), __FILE__, __LINE__);
 
                        // "Explode" all receivers into an array
-                       if (ereg(';', $DATA['receivers'])) {
+                       if (isInString(';', $DATA['receivers'])) {
                                // There's more than one receiver in the list...
-                               $RECEIVERS = explode(';', $DATA['receivers']);
+                               $receiverS = explode(';', $DATA['receivers']);
                        } elseif (!empty($DATA['points'])) {
                                // Only one user left
-                               $RECEIVERS = array($DATA['receivers']);
+                               $receiverS = array($DATA['receivers']);
                        } else {
                                // No users left
-                               $RECEIVERS = array(0);
+                               $receiverS = array(0);
                        }
-                       $dummy = $RECEIVERS;
+                       $dummy = $receiverS;
 
                        // Now, if we are good little boys and girls Santa Claus left us some user-ids.
                        // We can now send mails to them...
-                       foreach ($RECEIVERS as $key => $userid) {
+                       foreach ($receiverS as $key => $userid) {
                                // Load personal data
                                if (fetchUserData($userid)) {
                                        // The final receiver does exists so we can continue...
-                                       //* DEBUG: */ print("OK!/L:".__LINE__."<br />");
+                                       //* DEBUG: */ debugOutput('OK!/L:'.__LINE__);
 
                                        // Mark this user as "spammed" ;-) And place a line for him...
                                        if (removeReceiver($dummy, $key, $userid, $DATA['id'], $DATA['id'], true) == 'done') {
@@ -98,18 +99,8 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) {
                                                        if (isset($DATA[$key])) $DATA['text'] = str_replace($value, $DATA[$key], $DATA['text']);
                                                } // END - foreach
 
-                                               // Prepare content
-                                               $content = array(
-                                                       'id'       => $DATA['id'],
-                                                       'url'      => $DATA['url'],
-                                                       'time'     => createFancyTime($DATA['time']),
-                                                       'points'   => translateComma($DATA['points']),
-                                                       'category' => getCategory($DATA['cat_id']),
-                                                       'text'     => $DATA['text']
-                                               );
-
                                                // Prepare the mail
-                                               $mailText = loadEmailTemplate('bonus-mail', $content, $userid);
+                                               $mailText = loadEmailTemplate('bonus-mail', $DATA, $userid);
 
                                                // Send mail away
                                                if (isset($DATA['html_msg'])) {
@@ -123,16 +114,16 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) {
                                                // Count one up and remove entry from dummy array
                                                $GLOBALS['pool_cnt']++; unset($dummy[$key]);
 
-                                               if (getExtensionVersion('user') >= '0.1.4') {
+                                               if (isExtensionInstalledAndNewer('user', '0.1.4')) {
                                                        // Update mails received for receiver
-                                                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET emails_received=emails_received+1 WHERE `userid`=%s LIMIT 1",
+                                                       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET `emails_received`=`emails_received`+1 WHERE `userid`=%s LIMIT 1",
                                                        array(bigintval($userid)), __FILE__, __LINE__);
                                                } // END - if
 
                                                // Do we have send maximum mails?
-                                               if (($GLOBALS['pool_cnt'] >= getConfig('max_send')) || (countSelection($dummy) == '0')) {
+                                               if (($GLOBALS['pool_cnt'] >= getConfig('max_send')) || (countSelection($dummy) == 0)) {
                                                        // Yes, we have
-                                                       //* DEBUG: */ print("*EXIT/L:".__LINE__."<br />");
+                                                       //* DEBUG: */ debugOutput('*EXIT/L:'.__LINE__);
                                                        break;
                                                } // END - if
                                        } // END - if
@@ -140,46 +131,64 @@ if ($GLOBALS['pool_cnt'] < getConfig('max_send')) {
                        } // END - foreach
 
                        // Update mediadata if version is 0.0.4 or higher
-                       if (getExtensionVersion('mediadata') >= '0.0.4') {
+                       if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
                                // Update entry (or add missing
                                $P = $GLOBALS['pool_cnt'];
                                if (!empty($cnt2) && empty($GLOBALS['pool_cnt'])) $P = $cnt2;
-                               //* DEBUG: */ print("+MEDIA/L:".__LINE__.'/'.$P."+<br />");
-                               updateMediadataEntry(array("total_send", "bonus_send"), 'add', $P);
+                               //* DEBUG: */ debugOutput('+MEDIA/L:'.__LINE__.'/'.$P.'+');
+                               updateMediadataEntry(array('total_send', 'bonus_send'), 'add', $P);
                        } // END - if
 
                        // Close sending system
-                       //* DEBUG: */ print("-L:".__LINE__.'/'.countSelection($dummy)."-<br />");
-                       if (countSelection($dummy) == '0') {
+                       //* DEBUG: */ debugOutput('-L:'.__LINE__.'/'.countSelection($dummy).'-');
+                       if (countSelection($dummy) == 0) {
                                // Queue reached!
-                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `data_type`='SEND', `target_send`=0, `receivers`='' WHERE `id`=%s LIMIT 1",
-                               array(bigintval($DATA['id'])), __FILE__, __LINE__);
-                               //* DEBUG: */ print("*L:".__LINE__."*<br />");
+                               SQL_QUERY_ESC("UPDATE
+       `{?_MYSQL_PREFIX?}_bonus`
+SET
+       `data_type`='SEND',
+       `target_send`=0,
+       `receivers`=''
+WHERE
+       `id`=%s
+LIMIT 1",
+                                       array(bigintval($DATA['id'])), __FILE__, __LINE__);
+                               //* DEBUG: */ debugOutput('*L:'.__LINE__.'*');
 
                                // Update mediadata if version is 0.0.4 or higher
-                               if (getExtensionVersion('mediadata') >= '0.0.4') {
+                               if (isExtensionInstalledAndNewer('mediadata', '0.0.4')) {
                                        // Update entry (or add missing)
-                                       //* DEBUG: */ print("*MEDIA/L:".__LINE__."*<br />");
-                                       updateMediadataEntry(array("total_orders", "bonus_orders"), 'add', 1);
+                                       //* DEBUG: */ debugOutput('*MEDIA/L:'.__LINE__.'*');
+                                       updateMediadataEntry(array('total_orders', 'bonus_orders'), 'add', 1);
                                } // END - if
                        } elseif ($GLOBALS['pool_cnt'] >= getConfig('max_send')) {
                                // Update bonus pool
-                               SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_bonus` SET `data_type`='NEW', `target_send`=%s, `receivers`='%s' WHERE `id`=%s LIMIT 1",
-                               array(countSelection($dummy), implode(';', $dummy), bigintval($DATA['id'])), __FILE__, __LINE__);
-                               //* DEBUG: */ print("*L:".__LINE__."<pre>");
-                               //* DEBUG: */ print(print_r($dummy, true));
-                               //* DEBUG: */ print("</pre>\n!!!<br />");
+                               SQL_QUERY_ESC("UPDATE
+       `{?_MYSQL_PREFIX?}_bonus`
+SET
+       `data_type`='NEW',
+       `target_send`=%s,
+       `receivers`='%s'
+WHERE
+       `id`=%s
+LIMIT 1",
+                                       array(
+                                               countSelection($dummy),
+                                               implode(';', $dummy),
+                                               bigintval($DATA['id'])
+                                       ), __FILE__, __LINE__);
+                               //* DEBUG: */ debugOutput('*L:'.__LINE__.'<pre>'.print_r($dummy, true).'</pre>!!!');
                                break;
                        }
-               }
-       }
+               } // END - while
+       } // END - if
 
        // Free memory
        SQL_FREERESULT($result_bonus);
 
        // Remove variable
        unset($mailText);
-}
+} // END - if
 
-//
+// [EOF]
 ?>