[TASK] Streamline usage of PageRenderer
[Packages/TYPO3.CMS.git] / typo3 / sysext / frontend / Classes / Page / FramesetRenderer.php
1 <?php
2 namespace TYPO3\CMS\Frontend\Page;
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 use TYPO3\CMS\Core\TypoScript\TemplateService;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Rendering of framesets
22 *
23 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
24 */
25 class FramesetRenderer {
26
27 /**
28 * Generates a frameset based on input configuration in a TypoScript array.
29 *
30 * @param array $setup The TypoScript properties of the PAGE object property "frameSet.". See link.
31 * @return string A <frameset> tag.
32 * @see \TYPO3\CMS\Frontend\Page\PageGenerator::renderContentWithHeader()
33 */
34 public function make($setup) {
35 $content = '';
36 if (is_array($setup)) {
37 $sKeyArray = TemplateService::sortedKeyList($setup);
38 foreach ($sKeyArray as $theKey) {
39 $theValue = $setup[$theKey];
40 if ((int)$theKey && ($conf = $setup[$theKey . '.'])) {
41 switch ($theValue) {
42 case 'FRAME':
43 $typeNum = (int)$GLOBALS['TSFE']->tmpl->setup[$conf['obj'] . '.']['typeNum'];
44 if (!$conf['src'] && !$typeNum) {
45 $typeNum = -1;
46 }
47 $content .= '<frame' . $this->frameParams($conf, $typeNum) . ' />' . LF;
48 break;
49 case 'FRAMESET':
50 $frameset = GeneralUtility::makeInstance(__CLASS__);
51 $content .= $frameset->make($conf) . LF;
52 break;
53 }
54 }
55 }
56 return '<frameset' . $this->framesetParams($setup) . '>' . LF . $content . '</frameset>';
57 }
58 }
59
60 /**
61 * Creates the attributes for a <frame> tag based on a $conf array and the type number
62 *
63 * @param array $setup Configuration for the parameter generation for the FRAME set. See link
64 * @param int $typeNum The typenumber to use for the link.
65 * @return string String with attributes for the frame-tag. With a prefixed space character.
66 * @access private
67 * @link http://typo3.org/documentation/document-library/references/doc_core_tsref/current/view/7/9/
68 */
69 public function frameParams($setup, $typeNum) {
70 $paramStr = '';
71 $name = $setup['obj'];
72 if ($setup['src'] || $setup['src.']) {
73 $src = $setup['src'];
74 if (is_array($setup['src.'])) {
75 $src = $GLOBALS['TSFE']->cObj->stdWrap($src, $setup['src.']);
76 }
77 $paramStr .= ' src="' . htmlspecialchars($src) . '"';
78 } else {
79 $LD = $GLOBALS['TSFE']->tmpl->linkData($GLOBALS['TSFE']->page, '', $GLOBALS['TSFE']->no_cache, '', '', ($setup['options'] ? '&' . $setup['options'] : '') . $GLOBALS['TSFE']->cObj->getClosestMPvalueForPage($GLOBALS['TSFE']->page['uid']), (int)$typeNum);
80 $finalURL = $LD['totalURL'];
81 $paramStr .= ' src="' . htmlspecialchars($finalURL) . '"';
82 }
83 if ($setup['name']) {
84 $paramStr .= ' name="' . $setup['name'] . '"';
85 } else {
86 $paramStr .= ' name="' . $name . '"';
87 }
88 if ($setup['params']) {
89 $paramStr .= ' ' . $setup['params'];
90 }
91 return $paramStr;
92 }
93
94 /**
95 * Creates the attributes for a <frameset> tag based on a conf array($setup)
96 *
97 * @param array $setup The setup array(TypoScript properties)
98 * @return string Attributes with preceding space.
99 * @access private
100 * @see make()
101 */
102 public function framesetParams($setup) {
103 $paramStr = '';
104 if ($setup['cols']) {
105 $paramStr .= ' cols="' . $setup['cols'] . '"';
106 }
107 if ($setup['rows']) {
108 $paramStr .= ' rows="' . $setup['rows'] . '"';
109 }
110 if ($setup['params']) {
111 $paramStr .= ' ' . $setup['params'];
112 }
113 return $paramStr;
114 }
115
116 }