* Needs to be in all Files and every File needs "svn propset *
* svn:keywords Date Revision" (autoprobset!) at least!!!!!! *
* -------------------------------------------------------------------- *
- * Copyright (c) 2003 - 2008 by Roland Haeder *
+ * Copyright (c) 2003 - 2009 by Roland Haeder *
* For more information visit: http://www.mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
// Some security stuff...
if (!defined('__SECURITY')) {
- $INC = substr(dirname(__FILE__), 0, strpos(dirname(__FILE__), '/inc') + 4) . '/security.php';
- require($INC);
+ die();
}
// -----------------------------------------------------------------------------
// 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 (!IS_ADMIN()) {
+ if (!isAdmin()) {
// Not an admin
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Not admin.", $url, $limit, $reload));
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Not admin.", $url, $limit, $reload));
return false;
} elseif (!isUrlValid($url)) {
// URL invalid
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Invalid URL.", $url, $limit, $reload));
+ 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')) {
+ } elseif (SURFBAR_LOOKUP_BY_URL($url, 0)) {
// URL already found in surfbar!
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Already added.", $url, $limit, $reload));
+ 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!
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : No more URLs allowed.", $url, $limit, $reload));
+ 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
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Invalid limit entered.", $url, $limit, $reload));
+ 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
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Invalid reload entered.", $url, $limit, $reload));
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf("Cannot add URL=%s,limit=%s,reload=%s : Invalid reload entered.", $url, $limit, $reload));
return false;
}
// Register the new URL
- return SURFBAR_REGISTER_URL($url, '0', 'ACTIVE', 'unlock', array('limit' => $limit, 'reload' => $reload));
+ return SURFBAR_REGISTER_URL($url, 0, 'ACTIVE', 'unlock', array('limit' => $limit, 'reload' => $reload));
}
// Admin unlocked an email so we can migrate the URL
-function SURFBAR_ADMIN_MIGRATE_URL ($url, $uid) {
+function SURFBAR_ADMIN_MIGRATE_URL ($url, $userid) {
// Do some pre-checks
- if (!IS_ADMIN()) {
+ if (!isAdmin()) {
// Not an admin
return false;
} elseif (!isUrlValid($url)) {
// URL invalid
return false;
- } elseif (SURFBAR_LOOKUP_BY_URL($url, $uid)) {
+ } elseif (SURFBAR_LOOKUP_BY_URL($url, $userid)) {
// URL already found in surfbar!
return false;
- } elseif (!SURFBAR_IF_USER_BOOK_MORE_URLS($uid)) {
+ } elseif (!SURFBAR_IF_USER_BOOK_MORE_URLS($userid)) {
// No more allowed!
return false;
}
// Register the new URL
- return SURFBAR_REGISTER_URL($url, $uid, 'MIGRATED', 'migrate');
+ return SURFBAR_REGISTER_URL($url, $userid, 'MIGRATED', 'migrate');
}
// Admin function for unlocking URLs
function SURFBAR_ADMIN_UNLOCK_URL_IDS ($IDs) {
// Is this an admin or invalid array?
- if (!IS_ADMIN()) {
+ if (!isAdmin()) {
// Not admin or invalid IDs array
return false;
} elseif (!is_array($IDs)) {
// Admin function for rejecting URLs
function SURFBAR_ADMIN_REJECT_URL_IDS ($IDs) {
// Is this an admin or invalid array?
- if (!IS_ADMIN()) {
+ if (!isAdmin()) {
// Not admin or invalid IDs array
return false;
} elseif (!is_array($IDs)) {
// Member has added an URL
function SURFBAR_MEMBER_ADD_URL ($url, $limit) {
// Do some pre-checks
- if (!IS_MEMBER()) {
+ if (!isMember()) {
// Not a member
return false;
- } elseif ((!isUrlValid($url)) && (!IS_ADMIN())) {
+ } elseif ((!isUrlValid($url)) && (!isAdmin())) {
// URL invalid
return false;
} elseif (SURFBAR_LOOKUP_BY_URL($url, getUserId())) {
// Create list of actions depending on status for the user
function SURFBAR_MEMBER_ACTIONS ($urlId, $status) {
// Load all actions in an array for given status
- $actionArray = SURFBAR_getModeAction_ARRAY($status);
+ $actionArray = SURFBAR_GET_ARRAY_FROM_STATUS($status);
// Init HTML code
$OUT = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"1\" width=\"100%\">
// "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 .= 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--}',
+ ));
} // END - foreach
// Close table
$performed = false;
// Is this a member?
- if (!IS_MEMBER()) {
+ if (!isMember()) {
// No member!
return false;
} elseif ((!isset($formData['id'])) || (!isset($formData['action']))) {
}
// Secure action
- $action = SQL_ESCAPE(htmlentities(strip_tags($formData['action']), ENT_QUOTES));
+ $action = SQL_ESCAPE(secureString($formData['action']));
// Has it changed?
if ($action != $formData['action']) {
$performed = call_user_func_array($functionName, $urlData);
} else {
// Log invalid request
- DEBUG_LOG(__FUNCTION__, __LINE__, " action={$formData['action']},id={$formData['id']},function={$functionName}");
+ 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));
}
// 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",
+ $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__);
// Is the entry there?
// Display selected "action form"
function SURFBAR_MEMBER_DISPLAY_ACTION_FORM ($action, $urlData) {
// Translate some data
- $urlData['registered'] = generateDateTime($urlData['registered'], '2');
+ $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['last_locked'] = generateDateTime($urlData['last_locked'], 2);
// Is the lock reason empty?
if (empty($urlData['lock_reason'])) {
// Include fields only for action 'edit'
if ($action == 'edit') {
// Default is not limited
- $urlData['limited_yes'] = '';
- $urlData['limited_no'] = ' checked="checked"';
- $urlData['limited'] = 'false';
+ $urlData['limited_y'] = '';
+ $urlData['limited_n'] = ' checked="checked"';
+ $urlData['limited'] = 'false';
// Is this URL limited?
if ($urlData['views_max'] > 0) {
// Then rewrite form data
- $urlData['limited_yes'] = ' checked="checked"';
- $urlData['limited_no'] = '';
- $urlData['limited'] = 'true';
+ $urlData['limited_y'] = ' checked="checked"';
+ $urlData['limited_n'] = '';
+ $urlData['limited'] = 'true';
} // END - if
} // END - if
// Load the form and display it
- LOAD_TEMPLATE(sprintf("member_surfbar_%s_action_form", $action), false, $urlData);
+ loadTemplate(sprintf("member_surfbar_%s_action_form", $action), false, $urlData);
// All fine by default ... ;-)
return true;
$executed = false;
// Is limitation "no" and "limit" is > 0?
- if ((isset($urlData[$action]['limited'])) && ($urlData[$action]['limited'] == 'N') && ((isset($urlData[$action]['limit'])) && ($urlData[$action]['limit'] > 0)) || (!isset($urlData[$action]['limit']))) {
+ 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;
} // END - if
// Construct function name
$functionName = sprintf("SURFBAR_MEMBER_EXECUTE_%s_ACTION", strtoupper($action));
- // Is 'userid' set and not 'uid' ?
- if ((!isset($urlData['uid'])) && (isset($urlData['userid']))) {
+ // Is 'userid' set and not 'userid' ?
+ if ((!isset($urlData['userid'])) && (isset($urlData['userid']))) {
// Auto-fix this
- $urlData['uid'] = $urlData['userid'];
+ $urlData['userid'] = $urlData['userid'];
} // END - if
// Is that function there?
$status = false;
// Translate URLs for testing
- $url1 = COMPILE_CODE($urlData['url']);
- $url2 = COMPILE_CODE($urlData['edit']['url']);
+ $url1 = compileCode($urlData['url']);
+ $url2 = compileCode($urlData['edit']['url']);
// Has the URL or limit changed?
if (true) {
//if (($urlData['views_allowed'] != $urlData['edit']['limit']) || ($url1 != $url2)) {
// Run the query
- SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_surfbar_urls` SET url='%s', views_allowed=%s, views_max=%s WHERE `id`=%s AND `status`='%s' LIMIT 1",
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_surfbar_urls` SET url='%s', views_allowed=%s, views_max=%s WHERE `id`=%s AND `status`='%s' LIMIT 1",
array($urlData['url'], $urlData['edit']['limit'], $urlData['edit']['limit'], $urlData['id'], $urlData['status']), __FUNCTION__, __LINE__);
// All fine
// Handle URLs which limit has depleted
function SURFBAR_HANDLE_DEPLETED_VIEWS () {
// Get all URLs
- $urlArray = SURFBAR_GET_URL_DATA('0', 'views_max', 'id', 'ASC', 'id', " AND views_allowed>0 AND `status`='ACTIVE'");
+ $urlArray = SURFBAR_GET_URL_DATA(0, 'views_max', 'id', 'ASC', 'id', " AND views_allowed>0 AND `status`='ACTIVE'");
// Do we have some entries?
if (count($urlArray) > 0) {
$UIDs = SURFBAR_DETERMINE_DEPLETED_USERIDS(getConfig('surfbar_warn_low_points'));
// "Walk" through all URLs
- foreach ($UIDs['uid'] as $uid => $dummy) {
+ foreach ($UIDs['userid'] as $userid => $dummy) {
// Is the last notification far enougth away to notify again?
- if ((time() - $UIDs['notified'][$uid]) >= getConfig('surfbar_low_interval')) {
+ if ((time() - $UIDs['notified'][$userid]) >= getConfig('surfbar_low_interval')) {
// Prepare content
$content = array(
- 'uid' => $uid,
+ 'userid' => $userid,
'low' => translateComma(getConfig('surfbar_warn_low_points')),
- 'points' => translateComma($UIDs['points'][$uid]),
- 'notified' => generateDateTime($UIDs['notified'][$uid]),
+ 'points' => translateComma($UIDs['points'][$userid]),
+ 'notified' => generateDateTime($UIDs['notified'][$userid]),
'interval' => createFancyTime(getConfig('surfbar_low_interval'))
);
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",
- array($uid), __FUNCTION__, __LINE__);
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_user_data` SET surfbar_low_notified=NOW() WHERE `userid`=%s LIMIT 1",
+ array($userid), __FUNCTION__, __LINE__);
} // END - if
} // END - foreach
}
//
// Looks up by an URL
-function SURFBAR_LOOKUP_BY_URL ($url, $uid) {
+function SURFBAR_LOOKUP_BY_URL ($url, $userid) {
// Now lookup that given URL by itself
- $urlArray = SURFBAR_GET_URL_DATA($url, 'url', 'id', 'ASC', 'id', sprintf(" AND `userid`=%s", bigintval($uid)));
+ $urlArray = SURFBAR_GET_URL_DATA($url, 'url', 'id', 'ASC', 'id', sprintf(" AND `userid`=%s", bigintval($userid)));
// Was it found?
return (count($urlArray) > 0);
}
// 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();
// 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`
+FROM `{?_MYSQL_PREFIX?}_surfbar_urls`
WHERE %s='%s'".$add."
ORDER BY %s %s
%s",
}
// Registers an URL with the surfbar. You should have called SURFBAR_LOOKUP_BY_URL() first!
-function SURFBAR_REGISTER_URL ($url, $uid, $status = 'PENDING', $addMode = 'reg', $extraFields = array()) {
+function SURFBAR_REGISTER_URL ($url, $userid, $status = 'PENDING', $addMode = 'reg', $extraFields = array()) {
// Make sure by the user registered URLs are always pending
if ($addMode == 'reg') {
$status = 'PENDING';
// Prepare content
$content = merge_array($extraFields, array(
'url' => $url,
- 'frametester' => FRAMETESTER($url),
- 'uid' => $uid,
+ 'frametester' => generateFrametesterUrl($url),
+ 'userid' => $userid,
'status' => $status,
));
} // END - if
// Translate status and limit
- $content['limit'] = surfbarTranslateLimit($content['limit']);
+ $content['limit'] = translateSurfbarLimit($content['limit']);
// If in reg-mode we notify admin
if (($addMode == 'reg') || (getConfig('surfbar_notify_admin_unlock') == 'Y')) {
// Inserts an url by given data array and return the insert id
function SURFBAR_INSERT_URL_BY_ARRAY ($urlData) {
// Get userid
- $uid = bigintval($urlData['uid']);
+ $userid = bigintval($urlData['userid']);
// Is the id set?
- if (empty($uid)) $uid = 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)",
+ 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(
- $uid,
+ $userid,
$urlData['url'],
$urlData['status'],
$urlData['limit'],
// Prepare subject
$subject = getMessage(sprintf("ADMIN_SURFBAR_NOTIFY_%s_SUBJECT",
- strtoupper($messageType)
+ strtoupper($messageType)
));
// Is the subject line there?
} // END - if
// Translate some data if present
- if (isset($content['status'])) $content['status'] = surfbarTranslateUserStatus($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['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']);
// Send the notification out
- return sendAdminNotification($subject, $templateName, $content, $content['uid']);
+ return sendAdminNotification($subject, $templateName, $content, $content['userid']);
}
// Notify the user about the performed action
function SURFBAR_NOTIFY_USER ($messageType, $content) {
// Skip notification if userid is zero
- if ($content['uid'] == 0) {
+ if ($content['userid'] == 0) {
return false;
} // END - if
} // END - if
// Translate some data if present
- if (isset($content['status'])) $content['status'] = surfbarTranslateUserStatus($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['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']);
// Load template
- $mailText = LOAD_EMAIL_TEMPLATE($templateName, $content, $content['uid']);
+ $mailText = loadEmailTemplate($templateName, $content, $content['userid']);
// Send the email
- return sendEmail($content['uid'], $subject, $mailText);
+ return sendEmail($content['userid'], $subject, $mailText);
}
// Translates the limit
-function surfbarTranslateLimit ($limit) {
+function translateSurfbarLimit ($limit) {
// Is this zero?
if ($limit == 0) {
// Unlimited!
}
// Translate the URL status
-function surfbarTranslateUserStatus ($status) {
+function translateSurfbarUrlStatus ($status) {
// Create constant name
$constantName = sprintf("SURFBAR_URL_STATUS_%s", strtoupper($status));
$templateName = "surfbar_frameset";
// Any frame set? ;-)
- if (REQUEST_ISSET_GET('frame')) {
+ if (isGetRequestElementSet('frame')) {
// Use the frame as a template name part... ;-)
$templateName = sprintf("surfbar_frame_%s",
- REQUEST_GET('frame')
+ getRequestElement('frame')
);
} // END - if
// Cache static reload lock
$GLOBALS['surfbar_cache']['surf_lock'] = getConfig('surfbar_static_lock');
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Fixed surf lock is ".getConfig('surfbar_static_lock')."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Fixed surf lock is '.getConfig('surfbar_static_lock') . '', false);
// Do we have dynamic model?
if (getConfig('surfbar_pay_model') == 'DYNAMIC') {
} // 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
$total = SURFBAR_GET_TOTAL_URLS();
// Do we have some URLs in lock? Admins can always surf on own URLs!
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "userLocks=".SURFBAR_GET_USER_LOCKS().",total={$total}", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "userLocks=".SURFBAR_GET_USER_LOCKS().",total={$total}", false);
$isFull = ((SURFBAR_GET_USER_LOCKS() == $total) && ($total > 0));
// Return result
// Determine depleted user account
$UIDs = SURFBAR_DETERMINE_DEPLETED_USERIDS();
+ // If we dont get any user ids back, there are no URLs
+ if (count($UIDs['userid']) == 0) {
+ // No user ids found, no URLs!
+ return 0;
+ } // END - if
+
// Is the exlude userid set?
if ($excludeUserId > 0) {
// Then add it
- $UIDs['uid'][$excludeUserId] = $excludeUserId;
+ $UIDs['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['uid']).") AND `status`='%s'",
- array($status), __FUNCTION__, __LINE__
+ $result = SQL_QUERY_ESC("SELECT COUNT(`id`) AS cnt
+FROM `{?_MYSQL_PREFIX?}_surfbar_urls`
+WHERE `userid` NOT IN (".implode(', ', $UIDs['userid']).") AND `status`='%s'",
+ array($status), __FUNCTION__, __LINE__
);
// Fetch row
}
// Check wether the user is allowed to book more URLs
-function SURFBAR_IF_USER_BOOK_MORE_URLS ($uid=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 ((($uid == 0) && (IS_ADMIN())) || (SURFBAR_GET_TOTAL_USER_URLS($uid, '', 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 ($uid=0, $status = '',$exclude = '') {
+function SURFBAR_GET_TOTAL_USER_URLS ($userid = 0, $status = '',$exclude = '') {
// Is the user 0 and user is logged in?
- if (($uid == 0) && (IS_MEMBER())) {
+ if (($userid == 0) && (isMember())) {
// Then use this userid
- $uid = getUserId();
- } elseif ($uid == 0) {
+ $userid = getUserId();
+ } elseif ($userid == 0) {
// Error!
return (getConfig('surfbar_max_order') + 1);
}
// 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 = countSumTotalData($userid, 'surfbar_urls', 'id', 'userid', true, $add);
// Return result
return $cnt;
if (empty($salt)) {
// Generate random hashed string
$GLOBALS['surfbar_cache']['salt'] = sha1(generatePassword(mt_rand(200, 255)));
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "newSalt=".SURFBAR_GET_SALT()."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newSalt='.SURFBAR_GET_SALT().'', false);
} else {
// Use this as salt!
$GLOBALS['surfbar_cache']['salt'] = $salt;
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "oldSalt=".SURFBAR_GET_SALT()."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'oldSalt='.SURFBAR_GET_SALT().'', false);
}
// ... and now the validation code
$valCode = generateRandomCode($length, sha1(SURFBAR_GET_SALT().':'.$urlId), getUserId());
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "valCode={$valCode}", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'valCode='.valCode.'', false);
} // END - while
// Hash it with md5() and salt it with the random string
$valHashedCode = generatePassString($hashedCode);
// Return hashed value
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "finalValCode={$valHashedCode}", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'finalValCode='.$valHashedCode.'', false);
return $valHashedCode;
}
$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: */ logDebugMessage(__FUNCTION__, __LINE__, '---'.$code.'|'.$check.'---', false);
+ //* DEBUG: */ logDebugMessage(__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: */ outputHtml('LOCK!');
///* DEBUG: */ return;
// Just add it to the database
- SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_surfbar_locks` (`userid`, `url_id`) VALUES (%s, %s)",
+ SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_locks` (`userid`, `url_id`) VALUES (%s, %s)",
array(getUserId(), 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",
+ 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__);
}
// Pay points to the user and remove it from the sender if userid is given else it is a "sponsored surf"
function SURFBAR_PAY_POINTS () {
// Remove it from the URL owner
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "uid=".SURFBAR_GET_USERID().",costs=".SURFBAR_GET_COSTS()."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.SURFBAR_GET_USERID().',costs='.SURFBAR_GET_COSTS().'', false);
if (SURFBAR_GET_USERID() > 0) {
- SUB_POINTS(sprintf("surfbar_%s", getConfig('surfbar_pay_model')), SURFBAR_GET_USERID(), SURFBAR_GET_COSTS());
+ subtractPoints(sprintf("surfbar_%s", getConfig('surfbar_pay_model')), SURFBAR_GET_USERID(), SURFBAR_GET_COSTS());
} // END - if
// Book it to the user
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "uid=".getUserId().",reward=".SURFBAR_GET_REWARD()."", false);
- ADD_POINTS_REFSYSTEM(sprintf("surfbar_%s", getConfig('surfbar_pay_model')), getUserId(), SURFBAR_GET_DATA('reward'));
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'userid='.getUserId().',reward='.SURFBAR_GET_REWARD().'', false);
+ addPointsThroughReferalSystem(sprintf("surfbar_%s", getConfig('surfbar_pay_model')), getUserId(), SURFBAR_GET_DATA('reward'));
}
// Updates the statistics of current URL/userid
} // END - if
// Update URL stats
- SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_surfbar_urls` SET `views_total`=`views_total`+1".$add." WHERE `id`=%s LIMIT 1",
+ SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_surfbar_urls` SET `views_total`=`views_total`+1".$add." WHERE `id`=%s LIMIT 1",
array(SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
// 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",
+ 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__);
// 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)",
+ SQL_QUERY_ESC("INSERT INTO `{?_MYSQL_PREFIX?}_surfbar_stats` (userid,url_id,count) VALUES (%s,%s,1)",
array(getUserId(), SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
} // END - if
SURFBAR_UPDATE_INSERT_STATS_RECORD();
// 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",
+ 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__);
// Debug message
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "salt=".SURFBAR_GET_SALT().",id=".SURFBAR_GET_ID().",uid=".getUserId()."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'salt='.SURFBAR_GET_SALT().',id='.SURFBAR_GET_ID().',userid='.getUserId().'', 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')",
+ 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__);
} // END - if
// Debug message
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "affectedRows=".SQL_AFFECTEDROWS()."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'affectedRows='.SQL_AFFECTEDROWS().'', false);
// Return if the update was okay
return (SQL_AFFECTEDROWS() == 1);
// Check if the reload lock is active for given id
function SURFBAR_CHECK_RELOAD_LOCK ($urlId) {
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "id={$urlId}", false);
+ //* DEBUG: */ logDebugMessage(__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
SQL_FREERESULT($result);
// Return check
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "cnt={$cnt},".SURFBAR_GET_SURF_LOCK()."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'cnt=' . $cnt . ',' . SURFBAR_GET_SURF_LOCK() . '', false);
return ($cnt == 1);
}
function SURFBAR_DETERMINE_DEPLETED_USERIDS ($limit=0) {
// Init array
$UIDs = array(
- 'uid' => array(),
+ 'userid' => array(),
'points' => array(),
'notified' => array(),
);
// Do we have a current user id?
- if ((IS_MEMBER()) && ($limit == 0)) {
+ if ((isMember()) && ($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['userid'][getUserId()] = getUserId();
+ $UIDs['points'][getUserId()] = countSumTotalData(getUserId(), 'user_points', 'points') - countSumTotalData(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");
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "uid={$content['userid']},points={$points}", false);
+ $points = countSumTotalData($content['userid'], 'user_points', 'points') - countSumTotalData($content['userid'], 'user_data', 'used_points');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "userid={$content['userid']},points={$points}", false);
// Shall we add this to ignore?
if ($points <= $limit) {
// Ignore this one!
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "uid={$content['userid']} has depleted points amount!", false);
- $UIDs['uid'][$content['userid']] = $content['userid'];
+ //* 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'];
} // END - if
SQL_FREERESULT($result);
// Debug message
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "UIDs::count=".count($UIDs)." (with own userid=".getUserId().')', false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "UIDs::count=".count($UIDs)." (with own userid=".getUserId().')', false);
// Return result
return $UIDs;
// Determine how many users are Online in surfbar
function SURFBAR_DETERMINE_TOTAL_ONLINE () {
// Count all users in surfbar modue and return the value
- $result = SQL_QUERY_ESC("SELECT id
-FROM `{!_MYSQL_PREFIX!}_surfbar_stats`
-WHERE (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(last_online)) <= %s
-GROUP BY userid",
- array(getConfig('online_timeout')), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY("SELECT
+ `id`
+FROM
+ `{?_MYSQL_PREFIX?}_surfbar_stats`
+WHERE
+ (UNIX_TIMESTAMP() - UNIX_TIMESTAMP(`last_surfed`)) <= {?online_timeout?}
+GROUP BY
+ `userid` ASC", __FUNCTION__, __LINE__);
// Fetch count
$cnt = SQL_NUMROWS($result);
// Update the status now
// ---------- Comment out for debugging/developing member actions! ---------
- //SQL_QUERY_ESC("UPDATE `{!_MYSQL_PREFIX!}_surfbar_urls` SET `status`='%s' WHERE `id`=%s LIMIT 1",
+ //SQL_QUERY_ESC("UPDATE `{?_MYSQL_PREFIX?}_surfbar_urls` SET `status`='%s' WHERE `id`=%s LIMIT 1",
// array($newStatus, bigintval($urlId)), __FUNCTION__, __LINE__);
// ---------- Comment out for debugging/developing member actions! ---------
// ---------- Comment out for debugging/developing member actions! ---------
// Prepare content for notification routines
- $data[$urlId]['uid'] = $data[$urlId]['userid'];
- $data[$urlId]['frametester'] = FRAMETESTER($data[$urlId]['url']);
+ $data[$urlId]['userid'] = $data[$urlId]['userid'];
+ $data[$urlId]['frametester'] = generateFrametesterUrl($data[$urlId]['url']);
$data[$urlId]['reward'] = translateComma(getConfig('surfbar_static_reward'));
$data[$urlId]['costs'] = translateComma(getConfig('surfbar_static_costs'));
$percent = abs(log(getConfig('surfbar_dynamic_percent') / 100 + 1));
// Get total users
- $totalUsers = GET_TOTAL_DATA('CONFIRMED', 'user_data', 'userid', 'status', true);
+ $totalUsers = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
// Get online users
$onlineUsers = SURFBAR_DETERMINE_TOTAL_ONLINE();
$addon += abs(log($onlineUsers / $totalUsers + 1) * $percent * $totalUsers);
// Get total URLs
- $totalUrls = SURFBAR_GET_TOTAL_URLS('ACTIVE', '0');
+ $totalUrls = SURFBAR_GET_TOTAL_URLS('ACTIVE', 0);
// Get user's total URLs
$userUrls = SURFBAR_GET_TOTAL_USER_URLS(0, 'ACTIVE');
$percent = abs(log(getConfig('surfbar_dynamic_percent') / 100 + 1));
// Get total users
- $totalUsers = GET_TOTAL_DATA('CONFIRMED', 'user_data', 'userid', 'status', true);
+ $totalUsers = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true);
// Calculate addon
$addon += abs($max * $percent * $totalUsers);
// Get total URLs
- $totalUrls = SURFBAR_GET_TOTAL_URLS('ACTIVE', '0');
+ $totalUrls = SURFBAR_GET_TOTAL_URLS('ACTIVE', 0);
// Calculate addon
$addon += abs($max * $percent * $totalUrls);
$ignored = array();
// Get all id from locks within the timestamp
- $result = SQL_QUERY_ESC("SELECT id, url_id, UNIX_TIMESTAMP(last_surfed) AS last
+ $result = SQL_QUERY_ESC("SELECT `id`, `url_id`, UNIX_TIMESTAMP(`last_surfed`) AS last_surfed
FROM
- {!_MYSQL_PREFIX!}_surfbar_locks
+ `{?_MYSQL_PREFIX?}_surfbar_locks`
WHERE
- userid=%s
+ `userid`=%s
ORDER BY
- id ASC", array(getUserId()),
+ `id` ASC", array(getUserId()),
__FUNCTION__, __LINE__);
// Load all entries
while ($content = SQL_FETCHARRAY($result)) {
// Debug message
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "next - lid={$content['id']},url={$content['url_id']},rest=".(time() - $last).'/'.SURFBAR_GET_SURF_LOCK()."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'next - lid='.$content['id'].',url='.$content['url_id'].',rest='.(time() - $content['last_surfed']).'/'.SURFBAR_GET_SURF_LOCK().'', false);
// Skip entries that are too old
- if (($last > (time() - SURFBAR_GET_SURF_LOCK())) && (!in_array($content['url_id'], $ignored))) {
+ if (($content['last_surfed'] > (time() - SURFBAR_GET_SURF_LOCK())) && (!in_array($content['url_id'], $ignored))) {
// Debug message
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "okay - lid={$content['id']},url={$content['url_id']},last={$last}", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'okay - lid='.$content['id'].',url='.$content['url_id'].',last='.$content['last_surfed'].'', false);
// Add only if missing or bigger
- if ((!isset($IDs[$content['url_id']])) || ($IDs[$content['url_id']] > $last)) {
+ if ((!isset($IDs[$content['url_id']])) || ($IDs[$content['url_id']] > $content['last_surfed'])) {
// Debug message
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "ADD - lid={$content['id']},url={$content['url_id']},last={$last}", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ADD - lid='.$content['id'].',url='.$content['url_id'].',last='.$content['last_surfed'].'', false);
// Add this ID
- $IDs[$content['url_id']] = $last;
+ $IDs[$content['url_id']] = $content['last_surfed'];
$USE[$content['url_id']] = $content['id'];
} // END - if
} else {
// Debug message
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "ignore - lid={$content['id']},url={$content['url_id']},last={$last}", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'ignore - lid='.$content['id'].',url='.$content['url_id'].',last='.$content['last_surfed'].'', false);
// Ignore these old entries!
$ignored[] = $content['url_id'];
function SURFBAR_GET_MAX_RANDOM ($UIDs, $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
+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
+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__);
// Log last query
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "lastQuery=".getConfig('db_last_query')."|numRows=".SQL_NUMROWS($result)."|Affected=".SQL_AFFECTEDROWS()."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'lastQuery='.getConfig('db_last_query').'|numRows='.SQL_NUMROWS($result).'|Affected='.SQL_AFFECTEDROWS().'', false);
// Fetch max rand
$maxRand = SQL_NUMROWS($result);
// 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
+FROM `{?_MYSQL_PREFIX?}_surfbar_urls` AS u
WHERE u.userid=%s AND u.status != 'DELETED'
ORDER BY u.id ASC",
array(getUserId()), __FUNCTION__, __LINE__);
}
// "Getter" for member action array for given status
-function SURFBAR_getModeAction_ARRAY ($status) {
+function SURFBAR_GET_ARRAY_FROM_STATUS ($status) {
// Init array
$returnArray = array();
// Get all assigned actions
- $result = SQL_QUERY_ESC("SELECT action FROM `{!_MYSQL_PREFIX!}_surfbar_actions` WHERE `status`='%s' ORDER BY `id` ASC",
+ $result = SQL_QUERY_ESC("SELECT action FROM `{?_MYSQL_PREFIX?}_surfbar_actions` WHERE `status`='%s' ORDER BY `id` ASC",
array($status), __FUNCTION__, __LINE__);
// Some entries there?
$UIDs = SURFBAR_DETERMINE_DEPLETED_USERIDS();
// Get maximum randomness factor
- $maxRand = SURFBAR_GET_MAX_RANDOM($UIDs['uid'], $add);
+ $maxRand = SURFBAR_GET_MAX_RANDOM($UIDs['userid'], $add);
// If more than one URL can be called generate the random number!
if ($maxRand > 1) {
} // END - if
// And query the database
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "randNum={$randNum},maxRand={$maxRand},surfLock=".SURFBAR_GET_SURF_LOCK()."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'randNum='.$randNum.',maxRand='.$maxRand.',surfLock='.SURFBAR_GET_SURF_LOCK().'', false);
$result = SQL_QUERY_ESC("SELECT sbu.id, sbu.userid, sbu.url, sbs.last_salt, sbu.views_total, sbu.views_max, sbu.views_allowed, UNIX_TIMESTAMP(l.last_surfed) AS last_surfed, sbu.fixed_reload
-FROM `{!_MYSQL_PREFIX!}_surfbar_urls` AS sbu
-LEFT JOIN `{!_MYSQL_PREFIX!}_surfbar_salts` AS sbs
+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
+LEFT JOIN `{?_MYSQL_PREFIX?}_surfbar_locks` AS l
ON sbu.id=l.url_id
-WHERE sbu.userid NOT IN (".implode(',', $UIDs['uid']).") 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(',', $UIDs['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",
- array($randNum), __FUNCTION__, __LINE__
+ array($randNum), __FUNCTION__, __LINE__
);
} else {
// Get data from specified id number
$result = SQL_QUERY_ESC("SELECT sbu.id, sbu.userid, sbu.url, sbs.last_salt, sbu.views_total, sbu.views_max, sbu.views_allowed, UNIX_TIMESTAMP(l.last_surfed) AS last_surfed, sbu.fixed_reload
-FROM `{!_MYSQL_PREFIX!}_surfbar_urls` AS sbu
-LEFT JOIN `{!_MYSQL_PREFIX!}_surfbar_salts` AS sbs
+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
+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(getUserId(), bigintval($urlId)), __FUNCTION__, __LINE__
);
}
// Is there an id number?
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "lastQuery=".getConfig('db_last_query')."|numRows=".SQL_NUMROWS($result)."|Affected=".SQL_AFFECTEDROWS()."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'lastQuery='.getConfig('db_last_query').'|numRows='.SQL_NUMROWS($result).'|Affected='.SQL_AFFECTEDROWS().'', false);
if (SQL_NUMROWS($result) == 1) {
// Load/cache data
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "count(".count($GLOBALS['surfbar_cache']).") - BEFORE", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count('.count($GLOBALS['surfbar_cache']).') - BEFORE', false);
$GLOBALS['surfbar_cache'] = merge_array($GLOBALS['surfbar_cache'], SQL_FETCHARRAY($result));
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "count(".count($GLOBALS['surfbar_cache']).") - AFTER", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'count('.count($GLOBALS['surfbar_cache']).') - AFTER', false);
// Determine waiting time
$GLOBALS['surfbar_cache']['time'] = SURFBAR_DETERMINE_WAIT_TIME();
// Is the last salt there?
if (is_null($GLOBALS['surfbar_cache']['last_salt'])) {
// Then repair it wit the static!
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "last_salt - FIXED!", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'last_salt - FIXED!', false);
$GLOBALS['surfbar_cache']['last_salt'] = '';
} // END - if
// Fix missing last_surfed
if ((!isset($GLOBALS['surfbar_cache']['last_surfed'])) || (is_null($GLOBALS['surfbar_cache']['last_surfed']))) {
// Fix it here
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "last_surfed - FIXED!", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'last_surfed - FIXED!', false);
$GLOBALS['surfbar_cache']['last_surfed'] = 0;
} // END - if
// Get base/fixed reward and costs
$GLOBALS['surfbar_cache']['reward'] = SURFBAR_DETERMINE_REWARD();
$GLOBALS['surfbar_cache']['costs'] = SURFBAR_DETERMINE_COSTS();
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "BASE/STATIC - reward=".SURFBAR_GET_REWARD()."|costs=".SURFBAR_GET_COSTS()."", false);
+ //* 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') {
// Calculate dynamic reward/costs and add it
$GLOBALS['surfbar_cache']['reward'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
$GLOBALS['surfbar_cache']['costs'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "DYNAMIC+ - reward=".SURFBAR_GET_REWARD()."|costs=".SURFBAR_GET_COSTS()."", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'DYNAMIC+ - reward='.SURFBAR_GET_REWARD().'|costs='.SURFBAR_GET_COSTS().'', false);
} // END - if
// Now get the id
SQL_FREERESULT($result);
// Return result
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "nextId={$nextId}", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'nextId='.$nextId.'', false);
return $nextId;
}
// Private getter for data elements
function SURFBAR_GET_DATA ($element) {
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "element={$element}", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "element={$element}", false);
// Default is null
$data = null;
}
// Return result
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "element[$element]={$data}", false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, "element[$element]={$data}", false);
return $data;
}