} // END - if
// Wrapper until we merged to the EL branch
-function preCompileCode ($code, $template = '', $compiled = false, $full = true, $overwrite = false) {
- return compileCode($code, false, true, $full);
+function preCompileCode ($code, $template = '', $compiled = FALSE, $full = TRUE, $overwrite = FALSE) {
+ return compileCode($code, FALSE, TRUE, $full);
}
// Setter for 'is_template_html'
-function enableTemplateHtml ($enable = true) {
+function enableTemplateHtml ($enable = TRUE) {
$GLOBALS['is_template_html'] = (bool) $enable;
}
// Is the output_mode other than 0 (HTML), then no comments are enabled
if (!isHtmlOutputMode()) {
// No HTML
- return false;
+ return FALSE;
} else {
// Maybe HTML?
return $GLOBALS['is_template_html'];
// "Getter" for color switch code
function getColorSwitchCode ($template) {
// Prepare the code
- $code = "{DQUOTE} . doTemplateColorSwitch('" . $template . "', false, false) . {DQUOTE}";
+ $code = "{DQUOTE} . doTemplateColorSwitch('" . $template . "', FALSE, FALSE) . {DQUOTE}";
// And return it
return $code;
}
// Output HTML code directly or 'render' it. You addionally switch the new-line character off
-function outputHtml ($htmlCode, $newLine = true) {
+function outputHtml ($htmlCode, $newLine = TRUE) {
// Init output
if (!isset($GLOBALS['__output'])) {
$GLOBALS['__output'] = '';
} // END - if
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'getOutputMode()=' . getOutputMode() . ',htmlCode(length)=' . strlen($htmlCode) . ',output(length)=' . strlen($GLOBALS['__output']));
- // Do we have HTML-Code here?
+ // Is there HTML-Code here?
if (!empty($htmlCode)) {
// Yes, so we handle it as you have configured
switch (getOutputMode()) {
outputRawCode($htmlCode);
// That's why you don't need any \n at the end of your HTML code... :-)
- if ($newLine === true) {
- outputRawCode(chr(10));
+ if ($newLine === TRUE) {
+ outputRawCode(PHP_EOL);
} // END - if
} else {
// Render mode for old or lame servers...
$GLOBALS['__output'] .= $htmlCode;
// That's why you don't need any \n at the end of your HTML code... :-)
- if ($newLine === true) {
- $GLOBALS['__output'] .= chr(10);
+ if ($newLine === TRUE) {
+ $GLOBALS['__output'] .= PHP_EOL;
} // END - if
}
break;
// The same as above... ^
outputRawCode($htmlCode);
- if ($newLine === true) {
- outputRawCode(chr(10));
+ if ($newLine === TRUE) {
+ outputRawCode(PHP_EOL);
} // END - if
break;
addPageHeaderFooter();
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, '__output(length)=' . strlen($GLOBALS['__output']) . ' - After addPageHeaderFooter() call.');
- // Do the final compilation
- $GLOBALS['__output'] = compileUriCode(doFinalCompilation($GLOBALS['__output']));
+ // Do the final (general) compilation
+ $GLOBALS['__output'] = doFinalCompilation($GLOBALS['__output']);
+
+ // Compile any other things out
+ $GLOBALS['__output'] = compileUriCode($GLOBALS['__output']);
// Extension 'rewrite' installed?
if ((isExtensionActive('rewrite')) && (!isCssOutputMode())) {
}
// Main compilation loop
-function doFinalCompilation ($code, $insertComments = true, $enableCodes = true) {
+function doFinalCompilation ($code, $insertComments = TRUE, $enableCodes = TRUE) {
// Insert comments? (Only valid with HTML templates, of course)
enableTemplateHtml($insertComments);
$count = 0;
// Compile all out
- while (((isInString('{--', $code)) || (isInString('{DQUOTE}', $code)) || (isInString('{?', $code)) || (isInString('{%', $code) !== false)) && ($count < 7)) {
+ while (((isInString('{--', $code)) || (isInString('{DQUOTE}', $code)) || (isInString('{?', $code)) || (isInString('{%', $code) !== FALSE)) && ($count < 7)) {
// Init common variables
$content = array();
$newContent = '';
// Compile it
//* DEBUG: */ debugOutput('<pre>'.linenumberCode($code).'</pre>');
- $eval = '$newContent = "' . str_replace('{DQUOTE}', '"', compileCode(escapeQuotes($code), false, true, $enableCodes)) . '";';
+ $eval = '$newContent = "' . str_replace('{DQUOTE}', '"', compileCode(escapeQuotes($code), FALSE, TRUE, $enableCodes)) . '";';
//* DEBUG: */ if (!$insertComments) print('EVAL=<pre>'.linenumberCode($eval).'</pre>');
eval($eval);
//* DEBUG: */ if (!$insertComments) print('NEW=<pre>'.linenumberCode($newContent).'</pre>');
// Was that eval okay?
if (empty($newContent)) {
// Something went wrong!
- reportBug(__FUNCTION__, __LINE__, 'Evaluation error:<pre>' . linenumberCode($eval) . '</pre>', false);
+ reportBug(__FUNCTION__, __LINE__, 'Evaluation error:<pre>' . linenumberCode($eval) . '</pre>', FALSE);
} // END - if
// Use it again
$code = $newContent;
// Compile the final code if insertComments is true
- if ($insertComments == true) {
+ if ($insertComments == TRUE) {
// ... because SQL queries shall keep OPEN_CONFIG and such in
$code = compileRawCode($code);
} // END - if
} // END - while
// Add debugging data in HTML code, if mode is enabled
- if ((isDebugModeEnabled()) && ($insertComments === true) && ((isHtmlOutputMode()) || (isCssOutputMode()))) {
+ if ((isDebugModeEnabled()) && ($insertComments === TRUE) && ((isHtmlOutputMode()) || (isCssOutputMode()))) {
// Add loop count
$code .= '<!-- Total compilation loop=' . $count . ' //-->';
} // END - if
}
// Load a template file and return it's content (only it's name; do not use ' or ")
-function loadTemplate ($template, $return = false, $content = array(), $compileCode = true) {
+function loadTemplate ($template, $return = FALSE, $content = array(), $compileCode = TRUE) {
// @TODO Remove these sanity checks if all is fine
if (!is_bool($return)) {
// $return has to be boolean
// Set current template
$GLOBALS['current_template'] = $template;
- // Do we have cache?
- if ((!isDebuggingTemplateCache()) && (isTemplateCached($template))) {
+ // Is there cache?
+ if ((!isDebuggingTemplateCache()) && (isTemplateCached('html', $template))) {
// Evaluate the cache
- eval(readTemplateCache($template));
- } elseif (!isset($GLOBALS['template_eval'][$template])) {
+ eval(readTemplateCache('html', $template));
+ } elseif (!isset($GLOBALS['template_eval']['html'][$template])) {
// Make all template names lowercase
$template = strtolower($template);
// Base directory
$basePath = sprintf("%stemplates/%s/html/", getPath(), getLanguage());
- $extraPath = detectExtraTemplatePath($template);
+ $extraPath = detectExtraTemplatePath('html', $template);
// Generate FQFN
$FQFN = $basePath . $extraPath . $template . '.tpl';
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Template ' . $template . ' is solved to FQFN=' . $FQFN);
// Does the special template exists?
if (!isFileReadable($FQFN)) {
incrementConfigEntry('num_templates');
// The local file does exists so we load it. :)
- $GLOBALS['tpl_content'][$template] = readFromFile($FQFN);
+ $GLOBALS['template_content']['html'][$template] = readFromFile($FQFN);
- // Do we have to compile the code?
- if ((isInString('$', $GLOBALS['tpl_content'][$template])) || (isInString('{--', $GLOBALS['tpl_content'][$template])) || (isInString('{?', $GLOBALS['tpl_content'][$template])) || (isInString('{%', $GLOBALS['tpl_content'][$template]))) {
+ // Is there to compile the code?
+ if ((isInString('$', $GLOBALS['template_content']['html'][$template])) || (isInString('{--', $GLOBALS['template_content']['html'][$template])) || (isInString('{?', $GLOBALS['template_content']['html'][$template])) || (isInString('{%', $GLOBALS['template_content']['html'][$template]))) {
// Normal HTML output?
if ((isHtmlOutputMode()) && (substr($template, 0, 3) != 'js_')) {
// Add surrounding HTML comments to help finding bugs faster
- $code = '<!-- Template ' . $template . ' - Start //-->' . $GLOBALS['tpl_content'][$template] . '<!-- Template ' . $template . ' - End //-->';
+ $code = '<!-- Template ' . $template . ' - Start //-->' . $GLOBALS['template_content']['html'][$template] . '<!-- Template ' . $template . ' - End //-->';
// Prepare eval() command
- $GLOBALS['template_eval'][$template] = '$ret = "' . getColorSwitchCode($template) . compileCode(escapeQuotes($code), false, true, true, $compileCode) . '";';
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
+ $GLOBALS['template_eval']['html'][$template] = '$ret = "' . getColorSwitchCode($template) . compileCode(escapeQuotes($code), FALSE, TRUE, TRUE, $compileCode) . '";';
} elseif (substr($template, 0, 3) == 'js_') {
// JavaScripts don't like entities, dollar signs and timings
- $GLOBALS['template_eval'][$template] = '$ret = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['tpl_content'][$template]), false, true, true, $compileCode) . '");';
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
+ $GLOBALS['template_eval']['html'][$template] = '$ret = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), FALSE, TRUE, TRUE, $compileCode) . '");';
} else {
// Prepare eval() command, other output doesn't like entities, maybe
- $GLOBALS['template_eval'][$template] = '$ret = decodeEntities("' . compileRawCode(escapeQuotes($GLOBALS['tpl_content'][$template]), false, true, true, $compileCode) . '");';
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
+ $GLOBALS['template_eval']['html'][$template] = '$ret = decodeEntities("' . compileRawCode(escapeQuotes($GLOBALS['template_content']['html'][$template]), FALSE, TRUE, TRUE, $compileCode) . '");';
}
} elseif (isHtmlOutputMode()) {
// Add surrounding HTML comments to help finding bugs faster
- $ret = '<!-- Template ' . $template . ' - Start //-->' . $GLOBALS['tpl_content'][$template] . '<!-- Template ' . $template . ' - End //-->';
- $GLOBALS['template_eval'][$template] = '$ret = "' . getColorSwitchCode($template) . compileRawCode(escapeQuotes($ret), false, true, true, $compileCode) . '";';
+ $ret = '<!-- Template ' . $template . ' - Start //-->' . $GLOBALS['template_content']['html'][$template] . '<!-- Template ' . $template . ' - End //-->';
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
+ $GLOBALS['template_eval']['html'][$template] = '$ret = "' . getColorSwitchCode($template) . compileRawCode(escapeQuotes($ret), FALSE, TRUE, TRUE, $compileCode) . '";';
} else {
// JavaScript again
- $GLOBALS['template_eval'][$template] = '$ret = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['tpl_content'][$template]), false, true, true, $compileCode) . '");';
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
+ $GLOBALS['template_eval']['html'][$template] = '$ret = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), FALSE, TRUE, TRUE, $compileCode) . '");';
} // END - if
} elseif ((isAdmin()) || ((isInstalling()) && (!isInstalled()))) {
// Only admins shall see this warning or when installation mode is active
</div>
<div class="para">
{--TEMPLATE_CONTENT--}:
- <pre>' . print_r($content, true) . '</pre>
+ <pre>' . print_r($content, TRUE) . '</pre>
</div>';
} else {
// No file!
- $GLOBALS['template_eval'][$template] = '404';
+ $GLOBALS['template_eval']['html'][$template] = '404';
}
}
// Code set?
- if ((isset($GLOBALS['template_eval'][$template])) && ($GLOBALS['template_eval'][$template] != '404')) {
+ if ((isset($GLOBALS['template_eval']['html'][$template])) && ($GLOBALS['template_eval']['html'][$template] != '404')) {
// Eval the code
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'template=' . $template . ' - BEFORE EVAL');
- ///* DEBUG: */ print('<pre>'.htmlentities($GLOBALS['template_eval'][$template]).'</pre>');
- eval($GLOBALS['template_eval'][$template]);
+ ///* DEBUG: */ print('<pre>'.htmlentities($GLOBALS['template_eval']['html'][$template]).'</pre>');
+ eval($GLOBALS['template_eval']['html'][$template]);
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'template=' . $template . ' - AFTER EVAL');
} // END - if
- // Do we have some content to output or return?
+ // Is there some content to output or return?
if (!empty($ret)) {
// Not empty so let's put it out! ;)
- if ($return === true) {
+ if ($return === TRUE) {
// Return the HTML code
return $ret;
} else {
}
} elseif (isDebugModeEnabled()) {
// Warning, empty output!
- return 'E:' . $template . ',content=<pre>' . print_r($content, true) . '</pre>';
+ return 'E:' . $template . ',content=<pre>' . print_r($content, TRUE) . '</pre>';
}
}
// Detects the extra template path from given template name
-function detectExtraTemplatePath ($template) {
+function detectExtraTemplatePath ($prefix, $template) {
// Default is empty
$extraPath = '';
- // Do we have cache?
- if (!isset($GLOBALS['extra_path'][$template])) {
+ // Is there cache?
+ if (!isset($GLOBALS['extra_path'][$prefix][$template])) {
// Check for admin/guest/member/etc. templates
if (substr($template, 0, 6) == 'admin_') {
// Admin template found
}
// Store it in cache
- $GLOBALS['extra_path'][$template] = $extraPath;
+ $GLOBALS['extra_path'][$prefix][$template] = $extraPath;
} // END - if
// Return result
- return $GLOBALS['extra_path'][$template];
+ return $GLOBALS['extra_path'][$prefix][$template];
}
// Loads an email template and compiles it
-function loadEmailTemplate ($template, $content = array(), $userid = NULL, $loadUserData = true) {
+function loadEmailTemplate ($template, $content = array(), $userid = NULL, $loadUserData = TRUE) {
// Make sure all template names are lowercase!
$template = strtolower($template);
// Is content an array?
if (is_array($content)) {
// Add expiration to array
- if ((isConfigEntrySet('auto_purge')) && (getAutoPurge() == '0')) {
+ if ((isExtensionInstalled('autopurge')) && (getAutoPurge() == '0')) {
// Will never expire!
$content['expiration'] = '{--MAIL_WILL_NEVER_EXPIRE--}';
- } elseif (isConfigEntrySet('auto_purge')) {
+ } elseif ((isExtensionInstalled('autopurge')) && (isConfigEntrySet('auto_purge'))) {
// Create nice date string
$content['expiration'] = '{%config,createFancyTime=auto_purge%}';
} else {
}
} // END - if
- // Base directory
- $basePath = sprintf("%stemplates/%s/emails/", getPath(), getLanguage());
+ // Is there cache?
+ if ((!isDebuggingTemplateCache()) && (isTemplateCached('email', $template))) {
+ // Evaluate the cache
+ eval(readTemplateCache('email', $template));
+ } elseif (!isset($GLOBALS['template_eval']['email'][$template])) {
+ // Base directory
+ $basePath = sprintf("%stemplates/%s/emails/", getPath(), getLanguage());
- // Detect extra path
- $extraPath = detectExtraTemplatePath($template);
+ // Detect extra path
+ $extraPath = detectExtraTemplatePath('email', $template);
- // Generate full FQFN
- $FQFN = $basePath . $extraPath . $template . '.tpl';
+ // Generate full FQFN
+ $FQFN = $basePath . $extraPath . $template . '.tpl';
- // Does the special template exists?
- if (!isFileReadable($FQFN)) {
- // Reset to default template
- $FQFN = $basePath . $template . '.tpl';
- } // END - if
+ // Does the special template exists?
+ if (!isFileReadable($FQFN)) {
+ // Reset to default template
+ $FQFN = $basePath . $template . '.tpl';
+ } // END - if
- // Now does the final template exists?
- $newContent = '';
- if (isFileReadable($FQFN)) {
- // The local file does exists so we load it. :)
- $GLOBALS['tpl_content'][$template] = readFromFile($FQFN);
-
- // Run code
- $GLOBALS['tpl_content'][$template] = '$newContent = decodeEntities("' . compileRawCode(escapeQuotes($GLOBALS['tpl_content'][$template])) . '");';
- eval($GLOBALS['tpl_content'][$template]);
- } elseif (!empty($template)) {
- // Template file not found
- $newContent = '<div class="para">
+ // Now does the final template exists?
+ $newContent = '';
+ if (isFileReadable($FQFN)) {
+ // The local file does exists so we load it. :)
+ $GLOBALS['template_content']['email'][$template] = readFromFile($FQFN);
+
+ // Run code
+ $GLOBALS['template_eval']['email'][$template] = '$newContent = decodeEntities("' . compileRawCode(escapeQuotes($GLOBALS['template_content']['email'][$template])) . '");';
+ } elseif (!empty($template)) {
+ // Template file not found
+ $newContent = '<div class="para">
{--TEMPLATE_404--}: ' . $template . '
</div>
<div class="para">
{--TEMPLATE_CONTENT--}:
- <pre>' . print_r($content, true) . '</pre>
+ <pre>' . print_r($content, TRUE) . '</pre>
</div>';
- // Debug mode not active? Then remove the HTML tags
- if (!isDebugModeEnabled()) {
- // Remove HTML tags
- $newContent = secureString($newContent);
- } // END - if
- } else {
- // No template name supplied!
- $newContent = '{--NO_TEMPLATE_SUPPLIED--}';
+ // Don't cache this, as there is no template to cache
+ $GLOBALS['template_eval']['email'][$template] = '404';
+
+ // Debug mode not active? Then remove the HTML tags
+ if (!isDebugModeEnabled()) {
+ // Remove HTML tags
+ $newContent = secureString($newContent);
+ } // END - if
+ } else {
+ // No template name supplied!
+ $newContent = '{--NO_TEMPLATE_SUPPLIED--}';
+ $GLOBALS['template_eval']['email'][$template] = '404';
+ }
}
- // Is there some content?
+ // Is there something to eval?
+ if ((isset($GLOBALS['template_eval']['email'][$template])) && ($GLOBALS['template_eval']['email'][$template] != '404')) {
+ // Eval the code
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'template=' . $template . ' - BEFORE EVAL');
+ ///* DEBUG: */ print('<pre>'.htmlentities($GLOBALS['template_eval']['email'][$template]).'</pre>');
+ eval($GLOBALS['template_eval']['email'][$template]);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'template=' . $template . ' - AFTER EVAL');
+ } // END - if
+
+ // Are there some content?
if (empty($newContent)) {
// Compiling failed
- $newContent = "Compiler error for template " . $template . " !\nUncompiled content:\n" . $GLOBALS['tpl_content'][$template];
+ $newContent = "Compiler error for template " . $template . " !\nUncompiled content:\n" . $GLOBALS['template_eval']['email'][$template];
// Add last error if the required function exists
if (function_exists('error_get_last')) {
// Add last error and some lines for better overview
- $newContent .= "\n--------------------------------------\nDebug:\n".print_r(error_get_last(), true)."--------------------------------------\nPlease don't alter these informations!\nThanx.";
+ $newContent .= "\n--------------------------------------\nDebug:\n" . print_r(error_get_last(), TRUE) . "--------------------------------------\nPlease don't alter these informations!\nThanx.";
} // END - if
} // END - if
function getMenuCssClasses ($data) {
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'data=' . $data);
- // Do we have cache?
+ // Is there cache?
if (!isset($GLOBALS[__FUNCTION__][$data])) {
// $data needs to be converted into an array
$content = explode('|', $data);
}
// Compiles the given HTML/mail code
-function compileCode ($code, $simple = false, $constants = true, $full = true, $compileCode = true) {
+function compileCode ($code, $simple = FALSE, $constants = TRUE, $full = TRUE, $compileCode = TRUE) {
// Is the code a string or should we not compile?
- if ((!is_string($code)) || ($compileCode === false)) {
+ if ((!is_string($code)) || ($compileCode === FALSE)) {
// Silently return it
return $code;
} // END - if
// Start couting
- $startCompile = microtime(true);
+ $startCompile = microtime(TRUE);
// Comile the code
$code = compileRawCode($code, $simple, $constants, $full);
// Get timing
- $compilationTime = $startCompile - microtime(true);
+ $compilationTime = $startCompile - microtime(TRUE);
// Add timing if enabled
if (isTemplateHtml()) {
// Compiles the code
// @TODO $simple/$constants are deprecated
-function compileRawCode ($code, $simple = false, $constants = true, $full = true, $compileCode = true) {
+function compileRawCode ($code, $simple = FALSE, $constants = TRUE, $full = TRUE, $compileCode = TRUE) {
// Is the code a string or shall we not compile?
- if ((!is_string($code)) || ($compileCode === false)) {
+ if ((!is_string($code)) || ($compileCode === FALSE)) {
// Silently return it
return $code;
} // END - if
$secChars = $GLOBALS['url_chars'];
// Select full set of chars to replace when we e.g. want to compile URLs
- if ($full === true) {
+ if ($full === TRUE) {
$secChars = $GLOBALS['security_chars'];
} // END - if
$matchesFound = array();
foreach ($matches[0] as $key => $match) {
// Fuzzy look has failed by default
- $fuzzyFound = false;
+ $fuzzyFound = FALSE;
// Fuzzy look on match if already found
foreach ($matchesFound as $found => $set) {
if ($test == $match) {
// Match found
//* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'fuzzyFound!');
- $fuzzyFound = true;
+ $fuzzyFound = TRUE;
break;
} // END - if
} // END - foreach
// Skip this entry?
- if ($fuzzyFound === true) {
+ if ($fuzzyFound === TRUE) {
continue;
} // END - if
$newMatch = str_replace(array('[', ']', '$'), array("['", "']", '{COMPILE_DOLLAR}'), $match);
$code = str_replace($match, '".' . $newMatch . '."', $code);
$matchesFound[$key . '_' . $matches[3][$key]] = 1;
- $matchesFound[$match] = true;
+ $matchesFound[$match] = TRUE;
} elseif (!isset($matchesFound[$match])) {
// Not yet replaced!
//* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'match=' . $match);
}
// Insert the code in $img_code into jpeg or PNG image
-function generateImageOrCode ($img_code, $headerSent = true) {
+function generateImageOrCode ($img_code, $headerSent = TRUE) {
// Is the code size oversized or shouldn't we display it?
if ((strlen($img_code) > 6) || (empty($img_code)) || (getCodeLength() == '0')) {
// Stop execution of function here because of over-sized code length
reportBug(__FUNCTION__, __LINE__, 'img_code ' . $img_code .' has invalid length. img_code(length)=' . strlen($img_code) . ' code_length=' . getCodeLength());
- } elseif ($headerSent === false) {
+ } elseif ($headerSent === FALSE) {
// Return an HTML code here
return '<img src="{%url=img.php?code=' . $img_code . '%}" alt="Image" />';
}
}
// Create selection box or array of splitted timestamp
-function createTimeSelections ($timestamp, $prefix = '', $display = '', $align = 'center', $asArray = false) {
+function createTimeSelections ($timestamp, $prefix = '', $display = '', $align = 'center', $asArray = FALSE) {
// Do not continue if ONE_DAY is absend
if (!isConfigEntrySet('ONE_DAY')) {
// Abort here
$stamp = round($timestamp);
//* DEBUG: */ debugOutput('*' . $stamp .'/' . $timestamp . '*');
- // Do we have a leap year?
+ // Is there a leap year?
$SWITCH = '0';
$TEST = getYear() / 4;
$M1 = getMonth();
//
// Now we convert them in seconds...
//
- if ($asArray === true) {
+ if ($asArray === TRUE) {
// Just put all data in an array for later use
$OUT = array(
'Y' => $Y,
} // END - if
// Define all main targets
- $targetArray = array('del_user', 'edit_user', 'lock_user', 'add_points', 'sub_points');
+ $targetArray = runFilterChain('member_admin_actions', array('del_user', 'edit_user', 'lock_user', 'list_refs', 'list_links', 'add_points', 'sub_points'));
// Get user status
$status = getFetchedUserData('userid', $userid, 'status');
// Begin of navigation links
$OUT = '[';
- foreach ($targetArray as $tar) {
- $OUT .= '<span class="admin_user_link"><a href="{%url=modules.php?module=admin&what=' . $tar . '&userid=' . $userid . '%}" title="{--ADMIN_USER_ACTION_LINK_';
- //* DEBUG: */ debugOutput('*' . $tar.'/' . $status.'*');
- if (($tar == 'lock_user') && ($status == 'LOCKED')) {
+ foreach ($targetArray as $target) {
+ $OUT .= '<span class="admin_user_link"><a href="{%url=modules.php?module=admin&what=' . $target . '&userid=' . $userid . '%}" title="{--ADMIN_USER_ACTION_LINK_';
+ //* DEBUG: */ debugOutput('*' . $target.'/' . $status.'*');
+ if (($target == 'lock_user') && ($status == 'LOCKED')) {
// Locked accounts shall be unlocked
$OUT .= 'UNLOCK_USER';
- } elseif ($tar == 'del_user') {
+ } elseif ($target == 'del_user') {
// @TODO Deprecate this thing
$OUT .= 'DELETE_USER';
} else {
// All other status is fine
- $OUT .= strtoupper($tar);
+ $OUT .= strtoupper($target);
}
$OUT .= '_TITLE--}">{--ADMIN_USER_ACTION_LINK_';
- if (($tar == 'lock_user') && ($status == 'LOCKED')) {
+ if (($target == 'lock_user') && ($status == 'LOCKED')) {
// Locked accounts shall be unlocked
$OUT .= 'UNLOCK_USER';
- } elseif ($tar == 'del_user') {
+ } elseif ($target == 'del_user') {
// @TODO Deprecate this thing
$OUT .= 'DELETE_USER';
} else {
// All other status is fine
- $OUT .= strtoupper($tar);
+ $OUT .= strtoupper($target);
}
$OUT .= '--}</a></span>|';
} // END - foreach
} // END - if
// Make sure, that the script realy realy diese here and now
- $GLOBALS['app_died'] = true;
+ $GLOBALS['app_died'] = TRUE;
// Set content type as text/html
setContentType('text/html');
);
// Load the message template
- loadTemplate('app_die_message', false, $message);
+ loadTemplate('app_exit_message', FALSE, $message);
// Load footer
loadIncludeOnce('inc/footer.php');
// Is the timer started?
if (!isset($GLOBALS['__start_time'])) {
// Abort here
- return false;
+ return FALSE;
} // END - if
// Get end time
- $endTime = microtime(true);
+ $endTime = microtime(TRUE);
// "Explode" both times
$start = explode(' ', $GLOBALS['__start_time']);
);
// Load the template
- $GLOBALS['__page_footer'] .= loadTemplate('show_timings', true, $content);
+ $GLOBALS['__page_footer'] .= loadTemplate('show_timings', TRUE, $content);
}
/**
* @param $sendEmail Wether to send an email to all configured administrators
* @return void
*/
-function reportBug ($F, $L, $message = '', $sendEmail = true) {
+function reportBug ($F, $L, $message = '', $sendEmail = TRUE) {
// Is this already called?
if (isset($GLOBALS[__FUNCTION__])) {
// Other backtrace
setHttpStatus('500 Internal Server Error');
// Mark this function as called
- $GLOBALS[__FUNCTION__] = true;
+ $GLOBALS[__FUNCTION__] = TRUE;
// Init message
$debug = '';
} // END - if
// Add output
- $debug .= 'Please report this bug at <a title="Direct link to the bug-tracker" href="http://bugs.mxchange.org" rel="external" target="_blank">http://bugs.mxchange.org</a> and include the logfile from <strong>' . str_replace(getPath(), '', getCachePath()) . 'debug.log</strong> in your report (you can now attach files):<pre>';
+ $debug .= 'Please report this bug at <a title="Direct link to the bug-tracker" href="http://bugs.mxchange.org" rel="external" target="_blank">http://bugs.mxchange.org</a> and include this whole message + logfile from <strong>' . str_replace(getPath(), '', getCachePath()) . 'debug.log</strong> in your report (you can now attach files).<br />Backtrace:<pre>';
$debug .= debug_get_printable_backtrace();
$debug .= '</pre>';
$debug .= '<div class="para">Request-URI: ' . getRequestUri() . '</div>';
$debug .= '<div class="para">Thank you for finding bugs.</div>';
// Send an email? (e.g. not wanted for evaluation errors)
- if (($sendEmail === true) && (!isInstallationPhase())) {
+ if (($sendEmail === TRUE) && (!isInstallationPhase())) {
// Prepare content
$content = array(
'message' => trim($message),
sendAdminNotification('{--REPORT_BUG_SUBJECT--}', 'admin_report_bug', $content);
} // END - if
- // Do we have HTML/CSS/AJAX mode?
+ // Is there HTML/CSS/AJAX mode?
if ((isHtmlOutputMode()) || (isCssOutputMode()) || (isAjaxOutputMode())) {
// And abort here
app_exit($F, $L, $debug);
}
// Compile characters which are allowed in URLs
-function compileUriCode ($code, $simple = true) {
+function compileUriCode ($code, $simple = TRUE) {
// Trim code
$test = trim($code);
);
// Compile constants
- if ($simple === false) {
+ if ($simple === FALSE) {
// Add more 'from'
- array_push($charsCompile['from'], '{--', '--}');
+ array_unshift($charsCompile['from'], '{--', '--}');
// Add more 'to'
- array_push($charsCompile['to'], '".', '."');
+ array_unshift($charsCompile['to'], '".', '."');
} // END - if
// Compile QUOT and other non-HTML codes
$code = str_replace($charsCompile['from'], $charsCompile['to'], $code);
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code=' . $code);
// Return compiled code
return $code;
$message = getMessageFromErrorCode(getRequestElement('code'));
// Load message template
- loadTemplate('message', false, $message);
+ loadTemplate('message', FALSE, $message);
} // END - if
}
// Is the extension not installed or just deactivated?
switch (isExtensionInstalled($ext_name)) {
- case true; // Deactivated!
+ case TRUE; // Deactivated!
$message = generateExtensionInactiveMessage($ext_name);
break;
- case false; // Not installed!
+ case FALSE; // Not installed!
$message = generateExtensionNotInstalledMessage($ext_name);
break;
if (!is_array($code)) {
// We need an array, so try it with the new-line character
- $codeE = explode(chr(10), $code);
+ $codeE = explode(PHP_EOL, $code);
} // END - if
$count_lines = count($codeE);
$pageTitle .= '{%config,trim=title_left%} ';
} // END - if
- // Do we have some extra title?
+ // Is there an extra title?
if (isExtraTitleSet()) {
// Then prepend it
$pageTitle .= '{%pipe,getExtraTitle%} by ';
}
// Checks whethere there is a cache file there. This function is cached.
-function isTemplateCached ($template) {
- // Do we have cached this result?
- if (!isset($GLOBALS['template_cache'][$template])) {
+function isTemplateCached ($prefix, $template) {
+ // Is there cached this result?
+ if (!isset($GLOBALS['template_cache'][$prefix][$template])) {
// Generate FQFN
- $FQFN = generateCacheFqfn($template);
+ $FQFN = generateCacheFqfn($prefix, $template);
// Is it there?
- $GLOBALS['template_cache'][$template] = isFileReadable($FQFN);
+ $GLOBALS['template_cache'][$prefix][$template] = isFileReadable($FQFN);
} // END - if
// Return it
- return $GLOBALS['template_cache'][$template];
+ return $GLOBALS['template_cache'][$prefix][$template];
}
// Flushes non-flushed template cache to disk
-function flushTemplateCache ($template, $eval) {
+function flushTemplateCache ($prefix, $template, $eval) {
// Is this cache flushed?
- if ((isDebuggingTemplateCache() === false) && (isTemplateCached($template) === false) && ($eval != '404')) {
+ if ((isDebuggingTemplateCache() === FALSE) && (isTemplateCached($prefix, $template) === FALSE) && ($eval != '404')) {
// Generate FQFN
- $FQFN = generateCacheFqfn($template);
+ $FQFN = generateCacheFqfn($prefix, $template);
+
+ // Is this a XML template?
+ if ($prefix == 'xml') {
+ // Compact only XML templates as emails needs new-line characters and HTML may contain required "comments"
+ $eval = compactContent($eval);
+ } // END - if
// And flush it
- writeToFile($FQFN, $eval, true);
+ writeToFile($FQFN, $eval, TRUE);
} // END - if
}
// Reads a template cache
-function readTemplateCache ($template) {
+function readTemplateCache ($prefix, $template) {
// Check it again
- if ((isDebuggingTemplateCache()) || (!isTemplateCached($template))) {
+ if ((isDebuggingTemplateCache()) || (!isTemplateCached($prefix, $template))) {
// This should not happen
reportBug('Wether debugging of template cache is enabled or template ' . $template . ' is not cached while expected.');
} // END - if
// Is it cached?
- if (!isset($GLOBALS['template_eval'][$template])) {
+ if (!isset($GLOBALS['template_eval'][$prefix][$template])) {
// Generate FQFN
- $FQFN = generateCacheFqfn($template);
+ $FQFN = generateCacheFqfn($prefix, $template);
// And read from it
- $GLOBALS['template_eval'][$template] = readFromFile($FQFN);
+ $GLOBALS['template_eval'][$prefix][$template] = readFromFile($FQFN);
} // END - if
// And return it
- return $GLOBALS['template_eval'][$template];
+ return $GLOBALS['template_eval'][$prefix][$template];
}
// Escapes quotes (default is only double-quotes)
-function escapeQuotes ($str, $single = false) {
+function escapeQuotes ($str, $single = FALSE) {
// Should we escape all?
- if ($single === true) {
+ if ($single === TRUE) {
// Escape all (including null)
$str = addslashes($str);
} else {
$str = str_replace(array("\\'", '"', "\\\\"), array(chr(39), "\\\"", chr(92)), $str);
}
- // Return the escaped string
+ // Return the escape'd string
return $str;
}
switch ($mode) {
case 'normal': break; // Do not add any special lines
case 'email': // Email was changed!
- $content['message'] = '{--MEMBER_CHANGED_EMAIL--}' . ': ' . postRequestElement('old_email') . chr(10);
+ $content['message'] = '{--MEMBER_CHANGED_EMAIL--}' . ': ' . postRequestElement('old_email') . PHP_EOL;
break;
case 'password': // Password was changed
- $content['message'] = '{--MEMBER_CHANGED_PASS--}' . chr(10);
+ $content['message'] = '{--MEMBER_CHANGED_PASS--}' . PHP_EOL;
break;
default:
logDebugMessage(__FUNCTION__, __LINE__, sprintf("Unknown mode %s detected.", $mode));
- $content['message'] = '{--MEMBER_UNKNOWN_MODE--}' . ': ' . $mode . "\n\n";
+ $content['message'] = '{--MEMBER_UNKNOWN_MODE--}' . ': ' . $mode . PHP_EOL . PHP_EOL;
break;
} // END - switch
} // END - foreach
}
// Generates a 'selection box' from given array
-function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionContent = '', $extraName = '', $templateName = '', $default = NULL, $nameElement = '', $allowNone = false, $useDefaultAsArray = false) {
+function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionContent = '', $extraName = '', $templateName = '', $default = NULL, $nameElement = '', $allowNone = FALSE, $useDefaultAsArray = FALSE) {
// Default is empty
$addKey = '';
// Use default value as array key?
- if ($useDefaultAsArray === true) {
+ if ($useDefaultAsArray === TRUE) {
// Then set it
$addKey = '[' . convertNullToZero($default) . ']';
} // END - if
<option value="X" disabled="disabled">{--PLEASE_SELECT--}</option>';
// Allow none?
- if ($allowNone === true) {
+ if ($allowNone === TRUE) {
// Then add it
$OUT .= '<option value="0">{--SELECT_NONE--}</option>';
} // END - if
// Is a template name given?
if (empty($templateName)) {
// ... $name template
- $OUT .= loadTemplate('select_' . $name . $extraName . '_option', true, $option);
+ $OUT .= loadTemplate('select_' . $name . $extraName . '_option', TRUE, $option);
} else {
// ... $templateName template
- $OUT .= loadTemplate('select_' . $templateName . $extraName . '_option', true, $option);
+ $OUT .= loadTemplate('select_' . $templateName . $extraName . '_option', TRUE, $option);
}
} else {
// ... direct HTML code
// Load template and return it
if (empty($templateName)) {
// Use name from $name + $extraName
- return loadTemplate('select_' . $name . $extraName . '_box', true, $content);
+ return loadTemplate('select_' . $name . $extraName . '_box', TRUE, $content);
} else {
// Use name from $templateName + $extraName
- return loadTemplate('select_' . $templateName . $extraName . '_box', true, $content);
+ return loadTemplate('select_' . $templateName . $extraName . '_box', TRUE, $content);
}
}
// Generates meta description for current module and 'what' value
function generateMetaDescriptionCode () {
- // Only include from guest area and if sql_patches has correct version
+ // Only include from guest area and if ext-sql_patches has correct version
if ((getModule() == 'index') && (isExtensionInstalledAndNewer('sql_patches', '0.1.6'))) {
// Output it directly
$GLOBALS['__page_header'] .= '<meta name="description" content="' . '{?MAIN_TITLE?} ' . trim(getConfig('title_middle')) . ' ' . getTitleFromMenu('guest', getWhat()) . '" />';
}
// Generates an FQFN for template cache from the given template name
-function generateCacheFqfn ($template, $mode = 'html') {
+function generateCacheFqfn ($prefix, $template) {
// Is this cached?
- if (!isset($GLOBALS['template_cache_fqfn'][$template])) {
+ if (!isset($GLOBALS['template_cache_fqfn'][$prefix][$template])) {
// Generate the FQFN
- $GLOBALS['template_cache_fqfn'][$template] = sprintf(
+ $GLOBALS['template_cache_fqfn'][$prefix][$template] = sprintf(
"%s_compiled/%s/%s.tpl.cache",
getCachePath(),
- $mode,
+ $prefix,
$template
);
} // END - if
// Return it
- return $GLOBALS['template_cache_fqfn'][$template];
+ return $GLOBALS['template_cache_fqfn'][$prefix][$template];
}
// "Fixes" null or empty string to count of dashes
}
// Displays given message in admin_settings_saved template
-function displayMessage ($message, $return = false) {
+function displayMessage ($message, $return = FALSE) {
// Load the template
return loadTemplate('admin_settings_saved', $return, $message);
}
// Function to add style tag (whether display:none/block)
function addStyleMenuContent ($menuMode, $mainAction, $action) {
- // Do we have foo_menu_javascript enabled?
+ // Is there foo_menu_javascript enabled?
if ((!isConfigEntrySet($menuMode . '_menu_javascript')) || (getConfig($menuMode . '_menu_javascript') == 'N')) {
// Silently abort here, not enabled
return '';
// Function to add onclick attribute
function addJavaScriptMenuContent ($menuMode, $mainAction, $action, $what) {
- // Do we have foo_menu_javascript enabled?
+ // Is there foo_menu_javascript enabled?
if ((!isConfigEntrySet($menuMode . '_menu_javascript')) || (getConfig($menuMode . '_menu_javascript') == 'N')) {
// Silently abort here, not enabled
return '';
//-----------------------------------------------------------------------------
// Color-switch helper function
-function doTemplateColorSwitch ($templateName, $clear = false, $return = true) {
+function doTemplateColorSwitch ($templateName, $clear = FALSE, $return = TRUE) {
// Is it there?
if (!isset($GLOBALS['color_switch'][$templateName])) {
// Initialize it
initTemplateColorSwitch($templateName);
- } elseif ($clear === false) {
+ } elseif ($clear === FALSE) {
// Switch color if called from loadTemplate()
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'SWITCH:' . $templateName);
$GLOBALS['color_switch'][$templateName] = 3 - $GLOBALS['color_switch'][$templateName];
}
// Return CSS class name
- if ($return === true) {
+ if ($return === TRUE) {
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'RETURN:' . $templateName . '=' . $GLOBALS['color_switch'][$templateName]);
return 'switch_sw' . $GLOBALS['color_switch'][$templateName];
} // END - if
$OUT = '<span title="{--ADMIN_EXTENSION_IS_DEPRECATED_TITLE--}">---</span>';
} elseif (isExtensionProductive($ext_name)) {
// Productive code
- $OUT = '<a title="{--ADMIN_REGISTER_EXTENSION_TITLE--}" href="{%url=modules.php?module=admin&what=extensions&reg_ext=' . $ext_name . '%}">{--ADMIN_REGISTER_EXTENSION--}</a>';
+ $OUT = '<a title="{--ADMIN_REGISTER_EXTENSION_TITLE--}" href="{%url=modules.php?module=admin&what=extensions&register_ext=' . $ext_name . '%}">{--ADMIN_REGISTER_EXTENSION--}</a>';
}
// Return code
}
// Template helper function to create selection box for "locked points mode"
-function doTemplatePointsLockedModeSelectionBox ($templateName, $clear = false, $default = NULL) {
+function doTemplatePointsLockedModeSelectionBox ($templateName, $clear = FALSE, $default = NULL) {
// Init array
$lockedModes = array(
0 => array('mode' => 'LOCKED'),
}
// Template helper function to create selection box for payment method
-function doTemplatePointsPaymentMethodSelectionBox ($templateName, $clear = false, $default = NULL) {
+function doTemplatePointsPaymentMethodSelectionBox ($templateName, $clear = FALSE, $default = NULL) {
// Init array
$paymentMethods = array(
0 => array('method' => 'DIRECT'),
return $content;
}
+// Template helper function to create a deferrer code if URL is not empty
+function doTemplateDereferrerUrl ($templateName, $clear = FALSE, $url = NULL) {
+ // Is the URL not NULL and not empty?
+ if ((!is_null($url)) && (!empty($url))) {
+ // Set HTML with EL code
+ $url = '<a href="{%pipe,generateDereferrerUrl=' . $url . '%}" rel="external" target="_blank">{--ADMIN_TEST_URL--}</a>';
+ } // END - if
+
+ // Return URL (or content) or dashes if empty
+ return fixEmptyContentToDashes($url);
+}
+
+// Tries to anonymize some sensitive data (e.g. IP address, user agent, referrer, etc.)
+function anonymizeSensitiveData ($data) {
+ // Trim it
+ $data = trim($data);
+
+ // Is it empty?
+ if (empty($data)) {
+ // Then add three dashes
+ $data = '---';
+ } elseif (isUrlValid($data)) {
+ // Is a referrer, so is it black-listed?
+ if (isAdmin()) {
+ // Is admin, has always priority
+ $data = '[<a href="{%pipe,generateFrametesterUrl=' . $data . '%}" target="_blank">{--ADMIN_TEST_URL--}</a>]';
+ } elseif (isUrlBlacklisted($data)) {
+ // Yes, so replace it with text
+ $data = '<em>{--URL_IS_BLACKLISTED--}</em>';
+ } else {
+ // A member is viewing this referral URL
+ $data = '[<a href="{%pipe,generateDereferrerUrl=' . $data . '%}" target="_blank">{--MEMBER_TEST_URL--}</a>]';
+ }
+ } elseif (isIp4AddressValid($data)) {
+ // Is an IPv4 address
+ $ipArray = explode('.', $data);
+
+ // Only display first 2 octets
+ $data = $ipArray[0] . '.' . $ipArray[1] . '.?.?';
+ } else {
+ // Generic data
+ $data = '<em>{--DATA_IS_HIDDEN--}</em>';
+ }
+
+ // Return it (hopefully) anonymized
+ return $data;
+}
+
+/**
+ * Removes all commentd, tabs and new-line characters to compact the content
+ *
+ * @param $uncompactedContent The uncompacted content
+ * @return $compactedContent The compacted content
+ */
+function compactContent ($uncompactedContent) {
+ // First, remove all tab/new-line/revert characters
+ $compactedContent = str_replace(chr(9), '', str_replace(PHP_EOL, '', str_replace(chr(13), '', $uncompactedContent)));
+
+ // Then regex all comments like <!-- //--> away
+ preg_match_all('/<!--[\w\W]*?(\/\/){0,1}-->/', $compactedContent, $matches);
+
+ // Do we have entries?
+ if (isset($matches[0][0])) {
+ // Remove all
+ foreach ($matches[0] as $match) {
+ // Remove the match
+ $compactedContent = str_replace($match, '', $compactedContent);
+ } // END - foreach
+ } // END - if
+
+ // Set the content again
+ // @TODO Is this needed for e.g. $GLOBALS['template_content'] ? $this->setRawTemplateData($compactedContent);
+
+ // Return compacted content
+ return $compactedContent;
+}
+
// [EOF]
?>