X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=inc%2Ffunctions.php;h=a7cd723a8d52654eee61469a7306f962cc33a7cc;hb=57a53db86560e6591c06c535b888f791d273ae2f;hp=d077a3c7a875919cf5f86af638de2b3b28272b8e;hpb=d52beaaad0b8388fec7f9f3cece88ef98a833751;p=mailer.git
diff --git a/inc/functions.php b/inc/functions.php
index d077a3c7a8..a7cd723a8d 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -77,7 +77,7 @@ function outputHtml ($htmlCode, $newLine = true) {
// The same as above... ^
outputRawCode($htmlCode);
- if ($newLine) print("\n");
+ if ($newLine === true) print("\n");
break;
default:
@@ -85,16 +85,7 @@ function outputHtml ($htmlCode, $newLine = true) {
app_die(__FUNCTION__, __LINE__, '{--FATAL_ERROR--}: {--LANG_NO_RENDER_DIRECT--}');
break;
} // END - switch
- } elseif ((getPhpCaching() == 'on') && (isset($GLOBALS['footer_sent'])) && ($GLOBALS['footer_sent'] == 1)) {
- // Headers already sent?
- if (headers_sent()) {
- // Log this error
- logDebugMessage(__FUNCTION__, __LINE__, 'Headers already sent! We need debug backtrace here.');
-
- // Trigger an user error
- debug_report_bug('Headers are already sent!');
- } // END - if
-
+ } elseif ((getPhpCaching() == 'on') && ((!isset($GLOBALS['header'])) || (count($GLOBALS['header']) == 0))) {
// Output cached HTML code
$GLOBALS['output'] = ob_get_contents();
@@ -108,12 +99,12 @@ function outputHtml ($htmlCode, $newLine = true) {
$GLOBALS['output'] = rewriteLinksInCode($GLOBALS['output']);
} // END - if
- // Compile and run finished rendered HTML code
- compileFinalOutput();
-
// Send all HTTP headers
sendHttpHeaders();
+ // Compile and run finished rendered HTML code
+ compileFinalOutput();
+
// Output code here, DO NOT REMOVE! ;-)
outputRawCode($GLOBALS['output']);
} elseif ((getConfig('OUTPUT_MODE') == 'render') && (!empty($GLOBALS['output']))) {
@@ -122,14 +113,17 @@ function outputHtml ($htmlCode, $newLine = true) {
$GLOBALS['output'] = rewriteLinksInCode($GLOBALS['output']);
} // END - if
- // Compile and run finished rendered HTML code
- compileFinalOutput();
-
// Send all HTTP headers
sendHttpHeaders();
+ // Compile and run finished rendered HTML code
+ compileFinalOutput();
+
// Output code here, DO NOT REMOVE! ;-)
outputRawCode($GLOBALS['output']);
+ } else {
+ // And flush all headers
+ flushHeaders();
}
}
@@ -142,7 +136,7 @@ function sendHttpHeaders () {
sendHeader('HTTP/1.1 200');
// General headers for no caching
- sendHeader('Expired: ' . $now); // RFC2616 - Section 14.21
+ sendHeader('Expires: ' . $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
@@ -169,7 +163,7 @@ function compileFinalOutput () {
// Was that eval okay?
if (empty($newContent)) {
// Something went wrong!
- debug_report_bug('Evaluation error:
' . linenumberCode($eval) . '
');
+ debug_report_bug('Evaluation error:' . linenumberCode($eval) . '
', false);
} // END - if
$GLOBALS['output'] = $newContent;
@@ -177,8 +171,26 @@ function compileFinalOutput () {
$cnt++;
} // END - while
+ // Compress it?
+ if (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos('gzip', $_SERVER['HTTP_ACCEPT_ENCODING']) !== null)) {
+ // Compress it for HTTP gzip
+ $GLOBALS['output'] = gzencode($GLOBALS['output'], 9, true);
+
+ // Add header
+ sendHeader('Content-Encoding: gzip');
+ } elseif (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos('deflate', $_SERVER['HTTP_ACCEPT_ENCODING']) !== null)) {
+ // Compress it for HTTP deflate
+ $GLOBALS['output'] = gzcompress($GLOBALS['output'], 9);
+
+ // Add header
+ sendHeader('Content-Encoding: deflate');
+ }
+
// Add final length
sendHeader('Content-Length: ' . strlen($GLOBALS['output']));
+
+ // Flush all headers
+ flushHeaders();
}
// Output the raw HTML code
@@ -217,7 +229,6 @@ function addFatalMessage ($F, $L, $message, $extra = '') {
$GLOBALS['fatal_messages'][] = $message;
// Log fatal messages away
- debug_report_bug($message);
logDebugMessage($F, $L, 'Fatal error message: ' . $message);
}
@@ -284,7 +295,7 @@ function loadTemplate ($template, $return = false, $content = array()) {
// Do we have to compile the code?
$ret = '';
- if ((strpos($GLOBALS['tpl_content'], '$') !== false) || (strpos($GLOBALS['tpl_content'], '{--') !== false) || (strpos($GLOBALS['tpl_content'], '{!') !== false) || (strpos($GLOBALS['tpl_content'], '{?') !== false)) {
+ if ((strpos($GLOBALS['tpl_content'], '$') !== false) || (strpos($GLOBALS['tpl_content'], '{--') !== false) || (strpos($GLOBALS['tpl_content'], '{!') !== false) || (strpos($GLOBALS['tpl_content'], '{?') !== false) || (strpos($GLOBALS['tpl_content'], '{%') !== false)) {
// Normal HTML output?
if (getOutputMode() == '0') {
// Add surrounding HTML comments to help finding bugs faster
@@ -302,7 +313,7 @@ function loadTemplate ($template, $return = false, $content = array()) {
} else {
// Add surrounding HTML comments to help finding bugs faster
$ret = '\n" . $GLOBALS['tpl_content'] . '\n";
- $eval = '$ret = "' . escapeQuotes($ret) . '";';
+ $eval = '$ret = "' . compileRawCode(escapeQuotes($ret)) . '";';
} // END - if
// Cache the eval() command here
@@ -312,7 +323,7 @@ function loadTemplate ($template, $return = false, $content = array()) {
eval($GLOBALS['template_eval'][$template]);
} elseif ((isAdmin()) || ((isInstalling()) && (!isInstalled()))) {
// Only admins shall see this warning or when installation mode is active
- $ret = '
{--TEMPLATE_404--}
+ $ret = '
{--TEMPLATE_404--}
(' . $template . ')
{--TEMPLATE_CONTENT--}
@@ -350,48 +361,57 @@ function detectExtraTemplatePath ($template) {
// Default is empty
$extraPath = '';
- // Check for admin/guest/member templates
- if (substr($template, 0, 6) == 'admin_') {
- // Admin template found
- $extraPath = 'admin/';
- } elseif (substr($template, 0, 6) == 'guest_') {
- // Guest template found
- $extraPath = 'guest/';
- } elseif (substr($template, 0, 7) == 'member_') {
- // Member template found
- $extraPath = 'member/';
- } elseif (substr($template, 0, 8) == 'install_') {
- // Installation template found
- $extraPath = 'install/';
- } elseif (substr($template, 0, 4) == 'ext_') {
- // Extension template found
- $extraPath = 'ext/';
- } elseif (substr($template, 0, 3) == 'la_') {
- // 'Logical-area' template found
- $extraPath = 'la/';
- } elseif (substr($template, 0, 3) == 'js_') {
- // JavaScript template found
- $extraPath = 'js/';
- } elseif (substr($template, 0, 5) == 'menu_') {
- // Menu template found
- $extraPath = 'menu/';
- } else {
- // Test for extension
- $test = substr($template, 0, strpos($template, '_'));
+ // Do we have cache?
+ if (!isset($GLOBALS['extra_path'][$template])) {
+ // Check for admin/guest/member/etc. templates
+ if (substr($template, 0, 6) == 'admin_') {
+ // Admin template found
+ $extraPath = 'admin/';
+ } elseif (substr($template, 0, 6) == 'guest_') {
+ // Guest template found
+ $extraPath = 'guest/';
+ } elseif (substr($template, 0, 7) == 'member_') {
+ // Member template found
+ $extraPath = 'member/';
+ } elseif (substr($template, 0, 7) == 'select_') {
+ // Selection template found
+ $extraPath = 'select/';
+ } elseif (substr($template, 0, 8) == 'install_') {
+ // Installation template found
+ $extraPath = 'install/';
+ } elseif (substr($template, 0, 4) == 'ext_') {
+ // Extension template found
+ $extraPath = 'ext/';
+ } elseif (substr($template, 0, 3) == 'la_') {
+ // 'Logical-area' template found
+ $extraPath = 'la/';
+ } elseif (substr($template, 0, 3) == 'js_') {
+ // JavaScript template found
+ $extraPath = 'js/';
+ } elseif (substr($template, 0, 5) == 'menu_') {
+ // Menu template found
+ $extraPath = 'menu/';
+ } else {
+ // Test for extension
+ $test = substr($template, 0, strpos($template, '_'));
- // Probe for valid extension name
- if (isExtensionNameValid($test)) {
- // Set extra path to extension's name
- $extraPath = $test . '/';
- } // END - if
- }
+ // Probe for valid extension name
+ if (isExtensionNameValid($test)) {
+ // Set extra path to extension's name
+ $extraPath = $test . '/';
+ } // END - if
+ }
+
+ // Store it in cache
+ $GLOBALS['extra_path'][$template] = $extraPath;
+ } // END - if
// Return result
- return $extraPath;
+ return $GLOBALS['extra_path'][$template];
}
// Loads an email template and compiles it
-function loadEmailTemplate ($template, $content = array(), $UID = '0') {
+function loadEmailTemplate ($template, $content = array(), $userid = '0') {
global $DATA;
// Make sure all template names are lowercase!
@@ -400,53 +420,36 @@ function loadEmailTemplate ($template, $content = array(), $UID = '0') {
// Default 'nickname' if extension is not installed
$nick = '---';
- // Prepare IP number and User Agent
- $REMOTE_ADDR = detectRemoteAddr();
- $HTTP_USER_AGENT = detectUserAgent();
-
- // Default admin
- $ADMIN = getConfig('MAIN_TITLE');
-
- // Is the admin logged in?
- if (isAdmin()) {
- // Get admin id
- $adminId = getCurrentAdminId();
-
- // Load Admin data
- $ADMIN = getAdminEmail($adminId);
- } // END - if
-
// Neutral email address is default
$email = getConfig('WEBMASTER');
- // Expiration in a nice output format
- // NOTE: Use $content[expiration] in your templates instead of $EXPIRATION
- if (getConfig('auto_purge') == '0') {
- // Will never expire!
- $EXPIRATION = getMessage('MAIL_WILL_NEVER_EXPIRE');
- } else {
- // Create nice date string
- $EXPIRATION = createFancyTime(getConfig('auto_purge'));
- }
-
// Is content an array?
if (is_array($content)) {
- // Add expiration to array, $EXPIRATION is now deprecated!
- $content['expiration'] = $EXPIRATION;
+ // Add expiration to array
+ if ((isConfigEntrySet('auto_purge')) && (getConfig('auto_purge') == '0')) {
+ // Will never expire!
+ $content['expiration'] = getMessage('MAIL_WILL_NEVER_EXPIRE');
+ } elseif (isConfigEntrySet('auto_purge')) {
+ // Create nice date string
+ $content['expiration'] = createFancyTime(getConfig('auto_purge'));
+ } else {
+ // Missing entry
+ $content['expiration'] = getMessage('MAIL_NO_CONFIG_AUTO_PURGE');
+ }
} // END - if
// Load user's data
- //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):UID={$UID},template={$template},content[]=".gettype($content).'
');
- if (($UID > 0) && (is_array($content))) {
+ //* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):UID={$userid},template={$template},content[]=".gettype($content).'
');
+ if (($userid > 0) && (is_array($content))) {
// If nickname extension is installed, fetch nickname as well
- if ((isExtensionActive('nickname')) && (isNicknameUsed($UID))) {
+ if ((isExtensionActive('nickname')) && (isNicknameUsed($userid))) {
//* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):NICKNAME!
");
// Load by nickname
- fetchUserData($UID, 'nickname');
+ fetchUserData($userid, 'nickname');
} else {
//* DEBUG: */ outputHtml(__FUNCTION__."(".__LINE__."):NO-NICK!
");
/// Load by userid
- fetchUserData($UID);
+ fetchUserData($userid);
}
// Merge data if valid
@@ -464,7 +467,7 @@ function loadEmailTemplate ($template, $content = array(), $UID = '0') {
if (isset($content['email'])) $email = $content['email'];
// Store email for some functions in global data array
- // @TODO Do only use $contentn, not $DATA or raw variables
+ // @TODO Do only use $content, not $DATA or raw variables
$DATA['email'] = $email;
// Base directory
@@ -510,7 +513,7 @@ function loadEmailTemplate ($template, $content = array(), $UID = '0') {
// Is there some content?
if (empty($newContent)) {
// Compiling failed
- $newContent = "Compiler error for template {$template}!\nUncompiled content:\n" . $GLOBALS['tpl_content'];
+ $newContent = "Compiler error for template " . $template . " !\nUncompiled content:\n" . $GLOBALS['tpl_content'];
// 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.";
@@ -578,17 +581,17 @@ function sendEmail ($toEmail, $subject, $message, $isHtml = 'N', $mailHeader = '
eval("\$toEmail = \"".compileRawCode(escapeQuotes($toEmail))."\";");
// Compile "MSG"
- eval("\$message = \"".compileRawCode(escapeQuotes($message))."\";");
+ eval("\$message = \"".str_replace('$', '$', compileRawCode(escapeQuotes($message)))."\";");
// Fix HTML parameter (default is no!)
if (empty($isHtml)) $isHtml = 'N';
if (isDebugModeEnabled()) {
// In debug mode we want to display the mail instead of sending it away so we can debug this part
outputHtml('
-Headers : ' . str_replace('<', '<', str_replace('>', '>', secureString(trim($mailHeader)))) . '
-To : ' . $toEmail . '
-Subject : ' . $subject . '
-Message : ' . $message . '
+Headers : ' . htmlentities(utf8_decode(trim($mailHeader))) . '
+To : ' . htmlentities(utf8_decode($toEmail)) . '
+Subject : ' . htmlentities(utf8_decode($subject)) . '
+Message : ' . htmlentities(utf8_decode($message)) . '
');
} elseif (($isHtml == 'Y') && (isExtensionActive('html_mail'))) {
// Send mail as HTML away
@@ -749,7 +752,7 @@ function translateYesNo ($yn) {
// Translates the "pool type" into human-readable
function translatePoolType ($type) {
// Default?type is unknown
- $translated = sprintf(getMessage('POOL_TYPE_UNKNOWN'), $type);
+ $translated = getMaskedMessage('POOL_TYPE_UNKNOWN', $type);
// Generate constant
$constName = sprintf("POOL_TYPE_%s", $type);
@@ -840,7 +843,7 @@ function translateUserStatus ($status) {
default:
logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown status %s detected.", $status));
- $ret = sprintf(getMessage('UNKNOWN_STATUS'), $status);
+ $ret = getMaskedMessage('UNKNOWN_STATUS', $status);
break;
} // END - switch
@@ -853,7 +856,7 @@ function generateDerefererUrl ($URL) {
// Don't de-refer our own links!
if (substr($URL, 0, strlen(getConfig('URL'))) != getConfig('URL')) {
// De-refer this link
- $URL = '{?URL?}/modules.php?module=loader&url=' . encodeString(compileUriCode($URL));
+ $URL = '{%url=modules.php?module=loader&url=' . encodeString(compileUriCode($URL)) . '%}';
} // END - if
// Return link
@@ -863,7 +866,7 @@ function generateDerefererUrl ($URL) {
// Generates an URL for the frametester
function generateFrametesterUrl ($URL) {
// Prepare frametester URL
- $frametesterUrl = sprintf("{?URL?}/modules.php?module=frametester&url=%s",
+ $frametesterUrl = sprintf("{%%url=modules.php?module=frametester&url=%s%%}",
encodeString(compileUriCode($URL))
);
@@ -894,7 +897,7 @@ function countSelection ($array) {
// Generate XHTML code for the CAPTCHA
function generateCaptchaCode ($code, $type, $DATA, $userid) {
- return '';
+ return '';
}
// Generates a timestamp (some wrapper for mktime())
@@ -918,18 +921,7 @@ function makeTime ($hours, $minutes, $seconds, $stamp) {
// Redirects to an URL and if neccessarry extends it with own base URL
function redirectToUrl ($URL) {
// Compile out codes
- eval('$URL = "' . compileRawCode($URL) . '";');
-
- // Check if http(s):// is there
- if ((substr($URL, 0, 7) != 'http://') && (substr($URL, 0, 8) != 'https://')) {
- // Make all URLs full-qualified
- $URL = getConfig('URL') . '/' . $URL;
- } // END - if
-
- // Three different debug ways...
- //* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
- //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'URL=' . $URL);
- //* DEBUG: */ die($URL);
+ eval('$URL = "' . compileRawCode(encodeUrl($URL)) . '";');
// Default 'rel' value is external, nofollow is evil from Google and hurts the Internet
$rel = ' rel="external"';
@@ -940,23 +932,19 @@ function redirectToUrl ($URL) {
$rel = '';
} // END - if
- // Get output buffer
- $GLOBALS['output'] = ob_get_contents();
-
- // Clear it only if there is content
- if (!empty($GLOBALS['output'])) {
- clearOutputBuffer();
- } // END - if
+ // Three different ways to debug...
+ //* DEBUG: */ debug_report_bug(sprintf("%s[%s:] URL=%s", __FUNCTION__, __LINE__, $URL));
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'URL=' . $URL);
+ //* DEBUG: */ die($URL);
// Simple probe for bots/spiders from search engines
- if ((strpos(detectUserAgent(), 'spider') !== false) || (strpos(detectUserAgent(), 'bot') !== false)) {
+ if (isSpider()) {
// Secure the URL against bad things such als HTML insertions and so on...
$URL = secureString($URL);
// Output new location link as anchor
outputHtml('' . $URL . '');
} elseif (!headers_sent()) {
- //* DEBUG: */ debug_report_bug("URL={$URL}");
// Clear own output buffer
$GLOBALS['output'] = '';
@@ -1034,11 +1022,11 @@ function compileRawCode ($code, $simple = false, $constants = true, $full = true
if ($constants === true) {
// BEFORE 0.2.1 : Language and data constants
// WITH 0.2.1+ : Only language constants
- $code = str_replace('{--', "\".getMessage('", str_replace('--}', "').\"", $code));
+ $code = str_replace('{--', "\" . getMessage('", str_replace('--}', "') . \"", $code));
// BEFORE 0.2.1 : Not used
// WITH 0.2.1+ : Data constants
- $code = str_replace('{!', "\".constant('", str_replace("!}", "').\"", $code));
+ $code = str_replace('{!', "\" . constant('", str_replace('!}', "') . \"", $code));
} // END - if
// Compile QUOT and other non-HTML codes
@@ -1345,7 +1333,7 @@ function generateImageOrCode ($img_code, $headerSent = true) {
debug_report_bug('img_code ' . $img_code .' has invalid length. img_code()=' . strlen($img_code) . ' code_length=' . getConfig('code_length'));
} elseif ($headerSent === false) {
// Return an HTML code here
- return "\n";
+ return "\n";
}
// Load image
@@ -1396,6 +1384,16 @@ function generateImageOrCode ($img_code, $headerSent = true) {
}
// Create selection box or array of splitted timestamp
function createTimeSelections ($timestamp, $prefix = '', $display = '', $align = 'center', $return_array=false) {
+ // Do not continue if ONE_DAY is absend
+ if (!isConfigEntrySet('ONE_DAY')) {
+ // And return the timestamp itself or empty array
+ if ($return_array === true) {
+ return array();
+ } else {
+ return $timestamp;
+ }
+ } // END - if
+
// Calculate 2-seconds timestamp
$stamp = round($timestamp);
//* DEBUG: */ print("*" . $stamp.'/' . $timestamp."*
");
@@ -1490,7 +1488,7 @@ function createTimeSelections ($timestamp, $prefix = '', $display = '', $align =
if (ereg('Y', $display) || (empty($display))) {
// Generate year selection
- $OUT .= " |