Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Make viewhelpers PHP 7 compatible #59

Merged
merged 1 commit into from Jan 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 35 additions & 8 deletions Classes/ViewHelpers/DownloadLinkViewHelper.php
Expand Up @@ -24,32 +24,59 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\FileInterface;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;

/**
* Download link view helper. Generates links that force a download action.
*/
class DownloadLinkViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Link\ExternalViewHelper
class DownloadLinkViewHelper extends AbstractTagBasedViewHelper
{

/**
* @var string
*/
protected $tagName = 'a';

/**
* Initialize arguments
*
* @return void
* @api
*/
public function initializeArguments() {
$this->registerUniversalTagAttributes();
$this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
$this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
$this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
$this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
$this->registerArgument('file', 'object', '', true);
$this->registerArgument('uriOnly', 'bool', '', false, false);
}

/**
* Create a link to a file that forces a download
*
* @param \TYPO3\CMS\Core\Resource\FileInterface $file
* @param bool $uriOnly
* @return string
*/
public function render(\TYPO3\CMS\Core\Resource\FileInterface $file, $uriOnly = false)
public function render()
{
/** @var FileInterface $file */
$file = $this->arguments['file'];

$queryParameterArray = array('eID' => 'dumpFile', 't' => '');
if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
if ($file instanceof File) {
$queryParameterArray['f'] = $file->getUid();
$queryParameterArray['t'] = 'f';
} elseif ($file instanceof \TYPO3\CMS\Core\Resource\ProcessedFile) {
} elseif ($file instanceof ProcessedFile) {
$queryParameterArray['p'] = $file->getUid();
$queryParameterArray['t'] = 'p';
}

$queryParameterArray['token'] = \TYPO3\CMS\Core\Utility\GeneralUtility::hmac(implode('|', $queryParameterArray),
$queryParameterArray['token'] = GeneralUtility::hmac(implode('|', $queryParameterArray),
'resourceStorageDumpFile');
$queryParameterArray['download'] = '';
$uri = 'index.php?' . str_replace('+', '%20', http_build_query($queryParameterArray));
Expand All @@ -59,7 +86,7 @@ public function render(\TYPO3\CMS\Core\Resource\FileInterface $file, $uriOnly =
$uri = $GLOBALS['TSFE']->absRefPrefix . $uri;
}

if ($uriOnly) {
if ($this->arguments['uriOnly']) {
return $uri;
}

Expand Down
18 changes: 13 additions & 5 deletions Classes/ViewHelpers/LeaveStateViewHelper.php
Expand Up @@ -25,24 +25,32 @@
***************************************************************/

use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;

/**
* Class LeaveStateViewHelper
*
* @package BeechIt\FalSecuredownload\ViewHelpers
*/
class LeaveStateViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper
class LeaveStateViewHelper extends AbstractConditionViewHelper
{

public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('folder', 'object', '', true);
}

/**
* renders <f:then> child if the current visitor ...
* otherwise renders <f:else> child.
*
* @param Folder $folder
* @return string
*/
public function render(Folder $folder)
public function render()
{
/** @var Folder $folder */
$folder = $this->arguments['folder'];

/** @var $leafStateService \BeechIt\FalSecuredownload\Service\LeafStateService */
$leafStateService = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('BeechIt\\FalSecuredownload\\Service\\LeafStateService');
Expand All @@ -54,4 +62,4 @@ public function render(Folder $folder)
return $this->renderElseChild();
}
}
}
}
23 changes: 13 additions & 10 deletions Classes/ViewHelpers/Security/AssetAccessViewHelper.php
Expand Up @@ -27,30 +27,31 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper;

/**
* Asset access ViewHelper
*
* @package BeechIt\FalSecuredownload\ViewHelpers\Security
*/
class AssetAccessViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractConditionViewHelper
class AssetAccessViewHelper extends AbstractConditionViewHelper
{
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('folder', 'object', '', true);
$this->registerArgument('file', 'object', '', false, null);
}

/**
* renders <f:then> child if the current logged in FE user has access to the given asset
* otherwise renders <f:else> child.
*
* @param Folder $folder
* @param File $file
* @return bool|string
* @return string
*/
public function render(Folder $folder, File $file = null)
public function render()
{
if (self::evaluateCondition(array('folder' => $folder, 'file' => $file))) {
return $this->renderThenChild();
} else {
return $this->renderElseChild();
}
return self::evaluateCondition($this->arguments) ? $this->renderThenChild() : $this->renderElseChild();
}

/**
Expand All @@ -61,7 +62,9 @@ public function render(Folder $folder, File $file = null)
*/
protected static function evaluateCondition($arguments = null)
{
/** @var Folder $folder */
$folder = $arguments['folder'];
/** @var File $file */
$file = $arguments['file'];

/** @var $checkPermissionsService \BeechIt\FalSecuredownload\Security\CheckPermissions */
Expand Down