[TASK] Remove unneeded parenthesis on array-access
[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 Psr\Http\Message\ResponseInterface;
18 use Psr\Http\Message\ServerRequestInterface;
19 use TYPO3\CMS\Backend\Module\AbstractModule;
20 use TYPO3\CMS\Backend\Template\Components\ButtonBar;
21 use TYPO3\CMS\Backend\Tree\View\NewRecordPageTreeView;
22 use TYPO3\CMS\Backend\Tree\View\PagePositionMap;
23 use TYPO3\CMS\Backend\Utility\BackendUtility;
24 use TYPO3\CMS\Core\Database\DatabaseConnection;
25 use TYPO3\CMS\Core\Imaging\Icon;
26 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
27 use TYPO3\CMS\Core\Utility\GeneralUtility;
28 use TYPO3\CMS\Core\Utility\HttpUtility;
29 use TYPO3\CMS\Frontend\Page\PageRepository;
30
31 /**
32 * Script class for 'db_new'
33 */
34 class NewRecordController extends AbstractModule
35 {
36 /**
37 * @var array
38 */
39 public $pageinfo;
40
41 /**
42 * @var array
43 */
44 public $pidInfo;
45
46 /**
47 * @var array
48 */
49 protected $newRecordSortList;
50
51 /**
52 * @var int
53 */
54 public $newPagesInto;
55
56 /**
57 * @var int
58 */
59 public $newContentInto;
60
61 /**
62 * @var int
63 */
64 public $newPagesAfter;
65
66 /**
67 * Determines, whether "Select Position" for new page should be shown
68 *
69 * @var bool
70 */
71 protected $newPagesSelectPosition = true;
72
73 /**
74 * @var array
75 */
76 public $web_list_modTSconfig;
77
78 /**
79 * @var array
80 */
81 public $allowedNewTables;
82
83 /**
84 * @var array
85 */
86 public $deniedNewTables;
87
88 /**
89 * @var array
90 */
91 public $web_list_modTSconfig_pid;
92
93 /**
94 * @var array
95 */
96 public $allowedNewTables_pid;
97
98 /**
99 * @var array
100 */
101 public $deniedNewTables_pid;
102
103 /**
104 * @var string
105 */
106 public $code;
107
108 /**
109 * @var string
110 */
111 public $R_URI;
112
113 /**
114 * @var int
115 */
116 public $id;
117
118 /**
119 * @var string
120 */
121 public $returnUrl;
122
123 /**
124 * pagesOnly flag.
125 *
126 * @var int
127 */
128 public $pagesOnly;
129
130 /**
131 * @var string
132 */
133 public $perms_clause;
134
135 /**
136 * Accumulated HTML output
137 *
138 * @var string
139 */
140 public $content;
141
142 /**
143 * @var array
144 */
145 public $tRows;
146
147 /**
148 * Constructor
149 */
150 public function __construct()
151 {
152 parent::__construct();
153 $GLOBALS['SOBE'] = $this;
154 $this->getLanguageService()->includeLLFile('EXT:lang/locallang_misc.xlf');
155 $this->init();
156 }
157
158 /**
159 * Constructor function for the class
160 *
161 * @return void
162 */
163 protected function init()
164 {
165 $beUser = $this->getBackendUserAuthentication();
166 // Page-selection permission clause (reading)
167 $this->perms_clause = $beUser->getPagePermsClause(1);
168 // This will hide records from display - it has nothing to do with user rights!!
169 if ($pidList = $beUser->getTSConfigVal('options.hideRecords.pages')) {
170 if ($pidList = $this->getDatabaseConnection()->cleanIntList($pidList)) {
171 $this->perms_clause .= ' AND pages.uid NOT IN (' . $pidList . ')';
172 }
173 }
174 // Setting GPvars:
175 // The page id to operate from
176 $this->id = (int)GeneralUtility::_GP('id');
177 $this->returnUrl = GeneralUtility::sanitizeLocalUrl(GeneralUtility::_GP('returnUrl'));
178 $this->pagesOnly = GeneralUtility::_GP('pagesOnly');
179 // Setting up the context sensitive menu:
180 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ClickMenu');
181 $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Tooltip');
182 // Creating content
183 $this->content = '';
184 $this->content .= '<h1>'
185 . $this->getLanguageService()->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.pagetitle')
186 . '</h1>';
187 // Id a positive id is supplied, ask for the page record with permission information contained:
188 if ($this->id > 0) {
189 $this->pageinfo = BackendUtility::readPageAccess($this->id, $this->perms_clause);
190 }
191 // If a page-record was returned, the user had read-access to the page.
192 if ($this->pageinfo['uid']) {
193 // Get record of parent page
194 $this->pidInfo = BackendUtility::getRecord('pages', $this->pageinfo['pid']);
195 // Checking the permissions for the user with regard to the parent page: Can he create new pages, new
196 // content record, new page after?
197 if ($beUser->doesUserHaveAccess($this->pageinfo, 8)) {
198 $this->newPagesInto = 1;
199 }
200 if ($beUser->doesUserHaveAccess($this->pageinfo, 16)) {
201 $this->newContentInto = 1;
202 }
203 if (($beUser->isAdmin() || is_array($this->pidInfo)) && $beUser->doesUserHaveAccess($this->pidInfo, 8)) {
204 $this->newPagesAfter = 1;
205 }
206 } elseif ($beUser->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 * Injects the request object for the current request or subrequest
221 * As this controller goes only through the main() method, it is rather simple for now
222 *
223 * @param ServerRequestInterface $request the current request
224 * @param ResponseInterface $response
225 * @return ResponseInterface the response with the content
226 */
227 public function mainAction(ServerRequestInterface $request, ResponseInterface $response)
228 {
229 $this->main();
230
231 $response->getBody()->write($this->moduleTemplate->renderContent());
232 return $response;
233 }
234
235 /**
236 * Main processing, creating the list of new record tables to select from
237 *
238 * @return void
239 */
240 public function main()
241 {
242 // If there was a page - or if the user is admin (admins has access to the root) we proceed:
243 if (!empty($this->pageinfo['uid']) || $this->getBackendUserAuthentication()->isAdmin()) {
244 if (empty($this->pageinfo)) {
245 // Explicitly pass an empty array to the docHeader
246 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation([]);
247 } else {
248 $this->moduleTemplate->getDocHeaderComponent()->setMetaInformation($this->pageinfo);
249 }
250 // Acquiring TSconfig for this module/current page:
251 $this->web_list_modTSconfig = BackendUtility::getModTSconfig($this->pageinfo['uid'], 'mod.web_list');
252 $this->allowedNewTables = GeneralUtility::trimExplode(
253 ',',
254 $this->web_list_modTSconfig['properties']['allowedNewTables'],
255 true
256 );
257 $this->deniedNewTables = GeneralUtility::trimExplode(
258 ',',
259 $this->web_list_modTSconfig['properties']['deniedNewTables'],
260 true
261 );
262 // Acquiring TSconfig for this module/parent page:
263 $this->web_list_modTSconfig_pid = BackendUtility::getModTSconfig($this->pageinfo['pid'], 'mod.web_list');
264 $this->allowedNewTables_pid = GeneralUtility::trimExplode(
265 ',',
266 $this->web_list_modTSconfig_pid['properties']['allowedNewTables'],
267 true
268 );
269 $this->deniedNewTables_pid = GeneralUtility::trimExplode(
270 ',',
271 $this->web_list_modTSconfig_pid['properties']['deniedNewTables'],
272 true
273 );
274 // More init:
275 if (!$this->showNewRecLink('pages')) {
276 $this->newPagesInto = 0;
277 }
278 if (!$this->showNewRecLink('pages', $this->allowedNewTables_pid, $this->deniedNewTables_pid)) {
279 $this->newPagesAfter = 0;
280 }
281 // Set header-HTML and return_url
282 if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
283 $title = strip_tags($this->pageinfo[$GLOBALS['TCA']['pages']['ctrl']['label']]);
284 } else {
285 $title = $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename'];
286 }
287 $this->moduleTemplate->setTitle($title);
288 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
289 // Regular new element:
290 if (!$this->pagesOnly) {
291 $this->regularNew();
292 } elseif ($this->showNewRecLink('pages')) {
293 // Pages only wizard
294 $this->pagesOnly();
295 }
296 // Add all the content to an output section
297 $this->content .= '<div>' . $this->code . '</div>';
298 // Setting up the buttons and markers for docheader
299 $this->getButtons();
300 // Build the <body> for the module
301 $this->moduleTemplate->setContent($this->content);
302 }
303 }
304
305 /**
306 * Create the panel of buttons for submitting the form or otherwise perform operations.
307 */
308 protected function getButtons()
309 {
310 $lang = $this->getLanguageService();
311 $buttonBar = $this->moduleTemplate->getDocHeaderComponent()->getButtonBar();
312 // Regular new element:
313 if (!$this->pagesOnly) {
314 // New page
315 if ($this->showNewRecLink('pages')) {
316 $newPageButton = $buttonBar->makeLinkButton()
317 ->setHref(GeneralUtility::linkThisScript(array('pagesOnly' => '1')))
318 ->setTitle($lang->sL(
319 'LLL:EXT:backend/Resources/Private/Language/locallang_layout.xlf:newPage',
320 true
321 ))
322 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-page-new', Icon::SIZE_SMALL));
323 $buttonBar->addButton($newPageButton, ButtonBar::BUTTON_POSITION_LEFT, 20);
324 }
325 // CSH
326 $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('new_regular');
327 $buttonBar->addButton($cshButton);
328 } elseif ($this->showNewRecLink('pages')) {
329 // Pages only wizard
330 // CSH
331 $buttons['csh'] = BackendUtility::cshItem('xMOD_csh_corebe', 'new_pages');
332 $cshButton = $buttonBar->makeHelpButton()->setModuleName('xMOD_csh_corebe')->setFieldName('new_pages');
333 $buttonBar->addButton($cshButton);
334 }
335 // Back
336 if ($this->returnUrl) {
337 $returnButton = $buttonBar->makeLinkButton()
338 ->setHref($this->returnUrl)
339 ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.goBack', true))
340 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon('actions-view-go-back', Icon::SIZE_SMALL));
341 $buttonBar->addButton($returnButton, ButtonBar::BUTTON_POSITION_LEFT, 10);
342 }
343
344
345 if (is_array($this->pageinfo) && $this->pageinfo['uid']) {
346 // View
347 $pagesTSconfig = BackendUtility::getPagesTSconfig($this->pageinfo['uid']);
348 if (isset($pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'])) {
349 $excludeDokTypes = GeneralUtility::intExplode(
350 ',',
351 $pagesTSconfig['TCEMAIN.']['preview.']['disableButtonForDokType'],
352 true
353 );
354 } else {
355 // exclude sysfolders and recycler by default
356 $excludeDokTypes = array(
357 PageRepository::DOKTYPE_RECYCLER,
358 PageRepository::DOKTYPE_SYSFOLDER,
359 PageRepository::DOKTYPE_SPACER
360 );
361 }
362 if (!in_array((int)$this->pageinfo['doktype'], $excludeDokTypes, true)) {
363 $viewButton = $buttonBar->makeLinkButton()
364 ->setHref('#')
365 ->setOnClick(BackendUtility::viewOnClick(
366 $this->pageinfo['uid'],
367 '',
368 BackendUtility::BEgetRootLine($this->pageinfo['uid'])
369 ))
370 ->setTitle($lang->sL('LLL:EXT:lang/locallang_core.xlf:labels.showPage', true))
371 ->setIcon($this->moduleTemplate->getIconFactory()->getIcon(
372 'actions-document-view',
373 Icon::SIZE_SMALL
374 ));
375 $buttonBar->addButton($viewButton, ButtonBar::BUTTON_POSITION_LEFT, 30);
376 }
377 }
378 }
379
380 /**
381 * Creates the position map for pages wizard
382 *
383 * @return void
384 */
385 public function pagesOnly()
386 {
387 $numberOfPages = $this->getDatabaseConnection()->exec_SELECTcountRows(
388 '*',
389 'pages',
390 '1=1' . BackendUtility::deleteClause('pages')
391 );
392 if ($numberOfPages > 0) {
393 $this->code .= '
394 <h3>' . htmlspecialchars($this->getLanguageService()->getLL('selectPosition')) . ':</h3>
395 ';
396 $positionMap = GeneralUtility::makeInstance(PagePositionMap::class, NewRecordPageTreeView::class);
397 /** @var $positionMap \TYPO3\CMS\Backend\Tree\View\PagePositionMap */
398 $this->code .= $positionMap->positionTree(
399 $this->id,
400 $this->pageinfo,
401 $this->perms_clause,
402 $this->returnUrl
403 );
404 } else {
405 // No pages yet, no need to prompt for position, redirect to page creation.
406 $urlParameters = [
407 'edit' => [
408 'pages' => [
409 0 => 'new'
410 ]
411 ],
412 'returnNewPageId' => 1,
413 'returnUrl' => BackendUtility::getModuleUrl('db_new', array('id' => $this->id, 'pagesOnly' => '1'))
414 ];
415 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
416 @ob_end_clean();
417 HttpUtility::redirect($url);
418 }
419 }
420
421 /**
422 * Create a regular new element (pages and records)
423 *
424 * @return void
425 */
426 public function regularNew()
427 {
428 $lang = $this->getLanguageService();
429 // Initialize array for accumulating table rows:
430 $this->tRows = array();
431 // Get TSconfig for current page
432 $pageTS = BackendUtility::getPagesTSconfig($this->id);
433 // Finish initializing new pages options with TSconfig
434 // Each new page option may be hidden by TSconfig
435 // Enabled option for the position of a new page
436 $this->newPagesSelectPosition = !empty(
437 $pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageSelectPosition']
438 );
439 // Pseudo-boolean (0/1) for backward compatibility
440 $displayNewPagesIntoLink = $this->newPagesInto && !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageInside']) ? 1 : 0;
441 $displayNewPagesAfterLink = $this->newPagesAfter && !empty($pageTS['mod.']['wizards.']['newRecord.']['pages.']['show.']['pageAfter']) ? 1 : 0;
442 // Slight spacer from header:
443 $this->code .= '';
444 // New Page
445 $table = 'pages';
446 $v = $GLOBALS['TCA'][$table];
447 $pageIcon = $this->moduleTemplate->getIconFactory()->getIconForRecord(
448 $table,
449 array(),
450 Icon::SIZE_SMALL
451 )->render();
452 $newPageIcon = $this->moduleTemplate->getIconFactory()->getIcon('actions-page-new', Icon::SIZE_SMALL)->render();
453 $rowContent = '';
454 // New pages INSIDE this pages
455 $newPageLinks = array();
456 if ($displayNewPagesIntoLink && $this->isTableAllowedForThisPage($this->pageinfo, 'pages') && $this->getBackendUserAuthentication()->check('tables_modify', 'pages') && $this->getBackendUserAuthentication()->workspaceCreateNewRecord(($this->pageinfo['_ORIG_uid'] ?: $this->id), 'pages')) {
457 // Create link to new page inside:
458 $newPageLinks[] = $this->linkWrap($this->moduleTemplate->getIconFactory()->getIconForRecord($table, array(), Icon::SIZE_SMALL)->render() . $lang->sL($v['ctrl']['title'], true) . ' (' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.inside', true) . ')', $table, $this->id);
459 }
460 // New pages AFTER this pages
461 if ($displayNewPagesAfterLink && $this->isTableAllowedForThisPage($this->pidInfo, 'pages') && $this->getBackendUserAuthentication()->check('tables_modify', 'pages') && $this->getBackendUserAuthentication()->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')) {
462 $newPageLinks[] = $this->linkWrap($pageIcon . $lang->sL($v['ctrl']['title'], true) . ' (' . $lang->sL('LLL:EXT:lang/locallang_core.xlf:db_new.php.after', true) . ')', 'pages', -$this->id);
463 }
464 // New pages at selection position
465 if ($this->newPagesSelectPosition && $this->showNewRecLink('pages')) {
466 // Link to page-wizard:
467 $newPageLinks[] = '<a href="' . htmlspecialchars(GeneralUtility::linkThisScript(array('pagesOnly' => 1))) . '">' . $pageIcon . htmlspecialchars($lang->getLL('pageSelectPosition')) . '</a>';
468 }
469 // Assemble all new page links
470 $numPageLinks = count($newPageLinks);
471 for ($i = 0; $i < $numPageLinks; $i++) {
472 $rowContent .= '<li>' . $newPageLinks[$i] . '</li>';
473 }
474 if ($this->showNewRecLink('pages')) {
475 $rowContent = '<ul class="list-tree"><li>' . $newPageIcon . '<strong>' .
476 $lang->getLL('createNewPage') . '</strong><ul>' . $rowContent . '</ul></li>';
477 } else {
478 $rowContent = '<ul class="list-tree"><li><ul>' . $rowContent . '</li></ul>';
479 }
480 // Compile table row
481 $startRows = array($rowContent);
482 $iconFile = array();
483 // New tables (but not pages) INSIDE this pages
484 $isAdmin = $this->getBackendUserAuthentication()->isAdmin();
485 $newContentIcon = $this->moduleTemplate->getIconFactory()->getIcon('actions-document-new', Icon::SIZE_SMALL)->render();
486 if ($this->newContentInto) {
487 if (is_array($GLOBALS['TCA'])) {
488 $groupName = '';
489 foreach ($GLOBALS['TCA'] as $table => $v) {
490 if ($table != 'pages'
491 && $this->showNewRecLink($table)
492 && $this->isTableAllowedForThisPage($this->pageinfo, $table)
493 && $this->getBackendUserAuthentication()->check('tables_modify', $table)
494 && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel'] == -1)
495 && $this->getBackendUserAuthentication()->workspaceCreateNewRecord(($this->pageinfo['_ORIG_uid'] ? $this->pageinfo['_ORIG_uid'] : $this->id), $table)
496 ) {
497 $newRecordIcon = $this->moduleTemplate->getIconFactory()->getIconForRecord($table, array(), Icon::SIZE_SMALL)->render();
498 $rowContent = '';
499 $thisTitle = '';
500 // Create new link for record:
501 $newLink = $this->linkWrap($newRecordIcon . $lang->sL($v['ctrl']['title'], true), $table, $this->id);
502 // If the table is 'tt_content', create link to wizard
503 if ($table == 'tt_content') {
504 $groupName = $lang->getLL('createNewContent');
505 $rowContent = $newContentIcon . '<strong>' . $lang->getLL('createNewContent') . '</strong><ul>';
506 // If mod.newContentElementWizard.override is set, use that extension's wizard instead:
507 $tsConfig = BackendUtility::getModTSconfig($this->id, 'mod');
508 $moduleName = $tsConfig['properties']['newContentElementWizard.']['override'] ?: 'new_content_element';
509 $url = BackendUtility::getModuleUrl($moduleName, ['id' => $this->id, 'returnUrl' => GeneralUtility::getIndpEnv('REQUEST_URI')]);
510 $rowContent .= '<li>' . $newLink . ' ' . BackendUtility::wrapInHelp($table, '') . '</li><li><a href="' . htmlspecialchars($url) . '">' . $newContentIcon . htmlspecialchars($lang->getLL('clickForWizard')) . '</a></li></ul>';
511 } else {
512 // Get the title
513 if ($v['ctrl']['readOnly'] || $v['ctrl']['hideTable'] || $v['ctrl']['is_static']) {
514 continue;
515 }
516 if ($v['ctrl']['adminOnly'] && !$isAdmin) {
517 continue;
518 }
519 $nameParts = explode('_', $table);
520 $thisTitle = '';
521 $_EXTKEY = '';
522 if ($nameParts[0] == 'tx' || $nameParts[0] == 'tt') {
523 // Try to extract extension name
524 if (substr($v['ctrl']['title'], 0, 8) == 'LLL:EXT:') {
525 $_EXTKEY = substr($v['ctrl']['title'], 8);
526 $_EXTKEY = substr($_EXTKEY, 0, strpos($_EXTKEY, '/'));
527 if ($_EXTKEY != '') {
528 // First try to get localisation of extension title
529 $temp = explode(':', substr($v['ctrl']['title'], 9 + strlen($_EXTKEY)));
530 $langFile = $temp[0];
531 $thisTitle = $lang->sL('LLL:EXT:' . $_EXTKEY . '/' . $langFile . ':extension.title');
532 // If no localisation available, read title from ext_emconf.php
533 $extEmConfFile = ExtensionManagementUtility::extPath($_EXTKEY) . 'ext_emconf.php';
534 if (!$thisTitle && is_file($extEmConfFile)) {
535 $EM_CONF = array();
536 include $extEmConfFile;
537 $thisTitle = $EM_CONF[$_EXTKEY]['title'];
538 }
539 $iconFile[$_EXTKEY] = '<img ' . 'src="' . ExtensionManagementUtility::extRelPath($_EXTKEY) . $GLOBALS['TYPO3_LOADED_EXT'][$_EXTKEY]['ext_icon'] . '" ' . 'width="16" height="16" ' . 'alt="' . $thisTitle . '" />';
540 }
541 }
542 if (empty($thisTitle)) {
543 $_EXTKEY = $nameParts[1];
544 $thisTitle = $nameParts[1];
545 $iconFile[$_EXTKEY] = '';
546 }
547 } else {
548 if ($table === 'pages_language_overlay' && !$this->checkIfLanguagesExist()) {
549 continue;
550 }
551 $_EXTKEY = 'system';
552 $thisTitle = $lang->getLL('system_records');
553 $iconFile['system'] = $this->moduleTemplate->getIconFactory()->getIcon('apps-pagetree-root', Icon::SIZE_SMALL)->render();
554 }
555 if ($groupName == '' || $groupName != $_EXTKEY) {
556 $groupName = empty($v['ctrl']['groupName']) ? $_EXTKEY : $v['ctrl']['groupName'];
557 }
558 $rowContent .= $newLink;
559 }
560 // Compile table row:
561 if ($table == 'tt_content') {
562 $startRows[] = '<li>' . $rowContent . '</li>';
563 } else {
564 $this->tRows[$groupName]['title'] = $thisTitle;
565 $this->tRows[$groupName]['html'][] = $rowContent;
566 $this->tRows[$groupName]['table'][] = $table;
567 }
568 }
569 }
570 }
571 }
572 // User sort
573 if (isset($pageTS['mod.']['wizards.']['newRecord.']['order'])) {
574 $this->newRecordSortList = GeneralUtility::trimExplode(',', $pageTS['mod.']['wizards.']['newRecord.']['order'], true);
575 }
576 uksort($this->tRows, array($this, 'sortNewRecordsByConfig'));
577 // Compile table row:
578 $finalRows = array();
579 $finalRows[] = implode('', $startRows);
580 foreach ($this->tRows as $key => $value) {
581 $row = '<li>' . $iconFile[$key] . ' <strong>' . $value['title'] . '</strong><ul>';
582 foreach ($value['html'] as $recordKey => $record) {
583 $row .= '<li>' . $record . ' ' . BackendUtility::wrapInHelp($value['table'][$recordKey], '') . '</li>';
584 }
585 $row .= '</ul></li>';
586 $finalRows[] = $row;
587 }
588
589 $finalRows[] = '</ul>';
590 // Make table:
591 $this->code .= implode('', $finalRows);
592 }
593
594 /**
595 * User array sort function used by regularNew
596 *
597 * @param string $a First array element for compare
598 * @param string $b First array element for compare
599 * @return int -1 for lower, 0 for equal, 1 for greater
600 */
601 public function sortNewRecordsByConfig($a, $b)
602 {
603 if (!empty($this->newRecordSortList)) {
604 if (in_array($a, $this->newRecordSortList) && in_array($b, $this->newRecordSortList)) {
605 // Both are in the list, return relative to position in array
606 $sub = array_search($a, $this->newRecordSortList) - array_search($b, $this->newRecordSortList);
607 $ret = ($sub < 0 ? -1 : $sub == 0) ? 0 : 1;
608 } elseif (in_array($a, $this->newRecordSortList)) {
609 // First element is in array, put to top
610 $ret = -1;
611 } elseif (in_array($b, $this->newRecordSortList)) {
612 // Second element is in array, put first to bottom
613 $ret = 1;
614 } else {
615 // No element is in array, return alphabetic order
616 $ret = strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
617 }
618 return $ret;
619 } else {
620 // Return alphabetic order
621 return strnatcasecmp($this->tRows[$a]['title'], $this->tRows[$b]['title']);
622 }
623 }
624
625 /**
626 * Ending page output and echo'ing content to browser.
627 *
628 * @return void
629 * @deprecated since TYPO3 CMS 7, will be removed in TYPO3 CMS 8, use mainAction() instead
630 */
631 public function printContent()
632 {
633 GeneralUtility::logDeprecatedFunction();
634 echo $this->content;
635 }
636
637 /**
638 * Links the string $code to a create-new form for a record in $table created on page $pid
639 *
640 * @param string $linkText Link text
641 * @param string $table Table name (in which to create new record)
642 * @param int $pid PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
643 * @param bool $addContentTable If $addContentTable is set, then a new tt_content record is created together with pages
644 * @return string The link.
645 */
646 public function linkWrap($linkText, $table, $pid, $addContentTable = false)
647 {
648 $urlParameters = [
649 'edit' => [
650 $table => [
651 $pid => 'new'
652 ]
653 ],
654 'returnUrl' => $this->returnUrl
655 ];
656 if ($table == 'pages' && $addContentTable) {
657 $urlParameters['tt_content']['prev'] = 'new';
658 $urlParameters['returnNewPageId'] = 1;
659 } elseif ($table == 'pages_language_overlay') {
660 $urlParameters['overrideVals']['pages_language_overlay']['doktype'] = (int)$this->pageinfo['doktype'];
661 }
662 $url = BackendUtility::getModuleUrl('record_edit', $urlParameters);
663 return '<a href="' . htmlspecialchars($url) . '">' . $linkText . '</a>';
664 }
665
666 /**
667 * Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
668 *
669 * @param array $pid_row Record for parent page.
670 * @param string $checkTable Table name to check
671 * @return bool Returns TRUE if the tablename $checkTable is allowed to be created on the page with record $pid_row
672 */
673 public function isTableAllowedForThisPage($pid_row, $checkTable)
674 {
675 if (!is_array($pid_row)) {
676 return $this->getBackendUserAuthentication()->isAdmin();
677 }
678 // be_users and be_groups may not be created anywhere but in the root.
679 if ($checkTable == 'be_users' || $checkTable == 'be_groups') {
680 return false;
681 }
682 // Checking doktype:
683 $doktype = (int)$pid_row['doktype'];
684 if (!($allowedTableList = $GLOBALS['PAGES_TYPES'][$doktype]['allowedTables'])) {
685 $allowedTableList = $GLOBALS['PAGES_TYPES']['default']['allowedTables'];
686 }
687 // If all tables or the table is listed as an allowed type, return TRUE
688 if (strstr($allowedTableList, '*') || GeneralUtility::inList($allowedTableList, $checkTable)) {
689 return true;
690 }
691
692 return false;
693 }
694
695 /**
696 * Returns TRUE if:
697 * - $allowedNewTables and $deniedNewTables are empty
698 * - the table is not found in $deniedNewTables and $allowedNewTables is not set or the $table tablename is found in
699 * $allowedNewTables
700 *
701 * If $table tablename is found in $allowedNewTables and $deniedNewTables, $deniedNewTables
702 * has priority over $allowedNewTables.
703 *
704 * @param string $table Table name to test if in allowedTables
705 * @param array $allowedNewTables Array of new tables that are allowed.
706 * @param array $deniedNewTables Array of new tables that are not allowed.
707 *
708 * @return bool Returns TRUE if a link for creating new records should be displayed for $table
709 */
710 public function showNewRecLink($table, array $allowedNewTables = array(), array $deniedNewTables = array())
711 {
712 if (!$this->getBackendUserAuthentication()->check('tables_modify', $table)) {
713 return false;
714 }
715
716 $allowedNewTables = $allowedNewTables ?: $this->allowedNewTables;
717 $deniedNewTables = $deniedNewTables ?: $this->deniedNewTables;
718 // No deny/allow tables are set:
719 if (empty($allowedNewTables) && empty($deniedNewTables)) {
720 return true;
721 }
722
723 return !in_array($table, $deniedNewTables) && (empty($allowedNewTables) || in_array($table, $allowedNewTables));
724 }
725
726 /**
727 * Checks if sys_language records are present
728 *
729 * @return bool
730 */
731 protected function checkIfLanguagesExist()
732 {
733 $languageCount = $this->getDatabaseConnection()->exec_SELECTcountRows('uid', 'sys_language', '1=1');
734 if ($languageCount) {
735 $languageCount = true;
736 }
737 return $languageCount;
738 }
739
740 /**
741 * Return language service instance
742 *
743 * @return \TYPO3\CMS\Lang\LanguageService
744 */
745 protected function getLanguageService()
746 {
747 return $GLOBALS['LANG'];
748 }
749
750 /**
751 * Returns the global BackendUserAuthentication object.
752 *
753 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
754 */
755 protected function getBackendUserAuthentication()
756 {
757 return $GLOBALS['BE_USER'];
758 }
759
760 /**
761 * Returns the database connection
762 *
763 * @return DatabaseConnection
764 */
765 protected function getDatabaseConnection()
766 {
767 return $GLOBALS['TYPO3_DB'];
768 }
769 }