Created
May 30, 2011 12:49
-
-
Save splittingred/998865 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$eventName = $modx->event->name; | |
switch ($eventName) { | |
case 'OnLoadWebDocument' : | |
$output = $modx->codeContent = $modx->resource->getContent(); | |
preg_match_all('/<pre.*?>(.*?)<\/pre>/ims', $output, $matches); | |
$i = 0; | |
if (empty($matches[1])) return; | |
if (empty($modx->codeMatches)) $modx->codeMatches = array(); | |
foreach ($matches[1] as $key => $match) { | |
$output = str_replace($match, '~*code_' . $i . '*~', $output); | |
$modx->codeMatches['~*code_' . $i . '*~'] = $match; | |
$i++; | |
} | |
$modx->resource->setContent($output); | |
break; | |
case 'OnWebPagePrerender' : | |
$html = & $modx->resource->_output; | |
$output = $modx->resource->getContent(); | |
/*preg_match_all('/<pre.*?>(.*?)<\/pre>/ims', $html, $matches); */ | |
$i = 0; | |
$replacements = array ( | |
'<' => '<', | |
'>' => '>', | |
); | |
if (empty($modx->codeMatches)) return; | |
foreach ($modx->codeMatches as $key => $match) { | |
//$match = preg_replace('/&([^\s]*;)/i', '&$1', $match); | |
foreach ($replacements as $key => $value) { | |
$match = str_replace($key, $value, $match); | |
} | |
$html = str_replace('~*code_' . $i . '*~', $match, $html); | |
$output = str_replace('~*code_' . $i . '*~', $match, $output); | |
$i++; | |
} | |
$modx->resource->setContent($output); | |
$modx->codeContent = $output; | |
break; | |
case 'OnBeforeSaveWebPageCache' : | |
$modx->resource->setContent($modx->codeContent); | |
break; | |
default : | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment