Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00063 unset($MCONF); 00064 require('conf.php'); 00065 require($BACK_PATH.'init.php'); 00066 require($BACK_PATH.'template.php'); 00067 00068 // Unset MCONF/MLANG since all we wanted was back path etc. for this particular script. 00069 unset($MCONF); 00070 unset($MLANG); 00071 00072 // Merging locallang files/arrays: 00073 $LANG->includeLLFile('EXT:lang/locallang_misc.xml'); 00074 $LOCAL_LANG_orig = $LOCAL_LANG; 00075 $LANG->includeLLFile('EXT:cms/layout/locallang_db_new_content_el.xml'); 00076 $LOCAL_LANG = t3lib_div::array_merge_recursive_overrule($LOCAL_LANG_orig,$LOCAL_LANG); 00077 00078 // Exits if 'cms' extension is not loaded: 00079 t3lib_extMgm::isLoaded('cms',1); 00080 00081 // Include needed libraries: 00082 require_once(PATH_t3lib.'class.t3lib_page.php'); 00083 require_once(PATH_t3lib.'class.t3lib_positionmap.php'); 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00101 class ext_posMap extends t3lib_positionMap { 00102 var $dontPrintPageInsertIcons = 1; 00103 00111 function wrapRecordTitle($str,$row) { 00112 return $str; 00113 } 00114 00125 function onClickInsertRecord($row,$vv,$moveUid,$pid,$sys_lang=0) { 00126 $table='tt_content'; 00127 00128 $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); 00129 00130 return 'document.location=\''.$location.'\'+document.editForm.defValues.value; return false;'; 00131 } 00132 } 00133 00134 00135 00136 00137 00138 00139 00140 00141 00142 00143 00144 00145 00153 class SC_db_new_content_el { 00154 00155 // Internal, static (from GPvars): 00156 var $id; // Page id 00157 var $sys_language=0; // Sys language 00158 var $R_URI=''; // Return URL. 00159 var $colPos; // If set, the content is destined for a specific column. 00160 var $uid_pid; // 00161 00162 // Internal, static: 00163 var $modTSconfig=array(); // Module TSconfig. 00164 var $doc; // Internal backend template object 00165 00166 // Internal, dynamic: 00167 var $include_once = array(); // Includes a list of files to include between init() and main() - see init() 00168 var $content; // Used to accumulate the content of the module. 00169 var $access; // Access boolean. 00170 00176 function init() { 00177 global $BE_USER,$BACK_PATH,$TBE_MODULES_EXT; 00178 00179 // Setting class files to include: 00180 if (is_array($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) { 00181 $this->include_once = array_merge($this->include_once,$TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']); 00182 } 00183 00184 // Setting internal vars: 00185 $this->id = intval(t3lib_div::_GP('id')); 00186 $this->sys_language = intval(t3lib_div::_GP('sys_language_uid')); 00187 $this->R_URI = t3lib_div::_GP('returnUrl'); 00188 $this->colPos = t3lib_div::_GP('colPos'); 00189 $this->uid_pid = intval(t3lib_div::_GP('uid_pid')); 00190 00191 $this->MCONF['name'] = 'xMOD_db_new_content_el'; 00192 $this->modTSconfig = t3lib_BEfunc::getModTSconfig($this->id,'mod.'.$this->MCONF['name']); 00193 00194 // Starting the document template object: 00195 $this->doc = t3lib_div::makeInstance('mediumDoc'); 00196 $this->doc->docType= 'xhtml_trans'; 00197 $this->doc->backPath = $BACK_PATH; 00198 $this->doc->JScode=''; 00199 $this->doc->form='<form action="" name="editForm"><input type="hidden" name="defValues" value="" />'; 00200 00201 // Getting the current page and receiving access information (used in main()) 00202 $perms_clause = $BE_USER->getPagePermsClause(1); 00203 $pageinfo = t3lib_BEfunc::readPageAccess($this->id,$perms_clause); 00204 $this->access = is_array($pageinfo) ? 1 : 0; 00205 } 00206 00212 function main() { 00213 global $LANG,$BACK_PATH; 00214 00215 if ($this->id && $this->access) { 00216 00217 // Init position map object: 00218 $posMap = t3lib_div::makeInstance('ext_posMap'); 00219 $posMap->cur_sys_language = $this->sys_language; 00220 $posMap->backPath = $BACK_PATH; 00221 00222 if ((string)$this->colPos!='') { // If a column is pre-set: 00223 if ($this->uid_pid<0) { 00224 $row=array(); 00225 $row['uid']=abs($this->uid_pid); 00226 } else { 00227 $row=''; 00228 } 00229 $onClickEvent = $posMap->onClickInsertRecord($row,$this->colPos,'',$this->uid_pid,$this->sys_language); 00230 } else { 00231 $onClickEvent=''; 00232 } 00233 00234 $this->doc->JScode=$this->doc->wrapScriptTags(' 00235 function goToalt_doc() { // 00236 '.$onClickEvent.' 00237 } 00238 '); 00239 00240 00241 // *************************** 00242 // Creating content 00243 // *************************** 00244 $this->content=''; 00245 $this->content.=$this->doc->startPage($LANG->getLL('newContentElement')); 00246 $this->content.=$this->doc->header($LANG->getLL('newContentElement')); 00247 $this->content.=$this->doc->spacer(5); 00248 00249 $elRow = t3lib_BEfunc::getRecord('pages',$this->id); 00250 $hline = t3lib_iconWorks::getIconImage('pages',$elRow,$BACK_PATH,' title="'.htmlspecialchars(t3lib_BEfunc::getRecordIconAltText($elRow,'pages')).'" align="top"'); 00251 $hline.= t3lib_BEfunc::getRecordTitle('pages',$elRow,1); 00252 $this->content.=$this->doc->section('',$hline,0,1); 00253 $this->content.=$this->doc->spacer(10); 00254 00255 00256 // Wizard 00257 $code=''; 00258 $lines=array(); 00259 $wizardItems = $this->getWizardItems(); 00260 00261 // Traverse items for the wizard. 00262 // An item is either a header or an item rendered with a radio button and title/description and icon: 00263 $cc=0; 00264 foreach($wizardItems as $k => $wInfo) { 00265 if ($wInfo['header']) { 00266 if ($cc>0) $lines[]=' 00267 <tr> 00268 <td colspan="3"><br /></td> 00269 </tr>'; 00270 $lines[]=' 00271 <tr class="bgColor5"> 00272 <td colspan="3"><strong>'.htmlspecialchars($wInfo['header']).'</strong></td> 00273 </tr>'; 00274 } else { 00275 $tL=array(); 00276 00277 // Radio button: 00278 $oC = "document.editForm.defValues.value=unescape('".rawurlencode($wInfo['params'])."');goToalt_doc();".(!$onClickEvent?"document.location='#sel2';":''); 00279 $tL[]='<input type="radio" name="tempB" value="'.htmlspecialchars($k).'" onclick="'.htmlspecialchars($this->doc->thisBlur().$oC).'" />'; 00280 00281 // Onclick action for icon/title: 00282 $aOnClick = 'document.editForm.tempB['.$cc.'].checked=1;'.$this->doc->thisBlur().$oC.'return false;'; 00283 00284 // Icon: 00285 $iInfo = @getimagesize($wInfo['icon']); 00286 $tL[]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><img'.t3lib_iconWorks::skinImg($this->doc->backPath,$wInfo['icon'],'').' alt="" /></a>'; 00287 00288 // Title + description: 00289 $tL[]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'"><strong>'.htmlspecialchars($wInfo['title']).'</strong><br />'.nl2br(htmlspecialchars(trim($wInfo['description']))).'</a>'; 00290 00291 // Finally, put it together in a table row: 00292 $lines[]=' 00293 <tr> 00294 <td valign="top">'.implode('</td> 00295 <td valign="top">',$tL).'</td> 00296 </tr>'; 00297 $cc++; 00298 } 00299 } 00300 // Add the wizard table to the content: 00301 $code.=$LANG->getLL('sel1',1).'<br /><br /> 00302 00303 00304 <!-- 00305 Content Element wizard table: 00306 --> 00307 <table border="0" cellpadding="1" cellspacing="2" id="typo3-ceWizardTable"> 00308 '.implode('',$lines).' 00309 </table>'; 00310 $this->content.=$this->doc->section(!$onClickEvent?$LANG->getLL('1_selectType'):'',$code,0,1); 00311 00312 00313 00314 // If the user must also select a column: 00315 if (!$onClickEvent) { 00316 00317 // Add anchor "sel2" 00318 $this->content.=$this->doc->section('','<a name="sel2"></a>'); 00319 $this->content.=$this->doc->spacer(20); 00320 00321 // Select position 00322 $code=$LANG->getLL('sel2',1).'<br /><br />'; 00323 00324 // Load SHARED page-TSconfig settings and retrieve column list from there, if applicable: 00325 $modTSconfig_SHARED = t3lib_BEfunc::getModTSconfig($this->id,'mod.SHARED'); 00326 $colPosList = strcmp(trim($modTSconfig_SHARED['properties']['colPos_list']),'') ? trim($modTSconfig_SHARED['properties']['colPos_list']) : '1,0,2,3'; 00327 $colPosList = implode(',',array_unique(t3lib_div::intExplode(',',$colPosList))); // Removing duplicates, if any 00328 00329 // Finally, add the content of the column selector to the content: 00330 $code.=$posMap->printContentElementColumns($this->id,0,$colPosList,1,$this->R_URI); 00331 $this->content.=$this->doc->section($LANG->getLL('2_selectPosition'),$code,0,1); 00332 } 00333 00334 // IF there is a return-url set, then print a go-back link: 00335 if ($this->R_URI) { 00336 $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>'; 00337 $this->content.=$this->doc->section('',$code,0,1); 00338 } 00339 00340 // Add CSH: 00341 $this->content.= $this->doc->section('',t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'new_ce', $GLOBALS['BACK_PATH'],'<br/>'),0,1); 00342 00343 // Add a very high clear-gif, 700 px (so that the link to the anchor "sel2" shows this part in top for sure...) 00344 $this->content.=$this->doc->section('','<img src="clear.gif" width="1" height="700" alt="" />',0,1); 00345 00346 } else { // In case of no access: 00347 $this->content=''; 00348 $this->content.=$this->doc->startPage($LANG->getLL('newContentElement')); 00349 $this->content.=$this->doc->header($LANG->getLL('newContentElement')); 00350 $this->content.=$this->doc->spacer(5); 00351 } 00352 } 00353 00359 function printContent() { 00360 global $SOBE; 00361 00362 $this->content.= $this->doc->endPage(); 00363 echo $this->content; 00364 } 00365 00366 00367 00368 00369 00370 00371 00372 00373 00374 00375 00376 /*************************** 00377 * 00378 * OTHER FUNCTIONS: 00379 * 00380 ***************************/ 00381 00382 00388 function getWizardItems() { 00389 return $this->wizardArray(); 00390 } 00391 00398 function wizardArray() { 00399 global $LANG,$TBE_MODULES_EXT; 00400 00401 $wizardItems = array( 00402 'common' => array('header'=>$LANG->getLL('common')), 00403 'common_1' => array( 00404 'icon'=>'gfx/c_wiz/regular_text.gif', 00405 'title'=>$LANG->getLL('common_1_title'), 00406 'description'=>$LANG->getLL('common_1_description'), 00407 'tt_content_defValues' => array( 00408 'CType' => 'text' 00409 ) 00410 ), 00411 'common_2' => array( 00412 'icon'=>'gfx/c_wiz/text_image_below.gif', 00413 'title'=>$LANG->getLL('common_2_title'), 00414 'description'=>$LANG->getLL('common_2_description'), 00415 'tt_content_defValues' => array( 00416 'CType' => 'textpic', 00417 'imageorient' => 8 00418 ) 00419 ), 00420 'common_3' => array( 00421 'icon'=>'gfx/c_wiz/text_image_right.gif', 00422 'title'=>$LANG->getLL('common_3_title'), 00423 'description'=>$LANG->getLL('common_3_description'), 00424 'tt_content_defValues' => array( 00425 'CType' => 'textpic', 00426 'imageorient' => 17 00427 ) 00428 ), 00429 'common_4' => array( 00430 'icon'=>'gfx/c_wiz/images_only.gif', 00431 'title'=>$LANG->getLL('common_4_title'), 00432 'description'=>$LANG->getLL('common_4_description'), 00433 'tt_content_defValues' => array( 00434 'CType' => 'image', 00435 'imagecols' => 2 00436 ) 00437 ), 00438 'common_5' => array( 00439 'icon'=>'gfx/c_wiz/bullet_list.gif', 00440 'title'=>$LANG->getLL('common_5_title'), 00441 'description'=>$LANG->getLL('common_5_description'), 00442 'tt_content_defValues' => array( 00443 'CType' => 'bullets', 00444 ) 00445 ), 00446 'common_6' => array( 00447 'icon'=>'gfx/c_wiz/table.gif', 00448 'title'=>$LANG->getLL('common_6_title'), 00449 'description'=>$LANG->getLL('common_6_description'), 00450 'tt_content_defValues' => array( 00451 'CType' => 'table', 00452 ) 00453 ), 00454 'special' => array('header'=>$LANG->getLL('special')), 00455 'special_1' => array( 00456 'icon'=>'gfx/c_wiz/filelinks.gif', 00457 'title'=>$LANG->getLL('special_1_title'), 00458 'description'=>$LANG->getLL('special_1_description'), 00459 'tt_content_defValues' => array( 00460 'CType' => 'uploads', 00461 ) 00462 ), 00463 'special_2' => array( 00464 'icon'=>'gfx/c_wiz/multimedia.gif', 00465 'title'=>$LANG->getLL('special_2_title'), 00466 'description'=>$LANG->getLL('special_2_description'), 00467 'tt_content_defValues' => array( 00468 'CType' => 'multimedia', 00469 ) 00470 ), 00471 'special_3' => array( 00472 'icon'=>'gfx/c_wiz/sitemap2.gif', 00473 'title'=>$LANG->getLL('special_3_title'), 00474 'description'=>$LANG->getLL('special_3_description'), 00475 'tt_content_defValues' => array( 00476 'CType' => 'menu', 00477 'menu_type' => 2 00478 ) 00479 ), 00480 'special_4' => array( 00481 'icon'=>'gfx/c_wiz/html.gif', 00482 'title'=>$LANG->getLL('special_4_title'), 00483 'description'=>$LANG->getLL('special_4_description'), 00484 'tt_content_defValues' => array( 00485 'CType' => 'html', 00486 ) 00487 ), 00488 'forms' => array('header'=>$LANG->getLL('forms')), 00489 'forms_1' => array( 00490 'icon'=>'gfx/c_wiz/mailform.gif', 00491 'title'=>$LANG->getLL('forms_1_title'), 00492 'description'=>$LANG->getLL('forms_1_description'), 00493 'tt_content_defValues' => array( 00494 'CType' => 'mailform', 00495 'bodytext' => trim(' 00496 # Example content: 00497 Name: | *name = input,40 | Enter your name here 00498 Email: | *email=input,40 | 00499 Address: | address=textarea,40,5 | 00500 Contact me: | tv=check | 1 00501 00502 |formtype_mail = submit | Send form! 00503 |html_enabled=hidden | 1 00504 |subject=hidden| This is the subject 00505 ') 00506 ) 00507 ), 00508 'forms_2' => array( 00509 'icon'=>'gfx/c_wiz/searchform.gif', 00510 'title'=>$LANG->getLL('forms_2_title'), 00511 'description'=>$LANG->getLL('forms_2_description'), 00512 'tt_content_defValues' => array( 00513 'CType' => 'search', 00514 ) 00515 ), 00516 'forms_3' => array( 00517 'icon'=>'gfx/c_wiz/login_form.gif', 00518 'title'=>$LANG->getLL('forms_3_title'), 00519 'description'=>$LANG->getLL('forms_3_description'), 00520 'tt_content_defValues' => array( 00521 'CType' => 'login', 00522 ) 00523 ), 00524 'plugins' => array('header'=>$LANG->getLL('plugins')), 00525 'plugins_1' => array( 00526 'icon'=>'gfx/c_wiz/user_defined.gif', 00527 'title'=>$LANG->getLL('plugins_1_title'), 00528 'description'=>$LANG->getLL('plugins_1_description'), 00529 'tt_content_defValues' => array( 00530 'CType' => 'list', 00531 ) 00532 ), 00533 ); 00534 00535 00536 // PLUG-INS: 00537 if (is_array($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) { 00538 reset($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']); 00539 while(list($class,$path)=each($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses'])) { 00540 $modObj = t3lib_div::makeInstance($class); 00541 $wizardItems = $modObj->proc($wizardItems); 00542 } 00543 } 00544 00545 // Remove elements where preset values are not allowed: 00546 $this->removeInvalidElements($wizardItems); 00547 00548 return $wizardItems; 00549 } 00550 00558 function removeInvalidElements(&$wizardItems) { 00559 global $TCA; 00560 00561 // Load full table definition: 00562 t3lib_div::loadTCA('tt_content'); 00563 00564 // Traverse wizard items: 00565 foreach($wizardItems as $key => $cfg) { 00566 00567 // Exploding parameter string, if any (old style) 00568 if ($wizardItems[$key]['params']) { 00569 // Explode GET vars recursively 00570 $tempGetVars = t3lib_div::explodeUrl2Array($wizardItems[$key]['params'],TRUE); 00571 // 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). 00572 if (is_array($tempGetVars['defVals']['tt_content'])) { 00573 $wizardItems[$key]['tt_content_defValues'] = array_merge(is_array($wizardItems[$key]['tt_content_defValues']) ? $wizardItems[$key]['tt_content_defValues'] : array(), $tempGetVars['defVals']['tt_content']); 00574 unset($tempGetVars['defVals']['tt_content']); 00575 $wizardItems[$key]['params'] = t3lib_div::implodeArrayForUrl('',$tempGetVars); 00576 } 00577 } 00578 00579 // If tt_content_defValues are defined...: 00580 if (is_array($wizardItems[$key]['tt_content_defValues'])) { 00581 00582 // Traverse field values: 00583 foreach($wizardItems[$key]['tt_content_defValues'] as $fN => $fV) { 00584 if (is_array($TCA['tt_content']['columns'][$fN])) { 00585 // Get information about if the field value is OK: 00586 $config = &$TCA['tt_content']['columns'][$fN]['config']; 00587 $authModeDeny = $config['type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode('tt_content',$fN,$fV,$config['authMode']); 00588 00589 if ($authModeDeny) { 00590 // Remove element all together: 00591 unset($wizardItems[$key]); 00592 break; 00593 } else { 00594 // Add the parameter: 00595 $wizardItems[$key]['params'].= '&defVals[tt_content]['.$fN.']='.rawurlencode($fV); 00596 } 00597 } 00598 } 00599 } 00600 } 00601 } 00602 } 00603 00604 // Include extension? 00605 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php']) { 00606 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php']); 00607 } 00608 00609 00610 00611 00612 00613 00614 00615 00616 00617 00618 00619 00620 // Make instance: 00621 $SOBE = t3lib_div::makeInstance('SC_db_new_content_el'); 00622 $SOBE->init(); 00623 00624 // Include files? 00625 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE); 00626 00627 $SOBE->main(); 00628 $SOBE->printContent(); 00629 ?>