[BUGFIX] PHP 5.4 warning in CLI context in switch back user
[Packages/TYPO3.CMS.git] / typo3 / sysext / wizard_crpages / class.tx_wizardcrpages_webfunc_2.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2011 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 * Contains class for "Create pages" wizard
29 *
30 * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
31 * XHTML compliant
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 */
35 /**
36 * [CLASS/FUNCTION INDEX of SCRIPT]
37 *
38 *
39 *
40 * 70: class tx_wizardcrpages_webfunc_2 extends t3lib_extobjbase
41 * 78: function modMenu()
42 * 95: function main()
43 * 179: function helpBubble()
44 *
45 * TOTAL FUNCTIONS: 3
46 * (This index is automatically created/updated by the extension "extdeveval")
47 *
48 */
49
50 /**
51 * Creates the "Create pages" wizard
52 *
53 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
54 * @package TYPO3
55 * @subpackage tx_wizardcrpages
56 */
57 class tx_wizardcrpages_webfunc_2 extends t3lib_extobjbase {
58
59 /**
60 * Holds reference of lorem ipsum class
61 *
62 * @var tx_loremipsum_wiz
63 */
64 protected $loremIpsumObject = NULL;
65
66 /**
67 * Complete tsConfig
68 *
69 * @var array
70 */
71 protected $tsConfig = array();
72
73 /**
74 * Part of tsConfig with TCEFORM.pages. settings
75 *
76 * @var array
77 */
78 protected $pagesTsConfig = array();
79
80
81 /**
82 * Adds menu items... but I think this is not used at all. Looks very much like some testing code. If anyone cares to check it we can remove it some day...
83 *
84 * @return array
85 * @ignore
86 */
87 function modMenu() {
88 global $LANG;
89
90 $modMenuAdd = array(
91 'cr_333' => array(
92 '0' => 'nul',
93 '1' => 'et'
94 )
95 );
96 return $modMenuAdd;
97 }
98
99 /**
100 * Main function creating the content for the module.
101 *
102 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
103 */
104 function main() {
105 global $SOBE,$LANG;
106
107 $theCode='';
108
109 $this->tsConfig = t3lib_BEfunc::getPagesTSconfig($this->pObj->id);
110 $this->pagesTsConfig = isset($this->tsConfig['TCEFORM.']['pages.']) ? $this->tsConfig['TCEFORM.']['pages.'] : array();
111
112
113 // Create loremIpsum code:
114 if (t3lib_extMgm::isLoaded('lorem_ipsum')) {
115 $this->loremIpsumObject = t3lib_div::getUserObj('EXT:lorem_ipsum/class.tx_loremipsum_wiz.php:tx_loremipsum_wiz');
116 }
117
118 $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(8); // create new pages here?
119 $pRec = t3lib_BEfunc::getRecord('pages',$this->pObj->id,'uid',' AND '.$m_perms_clause);
120 $sys_pages = t3lib_div::makeInstance('t3lib_pageSelect');
121 $menuItems = $sys_pages->getMenu($this->pObj->id,'*','sorting','',0);
122 if (is_array($pRec)) {
123 $data = t3lib_div::_GP('data');
124 if (is_array($data['pages'])) {
125 if (t3lib_div::_GP('createInListEnd')) {
126 $endI = end($menuItems);
127 $thePid = -intval($endI['uid']);
128 if (!$thePid) $thePid = $this->pObj->id;
129 } else {
130 $thePid = $this->pObj->id;
131 }
132
133 $firstRecord = true;
134 $previousIdentifier = '';
135
136 foreach ($data['pages'] as $identifier => $dat) {
137 if (!trim($dat['title'])) {
138 unset($data['pages'][$identifier]);
139 } else {
140 $data['pages'][$identifier]['hidden'] = t3lib_div::_GP('hidePages') ? 1 : 0;
141 if ($firstRecord) {
142 $firstRecord = false;
143 $data['pages'][$identifier]['pid'] = $thePid;
144 } else {
145 $data['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
146 }
147 $previousIdentifier = $identifier;
148 }
149 }
150
151 if (count($data['pages'])) {
152 reset($data);
153 $tce = t3lib_div::makeInstance('t3lib_TCEmain');
154 $tce->stripslashes_values=0;
155
156 // set default TCA values specific for the user
157 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
158 if (is_array($TCAdefaultOverride)) {
159 $tce->setDefaultsFromUserTS($TCAdefaultOverride);
160 }
161
162 $tce->start($data,array());
163 $tce->process_datamap();
164 t3lib_BEfunc::setUpdateSignal('updatePageTree');
165
166 $flashMessage = t3lib_div::makeInstance(
167 't3lib_FlashMessage',
168 '',
169 $GLOBALS['LANG']->getLL('wiz_newPages_create')
170 );
171 } else {
172 $flashMessage = t3lib_div::makeInstance(
173 't3lib_FlashMessage',
174 '',
175 $GLOBALS['LANG']->getLL('wiz_newPages_noCreate'),
176 t3lib_FlashMessage::ERROR
177 );
178 }
179
180 $theCode.= $flashMessage->render();
181
182 // Display result:
183 $menuItems = $sys_pages->getMenu($this->pObj->id,'*','sorting','',0);
184 $lines=array();
185 foreach ($menuItems as $rec) {
186 t3lib_BEfunc::workspaceOL('pages',$rec);
187 if (is_array($rec)) {
188 $lines[] = '<nobr>' . t3lib_iconWorks::getSpriteIconForRecord('pages', $rec, array('title' => t3lib_BEfunc::titleAttribForPages($rec , '', FALSE))) .
189 htmlspecialchars(t3lib_div::fixed_lgd_cs($rec['title'],$GLOBALS['BE_USER']->uc['titleLen'])).'</nobr>';
190 }
191 }
192 $theCode.= '<h4>' . $LANG->getLL('wiz_newPages_currentMenu') . '</h4>' . implode('<br />', $lines);
193 } else {
194
195 // Display create form
196 $lines = array();
197 for ($a = 0; $a < 9; $a++) {
198 $lines[] = $this->getFormLine($a);
199 }
200
201 $theCode .= '<h4>' . $LANG->getLL('wiz_newPages') . ':</h4>' .
202 '<div id="formFieldContainer">' . implode('', $lines) . '</div>' .
203 '<br class="clearLeft" />' .
204 '<input type="button" id="createNewFormFields" value="' . $LANG->getLL('wiz_newPages_addMoreLines') . '" />' .
205
206 '<br /><br />
207 <input type="checkbox" name="createInListEnd" id="createInListEnd" value="1" /> <label for="createInListEnd">'.$LANG->getLL('wiz_newPages_listEnd').'</label><br />
208 <input type="checkbox" name="hidePages" id="hidePages" value="1" /> <label for="hidePages">'.$LANG->getLL('wiz_newPages_hidePages').'</label><br /><br />
209 <input type="submit" name="create" value="' . $LANG->getLL('wiz_newPages_lCreate') . '" onclick="return confirm(' . $GLOBALS['LANG']->JScharCode($GLOBALS['LANG']->getLL('wiz_newPages_lCreate_msg1')) . ')" />&nbsp;<input type="reset" value="' . $LANG->getLL('wiz_newPages_lReset') . '" /><br />';
210
211 // Add ExtJS inline code
212 $extCode = '
213 var tpl = "' . addslashes(str_replace(
214 array(LF, TAB),
215 array('', ''),
216 $this->getFormLine('#')
217 )) . '", i, line, div, bg, label;
218 var lineCounter = 9;
219 Ext.get("createNewFormFields").on("click", function() {
220 div = Ext.get("formFieldContainer");
221 for (i = 0; i < 5; i++) {
222 label = lineCounter + i + 1;
223 bg = label % 2 === 0 ? 6 : 4;
224 line = String.format(tpl, (lineCounter + i), label, bg);
225 div.insertHtml("beforeEnd", line);
226 }
227 lineCounter += 5;
228 });
229 ';
230
231 /** @var t3lib_pageRenderer **/
232 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
233
234 $pageRenderer->loadExtJS();
235 $pageRenderer->addExtOnReadyCode($extCode);
236 $pageRenderer->addCssInlineBlock('tx_wizardcrpages_webfunc_2', '
237 #formFieldContainer {float: left; margin: 0 0 10px 0;}
238 .clearLeft {clear: left;}
239 #formFieldContainer label {width: 70px; display: inline-block;}
240 #formFieldContainer input {margin:4px 2px; padding:1px; vertical-align:middle}
241 #formFieldContainer span {padding: 0 3px;}
242 ');
243 }
244 } else {
245 $theCode.=$GLOBALS['TBE_TEMPLATE']->rfw($LANG->getLL('wiz_newPages_errorMsg1'));
246 }
247
248 // CSH
249 $theCode.= t3lib_BEfunc::cshItem('_MOD_web_func', 'tx_wizardcrpages', $GLOBALS['BACK_PATH'], '<br />|');
250
251 $out=$this->pObj->doc->section($LANG->getLL('wiz_crMany'),$theCode,0,1);
252 return $out;
253 }
254
255 /**
256 * Return the helpbubble image tag.
257 *
258 * @return string HTML code for a help-bubble image.
259 */
260 function helpBubble() {
261 return '<img src="'.$GLOBALS['BACK_PATH'].'gfx/helpbubble.gif" width="14" height="14" hspace="2" align="top" alt="" />';
262 }
263
264 /**
265 * Return one line in the form
266 *
267 * @param mixed $index An integer: the line counter for which to create the line. Use "#" to create an template for javascript (used by ExtJS)
268 * @return string HTML code for one input line for one new page
269 */
270 protected function getFormLine($index) {
271 $backPath = $GLOBALS['BACK_PATH'];
272
273 if (is_numeric(($index))) {
274 $backgroundClass = ($index % 2 === 0 ? 'bgColor4' : 'bgColor6');
275 $label = $index + 1;
276 } else {
277 // used as template for ExtJS
278 $index = '{0}';
279 $backgroundClass = 'bgColor{2}';
280 $label = '{1}';
281 }
282
283 $content = '<label for="page_new_' . $index . '"> ' . $GLOBALS['LANG']->getLL('wiz_newPages_page') .' '. $label;
284 $content .= ':&nbsp;</label>';
285
286 // title
287 $content .= '<input type="text" id="page_new_' . $index . '" name="data[pages][NEW' . $index . '][title]"' . $this->pObj->doc->formWidth(35) . ' />&nbsp';
288
289 // lorem ipsum link, if available
290 $content .= (is_object($this->loremIpsumObject) ?
291 '<a href="#" onclick="' . htmlspecialchars($this->loremIpsumObject->getHeaderTitleJS('document.forms[0][\'data[pages][NEW' .
292 $index . '][title]\'].value', 'title')) . '">' . $this->loremIpsumObject->getIcon('', $this->pObj->doc->backPath) . '</a>'
293 : '');
294
295 // type selector
296 $content .= '<span>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.php:LGL.type') . '</span>';
297 $content .= '<select onchange="this.style.backgroundImage=this.options[this.selectedIndex].style.backgroundImage;if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex=1;}" ';
298 $content .= 'class="select icon-select" name="data[pages][NEW' . $index . '][doktype]" style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); padding: 1px 1px 1px 24px;">';
299
300 // dokType
301 $types = $GLOBALS['PAGES_TYPES'];
302 unset($types['default']);
303 $types = array_keys($types);
304 $types[] = 1;
305 if (!$GLOBALS['BE_USER']->isAdmin() && isset($GLOBALS['BE_USER']->groupData['pagetypes_select'])) {
306 $types = t3lib_div::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select'], TRUE);
307 }
308
309 $removeItems = isset($this->pagesTsConfig['doktype.']['removeItems']) ? t3lib_div::trimExplode(',', $this->pagesTsConfig['doktype.']['removeItems'], TRUE) : array();
310
311 $group = '';
312 if (in_array(1, $types) && !in_array(1, $removeItems)) {
313 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" selected="selected" value="1">Standard</option>';
314 }
315 if (in_array(6, $types) && !in_array(6, $removeItems)) {
316 $group .= '<option style="background: url(&quot;' . $backPath . 'gfx/i/be_users_section.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="6">Backend User Section</option>';
317 }
318 $content .= $group ? '<optgroup class="c-divider" label="Page">' . $group . '</optgroup>' : '';
319
320 $group = '';
321 if (in_array(4, $types) && !in_array(4, $removeItems)) {
322 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages_shortcut.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="4">Shortcut</option>';
323 }
324 if (in_array(7, $types) && !in_array(7, $removeItems)) {
325 $group .= '<option style="background: url(&quot;' . $backPath . 'gfx/i/pages_mountpoint.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="7">Mount Point</option>';
326 }
327 if (in_array(3, $types) && !in_array(3, $removeItems)) {
328 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/pages_link.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="3">Link to external URL</option>';
329 }
330 $content .= $group ? '<optgroup class="c-divider" label="Link">' . $group . '</optgroup>' : '';
331
332 $group = '';
333 if (in_array(254, $types) && !in_array(254, $removeItems)) {
334 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/sysf.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="254">Folder</option>';
335 }
336 if (in_array(255, $types) && !in_array(255, $removeItems)) {
337 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/recycler.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="255">Recycler</option>';
338 }
339 if (in_array(199, $types) && !in_array(199, $removeItems)) {
340 $group .= '<option style="background: url(&quot;' . $backPath . 'sysext/t3skin/icons/gfx/i/spacer_icon.gif&quot;) no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="199">Visual menu separator</option>';
341 }
342 $content .= $group ? '<optgroup class="c-divider" label="Special">' . $group . '</optgroup>' : '';
343 $content .= '</select>';
344
345 return '<div id="form-line-' . $index . '" class="' . $backgroundClass . '">' . $content . '</div>';
346 }
347 }
348
349 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/wizard_crpages/class.tx_wizardcrpages_webfunc_2.php'])) {
350 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/wizard_crpages/class.tx_wizardcrpages_webfunc_2.php']);
351 }
352 ?>