Failed SQL queries are now also reported in bug mails, SQL queries improved (more...
[mailer.git] / inc / libs / surfbar_functions.php
index 1fc4d35ca50341717937e26ca9ba81e1f2315205..ab04a7fa5da55d1f803bb5f38a8f97c683799d32 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /************************************************************************
- * MXChange v0.2.1                                    Start: 08/31/2008 *
- * ===============                              Last change: 08/31/2008 *
+ * Mailer v0.2.1-FINAL                                Start: 08/31/2008 *
+ * ===================                          Last change: 08/31/2008 *
  *                                                                      *
  * -------------------------------------------------------------------- *
  * File              : surfbar_functions.php                            *
@@ -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 *
@@ -167,10 +168,10 @@ function SURFBAR_MEMBER_ADD_URL ($url, $limit) {
        } elseif ((!isUrlValid($url)) && (!isAdmin())) {
                // URL invalid
                return false;
-       } elseif (SURFBAR_LOOKUP_BY_URL($url, getUserId())) {
+       } elseif (SURFBAR_LOOKUP_BY_URL($url, getMemberId())) {
                // URL already found in surfbar!
                return false;
-       } elseif (!SURFBAR_IF_USER_BOOK_MORE_URLS(getUserId())) {
+       } elseif (!SURFBAR_IF_USER_BOOK_MORE_URLS(getMemberId())) {
                // No more allowed!
                return false;
        } elseif (''.($limit + 0).'' != ''.$limit.'') {
@@ -179,7 +180,7 @@ function SURFBAR_MEMBER_ADD_URL ($url, $limit) {
        }
 
        // Register the new URL
-       return SURFBAR_REGISTER_URL($url, getUserId(), 'PENDING', 'reg', array('limit' => $limit));
+       return SURFBAR_REGISTER_URL($url, getMemberId(), 'PENDING', 'reg', array('limit' => $limit));
 }
 
 // Create list of actions depending on status for the user
@@ -235,7 +236,7 @@ function SURFBAR_MEMBER_DO_FORM ($formData, $URLs) {
        }
 
        // Secure action
-       $action = SQL_ESCAPE(secureString($formData['action']));
+       $action = secureString($formData['action']);
 
        // Has it changed?
        if ($action != $formData['action']) {
@@ -363,11 +364,11 @@ function SURFBAR_MEMBER_RESUBMIT_ACTION ($urlData) {
 // Display selected "action form"
 function SURFBAR_MEMBER_DISPLAY_ACTION_FORM ($action, $urlData) {
        // Translate some data
-       $urlData['registered']    = generateDateTime($urlData['registered'], 2);
-       $urlData['views_total']   = translateComma($urlData['views_total']);
-       $urlData['views_max']     = translateComma($urlData['views_max']);
-       $urlData['views_allowed'] = translateComma($urlData['views_allowed']);
-       $urlData['last_locked']   = generateDateTime($urlData['last_locked'], 2);
+       $urlData['url_registered'] = generateDateTime($urlData['url_registered'], 2);
+       $urlData['views_total']    = translateComma($urlData['views_total']);
+       $urlData['views_max']      = translateComma($urlData['views_max']);
+       $urlData['views_allowed']  = translateComma($urlData['views_allowed']);
+       $urlData['last_locked']    = generateDateTime($urlData['last_locked'], 2);
 
        // Is the lock reason empty?
        if (empty($urlData['lock_reason'])) {
@@ -406,7 +407,7 @@ function SURFBAR_MEMBER_EXECUTE_ACTION ($action, $urlData) {
        // Is limitation "no" and "limit" is > 0?
        if ((isset($urlData[$action]['limited'])) && ($urlData[$action]['limited'] != 'Y') && ((isset($urlData[$action]['limit'])) && ($urlData[$action]['limit'] > 0)) || (!isset($urlData[$action]['limit']))) {
                // Set it to unlimited
-               $urlData[$action]['limit'] = 0;
+               $urlData[$action]['limit'] = '0';
        } // END - if
 
        // Construct function name
@@ -494,18 +495,18 @@ function SURFBAR_HANDLE_DEPLETED_VIEWS () {
 // Alert users which have URLs booked and are low on points amount
 function SURFBAR_HANDLE_LOW_POINTS () {
        // Get all userids
-       $UIDs = SURFBAR_DETERMINE_DEPLETED_USERIDS(getConfig('surfbar_warn_low_points'));
+       $userids = SURFBAR_DETERMINE_DEPLETED_USERIDS(getConfig('surfbar_warn_low_points'));
 
        // "Walk" through all URLs
-       foreach ($UIDs['userid'] as $userid => $dummy) {
+       foreach ($userids['userid'] as $userid => $dummy) {
                // Is the last notification far enougth away to notify again?
-               if ((time() - $UIDs['notified'][$userid]) >= getConfig('surfbar_low_interval')) {
+               if ((time() - $userids['notified'][$userid]) >= getConfig('surfbar_low_interval')) {
                        // Prepare content
                        $content = array(
                                'userid'      => $userid,
                                'low'      => translateComma(getConfig('surfbar_warn_low_points')),
-                               'points'   => translateComma($UIDs['points'][$userid]),
-                               'notified' => generateDateTime($UIDs['notified'][$userid]),
+                               'points'   => translateComma($userids['points'][$userid]),
+                               'notified' => generateDateTime($userids['notified'][$userid]),
                                'interval' => createFancyTime(getConfig('surfbar_low_interval'))
                        );
 
@@ -552,12 +553,25 @@ function SURFBAR_GET_URL_DATA ($searchTerm, $column = 'id', $order = 'id', $sort
        } // END - if
 
        // Look up the record
-       $result = SQL_QUERY_ESC("SELECT id, userid, url, views_total, views_max, views_allowed, status, registered, last_locked, lock_reason, views_max, views_allowed, fixed_reload
-FROM `{?_MYSQL_PREFIX?}_surfbar_urls`
-WHERE %s='%s'".$add."
-ORDER BY %s %s
+       $result = SQL_QUERY_ESC("SELECT
+       `id`, `userid`, `url`,
+       `views_total`, `views_max`, `views_allowed`, `status`,
+       UNIX_TIMESTAMP(`registered`) AS `url_registered`, UNIX_TIMESTAMP(`last_locked`) AS `last_locked`, `lock_reason`,
+       `views_max`, `views_allowed`, `fixed_reload`
+FROM
+       `{?_MYSQL_PREFIX?}_surfbar_urls`
+WHERE
+       `%s`='%s'".$add."
+ORDER BY
+       `%s` %s
 %s",
-       array($column, $searchTerm, $order, $sort, $limit), __FUNCTION__, __LINE__);
+               array(
+                       $column,
+                       $searchTerm,
+                       $order,
+                       $sort,
+                       $limit
+               ), __FUNCTION__, __LINE__);
 
        // Is there at least one record?
        if (SQL_NUMROWS($result) > 0) {
@@ -598,17 +612,17 @@ function SURFBAR_REGISTER_URL ($url, $userid, $status = 'PENDING', $addMode = 'r
 
        // Is limit/reload set?
        if (!isset($config['limit'])) {
-               $content['limit']  = 0;
+               $content['limit']  = '0';
        } // END - if
        if (!isset($config['reload'])) {
-               $content['reload'] = 0;
+               $content['reload'] = '0';
        } // END - if
 
        // Insert the URL into database
        $content['insert_id'] = SURFBAR_INSERT_URL_BY_ARRAY($content);
 
        // Is this id valid?
-       if ($content['insert_id'] == 0) {
+       if ($content['insert_id'] == '0') {
                // INSERT did not insert any data!
                return false;
        } // END - if
@@ -635,18 +649,18 @@ function SURFBAR_INSERT_URL_BY_ARRAY ($urlData) {
        $userid = bigintval($urlData['userid']);
 
        // Is the id set?
-       if (empty($userid)) $userid = 0;
+       if (empty($userid)) $userid = '0';
 
        // Just run the insert query for now
        SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_urls` (userid,url,status,views_max,views_allowed,fixed_reload) VALUES (%s,'%s','%s',%s,%s,%s)",
-       array(
-       $userid,
-       $urlData['url'],
-       $urlData['status'],
-       $urlData['limit'],
-       $urlData['limit'],
-       $urlData['reload']
-       ), __FUNCTION__, __LINE__
+               array(
+                       $userid,
+                       $urlData['url'],
+                       $urlData['status'],
+                       $urlData['limit'],
+                       $urlData['limit'],
+                       $urlData['reload']
+               ), __FUNCTION__, __LINE__
        );
 
        // Return insert id
@@ -670,12 +684,12 @@ function SURFBAR_NOTIFY_ADMIN ($messageType, $content) {
        } // END - if
 
        // Translate some data if present
-       if (isset($content['status']))        $content['status']        = translateSurfbarUrlStatus($content['status']);
-       if (isset($content['registered']))    $content['registered']    = generateDateTime($content['registered'], 2);
-       if (isset($content['last_locked']))   $content['last_locked']   = generateDateTime($content['last_locked'], 2);
-       if (isset($content['views_total']))   $content['views_total']   = translateComma($content['views_total']);
-       if (isset($content['views_allowed'])) $content['views_allowed'] = translateComma($content['views_allowed']);
-       if (isset($content['views_max']))     $content['views_max']     = translateComma($content['views_max']);
+       if (isset($content['status']))         $content['status']         = translateSurfbarUrlStatus($content['status']);
+       if (isset($content['url_registered'])) $content['url_registered'] = generateDateTime($content['url_registered'], 2);
+       if (isset($content['last_locked']))    $content['last_locked']    = generateDateTime($content['last_locked'], 2);
+       if (isset($content['views_total']))    $content['views_total']    = translateComma($content['views_total']);
+       if (isset($content['views_allowed']))  $content['views_allowed']  = translateComma($content['views_allowed']);
+       if (isset($content['views_max']))      $content['views_max']      = translateComma($content['views_max']);
 
        // Send the notification out
        return sendAdminNotification($subject, $templateName, $content, $content['userid']);
@@ -684,7 +698,7 @@ function SURFBAR_NOTIFY_ADMIN ($messageType, $content) {
 // Notify the user about the performed action
 function SURFBAR_NOTIFY_USER ($messageType, $content) {
        // Skip notification if userid is zero
-       if ($content['userid'] == 0) {
+       if ($content['userid'] == '0') {
                return false;
        } // END - if
 
@@ -703,12 +717,12 @@ function SURFBAR_NOTIFY_USER ($messageType, $content) {
        } // END - if
 
        // Translate some data if present
-       if (isset($content['status']))        $content['status']        = translateSurfbarUrlStatus($content['status']);
-       if (isset($content['registered']))    $content['registered']    = generateDateTime($content['registered'], 2);
-       if (isset($content['last_locked']))   $content['last_locked']   = generateDateTime($content['last_locked'], 2);
-       if (isset($content['views_total']))   $content['views_total']   = translateComma($content['views_total']);
-       if (isset($content['views_allowed'])) $content['views_allowed'] = translateComma($content['views_allowed']);
-       if (isset($content['views_max']))     $content['views_max']     = translateComma($content['views_max']);
+       if (isset($content['status']))         $content['status']         = translateSurfbarUrlStatus($content['status']);
+       if (isset($content['url_registered'])) $content['url_registered'] = generateDateTime($content['url_registered'], 2);
+       if (isset($content['last_locked']))    $content['last_locked']    = generateDateTime($content['last_locked'], 2);
+       if (isset($content['views_total']))    $content['views_total']    = translateComma($content['views_total']);
+       if (isset($content['views_allowed']))  $content['views_allowed']  = translateComma($content['views_allowed']);
+       if (isset($content['views_max']))      $content['views_max']      = translateComma($content['views_max']);
 
        // Load template
        $mailText = loadEmailTemplate($templateName, $content, $content['userid']);
@@ -720,7 +734,7 @@ function SURFBAR_NOTIFY_USER ($messageType, $content) {
 // Translates the limit
 function translateSurfbarLimit ($limit) {
        // Is this zero?
-       if ($limit == 0) {
+       if ($limit == '0') {
                // Unlimited!
                $return = getMessage('MEMBER_SURFBAR_UNLIMITED_VIEWS');
        } else {
@@ -737,14 +751,8 @@ function translateSurfbarUrlStatus ($status) {
        // Create constant name
        $constantName = sprintf("SURFBAR_URL_STATUS_%s", strtoupper($status));
 
-       // Set default translated status
-       $statusTranslated = '!'.$constantName.'!';
-
-       // Is the constant there?
-       if (defined($constantName)) {
-               // Then get it's value
-               $statusTranslated = constant($constantName);
-       } // END - if
+       // Get message
+       $statusTranslated = getMessage($constantName);
 
        // Return result
        return $statusTranslated;
@@ -804,10 +812,10 @@ function SURFBAR_DETERMINE_TEMPLATE_NAME() {
        $templateName = "surfbar_frameset";
 
        // Any frame set? ;-)
-       if (isGetRequestElementSet('frame')) {
+       if (isGetRequestParameterSet('frame')) {
                // Use the frame as a template name part... ;-)
                $templateName = sprintf("surfbar_frame_%s",
-               getRequestElement('frame')
+               getRequestParameter('frame')
                );
        } // END - if
 
@@ -841,9 +849,14 @@ INNER JOIN
 ON
        u.id=l.url_id
 WHERE
-       l.userid=%s AND (UNIX_TIMESTAMP() - ".SURFBAR_GET_SURF_LOCK().") < UNIX_TIMESTAMP(l.last_surfed) AND (((UNIX_TIMESTAMP(l.last_surfed) - u.fixed_reload) < 0 AND u.fixed_reload > 0) OR u.fixed_reload = 0)
+       l.userid=%s AND
+       (UNIX_TIMESTAMP() - ".SURFBAR_GET_SURF_LOCK().") < UNIX_TIMESTAMP(l.last_surfed) AND
+       (
+               ((UNIX_TIMESTAMP(l.last_surfed) - u.fixed_reload) < 0 AND u.fixed_reload > 0) OR
+               u.fixed_reload = '0'
+       )
 LIMIT 1",
-               array(getUserId()), __FUNCTION__, __LINE__
+               array(getMemberId()), __FUNCTION__, __LINE__
        );
 
        // Fetch row
@@ -852,7 +865,7 @@ LIMIT 1",
        // Is it null?
        if (is_null($GLOBALS['surfbar_cache']['user_locks'])) {
                // Then fix it to zero!
-               $GLOBALS['surfbar_cache']['user_locks'] = 0;
+               $GLOBALS['surfbar_cache']['user_locks'] = '0';
        } // END - if
 
        // Free result
@@ -870,12 +883,12 @@ LIMIT 1",
 }
 
 // Get total amount of URLs of given status for current user or of ACTIVE URLs by default
-function SURFBAR_GET_TOTAL_URLS ($status = 'ACTIVE', $excludeUserId = 0) {
+function SURFBAR_GET_TOTAL_URLS ($status = 'ACTIVE', $excludeUserId = '0') {
        // Determine depleted user account
-       $UIDs = SURFBAR_DETERMINE_DEPLETED_USERIDS();
+       $userids = SURFBAR_DETERMINE_DEPLETED_USERIDS();
 
        // If we dont get any user ids back, there are no URLs
-       if (count($UIDs['userid']) == 0) {
+       if (count($userids['userid']) == 0) {
                // No user ids found, no URLs!
                return 0;
        } // END - if
@@ -883,13 +896,13 @@ function SURFBAR_GET_TOTAL_URLS ($status = 'ACTIVE', $excludeUserId = 0) {
        // Is the exlude userid set?
        if ($excludeUserId > 0) {
                // Then add it
-               $UIDs['userid'][$excludeUserId] = $excludeUserId;
+               $userids['userid'][$excludeUserId] = $excludeUserId;
        } // END - if
 
        // Get amount from database
        $result = SQL_QUERY_ESC("SELECT COUNT(`id`) AS cnt
 FROM `{?_MYSQL_PREFIX?}_surfbar_urls`
-WHERE `userid` NOT IN (".implode(', ', $UIDs['userid']).") AND `status`='%s'",
+WHERE `userid` NOT IN (".implode(', ', $userids['userid']).") AND `status`='%s'",
                array($status), __FUNCTION__, __LINE__
        );
 
@@ -904,18 +917,18 @@ WHERE `userid` NOT IN (".implode(', ', $UIDs['userid']).") AND `status`='%s'",
 }
 
 // Check wether the user is allowed to book more URLs
-function SURFBAR_IF_USER_BOOK_MORE_URLS ($userid = 0) {
+function SURFBAR_IF_USER_BOOK_MORE_URLS ($userid = '0') {
        // Is this admin and userid is zero or does the user has some URLs left to book?
-       return ((($userid == 0) && (isAdmin())) || (SURFBAR_GET_TOTAL_USER_URLS($userid, '', array("REJECTED")) < getConfig('surfbar_max_order')));
+       return ((($userid == '0') && (isAdmin())) || (SURFBAR_GET_TOTAL_USER_URLS($userid, '', array('REJECTED')) < getConfig('surfbar_max_order')));
 }
 
 // Get total amount of URLs of given status for current user
-function SURFBAR_GET_TOTAL_USER_URLS ($userid = 0, $status = '',$exclude = '') {
+function SURFBAR_GET_TOTAL_USER_URLS ($userid = '0', $status = '',$exclude = '') {
        // Is the user 0 and user is logged in?
-       if (($userid == 0) && (isMember())) {
+       if (($userid == '0') && (isMember())) {
                // Then use this userid
-               $userid = getUserId();
-       } elseif ($userid == 0) {
+               $userid = getMemberId();
+       } elseif ($userid == '0') {
                // Error!
                return (getConfig('surfbar_max_order') + 1);
        }
@@ -954,7 +967,7 @@ function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt = '') {
        $length = getConfig('code_length');
 
        // Fix length to 10
-       if ($length == 0) $length = 10;
+       if ($length == '0') $length = 10;
 
        // Generate a code until the length matches
        $valCode = '';
@@ -971,7 +984,7 @@ function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt = '') {
                }
 
                // ... and now the validation code
-               $valCode = generateRandomCode($length, sha1(SURFBAR_GET_SALT().':'.$urlId), getUserId());
+               $valCode = generateRandomCode($length, sha1(SURFBAR_GET_SALT().':'.$urlId), getMemberId());
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'valCode='.valCode.'', false);
        } // END - while
 
@@ -979,7 +992,7 @@ function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt = '') {
        $hashedCode = generateHash(md5($valCode), SURFBAR_GET_SALT());
 
        // Finally encrypt it PGP-like and return it
-       $valHashedCode = generatePassString($hashedCode);
+       $valHashedCode = encodeHashForCookie($hashedCode);
 
        // Return hashed value
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'finalValCode='.$valHashedCode.'', false);
@@ -1006,11 +1019,11 @@ function SURFBAR_LOCKDOWN_ID ($urlId) {
        ///* 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__);
+               array(getMemberId(), 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__);
+               array(bigintval($urlId), getMemberId()), __FUNCTION__, __LINE__);
 }
 
 // Pay points to the user and remove it from the sender if userid is given else it is a "sponsored surf"
@@ -1022,8 +1035,8 @@ function SURFBAR_PAY_POINTS () {
        } // END - if
 
        // Book it to the user
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.getUserId().',reward='.SURFBAR_GET_REWARD().'', false);
-       addPointsThroughReferalSystem(sprintf("surfbar_%s", getConfig('surfbar_pay_model')), getUserId(), SURFBAR_GET_DATA('reward'));
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.getMemberId().',reward='.SURFBAR_GET_REWARD().'', false);
+       addPointsThroughReferalSystem(sprintf("surfbar_%s", getConfig('surfbar_pay_model')), getMemberId(), SURFBAR_GET_DATA('reward'));
 }
 
 // Updates the statistics of current URL/userid
@@ -1046,13 +1059,13 @@ function SURFBAR_UPDATE_INSERT_STATS_RECORD () {
 
        // 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__);
+               array(getMemberId(), SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
 
        // Was that update okay?
        if (SQL_AFFECTEDROWS() < 1) {
                // No, then insert entry
                SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_stats` (userid,url_id,count) VALUES (%s,%s,1)",
-               array(getUserId(), SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
+               array(getMemberId(), SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
        } // END - if
 
        // Update total/daily/weekly/monthly counter
@@ -1072,16 +1085,16 @@ function SURFBAR_UPDATE_SALT_STATS () {
 
        // 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__);
+               array(SURFBAR_GET_SALT(), SURFBAR_GET_ID(), getMemberId()), __FUNCTION__, __LINE__);
 
        // Debug message
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'salt='.SURFBAR_GET_SALT().',id='.SURFBAR_GET_ID().',userid='.getUserId().'', false);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'salt='.SURFBAR_GET_SALT().',id='.SURFBAR_GET_ID().',userid='.getMemberId().'', false);
 
        // 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__);
+                       array(SURFBAR_GET_ID(), getMemberId(), SURFBAR_GET_SALT()), __FUNCTION__, __LINE__);
        } // END - if
 
        // Debug message
@@ -1103,7 +1116,7 @@ WHERE
 ORDER BY
        `last_surfed` ASC
 LIMIT 1",
-               array(getUserId(), bigintval($urlId)), __FUNCTION__, __LINE__
+               array(getMemberId(), bigintval($urlId)), __FUNCTION__, __LINE__
        );
 
        // Fetch counter
@@ -1120,18 +1133,18 @@ LIMIT 1",
 // Determine which user hash no more points left
 function SURFBAR_DETERMINE_DEPLETED_USERIDS ($limit=0) {
        // Init array
-       $UIDs = array(
+       $userids = array(
                'userid'      => array(),
                'points'   => array(),
                'notified' => array(),
        );
 
        // Do we have a current user id?
-       if ((isMember()) && ($limit == 0)) {
+       if ((isMember()) && ($limit == '0')) {
                // Then add this as well
-               $UIDs['userid'][getUserId()]      = getUserId();
-               $UIDs['points'][getUserId()]   = countSumTotalData(getUserId(), 'user_points', 'points') - countSumTotalData(getUserId(), 'user_data', 'used_points');
-               $UIDs['notified'][getUserId()] = 0;
+               $userids['userid'][getMemberId()]      = getMemberId();
+               $userids['points'][getMemberId()]   = countSumTotalData(getMemberId(), 'user_points', 'points') - countSumTotalData(getMemberId(), 'user_data', 'used_points');
+               $userids['notified'][getMemberId()] = '0';
 
                // Get all userid except logged in one
                $result = SQL_QUERY_ESC("SELECT
@@ -1148,7 +1161,7 @@ GROUP BY
        u.userid
 ORDER BY
        u.userid ASC",
-                       array(getUserId()), __FUNCTION__, __LINE__);
+                       array(getMemberId()), __FUNCTION__, __LINE__);
        } else {
                // Get all userid
                $result = SQL_QUERY("SELECT
@@ -1177,9 +1190,9 @@ ORDER BY
                if ($points <= $limit) {
                        // Ignore this one!
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "userid={$content['userid']} has depleted points amount!", false);
-                       $UIDs['userid'][$content['userid']]      = $content['userid'];
-                       $UIDs['points'][$content['userid']]   = $points;
-                       $UIDs['notified'][$content['userid']] = $content['notified'];
+                       $userids['userid'][$content['userid']]      = $content['userid'];
+                       $userids['points'][$content['userid']]   = $points;
+                       $userids['notified'][$content['userid']] = $content['notified'];
                } // END - if
        } // END - while
 
@@ -1187,10 +1200,10 @@ ORDER BY
        SQL_FREERESULT($result);
 
        // Debug message
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "UIDs::count=".count($UIDs)." (with own userid=".getUserId().')', false);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "UIDs::count=".count($userids)." (with own userid=".getMemberId().')', false);
 
        // Return result
-       return $UIDs;
+       return $userids;
 }
 
 // Determine how many users are Online in surfbar
@@ -1302,7 +1315,7 @@ function SURFBAR_CHANGE_STATUS ($urlId, $prevStatus, $newStatus, $data=array())
 // Calculate minimum value for dynamic payment model
 function SURFBAR_CALCULATE_DYNAMIC_MIN_VALUE () {
        // Addon is zero by default
-       $addon = 0;
+       $addon = '0';
 
        // Percentage part
        $percent = abs(log(getConfig('surfbar_dynamic_percent') / 100 + 1));
@@ -1336,7 +1349,7 @@ function SURFBAR_CALCULATE_DYNAMIC_MIN_VALUE () {
 // Calculate maximum value for dynamic payment model
 function SURFBAR_CALCULATE_DYNAMIC_MAX_VALUE () {
        // Addon is zero by default
-       $addon = 0;
+       $addon = '0';
 
        // Maximum value
        $max = log(2);
@@ -1389,7 +1402,7 @@ FROM
 WHERE
        `userid`=%s
 ORDER BY
-       `id` ASC", array(getUserId()),
+       `id` ASC", array(getMemberId()),
        __FUNCTION__, __LINE__);
 
        // Load all entries
@@ -1430,16 +1443,27 @@ ORDER BY
 }
 
 // "Getter" for maximum random number
-function SURFBAR_GET_MAX_RANDOM ($UIDs, $add) {
+function SURFBAR_GET_MAX_RANDOM ($userids, $add) {
        // Count max availabe entries
-       $result = SQL_QUERY("SELECT sbu.id AS cnt
-FROM `{?_MYSQL_PREFIX?}_surfbar_urls` AS sbu
-LEFT JOIN `{?_MYSQL_PREFIX?}_surfbar_salts` AS sbs
-ON sbu.id=sbs.url_id
-LEFT JOIN `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
-ON sbu.id=l.url_id
-WHERE sbu.userid NOT IN (".implode(',', $UIDs).") AND (sbu.views_allowed=0 OR (sbu.views_allowed > 0 AND sbu.views_max > 0)) AND sbu.`status`='ACTIVE'".$add."
-GROUP BY sbu.id", __FUNCTION__, __LINE__);
+       $result = SQL_QUERY("SELECT
+       sbu.id AS cnt
+FROM
+       `{?_MYSQL_PREFIX?}_surfbar_urls` AS sbu
+LEFT JOIN
+       `{?_MYSQL_PREFIX?}_surfbar_salts` AS sbs
+ON
+       sbu.id=sbs.url_id
+LEFT JOIN
+       `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
+ON
+       sbu.id=l.url_id
+WHERE
+       sbu.userid NOT IN (".implode(',', $userids).") AND
+       (sbu.views_allowed=0 OR (sbu.views_allowed > 0 AND sbu.views_max > 0)) AND
+       sbu.`status`='ACTIVE'
+       ".$add."
+GROUP BY
+       sbu.id ASC", __FUNCTION__, __LINE__);
 
        // Log last query
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'lastQuery='.getConfig('db_last_query').'|numRows='.SQL_NUMROWS($result).'|Affected='.SQL_AFFECTEDROWS().'', false);
@@ -1460,11 +1484,20 @@ function SURFBAR_GET_USER_URLS () {
        $URLs = array();
 
        // Begin the query
-       $result = SQL_QUERY_ESC("SELECT u.id, u.userid, u.url, u.views_total, u.views_max, u.views_allowed, u.status, UNIX_TIMESTAMP(u.registered) AS registered, UNIX_TIMESTAMP(u.last_locked) AS last_locked, u.lock_reason AS lock_reason
-FROM `{?_MYSQL_PREFIX?}_surfbar_urls` AS u
-WHERE u.userid=%s AND u.status != 'DELETED'
-ORDER BY u.id ASC",
-       array(getUserId()), __FUNCTION__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT
+       u.id, u.userid, u.url, u.status,
+       u.views_total, u.views_max, u.views_allowed,
+       UNIX_TIMESTAMP(u.registered) AS url_registered,
+       UNIX_TIMESTAMP(u.last_locked) AS last_locked,
+       u.lock_reason AS lock_reason
+FROM
+       `{?_MYSQL_PREFIX?}_surfbar_urls` AS u
+WHERE
+       u.userid=%s AND
+       u.status != 'DELETED'
+ORDER BY
+       u.id ASC",
+       array(getMemberId()), __FUNCTION__, __LINE__);
 
        // Are there entries?
        if (SQL_NUMROWS($result) > 0) {
@@ -1508,7 +1541,7 @@ function SURFBAR_GET_ARRAY_FROM_STATUS ($status) {
 }
 
 // Reload to configured stop page
-function SURFBAR_RELOAD_TO_STOP_PAGE ($page="stop") {
+function SURFBAR_RELOAD_TO_STOP_PAGE ($page = 'stop') {
        // Internal or external?
        if ((getConfig('surfbar_pause_mode') == 'INTERNAL') || (getConfig('surfbar_pause_url') == '')) {
                // Reload to internal page
@@ -1521,13 +1554,13 @@ function SURFBAR_RELOAD_TO_STOP_PAGE ($page="stop") {
 
 // Determine next id for surfbar or get data for given id, always call this before you call other
 // getters below this function!!!
-function SURFBAR_DETERMINE_NEXT_ID ($urlId = 0) {
+function SURFBAR_DETERMINE_NEXT_ID ($urlId = '0') {
        // Default is no id and no random number
-       $nextId = 0;
-       $randNum = 0;
+       $nextId = '0';
+       $randNum = '0';
 
        // Is the id set?
-       if ($urlId == 0) {
+       if ($urlId == '0') {
                // Get array with lock ids
                $USE = SURFBAR_GET_LOCK_IDS();
 
@@ -1546,10 +1579,10 @@ function SURFBAR_DETERMINE_NEXT_ID ($urlId = 0) {
                } // END - if
 
                // Determine depleted user account
-               $UIDs = SURFBAR_DETERMINE_DEPLETED_USERIDS();
+               $userids = SURFBAR_DETERMINE_DEPLETED_USERIDS();
 
                // Get maximum randomness factor
-               $maxRand = SURFBAR_GET_MAX_RANDOM($UIDs['userid'], $add);
+               $maxRand = SURFBAR_GET_MAX_RANDOM($userids['userid'], $add);
 
                // If more than one URL can be called generate the random number!
                if ($maxRand > 1) {
@@ -1565,7 +1598,7 @@ LEFT JOIN `{?_MYSQL_PREFIX?}_surfbar_salts` AS sbs
 ON sbu.id=sbs.url_id
 LEFT JOIN `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
 ON sbu.id=l.url_id
-WHERE sbu.userid NOT IN (".implode(',', $UIDs['userid']).") AND sbu.`status`='ACTIVE' AND (sbu.views_allowed=0 OR (sbu.views_allowed > 0 AND sbu.views_max > 0))".$add."
+WHERE sbu.userid NOT IN (".implode(',', $userids['userid']).") AND sbu.`status`='ACTIVE' AND (sbu.views_allowed=0 OR (sbu.views_allowed > 0 AND sbu.views_max > 0))".$add."
 GROUP BY sbu.id
 ORDER BY l.last_surfed ASC, sbu.id ASC
 LIMIT %s,1",
@@ -1581,7 +1614,7 @@ LEFT JOIN `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
 ON sbu.id=l.url_id
 WHERE sbu.userid != %s AND sbu.`status`='ACTIVE' AND sbu.id=%s AND (sbu.views_allowed=0 OR (sbu.views_allowed > 0 AND sbu.views_max > 0))
 LIMIT 1",
-                       array(getUserId(), bigintval($urlId)), __FUNCTION__, __LINE__
+                       array(getMemberId(), bigintval($urlId)), __FUNCTION__, __LINE__
                );
        }
 
@@ -1607,7 +1640,7 @@ LIMIT 1",
                if ((!isset($GLOBALS['surfbar_cache']['last_surfed'])) || (is_null($GLOBALS['surfbar_cache']['last_surfed']))) {
                        // Fix it here
                        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'last_surfed - FIXED!', false);
-                       $GLOBALS['surfbar_cache']['last_surfed'] = 0;
+                       $GLOBALS['surfbar_cache']['last_surfed'] = '0';
                } // END - if
 
                // Get base/fixed reward and costs