function _collapse_text_check_options in Collapse Text 7.2
Same name and namespace in other branches
- 6.2 collapse_text.module \_collapse_text_check_options()
see if there is an options tag available. if so, remove it from the text and set the options.
1 call to _collapse_text_check_options()
- _collapse_text_filter_process in ./
collapse_text.module - Implements hook_filter_FILTER_process().
File
- ./
collapse_text.module, line 232 - collapse_text is an input filter that allows text to be collapsible
Code
function _collapse_text_check_options($text, $options) {
$matches = array();
$regex_text = '
(?<!\\\\) # not proceeded by a backslash
\\[ # opening bracket
collapse # the word collapse
\\s+ # white space
options # the word options
[^\\]]* # everything until the closing bracket
\\] # a closing bracket
';
if (preg_match('/' . $regex_text . '/smx', $text, $matches)) {
$opt_tag = $matches[0];
// remove the "collapse" from the front of the tag, baking in an "options" tag
$opt_tag = preg_replace('/^\\[collapse /', '[', $opt_tag);
// change to angle brackets, so it can be parsed as XML
$opt_tag = preg_replace(array(
'/^\\[/',
'/\\]$/',
), array(
'<',
'/>',
), $opt_tag);
// turn HTML entities into XML entities
// Issue #1109792 by eronte
$opt_tag = _collapse_text_html_to_xml_entities($opt_tag);
$opt_tag = simplexml_load_string($opt_tag);
// form options are either 'form="form"' or 'form="noform"'
if ($opt_tag['form'] == 'form') {
$options['form'] = 1;
}
elseif ($opt_tag['form'] == 'noform') {
$options['form'] = 0;
}
if ($opt_tag['default_title']) {
// Issue #1096070 by Asgardinho: issues with UTF8 text
$options['default_title'] = htmlspecialchars(trim($opt_tag['default_title']), ENT_QUOTES, 'UTF-8');
}
// remove the options tag, including any miscellaneous <p>, </p>, or <br> tags around it.
$text = preg_replace('/(?:<\\/?p>|<br\\s*\\/?>)*' . $regex_text . '(?:<\\/?p>|<br\\s*\\/?>)*/smx', '', $text);
}
return array(
$text,
$options,
);
}