Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /****
- This plugin escapes modx tags that are enclosed in %EscapeModx% %/EscapeModx% tags.
- eg in a resource content in a RTE:
- %EscapeModx%
- [[!AndIf?
- &condition=`[[+description]]%%notempty%%1||[[+urlLink]]%%notempty%%1`
- &operator=`OR`
- &operatorSeparator = `%%`
- &then=`this is an example`
- ]]
- %/EscapeModx%
- The following events should be set:
- - OnBeforeDocFormSave
- - OnDocFormRender
- - OnWebPagePrerender
- ***/
- $eventName = $modx->event->name;
- $escapeModxKeyIn = '%EscapeModx%';//escape tag in
- $escapeModxKeyOut = '%/EscapeModx%';//escape tag out
- $escapeModxTags_debug = false;
- switch ($eventName) {
- /*** OnBeforeDocFormSave ***/
- case 'OnBeforeDocFormSave' :
- $output = $resource->get('content');
- if ($escapeModxTags_debug) if ($escapeModxTags_debug) $modx->log(MODX_LOG_LEVEL_DEBUG,"--> escapeModxTags-------OnBeforeDocFormSave-----".$output);
- if (strpos($output, $escapeModxKeyIn) === false) return;
- preg_match_all('/'.preg_quote($escapeModxKeyIn,'/').'(.*?)'.preg_quote($escapeModxKeyOut,'/').'/ims', $output, $matches);
- if ($escapeModxTags_debug) $modx->log(MODX_LOG_LEVEL_DEBUG,"--> escapeModxTags----OnBeforeDocFormSave--------".print_r($matches,true));
- foreach ($matches[1] as $key => $match) {
- if ($escapeModxTags_debug) $modx->log(MODX_LOG_LEVEL_DEBUG,"--> escapeModxTags----OnBeforeDocFormSave--------".$output);
- $match64 = base64_encode($match);
- $output=str_replace($escapeModxKeyIn.$match.$escapeModxKeyOut,$escapeModxKeyIn.'Encoded64'.$match64.$escapeModxKeyOut,$output);
- }
- $resource->set('content', $output);
- break;
- /*** OnDocFormRender ***/
- case 'OnDocFormRender' :
- $output = $resource->get('content');
- if ($escapeModxTags_debug) $modx->log(MODX_LOG_LEVEL_DEBUG,"--> escapeModxTags----OnDocFormRender--------".$output);
- if (strpos($output, $escapeModxKeyIn) === false) return;
- preg_match_all('/'.preg_quote($escapeModxKeyIn,'/').'Encoded64(.*?)'.preg_quote($escapeModxKeyOut,'/').'/ims', $output, $matches);
- foreach ($matches[1] as $key => $match64) {
- $match = base64_decode($match64);
- if ($escapeModxTags_debug) $modx->log(MODX_LOG_LEVEL_DEBUG,"--> escapeModxTags----OnDocFormRender--------".$match);
- $output=str_replace($escapeModxKeyIn.'Encoded64'.$match64.$escapeModxKeyOut,$escapeModxKeyIn.$match.$escapeModxKeyOut,$output);
- }
- $resource->set('content', $output);
- if ($escapeModxTags_debug) $modx->log(MODX_LOG_LEVEL_DEBUG,"--> escapeModxTags----OnDocFormRender--content------".$resource->get('content').print_r(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,15) ,true));
- break;
- /*** OnWebPagePrerender ***/
- case 'OnWebPagePrerender' :
- $output = $modx->resource->_output;
- if ($escapeModxTags_debug) $modx->log(MODX_LOG_LEVEL_DEBUG,"--> escapeModxTags----OnWebPagePrerender--------".$output);
- if (strpos($output, $escapeModxKeyIn) === false) return;
- preg_match_all('/'.preg_quote($escapeModxKeyIn,'/').'Encoded64(.*?)'.preg_quote($escapeModxKeyOut,'/').'/ims', $output, $matches);
- foreach ($matches[1] as $key => $match64) {
- $match = base64_decode($match64);
- $output=str_replace($escapeModxKeyIn.'Encoded64'.$match64.$escapeModxKeyOut,$match,$output);
- }
- $modx->resource->_output = $output;
- if ($escapeModxTags_debug) $modx->log(MODX_LOG_LEVEL_DEBUG,"--> escapeModxTags----OnWebPagePrerender--content------".$modx->resource->_output);
- break;
- }
Add Comment
Please, Sign In to add comment