diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/request_controller.rb | 6 | ||||
-rw-r--r-- | app/models/incoming_message.rb | 14 |
2 files changed, 15 insertions, 5 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 5a03f0317..d2500dc21 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -578,12 +578,12 @@ class RequestController < ApplicationController # the same cache code in cache_attachments above will display them. image_dir = File.dirname(ActionController::Base.cache_store.cache_path + "/views" + url_for(params.merge(:only_path => true))) FileUtils.mkdir_p(image_dir) - html = @attachment.body_as_html(image_dir) + html, wrapper_class = @attachment.body_as_html(image_dir) view_html_stylesheet = render_to_string :partial => "request/view_html_stylesheet" html.sub!(/<head>/i, "<head>" + view_html_stylesheet) - html.sub!(/<body[^>]*>/i, '<body><prefix-here><div id="wrapper"><div id="view_html_content">' + view_html_stylesheet) - html.sub!(/<\/body[^>]*>/i, '</div></div></body>' + view_html_stylesheet) + html.sub!(/<body[^>]*>/i, '<body><prefix-here><div id="wrapper" class="' + wrapper_class + '"><div id="view_html_content">') + html.sub!(/<\/body[^>]*>/i, '</div></div></body>') view_html_prefix = render_to_string :partial => "request/view_html_prefix" html.sub!("<prefix-here>", view_html_prefix) diff --git a/app/models/incoming_message.rb b/app/models/incoming_message.rb index 81cbffe06..242fc3ebf 100644 --- a/app/models/incoming_message.rb +++ b/app/models/incoming_message.rb @@ -313,6 +313,8 @@ class FOIAttachment return true elsif self.content_type == 'application/vnd.ms-word' return true + elsif self.content_type == 'application/vnd.ms-excel' + return true elsif self.content_type == 'application/pdf' return true elsif self.content_type == 'application/rtf' @@ -327,6 +329,8 @@ class FOIAttachment return "Text file" elsif self.content_type == 'application/vnd.ms-word' return "Word document" + elsif self.content_type == 'application/vnd.ms-excel' + return "Excel spreadsheet" elsif self.content_type == 'application/pdf' return "PDF file" elsif self.content_type == 'application/rtf' @@ -337,6 +341,7 @@ class FOIAttachment # For "View as HTML" of attachment def body_as_html(dir) html = nil + wrapper_class = "default_output" # simple cases, can never fail if self.content_type == 'text/plain' @@ -344,7 +349,7 @@ class FOIAttachment text = CGI.escapeHTML(text) text = MySociety::Format.make_clickable(text) html = text.gsub(/\n/, '<br>') - return "<html><head></head><body>" + html + "</body></html>" + return "<html><head></head><body>" + html + "</body></html>", wrapper_class end # the extractions will also produce image files, which go in the @@ -360,6 +365,11 @@ class FOIAttachment system("/usr/bin/wvHtml --charset=UTF-8 " + tempfile.path + " " + tempfile.path + ".html") html = File.read(tempfile.path + ".html") File.unlink(tempfile.path + ".html") + elsif self.content_type == 'application/vnd.ms-excel' + IO.popen("/usr/bin/xlhtml -a " + tempfile.path + "", "r") do |child| + html = child.read() + wrapper_class = "xhtml_output" + end elsif self.content_type == 'application/pdf' IO.popen("/usr/bin/pdftohtml -nodrm -zoom 1.0 -stdout -enc UTF-8 -noframes " + tempfile.path + "", "r") do |child| html = child.read() @@ -391,7 +401,7 @@ class FOIAttachment return "<html><head></head><body><p>Sorry, the conversion to HTML failed. Please use the download link at the top right.</p></body></html>" end - return html + return html, wrapper_class end end |