Feature #16323 » 6039_v6.diff

Administrator Admin, 2008-08-19 21:48

View differences:

t3lib/class.t3lib_refindex.php (working copy)
204 204
 					switch((string)$dat['type'])	{
205 205
 						case 'db':
206 206
 							$this->createEntryData_dbRels($table,$uid,$fieldname,'',$deleted,$dat['itemArray']);
207
 						break;
207
							break;
208
						case 'file_reference':
208 209
 						case 'file':
209 210
 							$this->createEntryData_fileRels($table,$uid,$fieldname,'',$deleted,$dat['newValueFiles']);
210
 						break;
211
							break;
211 212
 						case 'flex':
212 213
								// DB references:
213 214
							if (is_array($dat['flexFormRels']['db']))	{
......
227 228
									$this->createEntryData_softreferences($table,$uid,$fieldname,$flexpointer,$deleted,$subList['keys']);
228 229
								}
229 230
							}
230
 						break;
231
							break;
231 232
 					}
232 233

  
233 234
 						// Softreferences in the field:
......
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)
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

  
2006
					// Creating string showing allowed types:
2004
			case 'file_reference':
2005
				$config['uploadfolder'] = '';
2006
				// Fall through
2007
			case 'file':
2008
				// Creating string showing allowed types:
2007 2009
				$tempFT = t3lib_div::trimExplode(',',$allowed,1);
2008 2010
				if (!count($tempFT))	{$info.='*';}
2009 2011
				foreach($tempFT as $ext)	{
......
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'])	{
......
3438 3443
			$clipElements = $this->getClipboardElements($allowed,$mode);
3439 3444
			if (count($clipElements))	{
3440 3445
				$aOnClick = '';
3441
	#			$counter = 0;
3442 3446
				foreach($clipElements as $elValue)	{
3443
					if ($mode=='file')	{
3444
						$itemTitle = 'unescape(\''.rawurlencode(basename($elValue)).'\')';
3445
					} else {	// 'db' mode assumed
3447
					if ($mode=='db') {
3446 3448
						list($itemTable,$itemUid) = explode('|', $elValue);
3447 3449
						$itemTitle = $GLOBALS['LANG']->JScharCode(t3lib_BEfunc::getRecordTitle($itemTable, t3lib_BEfunc::getRecordWSOL($itemTable,$itemUid)));
3448 3450
						$elValue = $itemTable.'_'.$itemUid;
3451
					} else {
3452
						// 'file', 'file_reference' and 'folder' mode
3453
						$itemTitle = 'unescape(\''.rawurlencode(basename($elValue)).'\')';
3449 3454
					}
3450 3455
					$aOnClick.= 'setFormValueFromBrowseWin(\''.$fName.'\',unescape(\''.rawurlencode(str_replace('%20',' ',$elValue)).'\'),'.$itemTitle.');';
3451 3456

  
3452
	#				$counter++;
3453
	#				if ($params['maxitems'] && $counter >= $params['maxitems'])	{	break;	}	// Makes sure that no more than the max items are inserted... for convenience.
3454 3457
				}
3455 3458
				$aOnClick.= 'return false;';
3456 3459
				$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))).' />'.
3460
						'<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 3461
						'</a>';
3459 3462
			}
3460 3463
			$rOnClick = $rOnClickInline.'setFormValueManipulate(\''.$fName.'\',\'Remove\'); return false';
......
3506 3509

  
3507 3510
		if (is_object($this->clipObj))	{
3508 3511
			switch($mode)	{
3512
				case 'file_reference':
3509 3513
				case 'file':
3510 3514
					$elFromTable = $this->clipObj->elFromTable('_FILE');
3511 3515
					$allowedExts = t3lib_div::trimExplode(',', $allowed, 1);
......
5780 5784
	 * @return 	string		HTML formatted output
5781 5785
	 */
5782 5786
	function previewFieldValue($value, $config)	{
5783
		if ($config['config']['type']==='group' && $config['config']['internal_type'] === 'file')	{
5787
		if ($config['config']['type']==='group' &&
5788
				($config['config']['internal_type'] === 'file' ||
5789
				 $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
						$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;
......
3147 3210
	 */
3148 3211
	function copyRecord_procFilesRefs($conf, $uid, $value)	{
3149 3212

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

  
3153 3216
				// Get an array with files as values:
3154
			if ($conf['MM'])	{
3217
			if ($conf['MM']) {
3155 3218
				$theFileValues = array();
3156 3219

  
3157 3220
				$dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
......
3168 3231
			}
3169 3232

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

  
3175 3238
			foreach($theFileValues as $file)	{
3176 3239
				if (trim($file))	{
3177
					$realFile = $dest.'/'.trim($file);
3240
					$realFile = str_replace('//', '/', $dest.'/'.trim($file));
3178 3241
					if (@is_file($realFile))	{
3179 3242
						$newValue[] = $realFile;
3180 3243
					}
......
6473 6536
		if ($TCA[$table]['columns'])	{
6474 6537
			reset($TCA[$table]['columns']);
6475 6538
			while (list($field,$configArr)=each($TCA[$table]['columns']))	{
6476
				if ($configArr['config']['type']=='group' && $configArr['config']['internal_type']=='file')	{
6539
				if ($configArr['config']['type']=='group' &&
6540
					($configArr['config']['internal_type']=='file' ||
6541
					 $configArr['config']['internal_type']=='file_reference'))	{
6477 6542
					$listArr[]=$field;
6478 6543
				}
6479 6544
			}
......
6642 6707
		global $TCA;
6643 6708
		t3lib_div::loadTCA($table);
6644 6709
		$uploadFolder = $TCA[$table]['columns'][$field]['config']['uploadfolder'];
6645
		if ($uploadFolder && trim($filelist))	{
6710
		if ($uploadFolder && trim($filelist) && $TCA[$table]['columns'][$field]['config']['internal_type'] == 'file') {
6646 6711
			$uploadPath = $this->destPathFromUploadFolder($uploadFolder);
6647 6712
			$fileArray = explode(',',$filelist);
6648 6713
			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);
......
3329 3333
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/impexp/class.tx_impexp.php'])	{
3330 3334
	include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/impexp/class.tx_impexp.php']);
3331 3335
}
3332
?>
3336
?>
(7-7/15)