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