[TASK] Re-work/simplify copyright header in PHP files - Part 2
[Packages/TYPO3.CMS.git] / typo3 / sysext / documentation / Classes / ViewHelpers / FormatsViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Documentation\ViewHelpers;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * ViewHelper to display all download links for a document
19 *
20 * Example: <doc:formats document="{document}" />
21 */
22 class FormatsViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {
23
24 /**
25 * Renders all format download links.
26 *
27 * @param \TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation
28 * @return string
29 */
30 public function render(\TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation) {
31 $output = '';
32 foreach ($documentTranslation->getFormats() as $format) {
33 /** @var \TYPO3\CMS\Documentation\Domain\Model\DocumentFormat $format */
34 $output .= '<a ';
35
36 $uri = '../' . $format->getPath();
37 $extension = substr($uri, strrpos($uri, '.') + 1);
38 if (strlen($extension) < 5) {
39 // This is direct link to a file
40 $output .= 'href="' . $uri . '"';
41 } else {
42 $extension = $format->getFormat();
43 if ($extension === 'json') {
44 $extension = 'js';
45 }
46 $output .= 'href="#" onclick="top.TYPO3.Backend.ContentContainer.setUrl(\'' . $uri . '\')"';
47 }
48
49 $xliff = 'LLL:EXT:documentation/Resources/Private/Language/locallang.xlf';
50 $title = sprintf(
51 $GLOBALS['LANG']->sL($xliff . ':tx_documentation_domain_model_documentformat.format.title'),
52 $format->getFormat()
53 );
54 $output .= ' title="' . htmlspecialchars($title) . '">';
55 $spriteIconHtml = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForFile($extension);
56 $output .= $spriteIconHtml . '</a>' . LF;
57 }
58 return $output;
59 }
60
61 }