public function smartyOutputfilterAddURLPrefixAndStripWhitespace($source, $smarty) { // rewrite urls for the device classifier in case our root is not / // also handles debugging mode for paths without hostnames $source = preg_replace(';(<[^>]+)(url\\("?\'?|href\\s*=\\s*"|src\\s*=\\s*"|action\\s*=\\s*")(' . URL_PREFIX . '|' . URL_DEVICE_DEBUG_PREFIX . '|/);', '\\1\\2' . URL_PREFIX, $source); if (Kurogo::getSiteVar('DEVICE_DEBUG')) { // if we are in debugging mode we need to also rewrite full paths with hostnames $source = preg_replace(';(<[^>]+)(url\\("?\'?|href\\s*=\\s*"|src\\s*=\\s*")(' . FULL_URL_PREFIX . '|' . FULL_URL_BASE . ');', '\\1\\2' . FULL_URL_PREFIX, $source); } // Most of the following code comes from the trimwhitespace filter: // Pull out the script blocks preg_match_all("!<script[^>]*?>.*?</script>!is", $source, $match); $scriptBlocks = $match[0]; $source = preg_replace("!<script[^>]*?>.*?</script>!is", '@@@SMARTY:TRIM:SCRIPT@@@', $source); // Pull out the pre blocks preg_match_all("!<pre[^>]*?>.*?</pre>!is", $source, $match); $preBlocks = $match[0]; $source = preg_replace("!<pre[^>]*?>.*?</pre>!is", '@@@SMARTY:TRIM:PRE@@@', $source); // Pull out the textarea blocks preg_match_all("!<textarea[^>]*?>.*?</textarea>!is", $source, $match); $textareaBlocks = $match[0]; $source = preg_replace("!<textarea[^>]*?>.*?</textarea>!is", '@@@SMARTY:TRIM:TEXTAREA@@@', $source); // remove all leading spaces, tabs and carriage returns NOT // preceeded by a php close tag. $source = trim(preg_replace('/((?<!\\?>)\\n)[\\s]+/m', '\\1', $source)); // remove all newlines before and after tags. $source = preg_replace('/[\\r\\n]*(<[^>]+>)[\\r\\n]*/m', '\\1', $source); // collapse whitespace before and after tags. $source = preg_replace(array('/\\s+(<)/m', '/(>)\\s+/s'), array(' \\1', '\\1 '), $source); // strip spaces around non-breaking spaces $source = preg_replace('/\\s* \\s*/m', ' ', $source); // restore textarea, pre, script and style blocks $this->stripWhitespaceReplace("@@@SMARTY:TRIM:TEXTAREA@@@", $textareaBlocks, $source); $this->stripWhitespaceReplace("@@@SMARTY:TRIM:PRE@@@", $preBlocks, $source); $this->stripWhitespaceReplace("@@@SMARTY:TRIM:SCRIPT@@@", $scriptBlocks, $source); if (KurogoWebBridge::shouldRewriteAssetPaths()) { // Need to rewrite Kurogo assets to use filenames used in native templates $rewriter = new KurogoWebBridge($smarty->getTemplateVars('configModule')); $source = $rewriter->rewriteURLsToFilePaths($source); } return $source; }