// 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;
}
// 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;
}
// 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;
}
// 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;
}
// 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;
}
// Register the new URL
- die('limit='.$limit);
return SURFBAR_REGISTER_URL($url, getMemberId(), 'PENDING', 'reg', array('limit' => $limit));
}
// "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(
+ $OUT .= loadTemplate('member_list_surfbar_form', true, array(
'width' => $width,
'url_id' => bigintval($urlId),
'action' => strtolower($action)
// 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;
}
$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
} // 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
// Handle low-points amounts
SURFBAR_HANDLE_LOW_POINTS();
}
+
// Handle URLs which limit has depleted
function SURFBAR_HANDLE_DEPLETED_VIEWS () {
// Get all URLs
$data = $urlData;
// Rewrite array for next call
- $urlData[$id] = $data;
+ $urlData = array(
+ $id => $data
+ );
// Handle the status
SURFBAR_CHANGE_STATUS($id, 'ACTIVE', 'DEPLETED', $urlData);
$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
//* 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__);
}
// 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()
// 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()
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'];
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;
// 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!');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',prevStatus=' . $prevStatus . ',newStatus=' . $newStatus . ' - ENTERED!');
// Make new status always lower-case
$newStatus = strtolower($newStatus);
$data = SURFBAR_GET_URL_DATA($urlId);
} // END - if
- // Is the new status set?
- if ((!is_string($newStatus)) || (empty($newStatus))) {
- // Abort here, but fine!
- /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'newStatus[' . gettype($newStatus) . ']=' . $newStatus . ' - EXIT!');
- 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
- /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, $data[$urlId]['url_status'] . '!=' . $prevStatus . ' - EXIT!');
- 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
+ if (SQL_AFFECTEDROWS() != 1) {
+ // No, something went wrong
+ return false;
+ } // END - if
// ---------- Comment out for debugging/developing member actions! ---------
- // Prepare array
- $filterData = array(
- 'url_id' => $urlId,
- 'prev_status' => $prevStatus,
- 'new_status' => $newStatus,
- 'data' => $data
- );
-
// Run post filter chain
$filterData = runFilterChain('post_change_surfbar_url_status', $filterData);
// Extract data from it again
$data = $filterData['data'];
- // 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';
- } // END - if
-
- // Send admin notification
- SURFBAR_NOTIFY_ADMIN('url_' . strtolower($data[$urlId]['url_status']) . '_' . $newStatus, $data[$urlId]);
-
- // Send user notification
- SURFBAR_NOTIFY_USER('url_' . strtolower($data[$urlId]['url_status']) . '_' . $newStatus, $data[$urlId]);
-
// All done!
- /* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',prevStatus=' . $prevStatus . ',newStatus=' . $newStatus . ' - EXIT!');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'urlId=' . $urlId . ',prevStatus=' . $prevStatus . ',newStatus=' . $newStatus . ' - EXIT!');
return true;
}
// 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;
}
// Return result
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . $element . ']=[' . gettype($data) . ']' . $data, false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'element[' . $element . ']=[' . gettype($data) . ']' . $data . ' - EXIT!');
return $data;
}