Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Implements hook_node_presave().
- */
- function MODULENAME_node_presave($node) {
- if ($node->type == 'news') {
- $summary = $node->body[$node->language][0]['summary'];
- if (empty($summary)) {
- $text = $node->body[$node->language][0]['value'];
- $size = variable_get('teaser_length', 600) + 200;
- $summary = truncate_utf8($text, $size);
- $search = array(
- '#[\r\n\t]#', // Remove line breaks and tabs
- '#<img[^>]*?>#is', // Remove images
- '#<h\d>(.*?)</h\d>#is', // Change headings to strong
- '#<a name="[^"]*"></a>#is', // Remove named anchors
- '#</?p>#is' // Remove paragraph tags
- );
- $replace = array(
- '',
- '',
- '<strong>\1</strong> — ',
- '',
- ' ',
- );
- $summary = preg_replace($search, $replace, $summary);
- $node->body[$node->language][0]['summary'] = text_summary($summary, $node->body[$node->language][0]['format']);
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment