AndyB
Well-known member
You'll need to reroute within renderRaw.
How would I reroute within renderRaw ??
You'll need to reroute within renderRaw.
if ($extension === 'pdf') {
$this->_response->setHeader('Content-type', 'application/pdf', true);
$this->setDownloadFileName($attachment['filename'], true);
return new XenForo_FileOutput($this->_params['attachmentFile'])
} else {
return parent::renderRaw();
}
Slightly off topic, but what exactly are you hoping this add-on would do?
I'm familiar with some of the code in this class, and I'm not entirely convinced that adding that line to that array would actually do anything.
Then you don't want to use a new function. You'll need to extend and overwrite renderRaw(). Then do basically the same exact code, just simplify it:
PHP:if ($extension === 'pdf') { $this->_response->setHeader('Content-type', 'application/pdf', true); $this->setDownloadFileName($attachment['filename'], true); return new XenForo_FileOutput($this->_params['attachmentFile']) } else { return parent::renderRaw(); }
I see. That behaviour is slightly browser and software dependent, though.
In Google Chrome, PDF files automatically open in the browser.
My previous code explains where to put it.
Then you don't want to use a new function. You'll need to extend and overwrite renderRaw(). Then do basically the same exact code, just simplify it:
PHP:if ($extension === 'pdf') { $this->_response->setHeader('Content-type', 'application/pdf', true); $this->setDownloadFileName($attachment['filename'], true); return new XenForo_FileOutput($this->_params['attachmentFile']) } else { return parent::renderRaw(); }
<?php
class Andy_OpenPDF_ViewPublic_Attachment_View extends XFCP_Andy_OpenPDF_ViewPublic_Attachment_View
{
public function renderRaw()
{
$attachment = $this->_params['attachment'];
$extension = XenForo_Helper_File::getFileExtension($attachment['filename']);
if ($extension === 'pdf')
{
$this->_response->setHeader('Content-type', 'application/pdf', true);
$this->setDownloadFileName($attachment['filename'], true);
return new XenForo_FileOutput($this->_params['attachmentFile']);
} else {
return parent::renderRaw();
}
}
}
?>
$this->_response->setHeader('ETag', $attachment['attach_date'], true);
$this->_response->setHeader('Content-Length', $attachment['file_size'], true);
$this->_response->setHeader('X-Content-Type-Options', 'nosniff');
return new XenForo_FileOutput($this->_params['attachmentFile']);
<?php
class Andy_OpenPDF_ViewPublic_Attachment_View extends XFCP_Andy_OpenPDF_ViewPublic_Attachment_View
{
//########################################
// the original renderRaw() function is located in library/Xenforo/ViewPublic/Attachment/View.php
// this renderRaw() will run instead of the original unless we the return parent::renderRaw()
//########################################
public function renderRaw()
{
$attachment = $this->_params['attachment'];
$extension = XenForo_Helper_File::getFileExtension($attachment['filename']);
if ($extension === 'pdf')
{
$this->_response->setHeader('Content-type', 'application/pdf', true);
$this->setDownloadFileName($attachment['filename'], true);
$this->_response->setHeader('ETag', $attachment['attach_date'], true);
$this->_response->setHeader('Content-Length', $attachment['file_size'], true);
$this->_response->setHeader('X-Content-Type-Options', 'nosniff');
return new XenForo_FileOutput($this->_params['attachmentFile']);
} else {
// run the original renderRaw() function
return parent::renderRaw();
}
}
}
?>
OpenAttachments, you name the setting OpenAttachmentsExtensions
Attachments (Attachment Type => ApplicationType):
pdf => application/pdf
abc => image/abcde
$extensions = array(
pdf => 'application/pdf',
abc => 'image/abcde');
public function renderRaw()
{ $attachment = $this->_params['attachment'];$extension = XenForo_Helper_File::getFileExtension($attachment['filename']);
$extensions = XenForo_Application::get('options')->get('OpenAttachmentsExtensions');
if (isset($extensions[$extension]))
{$this->_response->setHeader('Content-type', $extensions[$extension], true);$this->setDownloadFileName($attachment['filename'], true);
$this->_response->setHeader('ETag', $attachment['attach_date'], true);$this->_response->setHeader('Content-Length', $attachment['file_size'], true);$this->_response->setHeader('X-Content-Type-Options', 'nosniff');
return new XenForo_FileOutput($this->_params['attachmentFile']);
} else {// run the original renderRaw() functionreturn parent::renderRaw();
}
}
We use essential cookies to make this site work, and optional cookies to enhance your experience.