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