]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/surfbar_functions.php
Added missing wrapper for 'auto_purge' configuration
[mailer.git] / inc / libs / surfbar_functions.php
index 7a0760d4054ddd3356f56e9062b429571151fbf5..65f9614cedba0cc281c995383d99760807299698 100644 (file)
@@ -45,7 +45,7 @@ if (!defined('__SECURITY')) {
 //------------------------------------------------------------------------------
 
 // Admin has added an URL with given user id and so on
-function doSurfbarAdminAddUrl ($url, $limit, $reload) {
+function doSurfbarAdminAddUrl ($url, $limit, $reload, $waiting) {
        // Do some pre-checks
        if (!isAdmin()) {
                // Not an admin
@@ -71,10 +71,14 @@ function doSurfbarAdminAddUrl ($url, $limit, $reload) {
                // Invalid amount entered
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s: Invalid reload entered.", $url, $limit, $reload));
                return FALSE;
+       } elseif ('' . ($waiting + 0) . '' != '' . $waiting . '') {
+               // Invalid amount entered
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,waiting=%s: Invalid waiting entered.", $url, $limit, $waiting));
+               return FALSE;
        }
 
        // Register the new URL
-       return doSurfbarRegisterUrl($url, 0, 'ACTIVE', 'unlock', array('limit' => $limit, 'reload' => $reload));
+       return doSurfbarRegisterUrl($url, 0, 'ACTIVE', 'unlock', array('limit' => $limit, 'reload' => $reload, 'waiting' => $waiting));
 }
 
 // Admin unlocked an email so we can migrate the URL
@@ -229,19 +233,19 @@ function doSurfbarMemberByFormData ($formData, $urlArray) {
        // Is this a member?
        if (!isMember()) {
                // No member!
-               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: isMember()=false');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: isMember()=false');
                return FALSE;
        } elseif ((!isset($formData['url_id'])) || (!isset($formData['action']))) {
                // Important form elements are missing!
-               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Invalid form data, required field id/action not found');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Invalid form data, required field id/action not found');
                return FALSE;
        } elseif (!isset($urlArray[$formData['url_id']])) {
                // Id not found in cache
-               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Field url_id not found in cache');
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Field url_id not found in cache');
                return FALSE;
        } elseif (!isSurfbarMemberActionStatusValid($formData['action'], $urlArray[$formData['url_id']]['url_status'])) {
                // Action not allowed for current URL status
-               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Action not allowed to perform. action=' . $formData['action'] . ',url_status=' . $urlArray[$formData['url_id']]['url_status'] . ',url_id=' . $formData['url_id']);
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Action not allowed to perform. action=' . $formData['action'] . ',url_status=' . $urlArray[$formData['url_id']]['url_status'] . ',url_id=' . $formData['url_id']);
                return FALSE;
        }
 
@@ -597,7 +601,7 @@ function getSurfbarUrlData ($searchTerm, $column = 'url_id', $order = 'url_id',
        // If the column is 'url_id' there can be only one entry
        $limit = '';
        if ($column == 'url_id') {
-               $limit = "LIMIT 1";
+               $limit = 'LIMIT 1';
        } // END - if
 
        // Look up the record
@@ -614,7 +618,8 @@ function getSurfbarUrlData ($searchTerm, $column = 'url_id', $order = 'url_id',
        `url_lock_reason`,
        `url_views_max`,
        `url_views_allowed`,
-       `url_fixed_reload`
+       `url_fixed_reload`,
+       `url_fixed_waiting`
 FROM
        `{?_MYSQL_PREFIX?}_surfbar_urls`
 WHERE
@@ -673,6 +678,9 @@ function doSurfbarRegisterUrl ($url, $userid, $status = 'PENDING', $addMode = 'r
        if (!isset($content['reload'])) {
                $content['reload'] = '0';
        } // END - if
+       if (!isset($content['waiting'])) {
+               $content['waiting'] = '0';
+       } // END - if
 
        // Insert the URL into database
        $content['insert_id'] = insertSurfbarUrlByArray($content);
@@ -707,14 +715,15 @@ function insertSurfbarUrlByArray ($urlData) {
        } // END - if
 
        // Just run the insert query for now
-       SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_urls` (`url_userid`, `url`, `url_status`, `url_views_max`, `url_views_allowed`, `url_fixed_reload`) VALUES (%s,'%s','%s',%s,%s,%s)",
+       SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_urls` (`url_userid`, `url`, `url_status`, `url_views_max`, `url_views_allowed`, `url_fixed_reload`, `url_fixed_waiting`) VALUES (%s, '%s', '%s', %s, %s, %s, %s)",
                array(
                        $userid,
                        $urlData['url'],
                        $urlData['url_status'],
                        $urlData['limit'],
                        $urlData['limit'],
-                       $urlData['reload']
+                       $urlData['reload'],
+                       $urlData['waiting']
                ), __FUNCTION__, __LINE__
        );
 
@@ -859,7 +868,7 @@ function translateMemberSurfbarActionToSubmit ($action) {
 // Determine reward
 function determineSurfbarReward ($onlyMin = FALSE) {
        // Static values are default
-       $reward = getConfig('surfbar_static_reward');
+       $reward = getSurfbarStaticReward();
 
        // Is there static or dynamic?
        if (getSurfbarPaymentModel() == 'DYNAMIC') {
@@ -980,7 +989,7 @@ LIMIT 1",
        $isFull = ((getSurfbarUserLocks() == $total) && ($total > 0));
 
        // Return result
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userLocks=' . getSurfbarUserLocks() . ',total=' . $total . 'isFull=' . intval($isFull) . ' - EXIT!');
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userLocks=' . getSurfbarUserLocks() . ',total=' . $total . ',isFull=' . intval($isFull) . ' - EXIT!');
        return $isFull;
 }
 
@@ -1003,7 +1012,7 @@ function getSurfbarTotalUrls ($status = 'ACTIVE', $excludeUserId = NULL) {
 
        // Get amount from database
        $result = SQL_QUERY_ESC("SELECT
-       COUNT(`url_id`) AS cnt
+       COUNT(`url_id`) AS `cnt`
 FROM
        `{?_MYSQL_PREFIX?}_surfbar_urls`
 WHERE
@@ -1211,12 +1220,14 @@ function updateSurfbarSaltStatistics () {
        updateInsertSurfbarStatisticsRecord();
 
        // Simply store the salt from cache away in database...
-       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_surfbar_salts` SET `salts_last_salt`='%s' WHERE `salts_url_id`=%s AND `salts_userid`=%s LIMIT 1",
-               array(
-                       getSurfbarSalt(),
-                       getSurfbarId(),
-                       getMemberId()
-               ), __FUNCTION__, __LINE__);
+       SQL_QUERY("UPDATE
+       `{?_MYSQL_PREFIX?}_surfbar_salts`
+SET
+       `salts_last_salt`='{%pipe,getSurfbarSalt%}'
+WHERE
+       `salts_url_id`={%pipe,getSurfbarId%} AND
+       `salts_userid`={%pipe,getMemberId%}
+LIMIT 1", __FUNCTION__, __LINE__);
 
        // Debug message
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'salt=' . getSurfbarSalt() . ',id=' . getSurfbarId() . ',userid=' . getMemberId() . ',SQL_AFFECTEDROWS()=' . SQL_AFFECTEDROWS() . ' - UPDATE!');
@@ -1224,12 +1235,17 @@ function updateSurfbarSaltStatistics () {
        // Was that okay?
        if (SQL_HASZEROAFFECTED()) {
                // Insert missing entry!
-               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_salts` (`salts_url_id`, `salts_userid`, `salts_last_salt`) VALUES (%s, %s, '%s')",
-                       array(
-                               getSurfbarId(),
-                               getMemberId(),
-                               getSurfbarSalt()
-                       ), __FUNCTION__, __LINE__);
+               SQL_QUERY("INSERT INTO
+       `{?_MYSQL_PREFIX?}_surfbar_salts`
+(
+       `salts_url_id`,
+       `salts_userid`,
+       `salts_last_salt`
+) VALUES (
+       {%pipe,getSurfbarId%},
+       {%pipe,getMemberId%},
+       '{%pipe,getSurfbarSalt%}'
+)", __FUNCTION__, __LINE__);
        } // END - if
 
        // Debug message
@@ -1243,16 +1259,16 @@ function updateSurfbarSaltStatistics () {
 function ifSurfbarReloadLock ($urlId) {
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'id=' . $urlId . ' -  ENTERED!');
        // Ask the database
-       $result = SQL_QUERY_ESC("SELECT COUNT(`locks_id`) AS cnt
+       $result = SQL_QUERY_ESC('SELECT COUNT(`locks_id`) AS `cnt`
 FROM
        `{?_MYSQL_PREFIX?}_surfbar_locks`
 WHERE
        `locks_userid`=%s AND
        `locks_url_id`=%s AND
-       (UNIX_TIMESTAMP() - ".getSurfbarSurfLock().") < UNIX_TIMESTAMP(`locks_last_surfed`)
+       (UNIX_TIMESTAMP() - {%%pipe,getSurfbarSurfLock%%}) < UNIX_TIMESTAMP(`locks_last_surfed`)
 ORDER BY
        `locks_last_surfed` ASC
-LIMIT 1",
+LIMIT 1',
                array(getMemberId(), bigintval($urlId)), __FUNCTION__, __LINE__
        );
 
@@ -1371,16 +1387,16 @@ GROUP BY
 // Determine waiting time for one URL
 function determineSurfbarWaitingTime () {
        // Get fixed reload lock
-       $fixed = getSurfbarFixedReload();
+       $fixed = getSurfbarFixedWaitingTime();
 
-       // Is the fixed reload time set?
+       // Is the URL's fixed waiting time set?
        if ($fixed > 0) {
                // Return it
                return $fixed;
        } // END - if
 
        // Static time is default
-       $time = getConfig('surfbar_static_time');
+       $time = getSurfbarStaticTime();
 
        // Which payment model do we have?
        if (getSurfbarPaymentModel() == 'DYNAMIC') {
@@ -1587,7 +1603,7 @@ ORDER BY
 function getSurfbarMaximumRandom ($userids, $add) {
        // Count max availabe entries
        $result = SQL_QUERY("SELECT
-       sbu.url_id AS cnt
+       sbu.url_id AS `cnt`
 FROM
        `{?_MYSQL_PREFIX?}_surfbar_urls` AS sbu
 LEFT JOIN
@@ -1816,7 +1832,7 @@ LIMIT 1",
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count('.count($GLOBALS['surfbar_cache']).') - AFTER', FALSE);
 
                // Determine waiting time
-               $GLOBALS['surfbar_cache']['time'] = determineSurfbarWaitingTime();
+               $GLOBALS['surfbar_cache']['waiting'] = determineSurfbarWaitingTime();
 
                // Is the last salt there?
                if (is_null($GLOBALS['surfbar_cache']['salts_last_salt'])) {
@@ -1933,6 +1949,102 @@ function getSurfbarStatsReload () {
        return $GLOBALS[__FUNCTION__];
 }
 
+// "Getter" for surfbar_restart_time
+function getSurfbarRestartTime () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_restart_time');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for surfbar_auto_start
+function getSurfbarAutoStart () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_auto_start');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// Checks whether auto-start is enabled
+function isSurfbarAutoStartEnabled () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = (getSurfbarAutoStart() == 'Y');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for surfbar_daily_counter
+function getSurfbarDailyCounter () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_daily_counter');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for surfbar_yester_counter
+function getSurfbarYesterCounter () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_yester_counter');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for surfbar_weekly_counter
+function getSurfbarWeeklyCounter () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_weekly_counter');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for surfbar_monthly_counter
+function getSurfbarMonthlyCounter () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_monthly_counter');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for surfbar_total_counter
+function getSurfbarTotalCounter () {
+       // Is there cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_total_counter');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
 //------------------------------------------------------------------------------
 //                             Template helper functions
 //------------------------------------------------------------------------------
@@ -2013,22 +2125,18 @@ function initSurfbar () {
 
 // Private getter for data elements
 function getSurfbarData ($element) {
+       // Debug message
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ' - ENTERED!');
 
        // Default is null
        $data = NULL;
 
        // Is the entry there?
-       if (!isset($GLOBALS['surfbar_cache'][$element])) {
-               print('surfbar_cache=<pre>');
-               print_r($GLOBALS['surfbar_cache']);
-               print('</pre>');
-               reportBug(__FUNCTION__, __LINE__, 'Element ' . $element . ' not found.');
+       if (isset($GLOBALS['surfbar_cache'][$element])) {
+               // Then take it
+               $data = $GLOBALS['surfbar_cache'][$element];
        } // END - if
 
-       // Then take it
-       $data = $GLOBALS['surfbar_cache'][$element];
-
        // Return result
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . $element . ']=[' . gettype($data) . ']' . $data . ' - EXIT!');
        return $data;
@@ -2077,9 +2185,9 @@ function getSurfbarUserLocks () {
 }
 
 // Getter for reload time
-function getSurfbarReloadTime () {
+function getSurfbarWaitingTime () {
        // Get data element and return its contents
-       return getSurfbarData('time');
+       return getSurfbarData('waiting');
 }
 
 // Getter for allowed views
@@ -2100,6 +2208,12 @@ function getSurfbarFixedReload () {
        return getSurfbarData('url_fixed_reload');
 }
 
+// Getter for fixed waiting time
+function getSurfbarFixedWaitingTime () {
+       // Get data element and return its contents
+       return getSurfbarData('url_fixed_waiting');
+}
+
 // Getter for surf lock
 function getSurfbarSurfLock () {
        // Get data element and return its contents