From 548e25cd2c1ecee9bcbcc4a5f5386c74e3a702f8 Mon Sep 17 00:00:00 2001
From: Simon Story <simon.story@catalyst-eu.net>
Date: Tue, 13 Mar 2012 14:45:09 +0000
Subject: [PATCH] Fixes to forum export so that exported files pass basic weblint

---
 mod/forum/locallib.php |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/mod/forum/locallib.php b/mod/forum/locallib.php
index a140380..70d7f50 100644
--- a/mod/forum/locallib.php
+++ b/mod/forum/locallib.php
@@ -188,6 +188,9 @@ class forum_portfolio_caller extends portfolio_module_caller_base {
 
         } else if (empty($this->post)) {  // exporting whole discussion
             $content = ''; // if we're just writing HTML, start a string to add each post to
+            if (!$writingleap) {
+              $content = '<html><head><title></title></head><body>'; // Required basic html headers
+            }
             $ids = array(); // if we're writing leap2a, keep track of all entryids so we can add a selection element
             foreach ($this->posts as $post) {
                 $posthtml =  $this->prepare_post($post);
@@ -208,13 +211,18 @@ class forum_portfolio_caller extends portfolio_module_caller_base {
                 $leapwriter->make_selection($selection, $ids, 'Grouping');
                 $content = $leapwriter->to_xml();
                 $name = $this->get('exporter')->get('format')->manifest_name();
+            } else {
+              $content = $content . '</body></html>';
             }
             $this->get('exporter')->write_new_file($content, $name, $manifest);
 
-        } else { // exporting a single post
+            } else { // exporting a single post
+            if (!$writingleap) {
+              $content = '<html><head><title></title></head><body>';
+            }
             $posthtml = $this->prepare_post($this->post);
 
-            $content = $posthtml;
+            $content = $content . $posthtml;
             $name = 'post.html';
             $manifest = ($this->exporter->get('format') instanceof PORTFOLIO_FORMAT_RICH);
 
@@ -222,6 +230,8 @@ class forum_portfolio_caller extends portfolio_module_caller_base {
                 $this->prepare_post_leap2a($leapwriter, $this->post, $posthtml);
                 $content = $leapwriter->to_xml();
                 $name = $this->exporter->get('format')->manifest_name();
+            } else {
+              $content = $content . '</body></html>';
             }
             $this->copy_files($this->multifiles);
             $this->get('exporter')->write_new_file($content, $name, $manifest);
-- 
1.7.0.4

