static function userFileLocation($file, $defaultLocation = '.') { if (substr($file, 0, 1) != '/') { $file = $_ENV['projectFolder'] . $defaultLocation . '/' . $file; } //since file base ensured (not purely relative), can run through absolutePath function return Tool::absolutePath($file); }
static function getAbsoluteUrl($url, $relativeTo = null) { list($uPath, $query) = explode('?', $url); preg_match('@(^.*?://.*?)(/.*$|$)@', $uPath, $match); if (!$match) { //url is relative, use relativeTo as base list($rPath) = explode('?', $relativeTo); preg_match('@(^.*?://.*?)(/.*$|$)@', $rPath, $match); $pathParts = explode('/', $match[2]); if ($uPath) { if ($uPath[0] == '/') { //relative to base of site $base = $pathParts[0]; $pathParts = explode('/', $base . $uPath); } else { //relative to directory, so clear page part. ie url = "view.php?m=bob" array_pop($pathParts); $pathParts = implode('/', $pathParts) . '/' . $uPath; $pathParts = explode('/', $pathParts); } } } else { $pathParts = explode('/', $match[2]); } $path = Tool::absolutePath($pathParts); $url = $match[1] . $path; if ($query) { $url .= '?' . $query; } return $url; }
static function getAbsolute($basePath, $relativePath, $relativity = null) { if ($basePath[0] != '/') { $basePath = '/' . str_replace('_', '/', $basePath) . '/'; } if (!$relativity) { if (preg_match('@(^_+)(.*)@', $relativePath, $match)) { $relativePath = $match[2]; $relativity = $match[1]; } } $relativePath = $basePath . str_replace('_', '../', $relativity) . $relativePath; //ensure path has ending "/" if (substr($relativePath, -1) != '/') { $relativePath .= '/'; } $absoluteTable = str_replace('/', '_', substr(Tool::absolutePath($relativePath), 1, -1)); return $absoluteTable; }
function checkPath($fileName, $path, $options, &$excludePaths, $move = 0) { if (isset($options['stopMove']) && $options['stopMove'] <= $move) { return; } $path = Tool::absolutePath($path); if (!$path) { return; } elseif ($excludePaths[$path]) { return; } elseif (isset($options['stopPaths']) && in_array($path, $options['stopPaths'])) { return; } elseif (isset($options['stopFolders']) && in_array(dirname($path), $options['stopFolders'])) { return; } $excludePaths[$path] = true; $dirs = array(); if (is_dir($path)) { foreach (scandir($path) as $v) { if ($v != '.' && $v != '..') { if (is_dir($path . $v)) { $dirs[] = $path . $v . '/'; } else { if ($v == $fileName) { $filePath = $path . $fileName; if (!$excludePaths[$filePath]) { $excludePaths[$filePath] = true; return $filePath; } } } } } } if ($options['moveDown']) { foreach ($dirs as $path) { if ($path = $this->checkPath($fileName, $path, $options, $excludePaths, $move + 1)) { return $path; } } } elseif ($options['moveUp']) { if ($path = $this->checkPath($fileName, $path . '../', $options, $excludePaths, $move + 1)) { return $path; } } }