]> git.mxchange.org Git - mailer.git/blobdiff - inc/libs/surfbar_functions.php
Login form for guests in surfbar added, some trigger_error() added, misc rewrites
[mailer.git] / inc / libs / surfbar_functions.php
index 20f540223fd6711c63dc9958d4f92958f126af78..10a2ba6583693fc99c4f03c54ff0a6aac06abdeb 100644 (file)
@@ -259,7 +259,7 @@ function SURFBAR_MEMBER_DO_FORM ($formData, $URLs) {
                $performed = call_user_func_array($functionName, $urlData);
        } else {
                // Log invalid request
-               DEBUG_LOG(__FUNCTION__, __LINE__, " action={$formData['action']},id={$formData['id']},function={$functionName}");
+               DEBUG_LOG(__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));
        }
 
@@ -518,7 +518,7 @@ function SURFBAR_HANDLE_LOW_POINTS () {
                        SURFBAR_NOTIFY_USER('low_points', $content);
 
                        // Update last notified
-                       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET surfbar_low_notified=NOW() WHERE userid=%s LIMIT 1",
+                       SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_user_data` SET surfbar_low_notified=NOW() WHERE `userid`=%s LIMIT 1",
                        array($uid), __FUNCTION__, __LINE__);
                } // END - if
        } // END - foreach
@@ -837,12 +837,18 @@ function SURFBAR_CHECK_RELOAD_FULL() {
        } // END - if
 
        // Ask the database
-       $result = SQL_QUERY_ESC("SELECT COUNT(l.id) AS cnt FROM `{!_MYSQL_PREFIX!}_surfbar_locks` AS l
-INNER JOIN `{!_MYSQL_PREFIX!}_surfbar_urls` AS u
-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)
+       $result = SQL_QUERY_ESC("SELECT
+       COUNT(l.id) AS cnt
+FROM
+       `{!_MYSQL_PREFIX!}_surfbar_locks` AS l
+INNER JOIN
+       `{!_MYSQL_PREFIX!}_surfbar_urls` AS u
+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)
 LIMIT 1",
-       array(getUserId()), __FUNCTION__, __LINE__
+               array(getUserId()), __FUNCTION__, __LINE__
        );
 
        // Fetch row
@@ -873,6 +879,12 @@ function SURFBAR_GET_TOTAL_URLS ($status = 'ACTIVE', $excludeUserId = 0) {
        // Determine depleted user account
        $UIDs = SURFBAR_DETERMINE_DEPLETED_USERIDS();
 
+       // If we dont get any user ids back, there are no URLs
+       if (count($UIDs['uid']) == 0) {
+               // No user ids found, no URLs!
+               return 0;
+       } // END - if
+
        // Is the exlude userid set?
        if ($excludeUserId > 0) {
                // Then add it
@@ -880,10 +892,10 @@ function SURFBAR_GET_TOTAL_URLS ($status = 'ACTIVE', $excludeUserId = 0) {
        } // END - if
 
        // Get amount from database
-       $result = SQL_QUERY_ESC("SELECT COUNT(id) AS cnt
+       $result = SQL_QUERY_ESC("SELECT COUNT(`id`) AS cnt
 FROM `{!_MYSQL_PREFIX!}_surfbar_urls`
-WHERE userid NOT IN (".implode(',', $UIDs['uid']).") AND `status`='%s'",
-       array($status), __FUNCTION__, __LINE__
+WHERE `userid` NOT IN (".implode(', ', $UIDs['uid']).") AND `status`='%s'",
+               array($status), __FUNCTION__, __LINE__
        );
 
        // Fetch row
@@ -919,31 +931,20 @@ function SURFBAR_GET_TOTAL_USER_URLS ($uid=0, $status = '',$exclude = '') {
        // Is the status set?
        if (is_array($status)) {
                // Only URLs with these status
-               $add = sprintf(" AND status IN('%s')", implode("','", $status));
+               $add = sprintf(" AND `status` IN('%s')", implode("','", $status));
        } elseif (!empty($status)) {
                // Only URLs with this status
                $add = sprintf(" AND `status`='%s'", $status);
        } elseif (is_array($exclude)) {
                // Exclude URLs with these status
-               $add = sprintf(" AND status NOT IN('%s')", implode("','", $exclude));
+               $add = sprintf(" AND `status` NOT IN('%s')", implode("','", $exclude));
        } elseif (!empty($exclude)) {
                // Exclude URLs with this status
-               $add = sprintf(" AND status != '%s'", $exclude);
+               $add = sprintf(" AND `status` != '%s'", $exclude);
        }
 
        // Get amount from database
-       $result = SQL_QUERY_ESC("SELECT COUNT(id) AS cnt
-FROM `{!_MYSQL_PREFIX!}_surfbar_urls`
-WHERE `userid`=%s".$add."
-LIMIT %s",
-               array($uid, getConfig('surfbar_max_order')), __FUNCTION__, __LINE__
-       );
-
-       // Fetch row
-       list($cnt) = SQL_FETCHROW($result);
-
-       // Free result
-       SQL_FREERESULT($result);
+       $cnt = GET_TOTAL_DATA($uid, 'surfbar_urls', 'id', 'userid', true, $add);
 
        // Return result
        return $cnt;
@@ -999,14 +1000,14 @@ function SURFBAR_CHECK_VALIDATION_CODE ($urlId, $check, $salt) {
        $code = SURFBAR_GENERATE_VALIDATION_CODE($urlId, $salt);
 
        // Return result of checking hashes and salts
-       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, '---'.$code."|".$check.'---', false);
-       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "+++".$salt."|".SURFBAR_GET_DATA('last_salt')."+++", false);
+       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, '---'.$code.'|'.$check.'---', false);
+       //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "+++".$salt.'|'.SURFBAR_GET_DATA('last_salt')."+++", false);
        return (($code == $check) && ($salt == SURFBAR_GET_DATA('last_salt')));
 }
 
 // Lockdown the userid/id combination (reload lock)
 function SURFBAR_LOCKDOWN_ID ($urlId) {
-       //* DEBUG: */ print "LOCK!";
+       //* DEBUG: */ OUTPUT_HTML("LOCK!");
        ///* DEBUG: */ return;
        // Just add it to the database
        SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_surfbar_locks` (`userid`, `url_id`) VALUES (%s, %s)",
@@ -1099,12 +1100,15 @@ function SURFBAR_UPDATE_SALT_STATS () {
 function SURFBAR_CHECK_RELOAD_LOCK ($urlId) {
        //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "id={$urlId}", false);
        // Ask the database
-       $result = SQL_QUERY_ESC("SELECT COUNT(id) AS cnt
-FROM `{!_MYSQL_PREFIX!}_surfbar_locks`
-WHERE userid=%s AND url_id=%s AND (UNIX_TIMESTAMP() - ".SURFBAR_GET_SURF_LOCK().") < UNIX_TIMESTAMP(last_surfed)
-ORDER BY last_surfed ASC
+       $result = SQL_QUERY_ESC("SELECT COUNT(`id`) AS cnt
+FROM
+       `{!_MYSQL_PREFIX!}_surfbar_locks`
+WHERE
+       `userid`=%s AND `url_id`=%s AND (UNIX_TIMESTAMP() - ".SURFBAR_GET_SURF_LOCK().") < UNIX_TIMESTAMP(`last_surfed`)
+ORDER BY
+       `last_surfed` ASC
 LIMIT 1",
-       array(getUserId(), bigintval($urlId)), __FUNCTION__, __LINE__
+               array(getUserId(), bigintval($urlId)), __FUNCTION__, __LINE__
        );
 
        // Fetch counter
@@ -1131,33 +1135,47 @@ function SURFBAR_DETERMINE_DEPLETED_USERIDS ($limit=0) {
        if ((IS_MEMBER()) && ($limit == 0)) {
                // Then add this as well
                $UIDs['uid'][getUserId()]      = getUserId();
-               $UIDs['points'][getUserId()]   = GET_TOTAL_DATA(getUserId(), "user_points", "points") - GET_TOTAL_DATA(getUserId(), "user_data", "used_points");
+               $UIDs['points'][getUserId()]   = GET_TOTAL_DATA(getUserId(), 'user_points', 'points') - GET_TOTAL_DATA(getUserId(), 'user_data', 'used_points');
                $UIDs['notified'][getUserId()] = 0;
 
                // Get all userid except logged in one
-               $result = SQL_QUERY_ESC("SELECT u.userid, UNIX_TIMESTAMP(d.surfbar_low_notified) AS notified
-FROM `{!_MYSQL_PREFIX!}_surfbar_urls` AS u
-INNER JOIN `{!_MYSQL_PREFIX!}_user_data` AS d
-ON u.userid=d.userid
-WHERE u.userid NOT IN (%s,0) AND u.`status`='ACTIVE'
-GROUP BY u.userid
-ORDER BY u.userid ASC",
-               array(getUserId()), __FUNCTION__, __LINE__);
+               $result = SQL_QUERY_ESC("SELECT
+       u.userid, UNIX_TIMESTAMP(d.surfbar_low_notified) AS notified
+FROM
+       `{!_MYSQL_PREFIX!}_surfbar_urls` AS u
+INNER JOIN
+       `{!_MYSQL_PREFIX!}_user_data` AS d
+ON
+       u.userid=d.userid
+WHERE
+       u.userid NOT IN (%s,0) AND u.`status`='ACTIVE'
+GROUP BY
+       u.userid
+ORDER BY
+       u.userid ASC",
+                       array(getUserId()), __FUNCTION__, __LINE__);
        } else {
                // Get all userid
-               $result = SQL_QUERY("SELECT u.userid, UNIX_TIMESTAMP(d.surfbar_low_notified) AS notified
-FROM `{!_MYSQL_PREFIX!}_surfbar_urls` AS u
-INNER JOIN `{!_MYSQL_PREFIX!}_user_data` AS d
-ON u.userid=d.userid
-WHERE u.`status`='ACTIVE'
-GROUP BY u.userid
-ORDER BY u.userid ASC", __FUNCTION__, __LINE__);
+               $result = SQL_QUERY("SELECT
+       u.userid, UNIX_TIMESTAMP(d.surfbar_low_notified) AS notified
+FROM
+       `{!_MYSQL_PREFIX!}_surfbar_urls` AS u
+INNER JOIN
+       `{!_MYSQL_PREFIX!}_user_data` AS d
+ON
+       u.userid=d.userid
+WHERE
+       u.`status`='ACTIVE'
+GROUP BY
+       u.userid
+ORDER BY
+       u.userid ASC", __FUNCTION__, __LINE__);
        }
 
        // Load all userid
        while ($content = SQL_FETCHARRAY($result)) {
                // Get total points
-               $points = GET_TOTAL_DATA($content['userid'], "user_points", "points") - GET_TOTAL_DATA($content['userid'], "user_data", "used_points");
+               $points = GET_TOTAL_DATA($content['userid'], 'user_points', 'points') - GET_TOTAL_DATA($content['userid'], 'user_data', 'used_points');
                //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "uid={$content['userid']},points={$points}", false);
 
                // Shall we add this to ignore?