From 72d497d4ce7f1100e3cb90e530602b5d9af979de Mon Sep 17 00:00:00 2001 From: moodler Date: Sat, 5 Jul 2003 03:54:10 +0000 Subject: [PATCH] Display images inline when attached to forum posts --- mod/forum/lib.php | 133 +++++++++++++++++++++++++--------------------- 1 file changed, 72 insertions(+), 61 deletions(-) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index acea8ece64..3511045d3f 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -780,60 +780,60 @@ function forum_make_mail_post(&$post, $user, $touser, $course, $output = ""; if ($post->parent) { - $output .= "\n
"; - $output .= ""; + $output .= '
'; + $output .= ''; } else { - $output .= "
"; - $output .= ""; + $output .= '
'; + $output .= ''; } - $output .= ""; + $output .= ""; if ($post->parent) { - $output .= ""; - $output .= ""; + $output .= "
cellcontent2\" WIDTH=35 VALIGN=TOP>"; + $output .= "
cellcontent2\" width=\"35\" valign=\"top\">"; $output .= print_user_picture($user->id, $course->id, $user->picture, false, true); - $output .= "cellheading\">"; + $output .= "cellheading\">"; } else { - $output .= "cellheading2\">"; + $output .= "cellheading2\">"; } - $output .= "

"; - $output .= "$post->subject
"; - $output .= ""; - $by->name = "wwwroot/user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname"; + $output .= "

"; + $output .= "$post->subject
"; + $output .= ""; + $by->name = "wwwroot/user/view.php?id=$user->id&course=$course->id\">$user->firstname $user->lastname"; $by->date = userdate($post->modified, "", $touser->timezone); $output .= get_string("bynameondate", "forum", $by); - $output .= "

cellcontent2\" WIDTH=10>"; + $output .= "

cellcontent2\" width=10>"; $output .= " "; - $output .= "cellcontent\">\n"; + $output .= "cellcontent\">\n"; if ($post->attachment) { $post->course = $course->id; $post->forum = get_field("forum_discussions", "forum", "id", $post->discussion); - $output .= "
"; + $output .= "
"; $output .= forum_print_attachments($post, "html"); - $output .= "
"; + $output .= "
"; } $output .= format_text($post->message, $post->format); - $output .= "

"; + $output .= "

"; $age = time() - $post->created; if ($ownpost) { - $output .= "wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum").""; + $output .= "wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum").""; if ($reply) { - $output .= " | wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum").""; + $output .= " | wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum").""; } $output .= "  "; } else { if ($reply) { - $output .= "wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."  "; + $output .= "wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum")."  "; } } - $output .= "

"; - $output .= "

"; + $output .= "

"; + $output .= "

"; if ($link) { if ($post->replies == 1) { @@ -841,14 +841,14 @@ function forum_make_mail_post(&$post, $user, $touser, $course, } else { $replystring = get_string("repliesmany", "forum", $post->replies); } - $output .= "wwwroot/mod/forum/discuss.php?d=$post->discussion\">".get_string("discussthistopic", "forum")." ($replystring)  "; + $output .= "wwwroot/mod/forum/discuss.php?d=$post->discussion\">".get_string("discussthistopic", "forum")." ($replystring)  "; } - $output .= "

"; + $output .= "

"; if ($footer) { - $output .= "

$footer

"; + $output .= "

$footer

"; } - $output .= "
\n"; - $output .= "
\n\n"; + $output .= "
\n"; + $output .= "
\n\n"; return $output; } @@ -859,61 +859,62 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link echo "id\">"; if ($post->parent) { - echo ""; + echo '
'; } else { - echo "
"; + echo '
'; } - echo ""; + echo ""; if ($post->parent) { - echo ""; - echo ""; + echo "\n
cellcontent2\" CLASS=\"forumpostpicture\" WIDTH=35 VALIGN=TOP>"; + echo "
cellcontent2\" class=\"forumpostpicture\" width=\"35\" valign=\"top\">"; print_user_picture($post->userid, $courseid, $post->picture); - echo "cellheading\" CLASS=\"forumpostheader\" WIDTH=\"100%\">"; + echo "cellheading\" class=\"forumpostheader\" width=\"100%\">"; } else { - echo "cellheading2\" CLASS=\"forumpostheadertopic\" WIDTH=\"100%*\">"; + echo "cellheading2\" class=\"forumpostheadertopic\" width=\"100%\">"; } - echo "

"; - echo "$post->subject
"; - echo ""; - $by->name = "wwwroot/user/view.php?id=$post->userid&course=$courseid\">$post->firstname $post->lastname"; + echo "

"; + echo "$post->subject
"; + echo ""; + $by->name = "wwwroot/user/view.php?id=$post->userid&course=$courseid\">$post->firstname $post->lastname"; $by->date = userdate($post->modified); print_string("bynameondate", "forum", $by); - echo "

cellcontent2\" CLASS=\"forumpostside\" WIDTH=10>"; + echo "

cellcontent2\" class=\"forumpostside\" width=\"10\">"; echo " "; - echo "cellcontent\" CLASS=\"forumpostmessage\">\n"; + echo "cellcontent\" class=\"forumpostmessage\">\n"; if ($post->attachment) { $post->course = $courseid; $post->forum = get_field("forum_discussions", "forum", "id", $post->discussion); - echo "
"; - forum_print_attachments($post); - echo "
"; + echo "
"; + $attachedimages = forum_print_attachments($post); + echo "
"; } if ($link and (strlen(strip_tags($post->message)) > FORUM_LONG_POST)) { // Print shortened version echo format_text(forum_shorten_post($post->message), $post->format); $numwords = count_words(strip_tags($post->message)); - echo "

wwwroot/mod/forum/discuss.php?d=$post->discussion\">"; + echo "

wwwroot/mod/forum/discuss.php?d=$post->discussion\">"; echo get_string("readtherest", "forum"); - echo " (".get_string("numwords", "", $numwords).")...

"; + echo " (".get_string("numwords", "", $numwords).")...

"; } else { // Print whole message echo format_text($post->message, $post->format); + echo $attachedimages; } - echo "

"; + echo "

"; $age = time() - $post->created; if ($ownpost) { if ($age < $CFG->maxeditingtime) { - echo "wwwroot/mod/forum/post.php?edit=$post->id\">".get_string("edit", "forum")." | "; + echo "wwwroot/mod/forum/post.php?edit=$post->id\">".get_string("edit", "forum")." | "; } } if ($ownpost or isteacher($courseid)) { - echo "wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum").""; + echo "wwwroot/mod/forum/post.php?delete=$post->id\">".get_string("delete", "forum").""; if ($reply) { echo "| "; } else { @@ -921,12 +922,12 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link } } if ($reply) { - echo "wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum").""; + echo "wwwroot/mod/forum/post.php?reply=$post->id\">".get_string("reply", "forum").""; echo "  "; } - echo "

"; + echo "

"; - echo "

"; + echo "

"; if ($rate && $USER->id) { if (isteacher($courseid)) { forum_print_ratings($post->id); @@ -946,14 +947,14 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link } else { $replystring = get_string("repliesmany", "forum", $post->replies); } - echo "wwwroot/mod/forum/discuss.php?d=$post->discussion\">".get_string("discussthistopic", "forum")." ($replystring)  "; + echo "wwwroot/mod/forum/discuss.php?d=$post->discussion\">".get_string("discussthistopic", "forum")." ($replystring)  "; } - echo "

"; + echo "

"; if ($footer) { - echo "

$footer

"; + echo "

$footer

"; } - echo "
"; - echo "
\n\n"; + echo ""; + echo "
\n\n"; } @@ -1175,12 +1176,15 @@ function forum_delete_old_attachments($post, $exception="") { function forum_print_attachments($post, $return=NULL) { // if return=html, then return a html string. // if return=text, then return a text-only string. -// otherwise, print HTML +// otherwise, print HTML for non-images, and return image HTML global $CFG; $filearea = forum_file_area_name($post); + $imagereturn = ""; + $output = ""; + if ($basedir = forum_file_area($post)) { if ($files = get_directory_list($basedir)) { $strattachment = get_string("attachment", "forum"); @@ -1202,16 +1206,23 @@ function forum_print_attachments($post, $return=NULL) { $output .= "$strattachment $file:\n$CFG->wwwroot/$ffurl\n"; } else { - link_to_popup_window("/$ffurl", "attachment", $image, 500, 500, $strattachment); - echo "wwwroot/$ffurl\">$file"; - echo "
"; + if ($icon == "image.gif") { // Image attachments don't get printed as links + $imagereturn .= "
wwwroot/$ffurl\">"; + } else { + link_to_popup_window("/$ffurl", "attachment", $image, 500, 500, $strattachment); + echo "wwwroot/$ffurl\">$file"; + echo "
"; + } } } } } + if ($return) { return $output; } + + return $imagereturn; } function forum_add_attachment($post, $newfile) { -- 2.39.5