-
-
Save Mark-H/3494789 to your computer and use it in GitHub Desktop.
Busted
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 = $GLOBALS['code_content'] = $modx->resource->get('content'); | |
preg_match_all('/<pre.*?>(.*?)<\/pre>/ims', $output, $matches); | |
$i = 0; | |
$GLOBALS['code_matches'] = array(); | |
foreach ($matches[1] as $key => $match) { | |
$output = str_replace($match, '~*code_' . $i . '*~', $output); | |
$GLOBALS['code_matches']['~*code_' . $i . '*~'] = $match; | |
$i++; | |
} | |
$modx->resource->set('content', $output); | |
break; | |
case 'OnWebPagePrerender' : | |
$html = & $modx->resource->_output; | |
$output = $modx->resource->get('content'); | |
preg_match_all('/<pre.*?>(.*?)<\/pre>/ims', $html, $matches); | |
$i = 0; | |
$replacements = array ( | |
'<' => '<', | |
'>' => '>' | |
); | |
foreach ($GLOBALS['code_matches'] 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->set('content', $output); | |
break; | |
case 'OnBeforeSaveWebPageCache' : | |
$modx->resource->set('content', $GLOBALS['code_content']); | |
break; | |
default : | |
break; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The above was sanitized. Those strings are wrapped pre and code html tags in the output :)