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