Feature #16323 » 6039_v5.diff

Administrator Admin, 2008-08-19 12:06

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
			if ($conf['MM'])	{
545
			if ($conf['MM']) {
544 546
				$theFileValues = array();
545 547
				$dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
546 548
				$dbAnalysis->start('', 'files', $conf['MM'], $uid);
......
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;
......
974 977
	 * @param	string		Folder relative to PATH_site
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
	function destPathFromUploadFolder($folder)	{
978
		return PATH_site.$folder;
980
	function destPathFromUploadFolder($folder) {
981
		return $folder ? PATH_site . $folder : substr(PATH_site, 0, -1);
979 982
	}
980 983

  
981 984
	/**
t3lib/class.t3lib_tceforms.php (working copy)
981 981
				$hookObject->getSingleField_beforeRender($table, $field, $row, $PA);
982 982
			}
983 983
		}
984
		
984

  
985 985
		switch($PA['fieldConf']['config']['form_type'])	{
986 986
			case 'input':
987 987
				$item = $this->getSingleField_typeInput($table,$field,$row,$PA);
......
1654 1654

  
1655 1655
			// Get values in an array (and make unique, which is fine because there can be no duplicates anyway):
1656 1656
		$itemArray = array_flip($this->extractValuesOnlyFromValueLabelList($PA['itemFormElValue']));
1657
		
1657

  
1658 1658
		$disabled = '';
1659 1659
		if($this->renderReadonly || $config['readOnly'])  {
1660 1660
			$disabled = ' disabled="disabled"';
......
2045 2045

  
2046 2046
			// Acting according to either "file" or "db" type:
2047 2047
		switch((string)$config['internal_type'])	{
2048
			case 'file':	// If the element is of the internal type "file":
2049

  
2050
					// Creating string showing allowed types:
2048
			case 'file_reference':
2049
				$config['uploadfolder'] = '';
2050
				// Fall through
2051
			case 'file':
2052
				// Creating string showing allowed types:
2051 2053
				$tempFT = t3lib_div::trimExplode(',',$allowed,1);
2052 2054
				if (!count($tempFT))	{$info.='*';}
2053 2055
				foreach($tempFT as $ext)	{
......
2111 2113

  
2112 2114
				if(!$disabled && !(isset($config['disable_controls']) && t3lib_div::inList($config['disable_controls'], 'upload'))) {
2113 2115
						// Adding the upload field:
2114
					if ($this->edit_docModuleUpload)	$item.='<input type="file" name="'.$PA['itemFormElName_file'].'"'.$this->formWidth().' size="60" />';
2116
					if ($this->edit_docModuleUpload && $config['uploadfolder']) {
2117
						$item.='<input type="file" name="'.$PA['itemFormElName_file'].'"'.$this->formWidth().' size="60" />';
2118
					}
2115 2119
				}
2116 2120
			break;
2117 2121
			case 'folder':	// If the element is of the internal type "folder":
......
3430 3434
						}
3431 3435
					}
3432 3436
				break;
3437
				case 'file_reference':
3433 3438
				case 'file':
3434 3439
				case 'folder':
3435 3440
					while(list(,$pp)=each($itemArray))	{
3436 3441
						$pParts = explode('|',$pp);
3437 3442
						$uidList[]=$pUid=$pTitle = $pParts[0];
3438
						$opt[]='<option value="'.htmlspecialchars(rawurldecode($pParts[0])).'">'.htmlspecialchars(rawurldecode($pParts[0])).'</option>';
3443
						$opt[]='<option value="'.htmlspecialchars(rawurldecode($pParts[0])).'">'.htmlspecialchars(basename(rawurldecode($pParts[0]))).'</option>';
3439 3444
					}
3440 3445
				break;
3441 3446
				default:
......
3473 3478
				}
3474 3479
				$aOnClick='setFormValueOpenBrowser(\''.$mode.'\',\''.($fName.'|||'.$allowed.'|'.$aOnClickInline).'\'); return false;';
3475 3480
				$icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
3476
						'<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'))).' />'.
3481
						'<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'))).' />'.
3477 3482
						'</a>';
3478 3483
			}
3479 3484
			if (!$params['dontShowMoveIcons'])	{
......
3498 3503
			$clipElements = $this->getClipboardElements($allowed,$mode);
3499 3504
			if (count($clipElements))	{
3500 3505
				$aOnClick = '';
3501
	#			$counter = 0;
3502 3506
				foreach($clipElements as $elValue)	{
3503
					if ($mode=='file')	{
3504
						$itemTitle = 'unescape(\''.rawurlencode(basename($elValue)).'\')';
3505
					} else {	// 'db' mode assumed
3507
					if ($mode == 'db') {
3506 3508
						list($itemTable,$itemUid) = explode('|', $elValue);
3507 3509
						$itemTitle = $GLOBALS['LANG']->JScharCode(t3lib_BEfunc::getRecordTitle($itemTable, t3lib_BEfunc::getRecordWSOL($itemTable,$itemUid)));
3508 3510
						$elValue = $itemTable.'_'.$itemUid;
3511
					} else {
3512
						// 'file', 'file_reference' and 'folder' mode
3513
						$itemTitle = 'unescape(\''.rawurlencode(basename($elValue)).'\')';
3509 3514
					}
3510 3515
					$aOnClick.= 'setFormValueFromBrowseWin(\''.$fName.'\',unescape(\''.rawurlencode(str_replace('%20',' ',$elValue)).'\'),'.$itemTitle.');';
3511

  
3512
	#				$counter++;
3513
	#				if ($params['maxitems'] && $counter >= $params['maxitems'])	{	break;	}	// Makes sure that no more than the max items are inserted... for convenience.
3514 3516
				}
3515 3517
				$aOnClick.= 'return false;';
3516 3518
				$icons['R'][]='<a href="#" onclick="'.htmlspecialchars($aOnClick).'">'.
3517
						'<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))).' />'.
3519
						'<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))).' />'.
3518 3520
						'</a>';
3519 3521
			}
3520 3522
			$rOnClick = $rOnClickInline.'setFormValueManipulate(\''.$fName.'\',\'Remove\'); return false';
......
3566 3568

  
3567 3569
		if (is_object($this->clipObj))	{
3568 3570
			switch($mode)	{
3571
				case 'file_reference':
3569 3572
				case 'file':
3570 3573
					$elFromTable = $this->clipObj->elFromTable('_FILE');
3571 3574
					$allowedExts = t3lib_div::trimExplode(',', $allowed, 1);
......
5840 5843
	 * @return 	string		HTML formatted output
5841 5844
	 */
5842 5845
	function previewFieldValue($value, $config)	{
5843
		if ($config['config']['type']==='group' && $config['config']['internal_type'] === 'file')	{
5846
		if ($config['config']['type']==='group' &&
5847
				($config['config']['internal_type'] === 'file' ||
5848
				 $config['config']['internal_type'] === 'file_reference')) {
5849
			// Ignore uploadfolder if internal_type is file_reference
5850
			if ($config['config']['internal_type'] === 'file_reference') {
5851
				$config['config']['uploadfolder'] = '';
5852
			}
5853

  
5844 5854
			$show_thumbs = TRUE;
5845 5855
			$table = 'tt_content';
5846 5856

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

  
1583 1584
			// If there is an upload folder defined:
1584
		if ($tcaFieldConf['uploadfolder'])	{
1585
		if ($tcaFieldConf['uploadfolder'] && $tcaFieldConf['internal_type'] == 'file') {
1585 1586
			if (!$this->bypassFileHandling)	{	// If filehandling should NOT be bypassed, do processing:
1586 1587
					// For logging..
1587 1588
				$propArr = $this->getRecordProperties($table,$id);
......
1714 1715
				}
1715 1716
				$valueArray = $dbAnalysis->countItems();
1716 1717
			}
1718
		} else {
1719
			if (count($valueArray)){
1720
				// store path relative to site root (if uploadfolder is not set or internal_type is file_reference)
1721
				foreach($valueArray as &$theFile){
1722
					if (t3lib_div::isFirstPartOfStr($theFile,PATH_site))	{
1723
						$theFile = substr($theFile,strlen(PATH_site));
1724
					}
1725
				}
1726
			}
1717 1727
		}
1718 1728

  
1719 1729
		return $valueArray;
......
3147 3157
	 */
3148 3158
	function copyRecord_procFilesRefs($conf, $uid, $value)	{
3149 3159

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

  
3153 3163
				// Get an array with files as values:
3154
			if ($conf['MM'])	{
3164
			if ($conf['MM']) {
3155 3165
				$theFileValues = array();
3156 3166

  
3157 3167
				$dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
......
3168 3178
			}
3169 3179

  
3170 3180
				// Traverse this array of files:
3171
			$uploadFolder = $conf['uploadfolder'];
3181
			$uploadFolder = $conf['internal_type']=='file' ? $conf['uploadfolder'] : '';
3172 3182
			$dest = $this->destPathFromUploadFolder($uploadFolder);
3173 3183
			$newValue = array();
3174 3184

  
......
6473 6483
		if ($TCA[$table]['columns'])	{
6474 6484
			reset($TCA[$table]['columns']);
6475 6485
			while (list($field,$configArr)=each($TCA[$table]['columns']))	{
6476
				if ($configArr['config']['type']=='group' && $configArr['config']['internal_type']=='file')	{
6477
					$listArr[]=$field;
6486
				if ($configArr['config']['type']=='group' &&
6487
						($configArr['config']['internal_type']=='file' ||
6488
						 $configArr['config']['internal_type']=='file_reference'))	{
6489
					$listArr[] = $field;
6478 6490
				}
6479 6491
			}
6480 6492
		}
......
6642 6654
		global $TCA;
6643 6655
		t3lib_div::loadTCA($table);
6644 6656
		$uploadFolder = $TCA[$table]['columns'][$field]['config']['uploadfolder'];
6645
		if ($uploadFolder && trim($filelist))	{
6657
		if ($uploadFolder && trim($filelist) && $TCA[$table]['columns'][$field]['config']['internal_type'] == 'file') {
6646 6658
			$uploadPath = $this->destPathFromUploadFolder($uploadFolder);
6647 6659
			$fileArray = explode(',',$filelist);
6648 6660
			while (list(,$theFile)=each($fileArray))	{
(6-6/15)