X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=inc%2Ffunctions.php;h=5f9e1229ade302b33056d1ada5faeb8d7d17c4b0;hb=7dbf553750858b5a422c6ef736dfd2bc2e97c74f;hp=910c71ffa899f2200f77b260f4ae9f5cf6aec39a;hpb=08f39b5f6bbb6835cf35530fb87b716afae2fc7a;p=mailer.git
diff --git a/inc/functions.php b/inc/functions.php
index 910c71ffa8..5f9e1229ad 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -114,12 +114,15 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
sendHeader('Connection: Close');
// Extension 'rewrite' installed?
- if ((EXT_IS_ACTIVE('rewrite')) && ($GLOBALS['output_mode'] != '1') && ($GLOBALS['output_mode'] != '-1')) {
+ if ((EXT_IS_ACTIVE('rewrite')) && (getOutputMode() != '1') && (getOutputMode() != '-1')) {
$OUTPUT = rewriteLinksInCode($OUTPUT);
} // END - if
// Compile and run finished rendered HTML code
while (strpos($OUTPUT, '{!') > 0) {
+ // Replace _MYSQL_PREFIX
+ $OUTPUT = str_replace("{!_MYSQL_PREFIX!}", getConfig('_MYSQL_PREFIX'), $OUTPUT);
+
// Prepare the content and eval() it...
$newContent = '';
$eval = "\$newContent = \"".COMPILE_CODE(smartAddSlashes($OUTPUT))."\";";
@@ -128,7 +131,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
// Was that eval okay?
if (empty($newContent)) {
// Something went wrong!
- app_die(__FUNCTION__, __LINE__, "Evaluation error:
".htmlentities($eval)."
");
+ app_die(__FUNCTION__, __LINE__, 'Evaluation error:' . htmlentities($eval) . '
');
} // END - if
$OUTPUT = $newContent;
} // END - while
@@ -137,7 +140,7 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
outputRawCode($OUTPUT);
} elseif ((getConfig('OUTPUT_MODE') == 'render') && (!empty($OUTPUT))) {
// Rewrite links when rewrite extension is active
- if ((EXT_IS_ACTIVE('rewrite')) && ($GLOBALS['output_mode'] != '1') && ($GLOBALS['output_mode'] != '-1')) {
+ if ((EXT_IS_ACTIVE('rewrite')) && (getOutputMode() != '1') && (getOutputMode() != '-1')) {
$OUTPUT = rewriteLinksInCode($OUTPUT);
} // END - if
@@ -208,6 +211,9 @@ function getTotalFatalErrors () {
// Load a template file and return it's content (only it's name; do not use ' or ")
function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
+ // @TODO Remove this sanity-check if all is fine
+ if (!is_bool($return)) debug_report_bug('return is not bool (' . gettype($return) . ')');
+
// Add more variables which you want to use in your template files
global $DATA, $username;
@@ -230,10 +236,10 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
if (empty($GLOBALS['refid'])) $GLOBALS['refid'] = 0;
// @DEPRECATED Try to rewrite the if() condition
- if ($template == "member_support_form") {
+ if ($template == 'member_support_form') {
// Support request of a member
- $result = SQL_QUERY_ESC("SELECT userid, gender, surname, family, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
- array(getUserId()), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT `userid`, `gender`, `surname`, `family`, `email` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+ array(getUserId()), __FUNCTION__, __LINE__);
// Is content an array?
if (is_array($content)) {
@@ -244,13 +250,13 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
$content['gender'] = translateGender($content['gender']);
} else {
// @DEPRECATED
- // @TODO Fine all templates which are using these direct variables and rewrite them.
+ // @TODO Find 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
$gender = translateGender($gender);
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("DEPRECATION-WARNING: content is not array (%s).", gettype($content)));
+ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("DEPRECATION-WARNING: content is not array [%s], template=%s.", gettype($content), $template));
}
// Free result
@@ -265,45 +271,48 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
$mode = '';
// Check for admin/guest/member templates
- if (strpos($template, "admin_") > -1) {
+ if (strpos($template, 'admin_') > -1) {
// Admin template found
- $mode = "admin/";
- } elseif (strpos($template, "guest_") > -1) {
+ $mode = 'admin/';
+ } elseif (strpos($template, 'guest_') > -1) {
// Guest template found
- $mode = "guest/";
- } elseif (strpos($template, "member_") > -1) {
+ $mode = 'guest/';
+ } elseif (strpos($template, 'member_') > -1) {
// Member template found
- $mode = "member/";
- } elseif (strpos($template, "install_") > -1) {
+ $mode = 'member/';
+ } elseif (strpos($template, 'install_') > -1) {
// Installation template found
- $mode = "install/";
- } elseif (strpos($template, "ext_") > -1) {
+ $mode = 'install/';
+ } elseif (strpos($template, 'ext_') > -1) {
// Extension template found
- $mode = "ext/";
- } elseif (strpos($template, "la_") > -1) {
- // "Logical-area" template found
- $mode = "la/";
+ $mode = 'ext/';
+ } elseif (strpos($template, 'la_') > -1) {
+ // 'Logical-area' template found
+ $mode = 'la/';
+ } elseif (strpos($template, 'js_') > -1) {
+ // JavaScript template found
+ $mode = 'js/';
} else {
// Test for extension
- $test = substr($template, 0, strpos($template, "_"));
+ $test = substr($template, 0, strpos($template, '_'));
if (EXT_IS_ACTIVE($test)) {
// Set extra path to extension's name
- $mode = $test.'/';
- }
+ $mode = $test . '/';
+ } // END - if
}
////////////////////////
// Generate file name //
////////////////////////
- $FQFN = $basePath.$mode.$template.".tpl";
+ $FQFN = $basePath . $mode . $template . '.tpl';
- if ((!empty($GLOBALS['what'])) && ((strpos($template, "_header") > 0) || (strpos($template, "_footer") > 0)) && (($mode == "guest/") || ($mode == "member/") || ($mode == "admin/"))) {
+ if ((isWhatSet()) && ((strpos($template, '_header') > 0) || (strpos($template, '_footer') > 0)) && (($mode == 'guest/') || ($mode == 'member/') || ($mode == 'admin/'))) {
// Select what depended header/footer template file for admin/guest/member area
$file2 = sprintf("%s%s%s_%s.tpl",
- $basePath,
- $mode,
- $template,
- SQL_ESCAPE($GLOBALS['what'])
+ $basePath,
+ $mode,
+ $template,
+ getWhat()
);
// Probe for it...
@@ -311,12 +320,12 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
// Remove variable from memory
unset($file2);
- }
+ } // END - if
// Does the special template exists?
if (!isFileReadable($FQFN)) {
// Reset to default template
- $FQFN = $basePath.$template.".tpl";
+ $FQFN = $basePath . $template . '.tpl';
} // END - if
// Now does the final template exists?
@@ -338,8 +347,11 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
$ret = $tmpl_file;
}
- // Add surrounding HTML comments to help finding bugs faster
- $ret = "\n".$ret."\n";
+ // Normal HTML output?
+ if ($GLOBALS['output_mode'] == 0) {
+ // Add surrounding HTML comments to help finding bugs faster
+ $ret = "\n" . $ret . "\n";
+ } // END - if
} elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) {
// Only admins shall see this warning or when installation mode is active
$ret = "
{--TEMPLATE_404--}
@@ -368,12 +380,12 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
}
} elseif (isDebugModeEnabled()) {
// Warning, empty output!
- return "E:".$template."
\n";
+ return "E:" . $template."
\n";
}
}
// Send mail out to an email address
-function sendEmail($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '') {
+function sendEmail ($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '') {
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):TO={$toEmail},SUBJECT={$subject}
\n";
// Compile subject line (for POINTS constant etc.)
@@ -381,14 +393,16 @@ function sendEmail($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '')
eval($eval);
// Set from header
- if ((!eregi("@", $toEmail)) && ($toEmail > 0)) {
+ if ((!eregi('@', $toEmail)) && ($toEmail > 0)) {
// Value detected, is the message extension installed?
- if (EXT_IS_ACTIVE("msg")) {
+ // @TODO Extension 'msg' does not exist
+ if (EXT_IS_ACTIVE('msg')) {
ADD_MESSAGE_TO_BOX($toEmail, $subject, $message, $HTML);
return;
} else {
// Load email address
- $result_email = SQL_QUERY_ESC("SELECT email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1", array(bigintval($toEmail)), __FUNCTION__, __LINE__);
+ $result_email = SQL_QUERY_ESC("SELECT `email` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+ array(bigintval($toEmail)), __FUNCTION__, __LINE__);
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):numRows=".SQL_NUMROWS($result_email)."
\n";
// Does the user exist?
@@ -403,7 +417,7 @@ function sendEmail($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '')
// Free result
SQL_FREERESULT($result_email);
}
- } elseif ("$toEmail" == '0') {
+ } elseif ($toEmail == '0') {
// Is the webmaster!
$toEmail = constant('WEBMASTER');
}
@@ -414,18 +428,18 @@ function sendEmail($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '')
// Not in PHPMailer-Mode
if (empty($mailHeader)) {
// Load email header template
- $mailHeader = LOAD_EMAIL_TEMPLATE("header");
+ $mailHeader = LOAD_EMAIL_TEMPLATE('header');
} else {
// Append header
- $mailHeader .= LOAD_EMAIL_TEMPLATE("header");
+ $mailHeader .= LOAD_EMAIL_TEMPLATE('header');
}
} elseif (isDebugModeEnabled()) {
if (empty($mailHeader)) {
// Load email header template
- $mailHeader = LOAD_EMAIL_TEMPLATE("header");
+ $mailHeader = LOAD_EMAIL_TEMPLATE('header');
} else {
// Append header
- $mailHeader .= LOAD_EMAIL_TEMPLATE("header");
+ $mailHeader .= LOAD_EMAIL_TEMPLATE('header');
}
}
@@ -441,11 +455,11 @@ function sendEmail($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '')
if (empty($HTML)) $HTML = 'N';
if (isDebugModeEnabled()) {
// In debug mode we want to display the mail instead of sending it away so we can debug this part
- print("
+ OUTPUT_HTML("
".htmlentities(trim($mailHeader))."
-To : ".$toEmail."
-Subject : ".$subject."
-Message : ".$message."
+To : " . $toEmail."
+Subject : " . $subject."
+Message : " . $message."
\n");
} elseif (($HTML == 'Y') && (EXT_IS_ACTIVE('html_mail'))) {
// Send mail as HTML away
@@ -467,7 +481,7 @@ function checkPhpMailerUsage() {
}
// Send out a raw email with PHPMailer class or legacy mail() command
-function sendRawEmail ($toEmail, $subject, $msg, $from) {
+function sendRawEmail ($toEmail, $subject, $message, $from) {
// Shall we use PHPMailer class or legacy mode?
if (checkPhpMailerUsage()) {
// Use PHPMailer class with SMTP enabled
@@ -491,13 +505,13 @@ function sendRawEmail ($toEmail, $subject, $msg, $from) {
}
$mail->FromName = constant('MAIN_TITLE');
$mail->Subject = $subject;
- if ((EXT_IS_ACTIVE('html_mail')) && (strip_tags($msg) != $msg)) {
- $mail->Body = $msg;
+ if ((EXT_IS_ACTIVE('html_mail')) && (strip_tags($message) != $message)) {
+ $mail->Body = $message;
$mail->AltBody = 'Your mail program required HTML support to read this mail!';
$mail->WordWrap = 70;
$mail->IsHTML(true);
} else {
- $mail->Body = decodeEntities($msg);
+ $mail->Body = decodeEntities($message);
}
$mail->AddAddress($toEmail, '');
$mail->AddReplyTo(constant('WEBMASTER'), constant('MAIN_TITLE'));
@@ -506,21 +520,21 @@ function sendRawEmail ($toEmail, $subject, $msg, $from) {
$mail->Send();
} else {
// Use legacy mail() command
- @mail($toEmail, $subject, decodeEntities($msg), $from);
+ mail($toEmail, $subject, decodeEntities($message), $from);
}
}
// 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
@@ -577,7 +591,7 @@ function generateDateTime ($time, $mode = '0') {
// Translates Y/N to yes/no
function translateYesNo ($yn) {
// Default
- $translated = "??? (".$yn.')';
+ $translated = "??? (" . $yn.')';
switch ($yn) {
case 'Y': $translated = getMessage('YES'); break;
case 'N': $translated = getMessage('NO'); break;
@@ -732,7 +746,10 @@ function generateCaptchaCode ($code, $type, $DATA, $uid) {
// Loads an email template and compiles it
function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
- global $DATA, $_CONFIG;
+ global $DATA;
+
+ // Our configuration is kept non-global here
+ $_CONFIG = getConfigArray();
// Make sure all template names are lowercase!
$template = strtolower($template);
@@ -782,13 +799,13 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
if (EXT_IS_ACTIVE('nickname')) {
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):NICKNAME!
\n";
// Load nickname
- $result = SQL_QUERY_ESC("SELECT surname, family, gender, email, nickname FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
- array(bigintval($UID)), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT `surname`, `family`, `gender`, `email`, `nickname` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+ array(bigintval($UID)), __FUNCTION__, __LINE__);
} else {
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):NO-NICK!
\n";
/// Load normal data
- $result = SQL_QUERY_ESC("SELECT surname, family, gender, email FROM `{!_MYSQL_PREFIX!}_user_data` WHERE userid=%s LIMIT 1",
- array(bigintval($UID)), __FUNCTION__, __LINE__);
+ $result = SQL_QUERY_ESC("SELECT `surname`, `family`, `gender`, `email` FROM `{!_MYSQL_PREFIX!}_user_data` WHERE `userid`=%s LIMIT 1",
+ array(bigintval($UID)), __FUNCTION__, __LINE__);
}
// Fetch and merge data
@@ -815,29 +832,29 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
// Check for admin/guest/member templates
if (strpos($template, 'admin_') > -1) {
// Admin template found
- $FQFN = $basePath.'admin/'.$template.'.tpl';
+ $FQFN = $basePath.'admin/' . $template.'.tpl';
} elseif (strpos($template, 'guest_') > -1) {
// Guest template found
- $FQFN = $basePath.'guest/'.$template.'.tpl';
+ $FQFN = $basePath.'guest/' . $template.'.tpl';
} elseif (strpos($template, 'member_') > -1) {
// Member template found
- $FQFN = $basePath.'member/'.$template.'.tpl';
+ $FQFN = $basePath.'member/' . $template.'.tpl';
} else {
// Test for extension
$test = substr($template, 0, strpos($template, '_'));
if (EXT_IS_ACTIVE($test)) {
// Set extra path to extension's name
- $FQFN = $basePath.$test.'/'.$template.'.tpl';
+ $FQFN = $basePath . $test.'/' . $template.'.tpl';
} else {
// No special filename
- $FQFN = $basePath.$template.'.tpl';
+ $FQFN = $basePath . $template.'.tpl';
}
}
// Does the special template exists?
if (!isFileReadable($FQFN)) {
// Reset to default template
- $FQFN = $basePath.$template.'.tpl';
+ $FQFN = $basePath . $template.'.tpl';
} // END - if
// Now does the final template exists?
@@ -852,7 +869,7 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
eval($tmpl_file);
} elseif (!empty($template)) {
// Template file not found!
- $newContent = "{--TEMPLATE_404--}: ".$template."
+ $newContent = "{--TEMPLATE_404--}: " . $template."
{--TEMPLATE_CONTENT--}
".print_r($content, true)."
{--TEMPLATE_DATA--}
@@ -869,7 +886,7 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
// Is there some content?
if (empty($newContent)) {
// Compiling failed
- $newContent = "Compiler error for template {$template}!\nUncompiled content:\n".$tmpl_file;
+ $newContent = "Compiler error for template {$template}!\nUncompiled content:\n" . $tmpl_file;
// Add last error if the required function exists
if (function_exists('error_get_last')) $newContent .= "\n--------------------------------------\nDebug:\n".print_r(error_get_last(), true)."--------------------------------------\nPlease don't alter these informations!\nThanx.";
} // END - if
@@ -926,11 +943,11 @@ function redirectToUrl ($URL) {
clearOutputBuffer();
} // END - if
- // Secure the URL against bad things such als HTML insertions and so on...
- $URL = htmlentities(strip_tags($URL), ENT_QUOTES);
-
// Simple probe for bots/spiders from search engines
if ((strpos(detectUserAgent(), 'spider') !== false) || (strpos(detectUserAgent(), 'bot') !== false)) {
+ // Secure the URL against bad things such als HTML insertions and so on...
+ $URL = htmlentities(strip_tags($URL), ENT_QUOTES);
+
// Output new location link as anchor
OUTPUT_HTML('' . $URL . '');
} elseif (!headers_sent()) {
@@ -1027,17 +1044,17 @@ function COMPILE_CODE ($code, $simple = false, $constants = true, $full = true)
if ($fuzzyFound) continue;
// Take all string elements
- if ((is_string($matches[4][$key])) && (!isset($matchesFound[$match])) && (!isset($matchesFound[$key."_".$matches[4][$key]]))) {
+ if ((is_string($matches[4][$key])) && (!isset($matchesFound[$match])) && (!isset($matchesFound[$key."_" . $matches[4][$key]]))) {
// Replace it in the code
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):key={$key},match={$match}
\n";
- $newMatch = str_replace("[".$matches[4][$key]."]", "['".$matches[4][$key]."']", $match);
- $code = str_replace($match, "\".".$newMatch.".\"", $code);
- $matchesFound[$key."_".$matches[4][$key]] = 1;
+ $newMatch = str_replace("[" . $matches[4][$key]."]", "['" . $matches[4][$key]."']", $match);
+ $code = str_replace($match, "\"." . $newMatch.".\"", $code);
+ $matchesFound[$key."_" . $matches[4][$key]] = 1;
$matchesFound[$match] = 1;
} elseif (!isset($matchesFound[$match])) {
// Not yet replaced!
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):match={$match}
\n";
- $code = str_replace($match, "\".".$match.".\"", $code);
+ $code = str_replace($match, "\"." . $match.".\"", $code);
$matchesFound[$match] = 1;
}
} // END - foreach
@@ -1104,30 +1121,30 @@ function ADD_SELECTION ($type, $default, $prefix = '', $id = '0') {
if ($type == 'yn') {
// This is a yes/no selection only!
- if ($id > 0) $prefix .= "[".$id."]";
- $OUT .= "