Documentation TYPO3 par Ameos

db_new_content_el.php

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 'window.location.href=\''.$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::getRecordWSOL('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,TRUE);
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?"window.location.hash='#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_regularText' => array(  // Regular text element
00404                                 'icon'=>'gfx/c_wiz/regular_text.gif',
00405                                 'title'=>$LANG->getLL('common_regularText_title'),
00406                                 'description'=>$LANG->getLL('common_regularText_description'),
00407                                 'tt_content_defValues' => array(
00408                                         'CType' => 'text'
00409                                 )
00410                         ),
00411                         'common_textImage' => array(    // Text with image
00412                                 'icon'=>'gfx/c_wiz/text_image_right.gif',
00413                                 'title'=>$LANG->getLL('common_textImage_title'),
00414                                 'description'=>$LANG->getLL('common_textImage_description'),
00415                                 'tt_content_defValues' => array(
00416                                         'CType' => 'textpic',
00417                                         'imageorient' => 17
00418                                 )
00419                         ),
00420                         'common_imagesOnly' => array(   // Images only
00421                                 'icon'=>'gfx/c_wiz/images_only.gif',
00422                                 'title'=>$LANG->getLL('common_imagesOnly_title'),
00423                                 'description'=>$LANG->getLL('common_imagesOnly_description'),
00424                                 'tt_content_defValues' => array(
00425                                         'CType' => 'image',
00426                                         'imagecols' => 2
00427                                 )
00428                         ),
00429                         'common_bulletList' => array(   // Bullet list
00430                                 'icon'=>'gfx/c_wiz/bullet_list.gif',
00431                                 'title'=>$LANG->getLL('common_bulletList_title'),
00432                                 'description'=>$LANG->getLL('common_bulletList_description'),
00433                                 'tt_content_defValues' => array(
00434                                         'CType' => 'bullets',
00435                                 )
00436                         ),
00437                         'common_table' => array(        // Table
00438                                 'icon'=>'gfx/c_wiz/table.gif',
00439                                 'title'=>$LANG->getLL('common_table_title'),
00440                                 'description'=>$LANG->getLL('common_table_description'),
00441                                 'tt_content_defValues' => array(
00442                                         'CType' => 'table',
00443                                 )
00444                         ),
00445                         'special' => array('header'=>$LANG->getLL('special')),
00446                         'special_filelinks' => array(   // Filelinks
00447                                 'icon'=>'gfx/c_wiz/filelinks.gif',
00448                                 'title'=>$LANG->getLL('special_filelinks_title'),
00449                                 'description'=>$LANG->getLL('special_filelinks_description'),
00450                                 'tt_content_defValues' => array(
00451                                         'CType' => 'uploads',
00452                                 )
00453                         ),
00454                         'special_multimedia' => array(  // Multimedia
00455                                 'icon'=>'gfx/c_wiz/multimedia.gif',
00456                                 'title'=>$LANG->getLL('special_multimedia_title'),
00457                                 'description'=>$LANG->getLL('special_multimedia_description'),
00458                                 'tt_content_defValues' => array(
00459                                         'CType' => 'multimedia',
00460                                 )
00461                         ),
00462                         'special_sitemap' => array(     // Sitemap
00463                                 'icon'=>'gfx/c_wiz/sitemap2.gif',
00464                                 'title'=>$LANG->getLL('special_sitemap_title'),
00465                                 'description'=>$LANG->getLL('special_sitemap_description'),
00466                                 'tt_content_defValues' => array(
00467                                         'CType' => 'menu',
00468                                         'menu_type' => 2
00469                                 )
00470                         ),
00471                         'special_plainHTML' => array(   // Plain HTML
00472                                 'icon'=>'gfx/c_wiz/html.gif',
00473                                 'title'=>$LANG->getLL('special_plainHTML_title'),
00474                                 'description'=>$LANG->getLL('special_plainHTML_description'),
00475                                 'tt_content_defValues' => array(
00476                                         'CType' => 'html',
00477                                 )
00478                         ),
00479                         'forms' => array('header'=>$LANG->getLL('forms')),
00480                         'forms_mail' => array(  // Mail form
00481                                 'icon'=>'gfx/c_wiz/mailform.gif',
00482                                 'title'=>$LANG->getLL('forms_mail_title'),
00483                                 'description'=>$LANG->getLL('forms_mail_description'),
00484                                 'tt_content_defValues' => array(
00485                                         'CType' => 'mailform',
00486                                         'bodytext' => trim('
00487 # Example content:
00488 Name: | *name = input,40 | Enter your name here
00489 Email: | *email=input,40 |
00490 Address: | address=textarea,40,5 |
00491 Contact me: | tv=check | 1
00492 
00493 |formtype_mail = submit | Send form!
00494 |html_enabled=hidden | 1
00495 |subject=hidden| This is the subject
00496                                         ')
00497                                 )
00498                         ),
00499                         'forms_search' => array(        // Search form
00500                                 'icon'=>'gfx/c_wiz/searchform.gif',
00501                                 'title'=>$LANG->getLL('forms_search_title'),
00502                                 'description'=>$LANG->getLL('forms_search_description'),
00503                                 'tt_content_defValues' => array(
00504                                         'CType' => 'search',
00505                                 )
00506                         ),
00507                         'forms_login' => array( // Login form
00508                                 'icon'=>'gfx/c_wiz/login_form.gif',
00509                                 'title'=>$LANG->getLL('forms_login_title'),
00510                                 'description'=>$LANG->getLL('forms_login_description'),
00511                                 'tt_content_defValues' => array(
00512                                         'CType' => 'login',
00513                                 )
00514                         ),
00515                         'plugins' => array('header'=>$LANG->getLL('plugins')),
00516                         'plugins_general' => array(     // General plugin
00517                                 'icon'=>'gfx/c_wiz/user_defined.gif',
00518                                 'title'=>$LANG->getLL('plugins_general_title'),
00519                                 'description'=>$LANG->getLL('plugins_general_description'),
00520                                 'tt_content_defValues' => array(
00521                                         'CType' => 'list',
00522                                 )
00523                         ),
00524                 );
00525 
00526 
00527                         // PLUG-INS:
00528                 if (is_array($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']))       {
00529                         reset($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']);
00530                         while(list($class,$path)=each($TBE_MODULES_EXT['xMOD_db_new_content_el']['addElClasses']))      {
00531                                 $modObj = t3lib_div::makeInstance($class);
00532                                 $wizardItems = $modObj->proc($wizardItems);
00533                         }
00534                 }
00535 
00536                         // Remove elements where preset values are not allowed:
00537                 $this->removeInvalidElements($wizardItems);
00538 
00539                 return $wizardItems;
00540         }
00541 
00549         function removeInvalidElements(&$wizardItems)   {
00550                 global $TCA;
00551 
00552                         // Load full table definition:
00553                 t3lib_div::loadTCA('tt_content');
00554 
00555                         // Get TCEFORM from TSconfig of current page
00556                 $row = array('pid'=>$this->id);
00557                 $TCEFORM_TSconfig = t3lib_BEfunc::getTCEFORM_TSconfig('tt_content',$row);
00558                 $removeItems = t3lib_div::trimExplode(',',$TCEFORM_TSconfig['CType']['removeItems'],1);
00559 
00560                 $headersUsed = Array();
00561                         // Traverse wizard items:
00562                 foreach($wizardItems as $key => $cfg)   {
00563 
00564                                 // Exploding parameter string, if any (old style)
00565                         if ($wizardItems[$key]['params'])       {
00566                                         // Explode GET vars recursively
00567                                 $tempGetVars = t3lib_div::explodeUrl2Array($wizardItems[$key]['params'],TRUE);
00568                                         // 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).
00569                                 if (is_array($tempGetVars['defVals']['tt_content']))    {
00570                                         $wizardItems[$key]['tt_content_defValues'] = array_merge(is_array($wizardItems[$key]['tt_content_defValues']) ? $wizardItems[$key]['tt_content_defValues'] : array(), $tempGetVars['defVals']['tt_content']);
00571                                         unset($tempGetVars['defVals']['tt_content']);
00572                                         $wizardItems[$key]['params'] = t3lib_div::implodeArrayForUrl('',$tempGetVars);
00573                                 }
00574                         }
00575 
00576                                 // If tt_content_defValues are defined...:
00577                         if (is_array($wizardItems[$key]['tt_content_defValues']))       {
00578 
00579                                         // Traverse field values:
00580                                 foreach($wizardItems[$key]['tt_content_defValues'] as $fN => $fV)       {
00581                                         if (is_array($TCA['tt_content']['columns'][$fN]))       {
00582                                                         // Get information about if the field value is OK:
00583                                                 $config = &$TCA['tt_content']['columns'][$fN]['config'];
00584                                                 $authModeDeny = $config['type']=='select' && $config['authMode'] && !$GLOBALS['BE_USER']->checkAuthMode('tt_content',$fN,$fV,$config['authMode']);
00585 
00586                                                 if ($authModeDeny || in_array($fV,$removeItems))        {
00587                                                                 // Remove element all together:
00588                                                         unset($wizardItems[$key]);
00589                                                         break;
00590                                                 } else {
00591                                                                 // Add the parameter:
00592                                                         $wizardItems[$key]['params'].= '&defVals[tt_content]['.$fN.']='.rawurlencode($fV);
00593                                                         $tmp = explode('_', $key);
00594                                                         $headersUsed[$tmp[0]] = $tmp[0];
00595                                                 }
00596                                         }
00597                                 }
00598                         }
00599                 }
00600                         // remove headers without elements
00601                 foreach ($wizardItems as $key => $cfg)  {
00602                         $tmp = explode('_',$key);
00603                         if ($tmp[0] && !$tmp[1] && !in_array($tmp[0], $headersUsed))    {
00604                                 unset($wizardItems[$key]);
00605                         }
00606                 }
00607         }
00608 }
00609 
00610 // Include extension?
00611 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php'])    {
00612         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/layout/db_new_content_el.php']);
00613 }
00614 
00615 
00616 
00617 
00618 
00619 
00620 
00621 
00622 
00623 
00624 
00625 
00626 // Make instance:
00627 $SOBE = t3lib_div::makeInstance('SC_db_new_content_el');
00628 $SOBE->init();
00629 
00630 // Include files?
00631 foreach($SOBE->include_once as $INC_FILE)       include_once($INC_FILE);
00632 
00633 $SOBE->main();
00634 $SOBE->printContent();
00635 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6