function readmorecontrol_text_compare_items in Read More Control 7
Implements the callback readmorecontrol_MODULE_compare_items().
1 call to readmorecontrol_text_compare_items()
File
- ./
readmorecontrol.module, line 686 - Defines options to control how the Read more link is displayed on teasers.
Code
function readmorecontrol_text_compare_items($items, $context) {
extract($context, EXTR_SKIP);
// We can bypass processing of some combinations.
if ($display['type'] == $display_full['type']) {
switch ($display['type']) {
case 'text_default':
case 'text_plain':
return FALSE;
}
}
// Avoid additional processing, do this once for both if required.
$needs_sanitization = $display['type'] != 'text_plain' || $display_full['type'] != 'text_plain';
$has_summary = $display['type'] == 'text_summary_or_trimmed' || $display_full['type'] == 'text_summary_or_trimmed';
foreach ($items as $delta => $item) {
$sanitized_text = $needs_sanitization ? _text_sanitize($instance, $langcode, $item, 'value') : '';
$sanitized_summary = $has_summary ? _text_sanitize($instance, $langcode, $item, 'summary') : '';
$display_text = '';
$full_display_text = '';
foreach (array(
'display_text',
'full_display_text',
) as $var) {
$test_display = $var == 'display_text' ? $display : $display_full;
switch ($test_display['type']) {
case 'text_default':
case 'text_trimmed':
${$var} = $sanitized_text;
if ($test_display['type'] == 'text_trimmed') {
${$var} = text_summary(${$var}, $instance['settings']['text_processing'] ? $item['format'] : NULL, $test_display['settings']['trim_length']);
}
else {
// If <!--break--> was used, we need to strip it out.
${$var} = str_replace('<!--break-->', '', ${$var});
}
break;
case 'text_summary_or_trimmed':
if (!empty($item['summary'])) {
${$var} = $sanitized_summary;
}
else {
${$var} = text_summary($sanitized_text, $instance['settings']['text_processing'] ? $item['format'] : NULL, $test_display['settings']['trim_length']);
}
break;
case 'text_plain':
${$var} = strip_tags($item['value']);
break;
case 'smart_trim_format':
${$var} = '';
if (function_exists('smart_trim_field_formatter_view')) {
$smart_trim = smart_trim_field_formatter_view($entity_type, $entity, $field, $instance, $langcode, array(
$item,
), $display);
if (isset($smart_trim[0]['#markup'])) {
${$var} = $smart_trim[0]['#markup'];
}
}
break;
}
}
if ($display_text != $full_display_text) {
return TRUE;
}
}
return FALSE;
}