Exemplo n.º 1
0
 public function onFileAction(MOXMAN_Vfs_FileActionEventArgs $args)
 {
     $logger = MOXMAN::getLogger();
     if ($logger) {
         if ($args->getTargetFile()) {
             // Log copy/move operations these have a target file
             $logger->debug("Action: " . $args->getAction(), "Path: " . $args->getFile()->getPath(), "TargetPath: " . $args->getTargetFile()->getPath());
         } else {
             // Log single file operations
             $logger->debug("Action: " . $args->getAction(), "Path: " . $args->getFile()->getPath());
         }
     }
 }
Exemplo n.º 2
0
 /**
  * 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 = $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);
     }
 }
Exemplo n.º 3
0
 public function onBeforeFileAction(MOXMAN_Vfs_FileActionEventArgs $args)
 {
     switch ($args->getAction()) {
         case MOXMAN_Vfs_FileActionEventArgs::DELETE:
             $file = $args->getFile();
             $maxSize = $this->parseSize($file->getConfig()->get("quota.max_size", 0));
             if ($maxSize > 0) {
                 $this->currentSize = MOXMAN::getUserStorage()->get("quota.size", 0);
                 $this->currentSize = max(0, $this->currentSize - $file->getSize());
                 if (MOXMAN::getLogger()) {
                     MOXMAN::getLogger()->debug("[quota] Removed: " . $file->getPublicPath() . " (" . $this->formatSize($file->getSize()) . ").");
                 }
             }
             break;
         case MOXMAN_Vfs_FileActionEventArgs::COPY:
         case MOXMAN_Vfs_FileActionEventArgs::ADD:
             if (!isset($args->getData()->thumb)) {
                 $file = $args->getFile();
                 $targetFile = $args->getTargetFile();
                 if (!$file) {
                     return;
                 }
                 $publicPath = $targetFile ? $targetFile->getPublicPath() : $file->getPublicPath();
                 $maxSize = $this->parseSize($file->getConfig()->get("quota.max_size", 0));
                 if ($maxSize === 0) {
                     return;
                 }
                 $fileSize = 0;
                 // Get size of source directory in copy operation
                 if ($args->getAction() == MOXMAN_Vfs_FileActionEventArgs::COPY && $file->isDirectory()) {
                     $fileSize = $this->getDirectorySize($file);
                 } else {
                     if (isset($args->getData()->fileSize)) {
                         $fileSize = $args->getData()->fileSize;
                     }
                 }
                 $this->currentSize = MOXMAN::getUserStorage()->get("quota.size", 0);
                 if ($this->currentSize + $fileSize > $maxSize) {
                     throw new MOXMAN_Exception("Quota exceeded when adding file: " . $publicPath . " (" . $this->formatSize($this->currentSize + $fileSize) . " > " . $this->formatSize($maxSize) . ").");
                 }
                 $this->currentSize += $fileSize;
                 if (MOXMAN::getLogger()) {
                     MOXMAN::getLogger()->debug("[quota] Added: " . $file->getPublicPath() . " (" . $this->formatSize($fileSize) . ").");
                 }
             }
             break;
     }
 }
Exemplo n.º 4
0
 private function log($message)
 {
     $logger = MOXMAN::getLogger();
     if ($logger) {
         MOXMAN::getLogger()->debug($message);
     }
 }
Exemplo n.º 5
0
 /**
  * Logs HTTP client messages to log file with a specific prefix.
  *
  * @param mixed $str String to log.
  */
 public function logHttpClient($str)
 {
     MOXMAN::getLogger()->debug("[s3] " . $str);
 }