Feature #16323 » 6039_v7.patch

Administrator Admin, 2009-01-21 14:46

View differences:

typo3_src/t3lib/class.t3lib_admin.php 2009-01-21 14:22:29.000000000 +0100
582 582
	 */
583 583
	function testFileRefs ()	{
584 584
		$output=Array();
585
	
586
		// handle direct references with upload folder setting (workaround)
587
		$newCheckFileRefs = array();
585 588
		reset($this->checkFileRefs);
589
		foreach ($this->checkFileRefs as $folder => $files) {
590
			// only direct references without a folder setting
591
			if ($folder !== '') {
592
				$newCheckFileRefs[$folder] = $files;
593
				continue;
594
			}
595

  
596
			foreach ($files as $file => $references) {
597

  
598
				// direct file refernces have often many references (removes occurences in the moreReferences section of the result array)
599
				if ($references > 1) {
600
					$references = 1;
601
				}
602

  
603
				// the directory must be empty (prevents checking of the root directory)
604
				$directory = dirname($file);
605
				if ($directory !== '') {
606
					$newCheckFileRefs[$directory][basename($file)] = $references;
607
				}
608
			}
609
		}
610
		$this->checkFileRefs = $newCheckFileRefs;
611

  
586 612
		while(list($folder,$fileArr)=each($this->checkFileRefs))	{
587 613
			$path = PATH_site.$folder;
588 614
			if (@is_dir($path))	{
......
600 626
							}
601 627
							unset($fileArr[$entry]);
602 628
						} else {
603
							if (!strstr($entry,'index.htm'))	{
629
							// contains workaround for direct references
630
							if (!strstr($entry,'index.htm') && !preg_match('/^fileadmin/', $folder)) {
604 631
								$output['noReferences'][] = Array($path,$entry);
605 632
							}
606 633
						}
......
610 637
				reset($fileArr);
611 638
				$tempCounter=0;
612 639
				while(list($file,)=each($fileArr))	{
640
					// workaround for direct file references
641
					if (preg_match('/^fileadmin/', $folder)) {
642
						$file = $folder . '/' . $file;
643
						$folder = '';
644
						$path = substr(PATH_site, 0, strlen(PATH_site) - 1);
645
					}
646

  
613 647
					$temp = $this->whereIsFileReferenced($folder,$file);
614 648
					$tempList = '';
615 649
					while(list(,$inf)=each($temp))	{
typo3_src/t3lib/class.t3lib_refindex.php 2009-01-21 14:22:29.000000000 +0100
205 205
 						case 'db':
206 206
 							$this->createEntryData_dbRels($table,$uid,$fieldname,'',$deleted,$dat['itemArray']);
207 207
 						break;
208
						case 'file_reference':
208 209
 						case 'file':
209 210
 							$this->createEntryData_fileRels($table,$uid,$fieldname,'',$deleted,$dat['newValueFiles']);
210 211
 						break;
......
342 343
								 	list($tableName,$recordId) = explode(':',$el['subst']['recordRef']);
343 344
								 	$this->relations[] = $this->createEntryData($table,$uid,$fieldname,$flexpointer,$deleted,$tableName,$recordId,'',-1,$spKey,$subKey);
344 345
								 break;
346
								 case 'file_reference':
345 347
								 case 'file':
346 348
								 	$this->relations[] = $this->createEntryData($table,$uid,$fieldname,$flexpointer,$deleted,'_FILE',0,$el['subst']['relFileName'],-1,$spKey,$subKey);
347 349
								 break;
......
537 539
	 */
538 540
	function getRelations_procFiles($value, $conf, $uid)	{
539 541
			// Take care of files...
540
		if ($conf['type']=='group' && $conf['internal_type']=='file')	{
542
		if ($conf['type'] == 'group' && ($conf['internal_type'] == 'file' || $conf['internal_type'] == 'file_reference')) {
541 543

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

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

  
typo3_src/t3lib/class.t3lib_tceforms.php 2009-01-21 14:22:29.000000000 +0100
2001 2001

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

  
2004
			case 'file_reference':
2005
				$config['uploadfolder'] = '';
2006
				// Fall through
2007
			case 'file':
2006 2008
					// Creating string showing allowed types:
2007 2009
				$tempFT = t3lib_div::trimExplode(',',$allowed,1);
2008 2010
				if (!count($tempFT))	{$info.='*';}
......
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":
......
3376 3380
						}
3377 3381
					}
3378 3382
				break;
3383
				case 'file_reference':
3379 3384
				case 'file':
3380 3385
				case 'folder':
3381 3386
					while(list(,$pp)=each($itemArray))	{
3382 3387
						$pParts = explode('|',$pp);
3383 3388
						$uidList[]=$pUid=$pTitle = $pParts[0];
3384
						$opt[]='<option value="'.htmlspecialchars(rawurldecode($pParts[0])).'">'.htmlspecialchars(rawurldecode($pParts[0])).'</option>';
3389
						$opt[]='<option value="'.htmlspecialchars(rawurldecode($pParts[0])).'">'.htmlspecialchars(basename(rawurldecode($pParts[0]))).'</option>';
3385 3390
					}
3386 3391
				break;
3387 3392
				default:
......
3419 3424
				}
3420 3425
				$aOnClick='setFormValueOpenBrowser(\''.$mode.'\',\''.($fName.'|||'.$allowed.'|'.$aOnClickInline).'\'); return false;';
3421 3426
				$icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
3422
						'<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'))).' />'.
3427
						'<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'))).' />'.
3423 3428
						'</a>';
3424 3429
			}
3425 3430
			if (!$params['dontShowMoveIcons'])	{
......
3444 3449
			$clipElements = $this->getClipboardElements($allowed,$mode);
3445 3450
			if (count($clipElements))	{
3446 3451
				$aOnClick = '';
3447
	#			$counter = 0;
3448 3452
				foreach($clipElements as $elValue)	{
3449
					if ($mode=='file')	{
3450
						$itemTitle = 'unescape(\''.rawurlencode(basename($elValue)).'\')';
3451
					} else {	// 'db' mode assumed
3453
					if ($mode=='db') {
3452 3454
						list($itemTable,$itemUid) = explode('|', $elValue);
3453 3455
						$itemTitle = $GLOBALS['LANG']->JScharCode(t3lib_BEfunc::getRecordTitle($itemTable, t3lib_BEfunc::getRecordWSOL($itemTable,$itemUid)));
3454 3456
						$elValue = $itemTable.'_'.$itemUid;
3457
					} else {
3458
						// 'file', 'file_reference' and 'folder' mode
3459
						$itemTitle = 'unescape(\''.rawurlencode(basename($elValue)).'\')';
3455 3460
					}
3456 3461
					$aOnClick.= 'setFormValueFromBrowseWin(\''.$fName.'\',unescape(\''.rawurlencode(str_replace('%20',' ',$elValue)).'\'),'.$itemTitle.');';
3457 3462

  
3458
	#				$counter++;
3459
	#				if ($params['maxitems'] && $counter >= $params['maxitems'])	{	break;	}	// Makes sure that no more than the max items are inserted... for convenience.
3460 3463
				}
3461 3464
				$aOnClick.= 'return false;';
3462 3465
				$icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
3463
						'<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))).' />'.
3466
						'<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))).' />'.
3464 3467
						'</a>';
3465 3468
			}
3466 3469
			$rOnClick = $rOnClickInline.'setFormValueManipulate(\''.$fName.'\',\'Remove\'); return false';
......
3512 3515

  
3513 3516
		if (is_object($this->clipObj))	{
3514 3517
			switch($mode)	{
3518
				case 'file_reference':
3515 3519
				case 'file':
3516 3520
					$elFromTable = $this->clipObj->elFromTable('_FILE');
3517 3521
					$allowedExts = t3lib_div::trimExplode(',', $allowed, 1);
......
5798 5802
	 * @return 	string		HTML formatted output
5799 5803
	 */
5800 5804
	function previewFieldValue($value, $config)	{
5801
		if ($config['config']['type']==='group' && $config['config']['internal_type'] === 'file')	{
5805
		if ($config['config']['type']==='group' &&
5806
				($config['config']['internal_type'] === 'file' ||
5807
				 $config['config']['internal_type'] === 'file_reference')) {
5808
			// Ignore uploadfolder if internal_type is file_reference
5809
			if ($config['config']['internal_type'] === 'file_reference') {
5810
				$config['config']['uploadfolder'] = '';
5811
			}
5812
			
5802 5813
			$show_thumbs = TRUE;
5803 5814
			$table = 'tt_content';
5804 5815

  
typo3_src/t3lib/class.t3lib_tcemain.php 2009-01-21 14:22:29.000000000 +0100
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
						$theFile = t3lib_div::fixWindowsFilePath($theFile);
1774
						if (t3lib_div::isFirstPartOfStr($theFile,PATH_site)) {
1775
							$theFile = substr($theFile,strlen(PATH_site));
1776
						}
1777
					}
1778
				}
1779
			}
1717 1780
		}
1718 1781

  
1719 1782
		return $valueArray;
......
3151 3214
	function copyRecord_procFilesRefs($conf, $uid, $value)	{
3152 3215

  
3153 3216
			// Prepend absolute paths to files:
3154
		if ($conf['type']=='group' && $conf['internal_type']=='file')	{
3217
		if ($conf['type']=='group' && ($conf['internal_type']=='file' || $conf['internal_type']=='file_reference'))	{
3155 3218

  
3156 3219
				// Get an array with files as values:
3157 3220
			if ($conf['MM'])	{
......
3171 3234
			}
3172 3235

  
3173 3236
				// Traverse this array of files:
3174
			$uploadFolder = $conf['uploadfolder'];
3237
			$uploadFolder = $conf['internal_type']=='file' ? $conf['uploadfolder'] : '';
3175 3238
			$dest = $this->destPathFromUploadFolder($uploadFolder);
3176 3239
			$newValue = array();
3177 3240

  
3178 3241
			foreach($theFileValues as $file)	{
3179 3242
				if (trim($file))	{
3180
					$realFile = $dest.'/'.trim($file);
3243
					$realFile = str_replace('//', '/', $dest.'/'.trim($file));
3181 3244
					if (@is_file($realFile))	{
3182 3245
						$newValue[] = $realFile;
3183 3246
					}
......
6492 6555
		if ($TCA[$table]['columns'])	{
6493 6556
			reset($TCA[$table]['columns']);
6494 6557
			while (list($field,$configArr)=each($TCA[$table]['columns']))	{
6495
				if ($configArr['config']['type']=='group' && $configArr['config']['internal_type']=='file')	{
6558
				if ($configArr['config']['type']=='group' &&
6559
					($configArr['config']['internal_type']=='file' ||
6560
					 $configArr['config']['internal_type']=='file_reference'))	{
6496 6561
					$listArr[]=$field;
6497 6562
				}
6498 6563
			}
......
6661 6726
		global $TCA;
6662 6727
		t3lib_div::loadTCA($table);
6663 6728
		$uploadFolder = $TCA[$table]['columns'][$field]['config']['uploadfolder'];
6664
		if ($uploadFolder && trim($filelist))	{
6729
		if ($uploadFolder && trim($filelist) && $TCA[$table]['columns'][$field]['config']['internal_type'] == 'file') {
6665 6730
			$uploadPath = $this->destPathFromUploadFolder($uploadFolder);
6666 6731
			$fileArray = explode(',',$filelist);
6667 6732
			while (list(,$theFile)=each($fileArray))	{
typo3_src/typo3/sysext/impexp/class.tx_impexp.php 2009-01-21 14:22:29.000000000 +0100
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);
(9-9/15)