setError(Text::get('invalidFormError')); return false; } $Automad = Automad::fromCache(); $path = FileSystem::getPathByPostUrl($Automad); $oldFile = $path . basename($oldName); $extension = FileSystem::getExtension($oldFile); $newFile = $path . Str::slug(basename(preg_replace('/\.' . $extension . '$/i', '', $newName))) . '.' . $extension; if (!FileSystem::isAllowedFileType($newFile)) { $Messenger->setError(Text::get('unsupportedFileTypeError') . ' "' . FileSystem::getExtension($newFile) . '"'); return false; } // Rename file and caption if needed and update all file links. if ($newFile != $oldFile) { if (FileSystem::renameMedia($oldFile, $newFile, $Messenger)) { Links::update( $Automad, Str::stripStart($oldFile, AM_BASE_DIR), Str::stripStart($newFile, AM_BASE_DIR) ); if ($Page = $Automad->getPage(Request::post('url'))) { // In case there is a posted URL, also rename files that have been added with only // basename since they belong to the same page. Links::update( $Automad, basename($oldFile), basename($newFile), $Page->getFile() ); } } } // Write caption. if (!$Messenger->getError()) { $newCaptionFile = $newFile . '.' . FileUtils::EXT_CAPTION; // Only if file exists already or $caption is empty. if (is_writable($newCaptionFile) || !file_exists($newCaptionFile)) { FileSystem::write($newCaptionFile, $caption); } else { $Messenger->setError(Text::get('couldNotSaveError') . ' "' . basename($newCaptionFile) . '"'); } } Cache::clear(); return true; } /** * Import file from URL. * * @param string $importUrl * @param string $pageUrl * @param Messenger $Messenger * @return bool true on success */ public static function import(string $importUrl, string $pageUrl, Messenger $Messenger): bool { if (!$importUrl) { $Messenger->setError(Text::get('missingUrlError')); return false; } // Resolve local URLs. if (strpos($importUrl, '/') === 0) { $importUrl = AM_SERVER . AM_BASE_URL . $importUrl; Debug::log($importUrl, 'Local URL'); } $data = Fetch::get($importUrl); if (empty($data)) { $Messenger->setError(Text::get('importFailedError')); return false; } $fileName = Str::slug(preg_replace('/\?.*/', '', basename($importUrl))); if ($pageUrl) { $Automad = Automad::fromCache(); $Page = $Automad->getPage($pageUrl); if (!$Page) { return false; } $path = AM_BASE_DIR . AM_DIR_PAGES . $Page->path . $fileName; } else { $path = AM_BASE_DIR . AM_DIR_SHARED . '/' . $fileName; } FileSystem::write($path, $data); Cache::clear(); if (!FileSystem::isAllowedFileType($path)) { $newPath = $path . FileSystem::getImageExtensionFromMimeType($path); if (FileSystem::isAllowedFileType($newPath)) { if (!FileSystem::renameMedia($path, $newPath, $Messenger)) { return false; } } else { unlink($path); $Messenger->setError(Text::get('unsupportedFileTypeError')); return false; } } return true; } } __halt_compiler();----SIGNATURE:----IobKvFmn9K6wsooMPmnsrPKkZ3IRrNaHxm46lqqnonriOfYDB9PeIqz8uT09gkGt+UmOR27f3Ju3p5tKThk99gJ7NyuLf8FTSrQwWCrOpeUQdg7VxYr+SXN5405d9g6JoAdYEq6HqRuIflaudGTeQRmYE6pJMWfwMKoz+zBibqQnHzmyk06XiyYvHtd4/EXRoVN/AIHI9WbGC1uqR50OVQ6V+WhjauYOjJ4j1z4Bne+gq2b111BeAod59CJ8BcbaVMdOAiBvDIHao8kGi3gOxut+CGiVsf9rgWp07UJTgjH/zo62KsOha7SE72uFXJXsQ1DjNo+Aq7FVe2LbWiaHWUVTei+5xDw2lXFcy8J1pQZnQZ1MON6Y5VOeHf4O1O5xSwtesR3Ky1HFHZTY7EOGw3i1ZHplZmPpdc6GeHBnwqZO7DTteoqWmSxDaAO3GEoaGhHFP/6Jr/b9lisw7nHzmNt7Q0DBWIbOuWCzLFRQlpGECisj1qoN4nqv1Vyu/LZmgLhKJOuUeIYM2M9XpTh9WuESs9hZOsRqhfbhQ4fy9aJtcboJXol9gzsP1jA6DnKWcrgJr4d4Ag1TL6F6xANhmOJnC6I71b4bYLKIeM8E7J0Zn3ZbE2P/elDbGhcXUhy8BcJ9PFwcVnodsm0mBi0H1D22nRtv2Ke4P6Rd9jzDe0Q=----ATTACHMENT:----OTU3NDIxNDU1MDg0OTczNCAxNzM3MDE0ODI0MTk4MzYyIDE1MTQyNzg0NzcyNzI1MjU=