Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - GGeczy

Pages: [1]
1
How To's / Re: PDF Viewing - MIME application/pdf
« on: November 21, 2011, 12:34:37 am »
Oh and where it says "[blocked]" in the iframe section replace it with "https" and a colon and two slashes, no quotation marks - it won't let me post anything that looks like a web link in my message.


2
How To's / Re: PDF Viewing - MIME application/pdf
« on: November 21, 2011, 12:32:58 am »

The suggested solution to embed the PDF in a frame has the issue that it may not work if the client system has their browser set to not show PDF files in-browser.  So this may instead force a download of the PDF or cause other oddities.

However I took the above concept and tackled it from a different side, using the Google Viewer application to do the preview for me.  (Google allows the embedding of this, see  docs.google.com/viewer for information).

Using this, I can provide previews of not just PDF but also DOC, XLS, PPT, etc.

For those interested here is how it was implemented:

In /application/views/files/file_details_content.php :

 
Code: [Select]
<?php
 
   
if (substr($file->getFilename(), -3) == 'pdf' || substr($file->getFilename(), -3) == 'doc' || substr($file->getFilename(), -3) == 'xls' || substr($file->getFilename(), -3) == 'ppt' || substr($file->getFilename(), -4) == 'docx' || substr($file->getFilename(), -4) == 'pptx' || substr($file->getFilename(), -4) == 'xlsx'){
      echo
'<div>';
      if(
$file->getType() != ProjectFiles::TYPE_WEBLINK){       
// WAS:        $urlpdf=get_url('files', 'download_image', array('id' => $file->getId(), 'inline' => true, 'modtime' => $modtime));
// GG: Instead, need to use a sandbox URL, so that the non-logged in site (google) can access the document using a user token....
$urlpdfget_sandbox_url("feed""display_content", array("id" => $file->getId(), "user_id" => logged_user()->getId(), "token" => logged_user()->getTwistedToken()));
      }else{      
        
$urlpdf=$file->getUrl();
      }
      
// WAS: echo "<iframe src=".$urlpdf." width='100%' height='900px' frameborder=0 align='center'></iframe>";
      // GG: Try google embed:  (encode some of the url characters)
      
$urlpdf str_replace('&''%26'$urlpdf);
      
$urlpdf str_replace('?''%3F'$urlpdf);
      
$urlpdf str_replace('=''%3D'$urlpdf);
      
$urlpdf str_replace('/''%2F'$urlpdf);
      
$urlpdf str_replace(':''%3A'$urlpdf);
      echo 
"<iframe src=[blocked]docs.google.com/viewer?embedded=true&url=".$urlpdf." width='100%' height='900px' frameborder=0 align='center'></iframe>";
 
      echo 
'</div>';
   }
 
?>


I also needed to change
 /application/controllers/FileController.class.php :

Edited in function display_content(), to allow proper downloading of PDF etc files :
 
Code: [Select]
if ($file->getTypeString() == 'text/html') {
header("Expires: " . gmdate("D, d M Y H:i:s", mktime(date("H") + 2, date("i"), date("s"), date("m"), date("d"), date("Y"))) . " GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Content-Type: " . $file->getTypeString() . $charset);
header("Content-Length: " . (string) strlen($html_content));
 
print($html_content);
} else {
download_from_repository($file->getLastRevision()->getRepositoryId(), $file->getTypeString(), $file->getFilename(), !$inline);

}

The "print($html_content)" didn't support sending the PDF data, so if not text then it uses download_from_repository instead.

Note that this embed does use the "login via token" feature that seems to exist for the RSS feed support...  as such, it contains the same security issue that has been discussed on these forums for the token URLs - if you are not accessing your site via https then there could be over-the-wire leakage of a URL that would allow viewing content without login.

Pages: [1]