Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2004 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 ***************************************************************/ 00080 require_once(PATH_t3lib.'class.t3lib_tcemain.php'); 00081 00082 00083 00084 00085 00086 00087 00088 00089 00090 00098 class tx_impexp { 00099 var $maxFileSize = 1000000; // 1MB max file size 00100 var $maxRecordSize = 1000000; // 1MB max record size 00101 var $maxExportSize = 10000000; // 10MB max export size 00102 00103 var $dat = array(); 00104 var $display_import_pid_record=''; // If set to a page-record, then the preview display of the content will expect this page-record to be the target for the import and accordingly display validation information. 00105 00106 00107 00108 // Internal, dynamic: 00109 var $import_mapId = array(); 00110 var $import_newId = array(); 00111 var $import_newId_pids = array(); 00112 var $errorLog = array(); 00113 00114 var $relExclTables = array(); // add table names here which will not be included into export if found as relations. 00115 var $relOnlyTables = array(); // add table names here which are THE ONLY ones which will be included into export if found as relations. (activated if array is not empty) 00116 00117 var $compress=0; 00118 var $dontCompress=0; 00119 00120 00127 function init($dontCompress=0) { 00128 $this->compress = function_exists('gzcompress'); 00129 $this->dontCompress = $dontCompress; 00130 } 00131 00143 function setMetaData($title,$description,$notes,$packager_username,$packager_name,$packager_email) { 00144 $this->dat['header']['meta']=array( 00145 'title'=>$title, 00146 'description'=>$description, 00147 'notes'=>$notes, 00148 'packager_username'=>$packager_username, 00149 'packager_name'=>$packager_name, 00150 'packager_email'=>$packager_email 00151 ); 00152 } 00153 00160 function addThumbnail($imgFilepath) { 00161 if (@is_file($imgFilepath)) { 00162 $imgInfo = @getimagesize($imgFilepath); 00163 if (is_array($imgInfo)) { 00164 $fileContent = t3lib_div::getUrl($imgFilepath); 00165 $this->dat['header']['thumbnail']=array( 00166 'imgInfo' => $imgInfo, 00167 'content' => $fileContent, 00168 'filesize' => strlen($fileContent), 00169 'filemtime' => filemtime($imgFilepath), 00170 'filename' => basename($imgFilepath) 00171 ); 00172 } 00173 } 00174 } 00175 00182 function setPageTree($idH) { 00183 $this->dat['header']['pagetree']=$idH; 00184 return $this->flatInversePageTree($idH); 00185 } 00186 00194 function flatInversePageTree($idH,$a=array()) { 00195 if (is_array($idH)) { 00196 $idH = array_reverse($idH); 00197 reset($idH); 00198 while(list($k,$v)=each($idH)) { 00199 $a[$v['uid']]=$v['uid']; 00200 if (is_array($v['subrow'])) $a=$this->flatInversePageTree($v['subrow'],$a); 00201 } 00202 } 00203 return $a; 00204 } 00205 00215 function export_addRecord($table,$row,$relationLevel=0) { 00216 if (strcmp($table,'') && is_array($row) && $row['uid']>0) { 00217 if (!isset($this->dat['records'][$table.':'.$row['uid']])) { 00218 // header info: 00219 $headerInfo=array(); 00220 $headerInfo['uid']=$row['uid']; 00221 $headerInfo['pid']=$row['pid']; 00222 $headerInfo['title']=t3lib_div::fixed_lgd_cs(t3lib_BEfunc::getRecordTitle($table,$row),40); 00223 $headerInfo['size']=strlen(serialize($row)); 00224 if ($relationLevel) $headerInfo['relationLevel'] = $relationLevel; 00225 if ($headerInfo['size']<$this->maxRecordSize) { 00226 $this->dat['header']['records'][$table][$row['uid']]=$headerInfo; 00227 00228 // pid lookup: 00229 $this->dat['header']['pid_lookup'][$row['pid']][$table][$row['uid']]=1; 00230 00231 // data: 00232 $this->dat['records'][$table.':'.$row['uid']]=array(); 00233 $this->dat['records'][$table.':'.$row['uid']]['data']=$row; 00234 $this->dat['records'][$table.':'.$row['uid']]['rels']=$this->getRelations($table,$row); 00235 00236 $this->dat['header']['records'][$table][$row['uid']]['rels']=$this->flatDBrels($this->dat['records'][$table.':'.$row['uid']]['rels']); 00237 } else $this->error('Record '.$table.':'.$row['uid'].' was larger than maxRecordSize ('.t3lib_div::formatSize($this->maxRecordSize).')'); 00238 } else $this->error('Record '.$table.':'.$row['uid'].' already added.'); 00239 } 00240 } 00241 00250 function export_addDBRelations($relationLevel=0) { 00251 global $TCA; 00252 #echo "<HR>"; 00253 $addR=array(); 00254 if (is_array($this->dat['records'])) { 00255 reset($this->dat['records']); 00256 while(list($k)=each($this->dat['records'])) { 00257 if (is_array($this->dat['records'][$k])) { 00258 reset($this->dat['records'][$k]['rels']); 00259 while(list($fieldname,$vR)=each($this->dat['records'][$k]['rels'])) { 00260 if ($vR['type']=='db') { 00261 reset($vR['itemArray']); 00262 while(list(,$fI)=each($vR['itemArray'])) { 00263 $rId = $fI['table'].':'.$fI['id']; 00264 if (isset($TCA[$fI['table']]) && !$TCA[$fI['table']]['ctrl']['is_static'] 00265 && !in_array($fI['table'],$this->relExclTables) 00266 && (!count($this->relOnlyTables) || in_array($fI['table'],$this->relOnlyTables)) 00267 ) { 00268 if (isset($this->dat['records'][$rId])) { 00269 # debug($rId.": OK",1); 00270 } else { 00271 # debug($rId.": --",1); 00272 $addR[$rId]=$fI; 00273 } 00274 } 00275 } 00276 } 00277 } 00278 } 00279 } 00280 } else $this->error('There were no records available.'); 00281 00282 #debug($addR); 00283 if (count($addR)) { 00284 reset($addR); 00285 while(list(,$fI)=each($addR)) { 00286 $row = t3lib_BEfunc::getRecord($fI['table'],$fI['id']); 00287 if (is_array($row)) { 00288 $this->export_addRecord($fI['table'],$row,$relationLevel+1); 00289 } 00290 $rId = $fI['table'].':'.$fI['id']; 00291 if (!isset($this->dat['records'][$rId])) { 00292 $this->dat['records'][$rId]='NOT_FOUND'; 00293 $this->error('Relation record '.$rId.' was not found!'); 00294 } 00295 } 00296 } 00297 return $addR; 00298 } 00299 00306 function export_addFilesFromRelations() { 00307 if (is_array($this->dat['records'])) { 00308 reset($this->dat['records']); 00309 while(list($k)=each($this->dat['records'])) { 00310 if (is_array($this->dat['records'][$k]['rels'])) { 00311 reset($this->dat['records'][$k]['rels']); 00312 while(list($fieldname,$vR)=each($this->dat['records'][$k]['rels'])) { 00313 if ($vR['type']=='file') { 00314 reset($vR['newValueFiles']); 00315 while(list(,$fI)=each($vR['newValueFiles'])) { 00316 if (@is_file($fI['ID_absFile'])) { 00317 if (filesize($fI['ID_absFile'])<$this->maxFileSize) { 00318 $fileRec=array(); 00319 $fileRec['filesize']=filesize($fI['ID_absFile']); 00320 $fileRec['filename']=basename($fI['ID_absFile']); 00321 $fileRec['filemtime']=filemtime($fI['ID_absFile']); 00322 $fileRec['record_ref']=$k.'/'.$fieldname; 00323 00324 // Setting this data in the header 00325 $this->dat['header']['files'][$fI['ID']]=$fileRec; 00326 00327 // ... and for the recordlisting, why not let us know WHICH relations there was... 00328 $refParts=explode(':',$k,2); 00329 if (!is_array($this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'])) $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs']=array(); 00330 $this->dat['header']['records'][$refParts[0]][$refParts[1]]['filerefs'][]=$fI['ID']; 00331 00332 // ... and finally add the heavy stuff: 00333 $fileRec['content']=t3lib_div::getUrl($fI['ID_absFile']); 00334 $fileRec['content_md5']=md5($fileRec['content']); 00335 $this->dat['files'][$fI['ID']] = $fileRec; 00336 } else $this->error($fI['ID_absFile'].' was larger than the maxFileSize ('.t3lib_div::formatSize($this->maxFileSize).')! Skipping.'); 00337 } else $this->error($fI['ID_absFile'].' was not a file! Skipping.'); 00338 } 00339 } 00340 } 00341 } 00342 } 00343 } else $this->error('There were no records available.'); 00344 } 00345 00353 function getRelations($table,$row) { 00354 global $TCA; 00355 t3lib_div::loadTCA($table); 00356 $uid=$row['uid']; 00357 $nonFields = explode(',','uid,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,pid'); 00358 00359 $outRow=array(); 00360 reset($row); 00361 while (list($field,$value)=each($row)) { 00362 if (!in_array($field,$nonFields) && is_array($TCA[$table]['columns'][$field])) { 00363 $conf = $TCA[$table]['columns'][$field]['config']; 00364 00365 // Take care of files... 00366 if ($conf['type']=='group' && $conf['internal_type']=='file') { 00367 if ($conf['MM']) { 00368 $theFileValues=array(); 00369 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); 00370 $dbAnalysis->start('','files',$conf['MM'],$uid); 00371 reset($dbAnalysis->itemArray); 00372 while (list($somekey,$someval)=each($dbAnalysis->itemArray)) { 00373 // debug($someval['id']); 00374 if ($someval['id']) { 00375 $theFileValues[]=$someval['id']; 00376 } 00377 } 00378 } else { 00379 $theFileValues = explode(',',$value); 00380 } 00381 // debug($theFileValues); 00382 reset($theFileValues); 00383 $uploadFolder = $conf['uploadfolder']; 00384 $dest = $this->destPathFromUploadFolder($uploadFolder); 00385 $newValue = array(); 00386 $newValueFiles = array(); 00387 while (list(,$file)=each($theFileValues)) { 00388 if (trim($file)) { 00389 $realFile = $dest.'/'.trim($file); 00390 if (@is_file($realFile)) { 00391 $newValueFiles[] = array('fieldvalue'=>$file,'ID'=>md5($realFile),'ID_absFile'=>$realFile); // the order should be preserved here because 00392 } else $this->error('Missing file: '.$realFile); 00393 } 00394 } 00395 $outRow[$field]=array( 00396 'type'=>'file', 00397 'newValueFiles'=>$newValueFiles, 00398 ); 00399 } 00400 // db record lists: 00401 if (($conf['type']=='group' && $conf['internal_type']=='db') || ($conf['type']=='select' && $conf['foreign_table'])) { 00402 $allowedTables = $conf['type']=='group' ? $conf['allowed'] : $conf['foreign_table'].','.$conf['neg_foreign_table']; 00403 $prependName = $conf['type']=='group' ? $conf['prepend_tname'] : $conf['neg_foreign_table']; 00404 00405 $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup'); 00406 $dbAnalysis->start($value,$allowedTables,$conf['MM'],$uid); 00407 00408 $outRow[$field]=array( 00409 'type'=>'db', 00410 # 'tableArray' => $dbAnalysis->tableArray, 00411 'itemArray' => $dbAnalysis->itemArray, 00412 # 'getValueArray' => $dbAnalysis->getValueArray($prependName) 00413 ); 00414 } 00415 } 00416 } 00417 return $outRow; 00418 } 00419 00426 function flatDBrels($dbrels) { 00427 $list=array(); 00428 reset($dbrels); 00429 while(list($table,$dat)=each($dbrels)) { 00430 if ($dat['type']=='db') { 00431 reset($dat['itemArray']); 00432 while(list(,$i)=each($dat['itemArray'])) { 00433 $list[$i['table'].':'.$i['id']]=$i; 00434 } 00435 } 00436 } 00437 # if (count($list)) debug($list); 00438 return $list; 00439 # debug($dbrels); 00440 } 00441 00448 function loadContent($filecontent) { 00449 $pointer = 0; 00450 00451 $this->dat['header'] = $this->getNextContentPart($filecontent,$pointer,1,'header'); 00452 $this->dat['records'] = $this->getNextContentPart($filecontent,$pointer,1,'records'); 00453 $this->dat['files'] = $this->getNextContentPart($filecontent,$pointer,1,'files'); 00454 } 00455 00465 function getNextContentPart($filecontent,&$pointer,$unserialize=0,$name='') { 00466 $initStrLen = 32+1+1+1+10+1; 00467 // getting header data 00468 $initStr = substr($filecontent,$pointer,$initStrLen); 00469 $pointer+=$initStrLen; 00470 $initStrDat=explode(':',$initStr); 00471 if (!strcmp($initStrDat[3],'')) { 00472 $datString = substr($filecontent,$pointer,intval($initStrDat[2])); 00473 $pointer+=intval($initStrDat[2])+1; 00474 if (!strcmp(md5($datString),$initStrDat[0])) { 00475 if ($initStrDat[1]) { 00476 if ($this->compress) { 00477 $datString=gzuncompress($datString); 00478 } else debug('Content read error: This file requires decompression, but this server does not offer gzcompress()/gzuncompress() functions.',1); 00479 } 00480 return $unserialize ? unserialize($datString) : $datString; 00481 } else debug('MD5 check failed ('.$name.')'); 00482 } else debug('Content read error: InitString had a wrong length. ('.$name.')'); 00483 } 00484 00492 function loadFile($filename,$all=0) { 00493 if (@is_file($filename)) { 00494 if($fd = fopen($filename,'rb')) { 00495 $this->dat['header']=$this->getNextFilePart($fd,1,'header'); 00496 if ($all) { 00497 $this->dat['records']=$this->getNextFilePart($fd,1,'records'); 00498 $this->dat['files']=$this->getNextFilePart($fd,1,'files'); 00499 } 00500 } else debug('Error opening file: '.$filename); 00501 fclose($fd); 00502 } else debug('Filename not found: '.$filename); 00503 } 00504 00513 function getNextFilePart($fd,$unserialize=0,$name='') { 00514 $initStrLen = 32+1+1+1+10+1; 00515 00516 // getting header data 00517 $initStr = fread($fd,$initStrLen); 00518 $initStrDat=explode(':',$initStr); 00519 if (!strcmp($initStrDat[3],'')) { 00520 $datString = fread($fd,intval($initStrDat[2])); 00521 fread($fd,1); 00522 if (!strcmp(md5($datString),$initStrDat[0])) { 00523 if ($initStrDat[1]) { 00524 if ($this->compress) { 00525 $datString=gzuncompress($datString); 00526 } else debug('Content read error: This file requires decompression, but this server does not offer gzcompress()/gzuncompress() functions.',1); 00527 } 00528 return $unserialize ? unserialize($datString) : $datString; 00529 } else debug('MD5 check failed ('.$name.')'); 00530 } else debug('File read error: InitString had a wrong length. ('.$name.')'); 00531 } 00532 00538 function compileMemoryToFileContent() { 00539 $compress=$this->doOutputCompress(); 00540 $out=''; 00541 00542 // adding header: 00543 $out.=$this->addFilePart(serialize($this->dat['header']),$compress); 00544 00545 // adding records: 00546 $out.=$this->addFilePart(serialize($this->dat['records']),$compress); 00547 00548 // adding files: 00549 $out.=$this->addFilePart(serialize($this->dat['files']),$compress); 00550 00551 return $out; 00552 } 00553 00559 function doOutputCompress() { 00560 return $this->compress && !$this->dontCompress; 00561 } 00562 00570 function addFilePart($data,$compress=0) { 00571 if ($compress) $data=gzcompress($data); 00572 return md5($data).':'.($compress?'1':'0').':'.str_pad(strlen($data),10,'0',STR_PAD_LEFT).':'.$data.':'; 00573 } 00574 00581 function error($msg) { 00582 $this->errorLog[]=$msg; 00583 } 00584 00590 function printErrorLog() { 00591 return t3lib_div::view_array($this->errorLog); 00592 } 00593 00600 function destPathFromUploadFolder ($folder) { 00601 return PATH_site.$folder; 00602 } 00603 00604 00605 00606 00607 00608 00609 00610 00611 00612 00619 function importData($pid) { 00620 global $TCA; 00621 #debug($this->dat['header']); 00622 #debug($this->dat['records']); 00623 00624 // These vars MUST last for the whole section not being cleared. They are used by the method setRelations() which are called at the end of the import session. 00625 $this->import_mapId=array(); 00626 $this->import_newId=array(); 00627 $this->import_newId_pids=array(); 00628 00629 00630 00631 // BEGIN pages session 00632 if (is_array($this->dat['header']['records']['pages'])) { 00633 // $pageRecords is a copy of the pages array in the imported file. Records here are unset one by one when the addSingle function is called. 00634 $pageRecords = $this->dat['header']['records']['pages']; 00635 $this->initImportVars(); // Init each tcemain session with this! 00636 // First add page tree if any 00637 if (is_array($this->dat['header']['pagetree'])) { 00638 $pagesFromTree=$this->flatInversePageTree($this->dat['header']['pagetree']); 00639 reset($pagesFromTree); 00640 while(list(,$uid)=each($pagesFromTree)) { 00641 $thisRec = $this->dat['header']['records']['pages'][$uid]; 00642 // PID: Set the main $pid, unless a NEW-id is found 00643 $setPid = isset($this->import_newId_pids[$thisRec['pid']]) ? $this->import_newId_pids[$thisRec['pid']] : $pid; 00644 $this->addSingle('pages',$uid,$setPid); 00645 unset($pageRecords[$uid]); 00646 } 00647 } 00648 #debug($pageRecords); 00649 // Then add all remaining pages. 00650 if (count($pageRecords)) { 00651 reset($pageRecords); 00652 while(list($table,$recs)=each($pageRecords)) { 00653 reset($recs); 00654 while(list($uid)=each($recs)) { 00655 $this->addSingle($table,$uid,$pid); 00656 } 00657 } 00658 } 00659 00660 // Now write to database: 00661 $tce = $this->getNewTCE(); 00662 $tce->start($this->import_data,Array()); 00663 $tce->process_datamap(); 00664 00665 // post-processing: Removing files and registering new ids (end all tcemain sessions with this) 00666 $this->addToMapId($tce->substNEWwithIDs); 00667 $this->unlinkTempFiles(); 00668 } 00669 00670 #debug($this->import_mapId); 00671 // BEGIN tcemain session (rest except pages) 00672 $this->initImportVars(); // Init each tcemain session with this! 00673 if (is_array($this->dat['header']['records'])) { 00674 reset($this->dat['header']['records']); 00675 while(list($table,$recs)=each($this->dat['header']['records'])) { 00676 if ($table!='pages') { 00677 reset($recs); 00678 while(list($uid,$thisRec)=each($recs)) { 00679 // PID: Set the main $pid, unless a NEW-id is found 00680 $setPid = isset($this->import_mapId['pages'][$thisRec['pid']]) ? $this->import_mapId['pages'][$thisRec['pid']] : $pid; 00681 if (is_array($TCA[$table]) && $TCA[$table]['ctrl']['rootLevel']) { 00682 $setPid=0; 00683 } 00684 #debug($setPid); 00685 #debug($thisRec); 00686 $this->addSingle($table,$uid,$setPid); 00687 } 00688 } 00689 } 00690 } else debug('Error: No records defined in internal data array.'); 00691 00692 #debug($this->unlinkFiles); 00693 #debug($this->alternativeFileName); 00694 #debug($this->import_data); 00695 00696 // Now write to database: 00697 $tce = $this->getNewTCE(); 00698 $tce->reverseOrder=1; // Because all records are being submitted in their correct order with positive pid numbers - and so we should reverse submission order internally. 00699 $tce->start($this->import_data,Array()); 00700 $tce->process_datamap(); 00701 00702 00703 // post-processing: Removing files and registering new ids (end all tcemain sessions with this) 00704 $this->addToMapId($tce->substNEWwithIDs); 00705 $this->unlinkTempFiles(); 00706 00707 #debug($this->import_newId); 00708 #debug($tce->substNEWwithIDs); 00709 # $tce->clear_cacheCmd($cacheCmd); 00710 // END tcemain sessions 00711 00712 00713 // Finally all the database record references must be fixed. This is done after all records have supposedly been written to database: 00714 // $this->import_mapId will indicate two things: 1) that a record WAS written to db and 2) that it has got a new id-number. 00715 $this->setRelations(); 00716 } 00717 00723 function getNewTCE() { 00724 $tce = t3lib_div::makeInstance('t3lib_TCEmain'); 00725 $tce->stripslashes_values=0; 00726 $tce->dontProcessTransformations=1; 00727 $tce->enableLogging=0; 00728 $tce->alternativeFileName = $this->alternativeFileName; 00729 return $tce; 00730 } 00731 00737 function setRelations() { 00738 global $TCA; 00739 00740 $updateData=array(); 00741 reset($this->import_newId); 00742 while(list($nId,$dat)=each($this->import_newId)) { 00743 $table=$dat['table']; 00744 $uid=$dat['uid']; // original UID - NOT the new one! 00745 if (is_array($this->import_mapId[$table]) && isset($this->import_mapId[$table][$uid])) { 00746 $thisNewUid = $this->import_mapId[$table][$uid]; 00747 if (is_array($this->dat['records'][$table.':'.$uid]['rels'])) { 00748 reset($this->dat['records'][$table.':'.$uid]['rels']); 00749 while(list($field,$config)=each($this->dat['records'][$table.':'.$uid]['rels'])) { 00750 switch((string)$config['type']) { 00751 case 'db': 00752 if (count($config['itemArray'])) { 00753 $valArray=array(); 00754 reset($config['itemArray']); 00755 while(list(,$relDat)=each($config['itemArray'])) { 00756 if (is_array($this->import_mapId[$relDat['table']]) && isset($this->import_mapId[$relDat['table']][$relDat['id']])) { 00757 #debug('FOUND: '.$relDat['table'].':'.$relDat['id'],1); 00758 $valArray[]=$relDat['table'].'_'.$this->import_mapId[$relDat['table']][$relDat['id']]; 00759 } elseif (is_array($TCA[$relDat['table']]) && $TCA[$relDat['table']]['ctrl']['is_static']) { 00760 #debug('STATIC: '.$relDat['table'].':'.$relDat['id'],1); 00761 $valArray[]=$relDat['table'].'_'.$relDat['id']; 00762 } else { 00763 debug('Lost relation: '.$relDat['table'].':'.$relDat['id'],1); 00764 } 00765 } 00766 $updateData[$table][$thisNewUid][$field]=implode(',',$valArray); 00767 } 00768 break; 00769 } 00770 } 00771 } else debug('Error: no record was found in data array!',1); 00772 } else debug('Error: this records is NOT created it seems! ('.$table.':'.$uid.')',1); 00773 } 00774 if (count($updateData)) { 00775 #debug($updateData); 00776 $tce = $this->getNewTCE(); 00777 $tce->start($updateData,Array()); 00778 $tce->process_datamap(); 00779 } 00780 } 00781 00788 function addToMapId($substNEWwithIDs) { 00789 reset($this->import_data); 00790 while(list($table,$recs)=each($this->import_data)) { 00791 reset($recs); 00792 while(list($id)=each($recs)) { 00793 $old_uid = $this->import_newId[$id]['uid']; 00794 if (isset($substNEWwithIDs[$id])) { 00795 $this->import_mapId[$table][$old_uid]=$substNEWwithIDs[$id]; 00796 } else debug('Possible error: '.$table.':'.$old_uid.' had no new id assigned to it. This indicates that the record was not added to database during import. Please check changelog!',1); 00797 } 00798 } 00799 00800 } 00801 00807 function initImportVars() { 00808 $this->import_data=array(); 00809 $this->unlinkFiles=array(); 00810 $this->alternativeFileName=array(); 00811 } 00812 00818 function unlinkTempFiles() { 00819 $tempPath = $this->getTempPathFileName(''); 00820 #debug($tempPath); 00821 reset($this->unlinkFiles); 00822 while(list(,$fileName)=each($this->unlinkFiles)) { 00823 if (t3lib_div::isFirstPartOfStr($fileName,$tempPath)) { 00824 unlink($fileName); 00825 clearstatcache(); 00826 if (is_file($fileName)) { 00827 debug('Error: '.$fileName.' was NOT unlinked as it should have been!',1); 00828 } 00829 } else debug('Error: '.$fileName.' was not in temp-path. Not removed!',1); 00830 } 00831 } 00832 00841 function addSingle($table,$uid,$pid) { 00842 $record = $this->dat['records'][$table.':'.$uid]['data']; 00843 if (is_array($record)) { 00844 $ID = uniqid('NEW'); 00845 $this->import_newId[$ID] = array('table'=>$table,'uid'=>$uid); 00846 if ($table=='pages') $this->import_newId_pids[$uid]=$ID; 00847 00848 $this->import_data[$table][$ID]=$record; 00849 $this->import_data[$table][$ID]['tx_impexp_origuid']=$this->import_data[$table][$ID]['uid']; 00850 unset($this->import_data[$table][$ID]['uid']); 00851 $this->import_data[$table][$ID]['pid']=$pid; 00852 00853 reset($this->dat['records'][$table.':'.$uid]['rels']); 00854 while(list($field,$config)=each($this->dat['records'][$table.':'.$uid]['rels'])) { 00855 $this->import_data[$table][$ID][$field]=''; 00856 switch((string)$config['type']) { 00857 case 'db': 00858 #debug($config); 00859 // ... later 00860 break; 00861 case 'file': 00862 $valArr=array(); 00863 reset($config['newValueFiles']); 00864 while(list(,$fI)=each($config['newValueFiles'])) { 00865 $valArr[]=$this->import_addFileNameToBeCopied($fI); 00866 #debug($fI); 00867 } 00868 $this->import_data[$table][$ID][$field]=implode(',',$valArr); 00869 break; 00870 } 00871 } 00872 } else debug('Error: no record was found in data array!',1); 00873 } 00874 00881 function import_addFileNameToBeCopied($fI) { 00882 if (is_array($this->dat['files'][$fI['ID']])) { 00883 $tmpFile=$this->getTempPathFileName('import_'.$GLOBALS['EXEC_TIME'].'_'.$fI['ID'].'.tmp'); 00884 if (!@is_file($tmpFile)) { 00885 t3lib_div::writeFile($tmpFile,$this->dat['files'][$fI['ID']]['content']); 00886 clearstatcache(); 00887 if (@is_file($tmpFile)) { 00888 if (filesize($tmpFile)==$this->dat['files'][$fI['ID']]['filesize']) { 00889 $this->unlinkFiles[]=$tmpFile; 00890 $this->alternativeFileName[$tmpFile]=$fI['fieldvalue']; 00891 #debug($tmpFile,1); 00892 return $tmpFile; 00893 } else debug('Error: temporary file '.$tmpFile.' had a size ('.filesize($tmpFile).') different from the original ('.$this->dat['files'][$fI['ID']]['filesize'].')',1); 00894 } else debug('Error: temporary file '.$tmpFile.' was not written as it should have been!',1); 00895 } else debug('Error: temporary file '.$tmpFile.' existed already!',1); 00896 } else debug('Error: No file found for ID '.$fI['ID'],1); 00897 } 00898 00905 function getTempPathFileName($fN) { 00906 return PATH_site.'typo3temp/'.$fN; 00907 } 00908 00909 00910 00911 00912 00913 00914 00915 00916 00917 00918 00919 00920 00926 function displayContentOverview () { 00927 # unset($this->dat['records']); 00928 unset($this->dat['files']); 00929 # debug($this->dat['header']); 00930 00931 $this->remainHeader = $this->dat['header']; 00932 if (is_array($this->remainHeader)) { 00933 00934 if (is_array($this->dat['header']['pagetree'])) { 00935 reset($this->dat['header']['pagetree']); 00936 $lines=array(); 00937 $this->traversePageTree($this->dat['header']['pagetree'],$lines); 00938 00939 $rows=array(); 00940 # debug($lines); 00941 reset($lines); 00942 while(list(,$r)=each($lines)) { 00943 $rows[]='<tr bgcolor="'.$r['bgColor'].'"> 00944 <td nowrap="nowrap">'.$r['preCode'].$r['title'].'</td> 00945 <td nowrap="nowrap">'.t3lib_div::formatSize($r['size']).'</td> 00946 <td nowrap="nowrap">'.($r['msg']?'<span class="typo3-red">'.$r['msg'].'</span>':'').'</td> 00947 </tr>'; 00948 } 00949 $rows[]='<tr> 00950 <td><img src="clear.gif" width="300" height="1" alt="" /></td> 00951 <td></td> 00952 <td></td> 00953 </tr>'; 00954 $out = '<strong>Inside pagetree:</strong><br /><br /><table border="0" cellpadding="0" cellspacing="0">'.implode('',$rows).'</table><br /><br />'; 00955 } 00956 00957 00958 $lines=array(); 00959 if (is_array($this->remainHeader['records']['pages'])) { 00960 $this->traversePageRecords($this->remainHeader['records']['pages'],$lines); 00961 } 00962 $this->traverseAllRecords($this->remainHeader['records'],$lines); 00963 00964 if (count($lines)) { 00965 $rows=array(); 00966 # debug($lines); 00967 reset($lines); 00968 while(list(,$r)=each($lines)) { 00969 $rows[]='<tr bgcolor="'.$r['bgColor'].'"> 00970 <td nowrap="nowrap">'.$r['preCode'].$r['title'].'</td> 00971 <td nowrap="nowrap">'.t3lib_div::formatSize($r['size']).'</td> 00972 <td nowrap="nowrap">'.($r['msg']?'<span class="typo3-red">'.$r['msg'].'</span>':'').'</td> 00973 </tr>'; 00974 } 00975 $rows[]='<tr> 00976 <td><img src="clear.gif" width="300" height="1" alt="" /></td> 00977 <td></td> 00978 <td></td> 00979 </tr>'; 00980 $out.= '<strong>Outside pagetree:</strong><br /><br /><table border="0" cellpadding="0" cellspacing="0">'.implode('',$rows).'</table>'; 00981 } 00982 00983 #debug($this->remainHeader); 00984 } 00985 return $out; 00986 } 00987 00996 function traversePageTree($pT,&$lines,$preCode='') { 00997 reset($pT); 00998 while(list($k,$v)=each($pT)) { 00999 $this->singleRecordLines('pages',$k,$lines,$preCode); 01000 // Subrecords: 01001 if (is_array($this->dat['header']['pid_lookup'][$k])) { 01002 reset($this->dat['header']['pid_lookup'][$k]); 01003 while(list($t,$recUidArr)=each($this->dat['header']['pid_lookup'][$k])) { 01004 if ($t!='pages') { 01005 reset($recUidArr); 01006 while(list($ruid)=each($recUidArr)) { 01007 $this->singleRecordLines($t,$ruid,$lines,$preCode.' '); 01008 } 01009 } 01010 } 01011 unset($this->remainHeader['pid_lookup'][$k]); 01012 } 01013 // Subpages: 01014 if (is_array($v['subrow'])) $this->traversePageTree($v['subrow'],$lines,$preCode.' '); 01015 } 01016 } 01017 01025 function traversePageRecords($pT,&$lines) { 01026 reset($pT); 01027 while(list($k,$rHeader)=each($pT)) { 01028 $this->singleRecordLines('pages',$k,$lines,'',1); 01029 // Subrecords: 01030 if (is_array($this->dat['header']['pid_lookup'][$k])) { 01031 reset($this->dat['header']['pid_lookup'][$k]); 01032 while(list($t,$recUidArr)=each($this->dat['header']['pid_lookup'][$k])) { 01033 if ($t!='pages') { 01034 reset($recUidArr); 01035 while(list($ruid)=each($recUidArr)) { 01036 $this->singleRecordLines($t,$ruid,$lines,$preCode.' '); 01037 } 01038 } 01039 } 01040 unset($this->remainHeader['pid_lookup'][$k]); 01041 } 01042 } 01043 } 01044 01052 function traverseallrecords($pT,&$lines) { 01053 reset($pT); 01054 while(list($t,$recUidArr)=each($pT)) { 01055 if ($t!='pages') { 01056 reset($recUidArr); 01057 while(list($ruid)=each($recUidArr)) { 01058 $this->singleRecordLines($t,$ruid,$lines,$preCode,1); 01059 } 01060 } 01061 } 01062 } 01063 01074 function singleRecordLines($table,$uid,&$lines,$preCode,$checkImportInPidRecord=0) { 01075 global $TCA,$BE_USER; 01076 01077 $record = $this->dat['header']['records'][$table][$uid]; 01078 unset($this->remainHeader['records'][$table][$uid]); 01079 if (!is_array($record)) debug('MISSING RECORD: '.$table.':'.$uid,1); 01080 01081 $pInfo=array(); 01082 $pInfo['ref']=$table.':'.$uid; 01083 if (!isset($TCA[$table])) { 01084 $pInfo['preCode']=$preCode; 01085 $pInfo['msg']="UNKNOWN TABLE '".$pInfo['ref']."'"; 01086 $pInfo['title']='<em>'.htmlspecialchars($record['title']).'</em>'; 01087 } else { 01088 if (is_array($this->display_import_pid_record)) { 01089 if ($checkImportInPidRecord) { 01090 if (!$BE_USER->doesUserHaveAccess($this->display_import_pid_record,$table=='pages'?8:16)) { 01091 $pInfo['msg'].="'".$pInfo['ref']."' cannot be INSERTED on this page! "; 01092 } 01093 if (!$this->checkDokType($table,$this->display_import_pid_record['doktype']) && !$TCA[$table]['ctrl']['rootLevel']) { 01094 $pInfo['msg'].="'".$table."' cannot be INSERTED on this page type (change to 'sysFolder'!) "; 01095 } 01096 } 01097 if (!$BE_USER->check('tables_modify',$table)) {$pInfo['msg'].="You are not allowed to CREATE '".$table."' tables! ";} 01098 01099 if ($TCA[$table]['ctrl']['readOnly']) {$pInfo['msg'].="TABLE '".$table."' is READ ONLY! ";} 01100 if ($TCA[$table]['ctrl']['adminOnly'] && !$BE_USER->isAdmin()) {$pInfo['msg'].="TABLE '".$table."' is ADMIN ONLY! ";} 01101 if ($TCA[$table]['ctrl']['is_static']) {$pInfo['msg'].="TABLE '".$table."' is a STATIC TABLE! ";} 01102 if ($TCA[$table]['ctrl']['rootLevel']) {$pInfo['msg'].="TABLE '".$table."' will be inserted on ROOT LEVEL! ";} 01103 } 01104 $pInfo['preCode']=$preCode.t3lib_iconworks::getIconImage($table,$this->dat['records'][$table.':'.$uid]['data'],$GLOBALS['BACK_PATH'],'align="top" title="'.htmlspecialchars($table.':'.$uid).'"'); 01105 $pInfo['title']=htmlspecialchars($record['title']); 01106 } 01107 $pInfo['bgColor']=$table=='pages' ? t3lib_div::modifyHTMLColor($GLOBALS['TBE_TEMPLATE']->bgColor4,-10,-10,-10) : t3lib_div::modifyHTMLColor($GLOBALS['TBE_TEMPLATE']->bgColor4,20,20,20); 01108 $pInfo['size']=$record['size']; 01109 $lines[]=$pInfo; 01110 // Files 01111 if (is_array($record['filerefs'])) { 01112 reset($record['filerefs']); 01113 while(list(,$ID)=each($record['filerefs'])) { 01114 $fI=$this->dat['header']['files'][$ID]; 01115 if (!is_array($fI)) debug('MISSING FILE: '.$ID,1); 01116 $pInfo=array(); 01117 $pInfo['preCode']=$preCode.' <img src="'.$GLOBALS['BACK_PATH'].'t3lib/gfx/rel_file.gif" width="13" height="12" align="top" alt="" />'; 01118 $pInfo['title']=htmlspecialchars($fI['filename']); 01119 $pInfo['ref']='FILE'; 01120 $pInfo['size']=$fI['filesize']; 01121 $pInfo['bgColor']=t3lib_div::modifyHTMLColor($GLOBALS['TBE_TEMPLATE']->bgColor4,10,10,10); 01122 $lines[]=$pInfo; 01123 unset($this->remainHeader['files'][$ID]); 01124 } 01125 } 01126 // DB: 01127 if (is_array($record['rels'])) { 01128 $this->addRelations($record['rels'],$lines,$preCode); 01129 } 01130 } 01131 01141 function addRelations($rels,&$lines,$preCode,$recurCheck=array()) { 01142 reset($rels); 01143 while(list(,$dat)=each($rels)) { 01144 $table=$dat['table']; 01145 $uid=$dat['id']; 01146 $pInfo=array(); 01147 $Iprepend=''; 01148 $pInfo['ref']=$table.':'.$uid; 01149 if (!in_array($pInfo['ref'],$recurCheck)) { 01150 $record = $this->dat['header']['records'][$table][$uid]; 01151 if (!is_array($record)) { 01152 if (isset($GLOBALS['TCA'][$table]) && $GLOBALS['TCA'][$table]['ctrl']['is_static']) { 01153 $pInfo['title']=htmlspecialchars('STATIC: '.$pInfo['ref']); 01154 $Iprepend='_static'; 01155 } else { 01156 $pInfo['title']=htmlspecialchars($pInfo['ref']); 01157 $pInfo['msg']='LOST RELATION'; 01158 $Iprepend='_lost'; 01159 # debug('MISSING relation: '.$table.':'.$uid,1); 01160 } 01161 } else { 01162 $pInfo['title']=htmlspecialchars($record['title']); 01163 $pInfo['size']=$record['size']; 01164 } 01165 01166 $pInfo['preCode']=$preCode.' <img src="'.$GLOBALS['BACK_PATH'].'t3lib/gfx/rel_db'.$Iprepend.'.gif" width="13" height="12" align="top" title="'.$pInfo['ref'].'" alt="" />'; 01167 $pInfo['bgColor']=t3lib_div::modifyHTMLColor($GLOBALS['TBE_TEMPLATE']->bgColor4,10,10,10); 01168 $lines[]=$pInfo; 01169 if (is_array($record) && is_array($record['rels'])) { 01170 $this->addRelations($record['rels'],$lines,$preCode.' ',array_merge($recurCheck,array($pInfo['ref']))); 01171 } 01172 } else debug($pInfo['ref'].' was recursive...'); 01173 } 01174 } 01175 01183 function checkDokType($checkTable,$doktype) { 01184 global $PAGES_TYPES; 01185 $allowedTableList = isset($PAGES_TYPES[$doktype]['allowedTables']) ? $PAGES_TYPES[$doktype]['allowedTables'] : $PAGES_TYPES['default']['allowedTables']; 01186 $allowedArray = t3lib_div::trimExplode(',',$allowedTableList,1); 01187 if (strstr($allowedTableList,'*') || in_array($checkTable,$allowedArray)) { // If all tables or the table is listed as a allowed type, return true 01188 return true; 01189 } 01190 } 01191 } 01192 01193 01194 01195 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/impexp/class.tx_impexp.php']) { 01196 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/impexp/class.tx_impexp.php']); 01197 } 01198 ?>