Example #1
0
 public function switchAction($action, $httpVars, $filesVars)
 {
     if (!isset($this->actions[$action])) {
         return false;
     }
     $repository = ConfService::getRepository();
     if (!$repository->detectStreamWrapper(true)) {
         return false;
     }
     if (!isset($this->pluginConf)) {
         $this->pluginConf = array("GENERATE_THUMBNAIL" => false);
     }
     $streamData = $repository->streamData;
     $this->streamData = $streamData;
     $destStreamURL = $streamData["protocol"] . "://" . $repository->getId();
     if ($action == "preview_data_proxy") {
         $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
         if (!file_exists($destStreamURL . $file)) {
             header("Content-Type: " . AJXP_Utils::getImageMimeType(basename($file)) . "; name=\"" . basename($file) . "\"");
             header("Content-Length: 0");
             return;
         }
         if (isset($httpVars["get_thumb"]) && $this->getFilteredOption("GENERATE_THUMBNAIL", $repository->getId())) {
             $dimension = 200;
             if (isset($httpVars["dimension"]) && is_numeric($httpVars["dimension"])) {
                 $dimension = $httpVars["dimension"];
             }
             $this->currentDimension = $dimension;
             $cacheItem = AJXP_Cache::getItem("diaporama_" . $dimension, $destStreamURL . $file, array($this, "generateThumbnail"));
             $data = $cacheItem->getData();
             $cId = $cacheItem->getId();
             header("Content-Type: " . AJXP_Utils::getImageMimeType(basename($cId)) . "; name=\"" . basename($cId) . "\"");
             header("Content-Length: " . strlen($data));
             header('Cache-Control: public');
             header("Pragma:");
             header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 10000) . " GMT");
             header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5 * 24 * 3600) . " GMT");
             print $data;
         } else {
             //$filesize = filesize($destStreamURL.$file);
             $node = new AJXP_Node($destStreamURL . $file);
             $fp = fopen($destStreamURL . $file, "r");
             $stat = fstat($fp);
             $filesize = $stat["size"];
             header("Content-Type: " . AJXP_Utils::getImageMimeType(basename($file)) . "; name=\"" . basename($file) . "\"");
             header("Content-Length: " . $filesize);
             header('Cache-Control: public');
             header("Pragma:");
             header("Last-Modified: " . gmdate("D, d M Y H:i:s", time() - 10000) . " GMT");
             header("Expires: " . gmdate("D, d M Y H:i:s", time() + 5 * 24 * 3600) . " GMT");
             $class = $streamData["classname"];
             $stream = fopen("php://output", "a");
             call_user_func(array($streamData["classname"], "copyFileInStream"), $destStreamURL . $file, $stream);
             fflush($stream);
             fclose($stream);
             AJXP_Controller::applyHook("node.read", array($node));
         }
     }
 }
 public function switchActions($actionName, $httpVars, $fileVars)
 {
     //$urlBase = $this->accessDriver
     $repository = ConfService::getRepository();
     if (!$repository->detectStreamWrapper(true)) {
         return false;
     }
     if (!isset($this->pluginConf)) {
         $this->pluginConf = array("GENERATE_THUMBNAIL" => false);
     }
     $streamData = $repository->streamData;
     $this->streamData = $streamData;
     $destStreamURL = $streamData["protocol"] . "://" . $repository->getId();
     switch ($actionName) {
         case "filehasher_signature":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             if (!file_exists($destStreamURL . $file)) {
                 break;
             }
             $cacheItem = AJXP_Cache::getItem("signatures", $destStreamURL . $file, array($this, "generateSignature"));
             $data = $cacheItem->getData();
             header("Content-Type:application/octet-stream");
             header("Content-Length", strlen($data));
             echo $data;
             break;
         case "filehasher_delta":
         case "filehasher_patch":
             // HANDLE UPLOAD DATA
             if (!isset($fileVars) && !is_array($fileVars["userfile_0"])) {
                 throw new Exception("These action should find uploaded data");
             }
             $uploadedData = tempnam(AJXP_Utils::getAjxpTmpDir(), $actionName . "-sig");
             move_uploaded_file($fileVars["userfile_0"]["tmp_name"], $uploadedData);
             $fileUrl = $destStreamURL . AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $file = call_user_func(array($this->streamData["classname"], "getRealFSReference"), $fileUrl, true);
             if ($actionName == "filehasher_delta") {
                 $signatureFile = $uploadedData;
                 $deltaFile = tempnam(AJXP_Utils::getAjxpTmpDir(), $actionName . "-delta");
                 rsync_generate_delta($signatureFile, $file, $deltaFile);
                 header("Content-Type:application/octet-stream");
                 header("Content-Length:" . filesize($deltaFile));
                 readfile($deltaFile);
                 unlink($signatureFile);
                 unlink($deltaFile);
             } else {
                 $patched = $file . ".rdiff_patched";
                 $deltaFile = $uploadedData;
                 rsync_patch_file($file, $deltaFile, $patched);
                 rename($patched, $file);
                 header("Content-Type:text/plain");
                 unlink($deltaFile);
                 echo md5_file($file);
             }
             break;
     }
 }
Example #3
0
 public function switchActions($actionName, $httpVars, $fileVars)
 {
     //$urlBase = $this->accessDriver
     $repository = $this->accessDriver->repository;
     if (!$repository->detectStreamWrapper(true)) {
         return false;
     }
     $selection = new UserSelection($repository, $httpVars);
     switch ($actionName) {
         case "filehasher_signature":
             $file = $selection->getUniqueNode();
             if (!file_exists($file->getUrl())) {
                 break;
             }
             $cacheItem = AJXP_Cache::getItem("signatures", $file->getUrl(), array($this, "generateSignature"));
             $data = $cacheItem->getData();
             header("Content-Type:application/octet-stream");
             header("Content-Length", strlen($data));
             echo $data;
             break;
         case "filehasher_delta":
         case "filehasher_patch":
             // HANDLE UPLOAD DATA
             $this->logDebug("Received signature file, should compute delta now");
             if (!isset($fileVars) && !is_array($fileVars["userfile_0"])) {
                 throw new Exception("These action should find uploaded data");
             }
             $signature_delta_file = $fileVars["userfile_0"]["tmp_name"];
             $fileUrl = $selection->getUniqueNode()->getUrl();
             $file = AJXP_MetaStreamWrapper::getRealFSReference($fileUrl, true);
             if ($actionName == "filehasher_delta") {
                 $deltaFile = tempnam(AJXP_Utils::getAjxpTmpDir(), $actionName . "-delta");
                 $this->logDebug("Received signature file, should compute delta now");
                 rsync_generate_delta($signature_delta_file, $file, $deltaFile);
                 $this->logDebug("Computed delta file, size is " . filesize($deltaFile));
                 header("Content-Type:application/octet-stream");
                 header("Content-Length:" . filesize($deltaFile));
                 readfile($deltaFile);
                 unlink($deltaFile);
             } else {
                 $patched = $file . ".rdiff_patched";
                 rsync_patch_file($file, $signature_delta_file, $patched);
                 rename($patched, $file);
                 $node = $selection->getUniqueNode();
                 AJXP_Controller::applyHook("node.change", array($node, $node, false));
                 header("Content-Type:text/plain");
                 echo md5_file($file);
             }
             break;
         case "stat_hash":
             clearstatcache();
             header("Content-type:application/json");
             if ($selection->isUnique()) {
                 $node = $selection->getUniqueNode();
                 $stat = @stat($node->getUrl());
                 if (!$stat || !is_readable($node->getUrl())) {
                     print '{}';
                 } else {
                     if (is_file($node->getUrl())) {
                         if (isset($_SERVER["HTTP_RANGE"])) {
                             $fullSize = floatval($stat['size']);
                             $ranges = explode('=', $_SERVER["HTTP_RANGE"]);
                             $offsets = explode('-', $ranges[1]);
                             $offset = floatval($offsets[0]);
                             $length = floatval($offsets[1]) - $offset;
                             if (!$length) {
                                 $length = $fullSize - $offset;
                             }
                             if ($length + $offset > $fullSize || $length < 0) {
                                 $length = $fullSize - $offset;
                             }
                             $hash = $this->getPartialHash($node, $offset, $length);
                         } else {
                             $hash = $this->getFileHash($selection->getUniqueNode());
                         }
                     } else {
                         $hash = 'directory';
                     }
                     $stat[13] = $stat["hash"] = $hash;
                     print json_encode($stat);
                 }
             } else {
                 $files = $selection->getFiles();
                 print '{';
                 foreach ($files as $index => $path) {
                     $node = new AJXP_Node($selection->currentBaseUrl() . $path);
                     $stat = @stat($selection->currentBaseUrl() . $path);
                     if (!$stat || !is_readable($node->getUrl())) {
                         $stat = '{}';
                     } else {
                         if (!is_dir($node->getUrl())) {
                             $hash = $this->getFileHash($node);
                         } else {
                             $hash = 'directory';
                         }
                         $stat[13] = $stat["hash"] = $hash;
                         $stat = json_encode($stat);
                     }
                     print json_encode(SystemTextEncoding::toUTF8($path)) . ':' . $stat . ($index < count($files) - 1 ? "," : "");
                 }
                 print '}';
             }
             break;
             break;
     }
 }
 /**
  *
  * @param AJXP_Node $oldNode
  * @param AJXP_Node $newNode
  * @param Boolean $copy
  */
 public function deleteImagickCache($oldNode, $newNode = null, $copy = false)
 {
     if ($oldNode == null) {
         return;
     }
     $oldFile = $oldNode->getUrl();
     // Should remove imagick cache file
     if (!$this->handleMime($oldFile)) {
         return;
     }
     if ($newNode == null || $copy == false) {
         AJXP_Cache::clearItem("imagick_thumb", $oldFile);
         $cache = AJXP_Cache::getItem("imagick_full", $oldFile, false);
         $prefix = str_replace("." . pathinfo($cache->getId(), PATHINFO_EXTENSION), "", $cache->getId());
         $files = $this->listExtractedJpg($oldFile, $prefix);
         foreach ($files as $file) {
             if (is_file((defined('AJXP_SHARED_CACHE_DIR') ? AJXP_SHARED_CACHE_DIR : AJXP_CACHE_DIR) . "/" . $file["file"])) {
                 unlink(AJXP_CACHE_DIR . "/" . $file["file"]);
             }
         }
     }
 }
Example #5
0
 /**
  *
  * Enter description here ...
  * @param string $file url
  * @param boolean $cacheRemoteContent
  * @return Mail_mimeDecode
  */
 public function getStructureDecoder($file, $cacheRemoteContent = false)
 {
     require_once "Mail/mimeDecode.php";
     if ($cacheRemoteContent) {
         $cache = AJXP_Cache::getItem("eml_remote", $file, null, array("EmlParser", "computeCacheId"));
         $content = $cache->getData();
     } else {
         $content = file_get_contents($file);
     }
     $decoder = new Mail_mimeDecode($content);
     header('Content-Type: text/xml; charset=UTF-8');
     header('Cache-Control: no-cache');
     return $decoder;
 }
 /**
  *
  * @param AJXP_Node $oldNode
  * @param AJXP_Node $newNode
  * @param Boolean $copy
  */
 public function deleteImagickCache($oldNode, $newNode = null, $copy = false)
 {
     if ($oldNode == null) {
         return;
     }
     $oldFile = $oldNode->getUrl();
     // Should remove imagick cache file
     if (!$this->handleMime($oldFile)) {
         return;
     }
     if ($newNode == null || $copy == false) {
         // Main Thumb
         AJXP_Cache::clearItem("imagick_thumb", $oldFile);
         // Unoconv small PDF
         $thumbCache = AJXP_Cache::getItem("imagick_thumb", $oldFile, false);
         $unoFile = pathinfo($thumbCache->getId(), PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . pathinfo($thumbCache->getId(), PATHINFO_FILENAME) . "_unoconv.pdf";
         if (file_exists($unoFile)) {
             unlink($unoFile);
         }
         $cache = AJXP_Cache::getItem("imagick_full", $oldFile, false);
         // Unoconv full pdf
         $unoFile = pathinfo($cache->getId(), PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . pathinfo($cache->getId(), PATHINFO_FILENAME) . "_unoconv.pdf";
         if (file_exists($unoFile)) {
             unlink($unoFile);
         }
         $prefix = str_replace("." . pathinfo($cache->getId(), PATHINFO_EXTENSION), "", $cache->getId());
         // Additional Extracted pages
         $files = $this->listExtractedJpg($oldFile, $prefix);
         $cacheDir = (defined('AJXP_SHARED_CACHE_DIR') ? AJXP_SHARED_CACHE_DIR : AJXP_CACHE_DIR) . "/imagick_full";
         foreach ($files as $file) {
             if (is_file($cacheDir . "/" . $file["file"])) {
                 unlink($cacheDir . "/" . $file["file"]);
             }
         }
     }
 }
Example #7
0
 public function switchActions($actionName, $httpVars, $fileVars)
 {
     //$urlBase = $this->accessDriver
     $repository = ConfService::getRepository();
     if (!$repository->detectStreamWrapper(true)) {
         return false;
     }
     $streamData = $repository->streamData;
     $this->streamData = $streamData;
     $destStreamURL = $streamData["protocol"] . "://" . $repository->getId();
     switch ($actionName) {
         case "filehasher_signature":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             if (!file_exists($destStreamURL . $file)) {
                 break;
             }
             $cacheItem = AJXP_Cache::getItem("signatures", $destStreamURL . $file, array($this, "generateSignature"));
             $data = $cacheItem->getData();
             header("Content-Type:application/octet-stream");
             header("Content-Length", strlen($data));
             echo $data;
             break;
         case "filehasher_delta":
         case "filehasher_patch":
             // HANDLE UPLOAD DATA
             $this->logDebug("Received signature file, should compute delta now");
             if (!isset($fileVars) && !is_array($fileVars["userfile_0"])) {
                 throw new Exception("These action should find uploaded data");
             }
             $uploadedData = tempnam(AJXP_Utils::getAjxpTmpDir(), $actionName . "-sig");
             move_uploaded_file($fileVars["userfile_0"]["tmp_name"], $uploadedData);
             $fileUrl = $destStreamURL . AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $file = call_user_func(array($this->streamData["classname"], "getRealFSReference"), $fileUrl, true);
             if ($actionName == "filehasher_delta") {
                 $signatureFile = $uploadedData;
                 $deltaFile = tempnam(AJXP_Utils::getAjxpTmpDir(), $actionName . "-delta");
                 $this->logDebug("Received signature file, should compute delta now");
                 rsync_generate_delta($signatureFile, $file, $deltaFile);
                 $this->logDebug("Computed delta file, size is " . filesize($deltaFile));
                 header("Content-Type:application/octet-stream");
                 header("Content-Length:" . filesize($deltaFile));
                 readfile($deltaFile);
                 unlink($signatureFile);
                 unlink($deltaFile);
             } else {
                 $patched = $file . ".rdiff_patched";
                 $deltaFile = $uploadedData;
                 rsync_patch_file($file, $deltaFile, $patched);
                 rename($patched, $file);
                 unlink($deltaFile);
                 header("Content-Type:text/plain");
                 echo md5_file($file);
             }
             break;
         case "stat_hash":
             $selection = new UserSelection();
             $selection->initFromArray($httpVars);
             clearstatcache();
             header("Content-type:application/json");
             if ($selection->isUnique()) {
                 $node = $selection->getUniqueNode($this->accessDriver);
                 $stat = @stat($node->getUrl());
                 if (!$stat) {
                     print '{}';
                 } else {
                     if ($node->isLeaf()) {
                         $hash = $this->getFileHash($selection->getUniqueNode($this->accessDriver));
                     } else {
                         $hash = 'directory';
                     }
                     $stat[13] = $stat["hash"] = $hash;
                     print json_encode($stat);
                 }
             } else {
                 $files = $selection->getFiles();
                 print '{';
                 foreach ($files as $index => $path) {
                     $node = new AJXP_Node($destStreamURL . $path);
                     $stat = @stat($destStreamURL . $path);
                     if (!$stat) {
                         $stat = '{}';
                     } else {
                         if (!is_dir($node->getUrl())) {
                             $hash = $this->getFileHash($node);
                         } else {
                             $hash = 'directory';
                         }
                         $stat[13] = $stat["hash"] = $hash;
                         $stat = json_encode($stat);
                     }
                     print json_encode($path) . ':' . $stat . ($index < count($files) - 1 ? "," : "");
                 }
                 print '}';
             }
             break;
             break;
     }
 }