/[drupal]/drupal/modules/node.module
ViewVC logotype

Diff of /drupal/modules/node.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.641.2.29, Mon Jan 1 22:16:11 2007 UTC revision 1.641.2.30, Thu Jan 4 19:50:28 2007 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: node.module,v 1.641.2.28 2007/01/01 18:28:34 killes Exp $  // $Id: node.module,v 1.641.2.29 2007/01/01 22:16:11 killes Exp $
3    
4  /**  /**
5   * @file   * @file
# Line 180  function node_teaser($body, $format = NU Line 180  function node_teaser($body, $format = NU
180      return $body;      return $body;
181    }    }
182    
183    // In some cases, no delimiter has been specified (e.g. when posting using    // The teaser may not be longer than maximum length specified. Initial slice.
184    // the Blogger API). In this case, we try to split at paragraph boundaries.    $teaser = truncate_utf8($body, $size);
185    // When even the first paragraph is too long, we try to split at the end of    $position = 0;
186    // the next sentence.    // Cache the reverse of the teaser.
187    $breakpoints = array('</p>' => 4, '<br />' => 0, '<br>' => 0, "\n" => 0, '. ' => 1, '! ' => 1, '? ' => 1, '。' => 3, '؟ ' => 1);    $reversed = strrev($teaser);
188    foreach ($breakpoints as $point => $charnum) {  
189      if ($length = strpos($body, $point, $size)) {    // In some cases, no delimiter has been specified. In this case, we try to
190        return substr($body, 0, $length + $charnum);    // split at paragraph boundaries.
191      $breakpoints = array('</p>' => 0, '<br />' => 6, '<br>' => 4, "\n" => 1);
192      // We use strpos on the reversed needle and haystack for speed.
193      foreach ($breakpoints as $point => $offset) {
194        $length = strpos($reversed, strrev($point));
195        if ($length !== FALSE) {
196          $position = - $length - $offset;
197          return ($position == 0) ? $teaser : substr($teaser, 0, $position);
198      }      }
199    }    }
200    
201    // If all else fails, we simply truncate the string.    // When even the first paragraph is too long, we try to split at the end of
202    return truncate_utf8($body, $size);    // the last full sentence.
203      $breakpoints = array('. ' => 1, '! ' => 1, '? ' => 1, '。' => 0, '؟ ' => 1);
204      $min_length = strlen($reversed);
205      foreach ($breakpoints as $point => $offset) {
206        $length = strpos($reversed, strrev($point));
207        if ($length !== FALSE) {
208          $min_length = min($length, $min_length);
209          $position = 0 - $length - $offset;
210        }
211      }
212      return ($position == 0) ? $teaser : substr($teaser, 0, $position);
213  }  }
214    
215  function _node_names($op = '', $node = NULL) {  function _node_names($op = '', $node = NULL) {

Legend:
Removed from v.1.641.2.29  
changed lines
  Added in v.1.641.2.30

  ViewVC Help
Powered by ViewVC 1.1.2