From 9642d17a028f3e7fdc57fa12e5dbd7129f166816 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Roland=20H=C3=A4der?= <roland@mxchange.org>
Date: Sun, 6 Jun 2010 16:04:47 +0000
Subject: [PATCH] Old-lost eval() removed, rewrite-functions must be called
 after compilation and before compression

---
 inc/functions.php              | 15 +++++----------
 inc/libs/rewrite_functions.php | 28 ++++++++++++----------------
 2 files changed, 17 insertions(+), 26 deletions(-)

diff --git a/inc/functions.php b/inc/functions.php
index 7b9e64ad5b..6e3cda3de9 100644
--- a/inc/functions.php
+++ b/inc/functions.php
@@ -97,11 +97,6 @@ function outputHtml ($htmlCode, $newLine = true) {
 			clearOutputBuffer();
 		} // END - if
 
-		// Extension 'rewrite' installed?
-		if ((isExtensionActive('rewrite')) && (getOutputMode() != 1)) {
-			$GLOBALS['output'] = rewriteLinksInCode($GLOBALS['output']);
-		} // END - if
-
 		// Send all HTTP headers
 		sendHttpHeaders();
 
@@ -111,11 +106,6 @@ function outputHtml ($htmlCode, $newLine = true) {
 		// Output code here, DO NOT REMOVE! ;-)
 		outputRawCode($GLOBALS['output']);
 	} elseif ((getConfig('OUTPUT_MODE') == 'render') && (!empty($GLOBALS['output']))) {
-		// Rewrite links when rewrite extension is active
-		if ((isExtensionActive('rewrite')) && (getOutputMode() != 1)) {
-			$GLOBALS['output'] = rewriteLinksInCode($GLOBALS['output']);
-		} // END - if
-
 		// Send all HTTP headers
 		sendHttpHeaders();
 
@@ -182,6 +172,11 @@ function compileFinalOutput () {
 		$cnt++;
 	} // END - while
 
+	// Extension 'rewrite' installed?
+	if ((isExtensionActive('rewrite')) && (getOutputMode() != 1)) {
+		$GLOBALS['output'] = rewriteLinksInCode($GLOBALS['output']);
+	} // END - if
+
 	// Compress it?
 	if (!empty($_SERVER['HTTP_ACCEPT_ENCODING']) && (strpos('gzip', $_SERVER['HTTP_ACCEPT_ENCODING']) !== null)) {
 		// Compress it for HTTP gzip
diff --git a/inc/libs/rewrite_functions.php b/inc/libs/rewrite_functions.php
index 5b76d5a1b3..bf041ab195 100644
--- a/inc/libs/rewrite_functions.php
+++ b/inc/libs/rewrite_functions.php
@@ -43,29 +43,25 @@ if (!defined('__SECURITY')) {
 }
 
 // Rewrite links in HTML for better SEO (ugly part of mx!)
-function rewriteLinksInCode ($HTML) {
+function rewriteLinksInCode ($code) {
 	// Skip rewriting for configured modules
-	if (isInStringIgnoreCase(getModule(), getConfig('rewrite_skip')) !== false) return $HTML;
+	if (isInStringIgnoreCase(getModule(), getConfig('rewrite_skip')) !== false) return $code;
 
 	// Generate target URL
-	$target = '{?URL?}/cms/';
-
-	// Final eval()
-	$eval = '$output = "' . preCompileCode(escapeQuotes($HTML)) . '";';
-	eval($eval);
+	$target = getConfig('URL') . '/cms/';
 
 	// Convert modules.php?module=...
 	foreach (array(getConfig('URL'), '{?URL?}') as $rewrite) {
-		$output = str_replace($rewrite . '/modules.php?module=', $target, $output);
+		$code = str_replace($rewrite . '/modules.php?module=', $target, $code);
 	} // END - foreach
 
 	// Do we have an URL linked to mxchange.org?
-	if (isInStringIgnoreCase(getConfig('SERVER_URL'), $output)) {
+	if (isInStringIgnoreCase(getConfig('SERVER_URL'), $code)) {
 		// Convert URLs from my server
-		$output = str_replace('{?URL?}/modules.php?module=', getConfig('SERVER_URL') . '/cms/', $output);
+		$code = str_replace('{?URL?}/modules.php?module=', getConfig('SERVER_URL') . '/cms/', $code);
 
 		// Convert URLs from my server
-		$output = str_replace(getConfig('URL') . '/modules.php?module=', getConfig('SERVER_URL') . '/cms/', $output);
+		$code = str_replace(getConfig('URL') . '/modules.php?module=', getConfig('SERVER_URL') . '/cms/', $code);
 	} // END - if
 
 	// Strip slashes as above for the main URL
@@ -75,19 +71,19 @@ function rewriteLinksInCode ($HTML) {
 	$action = $target . '$1/act/';
 
 	// Convert &amp;|&action=...
-	$output = preg_replace('/' . $target2 . '(.*)&amp;action=/i', $action, $output);
+	$code = preg_replace('/' . $target2 . '(.*)&amp;action=/i', $action, $code);
 
 	// "The same procedure as last variable"... now for &amp;what=
 	$what = $target . '$1/wht/';
-	$output = preg_replace('/' . $target2 . '(.*)&amp;what=/i', $what, $output);
+	$code = preg_replace('/' . $target2 . '(.*)&amp;what=/i', $what, $code);
 
 	// Repair missed &amp;what=??? entries
-	while (preg_match("/&amp;what=(.*)\/(.*)\/(.*)/i", $output)) {
-		$output = preg_replace("/&amp;what=(.*)\/(.*)\/(.*)/i", "/wht/\$1/\$2/\$3", $output);
+	while (preg_match("/&amp;what=(.*)\/(.*)\/(.*)/i", $code)) {
+		$code = preg_replace("/&amp;what=(.*)\/(.*)\/(.*)/i", "/wht/\$1/\$2/\$3", $code);
 	} // END - while
 
 	// Return rewritten code
-	return $output;
+	return $code;
 }
 
 // [EOF]
-- 
2.39.5