Feature #16323 » 6039_v5_with_impexp.patch

Administrator Admin, 2008-08-02 13:47

View differences:

t3lib/class.t3lib_refindex.php (working copy)
204 204
 						case 'db':
205 205
 							$this->createEntryData_dbRels($table,$uid,$fieldname,'',$deleted,$dat['itemArray']);
206 206
 						break;
207
						case 'file_reference':
207 208
 						case 'file':
208 209
 							$this->createEntryData_fileRels($table,$uid,$fieldname,'',$deleted,$dat['newValueFiles']);
209 210
 						break;
......
341 342
								 	list($tableName,$recordId) = explode(':',$el['subst']['recordRef']);
342 343
								 	$this->relations[] = $this->createEntryData($table,$uid,$fieldname,$flexpointer,$deleted,$tableName,$recordId,'',-1,$spKey,$subKey);
343 344
								 break;
345
								 case 'file_reference':
344 346
								 case 'file':
345 347
								 	$this->relations[] = $this->createEntryData($table,$uid,$fieldname,$flexpointer,$deleted,'_FILE',0,$el['subst']['relFileName'],-1,$spKey,$subKey);
346 348
								 break;
......
536 538
	 */
537 539
	function getRelations_procFiles($value, $conf, $uid)	{
538 540
			// Take care of files...
539
		if ($conf['type']=='group' && $conf['internal_type']=='file')	{
541
		if ($conf['type']=='group' && ($conf['internal_type']=='file' || $conf['internal_type']=='file_reference'))	{
540 542

  
541 543
				// Collect file values in array:
542 544
			if ($conf['MM'])	{
......
554 556
			}
555 557

  
556 558
				// Traverse the files and add them:
557
			$uploadFolder = $conf['uploadfolder'];
559
			$uploadFolder = $conf['internal_type']=='file' ? $conf['uploadfolder'] : '';
558 560
			$dest = $this->destPathFromUploadFolder($uploadFolder);
559 561
			$newValue = array();
560 562
			$newValueFiles = array();
......
564 566
					$realFile = $dest.'/'.trim($file);
565 567
#					if (@is_file($realFile))	{		// Now, the refernece index should NOT look if files exist - just faithfully include them if they are in the records!
566 568
						$newValueFiles[] = array(
567
							'filename' => $file,
569
							'filename' => basename($file),
568 570
							'ID' => md5($realFile),
569 571
							'ID_absFile' => $realFile
570 572
						);	// the order should be preserved here because.. (?)
......
667 669
		 							$error = $this->setReferenceValue_dbRels($refRec,$dat['itemArray'],$newValue,$dataArray);
668 670
									if ($error)	return $error;
669 671
		 						break;
672
								case 'file_reference':
670 673
		 						case 'file':
671 674
		 							$this->setReferenceValue_fileRels($refRec,$dat['newValueFiles'],$newValue,$dataArray);
672 675
									if ($error)	return $error;
......
974 977
	 * @return	string		Input folder prefixed with PATH_site. No checking for existence is done. Output must be a folder without trailing slash.
975 978
	 */
976 979
	function destPathFromUploadFolder($folder)	{
980
		if (!$folder) {
981
			return substr(PATH_site, 0, -1);
982
		}
977 983
		return PATH_site.$folder;
978 984
	}
979 985

  
t3lib/class.t3lib_tceforms.php (working copy)
2001 2001

  
2002 2002
			// Acting according to either "file" or "db" type:
2003 2003
		switch((string)$config['internal_type'])	{
2004
			case 'file_reference':
2005
				$config['uploadfolder'] = '';
2004 2006
			case 'file':	// If the element is of the internal type "file":
2005 2007

  
2006 2008
					// Creating string showing allowed types:
......
2067 2069

  
2068 2070
				if(!$disabled && !(isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'upload'))) {
2069 2071
						// Adding the upload field:
2070
					if ($this->edit_docModuleUpload)	$item.='<input type="file" name="'.$PA['itemFormElName_file'].'"'.$this->formWidth().' size="60" />';
2072
					if ($this->edit_docModuleUpload && $config['uploadfolder']) {
2073
						$item.='<input type="file" name="'.$PA['itemFormElName_file'].'"'.$this->formWidth().' size="60" />';
2074
					}
2071 2075
				}
2072 2076
			break;
2073 2077
			case 'folder':	// If the element is of the internal type "folder":
......
3370 3374
						}
3371 3375
					}
3372 3376
				break;
3377
				case 'file_reference':
3373 3378
				case 'file':
3374 3379
				case 'folder':
3375 3380
					while(list(,$pp)=each($itemArray))	{
3376 3381
						$pParts = explode('|',$pp);
3377 3382
						$uidList[]=$pUid=$pTitle = $pParts[0];
3378
						$opt[]='<option value="'.htmlspecialchars(rawurldecode($pParts[0])).'">'.htmlspecialchars(rawurldecode($pParts[0])).'</option>';
3383
						$opt[]='<option value="'.htmlspecialchars(rawurldecode($pParts[0])).'">'.htmlspecialchars(basename(rawurldecode($pParts[0]))).'</option>';
3379 3384
					}
3380 3385
				break;
3381 3386
				default:
......
3413 3418
				}
3414 3419
				$aOnClick='setFormValueOpenBrowser(\''.$mode.'\',\''.($fName.'|||'.$allowed.'|'.$aOnClickInline).'\'); return false;';
3415 3420
				$icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
3416
						'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/insert3.gif','width="14" height="14"').' border="0" '.t3lib_BEfunc::titleAltAttrib($this->getLL('l_browse_'.($mode=='file'?'file':'db'))).' />'.
3421
						'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/insert3.gif','width="14" height="14"').' border="0" '.t3lib_BEfunc::titleAltAttrib($this->getLL('l_browse_'.($mode=='db'?'db':'file'))).' />'.
3417 3422
						'</a>';
3418 3423
			}
3419 3424
			if (!$params['dontShowMoveIcons'])	{
......
3440 3445
				$aOnClick = '';
3441 3446
	#			$counter = 0;
3442 3447
				foreach($clipElements as $elValue)	{
3443
					if ($mode=='file')	{
3444
						$itemTitle = 'unescape(\''.rawurlencode(basename($elValue)).'\')';
3445
					} else {	// 'db' mode assumed
3448
					if ($mode=='db')	{
3446 3449
						list($itemTable,$itemUid) = explode('|', $elValue);
3447 3450
						$itemTitle = $GLOBALS['LANG']->JScharCode(t3lib_BEfunc::getRecordTitle($itemTable, t3lib_BEfunc::getRecordWSOL($itemTable,$itemUid)));
3448 3451
						$elValue = $itemTable.'_'.$itemUid;
3452
					} else {	// 'file' mode assumed
3453
						$itemTitle = 'unescape(\''.rawurlencode(basename($elValue)).'\')';
3449 3454
					}
3450 3455
					$aOnClick.= 'setFormValueFromBrowseWin(\''.$fName.'\',unescape(\''.rawurlencode(str_replace('%20',' ',$elValue)).'\'),'.$itemTitle.');';
3451 3456

  
......
3454 3459
				}
3455 3460
				$aOnClick.= 'return false;';
3456 3461
				$icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
3457
						'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/insert5.png','width="14" height="14"').' border="0" '.t3lib_BEfunc::titleAltAttrib(sprintf($this->getLL('l_clipInsert_'.($mode=='file'?'file':'db')),count($clipElements))).' />'.
3462
						'<img'.t3lib_iconWorks::skinImg($this->backPath,'gfx/insert5.png','width="14" height="14"').' border="0" '.t3lib_BEfunc::titleAltAttrib(sprintf($this->getLL('l_clipInsert_'.($mode=='db'?'db':'file')),count($clipElements))).' />'.
3458 3463
						'</a>';
3459 3464
			}
3460 3465
			$rOnClick = $rOnClickInline.'setFormValueManipulate(\''.$fName.'\',\'Remove\'); return false';
......
3506 3511

  
3507 3512
		if (is_object($this->clipObj))	{
3508 3513
			switch($mode)	{
3514
				case 'file_reference':
3509 3515
				case 'file':
3510 3516
					$elFromTable = $this->clipObj->elFromTable('_FILE');
3511 3517
					$allowedExts = t3lib_div::trimExplode(',', $allowed, 1);
......
5780 5786
	 * @return 	string		HTML formatted output
5781 5787
	 */
5782 5788
	function previewFieldValue($value, $config)	{
5783
		if ($config['config']['type']==='group' && $config['config']['internal_type'] === 'file')	{
5789
		if ($config['config']['type']==='group' && ($config['config']['internal_type'] === 'file' || $config['config']['internal_type'] === 'file_reference'))	{
5790
				// Ignore uploadfolder if internal_type is file_reference
5791
			if ($config['config']['internal_type'] === 'file_reference') {
5792
				$config['config']['uploadfolder'] = '';
5793
			}
5794
			
5784 5795
			$show_thumbs = TRUE;
5785 5796
			$table = 'tt_content';
5786 5797

  
t3lib/class.t3lib_tcemain.php (working copy)
270 270
	var $defaultValues = array();			// Array [table][fields]=value: New records are created with default values and you can set this array on the form $defaultValues[$table][$field] = $value to override the default values fetched from TCA. If ->setDefaultsFromUserTS is called UserTSconfig default values will overrule existing values in this array (thus UserTSconfig overrules externally set defaults which overrules TCA defaults)
271 271
	var $overrideValues = array();			// Array [table][fields]=value: You can set this array on the form $overrideValues[$table][$field] = $value to override the incoming data. You must set this externally. You must make sure the fields in this array are also found in the table, because it's not checked. All columns can be set by this array!
272 272
	var $alternativeFileName = array();		// Array [filename]=alternative_filename: Use this array to force another name onto a file. Eg. if you set ['/tmp/blablabal'] = 'my_file.txt' and '/tmp/blablabal' is set for a certain file-field, then 'my_file.txt' will be used as the name instead.
273
	var $alternativeFilePath = array();		// Array [filename]=alternative_filepath: Same as alternativeFileName but with relative path to the file 
273 274
	var $data_disableFields=array();		// If entries are set in this array corresponding to fields for update, they are ignored and thus NOT updated. You could set this array from a series of checkboxes with value=0 and hidden fields before the checkbox with 1. Then an empty checkbox will disable the field.
274 275
	var $suggestedInsertUids=array();		// Use this array to validate suggested uids for tables by setting [table]:[uid]. This is a dangerous option since it will force the inserted record to have a certain UID. The value just have to be true, but if you set it to "DELETE" it will make sure any record with that UID will be deleted first (raw delete). The option is used for import of T3D files when synchronizing between two mirrored servers. As a security measure this feature is available only for Admin Users (for now)
275 276

  
......
1497 1498
			// For group types:
1498 1499
		if ($tcaFieldConf['type']=='group')	{
1499 1500
			switch($tcaFieldConf['internal_type'])	{
1501
				case 'file_reference':
1500 1502
				case 'file':
1501 1503
					$valueArray = $this->checkValue_group_select_file(
1502 1504
						$valueArray,
......
1581 1583
		}
1582 1584

  
1583 1585
			// If there is an upload folder defined:
1584
		if ($tcaFieldConf['uploadfolder'])	{
1586
		if ($tcaFieldConf['uploadfolder'] && $tcaFieldConf['internal_type'] == 'file') {
1585 1587
			if (!$this->bypassFileHandling)	{	// If filehandling should NOT be bypassed, do processing:
1586 1588
					// For logging..
1587 1589
				$propArr = $this->getRecordProperties($table,$id);
......
1714 1716
				}
1715 1717
				$valueArray = $dbAnalysis->countItems();
1716 1718
			}
1719
		//store path relative to site root (if uploadfolder is not set or internal_type is file_reference)
1720
		} else {
1721
			if (count($valueArray)){
1722
				if (!$this->bypassFileHandling) {	// If filehandling should NOT be bypassed, do processing:
1723
					$propArr = $this->getRecordProperties($table,$id); // For logging..
1724
					foreach($valueArray as &$theFile){ 
1725
						
1726
						// if alernative File Path is set for the file, then it was an import
1727
						if ($this->alternativeFilePath[$theFile]){
1728
							
1729
							// don't import the file if it already exists
1730
							if (@is_file(PATH_site.$this->alternativeFilePath[$theFile])){
1731
								$theFile = PATH_site.$this->alternativeFilePath[$theFile];
1732
							
1733
							// import the file
1734
							} else if (@is_file($theFile)){
1735
								$dest = dirname(PATH_site.$this->alternativeFilePath[$theFile]);
1736
								if (!@is_dir($dest)) {
1737
									t3lib_div::mkdir_deep(PATH_site, dirname($this->alternativeFilePath[$theFile]).'/');
1738
								}
1739
								
1740
								// Init:
1741
								$maxSize = intval($tcaFieldConf['max_size']);
1742
								$cmd='';
1743
								$theDestFile='';		// Must be cleared. Else a faulty fileref may be inserted if the below code returns an error!
1744
								$fileSize = filesize($theFile);
1745

  
1746
								if (!$maxSize || $fileSize<=($maxSize*1024))	{	// Check file size:
1747
										// Prepare filename:
1748
									$theEndFileName = isset($this->alternativeFileName[$theFile]) ? $this->alternativeFileName[$theFile] : $theFile;
1749
									$fI = t3lib_div::split_fileref($theEndFileName);
1750

  
1751
										// Check for allowed extension:
1752
									if ($this->fileFunc->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
1753
										$theDestFile = PATH_site.$this->alternativeFilePath[$theFile];
1754

  
1755
											// Write the file:
1756
										if ($theDestFile)	{
1757
											t3lib_div::upload_copy_move($theFile,$theDestFile);
1758
											$this->copiedFileMap[$theFile] = $theDestFile;
1759
											clearstatcache();
1760
											if (!@is_file($theDestFile))	$this->log($table,$id,5,0,1,"Copying file '%s' failed!: The destination path (%s) may be write protected. Please make it write enabled!. (%s)",16,array($theFile, dirname($theDestFile), $recFID),$propArr['event_pid']);
1761
										} else $this->log($table,$id,5,0,1,"Copying file '%s' failed!: No destination file (%s) possible!. (%s)",11,array($theFile, $theDestFile, $recFID),$propArr['event_pid']);
1762
									} else $this->log($table,$id,5,0,1,"Fileextension '%s' not allowed. (%s)",12,array($fI['fileext'], $recFID),$propArr['event_pid']);
1763
								} else $this->log($table,$id,5,0,1,"Filesize (%s) of file '%s' exceeds limit (%s). (%s)",13,array(t3lib_div::formatSize($fileSize),$theFile,t3lib_div::formatSize($maxSize*1024),$recFID),$propArr['event_pid']);
1764

  
1765
									// If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array!
1766
								if (@is_file($theDestFile))	{
1767
									$theFile = $theDestFile; // The value is set to the new filename
1768
								} else {
1769
									unset($theFile); // The value is set to the new filename
1770
								}
1771
							}
1772
						}
1773
					}
1774
					
1775
					$theFile = t3lib_div::fixWindowsFilePath($theFile);
1776
					if (t3lib_div::isFirstPartOfStr($theFile,PATH_site)) {
1777
						$theFile = substr($theFile,strlen(PATH_site));
1778
					}
1779
				}
1780
			}
1717 1781
		}
1718 1782

  
1719 1783
		return $valueArray;
......
3148 3212
	function copyRecord_procFilesRefs($conf, $uid, $value)	{
3149 3213

  
3150 3214
			// Prepend absolute paths to files:
3151
		if ($conf['type']=='group' && $conf['internal_type']=='file')	{
3215
		if ($conf['type']=='group' && ($conf['internal_type']=='file' || $conf['internal_type']=='file_reference'))	{
3152 3216

  
3153 3217
				// Get an array with files as values:
3154 3218
			if ($conf['MM'])	{
......
3168 3232
			}
3169 3233

  
3170 3234
				// Traverse this array of files:
3171
			$uploadFolder = $conf['uploadfolder'];
3235
			$uploadFolder = $conf['internal_type']=='file' ? $conf['uploadfolder'] : '';
3172 3236
			$dest = $this->destPathFromUploadFolder($uploadFolder);
3173 3237
			$newValue = array();
3174 3238

  
3175 3239
			foreach($theFileValues as $file)	{
3176 3240
				if (trim($file))	{
3177
					$realFile = $dest.'/'.trim($file);
3241
					$realFile = str_replace('//', '/', $dest.'/'.trim($file));
3178 3242
					if (@is_file($realFile))	{
3179 3243
						$newValue[] = $realFile;
3180 3244
					}
......
6473 6537
		if ($TCA[$table]['columns'])	{
6474 6538
			reset($TCA[$table]['columns']);
6475 6539
			while (list($field,$configArr)=each($TCA[$table]['columns']))	{
6476
				if ($configArr['config']['type']=='group' && $configArr['config']['internal_type']=='file')	{
6540
				if ($configArr['config']['type']=='group' && ($configArr['config']['internal_type']=='file' || $configArr['config']['internal_type']=='file_reference'))	{
6477 6541
					$listArr[]=$field;
6478 6542
				}
6479 6543
			}
......
6642 6706
		global $TCA;
6643 6707
		t3lib_div::loadTCA($table);
6644 6708
		$uploadFolder = $TCA[$table]['columns'][$field]['config']['uploadfolder'];
6645
		if ($uploadFolder && trim($filelist))	{
6709
		if ($uploadFolder && trim($filelist) && $TCA[$table]['columns'][$field]['config']['internal_type'] == 'file')	{
6646 6710
			$uploadPath = $this->destPathFromUploadFolder($uploadFolder);
6647 6711
			$fileArray = explode(',',$filelist);
6648 6712
			while (list(,$theFile)=each($fileArray))	{
typo3/sysext/impexp/class.tx_impexp.php (working copy)
783 783
				$fileRec['filesize'] = filesize($fI['ID_absFile']);
784 784
				$fileRec['filename'] = basename($fI['ID_absFile']);
785 785
				$fileRec['filemtime'] = filemtime($fI['ID_absFile']);
786
				$fileRec['relFileRef'] = substr($fI['ID_absFile'],strlen(PATH_site)); //for internal type file_reference
786 787
				if ($recordRef)	{
787 788
					$fileRec['record_ref'] = $recordRef.'/'.$fieldname;
788 789
				}
......
1167 1168
			// Temporary files stack initialized:
1168 1169
		$this->unlinkFiles = array();
1169 1170
		$this->alternativeFileName = array();
1171
		$this->alternativeFilePath = array();
1170 1172

  
1171 1173
			// Write records, first pages, then the rest
1172 1174
			// Fields with "hard" relations to database, files and flexform fields are kept empty during this run
......
1486 1488
		$tce->dontProcessTransformations = 1;
1487 1489
		$tce->enableLogging = $this->enableLogging;
1488 1490
		$tce->alternativeFileName = $this->alternativeFileName;
1491
		$tce->alternativeFilePath = $this->alternativeFilePath;
1489 1492
		return $tce;
1490 1493
	}
1491 1494

  
......
1623 1626
				$this->unlinkFiles[] = $tmpFile;
1624 1627
				if (filesize($tmpFile)==$this->dat['files'][$fI['ID']]['filesize'])	{
1625 1628
					$this->alternativeFileName[$tmpFile] = $fI['filename'];
1629
					$this->alternativeFilePath[$tmpFile] = $this->dat['files'][$fI['ID']]['relFileRef'];
1626 1630

  
1627 1631
					return $tmpFile;
1628 1632
				} else $this->error('Error: temporary file '.$tmpFile.' had a size ('.filesize($tmpFile).') different from the original ('.$this->dat['files'][$fI['ID']]['filesize'].')',1);
(5-5/15)