]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/surfbar_functions.php
Fixed bug in surfbar member list
[mailer.git] / inc / libs / surfbar_functions.php
index 3eecd87c8eae46c76ba60ae70c8ae968ef92c4f1..f04a3b7a91a02029d66ab4a4b7addc73290e7321 100644 (file)
@@ -51,21 +51,27 @@ function SURFBAR_ADMIN_ADD_URL ($url, $limit, $reload) {
        // Do some pre-checks
        if (!IS_ADMIN()) {
                // Not an admin
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Not admin.", $url, $limit, $reload));
                return false;
        } elseif (!isUrlValid($url)) {
                // URL invalid
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Invalid URL.", $url, $limit, $reload));
                return false;
        } elseif (SURFBAR_LOOKUP_BY_URL($url, '0')) {
                // URL already found in surfbar!
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Already added.", $url, $limit, $reload));
                return false;
        } elseif (!SURFBAR_IF_USER_BOOK_MORE_URLS()) {
                // No more allowed!
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : No more URLs allowed.", $url, $limit, $reload));
                return false;
-       } elseif (''.($limit + 0).'' != ''.$limit.'') {
-               // Invalid amount entered
+       } elseif ('' . ($limit + 0) . '' != '' . $limit . '') {
+               // Invalid limit entered
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Invalid limit entered.", $url, $limit, $reload));
                return false;
-       } elseif (''.($reload + 0).'' != ''.$reload.'') {
+       } elseif ('' . ($reload + 0) . '' != '' . $reload . '') {
                // Invalid amount entered
+               DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Invalid reload entered.", $url, $limit, $reload));
                return false;
        }
 
@@ -159,7 +165,7 @@ function SURFBAR_MEMBER_ADD_URL ($url, $limit) {
        if (!IS_MEMBER()) {
                // Not a member
                return false;
-       } elseif (!isUrlValid($url)) {
+       } elseif ((!isUrlValid($url)) && (!IS_ADMIN())) {
                // URL invalid
                return false;
        } elseif (SURFBAR_LOOKUP_BY_URL($url, getUserId())) {
@@ -192,13 +198,13 @@ function SURFBAR_MEMBER_ACTIONS ($urlId, $status) {
        // "Walk" through all actions and create forms
        foreach ($actionArray as $actionId => $action) {
                // Add form for this action
-               $OUT .= sprintf(LOAD_TEMPLATE('member_surfbar_list_form', true),
-               $width,
-               bigintval($urlId),
-               strtolower($action),
-               strtoupper($action),
-               strtoupper($action)
-               );
+               $OUT .= LOAD_TEMPLATE('member_surfbar_list_form', true, array(
+                       'width'    => $width,
+                       'id'       => bigintval($urlId),
+                       'action'   => strtolower($action),
+                       'title'    => '{--MEMBER_SURFBAR_ACTION_' . strtoupper($action) . '_TITLE--}',
+                       'submit'   => '{--MEMBER_SURFBAR_ACTION_' . strtoupper($action) . '_SUBMIT--}',
+               ));
        } // END - foreach
 
        // Close table
@@ -244,7 +250,7 @@ function SURFBAR_MEMBER_DO_FORM ($formData, $URLs) {
        // Is the function there?
        if (function_exists($functionName)) {
                // Add new status
-               $URLs[$formData['id']]['new_status'] = $GLOBALS['cache_array']['surfbar']['new_status'];
+               $URLs[$formData['id']]['new_status'] = SURFBAR_GET_NEW_STATUS('new_status');
 
                // Extract URL data for call-back
                $urlData = array(merge_array($URLs[$formData['id']], array($action => $formData)));
@@ -273,7 +279,7 @@ function SURFBAR_VALIDATE_MEMBER_ACTION_STATUS ($action, $status) {
        // Fetch the new status if found
        if ($isValid) {
                // Load new status
-               list($GLOBALS['cache_array']['surfbar']['new_status']) = SQL_FETCHROW($result);
+               list($GLOBALS['surfbar_cache']['new_status']) = SQL_FETCHROW($result);
        } // END - if
 
        // Free result
@@ -821,13 +827,13 @@ function SURFBAR_CHECK_RELOAD_FULL() {
        $isFull = true;
 
        // Cache static reload lock
-       $GLOBALS['cache_array']['surfbar']['surf_lock'] = getConfig('surfbar_static_lock');
+       $GLOBALS['surfbar_cache']['surf_lock'] = getConfig('surfbar_static_lock');
        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Fixed surf lock is ".getConfig('surfbar_static_lock')."", false);
 
        // Do we have dynamic model?
        if (getConfig('surfbar_pay_model') == 'DYNAMIC') {
                // "Calculate" dynamic lock
-               $GLOBALS['cache_array']['surfbar']['surf_lock'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
+               $GLOBALS['surfbar_cache']['surf_lock'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
        } // END - if
 
        // Ask the database
@@ -840,12 +846,12 @@ LIMIT 1",
        );
 
        // Fetch row
-       list($GLOBALS['cache_array']['surfbar']['user_locks']) = SQL_FETCHROW($result);
+       list($GLOBALS['surfbar_cache']['user_locks']) = SQL_FETCHROW($result);
 
        // Is it null?
-       if (is_null($GLOBALS['cache_array']['surfbar']['user_locks'])) {
+       if (is_null($GLOBALS['surfbar_cache']['user_locks'])) {
                // Then fix it to zero!
-               $GLOBALS['cache_array']['surfbar']['user_locks'] = 0;
+               $GLOBALS['surfbar_cache']['user_locks'] = 0;
        } // END - if
 
        // Free result
@@ -928,9 +934,9 @@ function SURFBAR_GET_TOTAL_USER_URLS ($uid=0, $status = '',$exclude = '') {
        // Get amount from database
        $result = SQL_QUERY_ESC("SELECT COUNT(id) AS cnt
 FROM `{!_MYSQL_PREFIX!}_surfbar_urls`
-WHERE userid=%s".$add."
+WHERE `userid`=%s".$add."
 LIMIT %s",
-       array($uid, getConfig('surfbar_max_order')), __FUNCTION__, __LINE__
+               array($uid, getConfig('surfbar_max_order')), __FUNCTION__, __LINE__
        );
 
        // Fetch row
@@ -946,7 +952,7 @@ LIMIT %s",
 // Generate a validation code for the given id number
 function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt = '') {
        // @TODO Invalid salt should be refused
-       $GLOBALS['cache_array']['surfbar']['salt'] = "INVALID";
+       $GLOBALS['surfbar_cache']['salt'] = 'INVALID';
 
        // Get code length from config
        $length = getConfig('code_length');
@@ -960,16 +966,16 @@ function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt = '') {
                // Is the salt set?
                if (empty($salt)) {
                        // Generate random hashed string
-                       $GLOBALS['cache_array']['surfbar']['salt'] = sha1(generatePassword(255));
+                       $GLOBALS['surfbar_cache']['salt'] = sha1(generatePassword(mt_rand(200, 255)));
                        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "newSalt=".SURFBAR_GET_SALT()."", false);
                } else {
                        // Use this as salt!
-                       $GLOBALS['cache_array']['surfbar']['salt'] = $salt;
+                       $GLOBALS['surfbar_cache']['salt'] = $salt;
                        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "oldSalt=".SURFBAR_GET_SALT()."", false);
                }
 
                // ... and now the validation code
-               $valCode = generateRandomCodde($length, sha1(SURFBAR_GET_SALT().':'.$urlId), getUserId());
+               $valCode = generateRandomCode($length, sha1(SURFBAR_GET_SALT().':'.$urlId), getUserId());
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "valCode={$valCode}", false);
        } // END - while
 
@@ -1000,15 +1006,15 @@ function SURFBAR_CHECK_VALIDATION_CODE ($urlId, $check, $salt) {
 
 // Lockdown the userid/id combination (reload lock)
 function SURFBAR_LOCKDOWN_ID ($urlId) {
-       //* DEBUG: */ print "LOCK!");
+       //* DEBUG: */ print "LOCK!";
        ///* DEBUG: */ return;
        // Just add it to the database
-       SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_surfbar_locks` (userid, url_id) VALUES (%s, %s)",
-       array(getUserId(), bigintval($urlId)), __FUNCTION__, __LINE__);
+       SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_surfbar_locks` (`userid`, `url_id`) VALUES (%s, %s)",
+               array(getUserId(), bigintval($urlId)), __FUNCTION__, __LINE__);
 
        // Remove the salt from database
-       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_surfbar_salts` WHERE url_id=%s AND `userid`=%s LIMIT 1",
-       array(bigintval($urlId), getUserId()), __FUNCTION__, __LINE__);
+       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{!_MYSQL_PREFIX!}_surfbar_salts` WHERE `url_id`=%s AND `userid`=%s LIMIT 1",
+               array(bigintval($urlId), getUserId()), __FUNCTION__, __LINE__);
 }
 
 // Pay points to the user and remove it from the sender if userid is given else it is a "sponsored surf"
@@ -1035,16 +1041,16 @@ function SURFBAR_UPDATE_INSERT_STATS_RECORD () {
        // Do we have a limit?
        if ($allowed > 0) {
                // Then count views_max down!
-               $add .= ",views_max=views_max-1";
+               $add .= ", `views_max`=`views_max`-1";
        } // END - if
 
        // Update URL stats
-       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_surfbar_urls` SET views_total=views_total+1".$add." WHERE `id`=%s LIMIT 1",
-       array(SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
+       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_surfbar_urls` SET `views_total`=`views_total`+1".$add." WHERE `id`=%s LIMIT 1",
+               array(SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
 
        // Update the stats entry
-       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_surfbar_stats` SET count=count+1 WHERE userid=%s AND url_id=%s LIMIT 1",
-       array(getUserId(), SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
+       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_surfbar_stats` SET `count`=`count`+1 WHERE `userid`=%s AND `url_id`=%s LIMIT 1",
+               array(getUserId(), SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
 
        // Was that update okay?
        if (SQL_AFFECTEDROWS() < 1) {
@@ -1069,8 +1075,8 @@ function SURFBAR_UPDATE_SALT_STATS () {
        SURFBAR_UPDATE_INSERT_STATS_RECORD();
 
        // Simply store the salt from cache away in database...
-       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_surfbar_salts` SET last_salt='%s' WHERE url_id=%s AND `userid`=%s LIMIT 1",
-       array(SURFBAR_GET_SALT(), SURFBAR_GET_ID(), getUserId()), __FUNCTION__, __LINE__);
+       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_surfbar_salts` SET `last_salt`='%s' WHERE `url_id`=%s AND `userid`=%s LIMIT 1",
+               array(SURFBAR_GET_SALT(), SURFBAR_GET_ID(), getUserId()), __FUNCTION__, __LINE__);
 
        // Debug message
        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "salt=".SURFBAR_GET_SALT().",id=".SURFBAR_GET_ID().",uid=".getUserId()."", false);
@@ -1078,8 +1084,8 @@ function SURFBAR_UPDATE_SALT_STATS () {
        // Was that okay?
        if (SQL_AFFECTEDROWS() < 1) {
                // Insert missing entry!
-               SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_surfbar_salts` (url_id,userid,last_salt) VALUES (%s, %s, '%s')",
-               array(SURFBAR_GET_ID(), getUserId(), SURFBAR_GET_SALT()), __FUNCTION__, __LINE__);
+               SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_surfbar_salts` (`url_id`, `userid`, `last_salt`) VALUES (%s, %s, '%s')",
+                       array(SURFBAR_GET_ID(), getUserId(), SURFBAR_GET_SALT()), __FUNCTION__, __LINE__);
        } // END - if
 
        // Debug message
@@ -1567,37 +1573,37 @@ LIMIT 1",
        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "lastQuery=".getConfig('db_last_query')."|numRows=".SQL_NUMROWS($result)."|Affected=".SQL_AFFECTEDROWS()."", false);
        if (SQL_NUMROWS($result) == 1) {
                // Load/cache data
-               //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "count(".count($GLOBALS['cache_array']['surfbar']).") - BEFORE", false);
-               $GLOBALS['cache_array']['surfbar'] = merge_array($GLOBALS['cache_array']['surfbar'], SQL_FETCHARRAY($result));
-               //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "count(".count($GLOBALS['cache_array']['surfbar']).") - AFTER", false);
+               //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "count(".count($GLOBALS['surfbar_cache']).") - BEFORE", false);
+               $GLOBALS['surfbar_cache'] = merge_array($GLOBALS['surfbar_cache'], SQL_FETCHARRAY($result));
+               //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "count(".count($GLOBALS['surfbar_cache']).") - AFTER", false);
 
                // Determine waiting time
-               $GLOBALS['cache_array']['surfbar']['time'] = SURFBAR_DETERMINE_WAIT_TIME();
+               $GLOBALS['surfbar_cache']['time'] = SURFBAR_DETERMINE_WAIT_TIME();
 
                // Is the last salt there?
-               if (is_null($GLOBALS['cache_array']['surfbar']['last_salt'])) {
+               if (is_null($GLOBALS['surfbar_cache']['last_salt'])) {
                        // Then repair it wit the static!
                        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "last_salt - FIXED!", false);
-                       $GLOBALS['cache_array']['surfbar']['last_salt'] = '';
+                       $GLOBALS['surfbar_cache']['last_salt'] = '';
                } // END - if
 
                // Fix missing last_surfed
-               if ((!isset($GLOBALS['cache_array']['surfbar']['last_surfed'])) || (is_null($GLOBALS['cache_array']['surfbar']['last_surfed']))) {
+               if ((!isset($GLOBALS['surfbar_cache']['last_surfed'])) || (is_null($GLOBALS['surfbar_cache']['last_surfed']))) {
                        // Fix it here
                        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "last_surfed - FIXED!", false);
-                       $GLOBALS['cache_array']['surfbar']['last_surfed'] = 0;
+                       $GLOBALS['surfbar_cache']['last_surfed'] = 0;
                } // END - if
 
                // Get base/fixed reward and costs
-               $GLOBALS['cache_array']['surfbar']['reward'] = SURFBAR_DETERMINE_REWARD();
-               $GLOBALS['cache_array']['surfbar']['costs']  = SURFBAR_DETERMINE_COSTS();
+               $GLOBALS['surfbar_cache']['reward'] = SURFBAR_DETERMINE_REWARD();
+               $GLOBALS['surfbar_cache']['costs']  = SURFBAR_DETERMINE_COSTS();
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "BASE/STATIC - reward=".SURFBAR_GET_REWARD()."|costs=".SURFBAR_GET_COSTS()."", false);
 
                // Only in dynamic model add the dynamic bonus!
                if (getConfig('surfbar_pay_model') == 'DYNAMIC') {
                        // Calculate dynamic reward/costs and add it
-                       $GLOBALS['cache_array']['surfbar']['reward'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
-                       $GLOBALS['cache_array']['surfbar']['costs']  += SURFBAR_CALCULATE_DYNAMIC_ADD();
+                       $GLOBALS['surfbar_cache']['reward'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
+                       $GLOBALS['surfbar_cache']['costs']  += SURFBAR_CALCULATE_DYNAMIC_ADD();
                        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "DYNAMIC+ - reward=".SURFBAR_GET_REWARD()."|costs=".SURFBAR_GET_COSTS()."", false);
                } // END - if
 
@@ -1615,8 +1621,15 @@ LIMIT 1",
 
 // -----------------------------------------------------------------------------
 // PLEASE DO NOT ADD ANY OTHER FUNCTIONS BELOW THIS LINE IF THEY DON'T "WRAP"
-// THE $GLOBALS['cache_array']['surfbar'] ARRAY!
+// THE $GLOBALS['surfbar_cache'] ARRAY!
 // -----------------------------------------------------------------------------
+
+// Initializes the surfbar
+function SURFBAR_INIT () {
+       // Init cache array
+       $GLOBALS['surfbar_cache'] = array();
+}
+
 // Private getter for data elements
 function SURFBAR_GET_DATA ($element) {
        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "element={$element}", false);
@@ -1625,12 +1638,12 @@ function SURFBAR_GET_DATA ($element) {
        $data = null;
 
        // Is the entry there?
-       if (isset($GLOBALS['cache_array']['surfbar'][$element])) {
+       if (isset($GLOBALS['surfbar_cache'][$element])) {
                // Then take it
-               $data = $GLOBALS['cache_array']['surfbar'][$element];
+               $data = $GLOBALS['surfbar_cache'][$element];
        } else { // END - if
                print("<pre>");
-               print_r($GLOBALS['cache_array']['surfbar']);
+               print_r($GLOBALS['surfbar_cache']);
                print("</pre>");
                debug_report_bug();
        }
@@ -1706,5 +1719,11 @@ function SURFBAR_GET_SURF_LOCK () {
        return SURFBAR_GET_DATA('surf_lock');
 }
 
+// Getter for new status
+function SURFBAR_GET_NEW_STATUS () {
+       // Get data element and return its contents
+       return SURFBAR_GET_DATA('new_status');
+}
+
 // [EOF]
 ?>