[FEATURE] stdWrap caching
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_tableoffset.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2012 Kasper Skårhøj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * Rendering of tables for offset
30 *
31 * @see tslib_cObj::OTABLE(), tslib_cObj::stdWrap()
32 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
33 * @package TYPO3
34 * @subpackage tslib
35 */
36 class tslib_tableOffset {
37 var $tableParams = 'border="0" cellspacing="0" cellpadding="0"';
38 var $default_tableParams = 'border="0" cellspacing="0" cellpadding="0"';
39 var $tdParams = ' width="99%" valign="top"';
40
41 /**
42 * Wrapping the input content string in a table which will space it out from top/left/right/bottom
43 *
44 * @param string The HTML content string
45 * @param string List of offset parameters; x,y,r,b,w,h
46 * @return string The HTML content string being wrapped in a <table> offsetting the content as the $offset parameters defined
47 */
48 function start($content, $offset) {
49 $valPairs = t3lib_div::intExplode(',', $offset . ',,,,,');
50
51 if ($valPairs[0] || $valPairs[1] || $valPairs[2] || $valPairs[3] || $valPairs[4] || $valPairs[5]) {
52 // If width is defined AND there has been no change to the default table params, then extend them to a tablewidth of 1
53 if ($valPairs[4] && $this->default_tableParams == $this->tableParams) {
54 $this->tableParams .= ' width="1"';
55 }
56 // Init:
57 $this->begin = LF . '<table ' . $this->tableParams . '>';
58 $this->end = '</table>';
59 $rows = array();
60 $widthImg = '';
61 $heightImg = '';
62 // If width is required, set so bottom column will display for sure
63 if ($valPairs[4]) {
64 if (!$valPairs[3])
65 $valPairs[3] = 1;
66 $widthImg = '<img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' .
67 $valPairs[4] . '" height="1" alt="" title="" />';
68 }
69 // If height is required, set so right column will display for sure
70 if ($valPairs[5]) {
71 if (!$valPairs[2])
72 $valPairs[2] = 1;
73 $valPairs[2] = 1;
74 $heightImg = '<img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="1" height="' .
75 $valPairs[5] . '" alt="" title="" />';
76 }
77
78 // First row:
79 if ($valPairs[1]) { // top
80 $rows[1] .= '<tr>';
81 $rows[1] .= '<td><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' .
82 ($valPairs[0] ? $valPairs[0] : 1) . '" height="' . $valPairs[1] . '" alt="" title="" /></td>';
83 if ($valPairs[0])
84 $rows[1] .= '<td></td>';
85 if ($valPairs[2])
86 $rows[1] .= '<td></td>';
87 $rows[1] .= '</tr>';
88 }
89 // Middle row:
90 $rows[2] .= '<tr>';
91 if ($valPairs[0]) {
92 $rows[2] .= $valPairs[1] ? '<td></td>' : '<td><img src="' . $GLOBALS['TSFE']->absRefPrefix .
93 'clear.gif" width="' . $valPairs[0] . '" height="1" alt="" title="" /></td>';
94 }
95 $rows[2] .= '<td' . $this->tdParams . '>' . $content . '</td>';
96 if ($valPairs[2]) {
97 $rows[2] .= $valPairs[3] ? '<td>' . $heightImg . '</td>' : '<td><img src="' .
98 $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' . $valPairs[2] . '" height="' .
99 ($valPairs[5] ? $valPairs[5] : 1) . '" alt="" title="" /></td>';
100 }
101 $rows[2] .= '</tr>';
102 // Bottom row:
103 if ($valPairs[3]) { // bottom
104 $rows[3] .= '<tr>';
105 if ($valPairs[0])
106 $rows[3] .= '<td></td>';
107 if ($valPairs[2])
108 $rows[3] .= '<td>' . $widthImg . '</td>';
109 $rows[3] .= '<td><img src="' . $GLOBALS['TSFE']->absRefPrefix . 'clear.gif" width="' .
110 ($valPairs[2] ? $valPairs[2] : ($valPairs[4] ? $valPairs[4] : 1)) . '" height="' .
111 $valPairs[3] . '" alt="" title="" /></td>';
112 $rows[3] .= '</tr>';
113 }
114 return $this->begin . implode('', $rows) . $this->end;
115 } else
116 return $content;
117 }
118 }
119
120 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_tableoffset.php'])) {
121 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/class.tslib_tableoffset.php']);
122 }
123
124 ?>