]> gitweb.fluxo.info Git - lorea/elgg.git/commitdiff
Truncating lengthy blog excerpts on word breaks.
authornickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 2 Apr 2010 20:58:41 +0000 (20:58 +0000)
committernickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544>
Fri, 2 Apr 2010 20:58:41 +0000 (20:58 +0000)
git-svn-id: http://code.elgg.org/elgg/trunk@5582 36083f99-b078-4883-b0ff-0f9b5a30f544

mod/blog/blog_lib.php

index e8daeeed9863990d95c889ddc9da1a49f46eadb4..66d93ddce7478a6cd73368f9db4ad89ad14da2bd 100644 (file)
@@ -169,10 +169,19 @@ function blog_get_page_content_archive($owner_guid, $lower, $upper) {
  * Returns an appropriate excerpt for a blog.
  *
  * @param string $text
+ * @param int $words
  * @return string
  */
-function blog_make_excerpt($text) {
-       return substr(strip_tags($text), 0, 300);
+function blog_make_excerpt($text, $words=60) {
+       $text = strip_tags($text);
+       preg_match("/([\S]+\s*){0,$words}/", $text, $matches);
+       
+       $trimmed = trim($matches[0]);
+       if ($trimmed != $text) {
+               return  "$trimmed &#8230";
+       }
+       
+       return $trimmed;
 }
 
 /**