Bug #16419 » class.em_index.060804.org.diff

Administrator Admin, 2006-08-04 13:49

View differences:

class.em_index.php 4 Aug 2006 11:31:32 -0000
28 28
/**
29 29
 * Module: Extension manager
30 30
 *
31
 * $Id: class.em_index.php,v 1.1 2006/08/01 12:04:25 pruss Exp $
31
 * $Id: class.em_index.php,v 1.2 2006/08/03 11:33:04 pruss Exp $
32 32
 *
33 33
 * @author	Kasper Skaarhoj <kasperYYYY@typo3.com>
34 34
 * @author	Karsten Dambekalns <karsten@typo3.org>
......
322 322
	var $listRemote;					// If set, connects to remote repository
323 323
	var $lookUpStr;						// Search string when listing local extensions
324 324

  
325

  
325
//prs+ 01.08.2006
326
	var $excludeHidden=false;			// if set, hidden or system files will not be transfered
327
	var $pathAttribs=array();			// holds the attribs for a path to reduce exec calls
328
//prs- 01.08.2006
329
//prs+ 03.08.2006
330
	var $disallowedToTransfer=null;		// will hold pathes and file extension not allowed to transfer to TER
331
	var $noFurtherCheck=false;			
332
//prs- 03.08.2006
326 333

  
327 334

  
328 335
	/*********************************
......
2581 2588
					</td>
2582 2589
				</tr>
2583 2590
				<tr class="bgColor4">
2591
					<td>Exclude hidden files:</td>
2592
					<td nowrap="nowrap">
2593
						<input type="checkbox" name="em[upload][exclude]" value="1" checked="checked" />
2594
					</td>
2595
				</tr>
2596
				<tr class="bgColor4">
2584 2597
					<td>&nbsp;</td>
2585 2598
					<td><input type="submit" name="submit" value="Upload extension" />
2586 2599
					</td>
......
3868 3881
		$lines .= str_repeat(chr(9),$level-1).')'.($level-1==0 ? '':','.chr(10));
3869 3882
		return $lines;
3870 3883
	}
3871

  
3884
	/** 
3885
	 * Checks if there are some preset in localconf.php or TSCONFIG
3886
	 * 
3887
	 */
3888
	function _getArray($str='',$delim=',',$onlyNonEmptyValues=true,$isUnique=true)
3889
	{
3890
		$ar=t3lib_div::trimExplode($delim,$str,$onlyNonEmptyValues);
3891
		if (is_array($ar) && $isUnique)
3892
		{
3893
			$ar=array_unique($ar);
3894
		}
3895
		return $ar;
3896
	}
3897
	function _setDisallowedArray()
3898
	{
3899
		$dA=null;
3900
		$check=array('excludePath','excludeExt');
3901
		if (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['uploadTer']))
3902
		{
3903
			foreach($check as $key)
3904
			{
3905
				if (isset($GLOBALS['TYPO3_CONF_VARS']['EXT']['uploadTer'][$key]))
3906
				{
3907
					$ar=$this->_getArray($GLOBALS['TYPO3_CONF_VARS']['EXT']['uploadTer'][$key]);
3908
					if (count($ar)>0)
3909
					{
3910
						if ($dA==null)
3911
						{
3912
							$dA=array();
3913
						}
3914
						$dA[$key]=$ar;
3915
					}
3916
				}
3917
			}
3918
		}
3919
		$userConf=$GLOBALS['BE_USER']->getTSConfig('EXT');
3920
		if ($userConf['properties']!=null && isset($userConf['properties']['uploadTer.']))
3921
		{
3922
			//if userConf parameter is set it will ALLWAYS replace the global setting!
3923
			foreach($check as $key)
3924
			{
3925
				if (isset($userConf['properties']['uploadTer.'][$key]))
3926
				{
3927
					$ar=$this->_getArray($userConf['properties']['uploadTer.'][$key]);
3928
					if (count($ar)>0)
3929
					{
3930
						if ($dA==null)
3931
						{
3932
							$dA=array();
3933
						}
3934
						$dA[$key]=$ar;
3935
					} 
3936
					elseif (isset($dA[$key]))
3937
					{
3938
						unset($dA[$key]);
3939
					}
3940
				}
3941
			}
3942
		}
3943
		return $dA;
3944
	}
3945
	function _excludePath($fKey,$cName='',$ar=array())
3946
	{
3947
		$exclude=false;
3948
		if(!isset($this->pathAttribs[$fKey]))
3949
		{
3950
			foreach($ar as $path)
3951
			{
3952
				$pos=strpos($cName,'/'.$path.'/');
3953
				if ($pos===false)
3954
				{
3955
					continue;
3956
				} else {
3957
					$exclude=true;
3958
					break;
3959
				}
3960
			}
3961
			$this->pathAttribs[$fKey]=$exclude;
3962
		}
3963
		return $this->pathAttribs[$fKey];
3964
	}
3965
	function _unsetPathAttribs()
3966
	{
3967
		foreach($this->pathAttribs as $key=>$value)
3968
		{
3969
			if (!$value)
3970
			{
3971
				unset($this->pathAttribs[$key]);
3972
			}
3973
		}
3974
	}
3975
	function _excludeExt($cName='',$ar=array())
3976
	{
3977
		$fI=pathinfo($cName);
3978
		return in_array($fI['extension'],$ar);
3979
	}
3980
		
3981
	function _isDisallowedFileOrPath($fKey='',$fName='',$extPath='')
3982
	{
3983
		$isDisallowed=false;
3984
		if ($this->noFurtherCheck)
3985
		{
3986
			return $isDisallowed;
3987
		}
3988
		if ($this->disallowedToTransfer==null)
3989
		{
3990
			$this->disallowedToTransfer=$this->_setDisallowedArray();
3991
			if (!is_array($this->disallowedToTransfer))
3992
			{
3993
				$this->noFurtherCheck=true;
3994
			}	
3995
		}
3996
		if ($this->noFurtherCheck)
3997
		{
3998
			return $isDisallowed;
3999
		}
4000
		$cName=$this->_getCName($fName,$extPath);
4001
		/*
4002
		 * We have to reset all NONE setted, i.e. value=false
4003
		 * otherwise it won't get checked
4004
		 */
4005
		$this->_unsetPathAttribs(); 
4006
		foreach ($this->disallowedToTransfer as $key=>$array)
4007
		{
4008
			switch($key)
4009
			{
4010
				case 'excludePath':
4011
					$isDisallowed = $isDisallowed || $this->_excludePath($fKey,$cName,$array);
4012
					break;
4013
				case 'excludeExt':
4014
					$isDisallowed = $isDisallowed || $this->_excludeExt($cName,$array);
4015
					break;
4016
				default:
4017
					//not defined items so far
4018
					break;
4019
			}
4020
			if ($isDisallowed)
4021
			{
4022
				break;
4023
			}
4024
		}
4025
		return $isDisallowed;
4026
	}
4027
	function _isHiddenWin($fName='',$extPath='')
4028
	{
4029
		/*
4030
		 * On windows S and H attribute is set on index 3 or 4
4031
		 * 
4032
		 */
4033
		$str=substr(exec('attrib '.$fName),0,6);
4034
		$isHidden=strpos($str,'S') || strpos($str,'H');
4035
		$isHidden=($isHidden===false)?false:true;
4036
		$key=$this->_getKey($fName);
4037
		if (!isset($this->pathAttribs[$key]))
4038
		{
4039
			$d=substr((exec('attrib '.dirname($fName))),0,6);
4040
			$this->pathAttribs[$key]=(strpos($d,'S') || strpos($d,'H'));
4041
			$this->pathAttribs[$key]=($this->pathAttribs[$key]===false)?false:true;
4042
		}
4043
		if (!($isHidden && $this->pathAttribs[$key]))
4044
		{
4045
			$isHidden=$this->_isDisallowedFileOrPath($key,$fName,$extPath);
4046
		}
4047
		return ($isHidden || $this->pathAttribs[$key]);
4048
	}
4049
	function _getKey($fName)
4050
	{
4051
		return md5(dirname($fName));
4052
	}
4053
	function _getCName($fName='',$extPath='')
4054
	{
4055
		return substr($fName,strlen($extPath)-1);
4056
	}
4057
	function _isHiddenNix($fName='',$extPath='')
4058
	{
4059
		$cName=$this->_getCName($fName,$extPath);
4060
		$pos=strpos($cName,'/.');
4061
		$isHidden=($pos===false)?false:true;
4062
		if (!$isHidden)
4063
		{
4064
			$key=$this->_getKey($fName);
4065
			$isHidden=$this->_isDisallowedFileOrPath($key,$fName,$extPath);
4066
		}
4067
		return $isHidden;
4068
	}
4069
	/**
4070
	 * Removes hidden files from file array
4071
	 * 
4072
	 * @param array	Array of files
4073
	 * @return array Array of files not hidden or system
4074
	 */
4075
	function removeHiddenFiles($fileArr=array(),$extPath='')
4076
	{
4077
		$fA=array();
4078
		$func=(TYPO3_OS=='WIN')?'_isHiddenWin':'_isHiddenNix';
4079
		foreach($fileArr as $key=>$fName)
4080
		{
4081
			if (! $this->$func($fName,$extPath))
4082
			{
4083
				$fA[$key]=$fName;
4084
			}
4085
		}
4086
		return $fA;
4087
	}
3872 4088
	/**
3873 4089
	 * Make upload array out of extension
3874 4090
	 *
......
3885 4101
			$fileArr = array();
3886 4102
			$fileArr = t3lib_div::getAllFilesAndFoldersInPath($fileArr,$extPath);
3887 4103

  
4104
//prs+ 01.08.2006
4105
			if ($this->excludeHidden)
4106
			{
4107
				//remove hidden or system files from fileArr;
4108
				$fileArr=$this->removeHiddenFiles($fileArr,$extPath);
4109
			}
4110
//prs- 01.08.2006
4111

  
3888 4112
			// Calculate the total size of those files:
3889 4113
			$totalSize = 0;
3890 4114
			foreach($fileArr as $file)	{
......
3946 4170
	 * @see makeUploadArray()
3947 4171
	 */
3948 4172
	function getSerializedLocalLang($file,$content)	{
4173
		global $LOCAL_LANG;
3949 4174
		$returnParts = explode('$LOCAL_LANG',$content,2);
3950 4175

  
3951 4176
		include($file);
......
4818 5043
	 */
4819 5044
	function uploadExtensionToTER($em)	{
4820 5045
		$msg = '';
5046
		//prs+ 01.08.2006
5047
		$this->excludeHidden=isset($em['upload']['exclude'])&& $em['upload']['exclude'];
5048
		//prs- 01.08.2006
4821 5049
		$response = $this->terConnection->uploadToTER($em);
4822 5050

  
4823 5051
		if(!is_array($response)) return $response;
(3-3/9)