function _syntaxhighlighter_validate_input in Syntax Highlighter 7.2
Same name and namespace in other branches
- 8 syntaxhighlighter.module \_syntaxhighlighter_validate_input()
- 6.2 syntaxhighlighter.module \_syntaxhighlighter_validate_input()
- 6 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_node_validate in ./
syntaxhighlighter.module - Validate on the node input text to be sure there is no bad {syntaxhighlighter} tags
- _syntaxhighlighter_comment_validate in ./
syntaxhighlighter.module - Validate on comment input text to be sure there is no bad {syntaxhighlighter} tags
File
- ./
syntaxhighlighter.module, line 326 - Syntax highlight code using the Syntaxhighlighter javascript library. See http://alexgorbatchev.com/wiki/SyntaxHighlighter
Code
function _syntaxhighlighter_validate_input($field, $text) {
$errors = array();
$tag_name = variable_get('syntaxhighlighter_tagname', 'pre');
// check for balance open/close tags
preg_match_all("#<{$tag_name}\\s*[^>]*>#", $text, $matches_open);
preg_match_all("#</\\s*{$tag_name}\\s*>#", $text, $matches_close);
if (count($matches_open[0]) != count($matches_close[0])) {
$errors[] = t('Unbalanced !tag tags.', array(
'!tag' => "<{$tag_name}>",
));
}
// make sure no nesting
preg_match_all("#<{$tag_name}\\s*[^>]*>.*</\\s*{$tag_name}\\s*>#sU", $text, $matches_pair);
if (count($matches_pair[0]) != count($matches_open[0]) || count($matches_pair[0]) != count($matches_close[0])) {
$errors[] = t('!tag tags cannot be nested.', array(
'!tag' => "<{$tag_name}>",
));
}
if (!empty($errors)) {
form_set_error($field, implode(' ', $errors));
}
}