[TASK] Use $x[n] instead of substr($x, n, 1)
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Form / FrontendFormEngine.php
1 <?php
2 namespace TYPO3\CMS\Backend\Form;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2013 Kasper Skårhøj (kasperYYYY@typo3.com)
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Core\Utility\GeneralUtility;
31
32 /**
33 * Extension class for the rendering of TCEforms in the frontend
34 *
35 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
36 */
37 class FrontendFormEngine extends \TYPO3\CMS\Backend\Form\FormEngine {
38
39 /**
40 * Constructs this object.
41 */
42 public function __construct() {
43 $this->initializeTemplateContainer();
44 parent::__construct();
45 }
46
47 /**
48 * Function for wrapping labels.
49 *
50 * @param string $str The string to wrap
51 * @return string
52 */
53 public function wrapLabels($str) {
54 return '<font face="verdana" size="1" color="black">' . $str . '</font>';
55 }
56
57 /**
58 * Prints the palette in the frontend editing (forms-on-page?)
59 *
60 * @param array $paletteArray The palette array to print
61 * @return string HTML output
62 */
63 public function printPalette(array $paletteArray) {
64 $out = '';
65 $bgColor = ' bgcolor="#D6DAD0"';
66 foreach ($paletteArray as $content) {
67 $hRow[] = '<td' . $bgColor . '><font face="verdana" size="1">&nbsp;</font></td><td nowrap="nowrap"' . $bgColor . '><font color="#666666" face="verdana" size="1">' . $content['NAME'] . '</font></td>';
68 $iRow[] = '<td valign="top">' . '<img name="req_' . $content['TABLE'] . '_' . $content['ID'] . '_' . $content['FIELD'] . '" src="clear.gif" width="10" height="10" alt="" />' . '<img name="cm_' . $content['TABLE'] . '_' . $content['ID'] . '_' . $content['FIELD'] . '" src="clear.gif" width="7" height="10" alt="" />' . '</td><td nowrap="nowrap" valign="top">' . $content['ITEM'] . $content['HELP_ICON'] . '</td>';
69 }
70 $out = '<table border="0" cellpadding="0" cellspacing="0">
71 <tr><td><img src="clear.gif" width="' . (int)$this->paletteMargin . '" height="1" alt="" /></td>' . implode('', $hRow) . '</tr>
72 <tr><td></td>' . implode('', $iRow) . '</tr>
73 </table>';
74 return $out;
75 }
76
77 /**
78 * Sets the fancy front-end design of the editor.
79 * Frontend
80 *
81 * @return void
82 */
83 public function setFancyDesign() {
84 $this->fieldTemplate = '
85 <tr>
86 <td nowrap="nowrap" bgcolor="#F6F2E6">###FIELD_HELP_ICON###<font face="verdana" size="1" color="black"><strong>###FIELD_NAME###</strong></font>###FIELD_HELP_TEXT###</td>
87 </tr>
88 <tr>
89 <td nowrap="nowrap" bgcolor="#ABBBB4"><img name="req_###FIELD_TABLE###_###FIELD_ID###_###FIELD_FIELD###" src="clear.gif" width="10" height="10" alt="" /><img name="cm_###FIELD_TABLE###_###FIELD_ID###_###FIELD_FIELD###" src="clear.gif" width="7" height="10" alt="" /><font face="verdana" size="1" color="black">###FIELD_ITEM###</font>###FIELD_PAL_LINK_ICON###</td>
90 </tr> ';
91 $this->totalWrap = '<table border="0" cellpadding="1" cellspacing="0" bgcolor="black"><tr><td><table border="0" cellpadding="2" cellspacing="0">|</table></td></tr></table>';
92 $this->palFieldTemplate = '
93 <tr>
94 <td nowrap="nowrap" bgcolor="#ABBBB4"><font face="verdana" size="1" color="black">###FIELD_PALETTE###</font></td>
95 </tr> ';
96 $this->palFieldTemplateHeader = '
97 <tr>
98 <td nowrap="nowrap" bgcolor="#F6F2E6"><font face="verdana" size="1" color="black"><strong>###FIELD_HEADER###</strong></font></td>
99 </tr> ';
100 }
101
102 /**
103 * Includes a javascript library that exists in the core /typo3/ directory. The
104 * backpath is automatically applied.
105 * This method adds the library to $GLOBALS['TSFE']->additionalHeaderData[$lib].
106 *
107 * @param string $lib Library name. Call it with the full path like "contrib/prototype/prototype.js" to load it
108 * @return void
109 */
110 public function loadJavascriptLib($lib) {
111 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
112 $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
113 $pageRenderer->addJsLibrary($lib, $this->prependBackPath($lib));
114 }
115
116 /**
117 * Insert additional style sheet link
118 *
119 * @param string $key Some key identifying the style sheet
120 * @param string $href Uri to the style sheet file
121 * @param string $title Value for the title attribute of the link element
122 * @param string $relation Value for the rel attribute of the link element
123 * @return void
124 */
125 public function addStyleSheet($key, $href, $title = '', $relation = 'stylesheet') {
126 /** @var $pageRenderer \TYPO3\CMS\Core\Page\PageRenderer */
127 $pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
128 $pageRenderer->addCssFile($this->prependBackPath($href), $relation, 'screen', $title);
129 }
130
131 /**
132 * Initializes an anonymous template container.
133 * The created container can be compared to alt_doc.php in backend-only disposal.
134 *
135 * @return void
136 */
137 public function initializeTemplateContainer() {
138 $GLOBALS['TBE_TEMPLATE'] = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Template\\FrontendDocumentTemplate');
139 $GLOBALS['TBE_TEMPLATE']->getPageRenderer()->addInlineSetting('', 'PATH_typo3', GeneralUtility::dirname(GeneralUtility::getIndpEnv('SCRIPT_NAME')) . '/' . TYPO3_mainDir);
140 $GLOBALS['SOBE'] = new \stdClass();
141 $GLOBALS['SOBE']->doc = $GLOBALS['TBE_TEMPLATE'];
142 }
143
144 /**
145 * Prepends backPath to given URL if it's not an absolute URL
146 *
147 * @param string $url
148 * @return string
149 */
150 private function prependBackPath($url) {
151 if (strpos($url, '://') !== FALSE || $url[0] === '/') {
152 return $url;
153 } else {
154 return $this->backPath . $url;
155 }
156 }
157
158 }