* -------------------------------------------------------------------- *
* Kurzbeschreibung : Template-Funktionen *
* -------------------------------------------------------------------- *
- * $Revision:: $ *
- * $Date:: $ *
- * $Tag:: 0.2.1-FINAL $ *
- * $Author:: $ *
- * -------------------------------------------------------------------- *
* Copyright (c) 2003 - 2009 by Roland Haeder *
- * Copyright (c) 2009 - 2013 by Mailer Developer Team *
+ * Copyright (c) 2009 - 2016 by Mailer Developer Team *
* For more information visit: http://mxchange.org *
* *
* This program is free software; you can redistribute it and/or modify *
// Main compilation loop
function doFinalCompilation ($code, $insertComments = TRUE, $enableCodes = TRUE) {
+ // Code must not be an array (happens in installer)
+ assert(!is_array($code));
+
// Insert comments? (Only valid with HTML templates, of course)
enableTemplateHtml($insertComments);
// Compile it
//* DEBUG: */ debugOutput('<pre>'.lineNumberCode($code).'</pre>');
+ //* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code[]=' . gettype($code) . ',enableCodes[]=' . gettype($enableCodes));
$eval = '$newContent = "' . str_replace('{DQUOTE}', '"', compileCode(escapeQuotes($code), $enableCodes)) . '";';
//* DEBUG: */ if (!$insertComments) print('EVAL=<pre>'.lineNumberCode($eval).'</pre>');
eval($eval);
}
// Init returned content
- $ret = '';
+ $templateContent = '';
// Set current template
$GLOBALS['current_template'] = $template;
} elseif (substr($template, 0, 3) == 'js_') {
// JavaScripts don't like entities, dollar signs and timings
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
- $GLOBALS['template_eval']['html'][$template] = '$templateContent = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), TRUE, $compileCode) . '");';
+ $GLOBALS['template_eval']['html'][$template] = '$templateContent = decodeEntities("' . escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]) . '");';
} elseif (isAjaxOutputMode()) {
// AJAX (JSON content)
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
- $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), TRUE, $compileCode) . '";';
+ $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]) . '";';
} else {
// Prepare eval() command, other output doesn't like entities, maybe
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
} elseif (isAjaxOutputMode()) {
// AJAX (JSON content)
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
- $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), TRUE, $compileCode) . '";';
+ $GLOBALS['template_eval']['html'][$template] = '$templateContent = "' . escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]) . '";';
} else {
// JavaScript again
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Reached!');
- $GLOBALS['template_eval']['html'][$template] = '$templateContent = decodeEntities("' . compileRawCode(escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]), TRUE, $compileCode) . '");';
+ $GLOBALS['template_eval']['html'][$template] = '$templateContent = decodeEntities("' . escapeJavaScriptQuotes($GLOBALS['template_content']['html'][$template]) . '");';
} // END - if
} elseif ((isAdmin()) || ((isInstalling()) && (!isInstalled()))) {
// Only admins shall see this warning or when installation mode is active
// Compiles the code
function compileRawCode ($code, $full = TRUE, $compileCode = TRUE) {
+ //* DIE: */ reportBug(__FUNCTION__, __LINE__, 'Called with ' . strlen($code) . ' code length.');
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Called with code()=' . strlen($code) . ',full=' . intval($full) . ',compileCode=' . intval($compileCode));
+
// Is the code a string or shall we not compile?
if ((!is_string($code)) || ($compileCode === FALSE)) {
// Silently return it
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code[]= ' . gettype($code) . ' is not a string or compileCode(' . intval($compileCode) . ') is FALSE.');
return $code;
} // END - if
$secChars = $GLOBALS['security_chars'];
} // END - if
- // Compile more through a filter
- $code = runFilterChain('compile_code', $code);
-
// First compile these chars
array_unshift($secChars['to'] , '{--' , '--}');
array_unshift($secChars['from'], '{%message,', '%}' );
- // Compile QUOT and other non-HTML codes
+ // Replace QUOT and other non-HTML codes
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code()=' . strlen($code) . ' - before str_replace() ...');
$code = str_replace($secChars['to'], $secChars['from'], $code);
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code()=' . strlen($code) . ' - after str_replace() ...');
+
+ // Compile the prepared code through a filter chain
+ $code = runFilterChain('compile_code', $code);
- // Find $content[bla][blub] entries
+ // Find all $content[bla][blub] entries
preg_match_all('/\$content((\[([a-zA-Z0-9-_]+)\])*)/', $code, $matches);
//* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Second regex gave ' . count($matches[0]) . ' matches.');
} // END - if
} // END - if
- // Replace {COMPILE_DOLLAR} back to dollar sign
- $code = str_replace('{COMPILE_DOLLAR}', '$', $code);
+ // Add 'COMPILE_DOLLAR' again
+ array_push($secChars['to'] , '{COMPILE_DOLLAR}');
+ array_push($secChars['from'], '$');
+
+ // Replace QUOT and other non-HTML codes
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code()=' . strlen($code) . ' - before str_replace() ...');
+ $code = str_replace($secChars['to'], $secChars['from'], $code);
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'code()=' . strlen($code) . ' - after str_replace() ...');
// Finally return it
+ //* NOISY-DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'Exiting with code()=' . strlen($code));
return $code;
}
//
-function addSelectionBox ($type, $default, $prefix = '', $id = NULL, $class = 'form_select') {
+function addSelectionBox ($type, $default, $prefix = '', $id = NULL, $class = 'form_select', $allSteps = FALSE) {
$OUT = '';
if ($type == 'yn') {
case 'ho': // Hours
for ($idx = 0; $idx <= 23; $idx++) {
- $padded = padLeftZero($idx);
+ $padded = padLeftZero($idx, 2);
$OUT .= '<option value="' . $padded . '"';
if ($default == $padded) $OUT .= ' selected="selected"';
$OUT .= '>' . $padded . '</option>';
case 'mi': // Minutes
case 'se': // Seconds
- for ($idx = 0; $idx <= 59; $idx+=5) {
- $padded = padLeftZero($idx);
+ // Default is 5 minutes/seconds step
+ $step = 5;
+
+ // All steps?
+ if ($allSteps === TRUE) {
+ // Then all steps
+ $step = 1;
+ } // END - if
+
+ for ($idx = 0; $idx <= 59; $idx += $step) {
+ $padded = padLeftZero($idx, 2);
$OUT .= '<option value="' . $padded . '"';
if ($default == $padded) $OUT .= ' selected="selected"';
$OUT .= '>' . $padded . '</option>';
}
// 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, $allSteps = FALSE) {
// Do not continue if ONE_DAY is absend
if (!isConfigEntrySet('ONE_DAY')) {
// Abort here
if (isInString($unit, $display) || (empty($display))) {
// Generate year selection
$OUT .= '<td align="center">';
- $OUT .= addSelectionBox($field, $data[$unit], $prefix, NULL, 'mini_select');
+ $OUT .= addSelectionBox($field, $data[$unit], $prefix, NULL, 'mini_select', $allSteps);
$OUT .= '</td>';
} else {
$OUT .= '<input type="hidden" name="' . $prefix . '_' . $field . '" value="0" />';
}
// Load header
- loadIncludeOnce('inc/header.php');
+ loadPageHeader();
// Rewrite message for output
$message = sprintf(
$OUT = loadTemplate('ajax_app_exit_message', TRUE, $message);
// Output it as JSON encoded
- outputHtml(encodeJson(array('reply_content' => urlencode(doFinalCompilation($OUT)))));
+ outputHtml(encodeJson(array('reply_content' => urlencode(doFinalCompilation(compileRawCode($OUT))))));
} else {
// Load the message template
loadTemplate('app_exit_message', FALSE, $message);
}
// Load footer
- loadIncludeOnce('inc/footer.php');
+ loadPageFooter();
}
// Display parsing time and number of SQL queries in footer
} // END - if
// Is there HTML/CSS/AJAX mode while debug-mode is enabled?
- if ((isDebugModeEnabled()) && ((isHtmlOutputMode()) || (isCssOutputMode()) || (isAjaxOutputMode()))) {
+ if (((isDebugModeEnabled()) || (isInstaller())) && ((isHtmlOutputMode()) || (isCssOutputMode()) || (isAjaxOutputMode()))) {
// And abort here
app_exit($file, $line, $debug);
} elseif (isAjaxOutputMode()) {
sendAjaxContent(TRUE);
// Include footer
- loadIncludeOnce('inc/footer.php');
+ loadPageFooter();
} else {
// Raw/image output mode and all other modes doesn't work well with text ...
die();
break;
default: // Should not happen!
- logDebugMessage(__FUNCTION__, __LINE__, sprintf("Invalid state of extension %s detected.", $ext_name));
- $message = sprintf("Invalid state of extension %s detected.", $ext_name);
+ logDebugMessage(__FUNCTION__, __LINE__, sprintf('Invalid state of extension %s detected.', $ext_name));
+ $message = sprintf('Invalid state of extension %s detected.', $ext_name);
break;
} // END - switch
// Generates a 'selection box' from given array
function generateSelectionBoxFromArray ($options, $name, $optionKey, $optionContent = '', $extraName = '', $templateName = '', $default = NULL, $nameElement = '', $allowNone = FALSE, $useDefaultAsArray = FALSE) {
+ // options must be an array
+ assert(is_array($options));
+
// Default is empty
$addKey = '';
// Allow none?
if ($allowNone === TRUE) {
// Then add it
- $OUT .= '<option value="0">{--SELECT_NONE--}</option>';
+ $OUT .= '<option value="">{--SELECT_NONE--}</option>';
} // END - if
// Walk through all options
//* DEBUG: */ logDebugMessage(__FUNCTION__, __LINE__, 'name=' . $name . ',default[' . gettype($default) . ']=' . $default . ',optionKey[' . gettype($optionKey) . ']=' . $optionKey);
// Is default value same as given value?
- if ((!is_null($default)) && (isset($option[$optionKey])) && ($default == $option[$optionKey])) {
+ if ((!is_null($default)) && (isset($option[$optionKey])) && ($default === $option[$optionKey])) {
// Then set default
$option['default'] = ' selected="selected"';
} // END - if
if (!isset($GLOBALS['template_cache_fqfn'][$prefix][$template])) {
// Generate the FQFN
$GLOBALS['template_cache_fqfn'][$prefix][$template] = sprintf(
- '%s_compiled/%s/%s.tpl.cache',
+ '%s%s_compiled/%s/%s%s',
+ getPath(),
getCachePath(),
$prefix,
- $template
+ $template,
+ getCacheExtension()
);
} // END - if
}
// Displays given message in admin_settings_saved template
-function displayMessage ($message, $return = FALSE) {
+function displayMessage ($message) {
+ // Call inner function
+ outputHtml(returnMessage($message));
+}
+
+// Returns given message in admin_settings_saved template
+function returnMessage ($message) {
+ // Load the template
+ return loadTemplate('admin_settings_saved', TRUE, $message);
+}
+
+// Displays given error message in admin_settings_unsaved template
+function displayErrorMessage ($message) {
// Load the template
- return loadTemplate('admin_settings_saved', $return, $message);
+ outputHtml(returnErrorMessage($message));
}
-// Displays given error message in admin_settings_saved template
-function displayErrorMessage ($message, $return = FALSE) {
+// Displays given error message in admin_settings_unsaved template
+function returnErrorMessage ($message) {
// Load the template
- return loadTemplate('admin_settings_unsaved', $return, $message);
+ return loadTemplate('admin_settings_unsaved', TRUE, $message);
}
// Generates a selection box for (maybe) given gender
return $out;
}
+// Helper function to display referral id or hide it depending on settings
+function doTemplateDisplayReferralIdContent ($template, $clear = FALSE) {
+ // Ddisplay the refid or make it editable?
+ if (isDisplayRefidEnabled()) {
+ // Load "hide" form template
+ $out = loadTemplate('guest_register_refid_hide', TRUE);
+ } else {
+ // Load template to enter it
+ $out = loadTemplate('guest_register_refid', TRUE);
+ }
+
+ // Return code
+ return $out;
+}
+
// "Getter" for template base path
function getTemplateBasePath ($part) {
// Is there cache?
return $GLOBALS[__FUNCTION__][$part];
}
+// Removes comments with @DEPRECATED
+function removeDeprecatedComment ($output) {
+ // Explode it into pieces ... ;)
+ $lines = explode(chr(10), $output);
+
+ // Walk through all
+ $return = '';
+ foreach ($lines as $line) {
+ // Is there a @DEPRECATED?
+ if (isInString('@DEPRECATED', $line)) {
+ // Ignore this line
+ continue;
+ } // END - if
+
+ // Add it
+ $return .= $line . chr(13);
+ } // END - foreach
+
+ // Returned cleaned content
+ return $return;
+}
+
+// Generates a selection box suitable for e.g. birthdays: day, month and year
+function generateDayMonthYearSelectionBox ($day, $month, $year) {
+ // This depends on selected language
+ switch (getLanguage()) {
+ case 'de': // German date format
+ $content = addSelectionBox('da', $day) . addSelectionBox('mo', $month) . addSelectionBox('ye', $year);
+ break;
+
+ default: // Default is the US date format... :)
+ $content = addSelectionBox('mo', $month) . addSelectionBox('da', $day) . addSelectionBox('ye', $year);
+ break;
+ } // END - switch
+
+ // Return content
+ return $content;
+}
+
+// Loads page header
+function loadPageHeader () {
+ // Init header
+ $GLOBALS['__page_header'] = '';
+
+ // Is the header already sent?
+ if (($GLOBALS['__header_sent'] != 1) && ($GLOBALS['__header_sent'] != 2)) {
+ // Set default HTTP status to "200 OK"
+ setHttpStatus('200 OK');
+
+ // If not in CSS mode generate the header
+ if ((!isCssOutputMode()) && (!isAjaxOutputMode()) && (!isImageOutputMode())) {
+ // Prepare the header for HTML output
+ loadHtmlHeader();
+ } // END - if
+
+ // Closing HEAD tag
+ if ($GLOBALS['__header_sent'] == '0') {
+ $GLOBALS['__header_sent'] = 1;
+ } // END - if
+ } // END - if
+
+ // Add BODY tag or not?
+ // @TODO Find a way to not use direct module comparison
+ if ((!isCssOutputMode()) && (!isRawOutputMode()) && ($GLOBALS['__header_sent'] == 1) && (getModule() != 'frametester') && (!isFramesetModeEnabled())) {
+ loadTemplate('page_body');
+ $GLOBALS['__header_sent'] = 2;
+ } // END - if
+}
+
+// Loads page footer and calls doShutdown()
+function loadPageFooter () {
+ // Init page footer
+ $GLOBALS['__page_footer'] = '';
+
+ // Footer disabled (e.g. CSS/AJAX/image output) or already sent?
+ // 1234 5 54 45 5 5 543 3 443 3 443 3 44321
+ if ((((!isset($GLOBALS['__footer_sent'])) || (($GLOBALS['__footer_sent'] != 1) && ($GLOBALS['__footer_sent'] != 2))) && (!isCssOutputMode()) && (!isAjaxOutputMode()) && (!isImageOutputMode()))) {
+ // Run the filter, sweet huh?
+ runFilterChain('page_footer');
+
+ // Load page footer
+ $GLOBALS['__page_footer'] .= loadTemplate('page_footer', TRUE);
+ } // END - if
+
+ // Footer has been reached
+ $GLOBALS['__footer_sent'] = 1;
+
+ // Shutdown
+ doShutdown();
+}
+
// [EOF]
?>