2 namespace TYPO3\CMS\WizardCrpages\Controller
;
5 * This file is part of the TYPO3 CMS project.
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.
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
14 * The TYPO3 project - inspiring people to share!
17 use TYPO3\CMS\Backend\Utility\BackendUtility
;
18 use TYPO3\CMS\Core\Utility\GeneralUtility
;
21 * Creates the "Create pages" wizard
23 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
25 class CreatePagesWizardModuleFunctionController
extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule
{
28 * Holds reference of lorem ipsum class
30 * @var tx_loremipsum_wiz
32 protected $loremIpsumObject = NULL;
39 protected $tsConfig = array();
42 * Part of tsConfig with TCEFORM.pages. settings
46 protected $pagesTsConfig = array();
49 * Main function creating the content for the module.
51 * @return string HTML content for the module, actually a "section" made through the parent object in $this->pObj
53 public function main() {
54 $GLOBALS['LANG']->includeLLFile('EXT:wizard_crpages/locallang.xlf');
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');
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'];
74 $thePid = $this->pObj
->id
;
77 $thePid = $this->pObj
->id
;
80 $previousIdentifier = '';
81 foreach ($data['pages'] as $identifier => $dat) {
82 if (!trim($dat['title'])) {
83 unset($data['pages'][$identifier]);
85 $data['pages'][$identifier]['hidden'] = GeneralUtility
::_GP('hidePages') ?
1 : 0;
86 $data['pages'][$identifier]['nav_hide'] = GeneralUtility
::_GP('hidePagesInMenus') ?
1 : 0;
89 $data['pages'][$identifier]['pid'] = $thePid;
91 $data['pages'][$identifier]['pid'] = '-' . $previousIdentifier;
93 $previousIdentifier = $identifier;
96 if (!empty($data['pages'])) {
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);
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'));
110 $flashMessage = GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, '', $GLOBALS['LANG']->getLL('wiz_newPages_noCreate'), \TYPO3\CMS\Core\Messaging\FlashMessage
::ERROR
);
112 $theCode .= $flashMessage->render();
114 $menuItems = $sys_pages->getMenu($this->pObj
->id
, '*', 'sorting', '', 0);
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>';
122 $theCode .= '<h4>' . $GLOBALS['LANG']->getLL('wiz_newPages_currentMenu') . '</h4>' . implode('<br />', $lines);
124 // Display create form
126 $tableData = array();
127 for ($a = 0; $a < 9; $a++
) {
128 $tableData[] = $this->getFormLine($a);
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') . '" /> <input type="reset" value="' . $GLOBALS['LANG']->getLL('wiz_newPages_lReset') . '" /><br />';
137 /** @var \TYPO3\CMS\Core\Page\PageRenderer */
138 $pageRenderer = $GLOBALS['TBE_TEMPLATE']->getPageRenderer();
139 $pageRenderer->loadJquery();
140 $pageRenderer->loadRequireJsModule('TYPO3/CMS/WizardCrpages/WizardCreatePages');
142 $inlineJavaScriptCode = 'var tpl = "' . addslashes(str_replace(array(LF
, TAB
), array('', ''), $this->getFormLine('#'))) . '", i, line, div, bg, label;';
143 $pageRenderer->addJsInlineCode('wizard_crpages', $inlineJavaScriptCode);
145 $pageRenderer->addCssInlineBlock('TYPO3\CMS\WizardCrpages\Controller\CreatePagesWizardModuleFunctionController', '
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;}
153 $theCode .= GeneralUtility
::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessage
::class, '', $GLOBALS['LANG']->getLL('wiz_newPages_errorMsg1'), \TYPO3\CMS\Core\Messaging\FlashMessage
::ERROR
)->render();
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);
163 * Return one line in the form
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
168 protected function getFormLine($index) {
169 $backPath = $GLOBALS['BACK_PATH'];
170 if (is_numeric($index)) {
173 // used as template for JavaScript
177 $content = '<label for="page_new_' . $index . '"> ' . $GLOBALS['LANG']->getLL('wiz_newPages_page') . ' ' . $label;
178 $content .= ': </label>';
180 $content .= '<input type="text" id="page_new_' . $index . '" name="data[pages][NEW' . $index . '][title]"' . $this->pObj
->doc
->formWidth(35) . ' /> ';
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>' : '';
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("' . $backPath . 'sysext/t3skin/icons/gfx/i/pages.gif") no-repeat scroll 0% 50% rgb(255, 255, 255); padding: 1px 1px 1px 24px;">';
188 $types = $GLOBALS['PAGES_TYPES'];
189 unset($types['default']);
190 $types = array_keys($types);
192 if (!$GLOBALS['BE_USER']->isAdmin() && isset($GLOBALS['BE_USER']->groupData
['pagetypes_select'])) {
193 $types = GeneralUtility
::trimExplode(',', $GLOBALS['BE_USER']->groupData
['pagetypes_select'], TRUE);
195 $removeItems = isset($this->pagesTsConfig
['doktype.']['removeItems']) ? GeneralUtility
::trimExplode(',', $this->pagesTsConfig
['doktype.']['removeItems'], TRUE) : array();
197 if (in_array(1, $types) && !in_array(1, $removeItems)) {
198 $group .= '<option style="background: url("' . $backPath . 'sysext/t3skin/icons/gfx/i/pages.gif") no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" selected="selected" value="1">Standard</option>';
200 if (in_array(6, $types) && !in_array(6, $removeItems)) {
201 $group .= '<option style="background: url("' . $backPath . 'gfx/i/be_users_section.gif") no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="6">Backend User Section</option>';
203 $content .= $group ?
'<optgroup class="c-divider" label="Page">' . $group . '</optgroup>' : '';
205 if (in_array(4, $types) && !in_array(4, $removeItems)) {
206 $group .= '<option style="background: url("' . $backPath . 'sysext/t3skin/icons/gfx/i/pages_shortcut.gif") no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="4">Shortcut</option>';
208 if (in_array(7, $types) && !in_array(7, $removeItems)) {
209 $group .= '<option style="background: url("' . $backPath . 'gfx/i/pages_mountpoint.gif") no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="7">Mount Point</option>';
211 if (in_array(3, $types) && !in_array(3, $removeItems)) {
212 $group .= '<option style="background: url("' . $backPath . 'sysext/t3skin/icons/gfx/i/pages_link.gif") no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="3">Link to external URL</option>';
214 $content .= $group ?
'<optgroup class="c-divider" label="Link">' . $group . '</optgroup>' : '';
216 if (in_array(254, $types) && !in_array(254, $removeItems)) {
217 $group .= '<option style="background: url("' . $backPath . 'sysext/t3skin/icons/gfx/i/sysf.gif") no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="254">Folder</option>';
219 if (in_array(255, $types) && !in_array(255, $removeItems)) {
220 $group .= '<option style="background: url("' . $backPath . 'sysext/t3skin/icons/gfx/i/recycler.gif") no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="255">Recycler</option>';
222 if (in_array(199, $types) && !in_array(199, $removeItems)) {
223 $group .= '<option style="background: url("' . $backPath . 'sysext/t3skin/icons/gfx/i/spacer_icon.gif") no-repeat scroll 0% 50% rgb(255, 255, 255); height: 16px; padding-top: 2px; padding-left: 22px;" value="199">Visual menu separator</option>';
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>';