From aa153f29e208adbe3cf7d8cad5e246239177a213 Mon Sep 17 00:00:00 2001 From: martin Date: Wed, 31 Jul 2002 15:34:15 +0000 Subject: [PATCH] Fixes for long posts ... --- mod/forum/index.php | 2 ++ mod/forum/lib.php | 33 ++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/mod/forum/index.php b/mod/forum/index.php index 2c5c11ebac..66d5c51be4 100644 --- a/mod/forum/index.php +++ b/mod/forum/index.php @@ -90,6 +90,8 @@ foreach ($contentforums as $forum) { $count = count_records("forum_discussions", "forum", "$forum->id"); + $forum->intro = forum_shorten_post($forum->intro); + if ($can_subscribe) { if (forum_is_forcesubscribed($forum->id)) { $sublink = "YES"; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 0b5f431375..20a2b8026c 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -154,7 +154,7 @@ function make_mail_post(&$post, $user, $touser, $course, $ownpost=false, $reply= function print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false, $rate=false, $footer="") { - global $THEME, $USER, $CFG, $FORUM_LONG_POST; + global $THEME, $USER, $CFG; if ($post->parent) { echo "\n
"; @@ -183,18 +183,13 @@ function print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false echo "\n"; if ($link && (strlen($post->message) > $FORUM_LONG_POST)) { - // Look for the first return between 50 and $FORUM_LONG_POST - $shortmessage = substr($post->message, 50, $FORUM_LONG_POST); - if ($pos = strpos($shortmessage, "\n")) { - $shortmessage = substr($post->message, 0, 50 + $pos); - } else { - $shortmessage = substr($post->message, 0, $FORUM_LONG_POST). "..."; - } - echo text_to_html($shortmessage); + // Print shortened version + echo text_to_html(forum_shorten_post($post->message)); $numwords = count_words($post->message); - echo "wwwroot/mod/forum/discuss.php?d=$post->discussion\">Read the rest of this topic ($numwords words)..."; + echo "wwwroot/mod/forum/discuss.php?d=$post->discussion\">"; + echo "Read the rest of this topic ($numwords words)..."; } else { - // Just print the whole thing + // Print whole message echo text_to_html($post->message); } @@ -243,6 +238,22 @@ function print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false echo "
\n\n"; } +function forum_shorten_post($message) { + global $FORUM_LONG_POST; + + if (strlen($message) > $FORUM_LONG_POST) { + // Look for the first return between 50 and $FORUM_LONG_POST + $shortmessage = substr($message, 50, $FORUM_LONG_POST); + if ($pos = strpos($shortmessage, "\n")) { + return substr($message, 0, 50 + $pos); + } else { + return substr($message, 0, $FORUM_LONG_POST). "..."; + } + } else { + return $message; + } +} + function print_ratings($post) { -- 2.39.5