More misc fixes and rewrites (sorry, lame description)
[mailer.git] / inc / libs / surfbar_functions.php
index 2ea4f2d5bd2a12d4c7536520cd82bdde55850ec2..932259cc4087a93641850e22ff85c106936f8a77 100644 (file)
@@ -198,13 +198,13 @@ function SURFBAR_MEMBER_ACTIONS ($urlId, $status) {
        // "Walk" through all actions and create forms
        foreach ($actionArray as $actionId => $action) {
                // Add form for this action
-               $OUT .= sprintf(LOAD_TEMPLATE('member_surfbar_list_form', true),
-               $width,
-               bigintval($urlId),
-               strtolower($action),
-               strtoupper($action),
-               strtoupper($action)
-               );
+               $OUT .= LOAD_TEMPLATE('member_surfbar_list_form', true, array(
+                       'width'    => $width,
+                       'id'       => bigintval($urlId),
+                       'action'   => strtolower($action),
+                       'title'    => '{--MEMBER_SURFBAR_ACTION_' . strtoupper($action) . '_TITLE--}',
+                       'submit'   => '{--MEMBER_SURFBAR_ACTION_' . strtoupper($action) . '_SUBMIT--}',
+               ));
        } // END - foreach
 
        // Close table
@@ -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
@@ -540,7 +540,7 @@ function SURFBAR_LOOKUP_BY_URL ($url, $uid) {
 }
 
 // Load URL data by given search term and column
-function SURFBAR_GET_URL_DATA ($searchTerm, $column='id', $order='id', $sort="ASC", $group='id', $add = '') {
+function SURFBAR_GET_URL_DATA ($searchTerm, $column = 'id', $order = 'id', $sort = 'ASC', $group = 'id', $add = '') {
        // By default nothing is found
        $GLOBALS['last_url_data'] = array();
 
@@ -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
@@ -919,31 +925,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,8 +994,8 @@ 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')));
 }
 
@@ -1099,12 +1094,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 +1129,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?