Code Duplication    Length = 44-44 lines in 3 locations

Sources/Class-Package.php 1 location

@@ 1139-1182 (lines=44) @@
1136
	 * @param string $lookup_file The name of a file in the specified path
1137
	 * @return array An array of detected info - username, path from FTP root and whether or not the current path was found
1138
	 */
1139
	public function detect_path($filesystem_path, $lookup_file = null)
1140
	{
1141
		$username = '';
1142
1143
		if (isset($_SERVER['DOCUMENT_ROOT']))
1144
		{
1145
			if (preg_match('~^/home[2]?/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
1146
			{
1147
				$username = $match[1];
1148
1149
				$path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
1150
1151
				if (substr($path, -1) == '/')
1152
					$path = substr($path, 0, -1);
1153
1154
				if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
1155
					$path .= dirname($_SERVER['PHP_SELF']);
1156
			}
1157
			elseif (strpos($filesystem_path, '/var/www/') === 0)
1158
				$path = substr($filesystem_path, 8);
1159
			else
1160
				$path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
1161
		}
1162
		else
1163
			$path = '';
1164
1165
		if (is_resource($this->connection) && $this->list_dir($path) == '')
1166
		{
1167
			$data = $this->list_dir('', true);
1168
1169
			if ($lookup_file === null)
1170
				$lookup_file = $_SERVER['PHP_SELF'];
1171
1172
			$found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
1173
			if ($found_path == false)
1174
				$found_path = dirname($this->locate(basename($lookup_file)));
1175
			if ($found_path != false)
1176
				$path = $found_path;
1177
		}
1178
		elseif (is_resource($this->connection))
1179
			$found_path = true;
1180
1181
		return array($username, $path, isset($found_path));
1182
	}
1183
1184
	/**
1185
	 * Close the ftp connection

other/upgrade.php 1 location

@@ 510-553 (lines=44) @@
507
			return true;
508
		}
509
510
		function detect_path($filesystem_path, $lookup_file = null)
511
		{
512
			$username = '';
513
514
			if (isset($_SERVER['DOCUMENT_ROOT']))
515
			{
516
				if (preg_match('~^/home[2]?/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
517
				{
518
					$username = $match[1];
519
520
					$path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
521
522
					if (substr($path, -1) == '/')
523
						$path = substr($path, 0, -1);
524
525
					if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
526
						$path .= dirname($_SERVER['PHP_SELF']);
527
				}
528
				elseif (substr($filesystem_path, 0, 9) == '/var/www/')
529
					$path = substr($filesystem_path, 8);
530
				else
531
					$path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
532
			}
533
			else
534
				$path = '';
535
536
			if (is_resource($this->connection) && $this->list_dir($path) == '')
537
			{
538
				$data = $this->list_dir('', true);
539
540
				if ($lookup_file === null)
541
					$lookup_file = $_SERVER['PHP_SELF'];
542
543
				$found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
544
				if ($found_path == false)
545
					$found_path = dirname($this->locate(basename($lookup_file)));
546
				if ($found_path != false)
547
					$path = $found_path;
548
			}
549
			elseif (is_resource($this->connection))
550
				$found_path = true;
551
552
			return array($username, $path, isset($found_path));
553
		}
554
555
		function close()
556
		{

other/install.php 1 location

@@ 1947-1990 (lines=44) @@
1944
		return true;
1945
	}
1946
1947
	function detect_path($filesystem_path, $lookup_file = null)
1948
	{
1949
		$username = '';
1950
1951
		if (isset($_SERVER['DOCUMENT_ROOT']))
1952
		{
1953
			if (preg_match('~^/home[2]?/([^/]+?)/public_html~', $_SERVER['DOCUMENT_ROOT'], $match))
1954
			{
1955
				$username = $match[1];
1956
1957
				$path = strtr($_SERVER['DOCUMENT_ROOT'], array('/home/' . $match[1] . '/' => '', '/home2/' . $match[1] . '/' => ''));
1958
1959
				if (substr($path, -1) == '/')
1960
					$path = substr($path, 0, -1);
1961
1962
				if (strlen(dirname($_SERVER['PHP_SELF'])) > 1)
1963
					$path .= dirname($_SERVER['PHP_SELF']);
1964
			}
1965
			elseif (substr($filesystem_path, 0, 9) == '/var/www/')
1966
				$path = substr($filesystem_path, 8);
1967
			else
1968
				$path = strtr(strtr($filesystem_path, array('\\' => '/')), array($_SERVER['DOCUMENT_ROOT'] => ''));
1969
		}
1970
		else
1971
			$path = '';
1972
1973
		if (is_resource($this->connection) && $this->list_dir($path) == '')
1974
		{
1975
			$data = $this->list_dir('', true);
1976
1977
			if ($lookup_file === null)
1978
				$lookup_file = $_SERVER['PHP_SELF'];
1979
1980
			$found_path = dirname($this->locate('*' . basename(dirname($lookup_file)) . '/' . basename($lookup_file), $data));
1981
			if ($found_path == false)
1982
				$found_path = dirname($this->locate(basename($lookup_file)));
1983
			if ($found_path != false)
1984
				$path = $found_path;
1985
		}
1986
		elseif (is_resource($this->connection))
1987
			$found_path = true;
1988
1989
		return array($username, $path, isset($found_path));
1990
	}
1991
1992
	function close()
1993
	{