aboutsummaryrefslogtreecommitdiff
path: root/mod/blog/blog_lib.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-04-21 20:20:30 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2010-04-21 20:20:30 +0000
commit91b3803e754c27d0f4ed6459439b8b876fac1788 (patch)
treef364a8459e7e08b151fd87931f38f80b0bee2b43 /mod/blog/blog_lib.php
parent96eb12e58a36fe33dfd6af0a748ef992d0b1edf7 (diff)
downloadelgg-91b3803e754c27d0f4ed6459439b8b876fac1788.tar.gz
elgg-91b3803e754c27d0f4ed6459439b8b876fac1788.tar.bz2
Blog excerpts now work for MB strings and properly detect word breaks.
git-svn-id: http://code.elgg.org/elgg/trunk@5839 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'mod/blog/blog_lib.php')
-rw-r--r--mod/blog/blog_lib.php21
1 files changed, 14 insertions, 7 deletions
diff --git a/mod/blog/blog_lib.php b/mod/blog/blog_lib.php
index 12226ee2e..b6a4d53c2 100644
--- a/mod/blog/blog_lib.php
+++ b/mod/blog/blog_lib.php
@@ -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 ;
}
/**