2005-11-08 Sebastian Kurfuerst <sebastian@garbage-group.de>
[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 * 559: 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 'document.location=\''.$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,1);
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?"document.location='#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_1' => array(
404 'icon'=>'gfx/c_wiz/regular_text.gif',
405 'title'=>$LANG->getLL('common_1_title'),
406 'description'=>$LANG->getLL('common_1_description'),
407 'tt_content_defValues' => array(
408 'CType' => 'text'
409 )
410 ),
411 'common_2' => array(
412 'icon'=>'gfx/c_wiz/text_image_below.gif',
413 'title'=>$LANG->getLL('common_2_title'),
414 'description'=>$LANG->getLL('common_2_description'),
415 'tt_content_defValues' => array(
416 'CType' => 'textpic',
417 'imageorient' => 8
418 )
419 ),
420 'common_3' => array(
421 'icon'=>'gfx/c_wiz/text_image_right.gif',
422 'title'=>$LANG->getLL('common_3_title'),
423 'description'=>$LANG->getLL('common_3_description'),
424 'tt_content_defValues' => array(
425 'CType' => 'textpic',
426 'imageorient' => 17
427 )
428 ),
429 'common_4' => array(
430 'icon'=>'gfx/c_wiz/images_only.gif',
431 'title'=>$LANG->getLL('common_4_title'),
432 'description'=>$LANG->getLL('common_4_description'),
433 'tt_content_defValues' => array(
434 'CType' => 'image',
435 'imagecols' => 2
436 )
437 ),
438 'common_5' => array(
439 'icon'=>'gfx/c_wiz/bullet_list.gif',
440 'title'=>$LANG->getLL('common_5_title'),
441 'description'=>$LANG->getLL('common_5_description'),
442 'tt_content_defValues' => array(
443 'CType' => 'bullets',
444 )
445 ),
446 'common_6' => array(
447 'icon'=>'gfx/c_wiz/table.gif',
448 'title'=>$LANG->getLL('common_6_title'),
449 'description'=>$LANG->getLL('common_6_description'),
450 'tt_content_defValues' => array(
451 'CType' => 'table',
452 )
453 ),
454 'special' => array('header'=>$LANG->getLL('special')),
455 'special_1' => array(
456 'icon'=>'gfx/c_wiz/filelinks.gif',
457 'title'=>$LANG->getLL('special_1_title'),
458 'description'=>$LANG->getLL('special_1_description'),
459 'tt_content_defValues' => array(
460 'CType' => 'uploads',
461 )
462 ),
463 'special_2' => array(
464 'icon'=>'gfx/c_wiz/multimedia.gif',
465 'title'=>$LANG->getLL('special_2_title'),
466 'description'=>$LANG->getLL('special_2_description'),
467 'tt_content_defValues' => array(
468 'CType' => 'multimedia',
469 )
470 ),
471 'special_3' => array(
472 'icon'=>'gfx/c_wiz/sitemap2.gif',
473 'title'=>$LANG->getLL('special_3_title'),
474 'description'=>$LANG->getLL('special_3_description'),
475 'tt_content_defValues' => array(
476 'CType' => 'menu',
477 'menu_type' => 2
478 )
479 ),
480 'special_4' => array(
481 'icon'=>'gfx/c_wiz/html.gif',
482 'title'=>$LANG->getLL('special_4_title'),
483 'description'=>$LANG->getLL('special_4_description'),
484 'tt_content_defValues' => array(
485 'CType' => 'html',
486 )
487 ),
488 'forms' => array('header'=>$LANG->getLL('forms')),
489 'forms_1' => array(
490 'icon'=>'gfx/c_wiz/mailform.gif',
491 'title'=>$LANG->getLL('forms_1_title'),
492 'description'=>$LANG->getLL('forms_1_description'),
493 'tt_content_defValues' => array(
494 'CType' => 'mailform',
495 'bodytext' => trim('
496 # Example content:
497 Name: | *name = input,40 | Enter your name here
498 Email: | *email=input,40 |
499 Address: | address=textarea,40,5 |
500 Contact me: | tv=check | 1
501
502 |formtype_mail = submit | Send form!
503 |html_enabled=hidden | 1
504 |subject=hidden| This is the subject
505 ')
506 )
507 ),
508 'forms_2' => array(
509 'icon'=>'gfx/c_wiz/searchform.gif',
510 'title'=>$LANG->getLL('forms_2_title'),
511 'description'=>$LANG->getLL('forms_2_description'),
512 'tt_content_defValues' => array(
513 'CType' => 'search',
514 )
515 ),
516 'forms_3' => array(
517 'icon'=>'gfx/c_wiz/login_form.gif',
518 'title'=>$LANG->getLL('forms_3_title'),
519 'description'=>$LANG->getLL('forms_3_description'),
520 'tt_content_defValues' => array(
521 'CType' => 'login',
522 )
523 ),
524 'plugins' => array('header'=>$LANG->getLL('plugins')),
525 'plugins_1' => array(
526 'icon'=>'gfx/c_wiz/user_defined.gif',
527 'title'=>$LANG->getLL('plugins_1_title'),
528 'description'=>$LANG->getLL('plugins_1_description'),
529 'tt_content_defValues' => array(
530 'CType' => 'list',
531 )
532 ),
533 );
534
535
536 // PLUG-INS:
537 if (is_array($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) {
538 reset($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']);
539 while(list($class,$path)=each($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) {
540 $modObj = t3lib_div::makeInstance($class);
541 $wizardItems = $modObj->proc($wizardItems);
542 }
543 }
544
545 // Remove elements where preset values are not allowed:
546 $this->removeInvalidElements($wizardItems);
547
548 return $wizardItems;
549 }
550
551 /**
552 * Checks the array for elements which might contain unallowed default values and will unset them!
553 * 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).
554 *
555 * @param array Wizard items, passed by reference
556 * @return void
557 */
558 function removeInvalidElements(&$wizardItems) {
559 global $TCA;
560
561 // Load full table definition:
562 t3lib_div::loadTCA('tt_content');
563
564 $headersUsed = Array();
565 // Traverse wizard items:
566 foreach($wizardItems as $key => $cfg) {
567
568 // Exploding parameter string, if any (old style)
569 if ($wizardItems[$key]['params']) {
570 // Explode GET vars recursively
571 $tempGetVars = t3lib_div::explodeUrl2Array($wizardItems[$key]['params'],TRUE);
572 // 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).
573 if (is_array($tempGetVars['defVals']['tt_content'])) {
574 $wizardItems[$key]['tt_content_defValues'] = array_merge(is_array($wizardItems[$key]['tt_content_defValues']) ? $wizardItems[$key]['tt_content_defValues'] : array(), $tempGetVars['defVals']['tt_content']);
575 unset($tempGetVars['defVals']['tt_content']);
576 $wizardItems[$key]['params'] = t3lib_div::implodeArrayForUrl('',$tempGetVars);
577 }
578 }
579
580 // If tt_content_defValues are defined...:
581 if (is_array($wizardItems[$key]['tt_content_defValues'])) {
582
583 // Traverse field values:
584 foreach($wizardItems[$key]['tt_content_defValues'] as $fN => $fV) {
585 if (is_array($TCA['tt_content']['columns'][$fN])) {
586 // Get information about if the field value is OK:
587 $config = &$TCA['tt_content']['columns'][$fN]['config'];
588 $authModeDeny = $config['type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode('tt_content',$fN,$fV,$config['authMode']);
589
590 if ($authModeDeny) {
591 // Remove element all together:
592 unset($wizardItems[$key]);
593 break;
594 } else {
595 // Add the parameter:
596 $wizardItems[$key]['params'].= '&defVals[tt_content]['.$fN.']='.rawurlencode($fV);
597 $tmp = explode('_', $key);
598 $headersUsed[$tmp[0]] = $tmp[0];
599 }
600 }
601 }
602 }
603 }
604 // remove headers without elements
605 foreach ($wizardItems as $key => $cfg) {
606 $tmp = explode('_',$key);
607 if (count($tmp) == 2 && !$tmp[1] && !in_array($tmp[0], $headersUsed)) {
608 unset($wizardItems[$key]);
609 }
610 }
611 }
612 }
613
614 // Include extension?
615 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php']) {
616 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php']);
617 }
618
619
620
621
622
623
624
625
626
627
628
629
630 // Make instance:
631 $SOBE = t3lib_div::makeInstance('SC_db_new_content_el');
632 $SOBE->init();
633
634 // Include files?
635 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
636
637 $SOBE->main();
638 $SOBE->printContent();
639 ?>