// Name: // ShowSnippet v1.0 // Description: // Output the contents of a snippet as HTML. // Usage: // &snippetName [ string ] // The snippet name. // Author: // Stephan Dale. // http://mindspill.net // modx(a)mindspill.net // Note: // If some characters aren't encoded properly add new str_replace calls. See comment /* ADD EXTRA ENCODINGS HERE */ if (!isset($snippetName)) { echo 'No snippet name supplied, you must specify the snippetName parameter.'; } else { $table = $modx->getFullTableName("site_snippets"); $sql = "SELECT snippet FROM ".$table." WHERE name='".$snippetName."'"; $results = $modx->dbQuery($sql); $row = $modx->db->getRow($results); $theCode = $row['snippet']; // Convert the code to HTML. Must also encode the [] characters to prevent MODx interpreting them as a snippet call. $htmlCode = htmlentities($theCode, ENT_QUOTES); // Encode all characters that have a corresponding html code. This did not seem to effect the square brace characters. $htmlCode = str_replace('[', '[', $htmlCode); // Left square brace. $htmlCode = str_replace(']', ']', $htmlCode); // Right square brace. $htmlCode = str_replace('{', '{', $htmlCode); // Left curly brace, just to be sure. $htmlCode = str_replace('}', '}', $htmlCode); // Right curley brace, just to be sure. /* ADD EXTRA ENCODINGS HERE */ // echo ''; echo '
'.$htmlCode.'
'; }