/**
  * Sends the specified file with the correct mime type back to the browser.
  * This method gets called from the client side using the stream file.
  *
  * @param MOXMAN_Http_Context $httpContext Context instance to pass to use for the handler.
  */
 public function processRequest(MOXMAN_Http_Context $httpContext)
 {
     $request = $httpContext->getRequest();
     $response = $httpContext->getResponse();
     try {
         $file = MOXMAN::getFile($request->get("path"));
     } catch (Exception $e) {
         $response->setStatus("500", "Could not resolve path: " . $request->get("path"));
         if (MOXMAN::getLogger()) {
             MOXMAN::getLogger()->debug("Could not resolve path: " . $request->get("path"));
         }
         return;
     }
     // Create thumbnail
     if ($request->get("thumb")) {
         try {
             $file = $this->plugin->createThumbnail($file);
         } catch (Exception $e) {
             $response->setStatus("500", "Could not generate thumbnail.");
             $response->sendContent("Could not generate thumbnail.");
             return;
         }
     }
     // Fire before stream event
     $args = new MOXMAN_Vfs_StreamEventArgs($httpContext, $file);
     $this->plugin->fire("BeforeStream", $args);
     $file = $args->getFile();
     // Stream temp file if it exists
     if ($tempName = MOXMAN_Util_Sanitize::fileName($request->get("tempname"))) {
         $ext = MOXMAN_Util_PathUtils::getExtension($file->getName());
         $tempName = "mcic_" . md5(session_id() . $file->getName()) . "." . $ext;
         $tempFilePath = MOXMAN_Util_PathUtils::combine(MOXMAN_Util_PathUtils::getTempDir(), $tempName);
         if (file_exists($tempFilePath)) {
             $response->sendLocalFile($tempFilePath);
             return;
         }
     }
     $url = $file->getUrl();
     if ($url && !$request->get("stream", false)) {
         $response->redirect($url);
     } else {
         // Force 48h cache time
         $offset = 48 * 60 * 60;
         $response->setHeader("Cache-Control", "max-age=" . $offset);
         $response->setHeader("Date", gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
         $response->setHeader("Expires", gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");
         $response->setHeader("Pragma", "public");
         $response->sendFile($file);
     }
 }
 /**
  * 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();
     $size = 0;
     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(), MOXMAN_Util_Sanitize::fileName($params->tempname));
         $size = filesize($tempFilePath);
         $file->importFrom($tempFilePath);
     }
     $args = $this->fireBeforeFileAction("add", $file, $size);
     $file = $args->getFile();
     MOXMAN::getFileSystemManager()->removeLocalTempFile($file);
     $this->fireFileAction(MOXMAN_Vfs_FileActionEventArgs::ADD, $file);
     return parent::fileToJson($file, true);
 }