X-Git-Url: https://git.mxchange.org/?p=mailer.git;a=blobdiff_plain;f=inc%2Ffunctions.php;h=b69c8142dab1f2786ffe7652d49de2327bdbe18f;hp=dc5fe393673e2e7315da6d28456b434765148c2e;hb=5b37b49f283ef1c67015e626e483f21b837c36eb;hpb=40cba35363b7f371f88fe1048d444ca8e85be14c
diff --git a/inc/functions.php b/inc/functions.php
index dc5fe39367..b69c8142da 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -41,7 +41,7 @@ if (!defined('__SECURITY')) {
require($INC);
}
-// Output HTML code directly or "render" it. You addionally switch the new-line character off
+// Output HTML code directly or 'render' it. You addionally switch the new-line character off
function OUTPUT_HTML ($HTML, $newLine = true) {
// Some global variables
global $OUTPUT;
@@ -49,41 +49,40 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
// Do we have HTML-Code here?
if (!empty($HTML)) {
// Yes, so we handle it as you have configured
- switch (constant('OUTPUT_MODE'))
+ switch (getConfig('OUTPUT_MODE'))
{
- case "render":
- // That's why you don't need any \n at the end of your HTML code... :-)
- if (constant('_OB_CACHING') == "on") {
- // Output into PHP's internal buffer
- outputRawCode($HTML);
-
+ case 'render':
// That's why you don't need any \n at the end of your HTML code... :-)
- if ($newLine) echo "\n";
- } else {
- // Render mode for old or lame servers...
- $OUTPUT .= $HTML;
+ if (constant('_OB_CACHING') == 'on') {
+ // Output into PHP's internal buffer
+ outputRawCode($HTML);
- // That's why you don't need any \n at the end of your HTML code... :-)
- if ($newLine) $OUTPUT .= "\n";
- }
- break;
+ // That's why you don't need any \n at the end of your HTML code... :-)
+ if ($newLine) echo "\n";
+ } else {
+ // Render mode for old or lame servers...
+ $OUTPUT .= $HTML;
- case 'direct':
- // If we are switching from render to direct output rendered code
- if ((!empty($OUTPUT)) && (constant('_OB_CACHING') != "on")) { outputRawCode($OUTPUT); $OUTPUT = ''; }
+ // That's why you don't need any \n at the end of your HTML code... :-)
+ if ($newLine) $OUTPUT .= "\n";
+ }
+ break;
- // The same as above... ^
- outputRawCode($HTML);
- if ($newLine) echo "\n";
- break;
+ case 'direct':
+ // If we are switching from render to direct output rendered code
+ if ((!empty($OUTPUT)) && (constant('_OB_CACHING') != 'on')) { outputRawCode($OUTPUT); $OUTPUT = ''; }
- default:
- // Huh, something goes wrong or maybe you have edited config.php ???
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid renderer %s detected.", constant('OUTPUT_MODE')));
- app_die(__FUNCTION__, __LINE__, "{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}");
- break;
+ // The same as above... ^
+ outputRawCode($HTML);
+ if ($newLine) echo "\n";
+ break;
+
+ default:
+ // Huh, something goes wrong or maybe you have edited config.php ???
+ app_die(__FUNCTION__, __LINE__, "{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}");
+ break;
}
- } elseif ((constant('_OB_CACHING') == "on") && (isset($GLOBALS['footer_sent'])) && ($GLOBALS['footer_sent'] == 1)) {
+ } elseif ((constant('_OB_CACHING') == 'on') && (isset($GLOBALS['footer_sent'])) && ($GLOBALS['footer_sent'] == 1)) {
// Headers already sent?
if (headers_sent()) {
// Log this error
@@ -102,20 +101,20 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
} // END - if
// Send HTTP header
- header("HTTP/1.1 200");
+ sendHeader('HTTP/1.1 200');
// Used later
$now = gmdate('D, d M Y H:i:s') . ' GMT';
// General headers for no caching
- header("Expired: " . $now); // RFC2616 - Section 14.21
- header("Last-Modified: " . $now);
- header("Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0"); // HTTP/1.1
- header("Pragma: no-cache"); // HTTP/1.0
- header("Connection: Close");
+ sendHeader('Expired: ' . $now); // RFC2616 - Section 14.21
+ sendHeader('Last-Modified: ' . $now);
+ sendHeader('Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0'); // HTTP/1.1
+ sendHeader('Pragma: no-cache'); // HTTP/1.0
+ sendHeader('Connection: Close');
// Extension 'rewrite' installed?
- if ((EXT_IS_ACTIVE('rewrite')) && ($GLOBALS['output_mode'] != "1") && ($GLOBALS['output_mode'] != "-1")) {
+ if ((EXT_IS_ACTIVE('rewrite')) && ($GLOBALS['output_mode'] != '1') && ($GLOBALS['output_mode'] != '-1')) {
$OUTPUT = rewriteLinksInCode($OUTPUT);
} // END - if
@@ -136,9 +135,9 @@ function OUTPUT_HTML ($HTML, $newLine = true) {
// Output code here, DO NOT REMOVE! ;-)
outputRawCode($OUTPUT);
- } elseif ((constant('OUTPUT_MODE') == "render") && (!empty($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')) && ($GLOBALS['output_mode'] != '1') && ($GLOBALS['output_mode'] != '-1')) {
$OUTPUT = rewriteLinksInCode($OUTPUT);
} // END - if
@@ -158,8 +157,8 @@ function outputRawCode ($HTML) {
// Output stripped HTML code to avoid broken JavaScript code, etc.
echo stripslashes(stripslashes($HTML));
- // Flush the output if only constant('_OB_CACHING') is not "on"
- if (constant('_OB_CACHING') != "on") {
+ // Flush the output if only constant('_OB_CACHING') is not 'on'
+ if (constant('_OB_CACHING') != 'on') {
// Flush it
flush();
} // END - if
@@ -234,7 +233,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
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__);
+ array(getUserId()), __FUNCTION__, __LINE__);
// Is content an array?
if (is_array($content)) {
@@ -259,7 +258,7 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
} // END - if
// Generate date/time string
- $date_time = generateDateTime(time(), "1");
+ $date_time = generateDateTime(time(), '1');
// Base directory
$basePath = sprintf("%stemplates/%s/html/", constant('PATH'), getLanguage());
@@ -301,10 +300,10 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
if ((!empty($GLOBALS['what'])) && ((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,
+ SQL_ESCAPE($GLOBALS['what'])
);
// Probe for it...
@@ -343,12 +342,12 @@ function LOAD_TEMPLATE ($template, $return=false, $content=array()) {
$ret = "\n".$ret."\n";
} elseif ((IS_ADMIN()) || ((isInstalling()) && (!isInstalled()))) {
// Only admins shall see this warning or when installation mode is active
- $ret = " ".TEMPLATE_404."
+ $ret = " {--TEMPLATE_404--}
(".basename($FQFN).")
-".TEMPLATE_CONTENT."
+{--TEMPLATE_CONTENT--}
".print_r($content, true)."
-".TEMPLATE_DATA."
+{--TEMPLATE_DATA--}
".print_r($DATA, true)."
";
}
@@ -411,7 +410,7 @@ function sendEmail($toEmail, $subject, $message, $HTML = 'N', $mailHeader = '')
//* DEBUG: */ print __FUNCTION__."(".__LINE__."):TO={$toEmail} \n";
// Check for PHPMailer or debug-mode
- if (!CHECK_PHPMAILER_USAGE()) {
+ if (!checkPhpMailerUsage()) {
// Not in PHPMailer-Mode
if (empty($mailHeader)) {
// Load email header template
@@ -450,32 +449,30 @@ Message : ".$message."
\n");
} elseif (($HTML == 'Y') && (EXT_IS_ACTIVE('html_mail'))) {
// Send mail as HTML away
- SEND_HTML_EMAIL($toEmail, $subject, $message, $mailHeader);
+ sendHtmlEmail($toEmail, $subject, $message, $mailHeader);
} elseif (!empty($toEmail)) {
// Send Mail away
- SEND_RAW_EMAIL($toEmail, $subject, $message, $mailHeader);
+ sendRawEmail($toEmail, $subject, $message, $mailHeader);
} elseif ($HTML == 'N') {
// Problem found!
- SEND_RAW_EMAIL(constant('WEBMASTER'), "[PROBLEM:]".$subject, $message, $mailHeader);
+ sendRawEmail(constant('WEBMASTER'), '[PROBLEM:]' . $subject, $message, $mailHeader);
}
}
// Check if legacy or PHPMailer command
// @TODO Rewrite this to an extension 'smtp'
// @private
-function CHECK_PHPMAILER_USAGE() {
- return ((defined('SMTP_HOSTNAME')) && (defined('SMTP_USER')) && (defined('SMTP_PASSWORD')) && (constant('SMTP_HOSTNAME') != '') && (constant('SMTP_USER') != ''));
+function checkPhpMailerUsage() {
+ return ((getConfig('SMTP_HOSTNAME') != '') && (getConfig('SMTP_USER') != ''));
}
-/*
- * Send out a raw email with PHPMailer class or legacy mail() command
- */
-function SEND_RAW_EMAIL ($toEmail, $subject, $msg, $from) {
+// Send out a raw email with PHPMailer class or legacy mail() command
+function sendRawEmail ($toEmail, $subject, $msg, $from) {
// Shall we use PHPMailer class or legacy mode?
- if (CHECK_PHPMAILER_USAGE()) {
+ if (checkPhpMailerUsage()) {
// Use PHPMailer class with SMTP enabled
- loadIncludeOnce("inc/phpmailer/class.phpmailer.php");
- loadIncludeOnce("inc/phpmailer/class.smtp.php");
+ loadIncludeOnce('inc/phpmailer/class.phpmailer.php');
+ loadIncludeOnce('inc/phpmailer/class.smtp.php');
// get new instance
$mail = new PHPMailer();
@@ -483,10 +480,10 @@ function SEND_RAW_EMAIL ($toEmail, $subject, $msg, $from) {
$mail->IsSMTP();
$mail->SMTPAuth = true;
- $mail->Host = constant('SMTP_HOSTNAME');
+ $mail->Host = getConfig('SMTP_HOSTNAME');
$mail->Port = 25;
- $mail->Username = constant('SMTP_USER');
- $mail->Password = constant('SMTP_PASSWORD');
+ $mail->Username = getConfig('SMTP_USER');
+ $mail->Password = getConfig('SMTP_PASSWORD');
if (empty($from)) {
$mail->From = constant('WEBMASTER');
} else {
@@ -496,7 +493,7 @@ function SEND_RAW_EMAIL ($toEmail, $subject, $msg, $from) {
$mail->Subject = $subject;
if ((EXT_IS_ACTIVE('html_mail')) && (strip_tags($msg) != $msg)) {
$mail->Body = $msg;
- $mail->AltBody = "Your mail program required HTML support to read this mail!";
+ $mail->AltBody = 'Your mail program required HTML support to read this mail!';
$mail->WordWrap = 70;
$mail->IsHTML(true);
} else {
@@ -504,8 +501,8 @@ function SEND_RAW_EMAIL ($toEmail, $subject, $msg, $from) {
}
$mail->AddAddress($toEmail, '');
$mail->AddReplyTo(constant('WEBMASTER'), constant('MAIN_TITLE'));
- $mail->AddCustomHeader("Errors-To:".constant('WEBMASTER'));
- $mail->AddCustomHeader("X-Loop:".constant('WEBMASTER'));
+ $mail->AddCustomHeader('Errors-To:' . constant('WEBMASTER'));
+ $mail->AddCustomHeader('X-Loop:' . constant('WEBMASTER'));
$mail->Send();
} else {
// Use legacy mail() command
@@ -551,28 +548,28 @@ function generateDateTime ($time, $mode = '0') {
switch (getLanguage())
{
- case 'de': // German date / time format
- switch ($mode) {
- case '0': $ret = date("d.m.Y \u\m H:i \U\h\\r", $time); break;
- case '1': $ret = strtolower(date("d.m.Y - H:i", $time)); break;
- case '2': $ret = date("d.m.Y|H:i", $time); break;
- case '3': $ret = date("d.m.Y", $time); break;
- default:
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode));
- break;
- }
- break;
-
- default: // Default is the US date / time format!
- switch ($mode) {
- case '0': $ret = date("r", $time); break;
- case '1': $ret = date("Y-m-d - g:i A", $time); break;
- case '2': $ret = date("y-m-d|H:i", $time); break;
- case '3': $ret = date("y-m-d", $time); break;
- default:
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode));
- break;
- }
+ case 'de': // German date / time format
+ switch ($mode) {
+ case '0': $ret = date("d.m.Y \u\m H:i \U\h\\r", $time); break;
+ case '1': $ret = strtolower(date("d.m.Y - H:i", $time)); break;
+ case '2': $ret = date("d.m.Y|H:i", $time); break;
+ case '3': $ret = date("d.m.Y", $time); break;
+ default:
+ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode));
+ break;
+ }
+ break;
+
+ default: // Default is the US date / time format!
+ switch ($mode) {
+ case '0': $ret = date("r", $time); break;
+ case '1': $ret = date("Y-m-d - g:i A", $time); break;
+ case '2': $ret = date("y-m-d|H:i", $time); break;
+ case '3': $ret = date("y-m-d", $time); break;
+ default:
+ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Invalid date mode %s detected.", $mode));
+ break;
+ }
}
return $ret;
}
@@ -580,7 +577,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;
@@ -638,13 +635,13 @@ function translateComma ($dotted, $cut = true, $max = 0) {
// Translate it now
switch (getLanguage()) {
- case 'de':
- $dotted = number_format($dotted, $maxComma, ',', '.');
- break;
+ case 'de':
+ $dotted = number_format($dotted, $maxComma, ',', '.');
+ break;
- default:
- $dotted = number_format($dotted, $maxComma, '.', ',');
- break;
+ default:
+ $dotted = number_format($dotted, $maxComma, '.', ',');
+ break;
}
// Return translated value
@@ -675,21 +672,21 @@ function translateGender ($gender) {
function translateUserStatus ($status) {
switch ($status)
{
- case 'UNCONFIRMED':
- case 'CONFIRMED':
- case 'LOCKED':
- $ret = getMessage(sprintf("ACCOUNT_%s", $status));
- break;
-
- case '':
- case null:
- $ret = getMessage('ACCOUNT_DELETED');
- break;
-
- default:
- DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected.", $status));
- $ret = sprintf(getMessage('UNKNOWN_STATUS'), $status);
- break;
+ case 'UNCONFIRMED':
+ case 'CONFIRMED':
+ case 'LOCKED':
+ $ret = getMessage(sprintf("ACCOUNT_%s", $status));
+ break;
+
+ case '':
+ case null:
+ $ret = getMessage('ACCOUNT_DELETED');
+ break;
+
+ default:
+ DEBUG_LOG(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected.", $status));
+ $ret = sprintf(getMessage('UNKNOWN_STATUS'), $status);
+ break;
}
// Return it
@@ -712,7 +709,7 @@ function DEREFERER ($URL) {
function FRAMETESTER ($URL) {
// Prepare frametester URL
$frametesterUrl = sprintf("{!URL!}/modules.php?module=frametester&url=%s",
- encodeString(compileUriCode($URL))
+ encodeString(compileUriCode($URL))
);
return $frametesterUrl;
}
@@ -728,61 +725,11 @@ function countSelection ($array) {
return $ret;
}
-// Wrapper for $_POST['sel']
-function countPostSelection () {
- return countSelection(REQUEST_POST('sel'));
-}
-
// Generate XHTML code for the CAPTCHA
function generateCaptchaCode ($code, $type, $DATA, $uid) {
return '';
}
-// "Getter" for language
-function getLanguage () {
- // Set default return value to default language from config
- $ret = constant('DEFAULT_LANG');
-
- // Init variable
- $lang = '';
-
- // Is the variable set
- if (REQUEST_ISSET_GET(('mx_lang'))) {
- // Accept only first 2 chars
- $lang = substr(REQUEST_GET('mx_lang'), 0, 2);
- } elseif (isset($GLOBALS['cache_array']['language'])) {
- // Use cached
- $ret = $GLOBALS['cache_array']['language'];
- } elseif (!empty($lang)) {
- // Check if main language file does exist
- if (isFileReadable(constant('PATH').'inc/language/'.$lang.'.php')) {
- // Okay found, so let's update cookies
- setLanguage($lang);
- }
- } elseif (!isSessionVariableSet('mx_lang')) {
- // Return stored value from cookie
- $ret = getSession('mx_lang');
-
- // Fixes a warning before the session has the mx_lang constant
- if (empty($ret)) $ret = constant('DEFAULT_LANG');
- }
-
- // Cache entry
- $GLOBALS['cache_array']['language'] = $ret;
-
- // Return value
- return $ret;
-}
-
-// "Setter" for language
-function setLanguage ($lang) {
- // Accept only first 2 chars!
- $lang = substr(SQL_ESCAPE(strip_tags($lang)), 0, 2);
-
- // Set cookie
- setSession('mx_lang', $lang);
-}
-
// Loads an email template and compiles it
function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
global $DATA, $_CONFIG;
@@ -836,12 +783,12 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
//* 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__);
+ 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__);
+ array(bigintval($UID)), __FUNCTION__, __LINE__);
}
// Fetch and merge data
@@ -935,7 +882,7 @@ function LOAD_EMAIL_TEMPLATE ($template, $content = array(), $UID = '0') {
return COMPILE_CODE($newContent);
}
-// Generates a timestamp (wrapper for mktime())
+// Generates a timestamp (some wrapper for mktime())
function makeTime ($H, $M, $S, $stamp) {
// Extract day, month and year from given timestamp
$day = date('d', $stamp);
@@ -947,7 +894,7 @@ function makeTime ($H, $M, $S, $stamp) {
}
// Redirects to an URL and if neccessarry extends it with own base URL
-function redirectToUrl ($URL, $addUrlData=true) {
+function redirectToUrl ($URL) {
// Compile out URI codes
$URL = compileUriCode($URL);
@@ -979,9 +926,6 @@ function redirectToUrl ($URL, $addUrlData=true) {
clearOutputBuffer();
} // END - if
- // Add some data to URL if cookies are not accepted
- if ((!isBooleanConstantAndTrue('__COOKIES')) && ($addUrlData === true)) $URL = addUrlData($URL);
-
// Secure the URL against bad things such als HTML insertions and so on...
$URL = htmlentities(strip_tags($URL), ENT_QUOTES);
@@ -992,7 +936,7 @@ function redirectToUrl ($URL, $addUrlData=true) {
} elseif (!headers_sent()) {
// Load URL when headers are not sent
//* DEBUG: */ debug_report_bug("URL={$URL}");
- header ('Location: '.str_replace('&', '&', $URL));
+ sendHeader('Location: '.str_replace('&', '&', $URL));
} else {
// Output error message
loadInclude('inc/header.php');
@@ -1005,7 +949,7 @@ function redirectToUrl ($URL, $addUrlData=true) {
}
// Wrapper for redirectToUrl but URL comes from a configuration entry
-function LOAD_CONFIGURED_URL ($configEntry) {
+function redirectToConfiguredUrl ($configEntry) {
// Get the URL
$URL = getConfig($configEntry);
@@ -1171,98 +1115,98 @@ function ADD_SELECTION ($type, $default, $prefix = '', $id = '0') {
}
switch ($type) {
- case "day": // Day
- for ($idx = 1; $idx < 32; $idx++) {
- $OUT .= "\n";
+ }
+ } else {
+ // Get current year and subtract the configured minimum age
+ $OUT .= "\n";
+ // Calculate earliest year depending on extension version
+ if (GET_EXT_VERSION('other') >= '0.2.1') {
+ // Use configured minimum age
+ $year = date('Y', time()) - getConfig('min_age');
+ } else {
+ // Use fixed 16 years age
+ $year = date('Y', time()) - 16;
+ }
- // Calculate earliest year (100 years old people can still enter Internet???)
- $minYear = $year - 100;
+ // Construct year selection list
+ for ($idx = $minYear; $idx <= $year; $idx++) {
+ $OUT .= "\n";
- }
- } else {
- // Get current year and subtract the configured minimum age
- $OUT .= "\n";
- // Calculate earliest year depending on extension version
- if (GET_EXT_VERSION('other') >= '0.2.1') {
- // Use configured minimum age
- $year = date('Y', time()) - getConfig('min_age');
- } else {
- // Use fixed 16 years age
- $year = date('Y', time()) - 16;
- }
+ break;
- // Construct year selection list
- for ($idx = $minYear; $idx <= $year; $idx++) {
+ case "hour":
+ for ($idx = 0; $idx < 24; $idx++) {
+ if (strlen($idx) == 1) $idx = '0'.$idx;
$OUT .= "");
@@ -1507,7 +1451,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align="
$OUT .= "