From 6b4d90cd585c989d6337773019134e00815f4793 Mon Sep 17 00:00:00 2001 From: mjollnir_ Date: Mon, 4 Aug 2008 16:08:50 +0000 Subject: [PATCH] MDL-15758 - bring back full forum post export --- lang/en_utf8/forum.php | 1 + mod/forum/lib.php | 101 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 91 insertions(+), 11 deletions(-) diff --git a/lang/en_utf8/forum.php b/lang/en_utf8/forum.php index cbaa9e9c4d..bb85d6b9d4 100644 --- a/lang/en_utf8/forum.php +++ b/lang/en_utf8/forum.php @@ -22,6 +22,7 @@ $string['allsubscribe'] = 'Subscribe to all forums'; $string['allunsubscribe'] = 'Unsubscribe from all forums'; $string['anyfile'] = 'Any file'; $string['attachment'] = 'Attachment'; +$string['attachments'] = 'Attachments'; $string['attachmentnopost'] = 'You cannot export attachments without a post id'; $string['blockafter'] = 'Post threshold for blocking'; $string['blockperiod'] = 'Time period for blocking'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index cfe3ee599d..8672ae7ddf 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -3072,7 +3072,7 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa $p = array( 'postid' => $post->id, ); - //$commands[] = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false, true); + $commands[] = portfolio_add_button('forum_portfolio_caller', $p, '/mod/forum/lib.php', false, true); } echo '
'; @@ -7045,32 +7045,111 @@ class forum_portfolio_caller extends portfolio_module_caller_base { } function prepare_package($tempdir) { - global $CFG; - if ($this->attachment) { + global $CFG, $SESSION; + // either a whole discussion + // a single post, with or without attachment + // or just an attachment with no post + if (!$this->post) { // whole discussion + portfolio_exporter::raise_error('exoprting whole discussion not implemented - see MDL-15758'); + // @todo see MDL-15758 + } else { if ($basedir = forum_file_area($this->post)) { //@todo penny fix all this with files api require_once($CFG->dirroot . '/backup/lib.php'); - return backup_copy_file($basedir, $tempdir); + $status = backup_copy_file($basedir, $tempdir); + if ($this->attachment) { + return $status; // all we need to do + } } - return true; + $post = $this->prepare_post($this->post); + // @todo penny convert to files api + $status = $status && ($handle = fopen($tempdir . '/post.html', 'w')); + $status = $status && fwrite($handle, $post); + $status = $status && fclose($handle); + return $status; } - portfolio_exporter::raise_error('TODO - see MDL-15758'); - // @todo see MDL-15758 + } + + /** + * this is a very cut down version of what is in forum_make_mail_post + */ + private function prepare_post($post) { + global $DB; + static $users; + if (empty($users)) { + $users = array($this->user->id => $this->user); + } + if (!array_key_exists($post->userid, $users)) { + $users[$post->userid] = $DB->get_record('user', array('id' => $post->userid)); + } + $viewfullnames = true; + // format the post body + $options = new object(); + $options->para = true; + $formattedtext = format_text(trusttext_strip($post->message), $post->format, $options, $this->get('course')->id); + + $output = ''; + + $output .= ''; + + if ($post->parent) { + $output .= ''; + + $output .= '
';// can't print picture. + $output .= ''; + } else { + $output .= ''; + } + $output .= '
'.format_string($post->subject).'
'; + + $fullname = fullname($users[$post->userid], $viewfullnames); + $by = new object(); + $by->name = $fullname; + $by->date = userdate($post->modified, '', $this->user->timezone); + $output .= '
'.get_string('bynameondate', 'forum', $by).'
'; + + $output .= '
'; + + $output .= ''; + + $output .= $formattedtext; + + if ($post->attachment) { + $post->course = $this->get('course')->id; + $output .= '
'; + if ($basedir = forum_file_area($this->post)) { + if ($files = get_directory_list($basedir)) { + $output .= '
' . get_string('attachments', 'forum') . ':

'; + foreach ($files as $file) { + $output .= clean_filename($file) . '
'; + } + } + } + $output .= "
"; + } + + $output .= '
'."\n\n"; + + return $output; } function get_sha1() { - if ($this->attachment) { + if ($this->post) { + $attachsha1 = ''; if ($basedir = forum_file_area($this->post)) { $sha1s = array(); foreach (get_directory_list($basedir) as $file) { $sha1s[] = sha1_file($basedir . '/' . $file); } asort($sha1s); - return sha1(implode('', $sha1s)); + $attachsha1 = sha1(implode('', $sha1s)); + if ($this->attachment) { + return $attachsha1; // all we have to do + } } - return false; + return sha1($attachsha1 . ',' . $this->post->subject . ',' . $this->post->message); } - portfolio_exporter::raise_error('TODO - see MDL-15758'); + portfolio_exporter::raise_error('exporting whole discussion not implemented - see MDL-15758'); // @todo see MDL-15758 } -- 2.39.5