Skip to content

Commit

Permalink
#32: prevent any output after EOF
Browse files Browse the repository at this point in the history
  • Loading branch information
macjohnny committed Nov 13, 2017
1 parent e546239 commit 42385a4
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
22 changes: 22 additions & 0 deletions Classes/Hooks/TypoScriptFrontendController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace Bithost\Pdfviewhelpers\Hooks;

use TYPO3\CMS\Core\SingletonInterface;

class TypoScriptFrontendController implements SingletonInterface {

/**
* Prevent any output when a pdf is rendered, especially any headers being set!
*
* @param array $params Parameters from frontend
* @param object $ref TSFE object
* @return void
*/
function isOutputting(&$params, $ref) {
if (isset($params['pObj']->applicationData['tx_pdfviewhelpers']['pdfOutput'])
&& $params['pObj']->applicationData['tx_pdfviewhelpers']['pdfOutput'] === true) {
$params['enableOutput'] = false;
}
}
}
5 changes: 5 additions & 0 deletions Classes/ViewHelpers/DocumentViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ public function initializeArguments() {
* @return void
*/
public function initialize() {
if (!isset($GLOBALS['TSFE']->applicationData['tx_pdfviewhelpers'])){
$GLOBALS['TSFE']->applicationData['tx_pdfviewhelpers'] = array();
}
$GLOBALS['TSFE']->applicationData['tx_pdfviewhelpers']['pdfOutput'] = true;

This comment has been minimized.

Copy link
@liayn

liayn Feb 5, 2018

Contributor

This check is a very bad idea! It breaks in BE context, where there is no TSFE!
In this case you create a TSFE dynamic class stdClass by assigning some property.

In line 122 below, then we have an insufficient check whether TSFE is there and you call set_no_cache there on the just created stdClass => bumm


$extPath = ExtensionManagementUtility::extPath('pdfviewhelpers');
$pdfClassName = empty($this->settings['config']['class']) ? 'TCPDF' : $this->settings['config']['class'];

Expand Down
4 changes: 4 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php


$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['isOutputting']['tx_pdfviewhelpers'] = \Bithost\Pdfviewhelpers\Hooks\TypoScriptFrontendController::class.'->isOutputting';
2 changes: 1 addition & 1 deletion ext_tables.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
die ('Access denied.');
}

\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'pdfviewhelepers');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'pdfviewhelpers');

0 comments on commit 42385a4

Please sign in to comment.