Added the media field for page type "Shortcut" as well
[Packages/TYPO3.CMS.git] / typo3 / db_new.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * New database item menu
29 *
30 * This script lets users choose a new database element to create.
31 * Includes a wizard mode for visually pointing out the position of new pages
32 *
33 * $Id$
34 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
35 * XHTML compliant
36 *
37 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
38 */
39 /**
40 * [CLASS/FUNCTION INDEX of SCRIPT]
41 *
42 *
43 *
44 * 90: class localPageTree extends t3lib_pageTree
45 * 99: function wrapIcon($icon,$row)
46 * 110: function expandNext($id)
47 *
48 *
49 * 128: class SC_db_new
50 * 157: function init()
51 * 224: function main()
52 * 276: function pagesOnly()
53 * 294: function regularNew()
54 * 458: function printContent()
55 * 473: function linkWrap($code,$table,$pid,$addContentTable=0)
56 * 493: function isTableAllowedForThisPage($pid_row, $checkTable)
57 * 523: function showNewRecLink($table,$allowedNewTables='')
58 *
59 * TOTAL FUNCTIONS: 10
60 * (This index is automatically created/updated by the extension "extdeveval")
61 *
62 */
63
64
65
66
67 $BACK_PATH='';
68 require('init.php');
69 require('template.php');
70 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
71
72 // ***************************
73 // Including classes
74 // ***************************
75 require_once(PATH_t3lib.'class.t3lib_page.php');
76 require_once(PATH_t3lib.'class.t3lib_positionmap.php');
77 require_once(PATH_t3lib.'class.t3lib_pagetree.php');
78
79
80
81
82
83 /**
84 * Extension for the tree class that generates the tree of pages in the page-wizard mode
85 *
86 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
87 * @package TYPO3
88 * @subpackage core
89 */
90 class localPageTree extends t3lib_pageTree {
91
92 /**
93 * Inserting uid-information in title-text for an icon
94 *
95 * @param string Icon image
96 * @param array Item row
97 * @return string Wrapping icon image.
98 */
99 function wrapIcon($icon,$row) {
100 return $this->addTagAttributes($icon,' title="id='.htmlspecialchars($row['uid']).'"');
101 }
102
103 /**
104 * Determines whether to expand a branch or not.
105 * Here the branch is expanded if the current id matches the global id for the listing/new
106 *
107 * @param integer The ID (page id) of the element
108 * @return boolean Returns true if the IDs matches
109 */
110 function expandNext($id) {
111 return $id==$GLOBALS['SOBE']->id ? 1 : 0;
112 }
113 }
114
115
116
117
118
119
120
121 /**
122 * Script class for 'db_new'
123 *
124 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
125 * @package TYPO3
126 * @subpackage core
127 */
128 class SC_db_new {
129 var $pageinfo;
130 var $pidInfo;
131 var $newPagesInto;
132 var $newContentInto;
133 var $newPagesAfter;
134 var $web_list_modTSconfig;
135 var $allowedNewTables;
136 var $web_list_modTSconfig_pid;
137 var $allowedNewTables_pid;
138 var $code;
139 var $R_URI;
140
141 // Internal, static: GPvar
142 var $id; // see init()
143 var $returnUrl; // Return url.
144 var $pagesOnly; // pagesOnly flag.
145
146 // Internal
147 var $perms_clause; // see init()
148
149 /**
150 * Document template object
151 *
152 * @var mediumDoc
153 */
154 var $doc;
155 var $content; // Accumulated HTML output
156
157
158 /**
159 * Constructor function for the class
160 *
161 * @return void
162 */
163 function init() {
164 global $BE_USER,$LANG,$BACK_PATH;
165
166 // page-selection permission clause (reading)
167 $this->perms_clause = $BE_USER->getPagePermsClause(1);
168
169 // this will hide records from display - it has nothing todo with user rights!!
170 if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) {
171 if ($pidList = $GLOBALS['TYPO3_DB']->cleanIntList($pidList)) {
172 $this->perms_clause .= ' AND pages.uid NOT IN ('.$pidList.')';
173 }
174 }
175 // Setting GPvars:
176 $this->id = intval(t3lib_div::_GP('id')); // The page id to operate from
177 $this->returnUrl = t3lib_div::_GP('returnUrl');
178 $this->pagesOnly = t3lib_div::_GP('pagesOnly');
179
180 // Create instance of template class for output
181 $this->doc = t3lib_div::makeInstance('mediumDoc');
182 $this->doc->backPath = $BACK_PATH;
183 $this->doc->docType= 'xhtml_trans';
184 $this->doc->JScode='';
185
186 // Creating content
187 $this->content='';
188 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
189 $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.pagetitle'));
190
191 // Id a positive id is supplied, ask for the page record with permission information contained:
192 if ($this->id > 0) {
193 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
194 }
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
200 $this->pidInfo=t3lib_BEfunc::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 ($BE_USER->doesUserHaveAccess($this->pageinfo,8)) {
203 $this->newPagesInto=1;
204 }
205 if ($BE_USER->doesUserHaveAccess($this->pageinfo,16)) {
206 $this->newContentInto=1;
207 }
208
209 if (($BE_USER->isAdmin()||is_array($this->pidInfo)) && $BE_USER->doesUserHaveAccess($this->pidInfo,8)) {
210 $this->newPagesAfter=1;
211 }
212 } elseif ($BE_USER->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 function main() {
231 global $BE_USER,$LANG;
232
233 // If there was a page - or if the user is admin (admins has access to the root) we proceed:
234 if ($this->pageinfo['uid'] || $BE_USER->isAdmin()) {
235 // Acquiring TSconfig for this module/current page:
236 $this->web_list_modTSconfig = t3lib_BEfunc::getModTSconfig($this->pageinfo['uid'],'mod.web_list');
237 $this->allowedNewTables = t3lib_div::trimExplode(',',$this->web_list_modTSconfig['properties']['allowedNewTables'],1);
238
239 // Acquiring TSconfig for this module/parent page:
240 $this->web_list_modTSconfig_pid = t3lib_BEfunc::getModTSconfig($this->pageinfo['pid'],'mod.web_list');
241 $this->allowedNewTables_pid = t3lib_div::trimExplode(',',$this->web_list_modTSconfig_pid['properties']['allowedNewTables'],1);
242
243 // More init:
244 if (!$this->showNewRecLink('pages')) {
245 $this->newPagesInto=0;
246 }
247 if (!$this->showNewRecLink('pages',$this->allowedNewTables_pid)) {
248 $this->newPagesAfter=0;
249 }
250
251
252 // Set header-HTML and return_url
253 $this->code = $this->doc->getHeader('pages',$this->pageinfo,$this->pageinfo['_thePath']).'<br />
254 ';
255 $this->R_URI = $this->returnUrl;
256
257 // GENERATE the HTML-output depending on mode (pagesOnly is the page wizard)
258 if (!$this->pagesOnly) { // Regular new element:
259 $this->regularNew();
260 } elseif ($this->showNewRecLink('pages')) { // Pages only wizard
261 $this->pagesOnly();
262 }
263
264 // Create go-back link.
265 if ($this->R_URI) {
266 $this->code.='<br />
267 <a href="'.htmlspecialchars($this->R_URI).'" class="typo3-goBack">'.
268 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/goback.gif','width="14" height="14"').' alt="" />'.
269 $LANG->getLL('goBack',1).
270 '</a>';
271 }
272 // Add all the content to an output section
273 $this->content.=$this->doc->section('',$this->code);
274 }
275 }
276
277 /**
278 * Creates the position map for pages wizard
279 *
280 * @return void
281 */
282 function pagesOnly() {
283 global $LANG;
284
285 $posMap = t3lib_div::makeInstance('t3lib_positionMap');
286 $this->code.='
287 <h3>'.htmlspecialchars($LANG->getLL('selectPosition')).':</h3>
288 ';
289 $this->code.= $posMap->positionTree($this->id,$this->pageinfo,$this->perms_clause,$this->R_URI);
290
291 // Add CSH:
292 $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_pages', $GLOBALS['BACK_PATH'],'<br/>');
293 }
294
295 /**
296 * Create a regular new element (pages and records)
297 *
298 * @return void
299 */
300 function regularNew() {
301 global $BE_USER,$LANG,$BACK_PATH,$TCA;
302
303 $doNotShowFullDescr = FALSE;
304
305 // Slight spacer from header:
306 $this->code.='<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" /><br />';
307
308 // Initialize array for accumulating table rows:
309 $tRows = array();
310
311 // New pages INSIDE this pages
312 if ($this->newPagesInto
313 && $this->isTableAllowedForThisPage($this->pageinfo, 'pages')
314 && $BE_USER->check('tables_modify','pages')
315 && $BE_USER->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, 'pages')
316 ) {
317
318 // Create link to new page inside:
319 $t = 'pages';
320 $v = $TCA[$t];
321 $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
322 $this->linkWrap(
323 '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/i/'.($v['ctrl']['iconfile'] ? $v['ctrl']['iconfile'] : $t.'.gif'),'width="18" height="16"').' alt="" />'.
324 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.inside',1).')',
325 $t,
326 $this->id).'<br/>';
327
328 // Link to page-wizard:
329 $rowContent.= '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/joinbottom.gif','width="18" height="16"').' alt="" />'.
330 '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>1))).'">'.
331 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" /> '.
332 htmlspecialchars($LANG->getLL('clickForWizard')).
333 '</a>';
334 // Half-line:
335 $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg('','gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
336
337 // Compile table row:
338 $tRows[]='
339 <tr>
340 <td nowrap="nowrap">'.$rowContent.'</td>
341 <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
342 </tr>
343 ';
344 }
345
346 // New tables (but not pages) INSIDE this pages
347 if ($this->newContentInto) {
348 if (is_array($TCA)) {
349 foreach($TCA as $t => $v) {
350 if ($t!='pages'
351 && $this->showNewRecLink($t)
352 && $this->isTableAllowedForThisPage($this->pageinfo, $t)
353 && $BE_USER->check('tables_modify',$t)
354 && (($v['ctrl']['rootLevel'] xor $this->id) || $v['ctrl']['rootLevel']==-1)
355 && $BE_USER->workspaceCreateNewRecord($this->pageinfo['_ORIG_uid']?$this->pageinfo['_ORIG_uid']:$this->id, $t)
356 ) {
357
358 // Create new link for record:
359 $rowContent = '<img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/join.gif','width="18" height="16"').' alt="" />'.
360 $this->linkWrap(
361 t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
362 $LANG->sL($v['ctrl']['title'],1)
363 ,$t
364 ,$this->id);
365
366 // If the table is 'tt_content' (from "cms" extension), create link to wizard
367 if ($t=='tt_content') {
368
369 // If mod.web_list.newContentWiz.overrideWithExtension is set, use that extension's wizard instead:
370 $overrideExt = $this->web_list_modTSconfig['properties']['newContentWiz.']['overrideWithExtension'];
371 $pathToWizard = (t3lib_extMgm::isLoaded($overrideExt)) ? (t3lib_extMgm::extRelPath($overrideExt).'mod1/db_new_content_el.php') : 'sysext/cms/layout/db_new_content_el.php';
372
373 $href = $pathToWizard.'?id='.$this->id.'&returnUrl='.rawurlencode(t3lib_div::getIndpEnv('REQUEST_URI'));
374 $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/line.gif','width="18" height="16"').' alt="" />'.
375 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/joinbottom.gif','width="18" height="16"').' alt="" />'.
376 '<a href="'.htmlspecialchars($href).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_record.gif','width="16" height="12"').' alt="" /> '.
377 htmlspecialchars($LANG->getLL('clickForWizard')).
378 '</a>';
379
380 // Half-line added:
381 $rowContent.= '<br /><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/ol/halfline.gif','width="18" height="8"').' alt="" />';
382 }
383
384
385 // Compile table row:
386 $tRows[] = '
387 <tr>
388 <td nowrap="nowrap">'.$rowContent.'</td>
389 <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
390 </tr>
391 ';
392
393 }
394 }
395 }
396 }
397
398 // New pages AFTER this pages
399 if ($this->newPagesAfter
400 && $this->isTableAllowedForThisPage($this->pidInfo,'pages')
401 && $BE_USER->check('tables_modify','pages')
402 && $BE_USER->workspaceCreateNewRecord($this->pidInfo['uid'], 'pages')
403 ) {
404
405 // Create link to new page after
406 $t = 'pages';
407 $v = $TCA[$t];
408 $rowContent = $this->linkWrap(
409 t3lib_iconWorks::getIconImage($t,array(),$BACK_PATH,'').
410 $LANG->sL($v['ctrl']['title'],1).' ('.$LANG->sL('LLL:EXT:lang/locallang_core.php:db_new.php.after',1).')',
411 'pages',
412 -$this->id
413 );
414
415 // Compile table row:
416 $tRows[] = '
417 <tr>
418 <td nowrap="nowrap">'.$rowContent.'</td>
419 <td>'.t3lib_BEfunc::cshItem($t,'',$GLOBALS['BACK_PATH'],'',$doNotShowFullDescr).'</td>
420 </tr>
421 ';
422 } else {
423 // Compile table row:
424 $tRows[]='
425 <tr>
426 <td><img'.t3lib_iconWorks::skinImg($BACK_PATH,'gfx/ol/stopper.gif','width="18" height="16"').' alt="" /></td>
427 <td></td>
428 </tr>
429 ';
430 }
431
432 // Make table:
433 $this->code.='
434 <table border="0" cellpadding="0" cellspacing="0" id="typo3-newRecord">
435 '.implode('',$tRows).'
436 </table>
437 ';
438
439 // Create a link to the new-pages wizard.
440 if ($this->showNewRecLink('pages')) {
441 $this->code.='
442
443 <!--
444 Link; create new page:
445 -->
446 <div id="typo3-newPageLink">
447 <a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('pagesOnly'=>'1'))).'">'.
448 '<img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/new_page.gif','width="13" height="12"').' alt="" />'.
449 htmlspecialchars($LANG->getLL('createNewPage')).
450 '</a>
451 </div>
452 ';
453 }
454
455 // Add CSH:
456 $this->code.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_regular', $GLOBALS['BACK_PATH'],'<br/>');
457 }
458
459 /**
460 * Ending page output and echo'ing content to browser.
461 *
462 * @return void
463 */
464 function printContent() {
465 $this->content.= $this->doc->endPage();
466 $this->content = $this->doc->insertStylesAndJS($this->content);
467 echo $this->content;
468 }
469
470 /**
471 * Links the string $code to a create-new form for a record in $table created on page $pid
472 *
473 * @param string Link string
474 * @param string Table name (in which to create new record)
475 * @param integer PID value for the "&edit['.$table.']['.$pid.']=new" command (positive/negative)
476 * @param boolean If $addContentTable is set, then a new contentTable record is created together with pages
477 * @return string The link.
478 */
479 function linkWrap($code,$table,$pid,$addContentTable=0) {
480 $params = '&edit['.$table.']['.$pid.']=new'.
481 ($table=='pages'
482 && $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']
483 && isset($GLOBALS['TCA'][$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']])
484 && $addContentTable ?
485 '&edit['.$GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'].'][prev]=new&returnNewPageId=1' :
486 ''
487 );
488 $onClick = t3lib_BEfunc::editOnClick($params,'',$this->returnUrl);
489 return '<a href="#" onclick="'.htmlspecialchars($onClick).'">'.$code.'</a>';
490 }
491
492 /**
493 * Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
494 *
495 * @param array Record for parent page.
496 * @param string Table name to check
497 * @return boolean Returns true if the tablename $checkTable is allowed to be created on the page with record $pid_row
498 */
499 function isTableAllowedForThisPage($pid_row, $checkTable) {
500 global $TCA, $PAGES_TYPES;
501 if (!is_array($pid_row)) {
502 if ($GLOBALS['BE_USER']->user['admin']) {
503 return true;
504 } else {
505 return false;
506 }
507 }
508 // be_users and be_groups may not be created anywhere but in the root.
509 if ($checkTable=='be_users' || $checkTable=='be_groups') {
510 return false;
511 }
512 // Checking doktype:
513 $doktype = intval($pid_row['doktype']);
514 if (!$allowedTableList = $PAGES_TYPES[$doktype]['allowedTables']) {
515 $allowedTableList = $PAGES_TYPES['default']['allowedTables'];
516 }
517 if (strstr($allowedTableList,'*') || t3lib_div::inList($allowedTableList,$checkTable)) { // If all tables or the table is listed as a allowed type, return true
518 return true;
519 }
520 }
521
522 /**
523 * Returns true if the $table tablename is found in $allowedNewTables (or if $allowedNewTables is empty)
524 *
525 * @param string Table name to test if in allowedTables
526 * @param array Array of new tables that are allowed.
527 * @return boolean Returns true if the $table tablename is found in $allowedNewTables (or if $allowedNewTables is empty)
528 */
529 function showNewRecLink($table,$allowedNewTables='') {
530 $allowedNewTables = is_array($allowedNewTables) ? $allowedNewTables : $this->allowedNewTables;
531 return !count($allowedNewTables) || in_array($table,$allowedNewTables);
532 }
533 }
534
535 // Include extension?
536 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']) {
537 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/db_new.php']);
538 }
539
540
541
542
543
544 // Make instance:
545 $SOBE = t3lib_div::makeInstance('SC_db_new');
546 $SOBE->init();
547 $SOBE->main();
548 $SOBE->printContent();
549 ?>