X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=ef6cbde5323b40bf5ff838a7513d39983f08896d;hb=7989ec603971c0dc8dc35d8be4e72f8098b83baa;hp=6f668fc188a1775352b19ec101e1b93074eb1597;hpb=595124165eb35633520ee0c8e7d5196ba515c00f;p=mailer.git
diff --git a/inc/functions.php b/inc/functions.php
index 6f668fc188..ef6cbde532 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -60,7 +60,7 @@ function IS_INC_WRITEABLE($inc) {
}
// Output HTML code directly or "render" it. You addionally switch the new-line character off
-function OUTPUT_HTML ($HTML, $NEW_LINE = true) {
+function OUTPUT_HTML ($HTML, $newLine = true) {
// Some global variables
global $OUTPUT, $footer, $CSS;
@@ -71,44 +71,44 @@ function OUTPUT_HTML ($HTML, $NEW_LINE = true) {
{
case "render":
// That's why you don't need any \n at the end of your HTML code... :-)
- if (_OB_CACHING == "on") {
+ if (constant('_OB_CACHING') == "on") {
// Output into PHP's internal buffer
OUTPUT_RAW($HTML);
// That's why you don't need any \n at the end of your HTML code... :-)
- if ($NEW_LINE) echo "\n";
+ if ($newLine) echo "\n";
} else {
// Render mode for old or lame servers...
$OUTPUT .= $HTML;
// That's why you don't need any \n at the end of your HTML code... :-)
- if ($NEW_LINE) $OUTPUT .= "\n";
+ if ($newLine) $OUTPUT .= "\n";
}
break;
case "direct":
// If we are switching from render to direct output rendered code
- if ((!empty($OUTPUT)) && (_OB_CACHING != "on")) { OUTPUT_RAW($OUTPUT); $OUTPUT = ""; }
+ if ((!empty($OUTPUT)) && (constant('_OB_CACHING') != "on")) { OUTPUT_RAW($OUTPUT); $OUTPUT = ""; }
// The same as above... ^
OUTPUT_RAW($HTML);
- if ($NEW_LINE) echo "\n";
+ if ($newLine) echo "\n";
break;
default:
// Huh, something goes wrong or maybe you have edited config.php ???
DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid renderer %s detected.", constant('OUTPUT_MODE')));
- mxchange_die("{!FATAL_ERROR!}: {!LANG_NO_RENDER_DIRECT!}");
+ mxchange_die("{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}");
break;
}
- } elseif ((_OB_CACHING == "on") && ($footer == 1)) {
+ } elseif ((constant('_OB_CACHING') == "on") && ($footer == 1)) {
// Headers already sent?
if (headers_sent()) {
// Log this error
DEBUG_LOG(__FUNCTION__, __LINE__, "Headers already sent! We need debug backtrace here.");
// Trigger an user error
- trigger_error("Headers are already sent!");
+ debug_report_bug("Headers are already sent!");
} // END - if
// Output cached HTML code
@@ -139,13 +139,13 @@ function OUTPUT_HTML ($HTML, $NEW_LINE = true) {
while (strpos($OUTPUT, '{!') > 0) {
// Prepare the content and eval() it...
$newContent = "";
- $eval = "\$newContent = \"".COMPILE_CODE(addslashes($OUTPUT))."\";";
+ $eval = "\$newContent = \"".COMPILE_CODE(SQL_ESCAPE($OUTPUT))."\";";
@eval($eval);
// Was that eval okay?
if (empty($newContent)) {
// Something went wrong!
- die("Evaluation error:
".htmlentities($eval)."
");
+ mxchange_die("Evaluation error:
".htmlentities($eval)."
");
} // END - if
$OUTPUT = $newContent;
} // END - while
@@ -160,7 +160,7 @@ function OUTPUT_HTML ($HTML, $NEW_LINE = true) {
// Compile and run finished rendered HTML code
while (strpos($OUTPUT, '{!') > 0) {
- $eval = "\$OUTPUT = \"".COMPILE_CODE(addslashes($OUTPUT))."\";";
+ $eval = "\$OUTPUT = \"".COMPILE_CODE(SQL_ESCAPE($OUTPUT))."\";";
eval($eval);
} // END - while
@@ -174,8 +174,8 @@ function OUTPUT_RAW ($HTML) {
// Output stripped HTML code to avoid broken JavaScript code, etc.
echo stripslashes(stripslashes($HTML));
- // Flush the output if only _OB_CACHING is not "on"
- if (_OB_CACHING != "on") {
+ // Flush the output if only constant('_OB_CACHING') is not "on"
+ if (constant('_OB_CACHING') != "on") {
// Flush it
flush();
} // END - if
@@ -185,15 +185,17 @@ function OUTPUT_RAW ($HTML) {
function addFatalMessage ($message, $extra="") {
global $FATAL;
- if (empty($extra)) {
- // Regular text message to add to $FATAL
- $FATAL[] = $message;
- } else {
+ if (is_array($extra)) {
+ // Multiple extras for a message with masks
+ $message = call_user_func_array('sprintf', $extra);
+ } elseif (!empty($extra)) {
// $message is text with a mask plus extras to insert into the text
$message = sprintf($message, $extra);
- $FATAL[] = $message;
}
+ // Add message to $FATAL
+ $FATAL[] = $message;
+
// Log fatal messages away
DEBUG_LOG(__FUNCTION__, __LINE__, " message={$message}");
}
@@ -249,7 +251,9 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
// Translate gender
$content['gender'] = TRANSLATE_GENDER($content['gender']);
} else {
- // DEPRECATED: Load data in direct variables
+ // @DEPRECATED
+ // @TODO Fine all templates which are using these direct variables and rewrite them.
+ // @TODO After this step is done, this else-block is history
list($gender, $surname, $family, $email) = SQL_FETCHROW($result);
// Translate gender
@@ -335,7 +339,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
$ret = "";
if ((strpos($tmpl_file, "\$") !== false) || (strpos($tmpl_file, '{--') !== false) || (strpos($tmpl_file, '--}') > 0)) {
// Okay, compile it!
- $tmpl_file = "\$ret=\"".COMPILE_CODE(addslashes($tmpl_file))."\";";
+ $tmpl_file = "\$ret=\"".COMPILE_CODE(SQL_ESCAPE($tmpl_file))."\";";
eval($tmpl_file);
} else {
// Simply return loaded code
@@ -381,7 +385,7 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = "N", $FROM = "") {
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):TO={$TO},SUBJECT={$SUBJECT} \n";
// Compile subject line (for POINTS constant etc.)
- $eval = "\$SUBJECT = html_entity_decode(\"".COMPILE_CODE(addslashes($SUBJECT))."\");";
+ $eval = "\$SUBJECT = decodeEntities(\"".COMPILE_CODE(SQL_ESCAPE($SUBJECT))."\");";
eval($eval);
// Set from header
@@ -434,11 +438,11 @@ function SEND_EMAIL($TO, $SUBJECT, $MSG, $HTML = "N", $FROM = "") {
}
// Compile "TO"
- $eval = "\$TO = \"".COMPILE_CODE(addslashes($TO))."\";";
+ $eval = "\$TO = \"".COMPILE_CODE(SQL_ESCAPE($TO))."\";";
eval($eval);
// Compile "MSG"
- $eval = "\$MSG = \"".COMPILE_CODE(addslashes($MSG))."\";";
+ $eval = "\$MSG = \"".COMPILE_CODE(SQL_ESCAPE($MSG))."\";";
eval($eval);
// Fix HTML parameter (default is no!)
@@ -502,7 +506,7 @@ function SEND_RAW_EMAIL ($to, $subject, $msg, $from) {
$mail->WordWrap = 70;
$mail->IsHTML(true);
} else {
- $mail->Body = html_entity_decode($msg);
+ $mail->Body = decodeEntities($msg);
}
$mail->AddAddress($to, "");
$mail->AddReplyTo(constant('WEBMASTER'), constant('MAIN_TITLE'));
@@ -511,7 +515,7 @@ function SEND_RAW_EMAIL ($to, $subject, $msg, $from) {
$mail->Send();
} else {
// Use legacy mail() command
- @mail($to, $subject, html_entity_decode($msg), $from);
+ @mail($to, $subject, decodeEntities($msg), $from);
}
}
//
@@ -524,9 +528,6 @@ function GEN_PASS ($LEN = 0) {
// 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,-,+,_,/");
- // Initialize randomizer
- mt_srand((double) microtime() * 1000000);
-
// Start creating password
$PASS = "";
for ($i = 0; $i < $LEN; $i++) {
@@ -583,10 +584,8 @@ function MAKE_DATETIME ($time, $mode="0")
// Translates the american decimal dot into a german comma
function TRANSLATE_COMMA ($dotted, $cut=true, $max=0) {
- global $_CONFIG;
-
// Default is 3 you can change this in admin area "Misc -> Misc Options"
- if (getConfig('max_comma') == null) $_CONFIG['max_comma'] = "3";
+ if (!isConfigEntrySet('max_comma')) setConfigEntry('max_comma', "3");
// Use from config is default
$maxComma = getConfig('max_comma');
@@ -627,35 +626,45 @@ function DEREFERER ($URL) {
// Don't de-refer our own links!
if (substr($URL, 0, strlen(URL)) != URL) {
// De-refer this link
- $URL = "modules.php?module=loader&url=".urlencode(base64_encode(gzcompress($URL)));
+ $URL = "modules.php?module=loader&url=".encodeString(compileUriCode($URL));
} // END - if
// Return link
return $URL;
}
-//
+// Translate Uni*-like gender to human-readable
function TRANSLATE_GENDER ($gender) {
- switch ($gender)
- {
- case "M": $ret = GENDER_M; break;
- case "F": $ret = GENDER_F; break;
- case "C": $ret = GENDER_C; break;
- default : $ret = $gender; break;
+ // Default
+ $ret = "!{$gender}!";
+
+ // Male/female or company?
+ switch ($gender) {
+ case "M": $ret = getMessage('GENDER_M'); break;
+ case "F": $ret = getMessage('GENDER_F'); break;
+ case "C": $ret = getMessage('GENDER_C'); break;
+ default:
+ // Log unknown gender
+ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown gender %s detected.", $gender));
+ break;
}
+
+ // Return translated gender
return $ret;
}
+
//
-function FRAMETESTER($URL) {
+function FRAMETESTER ($URL) {
// Prepare frametester URL
$frametesterUrl = sprintf("%s/modules.php?module=frametester&url=%s",
URL,
- urlencode(base64_encode(gzcompress(COMPILE_CODE($URL))))
+ encodeString(compileUriCode($URL))
);
return $frametesterUrl;
}
+
//
-function SELECTION_COUNT($array) {
+function SELECTION_COUNT ($array) {
$ret = 0;
if (is_array($array)) {
foreach ($array as $key => $sel) {
@@ -669,31 +678,27 @@ function IMG_CODE ($code, $type, $DATA, $uid) {
return "";
}
//
-function TRANSLATE_STATUS($status) {
+function TRANSLATE_STATUS ($status) {
switch ($status)
{
case "UNCONFIRMED":
- $ret = ACCOUNT_UNCONFIRMED;
- break;
-
case "CONFIRMED":
- $ret = ACCOUNT_CONFIRMED;
- break;
-
case "LOCKED":
- $ret = ACCOUNT_LOCKED;
+ $ret = getMessage(sprintf("ACCOUNT_%s", $status));
break;
case "":
case null:
- $ret = ACCOUNT_DELETED;
+ $ret = getMessage('ACCOUNT_DELETED');
break;
default:
DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected.", $status));
- $ret = UNKNOWN_STATUS_1.$status.UNKNOWN_STATUS_2;
+ $ret = sprintf(getMessage('UNKNOWN_STATUS"'), $status);
break;
}
+
+ // Return it
return $ret;
}
//
@@ -715,7 +720,7 @@ function GET_LANGUAGE() {
$ret = $cacheArray['language'];
} elseif (!empty($lang)) {
// Check if main language file does exist
- if (FILE_READABLE(PATH."inc/language/".$lang.".php")) {
+ if (FILE_READABLE(constant('PATH')."inc/language/".$lang.".php")) {
// Okay found, so let's update cookies
SET_LANGUAGE($lang);
}
@@ -773,7 +778,7 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
// Expiration in a nice output format
if (getConfig('auto_purge') == 0) {
// Will never expire!
- $EXPIRATION = MAIL_WILL_NEVER_EXPIRE;
+ $EXPIRATION = getMessage('MAIL_WILL_NEVER_EXPIRE');
} else {
// Create nice date string
$EXPIRATION = CREATE_FANCY_TIME(getConfig('auto_purge'));
@@ -855,25 +860,25 @@ function LOAD_EMAIL_TEMPLATE($template, $content=array(), $UID="0") {
if (FILE_READABLE($file)) {
// The local file does exists so we load it. :)
$tmpl_file = READ_FILE($file);
- $tmpl_file = addslashes($tmpl_file);
+ $tmpl_file = SQL_ESCAPE($tmpl_file);
// Run code
- $tmpl_file = "\$newContent=html_entity_decode(\"".COMPILE_CODE($tmpl_file)."\");";
+ $tmpl_file = "\$newContent = decodeEntities(\"".COMPILE_CODE($tmpl_file)."\");";
@eval($tmpl_file);
} elseif (!empty($template)) {
// Template file not found!
- $newContent = TEMPLATE_404.": ".$template."
-".TEMPLATE_CONTENT."
+ $newContent = "{--TEMPLATE_404--}: ".$template."
+{--TEMPLATE_CONTENT--}
".print_r($content, true)."
-".TEMPLATE_DATA."
+{--TEMPLATE_DATA--}
".print_r($DATA, true)."
";
// Debug mode not active? Then remove the HTML tags
- if (!DEBUG_MODE) $newContent = strip_tags($newContent);
+ if (!isBooleanConstantAndTrue('DEBUG_MODE')) $newContent = strip_tags($newContent);
} else {
// No template name supplied!
- $newContent = NO_TEMPLATE_SUPPLIED;
+ $newContent = getMessage('NO_TEMPLATE_SUPPLIED');
}
// Is there some content?
@@ -906,7 +911,7 @@ function LOAD_URL($URL, $addUrlData=true) {
global $CSS, $footer;
// Compile out URI codes
- $URL = COMPILE_CODE($URL);
+ $URL = compileUriCode($URL);
// Check if http(s):// is there
if ((substr($URL, 0, 7) != "http://") && (substr($URL, 0, 8) != "https://")) {
@@ -915,11 +920,7 @@ function LOAD_URL($URL, $addUrlData=true) {
}
// Get output buffer
- /*
- print "
";
- debug_print_backtrace();
- die("
");
- */
+ //* DEBUG: */ debug_report_bug();
$OUTPUT = ob_get_contents();
// Clear it only if there is content
@@ -939,11 +940,7 @@ function LOAD_URL($URL, $addUrlData=true) {
OUTPUT_HTML("".$URL."");
} elseif (!headers_sent()) {
// Load URL when headers are not sent
- /*
- print("
\n";
@@ -1574,9 +1578,10 @@ function CREATE_TIMESTAMP_FROM_SELECTIONS ($prefix, $POST) {
// Return calculated value
return $ret;
}
+
// Sends out mail to all administrators
// IMPORTANT: Please use SEND_ADMIN_NOTIFCATION() for now!
-function SEND_ADMIN_EMAILS_PRO($subj, $template, $content, $UID) {
+function SEND_ADMIN_EMAILS_PRO ($subj, $template, $content, $UID) {
// Trim template name
$template = trim($template);
@@ -1600,17 +1605,28 @@ function SEND_ADMIN_EMAILS_PRO($subj, $template, $content, $UID) {
$aids = array();
while (list($aid) = SQL_FETCHROW($result)) {
$aids[] = $aid;
- }
+ } // END - while
// Free memory
SQL_FREERESULT($result);
+ // Init result
+ $result = false;
+
// "implode" IDs and query string
$aid = implode(",", $aids);
if ($aid == "-1") {
- // Add line to userlog
- USERLOG_ADD_LINE($subj, $msg, $UID);
- return;
+ if (EXT_IS_ACTIVE("events")) {
+ // Add line to user events
+ EVENTS_ADD_LINE($subj, $msg, $UID);
+ } else {
+ // Log error for debug
+ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Extension 'events' missing: tpl=%s,subj=%s,UID=%s",
+ $template,
+ $subj,
+ $UID
+ ));
+ }
} elseif ($aid == "0") {
// Select all email adresses
$result = SQL_QUERY("SELECT email FROM `{!_MYSQL_PREFIX!}_admins` ORDER BY `id`", __FILE__, __LINE__);
@@ -1623,7 +1639,7 @@ function SEND_ADMIN_EMAILS_PRO($subj, $template, $content, $UID) {
// Load email addresses and send away
while (list($email) = SQL_FETCHROW($result)) {
SEND_EMAIL($email, $subj, $msg);
- }
+ } // END - while
// Free memory
SQL_FREERESULT($result);
@@ -1636,7 +1652,7 @@ function CREATE_FANCY_TIME ($stamp) {
foreach($data as $k => $v) {
if ($v > 0) {
// Value is greater than 0 "eval" data to return string
- $eval = "\$ret .= \", \".\$v.\" \"._".strtoupper($k).";";
+ $eval = "\$ret .= \", \".\$v.\" {--_".strtoupper($k)."--}\";";
eval($eval);
break;
} // END - if
@@ -1648,7 +1664,7 @@ function CREATE_FANCY_TIME ($stamp) {
$ret = substr($ret, 2);
} else {
// Zero seconds
- $ret = "0 "._SECONDS;
+ $ret = "0 {--_SECONDS--}";
}
// Return fancy time string
@@ -1714,7 +1730,7 @@ function ADD_EMAIL_NAV($PAGES, $offset, $show_form, $colspan, $return=false) {
// Extract host from script name
function EXTRACT_HOST (&$script) {
// Use default SERVER_URL by default... ;) So?
- $url = SERVER_URL;
+ $url = constant('SERVER_URL');
// Is this URL valid?
if (substr($script, 0, 7) == "http://") {
@@ -1757,8 +1773,8 @@ function GET_URL ($script) {
// Generate GET request header
$request = "GET /" . trim($script) . " HTTP/1.1\r\n";
$request .= "Host: " . $host . "\r\n";
- $request .= "Referer: " . URL . "/admin.php\r\n";
- $request .= "User-Agent: " . TITLE . "/" . FULL_VERSION . "\r\n";
+ $request .= "Referer: " . constant('URL') . "/admin.php\r\n";
+ $request .= "User-Agent: " . constant('TITLE') . "/" . constant('FULL_VERSION') . "\r\n";
$request .= "Content-Type: text/plain\r\n";
$request .= "Cache-Control: no-cache\r\n";
$request .= "Connection: Close\r\n\r\n";
@@ -1791,8 +1807,8 @@ function POST_URL ($script, $postData) {
// Generate POST request header
$request = "POST /" . trim($script) . " HTTP/1.1\r\n";
$request .= "Host: " . $host . "\r\n";
- $request .= "Referer: " . URL . "/admin.php\r\n";
- $request .= "User-Agent: " . TITLE . "/" . FULL_VERSION . "\r\n";
+ $request .= "Referer: " . constant('URL') . "/admin.php\r\n";
+ $request .= "User-Agent: " . constant('TITLE') . "/" . constant('FULL_VERSION') . "\r\n";
$request .= "Content-type: application/x-www-form-urlencoded\r\n";
$request .= "Content-length: " . strlen($data) . "\r\n";
$request .= "Cache-Control: no-cache\r\n";
@@ -1931,6 +1947,7 @@ function VALIDATE_EMAIL($email) {
// Return check result
return eregi($regex, $email);
}
+
// Function taken from user comments on www.php.net / function eregi()
function VALIDATE_URL ($URL, $compile=true) {
// Trim URL a little
@@ -1938,7 +1955,7 @@ function VALIDATE_URL ($URL, $compile=true) {
//* DEBUG: */ echo $URL." ";
// Compile some chars out...
- if ($compile) $URL = COMPILE_CODE($URL, false, false, false);
+ if ($compile) $URL = compileUriCode($URL, false, false, false);
//* DEBUG: */ echo $URL." ";
// Check for the extension filter
@@ -1949,8 +1966,9 @@ function VALIDATE_URL ($URL, $compile=true) {
// If not installed, perform a simple test. Just make it sure there is always a http:// or
// https:// in front of the URLs
- return (((substr($URL, 0, 7) == "http://") || (substr($URL, 0, 8) == "https://")) && (strlen($URL) >= 12));
+ return isUrlValid($URL);
}
+
//
function MEMBER_ACTION_LINKS ($uid, $status = "") {
// Define all main targets
@@ -1960,7 +1978,7 @@ function MEMBER_ACTION_LINKS ($uid, $status = "") {
$eval = "\$OUT = \"[ ";
foreach ($TARGETS as $tar) {
- $eval .= "\n";
if (($tar == "lock_user") && ($status == "LOCKED")) {
// Locked accounts shall be unlocked
@@ -1969,7 +1987,7 @@ function MEMBER_ACTION_LINKS ($uid, $status = "") {
// All other status is fine
$eval .= strtoupper($tar);
}
- $eval .= "_TITLE!}\\\">{!ADMIN_";
+ $eval .= "_TITLE--}\\\">{--ADMIN_";
if (($tar == "lock_user") && ($status == "LOCKED")) {
// Locked accounts shall be unlocked
$eval .= "UNLOCK_USER";
@@ -1977,7 +1995,7 @@ function MEMBER_ACTION_LINKS ($uid, $status = "") {
// All other status is fine
$eval .= strtoupper($tar);
}
- $eval .= "!} | ";
+ $eval .= "--} | ";
}
// Finish navigation link
@@ -1987,11 +2005,14 @@ function MEMBER_ACTION_LINKS ($uid, $status = "") {
// Return string
return $OUT;
}
+
// Function for backward-compatiblity
-function ADD_CATEGORY_table ($MODE, $return=false) {
+// @TODO Can this function be deprecated?
+function ADD_CATEGORY_TABLE ($MODE, $return=false) {
// Load it from the register extension
- return REGISTER_ADD_CATEGORY_table ($MODE, $return);
+ return REGISTER_ADD_CATEGORY_TABLE ($MODE, $return);
}
+
// Generate an email link
function CREATE_EMAIL_LINK ($email, $table = "admins") {
// Default email link (INSECURE! Spammer can read this by harvester programs)
@@ -2026,29 +2047,27 @@ function generateHash ($plainText, $salt = "") {
} // END - if
// Do we miss an arry element here?
- if (getConfig('file_hash') == null) {
+ if (!isConfigEntrySet('file_hash')) {
// Stop here
- print("Missing file_hash in ".__FUNCTION__.". Backtrace:
");
- debug_print_backtrace();
- die("
");
+ debug_report_bug("Missing file_hash in ".__FUNCTION__.".");
} // END - if
// When the salt is empty build a new one, else use the first x configured characters as the salt
if (empty($salt)) {
// Build server string
- $server = $_SERVER['PHP_SELF'].":".GET_USER_AGENT().":".getenv('SERVER_SOFTWARE').":".GET_REMOTE_ADDR().":".":".filemtime(PATH."inc/databases.php");
+ $server = $_SERVER['PHP_SELF'].":".GET_USER_AGENT().":".getenv('SERVER_SOFTWARE').":".GET_REMOTE_ADDR().":".":".filemtime(constant('PATH')."inc/databases.php");
// Build key string
- $keys = SITE_KEY.":".DATE_KEY.":".getConfig('secret_key').":".getConfig('file_hash').":".date("d-m-Y (l-F-T)", bigintval(getConfig('patch_ctime'))).":".getConfig('master_salt');
+ $keys = constant('SITE_KEY').":".constant('DATE_KEY').":".getConfig('secret_key').":".getConfig('file_hash').":".date("d-m-Y (l-F-T)", bigintval(getConfig('patch_ctime'))).":".getConfig('master_salt');
// Additional data
$data = $plainText.":".uniqid(mt_rand(), true).":".time();
// Calculate number for generating the code
- $a = time() + _ADD - 1;
+ $a = time() + constant('_ADD') - 1;
// Generate SHA1 sum from modula of number and the prime number
- $sha1 = sha1(($a % _PRIME).$server.":".$keys.":".$data.":".date("d-m-Y (l-F-T)", time()).":".$a);
+ $sha1 = sha1(($a % constant('_PRIME')).$server.":".$keys.":".$data.":".date("d-m-Y (l-F-T)", time()).":".$a);
//* DEBUG: */ echo "SHA1=".$sha1." (".strlen($sha1).") ";
$sha1 = scrambleString($sha1);
//* DEBUG: */ echo "Scrambled=".$sha1." (".strlen($sha1).") ";
@@ -2122,9 +2141,8 @@ function descrambleString($str) {
return $orig;
}
//
-function genScrambleString($len) {
- // Prepare randomizer and array for the numbers
- mt_srand((double) microtime() * 1000000);
+function genScrambleString ($len) {
+ // Prepare array for the numbers
$scrambleNumbers = array();
// First we need to setup randomized numbers from 0 to 31
@@ -2145,6 +2163,7 @@ function genScrambleString($len) {
$scrambleString = implode(":", $scrambleNumbers);
return $scrambleString;
}
+
// Append data like session ID or referal ID to the given URL which would
// normally be stored in cookies
function ADD_URL_DATA ($URL) {
@@ -2153,7 +2172,7 @@ function ADD_URL_DATA ($URL) {
// Determine URL binder
$BIND = "?";
- if (strpos($URL, "?") !== false) $BIND = "&";
+ if (strpos($URL, "?") !== false) $BIND = "&";
if ((!defined('__COOKIES')) || ((!__COOKIES))) {
// Cookies are not accepted
@@ -2164,25 +2183,14 @@ function ADD_URL_DATA ($URL) {
// Not found! So let's set default here
$ADD .= $BIND."refid=".getConfig('def_refid');
}
-
- // Is there already added data? Then change the binder
- if (!empty($ADD)) $BIND = "&";
-
- // Add session ID
- if ((!empty($_GET['PHPSESSID'])) && (strpos($URL, "PHPSESSID=") == 0)) {
- // Add session from URL
- $ADD .= $BIND."PHPSESSID=".SQL_ESCAPE(strip_tags($_GET['PHPSESSID']));
- } else {
- // Add current session
- $ADD .= $BIND."PHPSESSID=".session_id();
- }
} // END - if
// Add all together and return it
- return $URL.$ADD;
+ return $URL . $ADD;
}
+
// Generate an PGP-like encrypted hash of given hash for e.g. cookies
-function generatePassString($passHash) {
+function generatePassString ($passHash) {
// Return vanilla password hash
$ret = $passHash;
@@ -2195,9 +2203,9 @@ function generatePassString($passHash) {
$part2 = hexdec(substr(getConfig('secret_key'), $start, 4));
$mod = dechex($idx);
if ($part1 > $part2) {
- $mod = dechex(sqrt(($part1 - $part2) * _PRIME / pi()));
+ $mod = dechex(sqrt(($part1 - $part2) * constant('_PRIME') / pi()));
} elseif ($part2 > $part1) {
- $mod = dechex(sqrt(($part2 - $part1) * _PRIME / pi()));
+ $mod = dechex(sqrt(($part2 - $part1) * constant('_PRIME') / pi()));
}
$mod = substr(round($mod), 0, 4);
$mod = str_repeat('0', 4-strlen($mod)).$mod;
@@ -2243,7 +2251,7 @@ function mxchange_die ($msg) {
LOAD_TEMPLATE("admin_settings_saved", false, $msg);
// Load footer
- LOAD_INC("inc/footer.php");
+ LOAD_INC_ONCE("inc/footer.php");
// Exit explicitly
exit;
@@ -2406,17 +2414,15 @@ function merge_array ($array1, $array2) {
}
// Both are not arrays
- print(__FUNCTION__.":
");
- debug_print_backtrace();
- die("
");
+ debug_report_bug(__FUNCTION__.": No arrays provided!");
}
// Debug message logger
function DEBUG_LOG ($file, $line, $message, $force=true) {
// Is debug mode enabled?
- if ((isBooleanConstantAndTrue('DEBUG_MODE')) || ($force)) {
+ if ((isBooleanConstantAndTrue('DEBUG_MODE')) || ($force === true)) {
// Log this message away
- $fp = fopen(PATH."inc/cache/debug.log", 'a') or mxchange_die("Cannot write logfile debug.log!");
+ $fp = fopen(constant('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
@@ -2473,7 +2479,7 @@ function RESET_ADD_INCLUDES () {
} // END - if
// Get more daily reset scripts
- $INC_POOL = GET_DIR_AS_ARRAY(PATH."inc/reset/", "reset_");
+ $INC_POOL = GET_DIR_AS_ARRAY(constant('PATH')."inc/reset/", "reset_");
// Update database
if (!defined('DEBUG_RESET')) UPDATE_CONFIG("last_update", time());
@@ -2484,7 +2490,7 @@ function RESET_ADD_INCLUDES () {
// 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_"));
+ $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY(constant('PATH')."inc/weekly/", "weekly_"));
// Update config
if (!defined('DEBUG_WEEKLY')) UPDATE_CONFIG("last_week", $currWeek);
@@ -2496,7 +2502,7 @@ function RESET_ADD_INCLUDES () {
// 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_"));
+ $INC_POOL = merge_array($INC_POOL, GET_DIR_AS_ARRAY(constant('PATH')."inc/monthly/", "monthly_"));
// Update config
if (!defined('DEBUG_MONTHLY')) UPDATE_CONFIG("last_month", $currMonth);
@@ -2644,7 +2650,7 @@ function REBUILD_CACHE ($cache, $inc="") {
$INC = sprintf("inc/loader/load_cache-%s.php", $inc);
// Is the include there?
- if (FILE_READABLE($INC)) {
+ if (INCLUDE_READABLE($INC)) {
// And rebuild it from scratch
//* DEBUG: */ print __FUNCTION__."(".__LINE__."): inc={$inc} - LOADED! \n";
LOAD_INC($INC);
@@ -2668,19 +2674,19 @@ function CACHE_PURGE_ADMIN_MENU ($id=0, $action="", $what="", $str="") {
// No cache instance!
DEBUG_LOG(__FUNCTION__, __LINE__, " No cache instance found.");
return false;
- } elseif ((getConfig('cache_admin_menu') == null) || (getConfig('cache_admin_menu') == "N")) {
+ } elseif ((!isConfigEntrySet('cache_admin_menu')) || (getConfig('cache_admin_menu') != "Y")) {
// Caching disabled (currently experiemental!)
return false;
}
// Experiemental feature!
- trigger_error("Experimental feature: You have to delete the admin_*.cache files by yourself at this point.");
+ debug_report_bug("Experimental feature: 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);
+ // Default type is unknown
+ $translated = sprintf(getMessage('POOL_TYPE_UNKNOWN'), $type);
// Generate constant
$constName = sprintf("POOL_TYPE_%s", $type);
@@ -2688,7 +2694,7 @@ function TRANSLATE_POOL_TYPE ($type) {
// Does it exist?
if (defined($constName)) {
// Then use it
- $translated = constant($constName);
+ $translated = getMessage($constName);
} // END - if
// Return "translation"
@@ -2786,6 +2792,7 @@ function ADD_NEW_BONUS_MAIL ($data, $mode="", $output=true) {
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;
@@ -2828,7 +2835,7 @@ function DETERMINE_REFID () {
}
// Destroys the admin session
-function DESTROY_ADMIN_SESSION ($destroy = true) {
+function destroyAdminSession ($destroy = true) {
// Kill maybe existing session variables including array elements
set_session('admin_login', "");
set_session('admin_md5' , "");
@@ -2837,7 +2844,7 @@ function DESTROY_ADMIN_SESSION ($destroy = true) {
// Destroy session and return status
if ($destroy) {
- return @session_destroy();
+ return session_destroy();
} // END - if
// All fine if we shall not really destroy the session
@@ -2850,6 +2857,12 @@ function IF_APACHE_MODULE_LOADED ($apacheModule) {
return (((function_exists('apache_get_modules')) && (in_array($apacheModule, apache_get_modules()))) || (!function_exists('apache_get_modules')));
}
+// Merges $_CONFIG with data in given array
+function mergeConfig ($newConfig) {
+ global $_CONFIG;
+ $_CONFIG = merge_array($_CONFIG, $newConfig);
+}
+
// Getter for $_CONFIG entries
function getConfig ($entry) {
global $_CONFIG;
@@ -2858,7 +2871,7 @@ function getConfig ($entry) {
$value = null;
// Is the entry there?
- if (isset($_CONFIG[$entry])) {
+ if (isConfigEntrySet($entry)) {
// Then use it
$value = $_CONFIG[$entry];
} // END - if
@@ -2867,8 +2880,37 @@ function getConfig ($entry) {
return $value;
}
-// @TODO Rewrite all language constants to this function.
+// Setter for $_CONFIG entries
+function setConfigEntry ($entry, $value) {
+ global $_CONFIG;
+
+ // Secure the entry name
+ $entry = SQL_ESCAPE($entry);
+
+ // And set it
+ $_CONFIG[$entry] = $value;
+}
+
+// Checks wether the given config entry is set
+function isConfigEntrySet ($entry) {
+ global $_CONFIG;
+ return (isset($_CONFIG[$entry]));
+}
+
+// Increment or init with given value or 1 as default the given config entry
+function incrementConfigEntry ($configEntry, $value=1) {
+ global $_CONFIG;
+
+ // Increment it if set or init it with 1
+ if (getConfig($configEntry) > 0) {
+ $_CONFIG[$configEntry] += $value;
+ } else {
+ $_CONFIG[$configEntry] = $value;
+ }
+}
+
// "Getter" for language strings
+// @TODO Rewrite all language constants to this function.
function getMessage ($messageId) {
// Default is not found!
$return = "!".$messageId."!";
@@ -2880,7 +2922,7 @@ function getMessage ($messageId) {
} elseif (isset($GLOBALS['msg'][strtoupper($messageId)])) {
// @DEPRECATED Language array element found in BIG_LETTERS
$return = $GLOBALS['msg'][$messageId];
- } elseif (defined(strtoupper($messageId))) {
+ } elseif (defined($messageId)) {
// @DEPRECATED Deprecated constant found
$return = constant($messageId);
} else {
@@ -2984,18 +3026,6 @@ function THEME_GET_ID ($name) {
return $id;
}
-// Increment or init with given value or 1 as default the given config entry
-function incrementConfigEntry ($configEntry, $value=1) {
- global $_CONFIG;
-
- // Increment it if set or init it with 1
- if (getConfig($configEntry) > 0) {
- $_CONFIG[$configEntry] += $value;
- } else {
- $_CONFIG[$configEntry] = $value;
- }
-}
-
// Read a given file
function READ_FILE ($FQFN, $sqlPrepare = false) {
// Load the file
@@ -3038,7 +3068,7 @@ function WRITE_FILE ($FQFN, $content) {
// Generates an error code from given account status
function GEN_ERROR_CODE_FROM_ACCOUNT_STATUS ($status) {
// Default error code if unknown account status
- $ERROR = CODE_UNKNOWN_STATUS;
+ $ERROR = constant('CODE_UNKNOWN_STATUS');
// Generate constant name
$constantName = sprintf("CODE_ID_%s", $status);
@@ -3061,7 +3091,7 @@ function clearOutputBuffer () {
// Trigger an error on failure
if (!ob_end_clean()) {
// Failed!
- trigger_error(__FUNCTION__.": Failed to clean output buffer.");
+ debug_report_bug(__FUNCTION__.": Failed to clean output buffer.");
} // END - if
}
@@ -3091,8 +3121,9 @@ function getActualVersion ($type = 0) {
}
}
- if ($new) {
- // no Revision-File or has no valid Data so read the Revision from the Server.
+ // Has it been updated?
+ if ($new === true) {
+ // No Revision-File or has no valid Data so read the Revision from the Server.
$version = GET_URL("check-updates3.php");
// Prepare content
@@ -3149,6 +3180,261 @@ function LOAD_INC_ONCE ($INC) {
} // END - if
}
+// Back-ported from the new ship-simu engine. :-)
+function debug_get_printable_backtrace () {
+ // Init variable
+ $backtrace = "\n";
+
+ // Get and prepare backtrace for output
+ $backtraceArray = debug_backtrace();
+ foreach ($backtraceArray as $key => $trace) {
+ if (!isset($trace['file'])) $trace['file'] = __FILE__;
+ if (!isset($trace['line'])) $trace['line'] = __LINE__;
+ if (!isset($trace['args'])) $trace['args'] = array();
+ $backtrace .= "
\n";
+ } // END - foreach
+
+ // Close it
+ $backtrace .= "\n";
+
+ // Return the backtrace
+ return $backtrace;
+}
+
+// Output a debug backtrace to the user
+function debug_report_bug ($message = "") {
+ // Init message
+ $debug = "";
+ // Is the optional message set?
+ if (!empty($message)) {
+ // Use and log it
+ $debug = sprintf("Note: %s \n",
+ $message
+ );
+
+ // @TODO Add a little more infos here
+ DEBUG_LOG(__FUNCTION__, __LINE__, $message);
+ } // END - if
+
+ // Add output
+ $debug .= ("Please report this error at bugs.mxchange.org: