Several code cleanups:
[mailer.git] / inc / libs / surfbar_functions.php
index f22ac3899ee269f6748c4bceda58f570ab387751..fdf54732838642be27311ce0ef2b8763589bec24 100644 (file)
@@ -49,27 +49,27 @@ 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;
        }
 
@@ -162,18 +172,23 @@ 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;
        }
 
@@ -219,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;
        }
 
@@ -255,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
@@ -408,7 +426,7 @@ function SURFBAR_MEMBER_EXECUTE_ACTION ($action, $urlData) {
                } // END - if
        } else {
                // Not found
-               addFatalMessage(__FUNCTION__, __LINE__, '{--MEMBER_SURFBAR_EXECUTE_ACTION_404--}', $functionName);
+               debug_report_bug(__FUNCTION__, __LINE__, 'Callback function ' . $functionName . ' not found.');
        }
 
        // Return status
@@ -904,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
@@ -1247,12 +1265,12 @@ ORDER BY
        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'];
@@ -1263,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;
@@ -1850,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;
@@ -1867,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;
 }