Changeset View
Changeset View
Standalone View
Standalone View
branches/5.2.x/core/units/helpers/file_helper.php
Show First 20 Lines • Show All 412 Lines • ▼ Show 20 Line(s) | |||||
// escape replacement patterns, like "\<number>" | // escape replacement patterns, like "\<number>" | ||||
$full_path = preg_replace('/(\\\[\d]+)/', '\\\\\1', FULL_PATH); | $full_path = preg_replace('/(\\\[\d]+)/', '\\\\\1', FULL_PATH); | ||||
$path = preg_replace('/^' . preg_quote($base_url, '/') . '(.*)/', $full_path . '\\1', $url, 1); | $path = preg_replace('/^' . preg_quote($base_url, '/') . '(.*)/', $full_path . '\\1', $url, 1); | ||||
return str_replace('/', DIRECTORY_SEPARATOR, kUtil::unescape($path, kUtil::ESCAPE_URL)); | return str_replace('/', DIRECTORY_SEPARATOR, kUtil::unescape($path, kUtil::ESCAPE_URL)); | ||||
} | } | ||||
/** | /** | ||||
* Makes given paths DocumentRoot agnostic. | |||||
* | |||||
* @param array $paths List of file paths. | |||||
* | |||||
* @return array | |||||
*/ | |||||
public function makeRelative(array $paths) | |||||
{ | |||||
foreach ( $paths as $index => $path ) { | |||||
$replaced_count = 0; | |||||
$relative_path = preg_replace('/^' . preg_quote(FULL_PATH, '/') . '/', '', $path, 1, $replaced_count); | |||||
if ( $replaced_count === 1 ) { | |||||
$paths[$index] = $relative_path; | |||||
} | |||||
} | |||||
return $paths; | |||||
} | |||||
/** | |||||
* Ensures, that new file will not overwrite any of previously created files with same name | * Ensures, that new file will not overwrite any of previously created files with same name | ||||
* | * | ||||
* @param string $path | * @param string $path | ||||
* @param string $name | * @param string $name | ||||
* @param Array $forbidden_names | * @param Array $forbidden_names | ||||
* @return string | * @return string | ||||
*/ | */ | ||||
public function ensureUniqueFilename($path, $name, $forbidden_names = Array ()) | public function ensureUniqueFilename($path, $name, $forbidden_names = Array ()) | ||||
Show All 35 Lines |