diff options
author | nickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-04-02 20:58:41 +0000 |
---|---|---|
committer | nickw <nickw@36083f99-b078-4883-b0ff-0f9b5a30f544> | 2010-04-02 20:58:41 +0000 |
commit | 427b67e3401ff0b6416ac04c2a41926dfc932aff (patch) | |
tree | f471ad9b38cfdd6e2ee0d1bdba245c6dcdb650dd /mod | |
parent | 5224a87794f29031bda2f587dd672746d1ea08a0 (diff) | |
download | elgg-427b67e3401ff0b6416ac04c2a41926dfc932aff.tar.gz elgg-427b67e3401ff0b6416ac04c2a41926dfc932aff.tar.bz2 |
Truncating lengthy blog excerpts on word breaks.
git-svn-id: http://code.elgg.org/elgg/trunk@5582 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod')
-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; } /** |