From 427b67e3401ff0b6416ac04c2a41926dfc932aff Mon Sep 17 00:00:00 2001 From: nickw Date: Fri, 2 Apr 2010 20:58:41 +0000 Subject: Truncating lengthy blog excerpts on word breaks. git-svn-id: http://code.elgg.org/elgg/trunk@5582 36083f99-b078-4883-b0ff-0f9b5a30f544 --- mod/blog/blog_lib.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/mod/blog/blog_lib.php b/mod/blog/blog_lib.php index e8daeeed9..66d93ddce 100644 --- a/mod/blog/blog_lib.php +++ b/mod/blog/blog_lib.php @@ -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 …"; + } + + return $trimmed; } /** -- cgit v1.2.3