Fixed bug #4226: New content elements wizard removes CE from array if tt_content_defV...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / layout / db_new_content_el.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 content elements wizard
29 * (Part of the 'cms' extension)
30 *
31 * $Id$
32 * Revised for TYPO3 3.6 November/2003 by Kasper Skaarhoj
33 * XHTML compatible.
34 *
35 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
36 */
37 /**
38 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 *
41 *
42 * 101: class ext_posMap extends t3lib_positionMap
43 * 111: function wrapRecordTitle($str,$row)
44 * 125: function onClickInsertRecord($row,$vv,$moveUid,$pid,$sys_lang=0)
45 *
46 *
47 * 153: class SC_db_new_content_el
48 * 176: function init()
49 * 212: function main()
50 * 359: function printContent()
51 *
52 * SECTION: OTHER FUNCTIONS:
53 * 388: function getWizardItems()
54 * 398: function wizardArray()
55 * 549: function removeInvalidElements(&$wizardItems)
56 *
57 * TOTAL FUNCTIONS: 8
58 * (This index is automatically created/updated by the extension "extdeveval")
59 *
60 */
61
62
63 unset($MCONF);
64 require('conf.php');
65 require($BACK_PATH.'init.php');
66 require($BACK_PATH.'template.php');
67
68 // Unset MCONF/MLANG since all we wanted was back path etc. for this particular script.
69 unset($MCONF);
70 unset($MLANG);
71
72 // Merging locallang files/arrays:
73 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
74 $LOCAL_LANG_orig = $LOCAL_LANG;
75 $LANG->includeLLFile('EXT:cms/layout/locallang_db_new_content_el.xml');
76 $LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG_orig,$LOCAL_LANG);
77
78 // Exits if 'cms' extension is not loaded:
79 t3lib_extMgm::isLoaded('cms',1);
80
81 // Include needed libraries:
82 require_once(PATH_t3lib.'class.t3lib_page.php');
83 require_once(PATH_t3lib.'class.t3lib_positionmap.php');
84
85
86
87
88
89
90
91
92
93
94 /**
95 * Local position map class
96 *
97 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
98 * @package TYPO3
99 * @subpackage core
100 */
101 class ext_posMap extends t3lib_positionMap {
102 var $dontPrintPageInsertIcons = 1;
103
104 /**
105 * Wrapping the title of the record - here we just return it.
106 *
107 * @param string The title value.
108 * @param array The record row.
109 * @return string Wrapped title string.
110 */
111 function wrapRecordTitle($str,$row) {
112 return $str;
113 }
114
115 /**
116 * Create on-click event value.
117 *
118 * @param array The record.
119 * @param string Column position value.
120 * @param integer Move uid
121 * @param integer PID value.
122 * @param integer System language
123 * @return string
124 */
125 function onClickInsertRecord($row,$vv,$moveUid,$pid,$sys_lang=0) {
126 $table='tt_content';
127
128 $location=$this->backPath.'alt_doc.php?edit[tt_content]['.(is_array($row)?-$row['uid']:$pid).']=new&defVals[tt_content][colPos]='.$vv.'&defVals[tt_content][sys_language_uid]='.$sys_lang.'&returnUrl='.rawurlencode($GLOBALS['SOBE']->R_URI);
129
130 return 'window.location.href=\''.$location.'\'+document.editForm.defValues.value; return false;';
131 }
132 }
133
134
135
136
137
138
139
140
141
142
143
144
145
146 /**
147 * Script Class for the New Content element wizard
148 *
149 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
150 * @package TYPO3
151 * @subpackage core
152 */
153 class SC_db_new_content_el {
154
155 // Internal, static (from GPvars):
156 var $id; // Page id
157 var $sys_language=0; // Sys language
158 var $R_URI=''; // Return URL.
159 var $colPos; // If set, the content is destined for a specific column.
160 var $uid_pid; //
161
162 // Internal, static:
163 var $modTSconfig=array(); // Module TSconfig.
164 var $doc; // Internal backend template object
165
166 // Internal, dynamic:
167 var $include_once = array(); // Includes a list of files to include between init() and main() - see init()
168 var $content; // Used to accumulate the content of the module.
169 var $access; // Access boolean.
170
171 /**
172 * Constructor, initializing internal variables.
173 *
174 * @return void
175 */
176 function init() {
177 global $BE_USER,$BACK_PATH,$TBE_MODULES_EXT;
178
179 // Setting class files to include:
180 if (is_array($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) {
181 $this->include_once = array_merge($this->include_once,$TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']);
182 }
183
184 // Setting internal vars:
185 $this->id = intval(t3lib_div::_GP('id'));
186 $this->sys_language = intval(t3lib_div::_GP('sys_language_uid'));
187 $this->R_URI = t3lib_div::_GP('returnUrl');
188 $this->colPos = t3lib_div::_GP('colPos');
189 $this->uid_pid = intval(t3lib_div::_GP('uid_pid'));
190
191 $this->MCONF['name'] = 'xMOD_db_new_content_el';
192 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id,'mod.'.$this->MCONF['name']);
193
194 // Starting the document template object:
195 $this->doc = t3lib_div::makeInstance('mediumDoc');
196 $this->doc->docType= 'xhtml_trans';
197 $this->doc->backPath = $BACK_PATH;
198 $this->doc->JScode='';
199 $this->doc->form='<form action="" name="editForm"><input type="hidden" name="defValues" value="" />';
200
201 // Getting the current page and receiving access information (used in main())
202 $perms_clause = $BE_USER->getPagePermsClause(1);
203 $pageinfo = t3lib_BEfunc::readPageAccess($this->id,$perms_clause);
204 $this->access = is_array($pageinfo) ? 1 : 0;
205 }
206
207 /**
208 * Creating the module output.
209 *
210 * @return void
211 */
212 function main() {
213 global $LANG,$BACK_PATH;
214
215 if ($this->id && $this->access) {
216
217 // Init position map object:
218 $posMap = t3lib_div::makeInstance('ext_posMap');
219 $posMap->cur_sys_language = $this->sys_language;
220 $posMap->backPath = $BACK_PATH;
221
222 if ((string)$this->colPos!='') { // If a column is pre-set:
223 if ($this->uid_pid<0) {
224 $row=array();
225 $row['uid']=abs($this->uid_pid);
226 } else {
227 $row='';
228 }
229 $onClickEvent = $posMap->onClickInsertRecord($row,$this->colPos,'',$this->uid_pid,$this->sys_language);
230 } else {
231 $onClickEvent='';
232 }
233
234 $this->doc->JScode=$this->doc->wrapScriptTags('
235 function goToalt_doc() { //
236 '.$onClickEvent.'
237 }
238 ');
239
240
241 // ***************************
242 // Creating content
243 // ***************************
244 $this->content='';
245 $this->content.=$this->doc->startPage($LANG->getLL('newContentElement'));
246 $this->content.=$this->doc->header($LANG->getLL('newContentElement'));
247 $this->content.=$this->doc->spacer(5);
248
249 $elRow = t3lib_BEfunc::getRecordWSOL('pages',$this->id);
250 $hline = t3lib_iconWorks::getIconImage('pages',$elRow,$BACK_PATH,' title="'.htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($elRow,'pages')).'" align="top"');
251 $hline.= t3lib_BEfunc::getRecordTitle('pages',$elRow,TRUE);
252 $this->content.=$this->doc->section('',$hline,0,1);
253 $this->content.=$this->doc->spacer(10);
254
255
256 // Wizard
257 $code='';
258 $lines=array();
259 $wizardItems = $this->getWizardItems();
260
261 // Traverse items for the wizard.
262 // An item is either a header or an item rendered with a radio button and title/description and icon:
263 $cc=0;
264 foreach ($wizardItems as $k => $wInfo) {
265 if ($wInfo['header']) {
266 if ($cc>0) $lines[]='
267 <tr>
268 <td colspan="3"><br /></td>
269 </tr>';
270 $lines[]='
271 <tr class="bgColor5">
272 <td colspan="3"><strong>'.htmlspecialchars($wInfo['header']).'</strong></td>
273 </tr>';
274 } else {
275 $tL=array();
276
277 // Radio button:
278 $oC = "document.editForm.defValues.value=unescape('".rawurlencode($wInfo['params'])."');goToalt_doc();".(!$onClickEvent?"window.location.hash='#sel2';":'');
279 $tL[]='<input type="radio" name="tempB" value="'.htmlspecialchars($k).'" onclick="'.htmlspecialchars($this->doc->thisBlur().$oC).'" />';
280
281 // Onclick action for icon/title:
282 $aOnClick = 'document.editForm.tempB['.$cc.'].checked=1;'.$this->doc->thisBlur().$oC.'return false;';
283
284 // Icon:
285 $iInfo = @getimagesize($wInfo['icon']);
286 $tL[]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,$wInfo['icon'],'').' alt="" /></a>';
287
288 // Title + description:
289 $tL[]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><strong>'.htmlspecialchars($wInfo['title']).'</strong><br />'.nl2br(htmlspecialchars(trim($wInfo['description']))).'</a>';
290
291 // Finally, put it together in a table row:
292 $lines[]='
293 <tr>
294 <td valign="top">'.implode('</td>
295 <td valign="top">',$tL).'</td>
296 </tr>';
297 $cc++;
298 }
299 }
300 // Add the wizard table to the content:
301 $code.=$LANG->getLL('sel1',1).'<br /><br />
302
303
304 <!--
305 Content Element wizard table:
306 -->
307 <table border="0" cellpadding="1" cellspacing="2" id="typo3-ceWizardTable">
308 '.implode('',$lines).'
309 </table>';
310 $this->content.= $this->doc->section(!$onClickEvent?$LANG->getLL('1_selectType'):'',$code,0,1);
311
312
313
314 // If the user must also select a column:
315 if (!$onClickEvent) {
316
317 // Add anchor "sel2"
318 $this->content.= $this->doc->section('','<a name="sel2"></a>');
319 $this->content.= $this->doc->spacer(20);
320
321 // Select position
322 $code = $LANG->getLL('sel2',1).'<br /><br />';
323
324 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
325 $modTSconfig_SHARED = t3lib_BEfunc::getModTSconfig($this->id,'mod.SHARED');
326 $colPosList = strcmp(trim($modTSconfig_SHARED['properties']['colPos_list']),'') ? trim($modTSconfig_SHARED['properties']['colPos_list']) : '1,0,2,3';
327 $colPosList = implode(',',array_unique(t3lib_div::intExplode(',',$colPosList))); // Removing duplicates, if any
328
329 // Finally, add the content of the column selector to the content:
330 $code.= $posMap->printContentElementColumns($this->id,0,$colPosList,1,$this->R_URI);
331 $this->content.= $this->doc->section($LANG->getLL('2_selectPosition'),$code,0,1);
332 }
333
334 // IF there is a return-url set, then print a go-back link:
335 if ($this->R_URI) {
336 $code='<br /><br /><a href="'.htmlspecialchars($this->R_URI).'" class="typo3-goBack"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,'gfx/goback.gif','width="14" height="14"').' alt="" />'.$LANG->getLL('goBack',1).'</a>';
337 $this->content.= $this->doc->section('',$code,0,1);
338 }
339
340 // Add CSH:
341 $this->content.= $this->doc->section('',t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_ce', $GLOBALS['BACK_PATH'],'<br/>'),0,1);
342
343 // Add a very high clear-gif, 700 px (so that the link to the anchor "sel2" shows this part in top for sure...)
344 $this->content.= $this->doc->section('','<img src="clear.gif" width="1" height="700" alt="" />',0,1);
345
346 } else { // In case of no access:
347 $this->content = '';
348 $this->content.= $this->doc->startPage($LANG->getLL('newContentElement'));
349 $this->content.= $this->doc->header($LANG->getLL('newContentElement'));
350 $this->content.= $this->doc->spacer(5);
351 }
352 }
353
354 /**
355 * Print out the accumulated content:
356 *
357 * @return void
358 */
359 function printContent() {
360 global $SOBE;
361
362 $this->content.= $this->doc->endPage();
363 echo $this->content;
364 }
365
366
367
368
369
370
371
372
373
374
375
376 /***************************
377 *
378 * OTHER FUNCTIONS:
379 *
380 ***************************/
381
382
383 /**
384 * Returns the content of wizardArray() function...
385 *
386 * @return array Returns the content of wizardArray() function...
387 */
388 function getWizardItems() {
389 return $this->wizardArray();
390 }
391
392 /**
393 * Returns the array of elements in the wizard display.
394 * For the plugin section there is support for adding elements there from a global variable.
395 *
396 * @return array
397 */
398 function wizardArray() {
399 global $LANG,$TBE_MODULES_EXT;
400
401 $wizardItems = array(
402 'common' => array('header'=>$LANG->getLL('common')),
403 'common_regularText' => array( // Regular text element
404 'icon'=>'gfx/c_wiz/regular_text.gif',
405 'title'=>$LANG->getLL('common_regularText_title'),
406 'description'=>$LANG->getLL('common_regularText_description'),
407 'tt_content_defValues' => array(
408 'CType' => 'text'
409 )
410 ),
411 'common_textImage' => array( // Text with image
412 'icon'=>'gfx/c_wiz/text_image_right.gif',
413 'title'=>$LANG->getLL('common_textImage_title'),
414 'description'=>$LANG->getLL('common_textImage_description'),
415 'tt_content_defValues' => array(
416 'CType' => 'textpic',
417 'imageorient' => 17
418 )
419 ),
420 'common_imagesOnly' => array( // Images only
421 'icon'=>'gfx/c_wiz/images_only.gif',
422 'title'=>$LANG->getLL('common_imagesOnly_title'),
423 'description'=>$LANG->getLL('common_imagesOnly_description'),
424 'tt_content_defValues' => array(
425 'CType' => 'image',
426 'imagecols' => 2
427 )
428 ),
429 'common_bulletList' => array( // Bullet list
430 'icon'=>'gfx/c_wiz/bullet_list.gif',
431 'title'=>$LANG->getLL('common_bulletList_title'),
432 'description'=>$LANG->getLL('common_bulletList_description'),
433 'tt_content_defValues' => array(
434 'CType' => 'bullets',
435 )
436 ),
437 'common_table' => array( // Table
438 'icon'=>'gfx/c_wiz/table.gif',
439 'title'=>$LANG->getLL('common_table_title'),
440 'description'=>$LANG->getLL('common_table_description'),
441 'tt_content_defValues' => array(
442 'CType' => 'table',
443 )
444 ),
445 'special' => array('header'=>$LANG->getLL('special')),
446 'special_filelinks' => array( // Filelinks
447 'icon'=>'gfx/c_wiz/filelinks.gif',
448 'title'=>$LANG->getLL('special_filelinks_title'),
449 'description'=>$LANG->getLL('special_filelinks_description'),
450 'tt_content_defValues' => array(
451 'CType' => 'uploads',
452 )
453 ),
454 'special_multimedia' => array( // Multimedia
455 'icon'=>'gfx/c_wiz/multimedia.gif',
456 'title'=>$LANG->getLL('special_multimedia_title'),
457 'description'=>$LANG->getLL('special_multimedia_description'),
458 'tt_content_defValues' => array(
459 'CType' => 'multimedia',
460 )
461 ),
462 'special_sitemap' => array( // Sitemap
463 'icon'=>'gfx/c_wiz/sitemap2.gif',
464 'title'=>$LANG->getLL('special_sitemap_title'),
465 'description'=>$LANG->getLL('special_sitemap_description'),
466 'tt_content_defValues' => array(
467 'CType' => 'menu',
468 'menu_type' => 2
469 )
470 ),
471 'special_plainHTML' => array( // Plain HTML
472 'icon'=>'gfx/c_wiz/html.gif',
473 'title'=>$LANG->getLL('special_plainHTML_title'),
474 'description'=>$LANG->getLL('special_plainHTML_description'),
475 'tt_content_defValues' => array(
476 'CType' => 'html',
477 )
478 ),
479 'forms' => array('header'=>$LANG->getLL('forms')),
480 'forms_mail' => array( // Mail form
481 'icon'=>'gfx/c_wiz/mailform.gif',
482 'title'=>$LANG->getLL('forms_mail_title'),
483 'description'=>$LANG->getLL('forms_mail_description'),
484 'tt_content_defValues' => array(
485 'CType' => 'mailform',
486 'bodytext' => trim('
487 # Example content:
488 Name: | *name = input,40 | Enter your name here
489 Email: | *email=input,40 |
490 Address: | address=textarea,40,5 |
491 Contact me: | tv=check | 1
492
493 |formtype_mail = submit | Send form!
494 |html_enabled=hidden | 1
495 |subject=hidden| This is the subject
496 ')
497 )
498 ),
499 'forms_search' => array( // Search form
500 'icon'=>'gfx/c_wiz/searchform.gif',
501 'title'=>$LANG->getLL('forms_search_title'),
502 'description'=>$LANG->getLL('forms_search_description'),
503 'tt_content_defValues' => array(
504 'CType' => 'search',
505 )
506 ),
507 'forms_login' => array( // Login form
508 'icon'=>'gfx/c_wiz/login_form.gif',
509 'title'=>$LANG->getLL('forms_login_title'),
510 'description'=>$LANG->getLL('forms_login_description'),
511 'tt_content_defValues' => array(
512 'CType' => 'login',
513 )
514 ),
515 'plugins' => array('header'=>$LANG->getLL('plugins')),
516 'plugins_general' => array( // General plugin
517 'icon'=>'gfx/c_wiz/user_defined.gif',
518 'title'=>$LANG->getLL('plugins_general_title'),
519 'description'=>$LANG->getLL('plugins_general_description'),
520 'tt_content_defValues' => array(
521 'CType' => 'list',
522 )
523 ),
524 );
525
526
527 // PLUG-INS:
528 if (is_array($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) {
529 reset($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']);
530 while(list($class,$path)=each($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) {
531 $modObj = t3lib_div::makeInstance($class);
532 $wizardItems = $modObj->proc($wizardItems);
533 }
534 }
535
536 // Remove elements where preset values are not allowed:
537 $this->removeInvalidElements($wizardItems);
538
539 return $wizardItems;
540 }
541
542 /**
543 * Checks the array for elements which might contain unallowed default values and will unset them!
544 * Looks for the "tt_content_defValues" key in each element and if found it will traverse that array as fieldname / value pairs and check. The values will be added to the "params" key of the array (which should probably be unset or empty by default).
545 *
546 * @param array Wizard items, passed by reference
547 * @return void
548 */
549 function removeInvalidElements(&$wizardItems) {
550 global $TCA;
551
552 // Load full table definition:
553 t3lib_div::loadTCA('tt_content');
554
555 // Get TCEFORM from TSconfig of current page
556 $row = array('pid'=>$this->id);
557 $TCEFORM_TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig('tt_content',$row);
558 $removeItems = t3lib_div::trimExplode(',',$TCEFORM_TSconfig['CType']['removeItems'],1);
559
560 $headersUsed = Array();
561 // Traverse wizard items:
562 foreach($wizardItems as $key => $cfg) {
563
564 // Exploding parameter string, if any (old style)
565 if ($wizardItems[$key]['params']) {
566 // Explode GET vars recursively
567 $tempGetVars = t3lib_div::explodeUrl2Array($wizardItems[$key]['params'],TRUE);
568 // If tt_content values are set, merge them into the tt_content_defValues array, unset them from $tempGetVars and re-implode $tempGetVars into the param string (in case remaining parameters are around).
569 if (is_array($tempGetVars['defVals']['tt_content'])) {
570 $wizardItems[$key]['tt_content_defValues'] = array_merge(is_array($wizardItems[$key]['tt_content_defValues']) ? $wizardItems[$key]['tt_content_defValues'] : array(), $tempGetVars['defVals']['tt_content']);
571 unset($tempGetVars['defVals']['tt_content']);
572 $wizardItems[$key]['params'] = t3lib_div::implodeArrayForUrl('',$tempGetVars);
573 }
574 }
575
576 // If tt_content_defValues are defined...:
577 if (is_array($wizardItems[$key]['tt_content_defValues'])) {
578
579 // Traverse field values:
580 foreach($wizardItems[$key]['tt_content_defValues'] as $fN => $fV) {
581 if (is_array($TCA['tt_content']['columns'][$fN])) {
582 // Get information about if the field value is OK:
583 $config = &$TCA['tt_content']['columns'][$fN]['config'];
584 $authModeDeny = $config['type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode('tt_content',$fN,$fV,$config['authMode']);
585
586 if ($authModeDeny || ($fN=='CType' && in_array($fV,$removeItems))) {
587 // Remove element all together:
588 unset($wizardItems[$key]);
589 break;
590 } else {
591 // Add the parameter:
592 $wizardItems[$key]['params'].= '&defVals[tt_content]['.$fN.']='.rawurlencode($fV);
593 $tmp = explode('_', $key);
594 $headersUsed[$tmp[0]] = $tmp[0];
595 }
596 }
597 }
598 }
599 }
600 // remove headers without elements
601 foreach ($wizardItems as $key => $cfg) {
602 $tmp = explode('_',$key);
603 if ($tmp[0] && !$tmp[1] && !in_array($tmp[0], $headersUsed)) {
604 unset($wizardItems[$key]);
605 }
606 }
607 }
608 }
609
610 // Include extension?
611 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php']) {
612 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php']);
613 }
614
615
616
617
618
619
620
621
622
623
624
625
626 // Make instance:
627 $SOBE = t3lib_div::makeInstance('SC_db_new_content_el');
628 $SOBE->init();
629
630 // Include files?
631 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
632
633 $SOBE->main();
634 $SOBE->printContent();
635 ?>