Updated Copyright notices
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / layout / db_new_content_el.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2008 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
165 /**
166 * Internal backend template object
167 *
168 * @var mediumDoc
169 */
170 var $doc;
171
172 // Internal, dynamic:
173 var $include_once = array(); // Includes a list of files to include between init() and main() - see init()
174 var $content; // Used to accumulate the content of the module.
175 var $access; // Access boolean.
176
177 /**
178 * Constructor, initializing internal variables.
179 *
180 * @return void
181 */
182 function init() {
183 global $BE_USER,$BACK_PATH,$TBE_MODULES_EXT;
184
185 // Setting class files to include:
186 if (is_array($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) {
187 $this->include_once = array_merge($this->include_once,$TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']);
188 }
189
190 // Setting internal vars:
191 $this->id = intval(t3lib_div::_GP('id'));
192 $this->sys_language = intval(t3lib_div::_GP('sys_language_uid'));
193 $this->R_URI = t3lib_div::_GP('returnUrl');
194 $this->colPos = t3lib_div::_GP('colPos');
195 $this->uid_pid = intval(t3lib_div::_GP('uid_pid'));
196
197 $this->MCONF['name'] = 'xMOD_db_new_content_el';
198 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id,'mod.'.$this->MCONF['name']);
199
200 // Starting the document template object:
201 $this->doc = t3lib_div::makeInstance('template');
202 $this->doc->docType= 'xhtml_trans';
203 $this->doc->backPath = $BACK_PATH;
204 $this->doc->setModuleTemplate('templates/db_new_content_el.html');
205 $this->doc->JScode='';
206 $this->doc->form='<form action="" name="editForm"><input type="hidden" name="defValues" value="" />';
207
208 // Setting up the context sensitive menu:
209 $this->doc->getContextMenuCode();
210
211 // Getting the current page and receiving access information (used in main())
212 $perms_clause = $BE_USER->getPagePermsClause(1);
213 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->id,$perms_clause);
214 $this->access = is_array($this->pageinfo) ? 1 : 0;
215 }
216
217 /**
218 * Creating the module output.
219 *
220 * @return void
221 */
222 function main() {
223 global $LANG,$BACK_PATH;
224
225 if ($this->id && $this->access) {
226
227 // Init position map object:
228 $posMap = t3lib_div::makeInstance('ext_posMap');
229 $posMap->cur_sys_language = $this->sys_language;
230 $posMap->backPath = $BACK_PATH;
231
232 if ((string)$this->colPos!='') { // If a column is pre-set:
233 if ($this->uid_pid<0) {
234 $row=array();
235 $row['uid']=abs($this->uid_pid);
236 } else {
237 $row='';
238 }
239 $onClickEvent = $posMap->onClickInsertRecord($row,$this->colPos,'',$this->uid_pid,$this->sys_language);
240 } else {
241 $onClickEvent='';
242 }
243
244 $this->doc->JScode=$this->doc->wrapScriptTags('
245 function goToalt_doc() { //
246 '.$onClickEvent.'
247 }
248 ');
249
250
251 // ***************************
252 // Creating content
253 // ***************************
254 $this->content='';
255 $this->content.=$this->doc->header($LANG->getLL('newContentElement'));
256 $this->content.=$this->doc->spacer(5);
257
258 // Wizard
259 $code='';
260 $lines=array();
261 $wizardItems = $this->getWizardItems();
262
263 // Traverse items for the wizard.
264 // An item is either a header or an item rendered with a radio button and title/description and icon:
265 $cc=0;
266 foreach ($wizardItems as $k => $wInfo) {
267 if ($wInfo['header']) {
268 if ($cc>0) $lines[]='
269 <tr>
270 <td colspan="3"><br /></td>
271 </tr>';
272 $lines[]='
273 <tr class="bgColor5">
274 <td colspan="3"><strong>'.htmlspecialchars($wInfo['header']).'</strong></td>
275 </tr>';
276 } else {
277 $tL=array();
278
279 // Radio button:
280 $oC = "document.editForm.defValues.value=unescape('".rawurlencode($wInfo['params'])."');goToalt_doc();".(!$onClickEvent?"window.location.hash='#sel2';":'');
281 $tL[]='<input type="radio" name="tempB" value="'.htmlspecialchars($k).'" onclick="'.htmlspecialchars($this->doc->thisBlur().$oC).'" />';
282
283 // Onclick action for icon/title:
284 $aOnClick = 'document.getElementsByName(\'tempB\')['.$cc.'].checked=1;'.$this->doc->thisBlur().$oC.'return false;';
285
286 // Icon:
287 $iInfo = @getimagesize($wInfo['icon']);
288 $tL[]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,$wInfo['icon'],'').' alt="" /></a>';
289
290 // Title + description:
291 $tL[]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><strong>'.htmlspecialchars($wInfo['title']).'</strong><br />'.nl2br(htmlspecialchars(trim($wInfo['description']))).'</a>';
292
293 // Finally, put it together in a table row:
294 $lines[]='
295 <tr>
296 <td valign="top">'.implode('</td>
297 <td valign="top">',$tL).'</td>
298 </tr>';
299 $cc++;
300 }
301 }
302 // Add the wizard table to the content:
303 $code.=$LANG->getLL('sel1',1).'<br /><br />
304
305
306 <!--
307 Content Element wizard table:
308 -->
309 <table border="0" cellpadding="1" cellspacing="2" id="typo3-ceWizardTable">
310 '.implode('',$lines).'
311 </table>';
312 $this->content.= $this->doc->section(!$onClickEvent?$LANG->getLL('1_selectType'):'',$code,0,1);
313
314
315
316 // If the user must also select a column:
317 if (!$onClickEvent) {
318
319 // Add anchor "sel2"
320 $this->content.= $this->doc->section('','<a name="sel2"></a>');
321 $this->content.= $this->doc->spacer(20);
322
323 // Select position
324 $code = $LANG->getLL('sel2',1).'<br /><br />';
325
326 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
327 $modTSconfig_SHARED = t3lib_BEfunc::getModTSconfig($this->id,'mod.SHARED');
328 $colPosList = strcmp(trim($modTSconfig_SHARED['properties']['colPos_list']),'') ? trim($modTSconfig_SHARED['properties']['colPos_list']) : '1,0,2,3';
329 $colPosList = implode(',',array_unique(t3lib_div::intExplode(',',$colPosList))); // Removing duplicates, if any
330
331 // Finally, add the content of the column selector to the content:
332 $code.= $posMap->printContentElementColumns($this->id,0,$colPosList,1,$this->R_URI);
333 $this->content.= $this->doc->section($LANG->getLL('2_selectPosition'),$code,0,1);
334 }
335 } else { // In case of no access:
336 $this->content = '';
337 $this->content.= $this->doc->header($LANG->getLL('newContentElement'));
338 $this->content.= $this->doc->spacer(5);
339 }
340
341 // Setting up the buttons and markers for docheader
342 $docHeaderButtons = $this->getButtons();
343 $markers['CSH'] = $docHeaderButtons['csh'];
344 $markers['CONTENT'] = $this->content;
345
346 // Build the <body> for the module
347 $this->content = $this->doc->startPage($LANG->getLL('newContentElement'));
348 $this->content.= $this->doc->moduleBody($this->pageinfo, $docHeaderButtons, $markers);
349 $this->content.= $this->doc->endPage();
350 $this->content = $this->doc->insertStylesAndJS($this->content);
351 }
352
353 /**
354 * Print out the accumulated content:
355 *
356 * @return void
357 */
358 function printContent() {
359 echo $this->content;
360 }
361
362 /**
363 * Create the panel of buttons for submitting the form or otherwise perform operations.
364 *
365 * @return array all available buttons as an assoc. array
366 */
367 private function getButtons() {
368 global $LANG, $BACK_PATH;
369
370 $buttons = array(
371 'csh' => '',
372 'back' => ''
373 );
374
375
376 if ($this->id && $this->access) {
377 // CSH
378 $buttons['csh'] = t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_ce', $GLOBALS['BACK_PATH']);
379
380 // Back
381 if ($this->R_URI) {
382 $buttons['back'] = '<a href="' . htmlspecialchars($this->R_URI) . '" class="typo3-goBack">' .
383 '<img' . t3lib_iconWorks::skinImg($this->doc->backPath, 'gfx/goback.gif') . ' alt="" title="' . $LANG->getLL('goBack', 1) . '" />' .
384 '</a>';
385 }
386 }
387
388
389 return $buttons;
390 }
391
392
393
394
395
396
397
398
399
400 /***************************
401 *
402 * OTHER FUNCTIONS:
403 *
404 ***************************/
405
406
407 /**
408 * Returns the content of wizardArray() function...
409 *
410 * @return array Returns the content of wizardArray() function...
411 */
412 function getWizardItems() {
413 return $this->wizardArray();
414 }
415
416 /**
417 * Returns the array of elements in the wizard display.
418 * For the plugin section there is support for adding elements there from a global variable.
419 *
420 * @return array
421 */
422 function wizardArray() {
423 global $LANG,$TBE_MODULES_EXT;
424
425 $wizardItems = array(
426 'common' => array('header'=>$LANG->getLL('common')),
427 'common_regularText' => array( // Regular text element
428 'icon'=>'gfx/c_wiz/regular_text.gif',
429 'title'=>$LANG->getLL('common_regularText_title'),
430 'description'=>$LANG->getLL('common_regularText_description'),
431 'tt_content_defValues' => array(
432 'CType' => 'text'
433 )
434 ),
435 'common_textImage' => array( // Text with image
436 'icon'=>'gfx/c_wiz/text_image_right.gif',
437 'title'=>$LANG->getLL('common_textImage_title'),
438 'description'=>$LANG->getLL('common_textImage_description'),
439 'tt_content_defValues' => array(
440 'CType' => 'textpic',
441 'imageorient' => 17
442 )
443 ),
444 'common_imagesOnly' => array( // Images only
445 'icon'=>'gfx/c_wiz/images_only.gif',
446 'title'=>$LANG->getLL('common_imagesOnly_title'),
447 'description'=>$LANG->getLL('common_imagesOnly_description'),
448 'tt_content_defValues' => array(
449 'CType' => 'image',
450 'imagecols' => 2
451 )
452 ),
453 'common_bulletList' => array( // Bullet list
454 'icon'=>'gfx/c_wiz/bullet_list.gif',
455 'title'=>$LANG->getLL('common_bulletList_title'),
456 'description'=>$LANG->getLL('common_bulletList_description'),
457 'tt_content_defValues' => array(
458 'CType' => 'bullets',
459 )
460 ),
461 'common_table' => array( // Table
462 'icon'=>'gfx/c_wiz/table.gif',
463 'title'=>$LANG->getLL('common_table_title'),
464 'description'=>$LANG->getLL('common_table_description'),
465 'tt_content_defValues' => array(
466 'CType' => 'table',
467 )
468 ),
469 'special' => array('header'=>$LANG->getLL('special')),
470 'special_filelinks' => array( // Filelinks
471 'icon'=>'gfx/c_wiz/filelinks.gif',
472 'title'=>$LANG->getLL('special_filelinks_title'),
473 'description'=>$LANG->getLL('special_filelinks_description'),
474 'tt_content_defValues' => array(
475 'CType' => 'uploads',
476 )
477 ),
478 'special_multimedia' => array( // Multimedia
479 'icon'=>'gfx/c_wiz/multimedia.gif',
480 'title'=>$LANG->getLL('special_multimedia_title'),
481 'description'=>$LANG->getLL('special_multimedia_description'),
482 'tt_content_defValues' => array(
483 'CType' => 'multimedia',
484 )
485 ),
486 'special_sitemap' => array( // Sitemap
487 'icon'=>'gfx/c_wiz/sitemap2.gif',
488 'title'=>$LANG->getLL('special_sitemap_title'),
489 'description'=>$LANG->getLL('special_sitemap_description'),
490 'tt_content_defValues' => array(
491 'CType' => 'menu',
492 'menu_type' => 2
493 )
494 ),
495 'special_plainHTML' => array( // Plain HTML
496 'icon'=>'gfx/c_wiz/html.gif',
497 'title'=>$LANG->getLL('special_plainHTML_title'),
498 'description'=>$LANG->getLL('special_plainHTML_description'),
499 'tt_content_defValues' => array(
500 'CType' => 'html',
501 )
502 ),
503 'forms' => array('header'=>$LANG->getLL('forms')),
504 'forms_mail' => array( // Mail form
505 'icon'=>'gfx/c_wiz/mailform.gif',
506 'title'=>$LANG->getLL('forms_mail_title'),
507 'description'=>$LANG->getLL('forms_mail_description'),
508 'tt_content_defValues' => array(
509 'CType' => 'mailform',
510 'bodytext' => trim('
511 # Example content:
512 Name: | *name = input,40 | Enter your name here
513 Email: | *email=input,40 |
514 Address: | address=textarea,40,5 |
515 Contact me: | tv=check | 1
516
517 |formtype_mail = submit | Send form!
518 |html_enabled=hidden | 1
519 |subject=hidden| This is the subject
520 ')
521 )
522 ),
523 'forms_search' => array( // Search form
524 'icon'=>'gfx/c_wiz/searchform.gif',
525 'title'=>$LANG->getLL('forms_search_title'),
526 'description'=>$LANG->getLL('forms_search_description'),
527 'tt_content_defValues' => array(
528 'CType' => 'search',
529 )
530 ),
531 'forms_login' => array( // Login form
532 'icon'=>'gfx/c_wiz/login_form.gif',
533 'title'=>$LANG->getLL('forms_login_title'),
534 'description'=>$LANG->getLL('forms_login_description'),
535 'tt_content_defValues' => array(
536 'CType' => 'login',
537 )
538 ),
539 'plugins' => array('header'=>$LANG->getLL('plugins')),
540 'plugins_general' => array( // General plugin
541 'icon'=>'gfx/c_wiz/user_defined.gif',
542 'title'=>$LANG->getLL('plugins_general_title'),
543 'description'=>$LANG->getLL('plugins_general_description'),
544 'tt_content_defValues' => array(
545 'CType' => 'list',
546 )
547 ),
548 );
549
550
551 // PLUG-INS:
552 if (is_array($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) {
553 reset($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']);
554 while(list($class,$path)=each($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) {
555 $modObj = t3lib_div::makeInstance($class);
556 $wizardItems = $modObj->proc($wizardItems);
557 }
558 }
559
560 // Remove elements where preset values are not allowed:
561 $this->removeInvalidElements($wizardItems);
562
563 return $wizardItems;
564 }
565
566 /**
567 * Checks the array for elements which might contain unallowed default values and will unset them!
568 * 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).
569 *
570 * @param array Wizard items, passed by reference
571 * @return void
572 */
573 function removeInvalidElements(&$wizardItems) {
574 global $TCA;
575
576 // Load full table definition:
577 t3lib_div::loadTCA('tt_content');
578
579 // Get TCEFORM from TSconfig of current page
580 $row = array('pid'=>$this->id);
581 $TCEFORM_TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig('tt_content',$row);
582 $removeItems = t3lib_div::trimExplode(',',$TCEFORM_TSconfig['CType']['removeItems'],1);
583
584 $headersUsed = Array();
585 // Traverse wizard items:
586 foreach($wizardItems as $key => $cfg) {
587
588 // Exploding parameter string, if any (old style)
589 if ($wizardItems[$key]['params']) {
590 // Explode GET vars recursively
591 $tempGetVars = t3lib_div::explodeUrl2Array($wizardItems[$key]['params'],TRUE);
592 // 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).
593 if (is_array($tempGetVars['defVals']['tt_content'])) {
594 $wizardItems[$key]['tt_content_defValues'] = array_merge(is_array($wizardItems[$key]['tt_content_defValues']) ? $wizardItems[$key]['tt_content_defValues'] : array(), $tempGetVars['defVals']['tt_content']);
595 unset($tempGetVars['defVals']['tt_content']);
596 $wizardItems[$key]['params'] = t3lib_div::implodeArrayForUrl('',$tempGetVars);
597 }
598 }
599
600 // If tt_content_defValues are defined...:
601 if (is_array($wizardItems[$key]['tt_content_defValues'])) {
602
603 // Traverse field values:
604 foreach($wizardItems[$key]['tt_content_defValues'] as $fN => $fV) {
605 if (is_array($TCA['tt_content']['columns'][$fN])) {
606 // Get information about if the field value is OK:
607 $config = &$TCA['tt_content']['columns'][$fN]['config'];
608 $authModeDeny = $config['type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode('tt_content',$fN,$fV,$config['authMode']);
609
610 if ($authModeDeny || ($fN=='CType' && in_array($fV,$removeItems))) {
611 // Remove element all together:
612 unset($wizardItems[$key]);
613 break;
614 } else {
615 // Add the parameter:
616 $wizardItems[$key]['params'].= '&defVals[tt_content]['.$fN.']='.rawurlencode($fV);
617 $tmp = explode('_', $key);
618 $headersUsed[$tmp[0]] = $tmp[0];
619 }
620 }
621 }
622 }
623 }
624 // remove headers without elements
625 foreach ($wizardItems as $key => $cfg) {
626 $tmp = explode('_',$key);
627 if ($tmp[0] && !$tmp[1] && !in_array($tmp[0], $headersUsed)) {
628 unset($wizardItems[$key]);
629 }
630 }
631 }
632 }
633
634 // Include extension?
635 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php']) {
636 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php']);
637 }
638
639
640
641
642
643
644
645
646
647
648
649
650 // Make instance:
651 $SOBE = t3lib_div::makeInstance('SC_db_new_content_el');
652 $SOBE->init();
653
654 // Include files?
655 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
656
657 $SOBE->main();
658 $SOBE->printContent();
659 ?>