]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Blog excerpts now work for MB strings and properly detect word breaks.
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 21 Apr 2010 20:20:30 +0000 (20:20 +0000)
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>
Wed, 21 Apr 2010 20:20:30 +0000 (20:20 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@5839 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/blog/blog_lib.php
mod/blog/views/default/object/blog.php

index 12226ee2e496736e67b036b8e20208b7eac8e10b..b6a4d53c246cb0c30ed00b8f2ede2c8595ee02cb 100644 (file)
@@ -245,21 +245,28 @@ function blog_get_page_content_friends($user_guid) {
 
 /**
  * Returns an appropriate excerpt for a blog.
+ * Will return up to 250 chars stopping at the nearest space.
+ * If no spaces are found (like in Japanese) will crop off at the
+ * 250 char mark.
  *
  * @param string $text
  * @param int $words
  * @return string
  */
-function blog_make_excerpt($text, $words=60) {
-       $text = strip_tags($text);
-       preg_match("/([\S]+\s*){0,$words}/", $text, $matches);
+function blog_make_excerpt($text, $chars = 250) {
+       $text = trim(strip_tags($text));
 
-       $trimmed = trim($matches[0]);
-       if ($trimmed != $text) {
-               return  "$trimmed &#8230";
+       // handle cases
+       $excerpt = elgg_substr($text, 0, $chars);
+       $space = elgg_strrpos($excerpt, ' ', 0);
+
+       // don't crop if can't find a space.
+       if ($space === FALSE) {
+               $space = $chars;
        }
+       $excerpt = trim(elgg_substr($excerpt, 0, $space));
 
-       return $trimmed;
+       return $excerpt ;
 }
 
 /**
index d72d6a21d6fb650ab5c6946ac80c227dd311fc41..0c8944f7d8250dd4d8ec4dede05755e45b460565 100644 (file)
@@ -21,6 +21,12 @@ $container = get_entity($blog->container_guid);
 $linked_title = "<a href=\"{$blog->getURL()}\" title=\"" . htmlentities($blog->title) . "\">{$blog->title}</a>";
 $categories = elgg_view('categories/view', $vars);
 $excerpt = $blog->excerpt;
+
+// add ellipses to excerpt it not the full post
+if ($excerpt != trim(strip_tags($blog->description))) {
+       $excerpt .= ' &#8230';
+}
+
 $body = autop($blog->description);
 $owner_icon = elgg_view("profile/icon",array('entity' => $owner, 'size' => 'tiny'));
 $tags = elgg_view('output/tags', array('tags' => $blog->tags));