[TASK] Introduce CSS based trees
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / NewRecordController.php
1 <?php
2 namespace TYPO3\CMS\Backend\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\Backend\Utility\IconUtility;
19 use TYPO3\CMS\Core\Database\DatabaseConnection;
20 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
21 use TYPO3\CMS\Core\Utility\GeneralUtility;
22
23 /**
24 * Script class for 'db_new'
25 *
26 * @author Kasper Skårhøj <kasperYYYY@typo3.com>
27 */
28 class NewRecordController {
29
30 /**
31 * @var array
32 */
33 public $pageinfo;
34
35 /**
36 * @var array
37 */
38 public $pidInfo;
39
40 /**
41 * @var array
42 */
43 protected $newRecordSortList;
44
45 /**
46 * @var int
47 */
48 public $newPagesInto;
49
50 /**
51 * @var int
52 */
53 public $newContentInto;
54
55 /**
56 * @var int
57 */
58 public $newPagesAfter;
59
60 /**
61 * Determines, whether "Select Position" for new page should be shown
62 *
63 * @var bool
64 */
65 protected $newPagesSelectPosition = TRUE;
66
67 /**
68 * @var array
69 */
70 public $web_list_modTSconfig;
71
72 /**
73 * @var array
74 */
75 public $allowedNewTables;
76
77 /**
78 * @var array
79 */
80 public $deniedNewTables;
81
82 /**
83 * @var array
84 */
85 public $web_list_modTSconfig_pid;
86
87 /**
88 * @var array
89 */
90 public $allowedNewTables_pid;
91
92 /**
93 * @var array
94 */
95 public $deniedNewTables_pid;
96
97 /**
98 * @var string
99 */
100 public $code;
101
102 /**
103 * @var string
104 */
105 public $R_URI;
106
107 /**
108 * @var int
109 */
110 public $id;
111
112 /**
113 * @var string
114 */
115 public $returnUrl;
116
117 /**
118 * pagesOnly flag.
119 *
120 * @var int
121 */
122 public $pagesOnly;
123
124 /**
125 * @var string
126 */
127 public $perms_clause;
128
129 /**
130 * Document template object
131 *
132 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
133 */
134 public $doc;
135
136 /**
137 * Accumulated HTML output
138 *
139 * @var string
140 */
141 public $content;
142
143 /**
144 * @var array
145 */
146 public $tRows;
147
148 /**
149 * Constructor
150 */
151 public function __construct() {
152 $GLOBALS['SOBE'] = $this;
153 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xlf');
154 $GLOBALS['BACK_PATH'] = '';
155
156 $this->init();
157 }
158
159 /**
160 * Constructor function for the class
161 *
162 * @return void
163 */
164 protected function init() {
165 // Page-selection permission clause (reading)
166 $this->perms_clause = $GLOBALS['BE_USER']->getPagePermsClause(1);
167 // This will hide records from display - it has nothing to do with user rights!!
168 if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
169 if ($pidList = $GLOBALS['TYPO3_DB']->cleanIntList($pidList)) {
170 $this->perms_clause .= ' AND pages.uid NOT IN (' . $pidList . ')';
171 }
172 }
173 // Setting GPvars:
174 // The page id to operate from
175 $this->id = (int)GeneralUtility::_GP('id');
176 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
177 $this->pagesOnly = GeneralUtility::_GP('pagesOnly');
178 // Create instance of template class for output
179 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
180 $this->doc->backPath = $GLOBALS['BACK_PATH'];
181 $this->doc->setModuleTemplate('EXT:backend/Resources/Private/Templates/db_new.html');
182 $this->doc->JScode = '';
183 // Setting up the context sensitive menu:
184 $this->doc->getContextMenuCode();
185 // Creating content
186 $this->content = '';
187 $this->content .= $this->doc->header($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.pagetitle'));
188 // Id a positive id is supplied, ask for the page record with permission information contained:
189 if ($this->id > 0) {
190 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
191 }
192 // If a page-record was returned, the user had read-access to the page.
193 if ($this->pageinfo['uid']) {
194 // Get record of parent page
195 $this->pidInfo = BackendUtility::getRecord('pages', $this->pageinfo['pid']);
196 // Checking the permissions for the user with regard to the parent page: Can he create new pages, new content record, new page after?
197 if ($GLOBALS['BE_USER']->doesUserHaveAccess($this->pageinfo, 8)) {
198 $this->newPagesInto = 1;
199 }
200 if ($GLOBALS['BE_USER']->doesUserHaveAccess($this->pageinfo, 16)) {
201 $this->newContentInto = 1;
202 }
203 if (($GLOBALS['BE_USER']->isAdmin() || is_array($this->pidInfo)) && $GLOBALS['BE_USER']->doesUserHaveAccess($this->pidInfo, 8)) {
204 $this->newPagesAfter = 1;
205 }
206 } elseif ($GLOBALS['BE_USER']->isAdmin()) {
207 // Admins can do it all
208 $this->newPagesInto = 1;
209 $this->newContentInto = 1;
210 $this->newPagesAfter = 0;
211 } else {
212 // People with no permission can do nothing
213 $this->newPagesInto = 0;
214 $this->newContentInto = 0;
215 $this->newPagesAfter = 0;
216 }
217 }
218
219 /**
220 * Main processing, creating the list of new record tables to select from
221 *
222 * @return void
223 */
224 public function main() {
225 // If there was a page - or if the user is admin (admins has access to the root) we proceed:
226 if ($this->pageinfo['uid'] || $GLOBALS['BE_USER']->isAdmin()) {
227 // Acquiring TSconfig for this module/current page:
228 $this->web_list_modTSconfig = BackendUtility::getModTSconfig($this->pageinfo['uid'], 'mod.web_list');
229 $this->allowedNewTables = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig['properties']['allowedNewTables'], TRUE);
230 $this->deniedNewTables = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig['properties']['deniedNewTables'], TRUE);
231 // Acquiring TSconfig for this module/parent page:
232 $this->web_list_modTSconfig_pid = BackendUtility::getModTSconfig($this->pageinfo['pid'], 'mod.web_list');
233 $this->allowedNewTables_pid = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig_pid['properties']['allowedNewTables'], TRUE);
234 $this->deniedNewTables_pid = GeneralUtility::trimExplode(',', $this->web_list_modTSconfig_pid['properties']['deniedNewTables'], TRUE);
235 // More init:
236 if (!$this->showNewRecLink('pages')) {
237 $this->newPagesInto = 0;
238 }
239 if (!$this->showNewRecLink('pages', $this->allowedNewTables_pid, $this->deniedNewTables_pid)) {
240 $this->newPagesAfter = 0;
241 }
242 // Set header-HTML and return_url
243 if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
244 $iconImgTag = IconUtility::getSpriteIconForRecord('pages', $this->pageinfo, array('title' => htmlspecialchars($this->pageinfo['_thePath'])));
245 $title = strip_tags($this->pageinfo[$GLOBALS['TCA']['pages']['ctrl']['label']]);
246 } else {
247 $iconImgTag = IconUtility::getSpriteIcon('apps-pagetree-root', array('title' => htmlspecialchars($this->pageinfo['_thePath'])));
248 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
249 }
250 $this->code = '<span class="typo3-moduleHeader">' . $this->doc->wrapClickMenuOnIcon($iconImgTag, 'pages', $this->pageinfo['uid']) . htmlspecialchars(GeneralUtility::fixed_lgd_cs($title, 45)) . '</span><br />';
251 $this->R_URI = $this->returnUrl;
252 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
253 // Regular new element:
254 if (!$this->pagesOnly) {
255 $this->regularNew();
256 } elseif ($this->showNewRecLink('pages')) {
257 // Pages only wizard
258 $this->pagesOnly();
259 }
260 // Add all the content to an output section
261 $this->content .= $this->doc->section('', $this->code);
262 // Setting up the buttons and markers for docheader
263 $docHeaderButtons = $this->getButtons();
264 $markers['CSH'] = $docHeaderButtons['csh'];
265 $markers['CONTENT'] = $this->content;
266 // Build the <body> for the module
267 $this->content = $this->doc->startPage($GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.pagetitle'));
268 $this->content .= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
269 $this->content .= $this->doc->endPage();
270 $this->content = $this->doc->insertStylesAndJS($this->content);
271 }
272 }
273
274 /**
275 * Create the panel of buttons for submitting the form or otherwise perform operations.
276 *
277 * @return array All available buttons as an assoc. array
278 */
279 protected function getButtons() {
280 $buttons = array(
281 'csh' => '',
282 'back' => '',
283 'view' => '',
284 'new_page' => ''
285 );
286 // Regular new element:
287 if (!$this->pagesOnly) {
288 // New page
289 if ($this->showNewRecLink('pages')) {
290 $buttons['new_page'] = '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('pagesOnly' => '1'))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:cms/layout/locallang.xlf:newPage', TRUE) . '">' . IconUtility::getSpriteIcon('actions-page-new') . '</a>';
291 }
292 // CSH
293 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'new_regular');
294 } elseif ($this->showNewRecLink('pages')) {
295 // Pages only wizard
296 // CSH
297 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'new_pages');
298 }
299 // Back
300 if ($this->R_URI) {
301 $buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', TRUE) . '">' . IconUtility::getSpriteIcon('actions-view-go-back') . '</a>';
302 }
303 if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
304 // View
305 $buttons['view'] = '<a href="#" onclick="' . htmlspecialchars(BackendUtility::viewOnClick($this->pageinfo['uid'], $this->backPath, BackendUtility::BEgetRootLine($this->pageinfo['uid']))) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', TRUE) . '">' . IconUtility::getSpriteIcon('actions-document-view') . '</a>';
306 }
307 return $buttons;
308 }
309
310 /**
311 * Creates the position map for pages wizard
312 *
313 * @return void
314 */
315 public function pagesOnly() {
316 $numberOfPages = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows('*', 'pages', '1=1' . BackendUtility::deleteClause('pages'));
317 if ($numberOfPages > 0) {
318 $this->code .= '
319 <h3>' . htmlspecialchars($GLOBALS['LANG']->getLL('selectPosition')) . ':</h3>
320 ';
321 $positionMap = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Tree\View\PagePositionMap::class, \TYPO3\CMS\Backend\Tree\View\NewRecordPageTreeView::class);
322 /** @var $positionMap \TYPO3\CMS\Backend\Tree\View\PagePositionMap */
323 $this->code .= $positionMap->positionTree($this->id, $this->pageinfo, $this->perms_clause, $this->R_URI);
324 } else {
325 // No pages yet, no need to prompt for position, redirect to page creation.
326 $javascript = BackendUtility::editOnClick('returnUrl=%2Ftypo3%2Fdb_new.php%3Fid%3D0%26pagesOnly%3D1&edit[pages][0]=new&returnNewPageId=1');
327 $startPos = strpos($javascript, 'href=\'') + 6;
328 $endPos = strpos($javascript, '\';');
329 $url = substr($javascript, $startPos, $endPos - $startPos);
330 @ob_end_clean();
331 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($url);
332 }
333 }
334
335 /**
336 * Create a regular new element (pages and records)
337 *
338 * @return void
339 */
340 public function regularNew() {
341 $doNotShowFullDescr = FALSE;
342 // Initialize array for accumulating table rows:
343 $this->tRows = array();
344 // Get TSconfig for current page
345 $pageTS = BackendUtility::getPagesTSconfig($this->id);
346 // Finish initializing new pages options with TSconfig
347 // Each new page option may be hidden by TSconfig
348 // Enabled option for the position of a new page
349 $this->newPagesSelectPosition = !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageSelectPosition']);
350 // Pseudo-boolean (0/1) for backward compatibility
351 $displayNewPagesIntoLink = $this->newPagesInto && !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageInside']) ? 1 : 0;
352 $displayNewPagesAfterLink = $this->newPagesAfter && !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageAfter']) ? 1 : 0;
353 // Slight spacer from header:
354 $this->code .= '';
355 // New Page
356 $table = 'pages';
357 $v = $GLOBALS['TCA'][$table];
358 $pageIcon = IconUtility::getSpriteIconForRecord($table, array());
359 $newPageIcon = IconUtility::getSpriteIcon('actions-page-new');
360 $rowContent = '';
361 // New pages INSIDE this pages
362 $newPageLinks = array();
363 if ($displayNewPagesIntoLink && $this->isTableAllowedForThisPage($this->pageinfo, 'pages') && $this->getBackendUserAuthentication()->check('tables_modify', 'pages') && $this->getBackendUserAuthentication()->workspaceCreateNewRecord(($this->pageinfo['_ORIG_uid'] ?: $this->id), 'pages')) {
364 // Create link to new page inside:
365 $newPageLinks[] = $this->linkWrap(IconUtility::getSpriteIconForRecord($table, array()) . $GLOBALS['LANG']->sL($v['ctrl']['title'], TRUE) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.inside', TRUE) . ')', $table, $this->id);
366 }
367 // New pages AFTER this pages
368 if ($displayNewPagesAfterLink && $this->isTableAllowedForThisPage($this->pidInfo, 'pages') && $this->getBackendUserAuthentication()->check('tables_modify', 'pages') && $this->getBackendUserAuthentication()->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')) {
369 $newPageLinks[] = $this->linkWrap($pageIcon . $GLOBALS['LANG']->sL($v['ctrl']['title'], TRUE) . ' (' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.after', TRUE) . ')', 'pages', -$this->id);
370 }
371 // New pages at selection position
372 if ($this->newPagesSelectPosition) {
373 // Link to page-wizard:
374 $newPageLinks[] = '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('pagesOnly' => 1))) . '">' . $pageIcon . htmlspecialchars($GLOBALS['LANG']->getLL('pageSelectPosition')) . '</a>';
375 }
376 // Assemble all new page links
377 $numPageLinks = count($newPageLinks);
378 for ($i = 0; $i < $numPageLinks; $i++) {
379 $rowContent .= '<li>' . $newPageLinks[$i] . '</li>';
380 }
381 // Add row header and half-line if not empty
382 if (!empty($rowContent)) {
383 $rowContent = '<ul class="list-tree"><li>' .$newPageIcon . '<strong>' .
384 $GLOBALS['LANG']->getLL('createNewPage') . '</strong><ul>' . $rowContent . '</ul></li>';
385 }
386 // Compile table row to show the icon for "new page (select position)"
387 $startRows = array();
388 if ($this->showNewRecLink('pages') && !empty($rowContent)) {
389 $startRows[] = $rowContent;
390 }
391 // New tables (but not pages) INSIDE this pages
392 $isAdmin = $GLOBALS['BE_USER']->isAdmin();
393 $newContentIcon = IconUtility::getSpriteIcon('actions-document-new');
394 if ($this->newContentInto) {
395 if (is_array($GLOBALS['TCA'])) {
396 $groupName = '';
397 foreach ($GLOBALS['TCA'] as $table => $v) {
398 $counter = 1;
399 if ($table != 'pages'
400 && $this->showNewRecLink($table)
401 && $this->isTableAllowedForThisPage($this->pageinfo, $table)
402 && $GLOBALS['BE_USER']->check('tables_modify', $table)
403 && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel'] == -1)
404 && $GLOBALS['BE_USER']->workspaceCreateNewRecord(($this->pageinfo['_ORIG_uid'] ? $this->pageinfo['_ORIG_uid'] : $this->id), $table)
405 ) {
406 $newRecordIcon = IconUtility::getSpriteIconForRecord($table, array());
407 $rowContent = '';
408 // Create new link for record:
409 $newLink = $this->linkWrap($newRecordIcon . $GLOBALS['LANG']->sL($v['ctrl']['title'], TRUE), $table, $this->id);
410 // If the table is 'tt_content' (from "cms" extension), create link to wizard
411 if ($table == 'tt_content') {
412 $groupName = $GLOBALS['LANG']->getLL('createNewContent');
413 $rowContent = $newContentIcon . '<strong>' . $GLOBALS['LANG']->getLL('createNewContent') . '</strong><ul>';
414 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
415 $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
416 $pathToWizard = ExtensionManagementUtility::isLoaded($overrideExt) ? ExtensionManagementUtility::extRelPath($overrideExt) . 'mod1/db_new_content_el.php?' : BackendUtility::getModuleUrl('new_content_element') . '&';
417 $href = $pathToWizard . 'id=' . $this->id . '&returnUrl=' . rawurlencode(GeneralUtility::getIndpEnv('REQUEST_URI'));
418 $rowContent .= '<li>' . $newLink . ' ' . BackendUtility::wrapInHelp($table, '') . '</li><li><a href="' . htmlspecialchars($href) . '">' . $newContentIcon . htmlspecialchars($GLOBALS['LANG']->getLL('clickForWizard')) . '</a></li></ul>';
419 } else {
420 // Get the title
421 if ($v['ctrl']['readOnly'] || $v['ctrl']['hideTable'] || $v['ctrl']['is_static']) {
422 continue;
423 }
424 if ($v['ctrl']['adminOnly'] && !$isAdmin) {
425 continue;
426 }
427 $nameParts = explode('_', $table);
428 $thisTitle = '';
429 if ($nameParts[0] == 'tx' || $nameParts[0] == 'tt') {
430 // Try to extract extension name
431 if (substr($v['ctrl']['title'], 0, 8) == 'LLL:EXT:') {
432 $_EXTKEY = substr($v['ctrl']['title'], 8);
433 $_EXTKEY = substr($_EXTKEY, 0, strpos($_EXTKEY, '/'));
434 if ($_EXTKEY != '') {
435 // First try to get localisation of extension title
436 $temp = explode(':', substr($v['ctrl']['title'], 9 + strlen($_EXTKEY)));
437 $langFile = $temp[0];
438 $thisTitle = $GLOBALS['LANG']->sL('LLL:EXT:' . $_EXTKEY . '/' . $langFile . ':extension.title');
439 // If no localisation available, read title from ext_emconf.php
440 if (!$thisTitle && is_file(ExtensionManagementUtility::extPath($_EXTKEY) . 'ext_emconf.php')) {
441 include ExtensionManagementUtility::extPath($_EXTKEY) . 'ext_emconf.php';
442 $thisTitle = $EM_CONF[$_EXTKEY]['title'];
443 }
444 $iconFile[$_EXTKEY] = '<img ' . 'src="' . ExtensionManagementUtility::extRelPath($_EXTKEY) . $GLOBALS['TYPO3_LOADED_EXT'][$_EXTKEY]['ext_icon'] . '" ' . 'width="16" height="16" ' . 'alt="' . $thisTitle . '" />';
445 }
446 }
447 if (empty($thisTitle)) {
448 $_EXTKEY = $nameParts[1];
449 $thisTitle = $nameParts[1];
450 $iconFile[$_EXTKEY] = '';
451 }
452 } else {
453 if ($table === 'pages_language_overlay' && !$this->checkIfLanguagesExist()) {
454 continue;
455 }
456 $_EXTKEY = 'system';
457 $thisTitle = $GLOBALS['LANG']->getLL('system_records');
458 $iconFile['system'] = IconUtility::getSpriteIcon('apps-pagetree-root');
459 }
460 if ($groupName == '' || $groupName != $_EXTKEY) {
461 $groupName = empty($v['ctrl']['groupName']) ? $_EXTKEY : $v['ctrl']['groupName'];
462 }
463 $rowContent .= $newLink;
464 }
465 // Compile table row:
466 if ($table == 'tt_content') {
467 $startRows[] = '<li>' . $rowContent . '</li>';
468 } else {
469 $this->tRows[$groupName]['title'] = $thisTitle;
470 $this->tRows[$groupName]['html'][] = $rowContent;
471 $this->tRows[$groupName]['table'][] = $table;
472 }
473 }
474 }
475 }
476 }
477 // User sort
478 if (isset($pageTS['mod.']['wizards.']['newRecord.']['order'])) {
479 $this->newRecordSortList = GeneralUtility::trimExplode(',', $pageTS['mod.']['wizards.']['newRecord.']['order'], TRUE);
480 }
481 uksort($this->tRows, array($this, 'sortNewRecordsByConfig'));
482 // Compile table row:
483 $finalRows = array();
484 $finalRows[] = implode('', $startRows);
485 foreach ($this->tRows as $key => $value) {
486 $row = '<li>' . $iconFile[$key] . ' <strong>' . $value['title'] . '</strong><ul>';
487 foreach ($value['html'] as $recordKey => $record) {
488 $row .= '<li>' . $record . ' ' . BackendUtility::wrapInHelp($value['table'][$recordKey], '') . '</li>';
489 }
490 $row .= '</ul></li>';
491 $finalRows[] = $row;
492 }
493 // Make table:
494 $this->code .= implode('', $finalRows);
495 }
496
497 /**
498 * User array sort function used by regularNew
499 *
500 * @param string $a First array element for compare
501 * @param string $b First array element for compare
502 * @return int -1 for lower, 0 for equal, 1 for greater
503 */
504 public function sortNewRecordsByConfig($a, $b) {
505 if (count($this->newRecordSortList)) {
506 if (in_array($a, $this->newRecordSortList) && in_array($b, $this->newRecordSortList)) {
507 // Both are in the list, return relative to position in array
508 $sub = array_search($a, $this->newRecordSortList) - array_search($b, $this->newRecordSortList);
509 $ret = ($sub < 0 ? -1 : $sub == 0) ? 0 : 1;
510 } elseif (in_array($a, $this->newRecordSortList)) {
511 // First element is in array, put to top
512 $ret = -1;
513 } elseif (in_array($b, $this->newRecordSortList)) {
514 // Second element is in array, put first to bottom
515 $ret = 1;
516 } else {
517 // No element is in array, return alphabetic order
518 $ret = strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
519 }
520 return $ret;
521 } else {
522 // Return alphabetic order
523 return strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
524 }
525 }
526
527 /**
528 * Ending page output and echo'ing content to browser.
529 *
530 * @return void
531 */
532 public function printContent() {
533 echo $this->content;
534 }
535
536 /**
537 * Links the string $code to a create-new form for a record in $table created on page $pid
538 *
539 * @param string $linkText Link text
540 * @param string $table Table name (in which to create new record)
541 * @param int $pid PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
542 * @param bool $addContentTable If $addContentTable is set, then a new tt_content record is created together with pages
543 * @return string The link.
544 */
545 public function linkWrap($linkText, $table, $pid, $addContentTable = FALSE) {
546 $parameters = '&edit[' . $table . '][' . $pid . ']=new';
547 if ($table == 'pages' && $addContentTable) {
548 $parameters .= '&edit[tt_content][prev]=new&returnNewPageId=1';
549 } elseif ($table == 'pages_language_overlay') {
550 $parameters .= '&overrideVals[pages_language_overlay][doktype]=' . (int)$this->pageinfo['doktype'];
551 }
552 $onClick = BackendUtility::editOnClick($parameters, '', $this->returnUrl);
553 return '<a href="#" onclick="' . htmlspecialchars($onClick) . '">' . $linkText . '</a>';
554 }
555
556 /**
557 * Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
558 *
559 * @param array $pid_row Record for parent page.
560 * @param string $checkTable Table name to check
561 * @return bool Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
562 */
563 public function isTableAllowedForThisPage($pid_row, $checkTable) {
564 if (!is_array($pid_row)) {
565 if ($GLOBALS['BE_USER']->user['admin']) {
566 return TRUE;
567 } else {
568 return FALSE;
569 }
570 }
571 // be_users and be_groups may not be created anywhere but in the root.
572 if ($checkTable == 'be_users' || $checkTable == 'be_groups') {
573 return FALSE;
574 }
575 // Checking doktype:
576 $doktype = (int)$pid_row['doktype'];
577 if (!($allowedTableList = $GLOBALS['PAGES_TYPES'][$doktype]['allowedTables'])) {
578 $allowedTableList = $GLOBALS['PAGES_TYPES']['default']['allowedTables'];
579 }
580 // If all tables or the table is listed as a allowed type, return TRUE
581 if (strstr($allowedTableList, '*') || GeneralUtility::inList($allowedTableList, $checkTable)) {
582 return TRUE;
583 }
584
585 return FALSE;
586 }
587
588 /**
589 * Returns TRUE if:
590 * - $allowedNewTables and $deniedNewTables are empty
591 * - the table is not found in $deniedNewTables and $allowedNewTables is not set or the $table tablename is found in $allowedNewTables
592 *
593 * If $table tablename is found in $allowedNewTables and $deniedNewTables, $deniedNewTables
594 * has priority over $allowedNewTables.
595 *
596 * @param string $table Table name to test if in allowedTables
597 * @param array $allowedNewTables Array of new tables that are allowed.
598 * @param array $deniedNewTables Array of new tables that are not allowed.
599 * @return bool Returns TRUE if a link for creating new records should be displayed for $table
600 */
601 public function showNewRecLink($table, array $allowedNewTables = array(), array $deniedNewTables = array()) {
602
603 if (!$this->getBackendUserAuthentication()->check('tables_modify', $table)) {
604 return FALSE;
605 }
606
607 $allowedNewTables = $allowedNewTables ?: $this->allowedNewTables;
608 $deniedNewTables = $deniedNewTables ?: $this->deniedNewTables;
609 // No deny/allow tables are set:
610 if (!count($allowedNewTables) && !count($deniedNewTables)) {
611 return TRUE;
612 } elseif (!in_array($table, $deniedNewTables) && (!count($allowedNewTables) || in_array($table, $allowedNewTables))) {
613 return TRUE;
614 } else {
615 return FALSE;
616 }
617 }
618
619 /**
620 * Checks if sys_language records are present
621 *
622 * @return bool
623 */
624 protected function checkIfLanguagesExist() {
625 $languageCount = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_language', '1=1');
626 if ($languageCount) {
627 $languageCount = TRUE;
628 }
629 return $languageCount;
630 }
631
632 /**
633 * Returns the global BackendUserAuthentication object.
634 *
635 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
636 */
637 protected function getBackendUserAuthentication() {
638 return $GLOBALS['BE_USER'];
639 }
640
641 /**
642 * Returns the database connection
643 *
644 * @return DatabaseConnection
645 */
646 protected function getDatabaseConnection() {
647 return $GLOBALS['TYPO3_DB'];
648 }
649
650 }