[BUGFIX] Namespace: Revert extension split-up: wizard_crpages
[Packages/TYPO3.CMS.git] / typo3 / sysext / wizard_crpages / Classes / Controller / CreatePagesWizardModuleFunctionController.php
1 <?php
2 namespace TYPO3\CMS\WizardCrpages\Controller;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 1999-2011 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 textfile 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 /**
31 * Creates the "Create pages" wizard
32 *
33 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
34 * @package TYPO3
35 * @subpackage wizard_crpages
36 */
37 class CreatePagesWizardModuleFunctionController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
38
39 /**
40 * Holds reference of lorem ipsum class
41 *
42 * @var tx_loremipsum_wiz
43 */
44 protected $loremIpsumObject = NULL;
45
46 /**
47 * Complete tsConfig
48 *
49 * @var array
50 */
51 protected $tsConfig = array();
52
53 /**
54 * Part of tsConfig with TCEFORM.pages. settings
55 *
56 * @var array
57 */
58 protected $pagesTsConfig = array();
59
60 /**
61 * 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...
62 *
63 * @return array
64 * @ignore
65 * @todo Define visibility
66 */
67 public function modMenu() {
68 global $LANG;
69 $modMenuAdd = array(
70 'cr_333' => array(
71 '0' => 'nul',
72 '1' => 'et'
73 )
74 );
75 return $modMenuAdd;
76 }
77
78 /**
79 * Main function creating the content for the module.
80 *
81 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
82 * @todo Define visibility
83 */
84 public function main() {
85 global $SOBE, $LANG;
86 $theCode = '';
87 $this->tsConfig = \TYPO3\CMS\Backend\Utility\BackendUtility::getPagesTSconfig($this->pObj->id);
88 $this->pagesTsConfig = isset($this->tsConfig['TCEFORM.']['pages.']) ? $this->tsConfig['TCEFORM.']['pages.'] : array();
89 // Create loremIpsum code:
90 if (\TYPO3\CMS\Core\Extension\ExtensionManager::isLoaded('lorem_ipsum')) {
91 $this->loremIpsumObject = \TYPO3\CMS\Core\Utility\GeneralUtility::getUserObj('EXT:lorem_ipsum/class.tx_loremipsum_wiz.php:tx_loremipsum_wiz');
92 }
93 // Create new pages here?
94 $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(8);
95 $pRec = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages', $this->pObj->id, 'uid', ' AND ' . $m_perms_clause);
96 $sys_pages = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
97 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', 0);
98 if (is_array($pRec)) {
99 $data = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('data');
100 if (is_array($data['pages'])) {
101 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('createInListEnd')) {
102 $endI = end($menuItems);
103 $thePid = -intval($endI['uid']);
104 if (!$thePid) {
105 $thePid = $this->pObj->id;
106 }
107 } else {
108 $thePid = $this->pObj->id;
109 }
110 $firstRecord = TRUE;
111 $previousIdentifier = '';
112 foreach ($data['pages'] as $identifier => $dat) {
113 if (!trim($dat['title'])) {
114 unset($data['pages'][$identifier]);
115 } else {
116 $data['pages'][$identifier]['hidden'] = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('hidePages') ? 1 : 0;
117 if ($firstRecord) {
118 $firstRecord = FALSE;
119 $data['pages'][$identifier]['pid'] = $thePid;
120 } else {
121 $data['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
122 }
123 $previousIdentifier = $identifier;
124 }
125 }
126 if (count($data['pages'])) {
127 reset($data);
128 $tce = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandler\\DataHandler');
129 $tce->stripslashes_values = 0;
130 // set default TCA values specific for the user
131 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
132 if (is_array($TCAdefaultOverride)) {
133 $tce->setDefaultsFromUserTS($TCAdefaultOverride);
134 }
135 $tce->start($data, array());
136 $tce->process_datamap();
137 \TYPO3\CMS\Backend\Utility\BackendUtility::setUpdateSignal('updatePageTree');
138 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', '', $GLOBALS['LANG']->getLL('wiz_newPages_create'));
139 } else {
140 $flashMessage = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', '', $GLOBALS['LANG']->getLL('wiz_newPages_noCreate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
141 }
142 $theCode .= $flashMessage->render();
143 // Display result:
144 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', 0);
145 $lines = array();
146 foreach ($menuItems as $rec) {
147 \TYPO3\CMS\Backend\Utility\BackendUtility::workspaceOL('pages', $rec);
148 if (is_array($rec)) {
149 $lines[] = (('<nobr>' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $rec, array('title' => \TYPO3\CMS\Backend\Utility\BackendUtility::titleAttribForPages($rec, '', FALSE)))) . htmlspecialchars(\TYPO3\CMS\Core\Utility\GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen']))) . '</nobr>';
150 }
151 }
152 $theCode .= (('<h4>' . $LANG->getLL('wiz_newPages_currentMenu')) . '</h4>') . implode('<br />', $lines);
153 } else {
154 // Display create form
155 $lines = array();
156 for ($a = 0; $a < 9; $a++) {
157 $lines[] = $this->getFormLine($a);
158 }
159 $theCode .= ((((((((((((((((('<h4>' . $LANG->getLL('wiz_newPages')) . ':</h4>') . '<div id="formFieldContainer">') . implode('', $lines)) . '</div>') . '<br class="clearLeft" />') . '<input type="button" id="createNewFormFields" value="') . $LANG->getLL('wiz_newPages_addMoreLines')) . '" />') . '<br /><br />
160 <input type="checkbox" name="createInListEnd" id="createInListEnd" value="1" /> <label for="createInListEnd">') . $LANG->getLL('wiz_newPages_listEnd')) . '</label><br />
161 <input type="checkbox" name="hidePages" id="hidePages" value="1" /> <label for="hidePages">') . $LANG->getLL('wiz_newPages_hidePages')) . '</label><br /><br />
162 <input type="submit" name="create" value="') . $LANG->getLL('wiz_newPages_lCreate')) . '" />&nbsp;<input type="reset" value="') . $LANG->getLL('wiz_newPages_lReset')) . '" /><br />';
163 // Add ExtJS inline code
164 $extCode = ('
165 var tpl = "' . addslashes(str_replace(array(LF, TAB), array('', ''), $this->getFormLine('#')))) . '", i, line, div, bg, label;
166 var lineCounter = 9;
167 Ext.get("createNewFormFields").on("click", function() {
168 div = Ext.get("formFieldContainer");
169 for (i = 0; i < 5; i++) {
170 label = lineCounter + i + 1;
171 bg = label % 2 === 0 ? 6 : 4;
172 line = String.format(tpl, (lineCounter + i), label, bg);
173 div.insertHtml("beforeEnd", line);
174 }
175 lineCounter += 5;
176 });
177 ';
178 /** @var t3lib_pageRenderer * */
179 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
180 $pageRenderer->loadExtJS();
181 $pageRenderer->addExtOnReadyCode($extCode);
182 $pageRenderer->addCssInlineBlock('TYPO3\\CMS\\WizardCreatePages\\Controller\\CreatePagesWizardModuleFunctionController', '
183 #formFieldContainer {float: left; margin: 0 0 10px 0;}
184 .clearLeft {clear: left;}
185 #formFieldContainer label {width: 70px; display: inline-block;}
186 #formFieldContainer input {margin:4px 2px; padding:1px; vertical-align:middle}
187 #formFieldContainer span {padding: 0 3px;}
188 ');
189 }
190 } else {
191 $theCode .= $GLOBALS['TBE_TEMPLATE']->rfw($LANG->getLL('wiz_newPages_errorMsg1'));
192 }
193 // CSH
194 $theCode .= \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('_MOD_web_func', 'tx_wizardcrpages', $GLOBALS['BACK_PATH'], '<br />|');
195 $out = $this->pObj->doc->header($LANG->getLL('wiz_crMany'));
196 $out .= $this->pObj->doc->section('', $theCode, 0, 1);
197 return $out;
198 }
199
200 /**
201 * Return the helpbubble image tag.
202 *
203 * @return string HTML code for a help-bubble image.
204 * @todo Define visibility
205 */
206 public function helpBubble() {
207 return ('<img src="' . $GLOBALS['BACK_PATH']) . 'gfx/helpbubble.gif" width="14" height="14" hspace="2" align="top" alt="" />';
208 }
209
210 /**
211 * Return one line in the form
212 *
213 * @param mixed $index An integer: the line counter for which to create the line. Use "#" to create an template for javascript (used by ExtJS)
214 * @return string HTML code for one input line for one new page
215 */
216 protected function getFormLine($index) {
217 $backPath = $GLOBALS['BACK_PATH'];
218 if (is_numeric($index)) {
219 $backgroundClass = $index % 2 === 0 ? 'bgColor4' : 'bgColor6';
220 $label = $index + 1;
221 } else {
222 // used as template for ExtJS
223 $index = '{0}';
224 $backgroundClass = 'bgColor{2}';
225 $label = '{1}';
226 }
227 $content = (((('<label for="page_new_' . $index) . '"> ') . $GLOBALS['LANG']->getLL('wiz_newPages_page')) . ' ') . $label;
228 $content .= ':&nbsp;</label>';
229 // Title
230 $content .= ((((('<input type="text" id="page_new_' . $index) . '" name="data[pages][NEW') . $index) . '][title]"') . $this->pObj->doc->formWidth(35)) . ' />&nbsp';
231 // Lorem ipsum link, if available
232 $content .= is_object($this->loremIpsumObject) ? ((('<a href="#" onclick="' . htmlspecialchars($this->loremIpsumObject->getHeaderTitleJS((('document.forms[0][\'data[pages][NEW' . $index) . '][title]\'].value'), 'title'))) . '">') . $this->loremIpsumObject->getIcon('', $this->pObj->doc->backPath)) . '</a>' : '';
233 // type selector
234 $content .= ('<span>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.php:LGL.type')) . '</span>';
235 $content .= '<select onchange="this.style.backgroundImage=this.options[this.selectedIndex].style.backgroundImage;if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex=1;}" ';
236 $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;">';
237 // dokType
238 $types = $GLOBALS['PAGES_TYPES'];
239 unset($types['default']);
240 $types = array_keys($types);
241 $types[] = 1;
242 if (!$GLOBALS['BE_USER']->isAdmin() && isset($GLOBALS['BE_USER']->groupData['pagetypes_select'])) {
243 $types = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select'], TRUE);
244 }
245 $removeItems = isset($this->pagesTsConfig['doktype.']['removeItems']) ? \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->pagesTsConfig['doktype.']['removeItems'], TRUE) : array();
246 $group = '';
247 if (in_array(1, $types) && !in_array(1, $removeItems)) {
248 $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>';
249 }
250 if (in_array(6, $types) && !in_array(6, $removeItems)) {
251 $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>';
252 }
253 $content .= $group ? ('<optgroup class="c-divider" label="Page">' . $group) . '</optgroup>' : '';
254 $group = '';
255 if (in_array(4, $types) && !in_array(4, $removeItems)) {
256 $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>';
257 }
258 if (in_array(7, $types) && !in_array(7, $removeItems)) {
259 $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>';
260 }
261 if (in_array(3, $types) && !in_array(3, $removeItems)) {
262 $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>';
263 }
264 $content .= $group ? ('<optgroup class="c-divider" label="Link">' . $group) . '</optgroup>' : '';
265 $group = '';
266 if (in_array(254, $types) && !in_array(254, $removeItems)) {
267 $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>';
268 }
269 if (in_array(255, $types) && !in_array(255, $removeItems)) {
270 $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>';
271 }
272 if (in_array(199, $types) && !in_array(199, $removeItems)) {
273 $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>';
274 }
275 $content .= $group ? ('<optgroup class="c-divider" label="Special">' . $group) . '</optgroup>' : '';
276 $content .= '</select>';
277 return ((((('<div id="form-line-' . $index) . '" class="') . $backgroundClass) . '">') . $content) . '</div>';
278 }
279
280 }
281
282
283 ?>