function _collapse_text_process_child_item in Collapse Text 6.2
Same name and namespace in other branches
- 7.2 collapse_text.module \_collapse_text_process_child_item()
process a child item.
@todo -- deprecate the "collapsed-text-fieldset" class
1 call to _collapse_text_process_child_item()
- _collapse_text_process_recurse_tree in ./
collapse_text.module - Take a nested tree and turn it into a string.
File
- ./
collapse_text.module, line 530 - collapse_text is an input filter that allows text to be collapsible
Code
function _collapse_text_process_child_item($item, $options) {
// translate the "tag" into a proper tag, and then parse it
// as an xml tag; this is more robust than the previous method
$tag = preg_replace(array(
'/^\\[/',
'/\\]$/',
), array(
'<',
'/>',
), $item['tag']);
// turn HTML entities into XML entities
// Issue #1109792 by eronte
$tag = _collapse_text_html_to_xml_entities($tag);
$xmltag = simplexml_load_string($tag);
$collapsed = $xmltag['collapsed'] == 'collapsed';
$class = trim($xmltag['class']);
// Issue #1096070 by Asgardinho: issues with UTF8 text
$title = htmlspecialchars(trim($xmltag['title']), ENT_QUOTES, 'UTF-8');
// set up the styles array.
$classes = array();
$classes[] = _collapse_text_id_safe('collapse-text-fieldset');
$classes[] = _collapse_text_id_safe('collapsed-text-fieldset');
// @todo - deprecate
foreach (explode(' ', $class) as $c) {
if (!empty($c)) {
$classes[] = _collapse_text_id_safe($c);
}
}
// if a title is not supplied, look in the first child for a header tag
if (empty($title)) {
if ($item['value'][0]['type'] == 'text') {
$h_matches = array();
if (preg_match('/(<h\\d[^>]*>(.+?)<\\/h\\d>)/smi', $item['value'][0]['value'], $h_matches)) {
$title = strip_tags($h_matches[2]);
}
// if we get the title from the first header tag, we should remove it from
// the text so that it isn't repeated.
if (!empty($title)) {
$occ = 1;
// this is a hack to only replace the first instance.
$item['value'][0]['value'] = str_replace($h_matches[0], '', $item['value'][0]['value'], $occ);
}
}
}
// if still no title, put in the default title
if (empty($title)) {
$title = $options['default_title'];
$classes[] = _collapse_text_id_safe('collapse-text-default-title');
}
// create a fieldset that can be themed.
// per #634666, deviantintegral, although not including the form tag, as we allow nesting.
$fieldset = array(
'#type' => 'fieldset',
'#theme' => 'collapse_text_fieldset',
'#title' => $title,
'#collapsible' => TRUE,
'#collapsed' => $collapsed,
'#attributes' => array(
'class' => join(" ", $classes),
),
'collapse_text_contents' => _collapse_text_process_recurse_tree($item['value'], $options),
);
return $fieldset;
}