function _syntaxhighlighter_validate_input in Syntax Highlighter 6
Same name and namespace in other branches
- 8 syntaxhighlighter.module \_syntaxhighlighter_validate_input()
- 6.2 syntaxhighlighter.module \_syntaxhighlighter_validate_input()
- 7.2 syntaxhighlighter.module \_syntaxhighlighter_validate_input()
- 7 syntaxhighlighter.module \_syntaxhighlighter_validate_input()
Check for error with syntaxhighlighter input
Parameters
string $field: what input field are we checking? We do form_set_error on this if any error is found
string $text: the input text to check for
2 calls to _syntaxhighlighter_validate_input()
- syntaxhighlighter_comment in ./
syntaxhighlighter.module - Validate on comment input text to be sure there is no bad {syntaxhighlighter} tags
- syntaxhighlighter_nodeapi in ./
syntaxhighlighter.module - Validate on the node input text to be sure there is no bad {syntaxhighlighter} tags
File
- ./
syntaxhighlighter.module, line 231 - Syntax highlight code using the Syntaxhighlighter javascript library. See http://alexgorbatchev.com/wiki/SyntaxHighlighter
Code
function _syntaxhighlighter_validate_input($field, $text) {
$errors = array();
// check for balance open/close tags
preg_match_all('/\\{ *syntaxhighlighter *[^}]+\\}/', $text, $matches_open, PREG_OFFSET_CAPTURE);
preg_match_all('/\\{\\/ *syntaxhighlighter *\\}/', $text, $matches_close, PREG_OFFSET_CAPTURE);
if (count($matches_open[0]) != count($matches_close[0])) {
$errors[] = t('{syntaxhighlighter} tags are not balanced: open and close tags must match.');
}
// make sure no nesting
preg_match_all('/\\{ *syntaxhighlighter *[^}]+\\}.*\\{\\/ *syntaxhighlighter *\\}/sU', $text, $matches_pair, PREG_OFFSET_CAPTURE);
if (count($matches_pair[0]) != 0 && (count($matches_pair[0]) != count($matches_open[0]) || count($matches_pair[0]) != count($matches_close[0]))) {
$errors[] = t('{syntaxhighlighter} tags cannot be nested. If you need to show the {syntaxhighlighter}/{/syntaxhighlighter} strings in syntax highlighted code, show them in escape form as <code>&#123;syntaxhighlighter OPTIONS&#125;</code> and <code>&#123;/syntaxhighlighter&#125;</code>');
}
if (!empty($errors)) {
form_set_error($field, implode('<br />', $errors));
}
}