diff options
Diffstat (limited to 'mod/blog')
-rw-r--r-- | mod/blog/blog_lib.php | 13 |
1 files 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; } /** |