}
// Generate a password in a specified length or use default password length
-function generatePassword ($LEN = 0) {
+function generatePassword ($length = 0) {
// Auto-fix invalid length of zero
- if ($LEN == 0) $LEN = getConfig('pass_len');
+ if ($length == 0) $length = getConfig('pass_len');
// Initialize array with all allowed chars
- $ABC = explode(',', 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9,-,+,_,/');
+ $ABC = explode(',', 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,0,1,2,3,4,5,6,7,8,9,-,+,_,/,.');
// Start creating password
$PASS = '';
- for ($i = 0; $i < $LEN; $i++) {
+ for ($i = 0; $i < $length; $i++) {
$PASS .= $ABC[mt_rand(0, count($ABC) -1)];
} // END - for
// Generates a ***weak*** seed (taken from de.php.net/mt_srand)
function generateSeed () {
- list($usec, $sec) = explode(" ", microtime());
- return ((float)$sec + (float)$usec);
+ list($usec, $sec) = explode(' ', microtime());
+ $microTime = (((float)$sec + (float)$usec)) * 100000;
+ return $microTime;
}
// Converts a message code to a human-readable message
// Is the function there?
if (function_exists($functionName)) {
// Add new status
- $URLs[$formData['id']]['new_status'] = $GLOBALS['cache_array']['surfbar']['new_status'];
+ $URLs[$formData['id']]['new_status'] = SURFBAR_GET_NEW_STATUS('new_status');
// Extract URL data for call-back
$urlData = array(merge_array($URLs[$formData['id']], array($action => $formData)));
// Fetch the new status if found
if ($isValid) {
// Load new status
- list($GLOBALS['cache_array']['surfbar']['new_status']) = SQL_FETCHROW($result);
+ list($GLOBALS['surfbar_cache']['new_status']) = SQL_FETCHROW($result);
} // END - if
// Free result
$isFull = true;
// Cache static reload lock
- $GLOBALS['cache_array']['surfbar']['surf_lock'] = getConfig('surfbar_static_lock');
+ $GLOBALS['surfbar_cache']['surf_lock'] = getConfig('surfbar_static_lock');
//* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "Fixed surf lock is ".getConfig('surfbar_static_lock')."", false);
// Do we have dynamic model?
if (getConfig('surfbar_pay_model') == 'DYNAMIC') {
// "Calculate" dynamic lock
- $GLOBALS['cache_array']['surfbar']['surf_lock'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
+ $GLOBALS['surfbar_cache']['surf_lock'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
} // END - if
// Ask the database
);
// Fetch row
- list($GLOBALS['cache_array']['surfbar']['user_locks']) = SQL_FETCHROW($result);
+ list($GLOBALS['surfbar_cache']['user_locks']) = SQL_FETCHROW($result);
// Is it null?
- if (is_null($GLOBALS['cache_array']['surfbar']['user_locks'])) {
+ if (is_null($GLOBALS['surfbar_cache']['user_locks'])) {
// Then fix it to zero!
- $GLOBALS['cache_array']['surfbar']['user_locks'] = 0;
+ $GLOBALS['surfbar_cache']['user_locks'] = 0;
} // END - if
// Free result
// Get amount from database
$result = SQL_QUERY_ESC("SELECT COUNT(id) AS cnt
FROM `{!_MYSQL_PREFIX!}_surfbar_urls`
-WHERE userid=%s".$add."
+WHERE `userid`=%s".$add."
LIMIT %s",
- array($uid, getConfig('surfbar_max_order')), __FUNCTION__, __LINE__
+ array($uid, getConfig('surfbar_max_order')), __FUNCTION__, __LINE__
);
// Fetch row
// Generate a validation code for the given id number
function SURFBAR_GENERATE_VALIDATION_CODE ($urlId, $salt = '') {
// @TODO Invalid salt should be refused
- $GLOBALS['cache_array']['surfbar']['salt'] = "INVALID";
+ $GLOBALS['surfbar_cache']['salt'] = 'INVALID';
// Get code length from config
$length = getConfig('code_length');
// Is the salt set?
if (empty($salt)) {
// Generate random hashed string
- $GLOBALS['cache_array']['surfbar']['salt'] = sha1(generatePassword(255));
+ $GLOBALS['surfbar_cache']['salt'] = sha1(generatePassword(mt_rand(200, 255)));
//* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "newSalt=".SURFBAR_GET_SALT()."", false);
} else {
// Use this as salt!
- $GLOBALS['cache_array']['surfbar']['salt'] = $salt;
+ $GLOBALS['surfbar_cache']['salt'] = $salt;
//* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "oldSalt=".SURFBAR_GET_SALT()."", false);
}
// Lockdown the userid/id combination (reload lock)
function SURFBAR_LOCKDOWN_ID ($urlId) {
- //* DEBUG: */ print "LOCK!");
+ //* DEBUG: */ print "LOCK!";
///* DEBUG: */ return;
// Just add it to the database
- SQL_QUERY_ESC("INSERT INTO `{!_MYSQL_PREFIX!}_surfbar_locks` (userid, url_id) VALUES (%s, %s)",
- array(getUserId(), bigintval($urlId)), __FUNCTION__, __LINE__);
+ 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",
- array(bigintval($urlId), getUserId()), __FUNCTION__, __LINE__);
+ 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"
// Do we have a limit?
if ($allowed > 0) {
// Then count views_max down!
- $add .= ",views_max=views_max-1";
+ $add .= ", `views_max`=`views_max`-1";
} // 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",
- array(SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
+ 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",
- array(getUserId(), SURFBAR_GET_ID()), __FUNCTION__, __LINE__);
+ 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) {
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",
- array(SURFBAR_GET_SALT(), SURFBAR_GET_ID(), getUserId()), __FUNCTION__, __LINE__);
+ 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);
// 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')",
- array(SURFBAR_GET_ID(), getUserId(), SURFBAR_GET_SALT()), __FUNCTION__, __LINE__);
+ 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__, "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['cache_array']['surfbar']).") - BEFORE", false);
- $GLOBALS['cache_array']['surfbar'] = merge_array($GLOBALS['cache_array']['surfbar'], SQL_FETCHARRAY($result));
- //* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "count(".count($GLOBALS['cache_array']['surfbar']).") - AFTER", false);
+ //* DEBUG: */ DEBUG_LOG(__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);
// Determine waiting time
- $GLOBALS['cache_array']['surfbar']['time'] = SURFBAR_DETERMINE_WAIT_TIME();
+ $GLOBALS['surfbar_cache']['time'] = SURFBAR_DETERMINE_WAIT_TIME();
// Is the last salt there?
- if (is_null($GLOBALS['cache_array']['surfbar']['last_salt'])) {
+ if (is_null($GLOBALS['surfbar_cache']['last_salt'])) {
// Then repair it wit the static!
//* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "last_salt - FIXED!", false);
- $GLOBALS['cache_array']['surfbar']['last_salt'] = '';
+ $GLOBALS['surfbar_cache']['last_salt'] = '';
} // END - if
// Fix missing last_surfed
- if ((!isset($GLOBALS['cache_array']['surfbar']['last_surfed'])) || (is_null($GLOBALS['cache_array']['surfbar']['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);
- $GLOBALS['cache_array']['surfbar']['last_surfed'] = 0;
+ $GLOBALS['surfbar_cache']['last_surfed'] = 0;
} // END - if
// Get base/fixed reward and costs
- $GLOBALS['cache_array']['surfbar']['reward'] = SURFBAR_DETERMINE_REWARD();
- $GLOBALS['cache_array']['surfbar']['costs'] = SURFBAR_DETERMINE_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);
// Only in dynamic model add the dynamic bonus!
if (getConfig('surfbar_pay_model') == 'DYNAMIC') {
// Calculate dynamic reward/costs and add it
- $GLOBALS['cache_array']['surfbar']['reward'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
- $GLOBALS['cache_array']['surfbar']['costs'] += SURFBAR_CALCULATE_DYNAMIC_ADD();
+ $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);
} // END - if
// -----------------------------------------------------------------------------
// PLEASE DO NOT ADD ANY OTHER FUNCTIONS BELOW THIS LINE IF THEY DON'T "WRAP"
-// THE $GLOBALS['cache_array']['surfbar'] ARRAY!
+// THE $GLOBALS['surfbar_cache'] ARRAY!
// -----------------------------------------------------------------------------
+
+// Initializes the surfbar
+function SURFBAR_INIT () {
+ // Init cache array
+ $GLOBALS['surfbar_cache'] = array();
+}
+
// Private getter for data elements
function SURFBAR_GET_DATA ($element) {
//* DEBUG: */ DEBUG_LOG(__FUNCTION__, __LINE__, "element={$element}", false);
$data = null;
// Is the entry there?
- if (isset($GLOBALS['cache_array']['surfbar'][$element])) {
+ if (isset($GLOBALS['surfbar_cache'][$element])) {
// Then take it
- $data = $GLOBALS['cache_array']['surfbar'][$element];
+ $data = $GLOBALS['surfbar_cache'][$element];
} else { // END - if
print("<pre>");
- print_r($GLOBALS['cache_array']['surfbar']);
+ print_r($GLOBALS['surfbar_cache']);
print("</pre>");
debug_report_bug();
}
return SURFBAR_GET_DATA('surf_lock');
}
+// Getter for new status
+function SURFBAR_GET_NEW_STATUS () {
+ // Get data element and return its contents
+ return SURFBAR_GET_DATA('new_status');
+}
+
// [EOF]
?>