TYPO3 CMS  TYPO3_6-2
CreatePagesWizardModuleFunctionController.php
Go to the documentation of this file.
1 <?php
3 
19 
26 
32  protected $loremIpsumObject = NULL;
33 
39  protected $tsConfig = array();
40 
46  protected $pagesTsConfig = array();
47 
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 
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  ';
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 
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 }
static workspaceOL($table, &$row, $wsid=-99, $unsetMovePointers=FALSE)
static cshItem($table, $field, $BACK_PATH, $wrap='', $onlyIconMode=FALSE, $styleAttrib='')
static getUserObj($classRef, $checkPrefix='', $silent=FALSE)
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
static getSpriteIconForRecord($table, array $row, array $options=array())
static titleAttribForPages($row, $perms_clause='', $includeAttrib=1)
static setUpdateSignal($set='', $params='')
static fixed_lgd_cs($string, $chars, $appendString='...')
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]
static getPagesTSconfig($id, $rootLine=NULL, $returnPartArray=FALSE)