Changed lots of stuff...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / layout / db_new_content_el.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@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 <kasper@typo3.com>
36 */
37 /**
38 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 *
41 *
42 * 100: class ext_posMap extends t3lib_positionMap
43 * 110: function wrapRecordTitle($str,$row)
44 * 124: function onClickInsertRecord($row,$vv,$moveUid,$pid,$sys_lang=0)
45 *
46 *
47 * 152: class SC_db_new_content_el
48 * 175: function init()
49 * 211: function main()
50 * 355: function printContent()
51 *
52 * SECTION: OTHER FUNCTIONS:
53 * 384: function getWizardItems()
54 * 394: function wizardArray()
55 *
56 * TOTAL FUNCTIONS: 7
57 * (This index is automatically created/updated by the extension "extdeveval")
58 *
59 */
60
61
62 unset($MCONF);
63 require ('conf.php');
64 require ($BACK_PATH.'init.php');
65 require ($BACK_PATH.'template.php');
66
67 // Unset MCONF/MLANG since all we wanted was back path etc. for this particular script.
68 unset($MCONF);
69 unset($MLANG);
70
71 // Merging locallang files/arrays:
72 include ($BACK_PATH.'sysext/lang/locallang_misc.php');
73 $LOCAL_LANG_orig = $LOCAL_LANG;
74 include ('locallang_db_new_content_el.php');
75 $LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG_orig,$LOCAL_LANG);
76
77 // Exits if 'cms' extension is not loaded:
78 t3lib_extMgm::isLoaded('cms',1);
79
80 // Include needed libraries:
81 require_once (PATH_t3lib.'class.t3lib_page.php');
82 require_once (PATH_t3lib.'class.t3lib_positionmap.php');
83
84
85
86
87
88
89
90
91
92
93 /**
94 * Local position map class
95 *
96 * @author Kasper Skaarhoj <kasper@typo3.com>
97 * @package TYPO3
98 * @subpackage core
99 */
100 class ext_posMap extends t3lib_positionMap {
101 var $dontPrintPageInsertIcons = 1;
102
103 /**
104 * Wrapping the title of the record - here we just return it.
105 *
106 * @param string The title value.
107 * @param array The record row.
108 * @return string Wrapped title string.
109 */
110 function wrapRecordTitle($str,$row) {
111 return $str;
112 }
113
114 /**
115 * Create on-click event value.
116 *
117 * @param array The record.
118 * @param string Column position value.
119 * @param integer Move uid
120 * @param integer PID value.
121 * @param integer System language
122 * @return string
123 */
124 function onClickInsertRecord($row,$vv,$moveUid,$pid,$sys_lang=0) {
125 $table='tt_content';
126
127 $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);
128
129 return 'document.location=\''.$location.'\'+document.editForm.defValues.value; return false;';
130 }
131 }
132
133
134
135
136
137
138
139
140
141
142
143
144
145 /**
146 * Script Class for the New Content element wizard
147 *
148 * @author Kasper Skaarhoj <kasper@typo3.com>
149 * @package TYPO3
150 * @subpackage core
151 */
152 class SC_db_new_content_el {
153
154 // Internal, static (from GPvars):
155 var $id; // Page id
156 var $sys_language=0; // Sys language
157 var $R_URI=''; // Return URL.
158 var $colPos; // If set, the content is destined for a specific column.
159 var $uid_pid; //
160
161 // Internal, static:
162 var $modTSconfig=array(); // Module TSconfig.
163 var $doc; // Internal backend template object
164
165 // Internal, dynamic:
166 var $include_once = array(); // Includes a list of files to include between init() and main() - see init()
167 var $content; // Used to accumulate the content of the module.
168 var $access; // Access boolean.
169
170 /**
171 * Constructor, initializing internal variables.
172 *
173 * @return void
174 */
175 function init() {
176 global $BE_USER,$BACK_PATH,$TBE_MODULES_EXT;
177
178 // Setting class files to include:
179 if (is_array($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) {
180 $this->include_once = array_merge($this->include_once,$TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']);
181 }
182
183 // Setting internal vars:
184 $this->id = intval(t3lib_div::_GP('id'));
185 $this->sys_language = intval(t3lib_div::_GP('sys_language_uid'));
186 $this->R_URI = t3lib_div::_GP('returnUrl');
187 $this->colPos = t3lib_div::_GP('colPos');
188 $this->uid_pid = intval(t3lib_div::_GP('uid_pid'));
189
190 $this->MCONF['name'] = 'xMOD_db_new_content_el';
191 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id,'mod.'.$this->MCONF['name']);
192
193 // Starting the document template object:
194 $this->doc = t3lib_div::makeInstance('mediumDoc');
195 $this->doc->docType= 'xhtml_trans';
196 $this->doc->backPath = $BACK_PATH;
197 $this->doc->JScode='';
198 $this->doc->form='<form action="" name="editForm"><input type="hidden" name="defValues" value="" />';
199
200 // Getting the current page and receiving access information (used in main())
201 $perms_clause = $BE_USER->getPagePermsClause(1);
202 $pageinfo = t3lib_BEfunc::readPageAccess($this->id,$perms_clause);
203 $this->access = is_array($pageinfo) ? 1 : 0;
204 }
205
206 /**
207 * Creating the module output.
208 *
209 * @return void
210 */
211 function main() {
212 global $LANG,$BACK_PATH;
213
214 if ($this->id && $this->access) {
215
216 // Init position map object:
217 $posMap = t3lib_div::makeInstance('ext_posMap');
218 $posMap->cur_sys_language = $this->sys_language;
219 $posMap->backPath = $BACK_PATH;
220
221 if ((string)$this->colPos!='') { // If a column is pre-set:
222 if ($this->uid_pid<0) {
223 $row=array();
224 $row['uid']=abs($this->uid_pid);
225 } else {
226 $row='';
227 }
228 $onClickEvent = $posMap->onClickInsertRecord($row,$this->colPos,'',$this->uid_pid,$this->sys_language);
229 } else {
230 $onClickEvent='';
231 }
232
233 $this->doc->JScode=$this->doc->wrapScriptTags('
234 function goToalt_doc() { //
235 '.$onClickEvent.'
236 }
237 ');
238
239
240 // ***************************
241 // Creating content
242 // ***************************
243 $this->content='';
244 $this->content.=$this->doc->startPage($LANG->getLL('newContentElement'));
245 $this->content.=$this->doc->header($LANG->getLL('newContentElement'));
246 $this->content.=$this->doc->spacer(5);
247
248 $elRow = t3lib_BEfunc::getRecord('pages',$this->id);
249 $hline = t3lib_iconWorks::getIconImage('pages',$elRow,$BACK_PATH,' title="'.htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($elRow,'pages')).'" align="top"');
250 $hline.= t3lib_BEfunc::getRecordTitle('pages',$elRow,1);
251 $this->content.=$this->doc->section('',$hline,0,1);
252 $this->content.=$this->doc->spacer(10);
253
254
255 // Wizard
256 $code='';
257 $lines=array();
258 $wizardItems = $this->getWizardItems();
259
260 // Traverse items for the wizard.
261 // An item is either a header or an item rendered with a radio button and title/description and icon:
262 $cc=0;
263 foreach($wizardItems as $k => $wInfo) {
264 if ($wInfo['header']) {
265 if ($cc>0) $lines[]='
266 <tr>
267 <td colspan="3"><br /></td>
268 </tr>';
269 $lines[]='
270 <tr class="bgColor5">
271 <td colspan="3"><strong>'.htmlspecialchars($wInfo['header']).'</strong></td>
272 </tr>';
273 } else {
274 $tL=array();
275
276 // Radio button:
277 $oC = "document.editForm.defValues.value=unescape('".rawurlencode($wInfo['params'])."');goToalt_doc();".(!$onClickEvent?"document.location='#sel2';":'');
278 $tL[]='<input type="radio" name="tempB" value="'.htmlspecialchars($k).'" onclick="'.htmlspecialchars($this->doc->thisBlur().$oC).'" />';
279
280 // Onclick action for icon/title:
281 $aOnClick = 'document.editForm.tempB['.$cc.'].checked=1;'.$this->doc->thisBlur().$oC.'return false;';
282
283 // Icon:
284 $iInfo = @getimagesize($wInfo['icon']);
285 $tL[]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,$wInfo['icon'],'').' alt="" /></a>';
286
287 // Title + description:
288 $tL[]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><strong>'.htmlspecialchars($wInfo['title']).'</strong><br />'.nl2br(htmlspecialchars(trim($wInfo['description']))).'</a>';
289
290 // Finally, put it together in a table row:
291 $lines[]='
292 <tr>
293 <td valign="top">'.implode('</td>
294 <td valign="top">',$tL).'</td>
295 </tr>';
296 $cc++;
297 }
298 }
299 // Add the wizard table to the content:
300 $code.=$LANG->getLL('sel1',1).'<br /><br />
301
302
303 <!--
304 Content Element wizard table:
305 -->
306 <table border="0" cellpadding="1" cellspacing="2" id="typo3-ceWizardTable">
307 '.implode('',$lines).'
308 </table>';
309 $this->content.=$this->doc->section(!$onClickEvent?$LANG->getLL('1_selectType'):'',$code,0,1);
310
311
312
313 // If the user must also select a column:
314 if (!$onClickEvent) {
315
316 // Add anchor "sel2"
317 $this->content.=$this->doc->section('','<a name="sel2"></a>');
318 $this->content.=$this->doc->spacer(20);
319
320 // Select position
321 $code=$LANG->getLL('sel2',1).'<br /><br />';
322
323 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable:
324 $modTSconfig_SHARED = t3lib_BEfunc::getModTSconfig($this->id,'mod.SHARED');
325 $colPosList = strcmp(trim($modTSconfig_SHARED['properties']['colPos_list']),'') ? trim($modTSconfig_SHARED['properties']['colPos_list']) : '1,0,2,3';
326 $colPosList = implode(',',array_unique(t3lib_div::intExplode(',',$colPosList))); // Removing duplicates, if any
327
328 // Finally, add the content of the column selector to the content:
329 $code.=$posMap->printContentElementColumns($this->id,0,$colPosList,1,$this->R_URI);
330 $this->content.=$this->doc->section($LANG->getLL('2_selectPosition'),$code,0,1);
331 }
332
333 // IF there is a return-url set, then print a go-back link:
334 if ($this->R_URI) {
335 $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>';
336 $this->content.=$this->doc->section('',$code,0,1);
337 }
338
339 // Add a very high clear-gif, 700 px (so that the link to the anchor "sel2" shows this part in top for sure...)
340 $this->content.=$this->doc->section('','<img src="clear.gif" width="1" height="700" alt="" />',0,1);
341
342 } else { // In case of no access:
343 $this->content='';
344 $this->content.=$this->doc->startPage($LANG->getLL('newContentElement'));
345 $this->content.=$this->doc->header($LANG->getLL('newContentElement'));
346 $this->content.=$this->doc->spacer(5);
347 }
348 }
349
350 /**
351 * Print out the accumulated content:
352 *
353 * @return void
354 */
355 function printContent() {
356 global $SOBE;
357
358 $this->content.= $this->doc->endPage();
359 echo $this->content;
360 }
361
362
363
364
365
366
367
368
369
370
371
372 /***************************
373 *
374 * OTHER FUNCTIONS:
375 *
376 ***************************/
377
378
379 /**
380 * Returns the content of wizardArray() function...
381 *
382 * @return array Returns the content of wizardArray() function...
383 */
384 function getWizardItems() {
385 return $this->wizardArray();
386 }
387
388 /**
389 * Returns the array of elements in the wizard display.
390 * For the plugin section there is support for adding elements there from a global variable.
391 *
392 * @return array
393 */
394 function wizardArray() {
395 global $LANG,$TBE_MODULES_EXT;
396
397 $wizardItems = array(
398 'common' => array('header'=>$LANG->getLL('common')),
399 'common_1' => array(
400 'icon'=>'gfx/c_wiz/regular_text.gif',
401 'title'=>$LANG->getLL('common_1_title'),
402 'description'=>$LANG->getLL('common_1_description'),
403 'params'=>'&defVals[tt_content][CType]=text'
404 ),
405 'common_2' => array(
406 'icon'=>'gfx/c_wiz/text_image_below.gif',
407 'title'=>$LANG->getLL('common_2_title'),
408 'description'=>$LANG->getLL('common_2_description'),
409 'params'=>'&defVals[tt_content][CType]=textpic&defVals[tt_content][imageorient]=8'
410 ),
411 'common_3' => array(
412 'icon'=>'gfx/c_wiz/text_image_right.gif',
413 'title'=>$LANG->getLL('common_3_title'),
414 'description'=>$LANG->getLL('common_3_description'),
415 'params'=>'&defVals[tt_content][CType]=textpic&defVals[tt_content][imageorient]=17'
416 ),
417 'common_4' => array(
418 'icon'=>'gfx/c_wiz/images_only.gif',
419 'title'=>$LANG->getLL('common_4_title'),
420 'description'=>$LANG->getLL('common_4_description'),
421 'params'=>'&defVals[tt_content][CType]=image&defVals[tt_content][imagecols]=2'
422 ),
423 'common_5' => array(
424 'icon'=>'gfx/c_wiz/bullet_list.gif',
425 'title'=>$LANG->getLL('common_5_title'),
426 'description'=>$LANG->getLL('common_5_description'),
427 'params'=>'&defVals[tt_content][CType]=bullets'
428 ),
429 'common_6' => array(
430 'icon'=>'gfx/c_wiz/table.gif',
431 'title'=>$LANG->getLL('common_6_title'),
432 'description'=>$LANG->getLL('common_6_description'),
433 'params'=>'&defVals[tt_content][CType]=table'
434 ),
435 'special' => array('header'=>$LANG->getLL('special')),
436 'special_1' => array(
437 'icon'=>'gfx/c_wiz/filelinks.gif',
438 'title'=>$LANG->getLL('special_1_title'),
439 'description'=>$LANG->getLL('special_1_description'),
440 'params'=>'&defVals[tt_content][CType]=uploads'
441 ),
442 'special_2' => array(
443 'icon'=>'gfx/c_wiz/multimedia.gif',
444 'title'=>$LANG->getLL('special_2_title'),
445 'description'=>$LANG->getLL('special_2_description'),
446 'params'=>'&defVals[tt_content][CType]=multimedia'
447 ),
448 'special_3' => array(
449 'icon'=>'gfx/c_wiz/sitemap2.gif',
450 'title'=>$LANG->getLL('special_3_title'),
451 'description'=>$LANG->getLL('special_3_description'),
452 'params'=>'&defVals[tt_content][CType]=menu&defVals[tt_content][menu_type]=2'
453 ),
454 'special_4' => array(
455 'icon'=>'gfx/c_wiz/html.gif',
456 'title'=>$LANG->getLL('special_4_title'),
457 'description'=>$LANG->getLL('special_4_description'),
458 'params'=>'&defVals[tt_content][CType]=html'
459 ),
460
461
462 'forms' => array('header'=>$LANG->getLL('forms')),
463 'forms_1' => array(
464 'icon'=>'gfx/c_wiz/mailform.gif',
465 'title'=>$LANG->getLL('forms_1_title'),
466 'description'=>$LANG->getLL('forms_1_description'),
467 'params'=>'&defVals[tt_content][CType]=mailform&defVals[tt_content][bodytext]='.rawurlencode(trim('
468 # Example content:
469 Name: | *name = input,40 | Enter your name here
470 Email: | *email=input,40 |
471 Address: | address=textarea,40,5 |
472 Contact me: | tv=check | 1
473
474 |formtype_mail = submit | Send form!
475 |html_enabled=hidden | 1
476 |subject=hidden| This is the subject
477 '))
478 ),
479 'forms_2' => array(
480 'icon'=>'gfx/c_wiz/searchform.gif',
481 'title'=>$LANG->getLL('forms_2_title'),
482 'description'=>$LANG->getLL('forms_2_description'),
483 'params'=>'&defVals[tt_content][CType]=search'
484 ),
485 'forms_3' => array(
486 'icon'=>'gfx/c_wiz/login_form.gif',
487 'title'=>$LANG->getLL('forms_3_title'),
488 'description'=>$LANG->getLL('forms_3_description'),
489 'params'=>'&defVals[tt_content][CType]=login'
490 ),
491 'plugins' => array('header'=>$LANG->getLL('plugins')),
492 );
493
494
495 // PLUG-INS:
496 if (is_array($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) {
497 reset($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']);
498 while(list($class,$path)=each($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) {
499 $modObj = t3lib_div::makeInstance($class);
500 $wizardItems = $modObj->proc($wizardItems);
501 }
502 }
503
504 return $wizardItems;
505 }
506 }
507
508 // Include extension?
509 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php']) {
510 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php']);
511 }
512
513
514
515
516
517
518
519
520
521
522
523
524 // Make instance:
525 $SOBE = t3lib_div::makeInstance('SC_db_new_content_el');
526 $SOBE->init();
527
528 // Include files?
529 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
530
531 $SOBE->main();
532 $SOBE->printContent();
533 ?>