protected function resolveMedia($source, &$internalPath, &$internalSrc, &$isSourceExternal, $baseDir = "", $htmlDir = "")
{
if ($this->isFinalized) {
return false;
}
$mediaPath = null;
$tmpFile = null;
if (preg_match('#^(http|ftp)s?://#i', $source) == 1) {
$urlInfo = parse_url($source);
if (strpos($urlInfo['path'], $baseDir . "/") !== false) {
$internalSrc = substr($urlInfo['path'], strpos($urlInfo['path'], $baseDir . "/") + strlen($baseDir) + 1);
}
$internalPath = $urlInfo["scheme"] . "/" . $urlInfo["host"] . "/" . pathinfo($urlInfo["path"], PATHINFO_DIRNAME);
$isSourceExternal = true;
$mediaPath = FileHelper::getFileContents($source, true);
$tmpFile = $mediaPath;
} else {
if (strpos($source, "/") === 0) {
$internalPath = pathinfo($source, PATHINFO_DIRNAME);
$mediaPath = $source;
if (!file_exists($mediaPath)) {
$mediaPath = $this->docRoot . $mediaPath;
}
} else {
$internalPath = $htmlDir . "/" . preg_replace('#^[/\\.]+#', '', pathinfo($source, PATHINFO_DIRNAME));
$mediaPath = $baseDir . "/" . $source;
if (!file_exists($mediaPath)) {
$mediaPath = $this->docRoot . $mediaPath;
}
}
}
if ($mediaPath !== false) {
$mime = MimeHelper::getMimeTypeFromExtension(pathinfo($source, PATHINFO_EXTENSION));
$internalPath = RelativePath::getRelativePath("media/" . $internalPath . "/" . $internalSrc);
if (!array_key_exists($internalPath, $this->fileList) && $this->addLargeFile($internalPath, "m_" . $internalSrc, $mediaPath, $mime)) {
$this->fileList[$internalPath] = $source;
}
if (isset($tmpFile)) {
unlink($tmpFile);
}
return true;
}
return false;
}