/** * Executes the command logic with the specified RPC parameters. * * @param Object $params Command parameters sent from client. * @return Object Result object to be passed back to client. */ public function execute($params) { $rootPaths = array(); foreach (MOXMAN::getFileSystemManager()->getFileSystems() as $filesystem) { $rootFile = $filesystem->getRootFile(); if (!$rootFile->isHidden()) { // Get root file meta data $meta = $rootFile->getMetaData(); $meta = $meta->getAll("ui"); // Add show/hide login to meta $meta["standalone"] = MOXMAN::getAuthManager()->hasStandalone(); // Return name, path and optional meta data $rootPaths[] = (object) array("name" => $filesystem->getRootName(), "path" => $rootFile->getPublicPath(), "meta" => $meta, "config" => $this->getPublicConfig($rootFile)); } } return $rootPaths; }
/** * Constructs a new memory file stream. * * @param MOXMAN_Vfs_IFile $file File instance for memory stream. * @param string Stream mode READ or WRITE. */ public function __construct(MOXMAN_Vfs_IFile $file, $mode) { $this->mode = $mode; $this->file = $file; // Get local temp file path $fileSystemManager = MOXMAN::getFileSystemManager(); $this->localTempFilePath = $fileSystemManager->getLocalTempPath($file); // Export to local temp file if ($mode === MOXMAN_Vfs_IFileStream::READ || $mode === MOXMAN_Vfs_IFileStream::APPEND) { $file->exportTo($this->localTempFilePath); } // Open local temp file for r,w or a $this->fp = fopen($this->localTempFilePath, $mode); if (!$this->fp) { throw new MOXMAN_Exception("Could not open file stream for file: " . $file->getPath()); } }
/** * Executes the command logic with the specified RPC parameters. * * @param Object $params Command parameters sent from client. * @return Object Result object to be passed back to client. */ public function execute($params) { $rootPaths = array(); foreach (MOXMAN::getFileSystemManager()->getFileSystems() as $filesystem) { $rootFile = $filesystem->getRootFile(); if (!$rootFile->isHidden()) { // Get root file meta data $meta = $rootFile->getMetaData(); $meta = $meta->getAll("ui"); // Add initial path if it's specified in config $initalPath = $filesystem->getConfig()->get("filesystem.inital_path", ""); if ($initalPath) { $meta["initial_path"] = $initalPath; } // Return name, path and optional meta data $rootPaths[] = (object) array("name" => $filesystem->getRootName(), "path" => $rootFile->getPublicPath(), "meta" => $meta, "config" => $this->getPublicConfig($rootFile)); } } return $rootPaths; }
/** * Executes the command logic with the specified RPC parameters. * * @param Object $params Command parameters sent from client. * @return Object Result object to be passed back to client. */ public function execute($params) { $fromFile = MOXMAN::getFile($params->from); $toFile = MOXMAN::getFile($params->to); $config = $toFile->getConfig(); if ($config->get('general.demo')) { throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE); } if (!$fromFile->exists()) { throw new MOXMAN_Exception("From file doesn't exist: " . $fromFile->getPublicPath(), MOXMAN_Exception::FILE_DOESNT_EXIST); } if (!$toFile->canWrite()) { throw new MOXMAN_Exception("No write access to file: " . $toFile->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS); } $paths = array(); $fileSystemManager = MOXMAN::getFileSystemManager(); $zipArchive = new ZipArchive(); $localTempFilePath = null; $result = array(); if ($fromFile instanceof MOXMAN_Vfs_Local_File) { $res = $zipArchive->open($fromFile->getPath()); } else { $localTempFilePath = $fileSystemManager->getLocalTempPath($fromFile); $fromFile->exportTo($localTempFilePath); $res = $zipArchive->open($localTempFilePath); } if ($res) { for ($i = 0; $i < $zipArchive->numFiles; $i++) { $stat = $zipArchive->statIndex($i); $paths[] = $stat["name"]; } $filter = MOXMAN_Vfs_BasicFileFilter::createFromConfig($config); $fileSystem = $toFile->getFileSystem(); foreach ($paths as $path) { $isFile = !preg_match('/\\/$/', $path); $toPath = MOXMAN_Util_PathUtils::combine($toFile->getPath(), iconv('cp437', 'UTF-8', $path)); $targetFile = MOXMAN::getFile($toPath); if ($filter->accept($targetFile, $isFile) === MOXMAN_Vfs_IFileFilter::ACCEPTED) { if ($isFile) { $content = $zipArchive->getFromName($path); // Fire before file action add event $args = new MOXMAN_Core_FileActionEventArgs("add", $targetFile); $args->getData()->fileSize = strlen($content); MOXMAN::getPluginManager()->get("core")->fire("BeforeFileAction", $args); $targetFile = $args->getFile(); $targetFile = $this->mkdirs($targetFile, true); $stream = $targetFile->open(MOXMAN_Vfs_IFileStream::WRITE); $stream->write($content); $stream->close(); //echo "Create file: ". $targetFile->getPublicPath() ."\n"; $this->fireFileAction(MOXMAN_Core_FileActionEventArgs::ADD, $targetFile); } else { $targetFile = $this->mkdirs($targetFile); } $result[] = $this->fileToJson($targetFile); } } $zipArchive->close(); if ($localTempFilePath) { $fileSystemManager->removeLocalTempFile($fromFile); } } return $result; }
public function init() { MOXMAN::getFileSystemManager()->registerFileSystem("s3", "MOXMAN_AmazonS3_FileSystem"); }
/** * Removes formats from an image. * * @param MOXMAN_Vfs_IFile $file File to generate images for. */ public function removeFormat(MOXMAN_Vfs_IFile $file) { if (!$file->exists()) { return; } $config = $file->getConfig(); $format = $config->get("autoformat.rules", ""); if ($config->get("autoformat.delete_format_images", true) === false) { return; } // @codeCoverageIgnoreStart if (!$format) { return; } // @codeCoverageIgnoreEnd $chunks = preg_split('/,/', $format, 0, PREG_SPLIT_NO_EMPTY); $imageInfo = MOXMAN_Media_MediaInfo::getInfo($file); $width = $imageInfo["width"]; $height = $imageInfo["height"]; foreach ($chunks as $chunk) { $parts = explode('=', $chunk); $fileName = preg_replace('/\\..+$/', '', $file->getName()); $extension = preg_replace('/^.+\\./', '', $file->getName()); $targetWidth = $newWidth = $width; $targetHeight = $newHeight = $height; $items = explode('|', $parts[0]); foreach ($items as $item) { switch ($item) { case "gif": case "jpg": case "jpeg": case "png": $extension = $item; break; default: $matches = array(); if (preg_match('/\\s?([0-9|\\*]+)\\s?x([0-9|\\*]+)\\s?/', $item, $matches)) { $targetWidth = $matches[1]; $targetHeight = $matches[2]; if ($targetWidth == '*') { // Width is omitted $targetWidth = floor($width / ($height / $targetHeight)); } if ($targetHeight == '*') { // Height is omitted $targetHeight = floor($height / ($width / $targetWidth)); } } } } // Scale it if ($targetWidth != $width || $targetHeight != $height) { $scale = min($targetWidth / $width, $targetHeight / $height); $newWidth = $scale > 1 ? $width : floor($width * $scale); $newHeight = $scale > 1 ? $height : floor($height * $scale); } // Build output path $outPath = $parts[1]; $outPath = str_replace("%f", $fileName, $outPath); $outPath = str_replace("%e", $extension, $outPath); $outPath = str_replace("%ow", "" . $width, $outPath); $outPath = str_replace("%oh", "" . $height, $outPath); $outPath = str_replace("%tw", "" . $targetWidth, $outPath); $outPath = str_replace("%th", "" . $targetHeight, $outPath); $outPath = str_replace("%w", "" . $newWidth, $outPath); $outPath = str_replace("%h", "" . $newHeight, $outPath); $outFile = MOXMAN::getFileSystemManager()->getFile($file->getParent(), $outPath); if ($outFile->exists()) { $outFile->delete(); } } }
/** * Executes the save command logic with the specified RPC parameters. * * @param Object $params Command parameters sent from client. * @return Object Result object to be passed back to client. */ private function save($params) { $file = MOXMAN::getFile($params->path); $config = $file->getConfig(); if ($config->get("general.demo")) { throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE); } if (!$file->canWrite()) { throw new MOXMAN_Exception("No write access to file: " . $file->getPublicPath(), MOXMAN_Exception::NO_WRITE_ACCESS); } $filter = MOXMAN_Vfs_CombinedFileFilter::createFromConfig($config, "edit"); if ($filter->accept($file) !== MOXMAN_Vfs_CombinedFileFilter::ACCEPTED) { throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME); } // Import temp file as target file if (isset($params->tempname)) { $tempFilePath = MOXMAN_Util_PathUtils::combine(MOXMAN_Util_PathUtils::getTempDir(), $params->tempname); $file->importFrom($tempFilePath); } MOXMAN::getFileSystemManager()->removeLocalTempFile($file); $this->fireFileAction(MOXMAN_Core_FileActionEventArgs::ADD, $file); return parent::fileToJson($file, true); }
public function init() { MOXMAN::getFileSystemManager()->registerFileSystem("ftp", "MOXMAN_Ftp_FileSystem"); }
public function init() { MOXMAN::getFileSystemManager()->registerFileSystem("favorite", "MOXMAN_Favorites_FileSystem"); MOXMAN::getFileSystemManager()->addRoot("Favorites=favorite:///"); MOXMAN::getPluginManager()->get("core")->bind("FileAction", "onFileAction", $this); }
public function init() { MOXMAN::getFileSystemManager()->registerFileSystem("history", "MOXMAN_History_FileSystem"); MOXMAN::getFileSystemManager()->addRoot("History=history:///"); MOXMAN::getPluginManager()->get("core")->bind("FileAction", "onFileAction", $this); }
public function init() { MOXMAN::getFileSystemManager()->registerFileSystem("uploaded", "MOXMAN_Uploaded_FileSystem"); MOXMAN::getFileSystemManager()->addRoot("Uploaded=uploaded:///"); MOXMAN::getPluginManager()->get("core")->bind("FileAction", "onFileAction", $this); }
/** * Sends the specified file to the client by streaming it. * * @param MOXMAN_Vfs_IFile $file File to stream to client. * @param Boolean $download State if the file should be downloaded or not by the client. */ public function sendFile(MOXMAN_Vfs_IFile $file, $download = false) { // Check if the file is a local file is so use the faster method if ($file instanceof MOXMAN_Vfs_Local_File) { $this->sendLocalFile($file->getInternalPath(), $download); return; } // Check if the remote file system has a local temp path $localTempPath = MOXMAN::getFileSystemManager()->getLocalTempPath($file); if (file_exists($localTempPath)) { $this->sendLocalFile($localTempPath, $download); return; } if ($download) { $this->disableCache(); $this->setHeader("Content-type", "application/octet-stream"); $this->setHeader("Content-Disposition", "attachment; filename=\"" . $file->getName() . "\""); } else { $this->setHeader("Content-type", MOXMAN_Util_Mime::get($file->getName())); } // Non local file system then read and stream $stream = $file->open(MOXMAN_Vfs_IFileStream::READ); if ($stream) { // Read chunk by chunk and stream it while (($buff = $stream->read()) !== "") { $this->sendContent($buff); } $stream->close(); } }
public function init() { MOXMAN::getFileSystemManager()->registerFileSystem("azure", "MOXMAN_Azure_FileSystem"); }