FilesizeViewHelper.php 1.11 KB
Newer Older
1
<?php
2 3
namespace T3o\TerFe2\ViewHelpers;

4 5
/*
 * This file is part of the TYPO3 CMS project.
6
 *
7 8 9
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
10
 *
11 12
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
13
 *
14 15
 * The TYPO3 project - inspiring people to share!
 */
16

17 18 19
/**
 * Filesize view helper
 */
20
class FilesizeViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper
21
{
22

23 24 25
    /**
     * Disable the escaping interceptor
     */
Markus Sommer's avatar
Markus Sommer committed
26
    protected $escapingInterceptorEnabled = false;
27

28 29 30
    /**
     * Renders filesize in given format
     *
31
     * @param int $filesize Filesize in bytes
32 33
     * @return string New file size in given format
     */
Markus Sommer's avatar
Markus Sommer committed
34
    public function render($filesize = null)
35
    {
Markus Sommer's avatar
Markus Sommer committed
36
        if ($filesize === null) {
37 38
            $filesize = $this->renderChildren();
        }
39

40
        $filesize = (int)$filesize;
41
        return \TYPO3\CMS\Core\Utility\GeneralUtility::formatSize($filesize, 'B|kB|MB|GB');
42 43
    }
}