-// Check wether a session variable is set
-function isSessionVariableSet ($var) {
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):var={$var}<br />\n";
- return (isset($_SESSION[$var]));
-}
-// Returns wether the value of the session variable or NULL if not set
-function get_session ($var) {
- global $cacheArray;
-
- // Default is not found! ;-)
- $value = null;
-
- // Is the variable there or cached values?
- if (isset($cacheArray['session'][$var])) {
- // Get cached value (skips a lot SQL_ESCAPE() calles!
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$var."-CACHE!<br />\n";
- $value = $cacheArray['session'][$var];
- } elseif (isSessionVariableSet($var)) {
- // Then get it secured!
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): ".$var."-RESOLVE!<br />\n";
- $value = SQL_ESCAPE($_SESSION[$var]);
-
- // Cache the value
- $cacheArray['session'][$var] = $value;
- } // END - if
-
- // Return the value
- return $value;
-}
-// Send notification to admin
-function SEND_ADMIN_NOTIFICATION($subject, $templateName, $content=array(), $uid="0") {
- if (GET_EXT_VERSION("admins") >= "0.4.1") {
- // Send new way
- SEND_ADMIN_EMAILS_PRO($subject, $templateName, $content, $uid);
- } else {
- // Send outdated way
- $msg = LOAD_EMAIL_TEMPLATE($templateName, $content, $uid);
- SEND_ADMIN_EMAILS($subject, $msg);
- }
-}
-// Destroy user session
-function destroy_user_session () {
- // Remove all user data from session
- return ((set_session("userid", "")) && (set_session("u_hash", "")) && (set_session("lifetime", "")));
-}
-// Merges an array together but only if both are arrays
-function merge_array ($array1, $array2) {
- // Are both an array?
- if ((is_array($array1)) && (is_array($array2))) {
- // Merge all together
- return array_merge($array1, $array2);
- } elseif (is_array($array1)) {
- // Return left array
- return $array1;
- }
-
- // Something wired happened here...
- print(__FUNCTION__.":<pre>");
- debug_print_backtrace();
- die("</pre>");
-}
-// Debug message logger
-function DEBUG_LOG ($file, $line, $message, $force=true) {
- // Is debug mode enabled?
- if ((isBooleanConstantAndTrue('DEBUG_MODE')) || ($force)) {
- // Log this message away
- $fp = fopen(PATH."inc/cache/debug.log", 'a') or mxchange_die("Cannot write logfile debug.log!");
- fwrite($fp, date("d.m.Y|H:i:s", time())."|".basename($file)."|".$line."|".strip_tags($message)."\n");
- fclose($fp);
- } // END - if
-}
-// Reads a directory with PHP files in and gets only files back
-function GET_DIR_AS_ARRAY ($baseDir, $prefix) {
- $INCs = array();
-
- // Open directory
- $dirPointer = opendir($baseDir) or mxchange_die("Cannot read ".basename($baseDir)." path!");
-
- // Read all entries
- while ($baseFile = readdir($dirPointer)) {
- // Load file only if extension is active
- // Make full path
- $file = $baseDir.$baseFile;
-
- // Is this a valid reset file?
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):baseDir={$baseDir},prefix={$prefix},baseFile={$baseFile}<br />\n";
- if ((FILE_READABLE($file)) && (substr($baseFile, 0, strlen($prefix)) == $prefix) && (substr($baseFile, -4, 4) == ".php")) {
- // Remove both for extension name
- $extName = substr($baseFile, strlen($prefix), -4);
-
- // Try to find it
- $extId = GET_EXT_ID($extName);
-
- // Is the extension valid and active?
- if (($extId > 0) && (EXT_IS_ACTIVE($extName))) {
- // Then add this file
- $INCs[] = $file;
- } elseif ($extId == 0) {
- // Add non-extension files as well
- $INCs[] = $file;
- }
- } // END - if
- } // END - while
-
- // Close directory
- closedir($dirPointer);
-
- // Sort array
- asort($INCs);
-
- // Return array with include files
- return $INCs;
-}
-// Load more reset scripts
-function RESET_ADD_INCLUDES () {
- // Is the reset set or old sql_patches?
- if ((!defined('__DAILY_RESET')) || (EXT_VERSION_IS_OLDER("sql_patches", "0.4.5"))) {
- // Then abort here
- return array();
- } // END - if
-
- // Get more daily reset scripts
- $INC_POOL = GET_DIR_AS_ARRAY(PATH."inc/reset/", "reset_");
-
- // Update database
- if (!defined('DEBUG_RESET')) UPDATE_CONFIG("last_update", time());
-
- // Create current week mark
- $currWeek = date("W", time());
-
- // Has it changed?
- if (getConfig('last_week') != $currWeek) {
- // Include weekly reset scripts
- $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY(PATH."inc/weekly/", "weekly_"));
-
- // Update config
- if (!defined('DEBUG_WEEKLY')) UPDATE_CONFIG("last_week", $currWeek);
- } // END - if
-
- // Create current month mark
- $currMonth = date("m", time());
-
- // Has it changed?
- if (getConfig('last_month') != $currMonth) {
- // Include monthly reset scripts
- $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY(PATH."inc/monthly/", "monthly_"));
-
- // Update config
- if (!defined('DEBUG_MONTHLY')) UPDATE_CONFIG("last_month", $currMonth);
- } // END - if
-
- // Return array
- return $INC_POOL;
-}
-// Handle extra values
-function HANDLE_EXTRA_VALUES ($filterFunction, $value, $extraValue) {
- // Default is the value itself
- $ret = $value;
-
- // Do we have a special filter function?
- if (!empty($filterFunction)) {
- // Does the filter function exist?
- if (function_exists($filterFunction)) {
- // Do we have extra parameters here?
- if (!empty($extraValue)) {
- // Put both parameters in one new array by default
- $args = array($value, $extraValue);
-
- // If we have an array simply use it and pre-extend it with our value
- if (is_array($extraValue)) {
- // Make the new args array
- $args = merge_array(array($value), $extraValue);
- } // END - if
-
- // Call the multi-parameter call-back
- $ret = call_user_func_array($filterFunction, $args);
- } else {
- // One parameter call
- $ret = call_user_func($filterFunction, $value);
- }
- } // END - if
- } // END - if
-
- // Return the value
- return $ret;
-}
-// Check if given FQFN is a readable file
-function FILE_READABLE($fqfn) {
- // Check all...
- return ((file_exists($fqfn)) && (is_file($fqfn)) && (is_readable($fqfn)));
-}
-// Converts timestamp selections into a timestamp
-function CONVERT_SELECTIONS_TO_TIMESTAMP(&$POST, &$DATA, &$id, &$skip) {
- // Init test variable
- $test2 = "";
-
- // Get last three chars
- $test = substr($id, -3);
-
- // Improved way of checking! :-)
- if (in_array($test, array("_ye", "_mo", "_we", "_da", "_ho", "_mi", "_se"))) {
- // Found a multi-selection for timings?
- $test = substr($id, 0, -3);
- if ((isset($POST[$test."_ye"])) && (isset($POST[$test."_mo"])) && (isset($POST[$test."_we"])) && (isset($POST[$test."_da"])) && (isset($POST[$test."_ho"])) && (isset($POST[$test."_mi"])) && (isset($POST[$test."_se"])) && ($test != $test2)) {
- // Generate timestamp
- $POST[$test] = CREATE_TIMESTAMP_FROM_SELECTIONS($test, $POST);
- $DATA[] = sprintf("%s='%s'", $test, $POST[$test]);
-
- // Remove data from array
- foreach (array("ye", "mo", "we", "da", "ho", "mi", "se") as $rem) {
- unset($POST[$test."_".$rem]);
- } // END - foreach
-
- // Skip adding
- unset($id); $skip = true; $test2 = $test;
- } // END - if
- } else {
- // Process this entry
- $skip = false; $test2 = "";
- }
-}
-// Reverts the german decimal comma into Computer decimal dot
-function REVERT_COMMA ($str) {
- // Default float is not a float... ;-)
- $float = false;
-
- // Which language is selected?
- switch (GET_LANGUAGE()) {
- case "de": // German language
- // Remove german thousand dots first
- $str = str_replace(".", "", $str);
-
- // Replace german commata with decimal dot and cast it
- $float = (float)str_replace(",", ".", $str);
- break;
-
- default: // US and so on
- // Remove thousand dots first and cast
- $float = (float)str_replace(",", "", $str);
- break;
- }
-
- // Return float
- return $float;
-}
-
-// Handle menu-depending failed logins and return the rendered content
-function HANDLE_LOGIN_FAILTURES ($accessLevel) {
- // Default output is empty ;-)
- $OUT = "";
-
- // Is the session data set?
- if ((isSessionVariableSet('mxchange_'.$accessLevel.'_failtures')) && (isSessionVariableSet('mxchange_'.$accessLevel.'_last_fail'))) {
- // Ignore zero values
- if (get_session('mxchange_'.$accessLevel.'_failtures') > 0) {
- // Non-guest has login failtures found, get both data and prepare it for template
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>):accessLevel={$accessLevel}<br />\n";
- $content = array(
- 'login_failtures' => get_session('mxchange_'.$accessLevel.'_failtures'),
- 'last_failture' => MAKE_DATETIME(get_session('mxchange_'.$accessLevel.'_last_fail'), "2")
- );
-
- // Load template
- $OUT = LOAD_TEMPLATE("login_failtures", true, $content);
- } // END - if
-
- // Reset session data
- set_session('mxchange_'.$accessLevel.'_failtures', "");
- set_session('mxchange_'.$accessLevel.'_last_fail', "");
- } // END - if
-
- // Return rendered content
- return $OUT;
-}
-
-// Rebuild cache
-function REBUILD_CACHE ($cache, $inc="") {
- global $cacheInstance, $CSS;
-
- // Shall I remove the cache file?
- if ((EXT_IS_ACTIVE("cache")) && (is_object($cacheInstance))) {
- // Rebuild cache
- if ($cacheInstance->loadCacheFile($cache)) {
- // Destroy it
- $cacheInstance->destroyCacheFile();
- } // END - if
-
- // Include file given?
- if (!empty($inc)) {
- // Construct FQFN
- $fqfn = sprintf("%sinc/loader/load_cache-%s.php", PATH, $inc);
-
- // Is the include there?
- if (FILE_READABLE($fqfn)) {
- // And rebuild it from scratch
- //* DEBUG: */ print __FUNCTION__."(<font color=\"#0000aa\">".__LINE__."</font>): inc={$inc} - LOADED!<br />\n";
- require($fqfn);
- } else {
- // Include not found!
- DEBUG_LOG(__FUNCTION__, __LINE__, "Include {$inc} not found. cache={$cache}");
- }
- } // END - if
- } // END - if
-}
-
-// Purge admin menu cache
-function CACHE_PURGE_ADMIN_MENU ($id=0, $action="", $what="", $str="") {
- global $cacheInstance;
-
- // Is the cache extension enabled or no cache instance or admin menu cache disabled?
- if (!EXT_IS_ACTIVE("cache")) {
- // Cache extension not active
- return false;
- } elseif (!is_object($cacheInstance)) {
- // No cache instance!
- DEBUG_LOG(__FUNCTION__, __LINE__, " No cache instance found.");
- return false;
- } elseif ((getConfig('cache_admin_menu') == null) || (getConfig('cache_admin_menu') == "N")) {
- // Caching disabled (currently experiemental!)
- return false;
- }
-
- // Experiemental feature!
- trigger_error("<strong>Experimental feature:</strong> You have to delete the admin_*.cache files by yourself at this point.");
-}
-
-// Translates the "pool type" into human-readable
-function TRANSLATE_POOL_TYPE ($type) {
- // Default type is unknown
- $translated = sprintf(POOL_TYPE_UNKNOWN, $type);
-
- // Generate constant
- $constName = sprintf("POOL_TYPE_%s", $type);
-
- // Does it exist?
- if (defined($constName)) {
- // Then use it
- $translated = constant($constName);
- } // END - if
-
- // Return "translation"
- return $translated;
-}
-
-// "Getter" for remote IP number
-function GET_REMOTE_ADDR () {
- // Get remote ip from environment
- $remoteAddr = getenv('REMOTE_ADDR');
-
- // Is removeip installed?
- if (EXT_IS_ACTIVE("removeip")) {
- // Then anonymize it
- $remoteAddr = GET_ANONYMOUS_REMOTE_ADDR($remoteAddr);
- } // END - if
-
- // Return it
- return $remoteAddr;
-}
-// "Getter" for remote hostname
-function GET_REMOTE_HOST () {
- // Get remote ip from environment
- $remoteHost = getenv('REMOTE_HOST');
-
- // Is removeip installed?
- if (EXT_IS_ACTIVE("removeip")) {
- // Then anonymize it
- $remoteHost = GET_ANONYMOUS_REMOTE_HOST($remoteHost);
- } // END - if
-
- // Return it
- return $remoteHost;
-}
-// "Getter" for user agent
-function GET_USER_AGENT () {
- // Get remote ip from environment
- $userAgent = getenv('HTTP_USER_AGENT');
-
- // Is removeip installed?
- if (EXT_IS_ACTIVE("removeip")) {
- // Then anonymize it
- $userAgent = GET_ANONYMOUS_USER_AGENT($userAgent);
- } // END - if
-
- // Return it
- return $userAgent;
-}
-// "Getter" for referer
-function GET_REFERER () {
- // Get remote ip from environment
- $referer = getenv('HTTP_REFERER');
-
- // Is removeip installed?
- if (EXT_IS_ACTIVE("removeip")) {
- // Then anonymize it
- $referer = GET_ANONYMOUS_REFERER($referer);
- } // END - if
-
- // Return it
- return $referer;
-}
-
-// Adds a bonus mail to the queue
-// This is a high-level function!
-function ADD_NEW_BONUS_MAIL ($data, $mode="", $output=true) {
- // Use mode from data if not set and availble ;-)
- if ((empty($mode)) && (isset($data['mode']))) $mode = $data['mode'];
-
- // Generate receiver list
- $RECEIVER = GENERATE_RECEIVER_LIST($data['cat'], $data['receiver'], $mode);
-
- // Receivers added?
- if (!empty($RECEIVER)) {
- // Add bonus mail to queue
- ADD_BONUS_MAIL_TO_QUEUE(
- $data['subject'],
- $data['text'],
- $RECEIVER,
- $data['points'],
- $data['seconds'],
- $data['url'],
- $data['cat'],
- $mode,
- $data['receiver']
- );
-
- // Mail inserted into bonus pool
- if ($output) LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_BONUS_SEND);
- } elseif ($output) {
- // More entered than can be reached!
- LOAD_TEMPLATE("admin_settings_saved", false, ADMIN_MORE_SELECTED);
- } else {
- // Debug log
- DEBUG_LOG(__FUNCTION__, __LINE__, " cat={$data['cat']},receiver={$data['receiver']},data=".base64_encode(serialize($data))." More selected, than available!");
- }
-}
-// Determines referal id and sets it
-function DETERMINE_REFID () {
- global $CLICK, $_SERVER;
-
- // Check if refid is set
- if ((!empty($_GET['user'])) && ($CLICK == 1) && (basename($_SERVER['PHP_SELF']) == "click.php")) {
- // The variable user comes from the click-counter script click.php and we only accept this here
- $GLOBALS['refid'] = bigintval($_GET['user']);
- } elseif (!empty($_POST['refid'])) {
- // Get referal id from variable refid (so I hope this makes my script more compatible to other scripts)
- $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_POST['refid']));
- } elseif (!empty($_GET['refid'])) {
- // Get referal id from variable refid (so I hope this makes my script more compatible to other scripts)
- $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_GET['refid']));
- } elseif (!empty($_GET['ref'])) {
- // Set refid=ref (the referal link uses such variable)
- $GLOBALS['refid'] = SQL_ESCAPE(strip_tags($_GET['ref']));
- } elseif ((isSessionVariableSet('refid')) && (get_session('refid') != 0)) {
- // Set session refid als global
- $GLOBALS['refid'] = bigintval(get_session('refid'));
- } elseif ((GET_EXT_VERSION("sql_patches") != "") && (getConfig('def_refid') > 0)) {
- // Set default refid as refid in URL
- $GLOBALS['refid'] = bigintval(getConfig('def_refid'));
- } elseif ((GET_EXT_VERSION("user") >= "0.3.4") && (getConfig('select_user_zero_refid')) == "Y") {
- // Select a random user which has confirmed enougth mails
- $GLOBALS['refid'] = SELECT_RANDOM_REFID();
- } else {
- // No default ID when sql_patches is not installed or none set
- $GLOBALS['refid'] = 0;
- }
-
- // Set cookie when default refid > 0
- if (!isSessionVariableSet('refid') || (!empty($GLOBALS['refid'])) || ((get_session('refid') == "0") && (getConfig('def_refid') > 0))) {
- // Set cookie
- set_session('refid', $GLOBALS['refid']);
- } // END - if
-
- // Return determined refid
- return $GLOBALS['refid'];
-}
-
-// Destroys the admin session
-function DESTROY_ADMIN_SESSION ($destroy = true) {
- // Kill maybe existing session variables including array elements
- set_session('admin_login', "");
- set_session('admin_md5' , "");
- set_session('admin_last' , "");
- set_session('admin_to' , "");
-
- // Destroy session and return status
- if ($destroy) {
- return @session_destroy();
- } // END - if
-
- // All fine if we shall not really destroy the session
- return true;
-}
-