a66506c2102e0e4bb25028c4a430b0d7b502df6b
[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 * 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...
50 *
51 * @return array
52 * @ignore
53 * @todo Define visibility
54 */
55 public function modMenu() {
56 global $LANG;
57 $modMenuAdd = array(
58 'cr_333' => array(
59 '0' => 'nul',
60 '1' => 'et'
61 )
62 );
63 return $modMenuAdd;
64 }
65
66 /**
67 * Main function creating the content for the module.
68 *
69 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
70 * @todo Define visibility
71 */
72 public function main() {
73 $GLOBALS['LANG']->includeLLFile('EXT:wizard_crpages/locallang.xlf');
74 $theCode = '';
75 $this->tsConfig = BackendUtility::getPagesTSconfig($this->pObj->id);
76 $this->pagesTsConfig = isset($this->tsConfig['TCEFORM.']['pages.']) ? $this->tsConfig['TCEFORM.']['pages.'] : array();
77 // Create loremIpsum code:
78 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('lorem_ipsum')) {
79 $this->loremIpsumObject = GeneralUtility::getUserObj('EXT:lorem_ipsum/class.tx_loremipsum_wiz.php:tx_loremipsum_wiz');
80 }
81 // Create new pages here?
82 $m_perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(8);
83 $pRec = BackendUtility::getRecord('pages', $this->pObj->id, 'uid', ' AND ' . $m_perms_clause);
84 $sys_pages = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
85 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', 0);
86 if (is_array($pRec)) {
87 $data = GeneralUtility::_GP('data');
88 if (is_array($data['pages'])) {
89 if (GeneralUtility::_GP('createInListEnd')) {
90 $endI = end($menuItems);
91 $thePid = -(int)$endI['uid'];
92 if (!$thePid) {
93 $thePid = $this->pObj->id;
94 }
95 } else {
96 $thePid = $this->pObj->id;
97 }
98 $firstRecord = TRUE;
99 $previousIdentifier = '';
100 foreach ($data['pages'] as $identifier => $dat) {
101 if (!trim($dat['title'])) {
102 unset($data['pages'][$identifier]);
103 } else {
104 $data['pages'][$identifier]['hidden'] = GeneralUtility::_GP('hidePages') ? 1 : 0;
105 $data['pages'][$identifier]['nav_hide'] = GeneralUtility::_GP('hidePagesInMenus') ? 1 : 0;
106 if ($firstRecord) {
107 $firstRecord = FALSE;
108 $data['pages'][$identifier]['pid'] = $thePid;
109 } else {
110 $data['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
111 }
112 $previousIdentifier = $identifier;
113 }
114 }
115 if (count($data['pages'])) {
116 reset($data);
117 $tce = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
118 $tce->stripslashes_values = 0;
119 // set default TCA values specific for the user
120 $TCAdefaultOverride = $GLOBALS['BE_USER']->getTSConfigProp('TCAdefaults');
121 if (is_array($TCAdefaultOverride)) {
122 $tce->setDefaultsFromUserTS($TCAdefaultOverride);
123 }
124 $tce->start($data, array());
125 $tce->process_datamap();
126 BackendUtility::setUpdateSignal('updatePageTree');
127 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', '', $GLOBALS['LANG']->getLL('wiz_newPages_create'));
128 } else {
129 $flashMessage = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', '', $GLOBALS['LANG']->getLL('wiz_newPages_noCreate'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
130 }
131 $theCode .= $flashMessage->render();
132 // Display result:
133 $menuItems = $sys_pages->getMenu($this->pObj->id, '*', 'sorting', '', 0);
134 $lines = array();
135 foreach ($menuItems as $rec) {
136 BackendUtility::workspaceOL('pages', $rec);
137 if (is_array($rec)) {
138 $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>';
139 }
140 }
141 $theCode .= '<h4>' . $GLOBALS['LANG']->getLL('wiz_newPages_currentMenu') . '</h4>' . implode('<br />', $lines);
142 } else {
143 // Display create form
144 $lines = array();
145 $tableData = array();
146 for ($a = 0; $a < 9; $a++) {
147 $tableData[] = $this->getFormLine($a);
148 }
149 $lines[] = '<table id="formFieldContainer" class="t3-table"><tbody id="formFieldContainerBody">' . implode(LF, $tableData) . '</tbody></table>';
150 $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 />
151 <input type="checkbox" name="createInListEnd" id="createInListEnd" value="1" /> <label for="createInListEnd">' . $GLOBALS['LANG']->getLL('wiz_newPages_listEnd') . '</label><br />
152 <input type="checkbox" name="hidePages" id="hidePages" value="1" /> <label for="hidePages">' . $GLOBALS['LANG']->getLL('wiz_newPages_hidePages') . '</label><br />
153 <input type="checkbox" name="hidePagesInMenus" id="hidePagesInMenus" value="1" /> <label for="hidePagesInMenus">' . $GLOBALS['LANG']->getLL('wiz_newPages_hidePagesInMenus') . '</label><br /><br />
154 <input type="submit" name="create" value="' . $GLOBALS['LANG']->getLL('wiz_newPages_lCreate') . '" />&nbsp;<input type="reset" value="' . $GLOBALS['LANG']->getLL('wiz_newPages_lReset') . '" /><br />';
155 // Add ExtJS inline code
156 $extCode = '
157 var tpl = "' . addslashes(str_replace(array(LF, TAB), array('', ''), $this->getFormLine('#'))) . '", i, line, div, bg, label;
158 var lineCounter = 9;
159 Ext.get("createNewFormFields").on("click", function() {
160 div = Ext.get("formFieldContainerBody");
161 for (i = 0; i < 5; i++) {
162 label = lineCounter + i + 1;
163 line = String.format(tpl, (lineCounter + i), label);
164 div.insertHtml("beforeEnd", line);
165 }
166 lineCounter += 5;
167 });
168 ';
169 /** @var \TYPO3\CMS\Core\Page\PageRenderer */
170 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
171 $pageRenderer->loadExtJS();
172 $pageRenderer->addExtOnReadyCode($extCode);
173 $pageRenderer->addCssInlineBlock('TYPO3\CMS\WizardCrpages\Controller\CreatePagesWizardModuleFunctionController', '
174 #formFieldContainer {float: left; margin: 0 0 10px 0;}
175 .clearLeft {clear: left;}
176 #formFieldContainer label {width: 70px; display: inline-block;}
177 #formFieldContainer span {padding: 0 3px;}
178 ');
179 }
180 } else {
181 $theCode .= GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', '', $GLOBALS['LANG']->getLL('wiz_newPages_errorMsg1'), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR)->render();
182 }
183 // CSH
184 $theCode .= BackendUtility::cshItem('_MOD_web_func', 'tx_wizardcrpages', $GLOBALS['BACK_PATH'], '<br />|');
185 $out = $this->pObj->doc->header($GLOBALS['LANG']->getLL('wiz_crMany'));
186 $out .= $this->pObj->doc->section('', $theCode, 0, 1);
187 return $out;
188 }
189
190 /**
191 * Return one line in the form
192 *
193 * @param mixed $index An integer: the line counter for which to create the line. Use "#" to create an template for javascript (used by ExtJS)
194 * @return string HTML code for one input line for one new page
195 */
196 protected function getFormLine($index) {
197 $backPath = $GLOBALS['BACK_PATH'];
198 if (is_numeric($index)) {
199 $label = $index + 1;
200 } else {
201 // used as template for ExtJS
202 $index = '{0}';
203 $label = '{1}';
204 }
205 $content = '<label for="page_new_' . $index . '"> ' . $GLOBALS['LANG']->getLL('wiz_newPages_page') . ' ' . $label;
206 $content .= ':&nbsp;</label>';
207 // Title
208 $content .= '<input type="text" id="page_new_' . $index . '" name="data[pages][NEW' . $index . '][title]"' . $this->pObj->doc->formWidth(35) . ' />&nbsp';
209 // Lorem ipsum link, if available
210 $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>' : '';
211 // type selector
212 $content .= '<span>' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_general.xlf:LGL.type') . '</span>';
213 $content .= '<select onchange="this.style.backgroundImage=this.options[this.selectedIndex].style.backgroundImage;if (this.options[this.selectedIndex].value==\'--div--\') {this.selectedIndex=1;}" ';
214 $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;">';
215 // dokType
216 $types = $GLOBALS['PAGES_TYPES'];
217 unset($types['default']);
218 $types = array_keys($types);
219 $types[] = 1;
220 if (!$GLOBALS['BE_USER']->isAdmin() && isset($GLOBALS['BE_USER']->groupData['pagetypes_select'])) {
221 $types = GeneralUtility::trimExplode(',', $GLOBALS['BE_USER']->groupData['pagetypes_select'], TRUE);
222 }
223 $removeItems = isset($this->pagesTsConfig['doktype.']['removeItems']) ? GeneralUtility::trimExplode(',', $this->pagesTsConfig['doktype.']['removeItems'], TRUE) : array();
224 $group = '';
225 if (in_array(1, $types) && !in_array(1, $removeItems)) {
226 $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>';
227 }
228 if (in_array(6, $types) && !in_array(6, $removeItems)) {
229 $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>';
230 }
231 $content .= $group ? '<optgroup class="c-divider" label="Page">' . $group . '</optgroup>' : '';
232 $group = '';
233 if (in_array(4, $types) && !in_array(4, $removeItems)) {
234 $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>';
235 }
236 if (in_array(7, $types) && !in_array(7, $removeItems)) {
237 $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>';
238 }
239 if (in_array(3, $types) && !in_array(3, $removeItems)) {
240 $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>';
241 }
242 $content .= $group ? '<optgroup class="c-divider" label="Link">' . $group . '</optgroup>' : '';
243 $group = '';
244 if (in_array(254, $types) && !in_array(254, $removeItems)) {
245 $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>';
246 }
247 if (in_array(255, $types) && !in_array(255, $removeItems)) {
248 $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>';
249 }
250 if (in_array(199, $types) && !in_array(199, $removeItems)) {
251 $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>';
252 }
253 $content .= $group ? '<optgroup class="c-divider" label="Special">' . $group . '</optgroup>' : '';
254 $content .= '</select>';
255 return '<tr id="form-line-' . $index . '"><td>' . $content . '</td></tr>';
256 }
257
258 }