/**
  * 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)
 {
     $file = MOXMAN::getFile($params->path);
     $config = $file->getConfig();
     $resolution = $params->resolution;
     if ($config->get('general.demo')) {
         throw new MOXMAN_Exception("This action is restricted in demo mode.", MOXMAN_Exception::DEMO_MODE);
     }
     $content = $this->getUrlContent($params->url, $config);
     // Fire before file action add event
     $args = $this->fireBeforeFileAction("add", $file, strlen($content));
     $file = $args->getFile();
     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, "upload");
     if (!$filter->accept($file, true)) {
         throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
     }
     if ($resolution == "rename") {
         $file = MOXMAN_Util_FileUtils::uniqueFile($file);
     } else {
         if ($resolution == "overwrite") {
             MOXMAN::getPluginManager()->get("core")->deleteFile($file);
         } else {
             throw new MOXMAN_Exception("To file already exist: " . $file->getPublicPath(), MOXMAN_Exception::FILE_EXISTS);
         }
     }
     $stream = $file->open(MOXMAN_Vfs_IFileStream::WRITE);
     $stream->write($content);
     $stream->close();
     $args = new MOXMAN_Vfs_FileActionEventArgs("add", $file);
     MOXMAN::getPluginManager()->get("core")->fire("FileAction", $args);
     return parent::fileToJson($file, true);
 }
 /**
  * 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)
 {
     $file = MOXMAN::getFile($params->path);
     $url = parse_url($params->url);
     $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->exists()) {
         throw new MOXMAN_Exception("To file already exist: " . $file->getPublicPath(), MOXMAN_Exception::FILE_EXISTS);
     }
     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, "upload");
     if (!$filter->accept($file, true)) {
         throw new MOXMAN_Exception("Invalid file name for: " . $file->getPublicPath(), MOXMAN_Exception::INVALID_FILE_NAME);
     }
     $port = "";
     if (isset($url["port"])) {
         $port = ":" . $url["port"];
     }
     $query = "";
     if (isset($url["query"])) {
         $query = "?" . $url["query"];
     }
     $path = $url["path"] . $query;
     $host = $url["scheme"] . "://" . $url["host"] . $port;
     $httpClient = new MOXMAN_Http_HttpClient($host);
     $request = $httpClient->createRequest($path);
     $response = $request->send();
     // Handle redirects
     $location = $response->getHeader("location");
     if ($location) {
         $httpClient->close();
         $httpClient = new MOXMAN_Http_HttpClient($location);
         $request = $httpClient->createRequest($location);
         $response = $request->send();
     }
     // Read file into ram
     // TODO: This should not happen if we know the file size
     $content = "";
     while (($chunk = $response->read()) != "") {
         $content .= $chunk;
     }
     $httpClient->close();
     // Fire before file action add event
     $args = $this->fireBeforeFileAction("add", $file, strlen($content));
     $file = $args->getFile();
     $stream = $file->open(MOXMAN_Vfs_IFileStream::WRITE);
     $stream->write($content);
     $stream->close();
     $args = new MOXMAN_Vfs_FileActionEventArgs("add", $file);
     MOXMAN::getPluginManager()->get("core")->fire("FileAction", $args);
     return parent::fileToJson($file, true);
 }
 /**
  * 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)
 {
     $from = $params->from;
     $to = $params->to;
     // Copy multiple files
     if (is_array($from)) {
         $result = array();
         foreach ($from as $path) {
             $fromFile = MOXMAN::getFile($path);
             $toFile = MOXMAN::getFile($to, $fromFile->getName());
             $toFile = $this->copyFile($fromFile, $toFile);
             $result[] = parent::fileToJson($toFile);
         }
         return $result;
     }
     // Copy single file
     $fromFile = MOXMAN::getFile($from);
     $toFile = MOXMAN::getFile($params->to);
     $this->copyFile($fromFile, $toFile);
     return parent::fileToJson($toFile);
 }
示例#4
0
 /**
  * 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)
 {
     $from = $params->from;
     $to = $params->to;
     $resolution = isset($params->resolution) ? $params->resolution : "";
     // Move multiple files
     if (is_array($from)) {
         $result = array();
         foreach ($from as $path) {
             $fromFile = MOXMAN::getFile($path);
             $toFile = MOXMAN::getFile($to, $fromFile->getName());
             $this->moveFile($fromFile, $toFile, $resolution);
             $result[] = parent::fileToJson($toFile, true);
         }
         return $result;
     }
     // Move single file
     $fromFile = MOXMAN::getFile($from);
     $toFile = MOXMAN::getFile($params->to);
     $toFile = $this->moveFile($fromFile, $toFile, $resolution);
     return parent::fileToJson($toFile, true);
 }
 /**
  * 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)) {
         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_Vfs_FileActionEventArgs::ADD, $file);
     return parent::fileToJson($file, true);
 }