Feature #16323 » 6039_v8.diff

Administrator Admin, 2009-03-27 23:01

View differences:

t3lib/class.t3lib_admin.php (working copy)
582 582
	 */
583 583
	function testFileRefs ()	{
584 584
		$output=Array();
585
		// handle direct references with upload folder setting (workaround)
586
		$newCheckFileRefs = array();
587
        foreach ($this->checkFileRefs as $folder => $files) {
588
			// only direct references without a folder setting
589
			if ($folder !== '') {
590
				$newCheckFileRefs[$folder] = $files;
591
				continue;
592
			}
593

  
594
			foreach ($files as $file => $references) {
595

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

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

  
585 610
		reset($this->checkFileRefs);
586 611
		while(list($folder,$fileArr)=each($this->checkFileRefs))	{
587 612
			$path = PATH_site.$folder;
......
600 625
							}
601 626
							unset($fileArr[$entry]);
602 627
						} else {
603
							if (!strstr($entry,'index.htm'))	{
628
							// contains workaround for direct references
629
							if (!strstr($entry, 'index.htm') && !preg_match('/^fileadmin/', $folder)) {
604 630
								$output['noReferences'][] = Array($path,$entry);
605 631
							}
606 632
						}
......
610 636
				reset($fileArr);
611 637
				$tempCounter=0;
612 638
				while(list($file,)=each($fileArr))	{
639
					// workaround for direct file references
640
					if (preg_match('/^fileadmin/', $folder)) {
641
						$file = $folder . '/' . $file;
642
						$folder = '';
643
						$path = substr(PATH_site, 0, - 1);
644
					}
613 645
					$temp = $this->whereIsFileReferenced($folder,$file);
614 646
					$tempList = '';
615 647
					while(list(,$inf)=each($temp))	{
t3lib/class.t3lib_refindex.php (working copy)
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

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

  
2071 2071
			// Acting according to either "file" or "db" type:
2072 2072
		switch((string)$config['internal_type'])	{
2073
			case 'file_reference':
2074
				$config['uploadfolder'] = '';
2075
				// Fall through
2073 2076
			case 'file':	// If the element is of the internal type "file":
2074 2077

  
2075 2078
					// Creating string showing allowed types:
......
2136 2139

  
2137 2140
				if(!$disabled && !(isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'upload'))) {
2138 2141
						// Adding the upload field:
2139
					if ($this->edit_docModuleUpload)	$item.='<input type="file" name="'.$PA['itemFormElName_file'].'"'.$this->formWidth().' size="60" />';
2142
					if ($this->edit_docModuleUpload && $config['uploadfolder']) {
2143
						$item .= '<input type="file" name="' . $PA['itemFormElName_file'] . '"' . $this->formWidth() . ' size="60" />';
2144
					}
2140 2145
				}
2141 2146
			break;
2142 2147
			case 'folder':	// If the element is of the internal type "folder":
......
3468 3473
						}
3469 3474
					}
3470 3475
				break;
3476
				case 'file_reference':
3471 3477
				case 'file':
3472 3478
				case 'folder':
3473 3479
					while(list(,$pp)=each($itemArray))	{
3474 3480
						$pParts = explode('|',$pp);
3475 3481
						$uidList[]=$pUid=$pTitle = $pParts[0];
3476
						$opt[]='<option value="'.htmlspecialchars(rawurldecode($pParts[0])).'">'.htmlspecialchars(rawurldecode($pParts[0])).'</option>';
3482
						$opt[] = '<option value="' . htmlspecialchars(rawurldecode($pParts[0])) . '">' . htmlspecialchars(basename(rawurldecode($pParts[0]))) . '</option>';
3477 3483
					}
3478 3484
				break;
3479 3485
				default:
......
3511 3517
				}
3512 3518
				$aOnClick='setFormValueOpenBrowser(\''.$mode.'\',\''.($fName.'|||'.$allowed.'|'.$aOnClickInline).'\'); return false;';
3513 3519
				$icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
3514
						'<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'))).' />'.
3520
						'<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'))) . ' />' .
3515 3521
						'</a>';
3516 3522
			}
3517 3523
			if (!$params['dontShowMoveIcons'])	{
......
3536 3542
			$clipElements = $this->getClipboardElements($allowed,$mode);
3537 3543
			if (count($clipElements))	{
3538 3544
				$aOnClick = '';
3539
	#			$counter = 0;
3540 3545
				foreach($clipElements as $elValue)	{
3541
					if ($mode=='file')	{
3542
						$itemTitle = 'unescape(\''.rawurlencode(basename($elValue)).'\')';
3543
					} else {	// 'db' mode assumed
3546
					if ($mode == 'db') {
3544 3547
						list($itemTable,$itemUid) = explode('|', $elValue);
3545 3548
						$itemTitle = $GLOBALS['LANG']->JScharCode(t3lib_BEfunc::getRecordTitle($itemTable, t3lib_BEfunc::getRecordWSOL($itemTable,$itemUid)));
3546 3549
						$elValue = $itemTable.'_'.$itemUid;
3547
					}
3550
					} else {
3551
						// 'file', 'file_reference' and 'folder' mode
3552
						$itemTitle = 'unescape(\'' . rawurlencode(basename($elValue)) . '\')';
3553
 					}
3548 3554
					$aOnClick.= 'setFormValueFromBrowseWin(\''.$fName.'\',unescape(\''.rawurlencode(str_replace('%20',' ',$elValue)).'\'),'.$itemTitle.');';
3549 3555

  
3550
	#				$counter++;
3551
	#				if ($params['maxitems'] && $counter >= $params['maxitems'])	{	break;	}	// Makes sure that no more than the max items are inserted... for convenience.
3552 3556
				}
3553 3557
				$aOnClick.= 'return false;';
3554 3558
				$icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
3555
						'<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))).' />'.
3559
						'<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))) . ' />' .
3556 3560
						'</a>';
3557 3561
			}
3558 3562
			$rOnClick = $rOnClickInline.'setFormValueManipulate(\''.$fName.'\',\'Remove\'); return false';
......
3604 3608

  
3605 3609
		if (is_object($this->clipObj))	{
3606 3610
			switch($mode)	{
3611
				case 'file_reference':
3607 3612
				case 'file':
3608 3613
					$elFromTable = $this->clipObj->elFromTable('_FILE');
3609 3614
					$allowedExts = t3lib_div::trimExplode(',', $allowed, 1);
......
5911 5916
	 * @return 	string		HTML formatted output
5912 5917
	 */
5913 5918
	function previewFieldValue($value, $config)	{
5914
		if ($config['config']['type']==='group' && $config['config']['internal_type'] === 'file')	{
5919
		if ($config['config']['type']==='group' &&
5920
				($config['config']['internal_type'] === 'file' ||
5921
				 $config['config']['internal_type'] === 'file_reference')) {
5922
			// Ignore uploadfolder if internal_type is file_reference
5923
			if ($config['config']['internal_type'] === 'file_reference') {
5924
				$config['config']['uploadfolder'] = '';
5925
			}
5926

  
5915 5927
			$show_thumbs = TRUE;
5916 5928
			$table = 'tt_content';
5917 5929

  
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

  
......
1493 1494
			// For group types:
1494 1495
		if ($tcaFieldConf['type']=='group')	{
1495 1496
			switch($tcaFieldConf['internal_type'])	{
1497
				case 'file_reference':
1496 1498
				case 'file':
1497 1499
					$valueArray = $this->checkValue_group_select_file(
1498 1500
						$valueArray,
......
1577 1579
		}
1578 1580

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

  
1740
								if (!$maxSize || $fileSize <= ($maxSize * 1024))	{	// Check file size:
1741
										// Prepare filename:
1742
									$theEndFileName = isset($this->alternativeFileName[$theFile]) ? $this->alternativeFileName[$theFile] : $theFile;
1743
									$fI = t3lib_div::split_fileref($theEndFileName);
1744

  
1745
										// Check for allowed extension:
1746
									if ($this->fileFunc->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
1747
										$theDestFile = PATH_site . $this->alternativeFilePath[$theFile];
1748

  
1749
											// Write the file:
1750
										if ($theDestFile)	{
1751
											t3lib_div::upload_copy_move($theFile, $theDestFile);
1752
											$this->copiedFileMap[$theFile] = $theDestFile;
1753
											clearstatcache();
1754
											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']);
1755
										} 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']);
1756
									} else $this->log($table, $id, 5, 0, 1, "Fileextension '%s' not allowed. (%s)", 12, array($fI['fileext'], $recFID), $propArr['event_pid']);
1757
								} 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']);
1758

  
1759
									// If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array!
1760
								if (@is_file($theDestFile))	{
1761
									$theFile = $theDestFile; // The value is set to the new filename
1762
								} else {
1763
									unset($theFile); // The value is set to the new filename
1764
								}
1765
							}
1766
						}
1767
						$theFile = t3lib_div::fixWindowsFilePath($theFile);
1768
						if (t3lib_div::isFirstPartOfStr($theFile, PATH_site)) {
1769
							$theFile = substr($theFile, strlen(PATH_site));
1770
						}
1771
					}
1772
				}
1773
			}
1711 1774
		}
1712 1775

  
1713 1776
		return $valueArray;
......
3147 3210
	function copyRecord_procFilesRefs($conf, $uid, $value)	{
3148 3211

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

  
3152 3215
				// Get an array with files as values:
3153 3216
			if ($conf['MM'])	{
......
3167 3230
			}
3168 3231

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

  
3174 3237
			foreach($theFileValues as $file)	{
3175 3238
				if (trim($file))	{
3176
					$realFile = $dest.'/'.trim($file);
3239
					$realFile = str_replace('//', '/', $dest.'/'.trim($file));
3177 3240
					if (@is_file($realFile))	{
3178 3241
						$newValue[] = $realFile;
3179 3242
					}
......
6511 6574
		t3lib_div::loadTCA($table);
6512 6575
		if (isset($GLOBALS['TCA'][$table]['columns'])) {
6513 6576
			foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $configArr) {
6514
				if ($configArr['config']['type']=='group' && $configArr['config']['internal_type']=='file')	{
6515
					$listArr[]=$field;
6577
				if ($configArr['config']['type'] == 'group' &&
6578
					($configArr['config']['internal_type'] == 'file' ||
6579
					 $configArr['config']['internal_type'] == 'file_reference')) {
6580
					$listArr[] = $field;
6516 6581
				}
6517 6582
			}
6518 6583
		}
......
6683 6748
		global $TCA;
6684 6749
		t3lib_div::loadTCA($table);
6685 6750
		$uploadFolder = $TCA[$table]['columns'][$field]['config']['uploadfolder'];
6686
		if ($uploadFolder && trim($filelist))	{
6751
		if ($uploadFolder && trim($filelist) && $TCA[$table]['columns'][$field]['config']['internal_type'] == 'file') {
6687 6752
			$uploadPath = $this->destPathFromUploadFolder($uploadFolder);
6688 6753
			$fileArray = explode(',',$filelist);
6689 6754
			foreach ($fileArray as $theFile) {
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();
1170

  
1171
        $this->alternativeFilePath = array();
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
1173 1175
		$this->writeRecords_pages($pid);
......
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'];
1626

  
1629
                    $this->alternativeFilePath[$tmpFile] = $this->dat['files'][$fI['ID']]['relFileRef'];
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);
1629 1633
			} else $this->error('Error: temporary file '.$tmpFile.' was not written as it should have been!',1);
(10-10/15)