FramesetRenderer.php 3.57 KB
Newer Older
1
2
3
<?php
namespace TYPO3\CMS\Frontend\Page;

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
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;

20
21
22
23
24
25
26
27
28
29
/**
 * Rendering of framesets
 */
class FramesetRenderer {

	/**
	 * Generates a frameset based on input configuration in a TypoScript array.
	 *
	 * @param array $setup The TypoScript properties of the PAGE object property "frameSet.". See link.
	 * @return string A <frameset> tag.
30
	 * @see \TYPO3\CMS\Frontend\Page\PageGenerator::renderContentWithHeader()
31
32
33
34
	 */
	public function make($setup) {
		$content = '';
		if (is_array($setup)) {
35
			$sKeyArray = TemplateService::sortedKeyList($setup);
36
37
			foreach ($sKeyArray as $theKey) {
				$theValue = $setup[$theKey];
38
				if ((int)$theKey && ($conf = $setup[$theKey . '.'])) {
39
					switch ($theValue) {
40
						case 'FRAME':
41
							$typeNum = (int)$GLOBALS['TSFE']->tmpl->setup[$conf['obj'] . '.']['typeNum'];
42
43
44
45
46
47
							if (!$conf['src'] && !$typeNum) {
								$typeNum = -1;
							}
							$content .= '<frame' . $this->frameParams($conf, $typeNum) . ' />' . LF;
							break;
						case 'FRAMESET':
48
							$frameset = GeneralUtility::makeInstance(__CLASS__);
49
50
							$content .= $frameset->make($conf) . LF;
							break;
51
52
53
					}
				}
			}
54
			return '<frameset' . $this->framesetParams($setup) . '>' . LF . $content . '</frameset>';
55
56
57
58
59
60
61
		}
	}

	/**
	 * Creates the attributes for a <frame> tag based on a $conf array and the type number
	 *
	 * @param array $setup Configuration for the parameter generation for the FRAME set. See link
62
	 * @param int $typeNum The typenumber to use for the link.
63
64
	 * @return string String with attributes for the frame-tag. With a prefixed space character.
	 * @access private
65
	 * @link https://docs.typo3.org/typo3cms/TyposcriptReference/Setup/Frameset/
66
67
68
69
70
71
72
73
74
	 */
	public function frameParams($setup, $typeNum) {
		$paramStr = '';
		$name = $setup['obj'];
		if ($setup['src'] || $setup['src.']) {
			$src = $setup['src'];
			if (is_array($setup['src.'])) {
				$src = $GLOBALS['TSFE']->cObj->stdWrap($src, $setup['src.']);
			}
75
			$paramStr .= ' src="' . htmlspecialchars($src) . '"';
76
		} else {
77
			$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);
78
			$finalURL = $LD['totalURL'];
79
			$paramStr .= ' src="' . htmlspecialchars($finalURL) . '"';
80
81
		}
		if ($setup['name']) {
82
			$paramStr .= ' name="' . $setup['name'] . '"';
83
		} else {
84
			$paramStr .= ' name="' . $name . '"';
85
86
87
88
89
90
91
92
93
94
95
		}
		if ($setup['params']) {
			$paramStr .= ' ' . $setup['params'];
		}
		return $paramStr;
	}

	/**
	 * Creates the attributes for a <frameset> tag based on a conf array($setup)
	 *
	 * @param array $setup The setup array(TypoScript properties)
96
	 * @return string Attributes with preceding space.
97
98
99
100
101
102
	 * @access private
	 * @see make()
	 */
	public function framesetParams($setup) {
		$paramStr = '';
		if ($setup['cols']) {
103
			$paramStr .= ' cols="' . $setup['cols'] . '"';
104
105
		}
		if ($setup['rows']) {
106
			$paramStr .= ' rows="' . $setup['rows'] . '"';
107
108
109
110
111
112
113
114
		}
		if ($setup['params']) {
			$paramStr .= ' ' . $setup['params'];
		}
		return $paramStr;
	}

}