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