[TASK] Use name-resolution instead of strings where possible: 14
[Packages/TYPO3.CMS.git] / typo3 / sysext / wizard_crpages / Classes / Controller / CreatePagesWizardModuleFunctionController.php
1 <?php
2 namespace TYPO3\CMS\WizardCrpages\Controller;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Creates the "Create pages" wizard
22 *
23 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
24 */
25 class CreatePagesWizardModuleFunctionController extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
26
27 /**
28 * Holds reference of lorem ipsum class
29 *
30 * @var tx_loremipsum_wiz
31 */
32 protected $loremIpsumObject = NULL;
33
34 /**
35 * Complete tsConfig
36 *
37 * @var array
38 */
39 protected $tsConfig = array();
40
41 /**
42 * Part of tsConfig with TCEFORM.pages. settings
43 *
44 * @var array
45 */
46 protected $pagesTsConfig = array();
47
48 /**
49 * Main function creating the content for the module.
50 *
51 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
52 */
53 public function main() {
54 $GLOBALS['LANG']->includeLLFile('EXT:wizard_crpages/locallang.xlf');
55 $theCode = '';
56 $this->tsConfig = BackendUtility::getPagesTSconfig($this->pObj->id);
57 $this->pagesTsConfig = isset($this->tsConfig['TCEFORM.']['pages.']) ? $this->tsConfig['TCEFORM.']['pages.'] : array();
58 // Create loremIpsum code:
59 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('lorem_ipsum')) {
60 $this->loremIpsumObject = GeneralUtility::getUserObj('EXT:lorem_ipsum/class.tx_loremipsum_wiz.php:tx_loremipsum_wiz');
61 }
62 // Create new pages here?
63 $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(8);
64 $pRec = BackendUtility::getRecord('pages', $this->pObj->id, 'uid', ' AND ' . $m_perms_clause);
65 $sys_pages = GeneralUtility::makeInstance(\TYPO3\CMS\Frontend\Page\PageRepository::class);
66 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', FALSE);
67 if (is_array($pRec)) {
68 $data = GeneralUtility::_GP('data');
69 if (is_array($data['pages'])) {
70 if (GeneralUtility::_GP('createInListEnd')) {
71 $endI = end($menuItems);
72 $thePid = -(int)$endI['uid'];
73 if (!$thePid) {
74 $thePid = $this->pObj->id;
75 }
76 } else {
77 $thePid = $this->pObj->id;
78 }
79 $firstRecord = TRUE;
80 $previousIdentifier = '';
81 foreach ($data['pages'] as $identifier => $dat) {
82 if (!trim($dat['title'])) {
83 unset($data['pages'][$identifier]);
84 } else {
85 $data['pages'][$identifier]['hidden'] = GeneralUtility::_GP('hidePages') ? 1 : 0;
86 $data['pages'][$identifier]['nav_hide'] = GeneralUtility::_GP('hidePagesInMenus') ? 1 : 0;
87 if ($firstRecord) {
88 $firstRecord = FALSE;
89 $data['pages'][$identifier]['pid'] = $thePid;
90 } else {
91 $data['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
92 }
93 $previousIdentifier = $identifier;
94 }
95 }
96 if (!empty($data['pages'])) {
97 reset($data);
98 $tce = GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
99 $tce->stripslashes_values = 0;
100 // set default TCA values specific for the user
101 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
102 if (is_array($TCAdefaultOverride)) {
103 $tce->setDefaultsFromUserTS($TCAdefaultOverride);
104 }
105 $tce->start($data, array());
106 $tce->process_datamap();
107 BackendUtility::setUpdateSignal('updatePageTree');
108 $flashMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, '', $GLOBALS['LANG']->getLL('wiz_newPages_create'));
109 } else {
110 $flashMessage = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, '', $GLOBALS['LANG']->getLL('wiz_newPages_noCreate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
111 }
112 $theCode .= $flashMessage->render();
113 // Display result:
114 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', 0);
115 $lines = array();
116 foreach ($menuItems as $rec) {
117 BackendUtility::workspaceOL('pages', $rec);
118 if (is_array($rec)) {
119 $lines[] = '<nobr>' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $rec, array('title' => BackendUtility::titleAttribForPages($rec, '', FALSE))) . htmlspecialchars(GeneralUtility::fixed_lgd_cs($rec['title'], $GLOBALS['BE_USER']->uc['titleLen'])) . '</nobr>';
120 }
121 }
122 $theCode .= '<h4>' . $GLOBALS['LANG']->getLL('wiz_newPages_currentMenu') . '</h4>' . implode('<br />', $lines);
123 } else {
124 // Display create form
125 $lines = array();
126 $tableData = array();
127 for ($a = 0; $a < 9; $a++) {
128 $tableData[] = $this->getFormLine($a);
129 }
130 $lines[] = '<div class="table-fit"><table id="formFieldContainer" class="t3-table"><tbody id="formFieldContainerBody">' . implode(LF, $tableData) . '</tbody></table></div>';
131 $theCode .= '<h4>' . $GLOBALS['LANG']->getLL('wiz_newPages') . ':</h4>' . implode('', $lines) . '<br class="clearLeft" />' . '<input type="button" id="createNewFormFields" value="' . $GLOBALS['LANG']->getLL('wiz_newPages_addMoreLines') . '" />' . '<br /><br />';
132 $theCode .= '<div class="checkbox"><label for="createInListEnd"><input type="checkbox" name="createInListEnd" id="createInListEnd" value="1" />' . $GLOBALS['LANG']->getLL('wiz_newPages_listEnd') . '</label></div>';
133 $theCode .= '<div class="checkbox"><label for="hidePages"><input type="checkbox" name="hidePages" id="hidePages" value="1" />' . $GLOBALS['LANG']->getLL('wiz_newPages_hidePages') . '</label></div>';
134 $theCode .= '<div class="checkbox"><label for="hidePagesInMenus"><input type="checkbox" name="hidePagesInMenus" id="hidePagesInMenus" value="1" />' . $GLOBALS['LANG']->getLL('wiz_newPages_hidePagesInMenus') . '</label></div>';
135 $theCode .= '<input type="submit" name="create" value="' . $GLOBALS['LANG']->getLL('wiz_newPages_lCreate') . '" />&nbsp;<input type="reset" value="' . $GLOBALS['LANG']->getLL('wiz_newPages_lReset') . '" /><br />';
136
137 /** @var \TYPO3\CMS\Core\Page\PageRenderer $pageRenderer */
138 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
139 $pageRenderer->loadJquery();
140 $pageRenderer->loadRequireJsModule('TYPO3/CMS/WizardCrpages/WizardCreatePages');
141 // Add inline code
142 $inlineJavaScriptCode = 'var tpl = "' . addslashes(str_replace(array(LF, TAB), array('', ''), $this->getFormLine('#'))) . '", i, line, div, bg, label;';
143 $pageRenderer->addJsInlineCode('wizard_crpages', $inlineJavaScriptCode);
144
145 $pageRenderer->addCssInlineBlock(__CLASS__, '
146 #formFieldContainer {float: left; margin: 0 0 10px 0;}
147 .clearLeft {clear: left;}
148 #formFieldContainer label {width: 70px; display: inline-block;}
149 #formFieldContainer span {padding: 0 3px;}
150 ');
151 }
152 } else {
153 $theCode .= GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage::class, '', $GLOBALS['LANG']->getLL('wiz_newPages_errorMsg1'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR)->render();
154 }
155 // CSH
156 $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardcrpages', NULL, '<br />|');
157 $out = $this->pObj->doc->header($GLOBALS['LANG']->getLL('wiz_crMany'));
158 $out .= $this->pObj->doc->section('', $theCode, FALSE, TRUE);
159 return $out;
160 }
161
162 /**
163 * Return one line in the form
164 *
165 * @param mixed $index An integer: the line counter for which to create the line. Use "#" to create an template for javascript (used by ExtJS)
166 * @return string HTML code for one input line for one new page
167 */
168 protected function getFormLine($index) {
169 $backPath = $GLOBALS['BACK_PATH'];
170 if (is_numeric($index)) {
171 $label = $index + 1;
172 } else {
173 // used as template for JavaScript
174 $index = '{0}';
175 $label = '{1}';
176 }
177 $content = '<label for="page_new_' . $index . '"> ' . $GLOBALS['LANG']->getLL('wiz_newPages_page') . ' ' . $label;
178 $content .= ':&nbsp;</label>';
179 // Title
180 $content .= '<input type="text" id="page_new_' . $index . '" name="data[pages][NEW' . $index . '][title]"' . $this->pObj->doc->formWidth(35) . ' />&nbsp';
181 // Lorem ipsum link, if available
182 $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>' : '';
183 // type selector
184 $content .= '<span>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.type') . '</span>';
185 $content .= '<select id="type-select"';
186 $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;">';
187 // dokType
188 $types = $GLOBALS['PAGES_TYPES'];
189 unset($types['default']);
190 $types = array_keys($types);
191 $types[] = 1;
192 if (!$GLOBALS['BE_USER']->isAdmin() && isset($GLOBALS['BE_USER']->groupData['pagetypes_select'])) {
193 $types = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select'], TRUE);
194 }
195 $removeItems = isset($this->pagesTsConfig['doktype.']['removeItems']) ? GeneralUtility::trimExplode(',', $this->pagesTsConfig['doktype.']['removeItems'], TRUE) : array();
196 $group = '';
197 if (in_array(1, $types) && !in_array(1, $removeItems)) {
198 $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>';
199 }
200 if (in_array(6, $types) && !in_array(6, $removeItems)) {
201 $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>';
202 }
203 $content .= $group ? '<optgroup class="c-divider" label="Page">' . $group . '</optgroup>' : '';
204 $group = '';
205 if (in_array(4, $types) && !in_array(4, $removeItems)) {
206 $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>';
207 }
208 if (in_array(7, $types) && !in_array(7, $removeItems)) {
209 $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>';
210 }
211 if (in_array(3, $types) && !in_array(3, $removeItems)) {
212 $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>';
213 }
214 $content .= $group ? '<optgroup class="c-divider" label="Link">' . $group . '</optgroup>' : '';
215 $group = '';
216 if (in_array(254, $types) && !in_array(254, $removeItems)) {
217 $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>';
218 }
219 if (in_array(255, $types) && !in_array(255, $removeItems)) {
220 $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>';
221 }
222 if (in_array(199, $types) && !in_array(199, $removeItems)) {
223 $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>';
224 }
225 $content .= $group ? '<optgroup class="c-divider" label="Special">' . $group . '</optgroup>' : '';
226 $content .= '</select>';
227 return '<tr id="form-line-' . $index . '"><td>' . $content . '</td></tr>';
228 }
229
230 }