CC-3636: Media Folder: dir path in cc_music_dir should be in consistent format
- DateHelper.php is moved from model to common folder - created OsPath.php file which contains normpath() - normpath() is used instead of realpath()
This commit is contained in:
parent
a6f44226b9
commit
ffc17ba705
8 changed files with 86 additions and 39 deletions
45
airtime_mvc/application/common/OsPath.php
Normal file
45
airtime_mvc/application/common/OsPath.php
Normal file
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
class Application_Common_OsPath{
|
||||
// this function is from http://stackoverflow.com/questions/2670299/is-there-a-php-equivalent-function-to-the-python-os-path-normpath
|
||||
public static function normpath($path)
|
||||
{
|
||||
if (empty($path))
|
||||
return '.';
|
||||
|
||||
if (strpos($path, '/') === 0)
|
||||
$initial_slashes = true;
|
||||
else
|
||||
$initial_slashes = false;
|
||||
if (
|
||||
($initial_slashes) &&
|
||||
(strpos($path, '//') === 0) &&
|
||||
(strpos($path, '///') === false)
|
||||
)
|
||||
$initial_slashes = 2;
|
||||
$initial_slashes = (int) $initial_slashes;
|
||||
|
||||
$comps = explode('/', $path);
|
||||
$new_comps = array();
|
||||
foreach ($comps as $comp)
|
||||
{
|
||||
if (in_array($comp, array('', '.')))
|
||||
continue;
|
||||
if (
|
||||
($comp != '..') ||
|
||||
(!$initial_slashes && !$new_comps) ||
|
||||
($new_comps && (end($new_comps) == '..'))
|
||||
)
|
||||
array_push($new_comps, $comp);
|
||||
elseif ($new_comps)
|
||||
array_pop($new_comps);
|
||||
}
|
||||
$comps = $new_comps;
|
||||
$path = implode('/', $comps);
|
||||
if ($initial_slashes)
|
||||
$path = str_repeat('/', $initial_slashes) . $path;
|
||||
if ($path)
|
||||
return $path;
|
||||
else
|
||||
return '.';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue