Feature #16323 » 6039_v14.diff

Administrator Admin, 2009-07-31 14:10

View differences:

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

  
538 540
				// Collect file values in array:
539 541
			if ($conf['MM'])	{
......
551 553
			}
552 554

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

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

  
2062 2062
			// Acting according to either "file" or "db" type:
2063 2063
		switch((string)$config['internal_type'])	{
2064
			case 'file_reference':
2065
				$config['uploadfolder'] = '';
2066
				// Fall through
2064 2067
			case 'file':	// If the element is of the internal type "file":
2065 2068

  
2066 2069
					// Creating string showing allowed types:
......
2095 2098
						$rowCopy[$field] = $imgPath;
2096 2099

  
2097 2100
							// Icon + clickmenu:
2098
						$absFilePath = t3lib_div::getFileAbsFileName($config['uploadfolder'].'/'.$imgPath);
2101
						$absFilePath = t3lib_div::getFileAbsFileName($config['uploadfolder'] ? $config['uploadfolder'] . '/' . $imgPath : $imgPath);
2099 2102

  
2100 2103
						$fI = pathinfo($imgPath);
2101 2104
						$fileIcon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
......
2127 2130

  
2128 2131
				if(!$disabled && !(isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'upload'))) {
2129 2132
						// Adding the upload field:
2130
					if ($this->edit_docModuleUpload)	$item.='<input type="file" name="'.$PA['itemFormElName_file'].'"'.$this->formWidth().' size="60" />';
2133
					if ($this->edit_docModuleUpload && $config['uploadfolder']) {
2134
						$item .= '<input type="file" name="' . $PA['itemFormElName_file'] . '"' . $this->formWidth() . ' size="60" />';
2135
					}
2131 2136
				}
2132 2137
			break;
2133 2138
			case 'folder':	// If the element is of the internal type "folder":
......
3459 3464
						}
3460 3465
					}
3461 3466
				break;
3467
				case 'file_reference':
3462 3468
				case 'file':
3469
					foreach ($itemArray as $pp) {
3470
						$pParts = explode('|', $pp);
3471
						$uidList[] = $pUid = $pTitle = $pParts[0];
3472
						$opt[] = '<option value="' . htmlspecialchars(rawurldecode($pParts[0])) . '">' . htmlspecialchars(basename(rawurldecode($pParts[0]))) . '</option>';
3473
					}
3474
				break;
3463 3475
				case 'folder':
3464 3476
					while(list(,$pp)=each($itemArray))	{
3465 3477
						$pParts = explode('|',$pp);
......
3502 3514
				}
3503 3515
				$aOnClick='setFormValueOpenBrowser(\''.$mode.'\',\''.($fName.'|||'.$allowed.'|'.$aOnClickInline).'\'); return false;';
3504 3516
				$icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
3505
						'<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'))).' />'.
3517
						'<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'))) . ' />' .
3506 3518
						'</a>';
3507 3519
			}
3508 3520
			if (!$params['dontShowMoveIcons'])	{
......
3527 3539
			$clipElements = $this->getClipboardElements($allowed,$mode);
3528 3540
			if (count($clipElements))	{
3529 3541
				$aOnClick = '';
3530
	#			$counter = 0;
3531 3542
				foreach($clipElements as $elValue)	{
3532
					if ($mode=='file')	{
3533
						$itemTitle = 'unescape(\''.rawurlencode(basename($elValue)).'\')';
3534
					} else {	// 'db' mode assumed
3543
					if ($mode == 'db') {
3535 3544
						list($itemTable,$itemUid) = explode('|', $elValue);
3536 3545
						$itemTitle = $GLOBALS['LANG']->JScharCode(t3lib_BEfunc::getRecordTitle($itemTable, t3lib_BEfunc::getRecordWSOL($itemTable,$itemUid)));
3537 3546
						$elValue = $itemTable.'_'.$itemUid;
3547
					} else {
3548
							// 'file', 'file_reference' and 'folder' mode
3549
						$itemTitle = 'unescape(\'' . rawurlencode(basename($elValue)) . '\')';
3538 3550
					}
3539 3551
					$aOnClick.= 'setFormValueFromBrowseWin(\''.$fName.'\',unescape(\''.rawurlencode(str_replace('%20',' ',$elValue)).'\'),'.$itemTitle.');';
3540

  
3541
	#				$counter++;
3542
	#				if ($params['maxitems'] && $counter >= $params['maxitems'])	{	break;	}	// Makes sure that no more than the max items are inserted... for convenience.
3543 3552
				}
3544 3553
				$aOnClick.= 'return false;';
3545 3554
				$icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
3546
						'<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))).' />'.
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 == 'db' ? 'db' : 'file')), count($clipElements))) . ' />' .
3547 3556
						'</a>';
3548 3557
			}
3549 3558
			$rOnClick = $rOnClickInline.'setFormValueManipulate(\''.$fName.'\',\'Remove\'); return false';
......
3595 3604

  
3596 3605
		if (is_object($this->clipObj))	{
3597 3606
			switch($mode)	{
3607
				case 'file_reference':
3598 3608
				case 'file':
3599 3609
					$elFromTable = $this->clipObj->elFromTable('_FILE');
3600 3610
					$allowedExts = t3lib_div::trimExplode(',', $allowed, 1);
......
5906 5916
	 * @return 	string		HTML formatted output
5907 5917
	 */
5908 5918
	function previewFieldValue($value, $config)	{
5909
		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

  
5910 5927
			$show_thumbs = TRUE;
5911 5928
			$table = 'tt_content';
5912 5929

  
......
5925 5942
					$rowCopy[$field] = $imgPath;
5926 5943

  
5927 5944
						// Icon + clickmenu:
5928
					$absFilePath = t3lib_div::getFileAbsFileName($config['config']['uploadfolder'].'/'.$imgPath);
5945
					$absFilePath = t3lib_div::getFileAbsFileName($config['config']['uploadfolder'] ? $config['config']['uploadfolder'] . '/' . $imgPath : $imgPath);
5929 5946

  
5930 5947
					$fI = pathinfo($imgPath);
5931 5948
					$fileIcon = t3lib_BEfunc::getFileIcon(strtolower($fI['extension']));
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('/^' . preg_quote($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/') . '/', $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('/^' . preg_quote($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/') . '/', $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))	{
......
736 768
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_admin.php'])	{
737 769
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_admin.php']);
738 770
}
739
?>
771
?>
t3lib/class.t3lib_tcemain.php (working copy)
261 261
	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)
262 262
	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!
263 263
	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.
264
	var $alternativeFilePath = array();		// Array [filename]=alternative_filepath: Same as alternativeFileName but with relative path to the file 
264 265
	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.
265 266
	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)
266 267

  
......
1484 1485
			// For group types:
1485 1486
		if ($tcaFieldConf['type']=='group')	{
1486 1487
			switch($tcaFieldConf['internal_type'])	{
1488
				case 'file_reference':
1487 1489
				case 'file':
1488 1490
					$valueArray = $this->checkValue_group_select_file(
1489 1491
						$valueArray,
......
1568 1570
		}
1569 1571

  
1570 1572
			// If there is an upload folder defined:
1571
		if ($tcaFieldConf['uploadfolder'])	{
1573
		if ($tcaFieldConf['uploadfolder'] && $tcaFieldConf['internal_type'] == 'file') {
1572 1574
			if (!$this->bypassFileHandling)	{	// If filehandling should NOT be bypassed, do processing:
1573 1575
					// For logging..
1574 1576
				$propArr = $this->getRecordProperties($table,$id);
......
1699 1701
				}
1700 1702
				$valueArray = $dbAnalysis->countItems();
1701 1703
			}
1704
			//store path relative to site root (if uploadfolder is not set or internal_type is file_reference)
1705
		} else {
1706
			if (count($valueArray)){
1707
				if (!$this->bypassFileHandling) {	// If filehandling should NOT be bypassed, do processing:
1708
					$propArr = $this->getRecordProperties($table, $id); // For logging..
1709
					foreach($valueArray as &$theFile){ 
1710

  
1711
							// if alernative File Path is set for the file, then it was an import
1712
						if ($this->alternativeFilePath[$theFile]){
1713

  
1714
								// don't import the file if it already exists
1715
							if (@is_file(PATH_site . $this->alternativeFilePath[$theFile])) {
1716
								$theFile = PATH_site . $this->alternativeFilePath[$theFile];
1717

  
1718
								// import the file
1719
							} elseif (@is_file($theFile)){
1720
								$dest = dirname(PATH_site . $this->alternativeFilePath[$theFile]);
1721
								if (!@is_dir($dest)) {
1722
									t3lib_div::mkdir_deep(PATH_site, dirname($this->alternativeFilePath[$theFile]) . '/');
1723
								}
1724

  
1725
									// Init:
1726
								$maxSize = intval($tcaFieldConf['max_size']);
1727
								$cmd = '';
1728
								$theDestFile = '';		// Must be cleared. Else a faulty fileref may be inserted if the below code returns an error!
1729
								$fileSize = filesize($theFile);
1730

  
1731
								if (!$maxSize || $fileSize <= ($maxSize * 1024))	{	// Check file size:
1732
										// Prepare filename:
1733
									$theEndFileName = isset($this->alternativeFileName[$theFile]) ? $this->alternativeFileName[$theFile] : $theFile;
1734
									$fI = t3lib_div::split_fileref($theEndFileName);
1735

  
1736
										// Check for allowed extension:
1737
									if ($this->fileFunc->checkIfAllowed($fI['fileext'], $dest, $theEndFileName)) {
1738
										$theDestFile = PATH_site . $this->alternativeFilePath[$theFile];
1739

  
1740
											// Write the file:
1741
										if ($theDestFile)	{
1742
											t3lib_div::upload_copy_move($theFile, $theDestFile);
1743
											$this->copiedFileMap[$theFile] = $theDestFile;
1744
											clearstatcache();
1745
											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']);
1746
										} 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']);
1747
									} else $this->log($table, $id, 5, 0, 1, "Fileextension '%s' not allowed. (%s)", 12, array($fI['fileext'], $recFID), $propArr['event_pid']);
1748
								} 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']);
1749

  
1750
									// If the destination file was created, we will set the new filename in the value array, otherwise unset the entry in the value array!
1751
								if (@is_file($theDestFile))	{
1752
									$theFile = $theDestFile; // The value is set to the new filename
1753
								} else {
1754
									unset($theFile); // The value is set to the new filename
1755
								}
1756
							}
1757
						}
1758
						$theFile = t3lib_div::fixWindowsFilePath($theFile);
1759
						if (t3lib_div::isFirstPartOfStr($theFile, PATH_site)) {
1760
							$theFile = substr($theFile, strlen(PATH_site));
1761
						}
1762
					}
1763
				}
1764
			}
1702 1765
		}
1703 1766

  
1704 1767
		return $valueArray;
......
3149 3212
	function copyRecord_procFilesRefs($conf, $uid, $value)	{
3150 3213

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

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

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

  
3176 3239
			foreach($theFileValues as $file)	{
3177 3240
				if (trim($file))	{
3178
					$realFile = $dest.'/'.trim($file);
3241
					$realFile = str_replace('//', '/', $dest . '/' . trim($file));
3179 3242
					if (@is_file($realFile))	{
3180 3243
						$newValue[] = $realFile;
3181 3244
					}
......
6515 6578
		t3lib_div::loadTCA($table);
6516 6579
		if (isset($GLOBALS['TCA'][$table]['columns'])) {
6517 6580
			foreach ($GLOBALS['TCA'][$table]['columns'] as $field => $configArr) {
6518
				if ($configArr['config']['type']=='group' && $configArr['config']['internal_type']=='file')	{
6519
					$listArr[]=$field;
6520
				}
6581
				if ($configArr['config']['type'] == 'group' &&
6582
					($configArr['config']['internal_type'] == 'file' ||
6583
					 $configArr['config']['internal_type'] == 'file_reference')) {
6584
					$listArr[] = $field;
6585
 				}
6521 6586
			}
6522 6587
		}
6523 6588
		return $listArr;
......
6687 6752
		global $TCA;
6688 6753
		t3lib_div::loadTCA($table);
6689 6754
		$uploadFolder = $TCA[$table]['columns'][$field]['config']['uploadfolder'];
6690
		if ($uploadFolder && trim($filelist))	{
6755
		if ($uploadFolder && trim($filelist) && $TCA[$table]['columns'][$field]['config']['internal_type'] == 'file') {
6691 6756
			$uploadPath = $this->destPathFromUploadFolder($uploadFolder);
6692 6757
			$fileArray = explode(',',$filelist);
6693 6758
			foreach ($fileArray as $theFile) {
typo3/sysext/impexp/class.tx_impexp.php (working copy)
775 775
				$fileRec['filesize'] = filesize($fI['ID_absFile']);
776 776
				$fileRec['filename'] = basename($fI['ID_absFile']);
777 777
				$fileRec['filemtime'] = filemtime($fI['ID_absFile']);
778
					//for internal type file_reference
779
				$fileRec['relFileRef'] = substr($fI['ID_absFile'], strlen(PATH_site));
778 780
				if ($recordRef)	{
779 781
					$fileRec['record_ref'] = $recordRef.'/'.$fieldname;
780 782
				}
......
1159 1161
			// Temporary files stack initialized:
1160 1162
		$this->unlinkFiles = array();
1161 1163
		$this->alternativeFileName = array();
1164
		$this->alternativeFilePath = array();
1162 1165

  
1163 1166
			// Write records, first pages, then the rest
1164 1167
			// Fields with "hard" relations to database, files and flexform fields are kept empty during this run
......
1478 1481
		$tce->dontProcessTransformations = 1;
1479 1482
		$tce->enableLogging = $this->enableLogging;
1480 1483
		$tce->alternativeFileName = $this->alternativeFileName;
1484
		$tce->alternativeFilePath = $this->alternativeFilePath;
1481 1485
		return $tce;
1482 1486
	}
1483 1487

  
......
1615 1619
				$this->unlinkFiles[] = $tmpFile;
1616 1620
				if (filesize($tmpFile)==$this->dat['files'][$fI['ID']]['filesize'])	{
1617 1621
					$this->alternativeFileName[$tmpFile] = $fI['filename'];
1622
					$this->alternativeFilePath[$tmpFile] = $this->dat['files'][$fI['ID']]['relFileRef'];
1618 1623

  
1619 1624
					return $tmpFile;
1620 1625
				} else $this->error('Error: temporary file '.$tmpFile.' had a size ('.filesize($tmpFile).') different from the original ('.$this->dat['files'][$fI['ID']]['filesize'].')',1);
(13-13/15)