}
// Writes content to a file
-function writeToFile ($FQFN, $content, $aquireLock = false) {
+function writeToFile ($FQFN, $content, $aquireLock = FALSE) {
// Is the file writeable?
if ((isFileReadable($FQFN)) && (!is_writeable($FQFN)) && (!changeMode($FQFN, 0644))) {
// Not writeable!
logDebugMessage(__FUNCTION__, __LINE__, sprintf("File %s not writeable.", basename($FQFN)));
// Failed! :(
- return false;
+ return FALSE;
} // END - if
// By default all is failed...
- $GLOBALS['file_readable'][$FQFN] = false;
+ $GLOBALS['file_readable'][$FQFN] = FALSE;
unset($GLOBALS['file_content'][$FQFN]);
- $return = false;
+ $return = FALSE;
// Is the function there?
if (function_exists('file_put_contents')) {
// With lock?
- if ($aquireLock === true) {
+ if ($aquireLock === TRUE) {
// Write it directly with lock
$return = file_put_contents($FQFN, $content, LOCK_EX);
} else {
$fp = fopen($FQFN, 'w') or reportBug(__FUNCTION__, __LINE__, 'Cannot write to file ' . basename($FQFN) . '!');
// Aquire a lock?
- if ($aquireLock === true) {
+ if ($aquireLock === TRUE) {
// Aquire a lock.
flock($fp, LOCK_EX);
} // END - if
}
// Was something written?
- if ($return !== false) {
+ if ($return !== FALSE) {
// Mark it as readable
- $GLOBALS['file_readable'][$FQFN] = true;
+ $GLOBALS['file_readable'][$FQFN] = TRUE;
// Remember content in cache
$GLOBALS['file_content'][$FQFN] = $content;
} // END - if
// Return status
- return (($return !== false) && (changeMode($FQFN, 0644)));
+ return (($return !== FALSE) && (changeMode($FQFN, 0644)));
}
// Clears the output buffer. This function does *NOT* backup sent content.
} // END - if
// Mark this function as called
- $GLOBALS[__FUNCTION__] = true;
+ $GLOBALS[__FUNCTION__] = TRUE;
}
// Encode strings
}
// Merges an array together but only if both are arrays
-function merge_array ($array1, $array2) {
+function merge_array ($array1, $array2, $keepIndex = FALSE) {
// Are both an array?
if ((!is_array($array1)) && (!is_array($array2))) {
// Both are not arrays
reportBug(__FUNCTION__, __LINE__, sprintf("array2 is not an array. array != %s", gettype($array2)));
}
- // Merge both together
- return array_merge($array1, $array2);
+ // Maintain index of array2?
+ if ($keepIndex === TRUE) {
+ // Keep index of array2, array_merge() rewrites e.g. $key=1 to $key=0, $key=2 to $key=1 ! :(
+ foreach ($array2 as $key => $value) {
+ // Add it
+ $array1[$key] = $value;
+ } // END - foreach
+
+ // Return it
+ return $array1;
+ } else {
+ // Merge both together normally
+ return array_merge($array1, $array2);
+ }
}
// Check if given FQFN is a readable file
}
// "Getter" for the real remote IP number
-function detectRealIpAddress () {
+function detectRealIpAddress ($alwaysReal = FALSE) {
// Get remote ip from environment
$remoteAddr = determineRealRemoteAddress();
// Is removeip installed?
- if (isExtensionActive('removeip')) {
+ if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
// Then anonymize it
$remoteAddr = getAnonymousRemoteAddress($remoteAddr);
} // END - if
}
// "Getter" for remote IP number
-function detectRemoteAddr () {
+function detectRemoteAddr ($alwaysReal = FALSE) {
// Get remote ip from environment
- $remoteAddr = determineRealRemoteAddress(true);
+ $remoteAddr = determineRealRemoteAddress(TRUE);
// Is removeip installed?
- if (isExtensionActive('removeip')) {
+ if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
// Then anonymize it
$remoteAddr = getAnonymousRemoteAddress($remoteAddr);
} // END - if
}
// "Getter" for remote hostname
-function detectRemoteHostname () {
+function detectRemoteHostname ($alwaysReal = FALSE) {
// Get remote ip from environment
$remoteHost = getenv('REMOTE_HOST');
// Is removeip installed?
- if (isExtensionActive('removeip')) {
+ if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
// Then anonymize it
$remoteHost = getAnonymousRemoteHost($remoteHost);
} // END - if
}
// "Getter" for user agent
-function detectUserAgent ($alwaysReal = false) {
+function detectUserAgent ($alwaysReal = FALSE) {
// Get remote ip from environment
$userAgent = getenv('HTTP_USER_AGENT');
// Is removeip installed?
- if ((isExtensionActive('removeip')) && ($alwaysReal === false)) {
+ if ((isExtensionActive('removeip')) && ($alwaysReal === FALSE)) {
// Then anonymize it
$userAgent = getAnonymousUserAgent($userAgent);
} // END - if
}
// "Getter" for referer
-function detectReferer () {
+function detectReferer ($alwaysReal = FALSE) {
// Get remote ip from environment
$referer = getenv('HTTP_REFERER');
// Is removeip installed?
- if (isExtensionActive('removeip')) {
+ if ((isExtensionActive('removeip')) && ($alwaysReal === TRUE)) {
// Then anonymize it
$referer = getAnonymousReferer($referer);
} // END - if
// Checks whether the hourly reset mode is active
function isHourlyResetEnabled () {
// Now simply check it
- return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === true));
+ return ((isset($GLOBALS['hourly_enabled'])) && ($GLOBALS['hourly_enabled'] === TRUE));
}
// Checks whether the reset mode is active
function isResetModeEnabled () {
// Now simply check it
- return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === true));
+ return ((isset($GLOBALS['reset_enabled'])) && ($GLOBALS['reset_enabled'] === TRUE));
}
// Checks whether the debug mode is enabled
// even if there is no xdebug extension installed.
function copyFileVerified ($source, $dest, $chmod = '') {
// Failed is the default
- $status = false;
+ $status = FALSE;
// Is the source file there?
if (!isFileReadable($source)) {
reportBug(__FUNCTION__, __LINE__, 'copy() has failed to copy the file.');
} else {
// Reset cache
- $GLOBALS['file_readable'][$dest] = true;
+ $GLOBALS['file_readable'][$dest] = TRUE;
}
// All fine by default
- $status = true;
+ $status = TRUE;
// If there are chmod rights set, apply them
if (!empty($chmod)) {
// Is the file there?
if (isFileReadable($FQFN)) {
// Reset cache first
- $GLOBALS['file_readable'][$FQFN] = false;
+ $GLOBALS['file_readable'][$FQFN] = FALSE;
// Yes, so remove it
return unlink($FQFN);
// All fine if no file was removed. If we change this to 'false' or rewrite
// above if() block it would be to restrictive.
- return true;
+ return TRUE;
}
// Wrapper for $_POST['sel']
// Checks whether the config-local.php is loaded
function isConfigLocalLoaded () {
- return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === true));
+ return ((isset($GLOBALS['config_local_loaded'])) && ($GLOBALS['config_local_loaded'] === TRUE));
}
// Checks whether a nickname or userid was entered and caches the result
// Is the cache there
if (!isset($GLOBALS[__FUNCTION__][$userid])) {
// Determine it
- $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, true, false) . '') != $userid) && ($userid != 'NULL'));
+ $GLOBALS[__FUNCTION__][$userid] = ((!empty($userid)) && (('' . bigintval($userid, TRUE, FALSE) . '') != $userid) && ($userid != 'NULL'));
} // END - if
// Return the result
}
// Getter for 'what' value
-function getWhat ($strict = true) {
+function getWhat ($strict = TRUE) {
// Default is null
$what = NULL;
$isset = (isset($GLOBALS['__what']) && (!empty($GLOBALS['__what'])));
// Should we abort here?
- if (($strict === true) && ($isset === false)) {
+ if (($strict === TRUE) && ($isset === FALSE)) {
// Output backtrace
debug_report_bug(__FUNCTION__, __LINE__, 'what is empty.');
} // END - if
}
// Getter for 'action' value
-function getAction ($strict = true) {
+function getAction ($strict = TRUE) {
// Default is null
$action = NULL;
$isset = ((isset($GLOBALS['__action'])) && (!empty($GLOBALS['__action'])));
// Should we abort here?
- if (($strict === true) && ($isset === false)) {
+ if (($strict === TRUE) && ($isset === FALSE)) {
// Output backtrace
reportBug(__FUNCTION__, __LINE__, 'action is empty.');
} // END - if
}
// Getter for 'module' value
-function getModule ($strict = true) {
+function getModule ($strict = TRUE) {
// Default is null
$module = NULL;
$isset = ((isset($GLOBALS['__module'])) && (!empty($GLOBALS['__module'])));
// Should we abort here?
- if (($strict === true) && ($isset === false)) {
+ if (($strict === TRUE) && ($isset === FALSE)) {
// Output backtrace
reportBug(__FUNCTION__, __LINE__, 'Module is empty.');
} // END - if
// Return it
- return (($isset === true) && ($GLOBALS['__module'] != 'unknown')) ;
+ return (($isset === TRUE) && ($GLOBALS['__module'] != 'unknown')) ;
}
// Getter for 'output_mode' value
$isset = (isset($GLOBALS['__output_mode']));
// Should we abort here?
- if (($strict === true) && ($isset === false)) {
+ if (($strict === TRUE) && ($isset === FALSE)) {
// Output backtrace
reportBug(__FUNCTION__, __LINE__, 'Output mode is not set.');
} // END - if
}
// Enables block-mode
-function enableBlockMode ($enabled = true) {
+function enableBlockMode ($enabled = TRUE) {
$GLOBALS['__block_mode'] = $enabled;
}
// Wrapper function to redirect to de-refered URL
function redirectToDereferedUrl ($url) {
// Redirect to to
- redirectToUrl(generateDerefererUrl($url));
+ redirectToUrl(generateDereferrerUrl($url));
}
// Wrapper function for checking if extension is installed and newer or same version
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'isCurrentUserIdSet()=false - ABORTING!');
// Abort here
- return false;
+ return FALSE;
} // END - if
// Is it cached?
// Wrapper for strpos() to ease porting from deprecated ereg() function
function isInString ($needle, $haystack) {
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== false));
- return (strpos($haystack, $needle) !== false);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'needle=' . $needle . ', haystack=' . $haystack . ', returned=' . intval(strpos($haystack, $needle) !== FALSE));
+ return (strpos($haystack, $needle) !== FALSE);
}
// Wrapper for strpos() to ease porting from deprecated eregi() function
if (!isset($GLOBALS[__FUNCTION__])) {
// Then do it
if (isExtensionActive('user')) {
- $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
+ $GLOBALS[__FUNCTION__] = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
} else {
$GLOBALS[__FUNCTION__] = 0;
}
} // END - if
// Return cached value
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
return $GLOBALS[__FUNCTION__];
}
if (!isset($GLOBALS[__FUNCTION__])) {
// Then do it
if (isExtensionActive('user')) {
- $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
+ $GLOBALS[__FUNCTION__] = countSumTotalData('UNCONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
} else {
$GLOBALS[__FUNCTION__] = 0;
}
} // END - if
// Return cached value
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
return $GLOBALS[__FUNCTION__];
}
if (!isset($GLOBALS[__FUNCTION__])) {
// Then do it
if (isExtensionActive('user')) {
- $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' '));
+ $GLOBALS[__FUNCTION__] = countSumTotalData('LOCKED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' '));
} else {
$GLOBALS[__FUNCTION__] = 0;
}
} // END - if
// Return cached value
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
return $GLOBALS[__FUNCTION__];
}
if (!isset($GLOBALS[__FUNCTION__])) {
// Then do it
if (isExtensionInstalledAndNewer('user', '0.3.4')) {
- $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', true, runFilterChain('user_exclusion_sql', ' '), '>=');
+ $GLOBALS[__FUNCTION__] = countSumTotalData('{?user_min_confirmed?}', 'user_data', 'userid', 'rand_confirmed', TRUE, runFilterChain('user_exclusion_sql', ' '), '>=');
} else {
$GLOBALS[__FUNCTION__] = 0;
}
} // END - if
// Return cached value
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, __FUNCTION__ . '()=' . $GLOBALS[__FUNCTION__]);
return $GLOBALS[__FUNCTION__];
}
// Encodes entities
function encodeEntities ($str) {
// Secure it first
- $str = secureString($str, true, true);
+ $str = secureString($str, TRUE, TRUE);
// Encode dollar sign as well
$str = str_replace('$', '$', $str);
// Read and convert given entry
$postValue = convertCommaToDot(postRequestElement($postEntry));
+ // Log message
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'postEntry=' . $postEntry . ',postValue=' . $postValue);
+
// ... and set it again
setPostRequestElement($postEntry, $postValue);
}
* Searches a multi-dimensional array (as used in many places) for given
* key/value pair as taken from user comments from PHP documentation website.
*
- * @param $array An array with one or more dimensions
- * @param $key Key to look for
- * @param $valur Value to look for
- * @return $results Resulted array or empty array if $array is no array
+ * @param $array An array with one or more dimensions
+ * @param $key Key to look for
+ * @param $value Value to look for
+ * @param $parentIndex Parent index (ONLY INTERNAL USE!)
+ * @return $results Resulted array or empty array if $array is no array
* @author sunelbe<at>gmail<dot>com
* @link http://de.php.net/manual/en/function.array-search.php#110120
*/
-function search_array ($array, $key, $value) {
+function search_array ($array, $key, $value, $parentIndex = NULL) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'array(' . count($array) . ')=' . print_r($array, TRUE) . ',key=' . $key . ',value=' . $value . ',parentIndex[' . gettype($parentIndex) . '=' . $parentIndex . ' - ENTERED!');
// Init array result
$results = array();
// Is $array really an array?
if (is_array($array)) {
- // Does key and value match?
- if (isset($array[$key]) && $array[$key] == $value) {
- // Then add it as result
- $results[] = $array;
- } // END - if
-
// Search for whole array
- foreach ($array as $subArray) {
- // Search recursive and merge again
- $results = merge_array($results, search_array($subArray, $key, $value));
+ foreach ($array as $idx => $dummy) {
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'key=' . $key . ',value=' . $value . ',idx=' . $idx);
+ // Is dummy an array?
+ if (is_array($dummy)) {
+ // Then search again
+ $subResult = search_array($dummy, $key, $value, $idx);
+ //* DEBUG: */ print 'subResult=<pre>' . print_r($subResult, TRUE).'</pre>';
+
+ // And merge both
+ $results = merge_array($results, $subResult, TRUE);
+ } elseif ((isset($array[$key])) && ($array[$key] == $value)) {
+ // Is found, so add it
+ $results[$parentIndex] = $array;
+ }
} // END - foreach
} // END - if
// Return resulting array
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'results(' . count($results) . ')=' . print_r($results, TRUE) . ' - EXIT!');
return $results;
}
// "Getter" for total available receivers
function getTotalReceivers ($mode = 'normal') {
// Get num rows
- $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', true, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
+ $numRows = countSumTotalData('CONFIRMED', 'user_data', 'userid', 'status', TRUE, runFilterChain('user_exclusion_sql', ' AND `receive_mails` > 0' . runFilterChain('exclude_users', $mode)));
// Return value
return $numRows;
// Is there cache?
if (!isset($GLOBALS[__FUNCTION__][$userid])) {
// Determine it
- $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', true);
+ $GLOBALS[__FUNCTION__][$userid] = countSumTotalData($userid, 'user_links', 'id', 'userid', TRUE);
} // END - if
// Return cache
// Checks whether frameset_mode is set to true
function isFramesetModeEnabled () {
// Check it
- return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === true));
+ return ((isset($GLOBALS['frameset_mode'])) && ($GLOBALS['frameset_mode'] === TRUE));
}
// Function to determine correct 'what' value
function convertSelectionsToEpocheTimeInPostData ($id) {
// Init variables
$content = array();
- $skip = false;
+ $skip = FALSE;
// Get all POST data
$postData = postRequestArray();
// Wraps checking if given points account type matches with given in POST data
function ifPointsAccountTypeMatchesPost ($type) {
// Check condition
- exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), true).'</pre>');
+ exit(__FUNCTION__.':type='.$type.',post=<pre>'.print_r(postRequestArray(), TRUE).'</pre>');
}
// Gets given user's total referral
// Is the level NULL?
if (is_null($level)) {
// Get total amount (all levels)
- $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true);
+ $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE);
} else {
// Get it from user refs
- $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', true, ' AND `level`=' . bigintval($level));
+ $GLOBALS[__FUNCTION__][$userid][$level] = countSumTotalData($userid, 'user_refs', 'refid', 'userid', TRUE, ' AND `level`=' . bigintval($level));
}
} // END - if