コード例 #1
0
 protected function replaceVars($tplString, $mess, $rich = true)
 {
     $tplString = SystemTextEncoding::fromUTF8($tplString);
     $repoId = $this->getNode()->getRepositoryId();
     $repoObject = ConfService::getRepositoryById($repoId);
     if ($repoObject != null) {
         $repoLabel = $repoObject->getDisplay();
     } else {
         $repoLabel = "Repository";
     }
     $uLabel = "";
     if (strstr($tplString, "AJXP_USER") !== false) {
         $uLabel = $this->getAuthorLabel();
     }
     $em = $rich ? "<em>" : "";
     $me = $rich ? "</em>" : "";
     $replaces = array("AJXP_NODE_PATH" => $em . $this->getRoot($this->getNode()->getPath()) . $me, "AJXP_NODE_LABEL" => $em . $this->getNode()->getLabel() . $me, "AJXP_PARENT_PATH" => $em . $this->getRoot(dirname($this->getNode()->getPath())) . $me, "AJXP_PARENT_LABEL" => $em . $this->getRoot(basename(dirname($this->getNode()->getPath()))) . $me, "AJXP_REPOSITORY_ID" => $em . $repoId . $me, "AJXP_REPOSITORY_LABEL" => $em . $repoLabel . $me, "AJXP_LINK" => $this->getMainLink(), "AJXP_USER" => $uLabel, "AJXP_DATE" => SystemTextEncoding::fromUTF8(AJXP_Utils::relativeDate($this->getDate(), $mess)));
     if ($replaces["AJXP_NODE_LABEL"] == $em . $me || $replaces["AJXP_NODE_LABEL"] == $em . "/" . $me) {
         $replaces["AJXP_NODE_LABEL"] = $replaces["AJXP_REPOSITORY_LABEL"];
     }
     if ($replaces["AJXP_PARENT_LABEL"] == $em . $me || $replaces["AJXP_PARENT_LABEL"] == $em . "/" . $me) {
         $replaces["AJXP_PARENT_LABEL"] = $replaces["AJXP_REPOSITORY_LABEL"];
     }
     if ((strstr($tplString, "AJXP_TARGET_FOLDER") !== false || strstr($tplString, "AJXP_SOURCE_FOLDER")) && isset($this->secondaryNode)) {
         $p = $this->secondaryNode->getPath();
         if ($this->secondaryNode->isLeaf()) {
             $p = $this->getRoot(dirname($p));
         }
         $replaces["AJXP_TARGET_FOLDER"] = $replaces["AJXP_SOURCE_FOLDER"] = $em . $p . $me;
     }
     if ((strstr($tplString, "AJXP_TARGET_LABEL") !== false || strstr($tplString, "AJXP_SOURCE_LABEL") !== false) && isset($this->secondaryNode)) {
         $replaces["AJXP_TARGET_LABEL"] = $replaces["AJXP_SOURCE_LABEL"] = $em . $this->secondaryNode->getLabel() . $me;
     }
     return str_replace(array_keys($replaces), array_values($replaces), $tplString);
 }
コード例 #2
0
 protected function replaceVars($tplString, $mess, $rich = true)
 {
     $tplString = SystemTextEncoding::fromUTF8($tplString);
     $repoId = $this->getNode()->getRepositoryId();
     if (ConfService::getRepositoryById($repoId) != null) {
         $repoLabel = ConfService::getRepositoryById($repoId)->getDisplay();
     } else {
         $repoLabel = "Repository";
     }
     $uLabel = "";
     if (array_key_exists($this->getAuthor(), self::$usersCaches)) {
         if (self::$usersCaches[$this->getAuthor()] != 'AJXP_USER_DONT_EXISTS') {
             $uLabel = self::$usersCaches[$this->getAuthor()];
         }
     } else {
         if (strstr($tplString, "AJXP_USER") !== false) {
             if (AuthService::userExists($this->getAuthor())) {
                 $obj = ConfService::getConfStorageImpl()->createUserObject($this->getAuthor());
                 $uLabel = $obj->personalRole->filterParameterValue("core.conf", "USER_DISPLAY_NAME", AJXP_REPO_SCOPE_ALL, "");
                 self::$usersCaches[$this->getAuthor()] = $uLabel;
             } else {
                 self::$usersCaches[$this->getAuthor()] = 'AJXP_USER_DONT_EXISTS';
             }
         }
     }
     if (empty($uLabel)) {
         $uLabel = $this->getAuthor();
     }
     $em = $rich ? "<em>" : "";
     $me = $rich ? "</em>" : "";
     $replaces = array("AJXP_NODE_PATH" => $em . $this->getRoot($this->getNode()->getPath()) . $me, "AJXP_NODE_LABEL" => $em . $this->getNode()->getLabel() . $me, "AJXP_PARENT_PATH" => $em . $this->getRoot(dirname($this->getNode()->getPath())) . $me, "AJXP_PARENT_LABEL" => $em . $this->getRoot(basename(dirname($this->getNode()->getPath()))) . $me, "AJXP_REPOSITORY_ID" => $em . $repoId . $me, "AJXP_REPOSITORY_LABEL" => $em . $repoLabel . $me, "AJXP_LINK" => $this->getMainLink(), "AJXP_USER" => $uLabel, "AJXP_DATE" => SystemTextEncoding::fromUTF8(AJXP_Utils::relativeDate($this->getDate(), $mess)));
     if ($replaces["AJXP_NODE_LABEL"] == $em . $me) {
         $replaces["AJXP_NODE_LABEL"] = $em . "[" . $replaces["AJXP_REPOSITORY_LABEL"] . "]" . $me;
     }
     if ($replaces["AJXP_PARENT_LABEL"] == $em . $me) {
         $replaces["AJXP_PARENT_LABEL"] = $em . "[" . $replaces["AJXP_REPOSITORY_LABEL"] . "]" . $me;
     }
     if ((strstr($tplString, "AJXP_TARGET_FOLDER") !== false || strstr($tplString, "AJXP_SOURCE_FOLDER")) && isset($this->secondaryNode)) {
         $p = $this->secondaryNode->getPath();
         if ($this->secondaryNode->isLeaf()) {
             $p = $this->getRoot(dirname($p));
         }
         $replaces["AJXP_TARGET_FOLDER"] = $replaces["AJXP_SOURCE_FOLDER"] = $em . $p . $me;
     }
     if ((strstr($tplString, "AJXP_TARGET_LABEL") !== false || strstr($tplString, "AJXP_SOURCE_LABEL") !== false) && isset($this->secondaryNode)) {
         $replaces["AJXP_TARGET_LABEL"] = $replaces["AJXP_SOURCE_LABEL"] = $em . $this->secondaryNode->getLabel() . $me;
     }
     return str_replace(array_keys($replaces), array_values($replaces), $tplString);
 }
コード例 #3
0
 /**
  * @param AJXP_Node $oldNode
  * @param AJXP_Node $newNode
  * Main function, it is called by the hook.
  */
 public function scanFile($oldNode = null, $newNode = null)
 {
     if ($oldNode != null || $newNode == null) {
         return;
     }
     // ADD THOSE TWO LINES
     $newNode->loadNodeInfo();
     if (!$newNode->isLeaf()) {
         return;
     }
     $this->callSet($newNode);
     //initializes attributes
     // This block scans or doesn't scan the file. This is based on plugin parameters
     if ($this->file_size < $this->scan_max_size) {
         if ($this->scan_all == true) {
             if ($this->inList() == true) {
                 if ($this->getFilteredOption("TRACE") == false) {
                     return;
                 }
                 $this->scanLater();
                 return;
             } else {
                 $this->scanNow();
                 return;
             }
         } else {
             if ($this->inList() == true) {
                 $this->scanNow();
                 return;
             } else {
                 if ($this->getFilteredOption("TRACE") == false) {
                     return;
                 }
                 $this->scanLater();
                 return;
             }
         }
     } else {
         $this->scanLater();
         return;
     }
 }
コード例 #4
0
ファイル: class.ShareStore.php プロジェクト: ad-m/pydio-core
 /**
  * @param String $type
  * @param String $element
  * @param AJXP_Node $oldNode
  * @param AJXP_Node $newNode
  * @return bool
  */
 public function moveShareIfPossible($type, $element, $oldNode, $newNode)
 {
     if (!$this->sqlSupported) {
         return false;
     }
     $this->confStorage->simpleStoreGet("share", $element, "serial", $data);
     if ($oldNode->isLeaf() && $type == "minisite" && is_array($data)) {
         $repo = ConfService::getRepositoryById($data["REPOSITORY"]);
         $cFilter = $repo->getContentFilter();
         if (isset($cFilter)) {
             $cFilter->movePath($oldNode->getPath(), $newNode->getPath());
         }
     }
 }
コード例 #5
0
 /**
  * @param AJXP_Node $ajxpNode
  */
 public function extractMeta(&$ajxpNode)
 {
     $currentFile = $ajxpNode->getUrl();
     if (!$ajxpNode->isLeaf() || preg_match("/\\.zip\\//", $currentFile)) {
         return;
     }
     if (!preg_match("/\\.jpg\$|\\.jpeg\$|\\.tif\$|\\.tiff\$/i", $currentFile)) {
         return;
     }
     $definitions = $this->getMetaDefinition();
     if (!count($definitions)) {
         return;
     }
     if (!function_exists("exif_read_data")) {
         return;
     }
     //if(!exif_imagetype($currentFile)) return ;
     $realFile = $ajxpNode->getRealFile();
     $exif = @exif_read_data($realFile, 0, TRUE);
     $iptc = $this->extractIPTC($realFile);
     if ($exif === false) {
         return;
     }
     $additionalMeta = array();
     foreach ($definitions as $def => $label) {
         list($exifSection, $exifName) = explode("-", $def);
         if ($exifSection == "COMPUTED_GPS" && !isset($exif["COMPUTED_GPS"])) {
             $exif['COMPUTED_GPS'] = $this->convertGPSData($exif);
         }
         if (isset($exif[$exifSection]) && isset($exif[$exifSection][$exifName])) {
             $additionalMeta[$def] = $exif[$exifSection][$exifName];
         }
         if ($exifSection == "IPTC" && isset($iptc[$exifName])) {
             $additionalMeta[$def] = $iptc[$exifName];
         }
     }
     $ajxpNode->mergeMetadata($additionalMeta);
 }
コード例 #6
0
 /**
  * @param AJXP_Node $ajxpNode
  * @param array $httpVars
  * @param bool $update
  * @return Repository[]|ShareLink[]
  * @throws Exception
  */
 public function shareNode($ajxpNode, $httpVars, &$update)
 {
     $hiddenUserEntries = array();
     $originalHttpVars = $httpVars;
     $ocsStore = new Pydio\OCS\Model\SQLStore();
     $ocsClient = new Pydio\OCS\Client\OCSClient();
     $userSelection = new UserSelection($this->repository, $httpVars);
     $mess = ConfService::getMessages();
     /**
      * @var ShareLink[] $shareObjects
      */
     $shareObjects = array();
     // PUBLIC LINK
     if (isset($httpVars["enable_public_link"])) {
         if (!$this->getAuthorization($ajxpNode->isLeaf() ? "file" : "folder", "minisite")) {
             throw new Exception($mess["share_center." . ($ajxpNode->isLeaf() ? "225" : "226")]);
         }
         $this->shareObjectFromParameters($httpVars, $hiddenUserEntries, $shareObjects, "public");
     } else {
         if (isset($httpVars["disable_public_link"])) {
             $this->getShareStore()->deleteShare("minisite", $httpVars["disable_public_link"], true);
         }
     }
     if (isset($httpVars["ocs_data"])) {
         $ocsData = json_decode($httpVars["ocs_data"], true);
         $removeLinks = $ocsData["REMOVE"];
         foreach ($removeLinks as $linkHash) {
             // Delete Link, delete invitation(s)
             $this->getShareStore()->deleteShare("minisite", $linkHash, true);
             $invitations = $ocsStore->invitationsForLink($linkHash);
             foreach ($invitations as $invitation) {
                 $ocsStore->deleteInvitation($invitation);
                 $ocsClient->cancelInvitation($invitation);
             }
         }
         $newLinks = $ocsData["LINKS"];
         foreach ($newLinks as $linkData) {
             $this->shareObjectFromParameters($linkData, $hiddenUserEntries, $shareObjects, "targetted", $userSelection->getUniqueNode()->getLabel());
         }
     }
     $this->filterHttpVarsFromUniqueNode($httpVars, $ajxpNode);
     $users = array();
     $groups = array();
     $this->getRightsManager()->createUsersFromParameters($httpVars, $users, $groups);
     if ((count($users) || count($groups)) && !$this->getAuthorization($ajxpNode->isLeaf() ? "file" : "folder", "workspace")) {
         $users = $groups = array();
     }
     foreach ($hiddenUserEntries as $entry) {
         $users[$entry["ID"]] = $entry;
     }
     if (!count($users) && !count($groups)) {
         ob_start();
         unset($originalHttpVars["hash"]);
         $this->switchAction("unshare", $originalHttpVars, array());
         ob_end_clean();
         return null;
     }
     $newRepo = $this->createSharedRepository($httpVars, $repoUpdate, $users, $groups);
     foreach ($shareObjects as $shareObject) {
         $shareObject->setParentRepositoryId($this->repository->getId());
         $shareObject->attachToRepository($newRepo->getId());
         $shareObject->save();
         if ($shareObject instanceof \Pydio\OCS\Model\TargettedLink) {
             $invitation = $shareObject->getPendingInvitation();
             if (!empty($invitation)) {
                 $ocsStore->generateInvitationId($invitation);
                 try {
                     $ocsClient->sendInvitation($invitation);
                 } catch (Exception $e) {
                     $this->getShareStore()->deleteShare("minisite", $shareObject->getHash(), true);
                     $shareUserId = $shareObject->getUniqueUser();
                     unset($users[$shareUserId]);
                     if (!count($users) && !count($groups)) {
                         $this->getShareStore()->deleteShare("repository", $newRepo->getId());
                     }
                     throw $e;
                 }
                 $ocsStore->storeInvitation($invitation);
             }
         } else {
             $this->getPublicAccessManager()->initFolder();
             $url = $this->getPublicAccessManager()->buildPublicLink($shareObject->getHash());
             $existingShortForm = $shareObject->getShortFormUrl();
             if (empty($existingShortForm)) {
                 $shortForm = "";
                 AJXP_Controller::applyHook("url.shorten", array($url, &$shortForm));
                 if (!empty($shortForm)) {
                     $shareObject->setShortFormUrl($shortForm);
                     $shareObject->save();
                 }
             }
         }
     }
     $shareObjects[] = $newRepo;
     return $shareObjects;
 }
コード例 #7
0
 /**
  * @param AJXP_Node $ajxpNode
  * @param boolean $create
  * @return String
  */
 private function updateNodeMetaPath($ajxpNode, $create = false)
 {
     $folder = false;
     $trim = trim($ajxpNode->getPath(), "/");
     if ($ajxpNode->is_file !== null) {
         $folder = !$ajxpNode->isLeaf();
     } else {
         $folder = !is_file($ajxpNode->getUrl());
     }
     if (!$folder) {
         return $trim;
     }
     $meta = is_file(rtrim($ajxpNode->getUrl(), "/") . "/.meta");
     if (!$meta) {
         if ($create) {
             file_put_contents(rtrim($ajxpNode->getUrl(), "/") . "/.meta", "meta");
         } else {
             return null;
         }
     }
     return $trim . "/.meta";
 }
コード例 #8
0
ファイル: class.ShareCenter.php プロジェクト: biggtfish/cms
 /**
  *
  * Hooked to node.change, this will update the index
  * if $oldNode = null => create node $newNode
  * if $newNode = null => delete node $oldNode
  * Else copy or move oldNode to newNode.
  *
  * @param AJXP_Node $oldNode
  */
 public function updateNodeSharedData($oldNode)
 {
     if (empty($this->accessDriver) || $this->accessDriver->getId() == "access.imap") {
         return;
     }
     if ($oldNode == null || !$oldNode->hasMetaStore()) {
         return;
     }
     $metadata = $oldNode->retrieveMetadata("ajxp_shared", true);
     if (count($metadata) && !empty($metadata["element"])) {
         // TODO
         // Make sure node info is loaded, to check if it's a dir or a file.
         // Maybe could be directly embedded in metadata, to avoid having to load here.
         $oldNode->loadNodeInfo();
         try {
             $type = $oldNode->isLeaf() ? "file" : "repository";
             $elementIds = array();
             if ($type == "file") {
                 if (!is_array($metadata["element"])) {
                     $elementIds[] = $metadata["element"];
                 } else {
                     $elementIds = array_keys($metadata["element"]);
                 }
             } else {
                 $elementIds[] = $metadata["element"];
             }
             foreach ($elementIds as $elementId) {
                 self::deleteSharedElement($type, $elementId, AuthService::getLoggedUser());
             }
             $oldNode->removeMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY, true);
         } catch (Exception $e) {
             $this->logError("Exception", $e->getMessage(), $e->getTrace());
         }
     }
 }
コード例 #9
0
 /**
  * @param AJXP_Node $oldNode
  * @param AJXP_Node $newNode
  * @param bool $copy
  */
 public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false)
 {
     require_once AJXP_BIN_FOLDER . "/dibi.compact.php";
     try {
         if ($newNode == null) {
             $repoId = $this->computeIdentifier($oldNode->getRepository());
             // DELETE
             dibi::query("DELETE FROM [ajxp_index] WHERE [node_path] LIKE %like~ AND [repository_identifier] = %s", $oldNode->getPath(), $repoId);
         } else {
             if ($oldNode == null) {
                 // CREATE
                 $stat = stat($newNode->getUrl());
                 $res = dibi::query("INSERT INTO [ajxp_index]", array("node_path" => $newNode->getPath(), "bytesize" => $stat["size"], "mtime" => $stat["mtime"], "md5" => $newNode->isLeaf() ? md5_file($newNode->getUrl()) : "directory", "repository_identifier" => $repoId = $this->computeIdentifier($newNode->getRepository())));
             } else {
                 $repoId = $this->computeIdentifier($oldNode->getRepository());
                 if ($oldNode->getPath() == $newNode->getPath()) {
                     // CONTENT CHANGE
                     clearstatcache();
                     $stat = stat($newNode->getUrl());
                     $this->logDebug("Content changed", "current stat size is : " . $stat["size"]);
                     dibi::query("UPDATE [ajxp_index] SET ", array("bytesize" => $stat["size"], "mtime" => $stat["mtime"], "md5" => md5_file($newNode->getUrl())), "WHERE [node_path] = %s AND [repository_identifier] = %s", $oldNode->getPath(), $repoId);
                 } else {
                     // PATH CHANGE ONLY
                     $newNode->loadNodeInfo();
                     if ($newNode->isLeaf()) {
                         dibi::query("UPDATE [ajxp_index] SET ", array("node_path" => $newNode->getPath()), "WHERE [node_path] = %s AND [repository_identifier] = %s", $oldNode->getPath(), $repoId);
                     } else {
                         dibi::query("UPDATE [ajxp_index] SET [node_path]=REPLACE( REPLACE(CONCAT('\$\$\$',[node_path]), CONCAT('\$\$\$', %s), CONCAT('\$\$\$', %s)) , '\$\$\$', '') ", $oldNode->getPath(), $newNode->getPath(), "WHERE [node_path] LIKE %like~ AND [repository_identifier] = %s", $oldNode->getPath(), $repoId);
                     }
                 }
             }
         }
     } catch (Exception $e) {
         AJXP_Logger::error("[meta.syncable]", "Indexation", $e->getMessage());
     }
 }
コード例 #10
0
 public function switchAction($action, $httpVars, $fileVars)
 {
     if (!isset($this->actions[$action])) {
         return;
     }
     parent::accessPreprocess($action, $httpVars, $fileVars);
     $selection = new UserSelection();
     $dir = $httpVars["dir"] or "";
     if ($this->wrapperClassName == "fsAccessWrapper") {
         $dir = fsAccessWrapper::patchPathForBaseDir($dir);
     }
     $dir = AJXP_Utils::securePath($dir);
     if ($action != "upload") {
         $dir = AJXP_Utils::decodeSecureMagic($dir);
     }
     $selection->initFromHttpVars($httpVars);
     if (!$selection->isEmpty()) {
         $this->filterUserSelectionToHidden($selection->getFiles());
     }
     $mess = ConfService::getMessages();
     $newArgs = RecycleBinManager::filterActions($action, $selection, $dir, $httpVars);
     if (isset($newArgs["action"])) {
         $action = $newArgs["action"];
     }
     if (isset($newArgs["dest"])) {
         $httpVars["dest"] = SystemTextEncoding::toUTF8($newArgs["dest"]);
     }
     //Re-encode!
     // FILTER DIR PAGINATION ANCHOR
     $page = null;
     if (isset($dir) && strstr($dir, "%23") !== false) {
         $parts = explode("%23", $dir);
         $dir = $parts[0];
         $page = $parts[1];
     }
     $pendingSelection = "";
     $logMessage = null;
     $reloadContextNode = false;
     switch ($action) {
         //------------------------------------
         //	DOWNLOAD
         //------------------------------------
         case "download":
             $this->logInfo("Download", array("files" => $this->addSlugToPath($selection)));
             @set_error_handler(array("HTMLWriter", "javascriptErrorHandler"), E_ALL & ~E_NOTICE);
             @register_shutdown_function("restore_error_handler");
             $zip = false;
             if ($selection->isUnique()) {
                 if (is_dir($this->urlBase . $selection->getUniqueFile())) {
                     $zip = true;
                     $base = basename($selection->getUniqueFile());
                     $uniqDir = dirname($selection->getUniqueFile());
                     if (!empty($uniqDir) && $uniqDir != "/") {
                         $dir = dirname($selection->getUniqueFile());
                     }
                 } else {
                     if (!file_exists($this->urlBase . $selection->getUniqueFile())) {
                         throw new Exception("Cannot find file!");
                     }
                 }
                 $node = $selection->getUniqueNode($this);
             } else {
                 $zip = true;
             }
             if ($zip) {
                 // Make a temp zip and send it as download
                 $loggedUser = AuthService::getLoggedUser();
                 $file = AJXP_Utils::getAjxpTmpDir() . "/" . ($loggedUser ? $loggedUser->getId() : "shared") . "_" . time() . "tmpDownload.zip";
                 $zipFile = $this->makeZip($selection->getFiles(), $file, empty($dir) ? "/" : $dir);
                 if (!$zipFile) {
                     throw new AJXP_Exception("Error while compressing");
                 }
                 if (!$this->getFilteredOption("USE_XSENDFILE", $this->repository->getId()) && !$this->getFilteredOption("USE_XACCELREDIRECT", $this->repository->getId())) {
                     register_shutdown_function("unlink", $file);
                 }
                 $localName = ($base == "" ? "Files" : $base) . ".zip";
                 if (isset($httpVars["archive_name"])) {
                     $localName = AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]);
                 }
                 $this->readFile($file, "force-download", $localName, false, false, true);
             } else {
                 $localName = "";
                 AJXP_Controller::applyHook("dl.localname", array($this->urlBase . $selection->getUniqueFile(), &$localName, $this->wrapperClassName));
                 $this->readFile($this->urlBase . $selection->getUniqueFile(), "force-download", $localName);
             }
             if (isset($node)) {
                 AJXP_Controller::applyHook("node.read", array(&$node));
             }
             break;
         case "prepare_chunk_dl":
             $chunkCount = intval($httpVars["chunk_count"]);
             $fileId = $this->urlBase . $selection->getUniqueFile();
             $sessionKey = "chunk_file_" . md5($fileId . time());
             $totalSize = $this->filesystemFileSize($fileId);
             $chunkSize = intval($totalSize / $chunkCount);
             $realFile = call_user_func(array($this->wrapperClassName, "getRealFSReference"), $fileId, true);
             $chunkData = array("localname" => basename($fileId), "chunk_count" => $chunkCount, "chunk_size" => $chunkSize, "total_size" => $totalSize, "file_id" => $sessionKey);
             $_SESSION[$sessionKey] = array_merge($chunkData, array("file" => $realFile));
             HTMLWriter::charsetHeader("application/json");
             print json_encode($chunkData);
             $node = $selection->getUniqueNode($this);
             AJXP_Controller::applyHook("node.read", array(&$node));
             break;
         case "download_chunk":
             $chunkIndex = intval($httpVars["chunk_index"]);
             $chunkKey = $httpVars["file_id"];
             $sessData = $_SESSION[$chunkKey];
             $realFile = $sessData["file"];
             $chunkSize = $sessData["chunk_size"];
             $offset = $chunkSize * $chunkIndex;
             if ($chunkIndex == $sessData["chunk_count"] - 1) {
                 // Compute the last chunk real length
                 $chunkSize = $sessData["total_size"] - $chunkSize * ($sessData["chunk_count"] - 1);
                 if (call_user_func(array($this->wrapperClassName, "isRemote"))) {
                     register_shutdown_function("unlink", $realFile);
                 }
             }
             $this->readFile($realFile, "force-download", $sessData["localname"] . "." . sprintf("%03d", $chunkIndex + 1), false, false, true, $offset, $chunkSize);
             break;
         case "compress":
             // Make a temp zip and send it as download
             $loggedUser = AuthService::getLoggedUser();
             if (isset($httpVars["archive_name"])) {
                 $localName = AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]);
                 $this->filterUserSelectionToHidden(array($localName));
             } else {
                 $localName = (basename($dir) == "" ? "Files" : basename($dir)) . ".zip";
             }
             $file = AJXP_Utils::getAjxpTmpDir() . "/" . ($loggedUser ? $loggedUser->getId() : "shared") . "_" . time() . "tmpCompression.zip";
             if (isset($httpVars["compress_flat"])) {
                 $baseDir = "__AJXP_ZIP_FLAT__/";
             } else {
                 $baseDir = $dir;
             }
             $zipFile = $this->makeZip($selection->getFiles(), $file, $baseDir);
             if (!$zipFile) {
                 throw new AJXP_Exception("Error while compressing file {$localName}");
             }
             register_shutdown_function("unlink", $file);
             $tmpFNAME = $this->urlBase . $dir . "/" . str_replace(".zip", ".tmp", $localName);
             copy($file, $tmpFNAME);
             try {
                 AJXP_Controller::applyHook("node.before_create", array(new AJXP_Node($tmpFNAME), filesize($tmpFNAME)));
             } catch (Exception $e) {
                 @unlink($tmpFNAME);
                 throw $e;
             }
             @rename($tmpFNAME, $this->urlBase . $dir . "/" . $localName);
             AJXP_Controller::applyHook("node.change", array(null, new AJXP_Node($this->urlBase . $dir . "/" . $localName), false));
             //$reloadContextNode = true;
             //$pendingSelection = $localName;
             $newNode = new AJXP_Node($this->urlBase . $dir . "/" . $localName);
             if (!isset($nodesDiffs)) {
                 $nodesDiffs = $this->getNodesDiffArray();
             }
             $nodesDiffs["ADD"][] = $newNode;
             break;
         case "stat":
             clearstatcache();
             header("Content-type:application/json");
             if ($selection->isUnique()) {
                 $stat = @stat($this->urlBase . $selection->getUniqueFile());
                 if (!$stat) {
                     print '{}';
                 } else {
                     print json_encode($stat);
                 }
             } else {
                 $files = $selection->getFiles();
                 print '{';
                 foreach ($files as $index => $path) {
                     $stat = @stat($this->urlBase . $path);
                     if (!$stat) {
                         $stat = '{}';
                     } else {
                         $stat = json_encode($stat);
                     }
                     print json_encode($path) . ':' . $stat . ($index < count($files) - 1 ? "," : "");
                 }
                 print '}';
             }
             break;
             //------------------------------------
             //	ONLINE EDIT
             //------------------------------------
         //------------------------------------
         //	ONLINE EDIT
         //------------------------------------
         case "get_content":
             $dlFile = $this->urlBase . $selection->getUniqueFile();
             $this->logInfo("Get_content", array("files" => $this->addSlugToPath($selection)));
             if (AJXP_Utils::getStreamingMimeType(basename($dlFile)) !== false) {
                 $this->readFile($this->urlBase . $selection->getUniqueFile(), "stream_content");
             } else {
                 $this->readFile($this->urlBase . $selection->getUniqueFile(), "plain");
             }
             $node = $selection->getUniqueNode($this);
             AJXP_Controller::applyHook("node.read", array(&$node));
             break;
         case "put_content":
             if (!isset($httpVars["content"])) {
                 break;
             }
             // Load "code" variable directly from POST array, do not "securePath" or "sanitize"...
             $code = $httpVars["content"];
             $file = $selection->getUniqueFile();
             $this->logInfo("Online Edition", array("file" => $this->addSlugToPath($file)));
             if (isset($httpVars["encode"]) && $httpVars["encode"] == "base64") {
                 $code = base64_decode($code);
             } else {
                 $code = str_replace("&lt;", "<", SystemTextEncoding::magicDequote($code));
             }
             $fileName = $this->urlBase . $file;
             $currentNode = new AJXP_Node($fileName);
             try {
                 AJXP_Controller::applyHook("node.before_change", array(&$currentNode, strlen($code)));
             } catch (Exception $e) {
                 header("Content-Type:text/plain");
                 print $e->getMessage();
                 return;
             }
             if (!is_file($fileName) || !$this->isWriteable($fileName, "file")) {
                 header("Content-Type:text/plain");
                 print !$this->isWriteable($fileName, "file") ? "1001" : "1002";
                 return;
             }
             $fp = fopen($fileName, "w");
             fputs($fp, $code);
             fclose($fp);
             clearstatcache(true, $fileName);
             AJXP_Controller::applyHook("node.change", array($currentNode, $currentNode, false));
             header("Content-Type:text/plain");
             print $mess[115];
             break;
             //------------------------------------
             //	COPY / MOVE
             //------------------------------------
         //------------------------------------
         //	COPY / MOVE
         //------------------------------------
         case "copy":
         case "move":
             //throw new AJXP_Exception("", 113);
             if ($selection->isEmpty()) {
                 throw new AJXP_Exception("", 113);
             }
             $loggedUser = AuthService::getLoggedUser();
             if ($loggedUser != null && !$loggedUser->canWrite(ConfService::getCurrentRepositoryId())) {
                 throw new AJXP_Exception("You are not allowed to write", 207);
             }
             $success = $error = array();
             $dest = AJXP_Utils::decodeSecureMagic($httpVars["dest"]);
             $this->filterUserSelectionToHidden(array($httpVars["dest"]));
             if ($selection->inZip()) {
                 // Set action to copy anycase (cannot move from the zip).
                 $action = "copy";
                 $this->extractArchive($dest, $selection, $error, $success);
             } else {
                 $move = $action == "move" ? true : false;
                 if ($move && isset($httpVars["force_copy_delete"])) {
                     $move = false;
                 }
                 $this->copyOrMove($dest, $selection->getFiles(), $error, $success, $move);
             }
             if (count($error)) {
                 throw new AJXP_Exception(SystemTextEncoding::toUTF8(join("\n", $error)));
             } else {
                 if (isset($httpVars["force_copy_delete"])) {
                     $errorMessage = $this->delete($selection->getFiles(), $logMessages);
                     if ($errorMessage) {
                         throw new AJXP_Exception(SystemTextEncoding::toUTF8($errorMessage));
                     }
                     $this->logInfo("Copy/Delete", array("files" => $this->addSlugToPath($selection), "destination" => $this->addSlugToPath($dest)));
                 } else {
                     $this->logInfo($action == "move" ? "Move" : "Copy", array("files" => $this->addSlugToPath($selection), "destination" => $this->addSlugToPath($dest)));
                 }
                 $logMessage = join("\n", $success);
             }
             if (!isset($nodesDiffs)) {
                 $nodesDiffs = $this->getNodesDiffArray();
             }
             // Assume new nodes are correctly created
             $selectedItems = $selection->getFiles();
             foreach ($selectedItems as $selectedPath) {
                 $newPath = $this->urlBase . $dest . "/" . basename($selectedPath);
                 $newNode = new AJXP_Node($newPath);
                 $nodesDiffs["ADD"][] = $newNode;
                 if ($action == "move") {
                     $nodesDiffs["REMOVE"][] = $selectedPath;
                 }
             }
             if (!(RecycleBinManager::getRelativeRecycle() == $dest && $this->getFilteredOption("HIDE_RECYCLE", $this->repository->getId()) == true)) {
                 //$reloadDataNode = $dest;
             }
             break;
             //------------------------------------
             //	DELETE
             //------------------------------------
         //------------------------------------
         //	DELETE
         //------------------------------------
         case "delete":
             if ($selection->isEmpty()) {
                 throw new AJXP_Exception("", 113);
             }
             $logMessages = array();
             $errorMessage = $this->delete($selection->getFiles(), $logMessages);
             if (count($logMessages)) {
                 $logMessage = join("\n", $logMessages);
             }
             if ($errorMessage) {
                 throw new AJXP_Exception(SystemTextEncoding::toUTF8($errorMessage));
             }
             $this->logInfo("Delete", array("files" => $this->addSlugToPath($selection)));
             if (!isset($nodesDiffs)) {
                 $nodesDiffs = $this->getNodesDiffArray();
             }
             $nodesDiffs["REMOVE"] = array_merge($nodesDiffs["REMOVE"], $selection->getFiles());
             break;
         case "purge":
             $hardPurgeTime = intval($this->repository->getOption("PURGE_AFTER")) * 3600 * 24;
             $softPurgeTime = intval($this->repository->getOption("PURGE_AFTER_SOFT")) * 3600 * 24;
             $shareCenter = AJXP_PluginsService::findPluginById('action.share');
             if (!($shareCenter && $shareCenter->isEnabled())) {
                 //action.share is disabled, don't look at the softPurgeTime
                 $softPurgeTime = 0;
             }
             if ($hardPurgeTime > 0 || $softPurgeTime > 0) {
                 $this->recursivePurge($this->urlBase, $hardPurgeTime, $softPurgeTime);
             }
             break;
             //------------------------------------
             //	RENAME
             //------------------------------------
         //------------------------------------
         //	RENAME
         //------------------------------------
         case "rename":
             $file = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             $filename_new = AJXP_Utils::decodeSecureMagic($httpVars["filename_new"]);
             $dest = null;
             if (isset($httpVars["dest"])) {
                 $dest = AJXP_Utils::decodeSecureMagic($httpVars["dest"]);
                 $filename_new = "";
             }
             $this->filterUserSelectionToHidden(array($filename_new));
             $this->rename($file, $filename_new, $dest);
             $logMessage = SystemTextEncoding::toUTF8($file) . " {$mess['41']} " . SystemTextEncoding::toUTF8($filename_new);
             //$reloadContextNode = true;
             //$pendingSelection = $filename_new;
             if (!isset($nodesDiffs)) {
                 $nodesDiffs = $this->getNodesDiffArray();
             }
             if ($dest == null) {
                 $dest = AJXP_Utils::safeDirname($file);
             }
             $nodesDiffs["UPDATE"][$file] = new AJXP_Node($this->urlBase . $dest . "/" . $filename_new);
             $this->logInfo("Rename", array("original" => $this->addSlugToPath($file), "new" => $filename_new));
             break;
             //------------------------------------
             //	CREER UN REPERTOIRE / CREATE DIR
             //------------------------------------
         //------------------------------------
         //	CREER UN REPERTOIRE / CREATE DIR
         //------------------------------------
         case "mkdir":
             $messtmp = "";
             if (!isset($httpVars["dirname"])) {
                 $uniq = $selection->getUniqueFile();
                 $dir = AJXP_Utils::safeDirname($uniq);
                 $dirname = AJXP_Utils::safeBasename($uniq);
             } else {
                 $dirname = AJXP_Utils::decodeSecureMagic($httpVars["dirname"], AJXP_SANITIZE_FILENAME);
             }
             $dirname = substr($dirname, 0, ConfService::getCoreConf("NODENAME_MAX_LENGTH"));
             $this->filterUserSelectionToHidden(array($dirname));
             AJXP_Controller::applyHook("node.before_create", array(new AJXP_Node($dir . "/" . $dirname), -2));
             $error = $this->mkDir($dir, $dirname, isset($httpVars["ignore_exists"]) ? true : false);
             if (isset($error)) {
                 throw new AJXP_Exception($error);
             }
             $messtmp .= "{$mess['38']} " . SystemTextEncoding::toUTF8($dirname) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             //$pendingSelection = $dirname;
             //$reloadContextNode = true;
             $newNode = new AJXP_Node($this->urlBase . $dir . "/" . $dirname);
             if (!isset($nodesDiffs)) {
                 $nodesDiffs = $this->getNodesDiffArray();
             }
             array_push($nodesDiffs["ADD"], $newNode);
             $this->logInfo("Create Dir", array("dir" => $this->addSlugToPath($dir) . "/" . $dirname));
             break;
             //------------------------------------
             //	CREER UN FICHIER / CREATE FILE
             //------------------------------------
         //------------------------------------
         //	CREER UN FICHIER / CREATE FILE
         //------------------------------------
         case "mkfile":
             $messtmp = "";
             if (empty($httpVars["filename"]) && isset($httpVars["node"])) {
                 $filename = AJXP_Utils::decodeSecureMagic($httpVars["node"], AJXP_SANITIZE_FILENAME);
             } else {
                 $filename = AJXP_Utils::decodeSecureMagic($httpVars["filename"], AJXP_SANITIZE_FILENAME);
             }
             $filename = substr($filename, 0, ConfService::getCoreConf("NODENAME_MAX_LENGTH"));
             $this->filterUserSelectionToHidden(array($filename));
             $content = "";
             if (isset($httpVars["content"])) {
                 $content = $httpVars["content"];
             }
             $error = $this->createEmptyFile($dir, $filename, $content);
             if (isset($error)) {
                 throw new AJXP_Exception($error);
             }
             $messtmp .= "{$mess['34']} " . SystemTextEncoding::toUTF8($filename) . " {$mess['39']} ";
             if ($dir == "") {
                 $messtmp .= "/";
             } else {
                 $messtmp .= SystemTextEncoding::toUTF8($dir);
             }
             $logMessage = $messtmp;
             //$reloadContextNode = true;
             //$pendingSelection = $dir."/".$filename;
             $this->logInfo("Create File", array("file" => $this->addSlugToPath($dir) . "/" . $filename));
             $newNode = new AJXP_Node($this->urlBase . $dir . "/" . $filename);
             if (!isset($nodesDiffs)) {
                 $nodesDiffs = $this->getNodesDiffArray();
             }
             array_push($nodesDiffs["ADD"], $newNode);
             break;
             //------------------------------------
             //	CHANGE FILE PERMISSION
             //------------------------------------
         //------------------------------------
         //	CHANGE FILE PERMISSION
         //------------------------------------
         case "chmod":
             $files = $selection->getFiles();
             $changedFiles = array();
             $chmod_value = $httpVars["chmod_value"];
             $recursive = $httpVars["recursive"];
             $recur_apply_to = $httpVars["recur_apply_to"];
             foreach ($files as $fileName) {
                 $this->chmod($fileName, $chmod_value, $recursive == "on", $recursive == "on" ? $recur_apply_to : "both", $changedFiles);
             }
             $logMessage = "Successfully changed permission to " . $chmod_value . " for " . count($changedFiles) . " files or folders";
             $this->logInfo("Chmod", array("dir" => $this->addSlugToPath($dir), "filesCount" => count($changedFiles)));
             if (!isset($nodesDiffs)) {
                 $nodesDiffs = $this->getNodesDiffArray();
             }
             $nodesDiffs["UPDATE"] = array_merge($nodesDiffs["UPDATE"], $selection->buildNodes($this));
             break;
             //------------------------------------
             //	UPLOAD
             //------------------------------------
         //------------------------------------
         //	UPLOAD
         //------------------------------------
         case "upload":
             $repoData = array('base_url' => $this->urlBase, 'wrapper_name' => $this->wrapperClassName, 'chmod' => $this->repository->getOption('CHMOD_VALUE'), 'recycle' => $this->repository->getOption('RECYCLE_BIN'));
             $this->logDebug("Upload Files Data", $fileVars);
             $destination = $this->urlBase . AJXP_Utils::decodeSecureMagic($dir);
             $this->logDebug("Upload inside", array("destination" => $this->addSlugToPath($destination)));
             if (!$this->isWriteable($destination)) {
                 $errorCode = 412;
                 $errorMessage = "{$mess['38']} " . SystemTextEncoding::toUTF8($dir) . " {$mess['99']}.";
                 $this->logDebug("Upload error 412", array("destination" => $this->addSlugToPath($destination)));
                 return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage));
             }
             foreach ($fileVars as $boxName => $boxData) {
                 if (substr($boxName, 0, 9) != "userfile_") {
                     continue;
                 }
                 $err = AJXP_Utils::parseFileDataErrors($boxData);
                 if ($err != null) {
                     $errorCode = $err[0];
                     $errorMessage = $err[1];
                     break;
                 }
                 $userfile_name = $boxData["name"];
                 try {
                     $this->filterUserSelectionToHidden(array($userfile_name));
                 } catch (Exception $e) {
                     return array("ERROR" => array("CODE" => 411, "MESSAGE" => "Forbidden"));
                 }
                 $userfile_name = AJXP_Utils::sanitize(SystemTextEncoding::fromPostedFileName($userfile_name), AJXP_SANITIZE_FILENAME);
                 if (isset($httpVars["urlencoded_filename"])) {
                     $userfile_name = AJXP_Utils::sanitize(SystemTextEncoding::fromUTF8(urldecode($httpVars["urlencoded_filename"])), AJXP_SANITIZE_FILENAME);
                 }
                 $this->logDebug("User filename " . $userfile_name);
                 $userfile_name = substr($userfile_name, 0, ConfService::getCoreConf("NODENAME_MAX_LENGTH"));
                 if (isset($httpVars["auto_rename"])) {
                     $userfile_name = self::autoRenameForDest($destination, $userfile_name);
                 }
                 $already_existed = false;
                 try {
                     if (file_exists($destination . "/" . $userfile_name)) {
                         $already_existed = true;
                         AJXP_Controller::applyHook("node.before_change", array(new AJXP_Node($destination . "/" . $userfile_name), $boxData["size"]));
                     } else {
                         AJXP_Controller::applyHook("node.before_create", array(new AJXP_Node($destination . "/" . $userfile_name), $boxData["size"]));
                     }
                     AJXP_Controller::applyHook("node.before_change", array(new AJXP_Node($destination)));
                 } catch (Exception $e) {
                     $errorCode = 507;
                     $errorMessage = $e->getMessage();
                     break;
                 }
                 if (isset($boxData["input_upload"])) {
                     try {
                         $this->logDebug("Begining reading INPUT stream");
                         $input = fopen("php://input", "r");
                         $output = fopen("{$destination}/" . $userfile_name, "w");
                         $sizeRead = 0;
                         while ($sizeRead < intval($boxData["size"])) {
                             $chunk = fread($input, 4096);
                             $sizeRead += strlen($chunk);
                             fwrite($output, $chunk, strlen($chunk));
                         }
                         fclose($input);
                         fclose($output);
                         $this->logDebug("End reading INPUT stream");
                     } catch (Exception $e) {
                         $errorCode = 411;
                         $errorMessage = $e->getMessage();
                         break;
                     }
                 } else {
                     $result = @move_uploaded_file($boxData["tmp_name"], "{$destination}/" . $userfile_name);
                     if (!$result) {
                         $realPath = call_user_func(array($this->wrapperClassName, "getRealFSReference"), "{$destination}/" . $userfile_name);
                         $result = move_uploaded_file($boxData["tmp_name"], $realPath);
                     }
                     if (!$result) {
                         $errorCode = 411;
                         $errorMessage = "{$mess['33']} " . $userfile_name;
                         break;
                     }
                 }
                 if (isset($httpVars["appendto_urlencoded_part"])) {
                     $appendTo = AJXP_Utils::sanitize(SystemTextEncoding::fromUTF8(urldecode($httpVars["appendto_urlencoded_part"])), AJXP_SANITIZE_FILENAME);
                     if (file_exists($destination . "/" . $appendTo)) {
                         $this->logDebug("Should copy stream from {$userfile_name} to {$appendTo}");
                         $partO = fopen($destination . "/" . $userfile_name, "r");
                         $appendF = fopen($destination . "/" . $appendTo, "a+");
                         while (!feof($partO)) {
                             $buf = fread($partO, 1024);
                             fwrite($appendF, $buf, strlen($buf));
                         }
                         fclose($partO);
                         fclose($appendF);
                         $this->logDebug("Done, closing streams!");
                     }
                     @unlink($destination . "/" . $userfile_name);
                     $userfile_name = $appendTo;
                 }
                 $this->changeMode($destination . "/" . $userfile_name, $repoData);
                 $createdNode = new AJXP_Node($destination . "/" . $userfile_name);
                 //AJXP_Controller::applyHook("node.change", array(null, $createdNode, false));
                 $logMessage .= "{$mess['34']} " . SystemTextEncoding::toUTF8($userfile_name) . " {$mess['35']} {$dir}";
                 $this->logInfo("Upload File", array("file" => $this->addSlugToPath(SystemTextEncoding::fromUTF8($dir)) . "/" . $userfile_name));
             }
             if (isset($errorMessage)) {
                 $this->logDebug("Return error {$errorCode} {$errorMessage}");
                 return array("ERROR" => array("CODE" => $errorCode, "MESSAGE" => $errorMessage));
             } else {
                 $this->logDebug("Return success");
                 if ($already_existed) {
                     return array("SUCCESS" => true, "UPDATED_NODE" => $createdNode);
                 } else {
                     return array("SUCCESS" => true, "CREATED_NODE" => $createdNode);
                 }
             }
             return;
             break;
         case "lsync":
             if (!ConfService::currentContextIsCommandLine()) {
                 die("This command must be accessed via CLI only.");
             }
             $fromNode = null;
             $toNode = null;
             $copyOrMove = false;
             if (isset($httpVars["from"])) {
                 $fromNode = new AJXP_Node($this->urlBase . AJXP_Utils::decodeSecureMagic($httpVars["from"]));
             }
             if (isset($httpVars["to"])) {
                 $toNode = new AJXP_Node($this->urlBase . AJXP_Utils::decodeSecureMagic($httpVars["to"]));
             }
             if (isset($httpVars["copy"]) && $httpVars["copy"] == "true") {
                 $copyOrMove = true;
             }
             AJXP_Controller::applyHook("node.change", array($fromNode, $toNode, $copyOrMove));
             break;
             //------------------------------------
             //	XML LISTING
             //------------------------------------
         //------------------------------------
         //	XML LISTING
         //------------------------------------
         case "ls":
             if (!isset($dir) || $dir == "/") {
                 $dir = "";
             }
             $lsOptions = $this->parseLsOptions(isset($httpVars["options"]) ? $httpVars["options"] : "a");
             $startTime = microtime();
             if (isset($httpVars["file"])) {
                 $uniqueFile = AJXP_Utils::decodeSecureMagic($httpVars["file"]);
             }
             $dir = AJXP_Utils::securePath($dir);
             $path = $this->urlBase . ($dir != "" ? ($dir[0] == "/" ? "" : "/") . $dir : "");
             $nonPatchedPath = $path;
             if ($this->wrapperClassName == "fsAccessWrapper") {
                 $nonPatchedPath = fsAccessWrapper::unPatchPathForBaseDir($path);
             }
             if ($this->getFilteredOption("REMOTE_SORTING")) {
                 $orderDirection = isset($httpVars["order_direction"]) ? strtolower($httpVars["order_direction"]) : "asc";
                 $orderField = isset($httpVars["order_column"]) ? $httpVars["order_column"] : null;
                 if ($orderField != null && !in_array($orderField, array("ajxp_label", "filesize", "ajxp_modiftime", "mimestring"))) {
                     $orderField = "ajxp_label";
                 }
             }
             if (isset($httpVars["recursive"]) && $httpVars["recursive"] == "true") {
                 $max_depth = isset($httpVars["max_depth"]) ? intval($httpVars["max_depth"]) : 0;
                 $max_nodes = isset($httpVars["max_nodes"]) ? intval($httpVars["max_nodes"]) : 0;
                 $crt_depth = isset($httpVars["crt_depth"]) ? intval($httpVars["crt_depth"]) + 1 : 1;
                 $crt_nodes = isset($httpVars["crt_nodes"]) ? intval($httpVars["crt_nodes"]) : 0;
             } else {
                 $threshold = $this->repository->getOption("PAGINATION_THRESHOLD");
                 if (!isset($threshold) || intval($threshold) == 0) {
                     $threshold = 500;
                 }
                 $limitPerPage = $this->repository->getOption("PAGINATION_NUMBER");
                 if (!isset($limitPerPage) || intval($limitPerPage) == 0) {
                     $limitPerPage = 200;
                 }
             }
             $countFiles = $this->countFiles($path, !$lsOptions["f"]);
             if (isset($crt_nodes)) {
                 $crt_nodes += $countFiles;
             }
             if (isset($threshold) && isset($limitPerPage) && $countFiles > $threshold) {
                 if (isset($uniqueFile)) {
                     $originalLimitPerPage = $limitPerPage;
                     $offset = $limitPerPage = 0;
                 } else {
                     $offset = 0;
                     $crtPage = 1;
                     if (isset($page)) {
                         $offset = (intval($page) - 1) * $limitPerPage;
                         $crtPage = $page;
                     }
                     $totalPages = floor($countFiles / $limitPerPage) + 1;
                 }
             } else {
                 $offset = $limitPerPage = 0;
             }
             $metaData = array();
             if (RecycleBinManager::recycleEnabled() && $dir == "") {
                 $metaData["repo_has_recycle"] = "true";
             }
             $parentAjxpNode = new AJXP_Node($nonPatchedPath, $metaData);
             $parentAjxpNode->loadNodeInfo(false, true, $lsOptions["l"] ? "all" : "minimal");
             AJXP_Controller::applyHook("node.read", array(&$parentAjxpNode));
             if (AJXP_XMLWriter::$headerSent == "tree") {
                 AJXP_XMLWriter::renderAjxpNode($parentAjxpNode, false);
             } else {
                 AJXP_XMLWriter::renderAjxpHeaderNode($parentAjxpNode);
             }
             if (isset($totalPages) && isset($crtPage)) {
                 $remoteOptions = null;
                 if ($this->getFilteredOption("REMOTE_SORTING")) {
                     $remoteOptions = array("remote_order" => "true", "currentOrderCol" => isset($orderField) ? $orderField : "ajxp_label", "currentOrderDir" => isset($orderDirection) ? $orderDirection : "asc");
                 }
                 AJXP_XMLWriter::renderPaginationData($countFiles, $crtPage, $totalPages, $this->countFiles($path, TRUE), $remoteOptions);
                 if (!$lsOptions["f"]) {
                     AJXP_XMLWriter::close();
                     exit(1);
                 }
             }
             $cursor = 0;
             $handle = opendir($path);
             if (!$handle) {
                 throw new AJXP_Exception("Cannot open dir " . $nonPatchedPath);
             }
             closedir($handle);
             $fullList = array("d" => array(), "z" => array(), "f" => array());
             if (isset($orderField) && isset($orderDirection) && $orderField == "ajxp_label" && $orderDirection == "desc") {
                 $nodes = scandir($path, 1);
             } else {
                 $nodes = scandir($path);
             }
             if (!empty($this->driverConf["SCANDIR_RESULT_SORTFONC"])) {
                 usort($nodes, $this->driverConf["SCANDIR_RESULT_SORTFONC"]);
             }
             if (isset($orderField) && isset($orderDirection) && $orderField != "ajxp_label") {
                 $toSort = array();
                 foreach ($nodes as $node) {
                     if ($orderField == "filesize") {
                         $toSort[$node] = is_file($nonPatchedPath . "/" . $node) ? $this->filesystemFileSize($nonPatchedPath . "/" . $node) : 0;
                     } else {
                         if ($orderField == "ajxp_modiftime") {
                             $toSort[$node] = filemtime($nonPatchedPath . "/" . $node);
                         } else {
                             if ($orderField == "mimestring") {
                                 $toSort[$node] = pathinfo($node, PATHINFO_EXTENSION);
                             }
                         }
                     }
                 }
                 if ($orderDirection == "asc") {
                     asort($toSort);
                 } else {
                     arsort($toSort);
                 }
                 $nodes = array_keys($toSort);
             }
             //while (strlen($nodeName = readdir($handle)) > 0) {
             foreach ($nodes as $nodeName) {
                 if ($nodeName == "." || $nodeName == "..") {
                     continue;
                 }
                 if (isset($uniqueFile) && $nodeName != $uniqueFile) {
                     $cursor++;
                     continue;
                 }
                 if ($offset > 0 && $cursor < $offset) {
                     $cursor++;
                     continue;
                 }
                 $isLeaf = "";
                 if (!$this->filterNodeName($path, $nodeName, $isLeaf, $lsOptions)) {
                     continue;
                 }
                 if (RecycleBinManager::recycleEnabled() && $dir == "" && "/" . $nodeName == RecycleBinManager::getRecyclePath()) {
                     continue;
                 }
                 if ($limitPerPage > 0 && $cursor - $offset >= $limitPerPage) {
                     break;
                 }
                 $currentFile = $nonPatchedPath . "/" . $nodeName;
                 $meta = array();
                 if ($isLeaf != "") {
                     $meta = array("is_file" => $isLeaf ? "1" : "0");
                 }
                 $node = new AJXP_Node($currentFile, $meta);
                 $node->setLabel($nodeName);
                 $node->loadNodeInfo(false, false, $lsOptions["l"] ? "all" : "minimal");
                 if (!empty($node->metaData["nodeName"]) && $node->metaData["nodeName"] != $nodeName) {
                     $node->setUrl($nonPatchedPath . "/" . $node->metaData["nodeName"]);
                 }
                 if (!empty($node->metaData["hidden"]) && $node->metaData["hidden"] === true) {
                     continue;
                 }
                 if (!empty($node->metaData["mimestring_id"]) && array_key_exists($node->metaData["mimestring_id"], $mess)) {
                     $node->mergeMetadata(array("mimestring" => $mess[$node->metaData["mimestring_id"]]));
                 }
                 if (isset($originalLimitPerPage) && $cursor > $originalLimitPerPage) {
                     $node->mergeMetadata(array("page_position" => floor($cursor / $originalLimitPerPage) + 1));
                 }
                 $nodeType = "d";
                 if ($node->isLeaf()) {
                     if (AJXP_Utils::isBrowsableArchive($nodeName)) {
                         if ($lsOptions["f"] && $lsOptions["z"]) {
                             $nodeType = "f";
                         } else {
                             $nodeType = "z";
                         }
                     } else {
                         $nodeType = "f";
                     }
                 }
                 // There is a special sorting, cancel the reordering of files & folders.
                 if (isset($orderField) && $orderField != "ajxp_label") {
                     $nodeType = "f";
                 }
                 $fullList[$nodeType][$nodeName] = $node;
                 $cursor++;
                 if (isset($uniqueFile) && $nodeName != $uniqueFile) {
                     break;
                 }
             }
             if (isset($httpVars["recursive"]) && $httpVars["recursive"] == "true") {
                 $breakNow = false;
                 if (isset($max_depth) && $max_depth > 0 && $crt_depth >= $max_depth) {
                     $breakNow = true;
                 }
                 if (isset($max_nodes) && $max_nodes > 0 && $crt_nodes >= $max_nodes) {
                     $breakNow = true;
                 }
                 foreach ($fullList["d"] as &$nodeDir) {
                     if ($breakNow) {
                         $nodeDir->mergeMetadata(array("ajxp_has_children" => $this->countFiles($nodeDir->getUrl(), false, true) ? "true" : "false"));
                         AJXP_XMLWriter::renderAjxpNode($nodeDir, true);
                         continue;
                     }
                     $this->switchAction("ls", array("dir" => SystemTextEncoding::toUTF8($nodeDir->getPath()), "options" => $httpVars["options"], "recursive" => "true", "max_depth" => $max_depth, "max_nodes" => $max_nodes, "crt_depth" => $crt_depth, "crt_nodes" => $crt_nodes), array());
                 }
             } else {
                 array_map(array("AJXP_XMLWriter", "renderAjxpNode"), $fullList["d"]);
             }
             array_map(array("AJXP_XMLWriter", "renderAjxpNode"), $fullList["z"]);
             array_map(array("AJXP_XMLWriter", "renderAjxpNode"), $fullList["f"]);
             // ADD RECYCLE BIN TO THE LIST
             if ($dir == "" && !$uniqueFile && RecycleBinManager::recycleEnabled() && $this->getFilteredOption("HIDE_RECYCLE", $this->repository->getId()) !== true) {
                 $recycleBinOption = RecycleBinManager::getRelativeRecycle();
                 if (file_exists($this->urlBase . $recycleBinOption)) {
                     $recycleNode = new AJXP_Node($this->urlBase . $recycleBinOption);
                     $recycleNode->loadNodeInfo();
                     AJXP_XMLWriter::renderAjxpNode($recycleNode);
                 }
             }
             $this->logDebug("LS Time : " . intval((microtime() - $startTime) * 1000) . "ms");
             AJXP_XMLWriter::close();
             break;
     }
     $xmlBuffer = "";
     if (isset($logMessage) || isset($errorMessage)) {
         $xmlBuffer .= AJXP_XMLWriter::sendMessage(isset($logMessage) ? $logMessage : null, isset($errorMessage) ? $errorMessage : null, false);
     }
     if ($reloadContextNode) {
         if (!isset($pendingSelection)) {
             $pendingSelection = "";
         }
         $xmlBuffer .= AJXP_XMLWriter::reloadDataNode("", $pendingSelection, false);
     }
     if (isset($reloadDataNode)) {
         $xmlBuffer .= AJXP_XMLWriter::reloadDataNode($reloadDataNode, "", false);
     }
     if (isset($nodesDiffs)) {
         $xmlBuffer .= AJXP_XMLWriter::writeNodesDiff($nodesDiffs, false);
     }
     return $xmlBuffer;
 }
コード例 #11
0
 /**
  * @param AJXP_Node $node
  */
 protected function clearCacheForNode($node)
 {
     if ($node->isLeaf()) {
         // Clear meta
         CacheService::delete(AJXP_CACHE_SERVICE_NS_NODES, $this->computeId($node, true));
         CacheService::delete(AJXP_CACHE_SERVICE_NS_NODES, $this->computeId($node, false));
         // Clear stat
         CacheService::delete(AJXP_CACHE_SERVICE_NS_NODES, AbstractCacheDriver::computeIdForNode($node, "stat"));
         // Clear parent listing
         if ($node->getParent() !== null) {
             CacheService::delete(AJXP_CACHE_SERVICE_NS_NODES, AbstractCacheDriver::computeIdForNode($node->getParent(), "list"));
         }
     } else {
         $cacheDriver = ConfService::getCacheDriverImpl();
         $cacheDriver->deleteKeyStartingWith(AJXP_CACHE_SERVICE_NS_NODES, $this->computeId($node, true));
         $cacheDriver->deleteKeyStartingWith(AJXP_CACHE_SERVICE_NS_NODES, $this->computeId($node, false));
         $cacheDriver->deleteKeyStartingWith(AJXP_CACHE_SERVICE_NS_NODES, AbstractCacheDriver::computeIdForNode($node, "stat"));
         if ($node->getParent() !== null) {
             $cacheDriver->deleteKeyStartingWith(AJXP_CACHE_SERVICE_NS_NODES, AbstractCacheDriver::computeIdForNode($node->getParent(), "list"));
         } else {
             $cacheDriver->deleteKeyStartingWith(AJXP_CACHE_SERVICE_NS_NODES, AbstractCacheDriver::computeIdForNode($node, "list"));
         }
     }
 }
コード例 #12
0
 public function applyAction($actionName, $httpVars, $fileVars)
 {
     $messages = ConfService::getMessages();
     $repoId = $this->accessDriver->repository->getId();
     if ($actionName == "search") {
         // TMP
         if (strpos($httpVars["query"], "keyword:") === 0) {
             $parts = explode(":", $httpVars["query"]);
             $this->applyAction("search_by_keyword", array("field" => $parts[1]), array());
             return;
         }
         try {
             $this->loadIndex($repoId, false);
         } catch (Exception $ex) {
             $this->applyAction("index", array(), array());
             throw new Exception($messages["index.lucene.7"]);
         }
         $textQuery = $httpVars["query"];
         if ($this->getFilteredOption("AUTO_WILDCARD") === true && strlen($textQuery) > 0 && ctype_alnum($textQuery)) {
             if ($textQuery[0] == '"' && $textQuery[strlen($textQuery) - 1] == '"') {
                 $textQuery = substr($textQuery, 1, -1);
             } else {
                 if ($textQuery[strlen($textQuery) - 1] != "*") {
                     $textQuery .= "*";
                 }
             }
         }
         $this->currentIndex->open();
         $fieldQuery = new Elastica\Query\QueryString();
         $fieldQuery->setAllowLeadingWildcard(true);
         $fieldQuery->setFuzzyMinSim(0.8);
         if ($textQuery == "*") {
             $fields = ["ajxp_node"];
             $fieldQuery->setQuery("yes");
             $fieldQuery->setFields($fields);
         } else {
             if (strpos($textQuery, ":") !== false) {
                 // USE LUCENE DSL DIRECTLY (key1:value1 AND key2:value2...)
                 $textQuery = str_replace("ajxp_meta_ajxp_document_content:", "body:", $textQuery);
                 $textQuery = $this->filterSearchRangesKeywords($textQuery);
                 $fieldQuery->setQuery($textQuery);
             } else {
                 $fields = ["basename", "ajxp_meta_*", "body"];
                 $fieldQuery->setQuery($textQuery);
                 $fieldQuery->setFields($fields);
             }
         }
         /*
         TODO : READAPT QUERY WITH EACH FIELD
         if ((isSet($this->metaFields) || $this->indexContent) && isSet($httpVars["fields"])) {
              $sParts = array();
              foreach (explode(",",$httpVars["fields"]) as $searchField) {
                  if ($searchField == "filename") {
                      $sParts[] = "basename:".$httpVars["query"];
                  } else if (in_array($searchField, $this->metaFields)) {
                      $sParts[] = "ajxp_meta_".$searchField.":".$httpVars["query"];
                  } else if ($searchField == "ajxp_document_content") {
                      $sParts[] = "title:".$httpVars["query"];
                      $sParts[] = "body:".$httpVars["query"];
                      $sParts[] = "keywords:".$httpVars["query"];
                  }
              }
              $query = implode(" OR ", $sParts);
              $query = "ajxp_scope:shared AND ($query)";
              $this->logDebug("Query : $query");
         } else {
         */
         //}
         /*
            We create this object search because it'll allow us to fetch the number of results we want at once.
            We just have to set some parameters, the query type and the size of the result set.
         */
         $search = new Elastica\Search($this->client);
         $search->addIndex($this->currentIndex)->addType($this->currentType);
         $maxResults = $this->getFilteredOption("MAX_RESULTS");
         if (isset($httpVars['limit'])) {
             $maxResults = intval($httpVars['limit']);
         }
         $searchOptions = [\Elastica\Search::OPTION_SEARCH_TYPE => \Elastica\Search::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH, \Elastica\Search::OPTION_SIZE => $maxResults];
         $this->logDebug(__FUNCTION__, "Executing query: ", $textQuery);
         $fullQuery = new Elastica\Query();
         $fullQuery->setQuery($fieldQuery);
         $qb = new Elastica\QueryBuilder();
         $fullQuery = new Elastica\Query();
         $filter = $qb->query()->match("ajxp_scope", "shared");
         $fullQuery->setQuery($qb->query()->bool()->addMust($fieldQuery)->addFilter($filter));
         $result = $search->search($fullQuery, $searchOptions);
         $this->logDebug(__FUNCTION__, "Search finished. ");
         $hits = $result->getResults();
         AJXP_XMLWriter::header();
         foreach ($hits as $hit) {
             $source = $hit->getSource();
             if ($source["serialized_metadata"] != null) {
                 $meta = unserialize(base64_decode($source["serialized_metadata"]));
                 $tmpNode = new AJXP_Node(SystemTextEncoding::fromUTF8($source["node_url"]), $meta);
             } else {
                 $tmpNode = new AJXP_Node(SystemTextEncoding::fromUTF8($source["node_url"]), array());
                 $tmpNode->loadNodeInfo();
             }
             if (!file_exists($tmpNode->getUrl())) {
                 $this->currentType->deleteById($hit->getId());
                 continue;
             }
             $tmpNode->search_score = sprintf("%0.2f", $hit->getScore());
             AJXP_XMLWriter::renderAjxpNode($tmpNode);
         }
         AJXP_XMLWriter::close();
     } else {
         if ($actionName == "search_by_keyword") {
             $scope = "user";
             try {
                 $this->loadIndex($repoId, false);
             } catch (Exception $ex) {
                 throw new Exception($messages["index.lucene.7"]);
             }
             /*
                         $sParts = array();
                         $searchField = $httpVars["field"];
             
             
                         if ($scope == "user") {
                             if (AuthService::usersEnabled() && AuthService::getLoggedUser() == null) {
                                 throw new Exception("Cannot find current user");
                             }
                             $sParts[] = "ajxp_scope:user";
                             $sParts[] = "ajxp_user:"******"ajxp_scope:shared";
                         }
                         $query = implode(" AND ", $sParts);
                         $this->logDebug("Query : $query");*/
             $searchField = AJXP_Utils::sanitize($httpVars["field"], AJXP_SANITIZE_ALPHANUM);
             $fieldQuery = new Elastica\Query\QueryString();
             $fields = array($searchField);
             $fieldQuery->setQuery($searchField == "ajxp_node" ? "yes" : "true");
             $fieldQuery->setFields($fields);
             $fieldQuery->setAllowLeadingWildcard(false);
             $fieldQuery->setFuzzyMinSim(0.8);
             $search = new Elastica\Search($this->client);
             $search->addIndex($this->currentIndex)->addType($this->currentType);
             $maxResults = $this->getFilteredOption("MAX_RESULTS");
             if (isset($httpVars['limit'])) {
                 $maxResults = intval($httpVars['limit']);
             }
             $searchOptions = array(\Elastica\Search::OPTION_SEARCH_TYPE => \Elastica\Search::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH, \Elastica\Search::OPTION_SIZE => $maxResults);
             /* ADD SCOPE FILTER
                $term = new Elastica\Filter\Term();
                $term->setTerm("ajxp_scope", "user");*/
             $qb = new Elastica\QueryBuilder();
             $fullQuery = new Elastica\Query();
             $fullQuery->setQuery($qb->query()->bool()->addMust($fieldQuery)->addMust($qb->query()->match("ajxp_scope", "user"))->addMust($qb->query()->match("user", AuthService::getLoggedUser()->getId())));
             $result = $search->search($fullQuery, $searchOptions);
             $this->logDebug(__FUNCTION__, "Search finished. ");
             $hits = $result->getResults();
             AJXP_XMLWriter::header();
             $leafNodes = [];
             foreach ($hits as $hit) {
                 if ($hit->serialized_metadata != null) {
                     $meta = unserialize(base64_decode($hit->serialized_metadata));
                     $tmpNode = new AJXP_Node(SystemTextEncoding::fromUTF8($hit->node_url), $meta);
                 } else {
                     $tmpNode = new AJXP_Node(SystemTextEncoding::fromUTF8($hit->node_url), array());
                     $tmpNode->loadNodeInfo();
                 }
                 if (!file_exists($tmpNode->getUrl())) {
                     $this->currentType->deleteById($hit->id);
                     continue;
                 }
                 $tmpNode->search_score = sprintf("%0.2f", $hit->score);
                 if ($tmpNode->isLeaf()) {
                     $leafNodes[] = $tmpNode;
                 } else {
                     AJXP_XMLWriter::renderAjxpNode($tmpNode);
                 }
             }
             foreach ($leafNodes as $leaf) {
                 AJXP_XMLWriter::renderAjxpNode($leaf);
             }
             AJXP_XMLWriter::close();
         }
     }
 }
コード例 #13
0
 public function delete($selectedFiles, &$logMessages)
 {
     $repoData = array('base_url' => $this->urlBase, 'chmod' => $this->repository->getOption('CHMOD_VALUE'), 'recycle' => $this->repository->getOption('RECYCLE_BIN'));
     $mess = ConfService::getMessages();
     foreach ($selectedFiles as $selectedFile) {
         if ($selectedFile == "" || $selectedFile == DIRECTORY_SEPARATOR) {
             return $mess[120];
         }
         $fileToDelete = $this->urlBase . $selectedFile;
         if (!file_exists($fileToDelete)) {
             $logMessages[] = $mess[100] . " " . SystemTextEncoding::toUTF8($selectedFile);
             continue;
         }
         $node = new AJXP_Node($fileToDelete);
         $node->setLeaf(!is_dir($fileToDelete));
         $this->deldir($fileToDelete, $repoData);
         if ($node->isLeaf()) {
             $logMessages[] = "{$mess['38']} " . SystemTextEncoding::toUTF8($selectedFile) . " {$mess['44']}.";
         } else {
             $logMessages[] = "{$mess['34']} " . SystemTextEncoding::toUTF8($selectedFile) . " {$mess['44']}.";
         }
         AJXP_Controller::applyHook("node.change", [$node]);
     }
     return null;
 }
コード例 #14
0
 /**
  * @static
  * @param AJXP_Node $ajxpNode
  * @param bool $close
  * @param bool $print
  * @return void|string
  */
 public static function renderAjxpNode($ajxpNode, $close = true, $print = true)
 {
     return AJXP_XMLWriter::renderNode($ajxpNode->getPath(), $ajxpNode->getLabel(), $ajxpNode->isLeaf(), $ajxpNode->metadata, $close, $print);
 }
コード例 #15
0
 public function applyAction($actionName, $httpVars, $fileVars)
 {
     $messages = ConfService::getMessages();
     $repoId = $this->accessDriver->repository->getId();
     if ($actionName == "search") {
         // TMP
         if (strpos($httpVars["query"], "keyword:") === 0) {
             $parts = explode(":", $httpVars["query"]);
             $this->applyAction("search_by_keyword", array("field" => $parts[1]), array());
             return null;
         }
         require_once "Zend/Search/Lucene.php";
         try {
             $index = $this->loadIndex($repoId, false);
         } catch (Exception $ex) {
             AJXP_XMLWriter::header();
             if ($this->seemsCurrentlyIndexing($repoId, 3)) {
                 AJXP_XMLWriter::sendMessage($messages["index.lucene.11"], null);
             } else {
                 if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) {
                     AJXP_Controller::applyActionInBackground($repoId, "index", array());
                     sleep(2);
                     AJXP_XMLWriter::triggerBgAction("check_index_status", array("repository_id" => $repoId), sprintf($messages["index.lucene.8"], "/"), true, 5);
                     AJXP_XMLWriter::sendMessage($messages["index.lucene.7"], null);
                 } else {
                     AJXP_XMLWriter::sendMessage($messages["index.lucene.12"], null);
                 }
             }
             AJXP_XMLWriter::close();
             return null;
         }
         $textQuery = $httpVars["query"];
         if ($this->getFilteredOption("AUTO_WILDCARD") === true && strlen($textQuery) > 0 && ctype_alnum($textQuery)) {
             if ($textQuery[0] == '"' && $textQuery[strlen($textQuery) - 1] == '"') {
                 $textQuery = substr($textQuery, 1, -1);
             } else {
                 if ($textQuery[strlen($textQuery) - 1] != "*") {
                     $textQuery .= "*";
                 }
             }
         }
         if (strpos($textQuery, ":") !== false) {
             $textQuery = str_replace("ajxp_meta_ajxp_document_content:", "body:", $textQuery);
             $textQuery = $this->filterSearchRangesKeywords($textQuery);
             $query = "ajxp_scope:shared AND ({$textQuery})";
         } else {
             if ((isset($this->metaFields) || $this->indexContent) && isset($httpVars["fields"])) {
                 $sParts = array();
                 foreach (explode(",", $httpVars["fields"]) as $searchField) {
                     if ($searchField == "filename") {
                         $sParts[] = "basename:" . $textQuery;
                     } else {
                         if ($searchField == "ajxp_document_content") {
                             $sParts[] = $textQuery;
                         } else {
                             if (in_array($searchField, $this->metaFields)) {
                                 $sParts[] = "ajxp_meta_" . $searchField . ":" . $textQuery;
                             } else {
                                 if ($searchField == "ajxp_document_content") {
                                     $sParts[] = "title:" . $textQuery;
                                     $sParts[] = "body:" . $textQuery;
                                     $sParts[] = "keywords:" . $textQuery;
                                 }
                             }
                         }
                     }
                 }
                 $query = implode(" OR ", $sParts);
                 $query = "ajxp_scope:shared AND ({$query})";
                 $this->logDebug("Query : {$query}");
             } else {
                 $index->setDefaultSearchField("basename");
                 $query = $this->filterSearchRangesKeywords($textQuery);
             }
         }
         $this->setDefaultAnalyzer();
         if ($query == "*") {
             $index->setDefaultSearchField("ajxp_node");
             $query = "yes";
             $hits = $index->find($query, "node_url", SORT_STRING);
         } else {
             $hits = $index->find($query);
         }
         $commitIndex = false;
         if (isset($httpVars['return_selection'])) {
             $returnNodes = array();
         } else {
             AJXP_XMLWriter::header();
         }
         $cursor = 0;
         if (isset($httpVars['limit'])) {
             $limit = intval($httpVars['limit']);
         }
         foreach ($hits as $hit) {
             // Backward compatibility
             $hit->node_url = preg_replace("#ajxp\\.[a-z_]+://#", "pydio://", $hit->node_url);
             if ($hit->serialized_metadata != null) {
                 $meta = unserialize(base64_decode($hit->serialized_metadata));
                 if (isset($meta["ajxp_modiftime"])) {
                     $meta["ajxp_relativetime"] = $meta["ajxp_description"] = $messages[4] . " " . AJXP_Utils::relativeDate($meta["ajxp_modiftime"], $messages);
                 }
                 $tmpNode = new AJXP_Node(SystemTextEncoding::fromUTF8($hit->node_url), $meta);
             } else {
                 $tmpNode = new AJXP_Node(SystemTextEncoding::fromUTF8($hit->node_url), array());
                 $tmpNode->loadNodeInfo();
             }
             if ($tmpNode->getRepositoryId() != $repoId) {
                 $this->logDebug(__CLASS__, "Strange case, search retrieves a node from wrong repository!");
                 $index->delete($hit->id);
                 $commitIndex = true;
                 continue;
             }
             if (!file_exists($tmpNode->getUrl())) {
                 $index->delete($hit->id);
                 $commitIndex = true;
                 continue;
             }
             if (!is_readable($tmpNode->getUrl())) {
                 continue;
             }
             $basename = basename($tmpNode->getPath());
             $isLeaf = $tmpNode->isLeaf();
             if (!$this->accessDriver->filterNodeName($tmpNode->getPath(), $basename, $isLeaf, array("d" => true, "f" => true))) {
                 continue;
             }
             $tmpNode->search_score = sprintf("%0.2f", $hit->score);
             if (isset($returnNodes)) {
                 $returnNodes[] = $tmpNode;
             } else {
                 AJXP_XMLWriter::renderAjxpNode($tmpNode);
             }
             $cursor++;
             if (isset($limit) && $cursor > $limit) {
                 break;
             }
         }
         if (!isset($returnNodes)) {
             AJXP_XMLWriter::close();
         }
         if ($commitIndex) {
             $index->commit();
         }
     } else {
         if ($actionName == "search_by_keyword") {
             require_once "Zend/Search/Lucene.php";
             $scope = "user";
             try {
                 $index = $this->loadIndex($repoId, false);
             } catch (Exception $ex) {
                 AJXP_XMLWriter::header();
                 if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) {
                     AJXP_Controller::applyActionInBackground($repoId, "index", array());
                     AJXP_XMLWriter::triggerBgAction("check_index_status", array("repository_id" => $repoId), sprintf($messages["index.lucene.8"], "/"), true, 2);
                 }
                 AJXP_XMLWriter::sendMessage($messages["index.lucene.7"], null);
                 AJXP_XMLWriter::close();
                 return null;
             }
             $sParts = array();
             $searchField = $httpVars["field"];
             if ($searchField == "ajxp_node") {
                 $sParts[] = "{$searchField}:yes";
             } else {
                 $sParts[] = "{$searchField}:true";
             }
             if ($scope == "user" && AuthService::usersEnabled()) {
                 if (AuthService::getLoggedUser() == null) {
                     throw new Exception("Cannot find current user");
                 }
                 $sParts[] = "ajxp_scope:user";
                 $sParts[] = "ajxp_user:"******"ajxp_scope:shared";
             }
             $query = implode(" AND ", $sParts);
             $this->logDebug("Query : {$query}");
             $hits = $index->find($query);
             $commitIndex = false;
             if (isset($httpVars['return_selection'])) {
                 $returnNodes = array();
             } else {
                 AJXP_XMLWriter::header();
             }
             foreach ($hits as $hit) {
                 // Backward compat with old protocols
                 $hit->node_url = preg_replace("#ajxp\\.[a-z_]+://#", "pydio://", $hit->node_url);
                 if ($hit->serialized_metadata != null) {
                     $meta = unserialize(base64_decode($hit->serialized_metadata));
                     $tmpNode = new AJXP_Node(SystemTextEncoding::fromUTF8($hit->node_url), $meta);
                 } else {
                     $tmpNode = new AJXP_Node(SystemTextEncoding::fromUTF8($hit->node_url), array());
                     $tmpNode->loadNodeInfo();
                 }
                 if (!file_exists($tmpNode->getUrl())) {
                     $index->delete($hit->id);
                     $commitIndex = true;
                     continue;
                 }
                 if (!is_readable($tmpNode->getUrl())) {
                     continue;
                 }
                 $basename = basename($tmpNode->getPath());
                 $isLeaf = $tmpNode->isLeaf();
                 if (!$this->accessDriver->filterNodeName($tmpNode->getPath(), $basename, $isLeaf, array("d" => true, "f" => true))) {
                     continue;
                 }
                 $tmpNode->search_score = sprintf("%0.2f", $hit->score);
                 if (isset($returnNodes)) {
                     $returnNodes[] = $tmpNode;
                 } else {
                     AJXP_XMLWriter::renderAjxpNode($tmpNode);
                 }
             }
             if (!isset($returnNodes)) {
                 AJXP_XMLWriter::close();
             }
             if ($commitIndex) {
                 $index->commit();
             }
         }
     }
     if (isset($returnNodes)) {
         return $returnNodes;
     } else {
         return null;
     }
 }
コード例 #16
0
 /**
  * @param AJXP_Node $node
  * @return String md5
  */
 public function getFileHash($node)
 {
     if ($node->isLeaf()) {
         $md5 = null;
         if ($this->metaStore != false) {
             $hashMeta = $this->metaStore->retrieveMetadata($node, FileHasher::METADATA_HASH_NAMESPACE, false, AJXP_METADATA_SCOPE_GLOBAL);
             $mtime = filemtime($node->getUrl());
             if (is_array($hashMeta) && array_key_exists("md5", $hashMeta) && array_key_exists("md5_mtime", $hashMeta) && $hashMeta["md5_mtime"] >= $mtime) {
                 $md5 = $hashMeta["md5"];
             }
             if ($md5 == null) {
                 $md5 = md5_file($node->getUrl());
                 $hashMeta = array("md5" => $md5, "md5_mtime" => $mtime);
                 $this->metaStore->setMetadata($node, FileHasher::METADATA_HASH_NAMESPACE, $hashMeta, false, AJXP_METADATA_SCOPE_GLOBAL);
             }
         } else {
             $md5 = md5_file($node->getUrl());
         }
         $node->mergeMetadata(array("md5" => $md5));
         return $md5;
     } else {
         return 'directory';
     }
 }
コード例 #17
0
 /**
  * @static
  * @param AJXP_Node $ajxpNode
  * @param bool $close
  * @return void
  */
 static function renderAjxpNode($ajxpNode, $close = true)
 {
     AJXP_XMLWriter::renderNode($ajxpNode->getPath(), $ajxpNode->getLabel(), $ajxpNode->isLeaf(), $ajxpNode->metadata, $close);
 }