]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/surfbar_functions.php
Several code cleanups:
[mailer.git] / inc / libs / surfbar_functions.php
index 4c7f40a75fea358f6be5dd3754642bb4e89d437a..fdf54732838642be27311ce0ef2b8763589bec24 100644 (file)
@@ -16,7 +16,7 @@
  * $Author::                                                          $ *
  * -------------------------------------------------------------------- *
  * Copyright (c) 2003 - 2009 by Roland Haeder                           *
- * Copyright (c) 2009, 2010 by Mailer Developer Team                    *
+ * Copyright (c) 2009 - 2011 by Mailer Developer Team                   *
  * For more information visit: http://www.mxchange.org                  *
  *                                                                      *
  * This program is free software; you can redistribute it and/or modify *
@@ -40,36 +40,36 @@ if (!defined('__SECURITY')) {
        die();
 } // END - if
 
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 //                               Admin functions
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 //
 // Admin has added an URL with given user id and so on
 function SURFBAR_ADMIN_ADD_URL ($url, $limit, $reload) {
        // Do some pre-checks
        if (!isAdmin()) {
                // Not an admin
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Not admin.", $url, $limit, $reload));
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s: Not admin.", $url, $limit, $reload));
                return false;
        } elseif (!isUrlValid($url)) {
                // URL invalid
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Invalid URL.", $url, $limit, $reload));
+               /* DEBUG: */ logDebugMessage(__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!
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Already added.", $url, $limit, $reload));
+               /* DEBUG: */ logDebugMessage(__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!
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : No more URLs allowed.", $url, $limit, $reload));
+               /* DEBUG: */ logDebugMessage(__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 limit entered
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Invalid limit entered.", $url, $limit, $reload));
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s: Invalid limit entered.", $url, $limit, $reload));
                return false;
        } elseif ('' . ($reload + 0) . '' != '' . $reload . '') {
                // Invalid amount entered
-               logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Invalid reload entered.", $url, $limit, $reload));
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s: Invalid reload entered.", $url, $limit, $reload));
                return false;
        }
 
@@ -82,15 +82,19 @@ function SURFBAR_ADMIN_MIGRATE_URL ($url, $userid) {
        // Do some pre-checks
        if (!isAdmin()) {
                // Not an admin
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot migrate URL: Not admin, url=' . $url . ',userid=' . $userid);
                return false;
        } elseif (!isUrlValid($url)) {
                // URL invalid
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot migrate URL: Invalid URL, url=' . $url . ',userid=' . $userid);
                return false;
        } elseif (SURFBAR_LOOKUP_BY_URL($url, $userid)) {
                // URL already found in surfbar!
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot migrate URL: Already added, url=' . $url . ',userid=' . $userid);
                return false;
        } elseif (!SURFBAR_IF_USER_BOOK_MORE_URLS($userid)) {
                // No more allowed!
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot migrate URL: Maximum exceeded, url=' . $url . ',userid=' . $userid);
                return false;
        }
 
@@ -103,12 +107,15 @@ function SURFBAR_ADMIN_UNLOCK_URL_IDS ($IDs) {
        // Is this an admin or invalid array?
        if (!isAdmin()) {
                // Not admin or invalid ids array
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Not admin');
                return false;
        } elseif (!is_array($IDs)) {
                // No array
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: IDs type ' . gettype($IDs) . '!=array');
                return false;
        } elseif (count($IDs) == 0) {
                // Empty array
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: IDs is empty');
                return false;
        }
 
@@ -130,12 +137,15 @@ function SURFBAR_ADMIN_REJECT_URL_IDS ($IDs) {
        // Is this an admin or invalid array?
        if (!isAdmin()) {
                // Not admin or invalid ids array
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Not admin');
                return false;
        } elseif (!is_array($IDs)) {
                // No array
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: IDs type ' . gettype($IDs) . '!=array');
                return false;
        } elseif (count($IDs) == 0) {
                // Empty array
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: IDs is empty');
                return false;
        }
 
@@ -153,27 +163,32 @@ function SURFBAR_ADMIN_REJECT_URL_IDS ($IDs) {
 }
 
 //
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 //                               Member functions
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 //
 // Member has added an URL
 function SURFBAR_MEMBER_ADD_URL ($url, $limit) {
        // Do some pre-checks
        if (!isMember()) {
                // Not a member
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Not member');
                return false;
        } elseif ((!isUrlValid($url)) && (!isAdmin())) {
                // URL invalid
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Invalid, url=' . $url . ',limit=' . $limit);
                return false;
        } elseif (SURFBAR_LOOKUP_BY_URL($url, getMemberId())) {
                // URL already found in surfbar!
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Already found, url=' . $url . ',limit=' . $limit);
                return false;
        } elseif (!SURFBAR_IF_USER_BOOK_MORE_URLS(getMemberId())) {
                // No more allowed!
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Maximum exceeded, url=' . $url . ',limit=' . $limit);
                return false;
        } elseif (''.($limit + 0).'' != ''.$limit.'') {
                // Invalid amount entered
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Invalid limit, url=' . $url . ',limit=' . $limit);
                return false;
        }
 
@@ -196,12 +211,10 @@ function SURFBAR_MEMBER_ACTIONS ($urlId, $status) {
        // "Walk" through all actions and create forms
        foreach ($actionArray as $actionId => $action) {
                // Add form for this action
-               $OUT .= loadTemplate('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--}',
+               $OUT .= loadTemplate('member_list_surfbar_form', true, array(
+                       'width'  => $width,
+                       'url_id' => bigintval($urlId),
+                       'action' => strtolower($action)
                ));
        } // END - foreach
 
@@ -221,15 +234,19 @@ function SURFBAR_MEMBER_DO_FORM ($formData, $urlArray) {
        // Is this a member?
        if (!isMember()) {
                // No member!
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Not member');
                return false;
        } elseif ((!isset($formData['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');
                return false;
        } elseif (!isset($urlArray[$formData['id']])) {
-               // id not found in cache
+               // Id not found in cache
+               /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Cannot add URL: Field id not found in cache');
                return false;
        } elseif (!SURFBAR_VALIDATE_MEMBER_ACTION_STATUS($formData['action'], $urlArray[$formData['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['id']]['url_status'] . 'id=' . $formData['id']);
                return false;
        }
 
@@ -257,8 +274,7 @@ function SURFBAR_MEMBER_DO_FORM ($formData, $urlArray) {
                $performed = call_user_func_array($functionName, $urlData);
        } else {
                // Log invalid request
-               logDebugMessage(__FUNCTION__, __LINE__, "action={$formData['action']},id={$formData['id']},function={$functionName}");
-               addFatalMessage(__FUNCTION__, __LINE__, "Invalid member action! action=%s,id=%s,function=%s", array($formData['action'], $formData['id'], $functionName));
+               debug_report_bug(__FUNCTION__, __LINE__, 'Invalid member action! action=' . $formData['action'] . ',id=' . $formData['id'] . ',function=' . $functionName);
        }
 
        // Return status
@@ -268,8 +284,8 @@ function SURFBAR_MEMBER_DO_FORM ($formData, $urlArray) {
 // Validate if the requested action can be performed on current URL status
 function SURFBAR_VALIDATE_MEMBER_ACTION_STATUS ($action, $status) {
        // Search for the requested action/status combination in database
-       $result = SQL_QUERY_ESC("SELECT new_status FROM `{?_MYSQL_PREFIX?}_surfbar_actions` WHERE `action`='%s' AND `status`='%s' LIMIT 1",
-       array($action, $status), __FUNCTION__, __LINE__);
+       $result = SQL_QUERY_ESC("SELECT `actions_new_status` FROM `{?_MYSQL_PREFIX?}_surfbar_actions` WHERE `actions_action`='%s' AND `actions_status`='%s' LIMIT 1",
+               array($action, $status), __FUNCTION__, __LINE__);
 
        // Is the entry there?
        $isValid = (SQL_NUMROWS($result) == 1);
@@ -288,9 +304,9 @@ function SURFBAR_VALIDATE_MEMBER_ACTION_STATUS ($action, $status) {
 }
 
 //
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 //                               Member actions
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 //
 // Retreat a booked URL
 function SURFBAR_MEMBER_RETREAT_ACTION ($urlData) {
@@ -409,8 +425,8 @@ function SURFBAR_MEMBER_EXECUTE_ACTION ($action, $urlData) {
                        $executed = SURFBAR_CHANGE_STATUS($urlData['id'], $urlData['url_status'], $urlData['new_status'], array($urlData['id'] => $urlData));
                } // END - if
        } else {
-               // Not found!
-               addFatalMessage(__FUNCTION__, __LINE__, '{--MEMBER_SURFBAR_EXECUTE_ACTION_404--}', $functionName);
+               // Not found
+               debug_report_bug(__FUNCTION__, __LINE__, 'Callback function ' . $functionName . ' not found.');
        }
 
        // Return status
@@ -441,9 +457,9 @@ function SURFBAR_MEMBER_EXECUTE_DELETE_ACTION ($urlData) {
        return true;
 }
 //
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 //                           Self-maintenance functions
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 //
 // Main function
 function SURFBAR_HANDLE_SELF_MAINTENANCE () {
@@ -453,6 +469,7 @@ function SURFBAR_HANDLE_SELF_MAINTENANCE () {
        // Handle low-points amounts
        SURFBAR_HANDLE_LOW_POINTS();
 }
+
 // Handle URLs which limit has depleted
 function SURFBAR_HANDLE_DEPLETED_VIEWS () {
        // Get all URLs
@@ -466,7 +483,9 @@ function SURFBAR_HANDLE_DEPLETED_VIEWS () {
                        $data = $urlData;
 
                        // Rewrite array for next call
-                       $urlData[$id] = $data;
+                       $urlData = array(
+                               $id => $data
+                       );
 
                        // Handle the status
                        SURFBAR_CHANGE_STATUS($id, 'ACTIVE', 'DEPLETED', $urlData);
@@ -501,9 +520,9 @@ function SURFBAR_HANDLE_LOW_POINTS () {
 }
 
 //
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 //                               Generic functions
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 //
 
 // Looks up by an URL
@@ -599,10 +618,10 @@ function SURFBAR_REGISTER_URL ($url, $userid, $status = 'PENDING', $addMode = 'r
        ));
 
        // Is limit/reload set?
-       if (!isset($config['limit'])) {
+       if (!isset($content['limit'])) {
                $content['limit']  = '0';
        } // END - if
-       if (!isset($config['reload'])) {
+       if (!isset($content['reload'])) {
                $content['reload'] = '0';
        } // END - if
 
@@ -665,7 +684,7 @@ function SURFBAR_NOTIFY_ADMIN ($messageType, $content) {
        // Is the subject line there?
        if ((substr($subject, 0, 1) == '!') && (substr($subject, -1, 1) == '!')) {
                // Set default subject if following eval() wents wrong
-               $subject = getMaskedMessage('ADMIN_SURFBAR_NOTIFY_DEFAULT_SUBJECT', strtoupper($messageType));
+               $subject = '{%message,ADMIN_SURFBAR_NOTIFY_DEFAULT_SUBJECT=' . strtoupper($messageType) . '%}';
        } // END - if
 
        // Translate some data if present
@@ -734,19 +753,67 @@ function translateSurfbarLimit ($limit) {
 
 // Translate the URL status
 function translateSurfbarUrlStatus ($status) {
-       // Return result
-       return sprintf("{--SURFBAR_URL_STATUS_%s--}", strtoupper($status));
+       // NULL must be handled carfefully
+       if ((is_null($status)) || (trim($status) == '')) {
+               // Is NULL, so return other language string
+               return '{--SURFBAR_URL_STATUS_NONE--}';
+       } else {
+               // Return regular result
+               return sprintf("{--SURFBAR_URL_STATUS_%s--}", strtoupper($status));
+       }
+}
+
+// Translates the given action into a link title for members
+function translateMemberSurfbarActionToTitle ($action) {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__][$action])) {
+               // Construct default return string (unknown
+               $GLOBALS[__FUNCTION__][$action] = '{%message,MEMBER_SURFBAR_ACTION_UNKNOWN_TITLE=' . $action . '%}';
+
+               // ... and the id's name
+               $messageId = 'MEMBER_SURFBAR_ACTION_' . strtoupper($action) . '_TITLE';
+
+               // Is the id there?
+               if (isMessageIdValid($messageId)) {
+                       // Then use it
+                       $GLOBALS[__FUNCTION__][$action] = '{--' . $messageId . '--}';
+               } // END - if
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$action];
+}
+
+// Translates the given action into a submit button for members
+function translateMemberSurfbarActionToSubmit ($action) {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__][$action])) {
+               // Construct default return string (unknown
+               $GLOBALS[__FUNCTION__][$action] = '{%message,MEMBER_SURFBAR_ACTION_UNKNOWN_SUBMIT=' . $action . '%}';
+
+               // ... and the id's name
+               $messageId = 'MEMBER_SURFBAR_ACTION_' . strtoupper($action) . '_SUBMIT';
+
+               // Is the id there?
+               if (isMessageIdValid($messageId)) {
+                       // Then use it
+                       $GLOBALS[__FUNCTION__][$action] = '{--' . $messageId . '--}';
+               } // END - if
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__][$action];
 }
 
 // Determine reward
-function SURFBAR_DETERMINE_REWARD ($onlyMin=false) {
+function SURFBAR_DETERMINE_REWARD ($onlyMin = false) {
        // Static values are default
        $reward = getConfig('surfbar_static_reward');
 
        // Do we have static or dynamic?
-       if (getConfig('surfbar_pay_model') == 'DYNAMIC') {
+       if (getSurfbarPaymentModel() == 'DYNAMIC') {
                // "Calculate" dynamic reward
-               if ($onlyMin) {
+               if ($onlyMin === true) {
                        $reward += SURFBAR_CALCULATE_DYNAMIC_MIN_VALUE();
                } else {
                        $reward += SURFBAR_CALCULATE_DYNAMIC_ADD();
@@ -763,7 +830,7 @@ function SURFBAR_DETERMINE_COSTS ($onlyMin=false) {
        $costs  = getConfig('surfbar_static_costs');
 
        // Do we have static or dynamic?
-       if (getConfig('surfbar_pay_model') == 'DYNAMIC') {
+       if (getSurfbarPaymentModel() == 'DYNAMIC') {
                // "Calculate" dynamic costs
                if ($onlyMin) {
                        $costs += SURFBAR_CALCULATE_DYNAMIC_MIN_VALUE();
@@ -789,7 +856,7 @@ function SURFBAR_CALCULATE_DYNAMIC_ADD () {
 // Determine right template name
 function SURFBAR_DETERMINE_TEMPLATE_NAME() {
        // Default is the frameset
-       $templateName = "surfbar_frameset";
+       $templateName = 'surfbar_frameset';
 
        // Any frame set? ;-)
        if (isGetRequestParameterSet('frame')) {
@@ -814,26 +881,26 @@ function SURFBAR_CHECK_RELOAD_FULL () {
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Fixed surf lock is '.getConfig('surfbar_static_lock') . '', false);
 
        // Do we have dynamic model?
-       if (getConfig('surfbar_pay_model') == 'DYNAMIC') {
+       if (getSurfbarPaymentModel() == 'DYNAMIC') {
                // "Calculate" dynamic lock
                $GLOBALS['surfbar_cache']['surf_lock'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
        } // END - if
 
        // Ask the database
        $result = SQL_QUERY_ESC("SELECT
-       COUNT(l.locks_id) AS cnt
+       COUNT(l.`locks_id`) AS `cnt`
 FROM
        `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
 INNER JOIN
        `{?_MYSQL_PREFIX?}_surfbar_urls` AS u
 ON
-       u.url_id=l.locks_url_id
+       u.`url_id`=l.`locks_url_id`
 WHERE
-       l.locks_userid=%s AND
-       (UNIX_TIMESTAMP() - ".SURFBAR_GET_SURF_LOCK().") < UNIX_TIMESTAMP(l.locks_last_surfed) AND
+       l.`locks_userid`=%s AND
+       (UNIX_TIMESTAMP() - {%%pipe,SURFBAR_GET_SURF_LOCK%%}) < UNIX_TIMESTAMP(l.`locks_last_surfed`) AND
        (
-               ((UNIX_TIMESTAMP(l.locks_last_surfed) - u.url_fixed_reload) < 0 AND u.url_fixed_reload > 0) OR
-               u.url_fixed_reload = '0'
+               ((UNIX_TIMESTAMP(l.`locks_last_surfed`) - u.`url_fixed_reload`) < 0 AND u.`url_fixed_reload` > 0) OR
+               u.`url_fixed_reload` = 0
        )
 LIMIT 1",
                array(getMemberId()), __FUNCTION__, __LINE__
@@ -855,7 +922,7 @@ LIMIT 1",
        $total = SURFBAR_GET_TOTAL_URLS();
 
        // Do we have some URLs in lock? Admins can always surf on own URLs!
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "userLocks=".SURFBAR_GET_USER_LOCKS().",total={$total}", false);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userLocks=' . SURFBAR_GET_USER_LOCKS() . ',total=' . $total);
        $isFull = ((SURFBAR_GET_USER_LOCKS() == $total) && ($total > 0));
 
        // Return result
@@ -907,7 +974,7 @@ LIMIT 1",
 // Check wether the user is allowed to book more URLs
 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')) < getSurfbarMaxOrder()));
 }
 
 // Get total amount of URLs of given status for current user
@@ -918,7 +985,7 @@ function SURFBAR_GET_TOTAL_USER_URLS ($userid = '0', $status = '', $exclude = ''
                $userid = getMemberId();
        } elseif ($userid == '0') {
                // Error!
-               return (getConfig('surfbar_max_order') + 1);
+               return (getSurfbarMaxOrder() + 1);
        }
 
        // Default is all URLs
@@ -949,13 +1016,19 @@ function SURFBAR_GET_TOTAL_USER_URLS ($userid = '0', $status = '', $exclude = ''
 // Generate a validation code for the given id number
 function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt = '') {
        // @TODO Invalid salt should be refused
+       $length = '0';
        $GLOBALS['surfbar_cache']['salt'] = 'INVALID';
 
-       // Get code length from config
-       $length = getCodeLength();
+       // Is extension ext-other there?
+       if (isExtensionActive('other')) {
+               // Get code length from config
+               $length = getCodeLength();
+       } // END - if
 
        // Fix length to 10
-       if ($length == '0') $length = 10;
+       if ($length == '0') {
+               $length = 10;
+       } // END - if
 
        // Generate a code until the length matches
        $valCode = '';
@@ -972,7 +1045,7 @@ function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt = '') {
                }
 
                // ... and now the validation code
-               $valCode = generateRandomCode($length, sha1(SURFBAR_GET_SALT().':'.$urlId), getMemberId());
+               $valCode = generateRandomCode($length, sha1(SURFBAR_GET_SALT() . getEncryptSeperator() . $urlId), getMemberId());
                //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'valCode='.valCode.'', false);
        } // END - while
 
@@ -1006,11 +1079,11 @@ function SURFBAR_LOCKDOWN_ID ($urlId) {
        //* DEBUG: */ debugOutput('LOCK!');
        ///* DEBUG: */ return;
        // Just add it to the database
-       SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_locks` (`locks_userid`, `locks_url_id`) VALUES (%s, %s)",
+       SQL_QUERY_ESC('INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_locks` (`locks_userid`, `locks_url_id`) VALUES (%s, %s)',
                array(getMemberId(), bigintval($urlId)), __FUNCTION__, __LINE__);
 
        // Remove the salt from database
-       SQL_QUERY_ESC("DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_surfbar_salts` WHERE `salts_url_id`=%s AND `salts_userid`=%s LIMIT 1",
+       SQL_QUERY_ESC('DELETE LOW_PRIORITY FROM `{?_MYSQL_PREFIX?}_surfbar_salts` WHERE `salts_url_id`=%s AND `salts_userid`=%s LIMIT 1',
                array(bigintval($urlId), getMemberId()), __FUNCTION__, __LINE__);
 }
 
@@ -1019,7 +1092,7 @@ function SURFBAR_PAY_POINTS () {
        // Remove it from the URL owner
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.SURFBAR_GET_USERID().',costs='.SURFBAR_GET_COSTS().'', false);
        if (isValidUserId(SURFBAR_GET_USERID())) {
-               subtractPoints(sprintf("surfbar_%s", getConfig('surfbar_pay_model')), SURFBAR_GET_USERID(), SURFBAR_GET_COSTS());
+               subtractPoints(sprintf("surfbar_%s", getSurfbarPaymentModel()), SURFBAR_GET_USERID(), SURFBAR_GET_COSTS());
        } // END - if
 
        //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.getMemberId().',reward='.SURFBAR_GET_REWARD().'', false);
@@ -1027,7 +1100,7 @@ function SURFBAR_PAY_POINTS () {
        unset($GLOBALS['ref_level']);
 
        // Book it to the user
-       addPointsThroughReferalSystem(sprintf("surfbar_%s", getConfig('surfbar_pay_model')), getMemberId(), SURFBAR_GET_REWARD());
+       addPointsThroughReferalSystem(sprintf("surfbar_%s", getSurfbarPaymentModel()), getMemberId(), SURFBAR_GET_REWARD());
 }
 
 // Updates the statistics of current URL/userid
@@ -1041,15 +1114,15 @@ 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 .= ', `url_views_max`=`url_views_max`-1';
        } // END - if
 
        // Update URL stats
-       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_surfbar_urls` SET `url_views_total`=`url_views_total`+1".$add." WHERE `url_id`=%s LIMIT 1",
+       SQL_QUERY_ESC('UPDATE `{?_MYSQL_PREFIX?}_surfbar_urls` SET `url_views_total`=`url_views_total`+1' . $add . ' WHERE `url_id`=%s LIMIT 1',
                array(SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
 
        // Update the stats entry
-       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_surfbar_stats` SET `stats_count`=`stats_count`+1 WHERE `stats_userid`=%s AND `stats_url_id`=%s LIMIT 1",
+       SQL_QUERY_ESC('UPDATE `{?_MYSQL_PREFIX?}_surfbar_stats` SET `stats_count`=`stats_count`+1 WHERE `stats_userid`=%s AND `stats_url_id`=%s LIMIT 1',
                array(
                        getMemberId(),
                        SURFBAR_GET_ID()
@@ -1058,7 +1131,7 @@ function SURFBAR_UPDATE_INSERT_STATS_RECORD () {
        // Was that update okay?
        if (SQL_HASZEROAFFECTED()) {
                // No, then insert entry
-               SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_stats` (`stats_userid`, `stats_url_id`, `stats_count`) VALUES (%s,%s,1)",
+               SQL_QUERY_ESC('INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_stats` (`stats_userid`, `stats_url_id`, `stats_count`) VALUES (%s,%s,1)',
                        array(
                                getMemberId(),
                                SURFBAR_GET_ID()
@@ -1160,13 +1233,14 @@ FROM
 INNER JOIN
        `{?_MYSQL_PREFIX?}_user_data` AS d
 ON
-       u.url_userid=d.userid
+       u.`url_userid`=d.`userid`
 WHERE
-       u.url_userid NOT IN (%s,0) AND u.url_status='ACTIVE'
+       u.`url_userid` NOT IN (%s,0) AND
+       u.`url_status`='ACTIVE'
 GROUP BY
-       u.url_userid
+       u.`url_userid`
 ORDER BY
-       u.url_userid ASC",
+       u.`url_userid` ASC",
                        array(getMemberId()), __FUNCTION__, __LINE__);
        } else {
                // Get all userid
@@ -1177,25 +1251,26 @@ FROM
 INNER JOIN
        `{?_MYSQL_PREFIX?}_user_data` AS d
 ON
-       u.url_userid=d.userid
+       u.`url_userid`=d.`userid`
 WHERE
-       u.url_status='ACTIVE'
+       u.`url_userid` > 0 AND
+       u.`url_status`='ACTIVE'
 GROUP BY
-       u.url_userid
+       u.`url_userid`
 ORDER BY
-       u.url_userid ASC", __FUNCTION__, __LINE__);
+       u.`url_userid` ASC", __FUNCTION__, __LINE__);
        }
 
        // Load all userid
        while ($content = SQL_FETCHARRAY($result)) {
                // Get total points
                $points = getTotalPoints($content['url_userid']);
-               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "userid={$content['url_userid']},points={$points}", false);
+               //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $content['url_userid'] . ',points=' . $points);
 
                // Shall we add this to ignore?
                if ($points <= $limit) {
                        // Ignore this one!
-                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "userid={$content['url_userid']} has depleted points amount!", false);
+                       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid=' . $content['url_userid'] . ' has depleted points amount!');
                        $userids['url_userid'][$content['url_userid']] = $content['url_userid'];
                        $userids['points'][$content['url_userid']]     = $points;
                        $userids['notified'][$content['url_userid']]   = $content['notified'];
@@ -1206,7 +1281,7 @@ ORDER BY
        SQL_FREERESULT($result);
 
        // Debug message
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "UIDs::count=".count($userids)." (with own userid=".getMemberId().')', false);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'UIDs::count=' . count($userids) . ' (with own userid=' . getMemberId() . ')');
 
        // Return result
        return $userids;
@@ -1249,7 +1324,7 @@ function SURFBAR_DETERMINE_WAIT_TIME () {
        $time = getConfig('surfbar_static_time');
 
        // Which payment model do we have?
-       if (getConfig('surfbar_pay_model') == 'DYNAMIC') {
+       if (getSurfbarPaymentModel() == 'DYNAMIC') {
                // "Calculate" dynamic time
                $time += SURFBAR_CALCULATE_DYNAMIC_ADD();
        } // END - if
@@ -1260,6 +1335,7 @@ function SURFBAR_DETERMINE_WAIT_TIME () {
 
 // Changes the status of an URL from given to other
 function SURFBAR_CHANGE_STATUS ($urlId, $prevStatus, $newStatus, $data=array()) {
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',prevStatus=' . $prevStatus . ',newStatus=' . $newStatus . ' - ENTERED!');
        // Make new status always lower-case
        $newStatus = strtolower($newStatus);
 
@@ -1269,52 +1345,49 @@ function SURFBAR_CHANGE_STATUS ($urlId, $prevStatus, $newStatus, $data=array())
                $data = SURFBAR_GET_URL_DATA($urlId);
        } // END - if
 
-       // Is the new status set?
-       if ((!is_string($newStatus)) || (empty($newStatus))) {
-               // Abort here, but fine!
-               return true;
-       } // END - if
+       // Prepare array
+       $filterData =  array(
+               'url_id'      => $urlId,
+               'prev_status' => $prevStatus,
+               'new_status'  => $newStatus,
+               'data'        => $data,
+               'abort'       => null
+       );
 
-       // Is the status like prevStatus is saying?
-       if ($data[$urlId]['url_status'] != $prevStatus) {
-               // No, then abort here
-               return false;
-       } // END - if
+       // Run pre filter chain
+       $filterData = runFilterChain('pre_change_surfbar_url_status', $filterData);
 
+       // Abort here?
+       if (!is_null($filterData['abort'])) {
+               // Abort here
+               return $filterData['abort'];
+       }
 
        // Update the status now
        // ---------- Comment out for debugging/developing member actions! ---------
-       //SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_surfbar_urls` SET `status`='%s' WHERE `url_id`=%s LIMIT 1",
-       //      array($newStatus, bigintval($urlId)), __FUNCTION__, __LINE__);
+       SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_surfbar_urls` SET `url_status`='%s' WHERE `url_id`=%s LIMIT 1",
+               array(
+                       $newStatus,
+                       bigintval($urlId)
+               ), __FUNCTION__, __LINE__);
        // ---------- Comment out for debugging/developing member actions! ---------
 
        // Was that fine?
        // ---------- Comment out for debugging/developing member actions! ---------
-       //if (SQL_AFFECTEDROWS() != 1) {
-       //      // No, something went wrong
-       //      return false;
-       //} // END - if
-       // ---------- Comment out for debugging/developing member actions! ---------
-
-       // Prepare content for notification routines
-       $data[$urlId]['url_userid']  = $data[$urlId]['url_userid'];
-       $data[$urlId]['frametester'] = '{%pipe,generateFrametesterUrl=' . $data[$urlId]['url'] . '%}';
-       $data[$urlId]['reward']      = '{%config,translateComma=surfbar_static_reward%}';
-       $data[$urlId]['costs']       = '{%config,translateComma=surfbar_static_costs%}';
-
-       // Do some dirty fixing here:
-       if (($data[$urlId]['url_status'] == 'STOPPED') && ($newStatus == 'pending')) {
-               // Fix for template change
-               $newStatus = 'continued';
+       if (SQL_AFFECTEDROWS() != 1) {
+               // No, something went wrong
+               return false;
        } // END - if
+       // ---------- Comment out for debugging/developing member actions! ---------
 
-       // Send admin notification
-       SURFBAR_NOTIFY_ADMIN('url_' . $data[$urlId]['url_status'] . '_' . $newStatus, $data[$urlId]);
+       // Run post filter chain
+       $filterData = runFilterChain('post_change_surfbar_url_status', $filterData);
 
-       // Send user notification
-       SURFBAR_NOTIFY_USER('url_' . $data[$urlId]['url_status'] . '_' . $newStatus, $data[$urlId]);
+       // Extract data from it again
+       $data = $filterData['data'];
 
        // All done!
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',prevStatus=' . $prevStatus . ',newStatus=' . $newStatus . ' - EXIT!');
        return true;
 }
 
@@ -1499,13 +1572,13 @@ function SURFBAR_GET_USER_URLS () {
        u.url_views_max,
        u.url_views_allowed,
        UNIX_TIMESTAMP(u.url_registered) AS `url_registered`,
-       UNIX_TIMESTAMP(u.url_last_locked) AS `url_last_locked`,
-       u.url_lock_reason
+       UNIX_TIMESTAMP(u.`url_last_locked`) AS `url_last_locked`,
+       u.`url_lock_reason`
 FROM
        `{?_MYSQL_PREFIX?}_surfbar_urls` AS u
 WHERE
-       u.url_userid=%s AND
-       u.url_status != 'DELETED'
+       u.`url_userid`=%s AND
+       u.`url_status` != 'DELETED'
 ORDER BY
        u.url_id ASC",
        array(getMemberId()), __FUNCTION__, __LINE__);
@@ -1515,7 +1588,7 @@ ORDER BY
                // Load all rows
                while ($row = SQL_FETCHARRAY($result)) {
                        // Add the row
-                       $urlArray[$row['id']] = $row;
+                       $urlArray[$row['url_id']] = $row;
                } // END - while
        } // END - if
 
@@ -1532,7 +1605,7 @@ function SURFBAR_GET_ARRAY_FROM_STATUS ($status) {
        $returnArray = array();
 
        // Get all assigned actions
-       $result = SQL_QUERY_ESC("SELECT `action` FROM `{?_MYSQL_PREFIX?}_surfbar_actions` WHERE `actions_status`='%s' ORDER BY `actions_id` ASC",
+       $result = SQL_QUERY_ESC("SELECT `actions_action` FROM `{?_MYSQL_PREFIX?}_surfbar_actions` WHERE `actions_status`='%s' ORDER BY `actions_id` ASC",
                array($status), __FUNCTION__, __LINE__);
 
        // Some entries there?
@@ -1540,7 +1613,7 @@ function SURFBAR_GET_ARRAY_FROM_STATUS ($status) {
                // Load all actions
                // @TODO This can be somehow rewritten
                while ($content = SQL_FETCHARRAY($result)) {
-                       $returnArray[] = $content['action'];
+                       $returnArray[] = $content['actions_action'];
                } // END - if
        } // END - if
 
@@ -1579,7 +1652,7 @@ function SURFBAR_DETERMINE_NEXT_ID ($urlId = '0') {
                $add = '';
                if (count($USE) > 0) {
                        // Ignore some!
-                       $add = " AND sbu.url_id NOT IN (";
+                       $add = " AND sbu.`url_id` NOT IN (";
                        foreach ($USE as $url_id => $lid) {
                                // Add URL id
                                $add .= $url_id.',';
@@ -1624,12 +1697,12 @@ LEFT JOIN
 ON
        sbu.url_id=l.locks_url_id
 WHERE
-       sbu.url_userid NOT IN (".implode(',', $userids['url_userid']).") AND
+       sbu.`url_userid` NOT IN (".implode(',', $userids['url_userid']).") AND
        sbu.url_status='ACTIVE' AND
        (sbu.url_views_allowed=0 OR (sbu.url_views_allowed > 0 AND sbu.url_views_max > 0))
        ".$add."
 GROUP BY
-       sbu.url_id
+       sbu.`url_id`
 ORDER BY
        l.locks_last_surfed ASC,
        sbu.url_id ASC
@@ -1699,7 +1772,7 @@ LIMIT 1",
                //* DEBUG: */ logDebugMessage(__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') {
+               if (getSurfbarPaymentModel() == 'DYNAMIC') {
                        // Calculate dynamic reward/costs and add it
                        $GLOBALS['surfbar_cache']['reward'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
                        $GLOBALS['surfbar_cache']['costs']  += SURFBAR_CALCULATE_DYNAMIC_ADD();
@@ -1718,62 +1791,74 @@ LIMIT 1",
        return $nextId;
 }
 
-// ----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 // Wrapper function
-// ----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
 
 // "Getter" for surfbar_dynamic_percent
 function getSurfbarDynamicPercent () {
        // Do we have cache?
-       if (!isset($GLOBALS['surfbar_dynamic_percent'])) {
+       if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS['surfbar_dynamic_percent'] = getConfig('surfbar_dynamic_percent');
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_dynamic_percent');
        } // END - if
 
        // Return cache
-       return $GLOBALS['surfbar_dynamic_percent'];
+       return $GLOBALS[__FUNCTION__];
 }
 
 // "Getter" for surfbar_static_reward
 function getSurfbarStaticReward () {
        // Do we have cache?
-       if (!isset($GLOBALS['surfbar_static_reward'])) {
+       if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS['surfbar_static_reward'] = getConfig('surfbar_static_reward');
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_static_reward');
        } // END - if
 
        // Return cache
-       return $GLOBALS['surfbar_static_reward'];
+       return $GLOBALS[__FUNCTION__];
 }
 
 // "Getter" for surfbar_static_time
 function getSurfbarStaticTime () {
        // Do we have cache?
-       if (!isset($GLOBALS['surfbar_static_time'])) {
+       if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS['surfbar_static_time'] = getConfig('surfbar_static_time');
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_static_time');
        } // END - if
 
        // Return cache
-       return $GLOBALS['surfbar_static_time'];
+       return $GLOBALS[__FUNCTION__];
 }
 
 // "Getter" for surfbar_max_order
 function getSurfbarMaxOrder () {
        // Do we have cache?
-       if (!isset($GLOBALS['surfbar_max_order'])) {
+       if (!isset($GLOBALS[__FUNCTION__])) {
+               // Determine it
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_max_order');
+       } // END - if
+
+       // Return cache
+       return $GLOBALS[__FUNCTION__];
+}
+
+// "Getter" for surfbar_payment_model
+function getSurfbarPaymentModel () {
+       // Do we have cache?
+       if (!isset($GLOBALS[__FUNCTION__])) {
                // Determine it
-               $GLOBALS['surfbar_max_order'] = getConfig('surfbar_max_order');
+               $GLOBALS[__FUNCTION__] = getConfig('surfbar_payment_model');
        } // END - if
 
        // Return cache
-       return $GLOBALS['surfbar_max_order'];
+       return $GLOBALS[__FUNCTION__];
 }
 
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 // PLEASE DO NOT ADD ANY OTHER FUNCTIONS BELOW THIS LINE IF THEY DON'T "WRAP"
 // THE $GLOBALS['surfbar_cache'] ARRAY!
-// -----------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 
 // Initializes the surfbar
 function SURFBAR_INIT () {
@@ -1783,7 +1868,7 @@ function SURFBAR_INIT () {
 
 // Private getter for data elements
 function SURFBAR_GET_DATA ($element) {
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "element={$element}", false);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element=' . $element . ' - CALLED!');
 
        // Default is null
        $data = null;
@@ -1800,7 +1885,7 @@ function SURFBAR_GET_DATA ($element) {
        }
 
        // Return result
-       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . $element . ']=[' . gettype($data) . ']' . $data, false);
+       //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . $element . ']=[' . gettype($data) . ']' . $data . ' - EXIT!');
        return $data;
 }