/** * Test the subdirectory check in the filesystem class */ public function testSubdirectoryCheck() { $cx = Cx::instanciate(); $this->assertTrue(MediaSourceManager::isSubdirectory($cx->getWebsitePath() . '/images', 'files/')); $this->assertFalse(MediaSourceManager::isSubdirectory($cx->getWebsitePath() . '/media', 'files/')); $this->assertFalse(MediaSourceManager::isSubdirectory($cx->getWebsitePath() . '/images', 'media5/')); }
/** * Returns the smallest thumbnail for a file. * * @param $filename * * @return string Thumbnail Name */ public function getThumbnailFilename($filename) { // legacy fallback for older calls. if (preg_match('/\\.thumb$/', $filename)) { return $filename; } if (!file_exists($filename) && !file_exists($this->cx->getWebsitePath() . '/' . ltrim($filename, '/'))) { return $filename . '.thumb'; } $webpath = pathinfo($filename, PATHINFO_DIRNAME); if (!file_exists($filename)) { $filename = $this->cx->getWebsitePath() . $filename; } if (file_exists($filename) && MediaSourceManager::isSubdirectory($this->cx->getWebsitePath(), $filename)) { $this->createThumbnailFromPath($filename); } $extension = pathinfo($filename, PATHINFO_EXTENSION); $filename = pathinfo($filename, PATHINFO_FILENAME); $this->getThumbnails(); $thumbnailType = $this->thumbnails[0]; $thumbnail = preg_replace('/\\.' . lcfirst($extension) . '$/', $thumbnailType['value'] . '.' . lcfirst($extension), $webpath . '/' . $filename . '.' . $extension); return $thumbnail; }
public function moveFile(File $file, $destination) { global $_ARRAYLANG; if (!empty($destination) || !\FWValidator::is_file_ending_harmless($destination)) { if (is_dir($this->getFullPath($file) . $file->getFullName())) { $fileName = $this->getFullPath($file) . $file->getFullName(); $destinationFileName = $this->getFullPath($file) . $destination; } else { $fileName = $this->getFullPath($file) . $file->getFullName(); $destinationFileName = $this->getFullPath($file) . $destination . '.' . $file->getExtension(); } if ($fileName == $destinationFileName) { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_SUCCESSFULLY_RENAMED'], $file->getName()); } $destinationFolder = realpath(pathinfo($this->getFullPath($file) . $destination, PATHINFO_DIRNAME)); if (!MediaSourceManager::isSubdirectory($this->rootPath, $destinationFolder)) { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_RENAMED'], $file->getName()); } $this->removeThumbnails($file); if (!\Cx\Lib\FileSystem\FileSystem::move($fileName, $destinationFileName, false)) { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_RENAMED'], $file->getName()); } return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_SUCCESSFULLY_RENAMED'], $file->getName()); } else { return sprintf($_ARRAYLANG['TXT_FILEBROWSER_FILE_UNSUCCESSFULLY_RENAMED'], $file->getName()); } }