/** * * @param AJXP_Node $oldFile * @param AJXP_Node $newFile * @param Boolean $copy */ public function moveMeta($oldFile, $newFile = null, $copy = false) { if ($oldFile == null) { return; } $feedStore = AJXP_PluginsService::getInstance()->getUniqueActivePluginForType("feed"); if ($feedStore !== false) { $feedStore->updateMetaObject($oldFile->getRepositoryId(), $oldFile->getPath(), $newFile != null ? $newFile->getPath() : null, $copy); return; } if (!$copy && $this->metaStore->inherentMetaMove()) { return; } $oldMeta = $this->metaStore->retrieveMetadata($oldFile, AJXP_META_SPACE_COMMENTS); if (!count($oldMeta)) { return; } // If it's a move or a delete, delete old data if (!$copy) { $this->metaStore->removeMetadata($oldFile, AJXP_META_SPACE_COMMENTS); } // If copy or move, copy data. if ($newFile != null) { $this->metaStore->setMetadata($newFile, AJXP_META_SPACE_COMMENTS, $oldMeta); } }
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); }
/** * @return string */ public function getMainLink() { $repoId = $this->getNode()->getRepositoryId(); if (isset($_SESSION["CURRENT_MINISITE"])) { $hash = $_SESSION["CURRENT_MINISITE"]; $shareCenter = ShareCenter::getShareCenter(); if (!empty($shareCenter)) { return $shareCenter->buildPublicletLink($hash); } } return trim(AJXP_Utils::detectServerURL(true), "/") . "/?goto=" . $repoId . $this->node->getPath(); }
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); }
/** * * @param AJXP_Node $node * @param int $depth * @throws Exception */ public function recursiveIndexation($node, $depth = 0) { $repository = $node->getRepository(); $user = $node->getUser(); $messages = ConfService::getMessages(); if ($user == null && AuthService::usersEnabled()) { $user = AuthService::getLoggedUser(); } if ($depth == 0) { $this->logDebug("Starting indexation - node.index.recursive.start - " . memory_get_usage(true) . " - " . $node->getUrl()); $this->setIndexStatus("RUNNING", str_replace("%s", $node->getPath(), $messages["core.index.8"]), $repository, $user); AJXP_Controller::applyHook("node.index.recursive.start", array($node)); } else { if ($this->isInterruptRequired($repository, $user)) { $this->logDebug("Interrupting indexation! - node.index.recursive.end - " . $node->getUrl()); AJXP_Controller::applyHook("node.index.recursive.end", array($node)); $this->releaseStatus($repository, $user); throw new Exception("User interrupted"); } } if (!ConfService::currentContextIsCommandLine()) { @set_time_limit(120); } $url = $node->getUrl(); $this->logDebug("Indexing Node parent node " . $url); $this->setIndexStatus("RUNNING", str_replace("%s", $node->getPath(), $messages["core.index.8"]), $repository, $user); try { AJXP_Controller::applyHook("node.index", array($node)); } catch (Exception $e) { $this->logDebug("Error Indexing Node " . $url . " (" . $e->getMessage() . ")"); } $handle = opendir($url); if ($handle !== false) { while (($child = readdir($handle)) != false) { if ($child[0] == ".") { continue; } $childNode = new AJXP_Node(rtrim($url, "/") . "/" . $child); $childUrl = $childNode->getUrl(); if (is_dir($childUrl)) { $this->logDebug("Entering recursive indexation for " . $childUrl); $this->recursiveIndexation($childNode, $depth + 1); } else { try { $this->logDebug("Indexing Node " . $childUrl); AJXP_Controller::applyHook("node.index", array($childNode)); } catch (Exception $e) { $this->logDebug("Error Indexing Node " . $childUrl . " (" . $e->getMessage() . ")"); } } } closedir($handle); } else { $this->logDebug("Cannot open {$url}!!"); } if ($depth == 0) { $this->logDebug("End indexation - node.index.recursive.end - " . memory_get_usage(true) . " - " . $node->getUrl()); $this->setIndexStatus("RUNNING", "Indexation finished, cleaning...", $repository, $user); AJXP_Controller::applyHook("node.index.recursive.end", array($node)); $this->releaseStatus($repository, $user); $this->logDebug("End indexation - After node.index.recursive.end - " . memory_get_usage(true) . " - " . $node->getUrl()); } }
/** * @param AJXP_Node $origNode * @param AJXP_Node $newNode * @param bool $copy */ public function publishNodeChange($origNode = null, $newNode = null, $copy = false) { $content = ""; $repo = ""; $targetUserId = null; $nodePathes = array(); $update = false; if ($newNode != null) { $repo = $newNode->getRepositoryId(); $targetUserId = $newNode->getUser(); $nodePathes[] = $newNode->getPath(); $update = false; $data = array(); if ($origNode != null && !$copy) { $update = true; $data[$origNode->getPath()] = $newNode; } else { $data[] = $newNode; } $content = AJXP_XMLWriter::writeNodesDiff(array($update ? "UPDATE" : "ADD" => $data)); } if ($origNode != null && !$update && !$copy) { $repo = $origNode->getRepositoryId(); $targetUserId = $origNode->getUser(); $nodePathes[] = $origNode->getPath(); $content = AJXP_XMLWriter::writeNodesDiff(array("REMOVE" => array($origNode->getPath()))); } if (!empty($content) && $repo != "") { $this->sendInstantMessage($content, $repo, $targetUserId, null, $nodePathes); } }
/** * Hook node.change * @param AJXP_Node $oldNode * @param AJXP_Node $newNode * @param bool $copy */ public function updateNodeSharedData($oldNode = null, $newNode = null, $copy = false) { if ($oldNode == null || $copy) { // Create or copy, do nothing return; } if ($oldNode != null && $newNode != null && $oldNode->getUrl() == $newNode->getUrl()) { // Same path => must be a content update, do nothing return; } $this->logDebug("Should update node"); $delete = false; if ($newNode == null) { $delete = true; } else { $repo = $newNode->getRepository(); $recycle = $repo->getOption("RECYCLE_BIN"); if (!empty($recycle) && strpos($newNode->getPath(), $recycle) === 1) { $delete = true; } } $shareStore = $this->getShareStore(); $modifiedNodes = $shareStore->moveSharesFromMetaRecursive($oldNode, $delete, $oldNode->getPath(), $newNode != null ? $newNode->getPath() : null); // Force switching back to correct driver! if ($modifiedNodes > 0) { $oldNode->getRepository()->driverInstance = null; $oldNode->setDriver(null); $oldNode->getDriver(); } return; }
/** * @param AJXP_Node $ajxpNode * @param string $nameSpace * @param string $userScope * @return array */ public function collectChildrenWithRepositoryMeta($ajxpNode, $nameSpace, $userScope) { $result = array(); $repositoryId = $ajxpNode->getRepositoryId(); $metaFile = $this->globalMetaFile . "_" . $repositoryId; $metaFile = $this->updateSecurityScope($metaFile, $ajxpNode->getRepositoryId(), $ajxpNode->getUser()); if (!is_file($metaFile)) { return $result; } $raw_data = file_get_contents($metaFile); if ($raw_data === false) { return $result; } $metadata = unserialize($raw_data); if ($metadata === false || !is_array($metadata)) { return $result; } $srcPath = $ajxpNode->getPath(); if ($srcPath == "/") { $srcPath = ""; } foreach ($metadata as $path => $data) { preg_match("#^" . preg_quote($srcPath, "#") . "/#", $path, $matches); if ($path == $srcPath || count($matches)) { $relativePath = substr($path, strlen($srcPath)); // REMOVE ORIGINAL NODE PATH if ($relativePath === false) { $relativePath = "/"; } foreach ($data as $userId => $meta) { if (($userScope == $userId || $userScope == AJXP_METADATA_ALLUSERS) && isset($meta[$nameSpace])) { if (!isset($result[$relativePath])) { $result[$relativePath] = array(); } $result[$relativePath][$userId] = $meta[$nameSpace]; } } } } return $result; }
/** * @param AJXP_Node $ajxpNode */ public function videoAlternateVersions(&$ajxpNode) { if (!preg_match('/\\.mpg$|\\.mp4$|\\.ogv$|\\.webm$/i', $ajxpNode->getLabel())) { return; } if (file_exists(str_replace(".mpg", "_PREVIEW.mp4", $ajxpNode->getUrl()))) { $ajxpNode->mergeMetadata(array("video_altversion_mp4" => str_replace(".mpg", "_PREVIEW.mp4", $ajxpNode->getPath()))); } $rotating = array("mp4", "ogv", "webm"); foreach ($rotating as $ext) { if (preg_match('/\\.' . $ext . '$/i', $ajxpNode->getLabel())) { foreach ($rotating as $other) { if ($other == $ext) { continue; } if (file_exists(str_replace($ext, $other, $ajxpNode->getUrl()))) { $ajxpNode->mergeMetadata(array("video_altversion_" . $other => str_replace($ext, $other, $ajxpNode->getPath()))); } } } } }
/** * @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()); } } }
/** * @param AJXP_Node $ajxpNode * @return void */ public function nodeBookmarkMetadata(&$ajxpNode) { $user = AuthService::getLoggedUser(); if ($user == null) { return; } $metadata = $ajxpNode->retrieveMetadata("ajxp_bookmarked", true, AJXP_METADATA_SCOPE_REPOSITORY, true); if (is_array($metadata) && count($metadata)) { $ajxpNode->mergeMetadata(array("ajxp_bookmarked" => "true", "overlay_icon" => "bookmark.png", "overlay_class" => "icon-bookmark-empty"), true); return; } if (!isset(self::$loadedBookmarks)) { self::$loadedBookmarks = $user->getBookmarks(); } foreach (self::$loadedBookmarks as $bm) { if ($bm["PATH"] == $ajxpNode->getPath()) { $ajxpNode->mergeMetadata(array("ajxp_bookmarked" => "true", "overlay_icon" => "bookmark.png", "overlay_class" => "icon-bookmark-empty"), true); $ajxpNode->setMetadata("ajxp_bookmarked", array("ajxp_bookmarked" => "true"), true, AJXP_METADATA_SCOPE_REPOSITORY, true); } } }
/** * @param AJXP_Node $ajxpNode * @param String $scope * @param String $userId */ protected function saveMetaFileData($ajxpNode, $scope, $userId) { $currentFile = $ajxpNode->getUrl(); $repositoryId = $ajxpNode->getRepositoryId(); $fileKey = $ajxpNode->getPath(); if (isset($this->options["METADATA_FILE_LOCATION"]) && $this->options["METADATA_FILE_LOCATION"] == "outside") { // Force scope $scope = AJXP_METADATA_SCOPE_REPOSITORY; } if ($scope == AJXP_METADATA_SCOPE_GLOBAL) { $metaFile = dirname($currentFile) . "/" . $this->options["METADATA_FILE"]; $fileKey = basename($fileKey); } else { if (!is_dir(dirname($this->globalMetaFile))) { mkdir(dirname($this->globalMetaFile), 0755, true); } $metaFile = $this->globalMetaFile . "_" . $repositoryId; } if (@is_file($metaFile) && call_user_func(array($this->accessDriver, "isWriteable"), $metaFile) || call_user_func(array($this->accessDriver, "isWriteable"), dirname($metaFile)) || $scope == "repository") { if (!isset(self::$fullMetaCache[$fileKey])) { self::$fullMetaCache[$fileKey] = array(); } if (!isset(self::$fullMetaCache[$fileKey][$userId])) { self::$fullMetaCache[$fileKey][$userId] = array(); } self::$fullMetaCache[$fileKey][$userId] = self::$metaCache; $fp = fopen($metaFile, "w"); if ($fp !== false) { @fwrite($fp, serialize(self::$fullMetaCache), strlen(serialize(self::$fullMetaCache))); @fclose($fp); } if ($scope == AJXP_METADATA_SCOPE_GLOBAL) { AJXP_Controller::applyHook("version.commit_file", array($metaFile, $ajxpNode)); } } }
/** * @param AJXP_Node $ajxpNode * @return */ function nodeBookmarkMetadata(&$ajxpNode) { $user = AuthService::getLoggedUser(); if ($user == null) { return; } if (!isset(self::$loadedBookmarks)) { self::$loadedBookmarks = $user->getBookmarks(); } foreach (self::$loadedBookmarks as $bm) { if ($bm["PATH"] == $ajxpNode->getPath()) { $ajxpNode->mergeMetadata(array("ajxp_bookmarked" => "true", "overlay_icon" => "bookmark.png"), true); /* * TESTING MULTIPLE OVERLAYS $ajxpNode->mergeMetadata(array( "overlay_icon" => "shared.png" ), true); */ } } }
/** * @param AJXP_Node $ajxpNode * @param bool $parentNode * @param bool $details * @return void */ public function loadNodeInfo(&$ajxpNode, $parentNode = false, $details = false) { $nodeName = basename($ajxpNode->getPath()); $metaData = $ajxpNode->metadata; if (!isset($metaData["is_file"])) { $isLeaf = is_file($ajxpNode->getUrl()) || AJXP_Utils::isBrowsableArchive($nodeName); $metaData["is_file"] = $isLeaf ? "1" : "0"; } else { $isLeaf = $metaData["is_file"] == "1" ? true : false; } $metaData["filename"] = $ajxpNode->getPath(); if (RecycleBinManager::recycleEnabled() && $ajxpNode->getPath() == RecycleBinManager::getRelativeRecycle()) { $mess = ConfService::getMessages(); $recycleIcon = $this->countFiles($ajxpNode->getUrl(), false, true) > 0 ? "trashcan_full.png" : "trashcan.png"; $metaData["icon"] = $recycleIcon; $metaData["mimestring"] = $mess[122]; $ajxpNode->setLabel($mess[122]); $metaData["ajxp_mime"] = "ajxp_recycle"; } else { $mimeData = AJXP_Utils::mimeData($ajxpNode->getUrl(), !$isLeaf); $metaData["mimestring_id"] = $mimeData[0]; //AJXP_Utils::mimetype($ajxpNode->getUrl(), "type", !$isLeaf); $metaData["icon"] = $mimeData[1]; //AJXP_Utils::mimetype($nodeName, "image", !$isLeaf); if ($metaData["icon"] == "folder.png") { $metaData["openicon"] = "folder_open.png"; } if (!$isLeaf) { $metaData["ajxp_mime"] = "ajxp_folder"; } } //if ($lsOptions["l"]) { $metaData["file_group"] = @filegroup($ajxpNode->getUrl()) || "unknown"; $metaData["file_owner"] = @fileowner($ajxpNode->getUrl()) || "unknown"; $crtPath = $ajxpNode->getPath(); $vRoots = $this->repository->listVirtualRoots(); if (!empty($crtPath)) { if (!@$this->isWriteable($ajxpNode->getUrl())) { $metaData["ajxp_readonly"] = "true"; } if (isset($vRoots[ltrim($crtPath, "/")])) { $metaData["ajxp_readonly"] = $vRoots[ltrim($crtPath, "/")]["right"] == "r" ? "true" : "false"; } } else { if (count($vRoots)) { $metaData["ajxp_readonly"] = "true"; } } $fPerms = @fileperms($ajxpNode->getUrl()); if ($fPerms !== false) { $fPerms = substr(decoct($fPerms), $isLeaf ? 2 : 1); } else { $fPerms = '0000'; } $metaData["file_perms"] = $fPerms; $datemodif = $this->date_modif($ajxpNode->getUrl()); $metaData["ajxp_modiftime"] = $datemodif ? $datemodif : "0"; $metaData["bytesize"] = 0; if ($isLeaf) { $metaData["bytesize"] = $this->filesystemFileSize($ajxpNode->getUrl()); } $metaData["filesize"] = AJXP_Utils::roundSize($metaData["bytesize"]); if (AJXP_Utils::isBrowsableArchive($nodeName)) { $metaData["ajxp_mime"] = "ajxp_browsable_archive"; } if ($details == "minimal") { $miniMeta = array("is_file" => $metaData["is_file"], "filename" => $metaData["filename"], "bytesize" => $metaData["bytesize"], "ajxp_modiftime" => $metaData["ajxp_modiftime"]); $ajxpNode->mergeMetadata($miniMeta); } else { $ajxpNode->mergeMetadata($metaData); } }
/** * Find all existing lucene documents based on the parent url * @param Zend_Search_Lucene_Interface $index * @param AJXP_Node $ajxpNode * @return Zend_Search_Lucene_Search_QueryHit */ public function getIndexedChildrenDocuments($index, $ajxpNode) { // Try getting doc by url $testQ = str_replace("/", "AJXPFAKESEP", SystemTextEncoding::toUTF8($ajxpNode->getPath())); $pattern = new Zend_Search_Lucene_Index_Term($testQ . '*', 'node_path'); $query = new Zend_Search_Lucene_Search_Query_Wildcard($pattern); $hits = $index->find($query); return $hits; }
/** * @param AJXP_Node $oldNode * @param AJXP_Node $newNode * @param bool $copy * @param string $targetNotif * @return AJXP_Notification */ public function generateNotificationFromChangeHook(AJXP_Node $oldNode = null, AJXP_Node $newNode = null, $copy = false, $targetNotif = "new") { $type = ""; $primaryNode = null; $secondNode = null; $notif = new AJXP_Notification(); if ($oldNode == null) { if ($targetNotif == "old") { return false; } $type = AJXP_NOTIF_NODE_ADD; $primaryNode = $newNode; } else { if ($newNode == null) { if ($targetNotif == "new") { return false; } $type = AJXP_NOTIF_NODE_DEL; $primaryNode = $oldNode; } else { if ($oldNode->getUrl() == $newNode->getUrl()) { $type = AJXP_NOTIF_NODE_CHANGE; $primaryNode = $newNode; } else { if (dirname($oldNode->getPath()) == dirname($newNode->getPath())) { $type = AJXP_NOTIF_NODE_RENAME; $primaryNode = $newNode; $secondNode = $oldNode; } else { if ($targetNotif == "new") { $type = $copy ? AJXP_NOTIF_NODE_COPY_FROM : AJXP_NOTIF_NODE_MOVE_FROM; $primaryNode = $newNode; $secondNode = $oldNode; } else { if ($targetNotif == "old") { $type = $copy ? AJXP_NOTIF_NODE_COPY_TO : AJXP_NOTIF_NODE_MOVE_TO; $primaryNode = $oldNode; $secondNode = $newNode; } else { if ($targetNotif == "unify") { $type = $copy ? AJXP_NOTIF_NODE_COPY : AJXP_NOTIF_NODE_MOVE; $primaryNode = $newNode; $secondNode = $oldNode; } } } } } } } $notif->setNode($primaryNode); $notif->setAction($type); if ($secondNode != null) { $notif->setSecondaryNode($secondNode); } return $notif; }
/** * @return string */ public function getMainLink() { $repoId = $this->getNode()->getRepositoryId(); return AJXP_Utils::detectServerURL(true) . "/?goto=" . $repoId . $this->node->getPath(); }
/** * @param AJXP_Node $oldNode * @param AJXP_Node $newNode * @param bool $copy */ public function updateNodeSharedData($oldNode = null, $newNode = null, $copy = false) { if ($oldNode != null && !$copy) { $this->logDebug("Should update node"); $delete = false; if ($newNode == null) { $delete = true; } else { $repo = $newNode->getRepository(); $recycle = $repo->getOption("RECYCLE_BIN"); if (!empty($recycle) && strpos($newNode->getPath(), $recycle) === 1) { $delete = true; } } $this->getSharesFromMeta($oldNode, $shares, true); if (empty($shares)) { return; } $newShares = array(); foreach ($shares as $id => $data) { $type = $data["type"]; if ($delete) { $this->getShareStore()->deleteShare($type, $id); continue; } if ($type == "minisite") { $share = $this->getShareStore()->loadShare($id); $repo = ConfService::getRepositoryById($share["REPOSITORY"]); } else { if ($type == "repository") { $repo = ConfService::getRepositoryById($id); } else { if ($type == "file") { $publicLink = $this->getShareStore()->loadShare($id); } } } if (isset($repo)) { $cFilter = $repo->getContentFilter(); $path = $repo->getOption("PATH", true); $save = false; if (isset($cFilter)) { $cFilter->movePath($oldNode->getPath(), $newNode->getPath()); $repo->setContentFilter($cFilter); $save = true; } else { if (!empty($path)) { $path = str_replace($oldNode->getPath(), $newNode->getPath(), $path); $repo->addOption("PATH", $path); $save = true; } } if ($save) { ConfService::getConfStorageImpl()->saveRepository($repo, true); $newShares[$id] = $data; } } else { if (isset($publicLink["FILE_PATH"])) { $publicLink["FILE_PATH"] = str_replace($oldNode->getPath(), $newNode->getPath(), $publicLink["FILE_PATH"]); $this->getShareStore()->deleteShare("file", $id); $this->getShareStore()->storeShare($newNode->getRepositoryId(), $publicLink, "file", $id); $newShares[$id] = $data; } } } $oldNode->removeMetadata("ajxp_shared", true, AJXP_METADATA_SCOPE_REPOSITORY, true); if ($newNode != null && count($newShares)) { $newNode->setMetadata("ajxp_shared", array("shares" => $newShares), true, AJXP_METADATA_SCOPE_REPOSITORY, true); } } }
/** * @param array $shares * @param String $operation * @param AJXP_Node $oldNode * @param AJXP_Node $newNode * @param array $collectRepositories * @param string|null $parentRepositoryPath * @return array * @throws Exception */ public function moveSharesFromMeta($shares, $operation = "move", $oldNode, $newNode = null, &$collectRepositories = array(), $parentRepositoryPath = null) { $privateShares = array(); $publicShares = array(); foreach ($shares as $id => $data) { $type = $data["type"]; if ($operation == "delete") { $this->deleteShare($type, $id, false, true); continue; } if ($type == "minisite") { $share = $this->loadShare($id); $repo = ConfService::getRepositoryById($share["REPOSITORY"]); } else { if ($type == "repository") { $repo = ConfService::getRepositoryById($id); } else { if ($type == "file") { $publicLink = $this->loadShare($id); } } } if (isset($repo)) { $oldNodeLabel = SystemTextEncoding::toUTF8($oldNode->getLabel()); $newNodeLabel = SystemTextEncoding::toUTF8($newNode->getLabel()); if ($newNode != null && $newNodeLabel != $oldNodeLabel && $repo->getDisplay() == $oldNodeLabel) { $repo->setDisplay($newNodeLabel); } $cFilter = $repo->getContentFilter(); $path = $repo->getOption("PATH", true); $save = false; if (isset($cFilter)) { if ($parentRepositoryPath !== null) { $repo->addOption("PATH", $parentRepositoryPath); } else { $cFilter->movePath($oldNode->getPath(), $newNode->getPath()); $repo->setContentFilter($cFilter); } $save = true; } else { if (!empty($path)) { $oldNodePath = SystemTextEncoding::toUTF8($oldNode->getPath()); $newNodePath = SystemTextEncoding::toUTF8($newNode->getPath()); $path = preg_replace("#" . preg_quote($oldNodePath, "#") . "\$#", $newNodePath, $path); $repo->addOption("PATH", $path); $save = true; $collectRepositories[$repo->getId()] = $path; } } if ($save) { //ConfService::getConfStorageImpl()->saveRepository($repo, true); ConfService::replaceRepository($repo->getId(), $repo); } $access = $repo->getOption("SHARE_ACCESS"); if (!empty($access) && $access == "PUBLIC") { $publicShares[$id] = $data; } else { $privateShares[$id] = $data; } } else { if (isset($publicLink) && is_array($publicLink) && isset($publicLink["FILE_PATH"])) { $oldNodePath = SystemTextEncoding::toUTF8($oldNode->getPath()); $newNodePath = SystemTextEncoding::toUTF8($newNode->getPath()); $publicLink["FILE_PATH"] = str_replace($oldNodePath, $newNodePath, $publicLink["FILE_PATH"]); $this->deleteShare("file", $id); $this->storeShare($newNode->getRepositoryId(), $publicLink, "file", $id); $privateShares[$id] = $data; } } } return array($privateShares, $publicShares); }
protected function listPreviewFiles($file, $prefix) { $files = array(); $index = 0; $unoconv = $this->getFilteredOption("UNOCONV"); if (!empty($unoconv)) { $officeExt = array('xls', 'xlsx', 'ods', 'doc', 'docx', 'odt', 'ppt', 'pptx', 'odp', 'rtf'); $extension = pathinfo($file, PATHINFO_EXTENSION); if (in_array(strtolower($extension), $officeExt)) { $unoDoc = $prefix . "_unoconv.pdf"; if (is_file($unoDoc)) { $file = $unoDoc; } } } $count = $this->countPages($file); $n = new AJXP_Node($file); $path = $n->getPath(); while ($index < $count) { $extract = $prefix . "-" . $index . ".jpg"; list($width, $height, $type, $attr) = @getimagesize($extract); $files[] = array("file" => basename($extract), "width" => $width, "height" => $height, "rest" => "/get_extracted_page/" . basename($extract) . str_replace("%2F", "/", urlencode($path))); $index++; } if (is_file($prefix . ".jpg")) { $extract = $prefix . ".jpg"; list($width, $height, $type, $attr) = @getimagesize($extract); $files[] = array("file" => basename($extract), "width" => $width, "height" => $height, "rest" => "/get_extracted_page/" . basename($extract) . str_replace("%2F", "/", urlencode($path))); } return $files; }
/** * @param AJXP_Node $ajxpNode * @return void */ public function enrichNode(&$ajxpNode) { // Try both $aws = $this->getAwsService(); if ($aws == null) { return; } if (isset(self::$metaCache[$ajxpNode->getPath()])) { $data = self::$metaCache[$ajxpNode->getPath()]; } else { AJXP_Logger::debug("Should retrieve metadata for " . $ajxpNode->getPath()); $response = $aws->get_object_metadata($this->bucketName, ltrim($ajxpNode->getPath(), "/")); self::$metaCache[$ajxpNode->getPath()] = $response["Headers"]; $data = self::$metaCache[$ajxpNode->getPath()]; } $allMeta = array(); foreach ($data as $amzKey => $value) { $parts = explode("-", $amzKey); $all[$parts[0]] = $value; } $ajxpNode->mergeMetadata($allMeta); }
/** * @param AJXP_Node $ajxpNode */ public function hideExtension(&$ajxpNode) { if ($ajxpNode->hasExtension("pad")) { $baseName = AJXP_Utils::safeBasename($ajxpNode->getPath()); $ajxpNode->setLabel(str_replace(".pad", "", $baseName)); } }
/** * @param AJXP_Node $node * @return String */ function externalPath(AJXP_Node $node) { return $this->getVirtualPath($node->getPath()); }
/** * @param AJXP_Node $ajxpNode * @param String $scope * @param String $userId */ protected function saveMetaFileData($ajxpNode, $scope, $userId) { $currentFile = $ajxpNode->getUrl(); $repositoryId = $ajxpNode->getRepositoryId(); $fileKey = $ajxpNode->getPath(); if (isset($this->options["METADATA_FILE_LOCATION"]) && $this->options["METADATA_FILE_LOCATION"] == "outside") { // Force scope $scope = AJXP_METADATA_SCOPE_REPOSITORY; } if ($scope == AJXP_METADATA_SCOPE_GLOBAL) { $metaFile = dirname($currentFile) . "/" . $this->options["METADATA_FILE"]; $fileKey = basename($fileKey); } else { if (!is_dir(dirname($this->globalMetaFile))) { mkdir(dirname($this->globalMetaFile), 0755, true); } $metaFile = $this->globalMetaFile . "_" . $repositoryId; $metaFile = $this->updateSecurityScope($metaFile, $ajxpNode->getRepositoryId(), $ajxpNode->getUser()); } if ($scope == AJXP_METADATA_SCOPE_REPOSITORY || @is_file($metaFile) && call_user_func(array($this->accessDriver, "isWriteable"), $metaFile) || call_user_func(array($this->accessDriver, "isWriteable"), dirname($metaFile))) { if (is_array(self::$metaCache) && count(self::$metaCache)) { if (!isset(self::$fullMetaCache[$metaFile])) { self::$fullMetaCache[$metaFile] = array(); } if (!isset(self::$fullMetaCache[$metaFile][$fileKey])) { self::$fullMetaCache[$metaFile][$fileKey] = array(); } if (!isset(self::$fullMetaCache[$metaFile][$fileKey][$userId])) { self::$fullMetaCache[$metaFile][$fileKey][$userId] = array(); } self::$fullMetaCache[$metaFile][$fileKey][$userId] = self::$metaCache; } else { // CLEAN if (isset(self::$fullMetaCache[$metaFile][$fileKey][$userId])) { unset(self::$fullMetaCache[$metaFile][$fileKey][$userId]); } if (isset(self::$fullMetaCache[$metaFile][$fileKey]) && !count(self::$fullMetaCache[$metaFile][$fileKey])) { unset(self::$fullMetaCache[$metaFile][$fileKey]); } } $fp = @fopen($metaFile, "w"); if ($fp !== false) { @fwrite($fp, serialize(self::$fullMetaCache[$metaFile]), strlen(serialize(self::$fullMetaCache[$metaFile]))); @fclose($fp); } else { $this->logError(__FUNCTION__, "Error while trying to open the meta file, maybe a permission problem?"); } if ($scope == AJXP_METADATA_SCOPE_GLOBAL) { AJXP_Controller::applyHook("version.commit_file", array($metaFile, $ajxpNode)); } } }
/** * @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); }
/** * Find all existing lucene documents based on the parent url * @param AJXP_Node $ajxpNode * @return Elastica\ResultSet */ public function getIndexedChildrenDocuments($ajxpNode) { $testQ = str_replace("/", "AJXPFAKESEP", SystemTextEncoding::toUTF8($ajxpNode->getPath() . "/")); /* we use a wildcard query to fetch all children documents relatively to their paths */ $query = new Elastica\Query\Wildcard("node_path", $testQ . "*"); /* returns a result set from the query */ $results = $this->currentIndex->search($query); if ($results->getTotalHits() == 0) { return null; } return $results; }
/** * @param String $action * @param Array $httpVars * @param Array $fileVars * @throws Exception */ public function receiveAction($action, $httpVars, $fileVars) { //VAR CREATION OUTSIDE OF ALL CONDITIONS, THEY ARE "MUST HAVE" VAR !! $messages = ConfService::getMessages(); $repository = ConfService::getRepository(); $userSelection = new UserSelection($repository, $httpVars); $nodes = $userSelection->buildNodes(); $currentDirPath = AJXP_Utils::safeDirname($userSelection->getUniqueNode()->getPath()); $currentDirPath = rtrim($currentDirPath, "/") . "/"; $currentDirUrl = $userSelection->currentBaseUrl() . $currentDirPath; if (empty($httpVars["compression_id"])) { $compressionId = sha1(rand()); $httpVars["compression_id"] = $compressionId; } else { $compressionId = $httpVars["compression_id"]; } $progressCompressionFileName = $this->getPluginCacheDir(false, true) . DIRECTORY_SEPARATOR . "progressCompressionID-" . $compressionId . ".txt"; if (empty($httpVars["extraction_id"])) { $extractId = sha1(rand()); $httpVars["extraction_id"] = $extractId; } else { $extractId = $httpVars["extraction_id"]; } $progressExtractFileName = $this->getPluginCacheDir(false, true) . DIRECTORY_SEPARATOR . "progressExtractID-" . $extractId . ".txt"; if ($action == "compression") { $archiveName = AJXP_Utils::sanitize(AJXP_Utils::decodeSecureMagic($httpVars["archive_name"]), AJXP_SANITIZE_FILENAME); $archiveFormat = $httpVars["type_archive"]; $tabTypeArchive = array(".tar", ".tar.gz", ".tar.bz2"); $acceptedExtension = false; foreach ($tabTypeArchive as $extensionArchive) { if ($extensionArchive == $archiveFormat) { $acceptedExtension = true; break; } } if ($acceptedExtension == false) { file_put_contents($progressCompressionFileName, "Error : " . $messages["compression.16"]); throw new AJXP_Exception($messages["compression.16"]); } $typeArchive = $httpVars["type_archive"]; //if we can run in background we do it if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) { $archivePath = $currentDirPath . $archiveName; file_put_contents($progressCompressionFileName, $messages["compression.5"]); AJXP_Controller::applyActionInBackground($repository->getId(), "compression", $httpVars); AJXP_XMLWriter::header(); AJXP_XMLWriter::triggerBgAction("check_compression_status", array("repository_id" => $repository->getId(), "compression_id" => $compressionId, "archive_path" => SystemTextEncoding::toUTF8($archivePath)), $messages["compression.5"], true, 2); AJXP_XMLWriter::close(); return null; } else { $maxAuthorizedSize = 4294967296; $currentDirUrlLength = strlen($currentDirUrl); $tabFolders = array(); $tabAllRecursiveFiles = array(); $tabFilesNames = array(); foreach ($nodes as $node) { $nodeUrl = $node->getUrl(); if (is_file($nodeUrl) && filesize($nodeUrl) < $maxAuthorizedSize) { array_push($tabAllRecursiveFiles, $nodeUrl); array_push($tabFilesNames, substr($nodeUrl, $currentDirUrlLength)); } if (is_dir($nodeUrl)) { array_push($tabFolders, $nodeUrl); } } //DO A FOREACH OR IT'S GONNA HAVE SOME SAMES FILES NAMES foreach ($tabFolders as $value) { $dossiers = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($value)); foreach ($dossiers as $file) { if ($file->isDir()) { continue; } array_push($tabAllRecursiveFiles, $file->getPathname()); array_push($tabFilesNames, substr($file->getPathname(), $currentDirUrlLength)); } } //WE STOP IF IT'S JUST AN EMPTY FOLDER OR NO FILES if (empty($tabFilesNames)) { file_put_contents($progressCompressionFileName, "Error : " . $messages["compression.17"]); throw new AJXP_Exception($messages["compression.17"]); } try { $tmpArchiveName = tempnam(AJXP_Utils::getAjxpTmpDir(), "tar-compression") . ".tar"; $archive = new PharData($tmpArchiveName); } catch (Exception $e) { file_put_contents($progressCompressionFileName, "Error : " . $e->getMessage()); throw $e; } $counterCompression = 0; //THE TWO ARRAY ARE MERGED FOR THE FOREACH LOOP $tabAllFiles = array_combine($tabAllRecursiveFiles, $tabFilesNames); foreach ($tabAllFiles as $fullPath => $fileName) { try { $archive->addFile(AJXP_MetaStreamWrapper::getRealFSReference($fullPath), $fileName); $counterCompression++; file_put_contents($progressCompressionFileName, sprintf($messages["compression.6"], round($counterCompression / count($tabAllFiles) * 100, 0, PHP_ROUND_HALF_DOWN) . " %")); } catch (Exception $e) { unlink($tmpArchiveName); file_put_contents($progressCompressionFileName, "Error : " . $e->getMessage()); throw $e; } } $finalArchive = $tmpArchiveName; if ($typeArchive != ".tar") { $archiveTypeCompress = substr(strrchr($typeArchive, "."), 1); file_put_contents($progressCompressionFileName, sprintf($messages["compression.7"], strtoupper($archiveTypeCompress))); if ($archiveTypeCompress == "gz") { $archive->compress(Phar::GZ); } elseif ($archiveTypeCompress == "bz2") { $archive->compress(Phar::BZ2); } $finalArchive = $tmpArchiveName . "." . $archiveTypeCompress; } $destArchive = AJXP_MetaStreamWrapper::getRealFSReference($currentDirUrl . $archiveName); rename($finalArchive, $destArchive); AJXP_Controller::applyHook("node.before_create", array($destArchive, filesize($destArchive))); if (file_exists($tmpArchiveName)) { unlink($tmpArchiveName); unlink(substr($tmpArchiveName, 0, -4)); } $newNode = new AJXP_Node($currentDirUrl . $archiveName); AJXP_Controller::applyHook("node.change", array(null, $newNode, false)); file_put_contents($progressCompressionFileName, "SUCCESS"); } } elseif ($action == "check_compression_status") { $archivePath = AJXP_Utils::decodeSecureMagic($httpVars["archive_path"]); $progressCompression = file_get_contents($progressCompressionFileName); $substrProgressCompression = substr($progressCompression, 0, 5); if ($progressCompression != "SUCCESS" && $substrProgressCompression != "Error") { AJXP_XMLWriter::header(); AJXP_XMLWriter::triggerBgAction("check_compression_status", array("repository_id" => $repository->getId(), "compression_id" => $compressionId, "archive_path" => SystemTextEncoding::toUTF8($archivePath)), $progressCompression, true, 5); AJXP_XMLWriter::close(); } elseif ($progressCompression == "SUCCESS") { $newNode = new AJXP_Node($userSelection->currentBaseUrl() . $archivePath); $nodesDiffs = array("ADD" => array($newNode), "REMOVE" => array(), "UPDATE" => array()); AJXP_Controller::applyHook("node.change", array(null, $newNode, false)); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage($messages["compression.8"], null); AJXP_XMLWriter::writeNodesDiff($nodesDiffs, true); AJXP_XMLWriter::close(); if (file_exists($progressCompressionFileName)) { unlink($progressCompressionFileName); } } elseif ($substrProgressCompression == "Error") { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $progressCompression); AJXP_XMLWriter::close(); if (file_exists($progressCompressionFileName)) { unlink($progressCompressionFileName); } } } elseif ($action == "extraction") { $fileArchive = AJXP_Utils::sanitize(AJXP_Utils::decodeSecureMagic($httpVars["file"]), AJXP_SANITIZE_DIRNAME); $fileArchive = substr(strrchr($fileArchive, DIRECTORY_SEPARATOR), 1); $authorizedExtension = array("tar" => 4, "gz" => 7, "bz2" => 8); $acceptedArchive = false; $extensionLength = 0; $counterExtract = 0; $currentAllPydioPath = $currentDirUrl . $fileArchive; $pharCurrentAllPydioPath = "phar://" . AJXP_MetaStreamWrapper::getRealFSReference($currentAllPydioPath); $pathInfoCurrentAllPydioPath = pathinfo($currentAllPydioPath, PATHINFO_EXTENSION); //WE TAKE ONLY TAR, TAR.GZ AND TAR.BZ2 ARCHIVES foreach ($authorizedExtension as $extension => $strlenExtension) { if ($pathInfoCurrentAllPydioPath == $extension) { $acceptedArchive = true; $extensionLength = $strlenExtension; break; } } if ($acceptedArchive == false) { file_put_contents($progressExtractFileName, "Error : " . $messages["compression.15"]); throw new AJXP_Exception($messages["compression.15"]); } $onlyFileName = substr($fileArchive, 0, -$extensionLength); $lastPosOnlyFileName = strrpos($onlyFileName, "-"); $tmpOnlyFileName = substr($onlyFileName, 0, $lastPosOnlyFileName); $counterDuplicate = substr($onlyFileName, $lastPosOnlyFileName + 1); if (!is_int($lastPosOnlyFileName) || !is_int($counterDuplicate)) { $tmpOnlyFileName = $onlyFileName; $counterDuplicate = 1; } while (file_exists($currentDirUrl . $onlyFileName)) { $onlyFileName = $tmpOnlyFileName . "-" . $counterDuplicate; $counterDuplicate++; } if (ConfService::backgroundActionsSupported() && !ConfService::currentContextIsCommandLine()) { file_put_contents($progressExtractFileName, $messages["compression.12"]); AJXP_Controller::applyActionInBackground($repository->getId(), "extraction", $httpVars); AJXP_XMLWriter::header(); AJXP_XMLWriter::triggerBgAction("check_extraction_status", array("repository_id" => $repository->getId(), "extraction_id" => $extractId, "currentDirUrl" => $currentDirUrl, "onlyFileName" => $onlyFileName), $messages["compression.12"], true, 2); AJXP_XMLWriter::close(); return null; } mkdir($currentDirUrl . $onlyFileName, 0777, true); chmod(AJXP_MetaStreamWrapper::getRealFSReference($currentDirUrl . $onlyFileName), 0777); try { $archive = new PharData(AJXP_MetaStreamWrapper::getRealFSReference($currentAllPydioPath)); $fichiersArchive = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($pharCurrentAllPydioPath)); foreach ($fichiersArchive as $file) { $fileGetPathName = $file->getPathname(); if ($file->isDir()) { continue; } $fileNameInArchive = substr(strstr($fileGetPathName, $fileArchive), strlen($fileArchive) + 1); try { $archive->extractTo(AJXP_MetaStreamWrapper::getRealFSReference($currentDirUrl . $onlyFileName), $fileNameInArchive, false); } catch (Exception $e) { file_put_contents($progressExtractFileName, "Error : " . $e->getMessage()); throw new AJXP_Exception($e); } $counterExtract++; file_put_contents($progressExtractFileName, sprintf($messages["compression.13"], round($counterExtract / $archive->count() * 100, 0, PHP_ROUND_HALF_DOWN) . " %")); } } catch (Exception $e) { file_put_contents($progressExtractFileName, "Error : " . $e->getMessage()); throw new AJXP_Exception($e); } file_put_contents($progressExtractFileName, "SUCCESS"); $newNode = new AJXP_Node($currentDirUrl . $onlyFileName); AJXP_Controller::findActionAndApply("index", array("file" => $newNode->getPath()), array()); } elseif ($action == "check_extraction_status") { $currentDirUrl = $httpVars["currentDirUrl"]; $onlyFileName = $httpVars["onlyFileName"]; $progressExtract = file_get_contents($progressExtractFileName); $substrProgressExtract = substr($progressExtract, 0, 5); if ($progressExtract != "SUCCESS" && $progressExtract != "INDEX" && $substrProgressExtract != "Error") { AJXP_XMLWriter::header(); AJXP_XMLWriter::triggerBgAction("check_extraction_status", array("repository_id" => $repository->getId(), "extraction_id" => $extractId, "currentDirUrl" => $currentDirUrl, "onlyFileName" => $onlyFileName), $progressExtract, true, 4); AJXP_XMLWriter::close(); } elseif ($progressExtract == "SUCCESS") { $newNode = new AJXP_Node($currentDirUrl . $onlyFileName); $nodesDiffs = array("ADD" => array($newNode), "REMOVE" => array(), "UPDATE" => array()); AJXP_Controller::applyHook("node.change", array(null, $newNode, false)); AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(sprintf($messages["compression.14"], $onlyFileName), null); AJXP_XMLWriter::triggerBgAction("check_index_status", array("repository_id" => $newNode->getRepositoryId()), "starting indexation", true, 5); AJXP_XMLWriter::writeNodesDiff($nodesDiffs, true); AJXP_XMLWriter::close(); if (file_exists($progressExtractFileName)) { unlink($progressExtractFileName); } } elseif ($substrProgressExtract == "Error") { AJXP_XMLWriter::header(); AJXP_XMLWriter::sendMessage(null, $progressExtract); AJXP_XMLWriter::close(); if (file_exists($progressExtractFileName)) { unlink($progressExtractFileName); } } } }
public function beforeCreate(AJXP_Node $node) { $this->informWatcher("create", $node->getPath()); }
/** * @param AJXP_Node $oldNode * @param AJXP_Node $newNode * @param bool $copy */ public function updateNodesIndex($oldNode = null, $newNode = null, $copy = false) { if (!dibi::isConnected()) { dibi::connect($this->sqlDriver); } //$this->logInfo("Syncable index", array($oldNode == null?'null':$oldNode->getUrl(), $newNode == null?'null':$newNode->getUrl())); try { if ($newNode != null && $this->excludeNode($newNode)) { // CREATE if ($oldNode == null) { AJXP_Logger::debug("Ignoring " . $newNode->getUrl() . " for indexation"); return; } else { AJXP_Logger::debug("Target node is excluded, see it as a deletion: " . $newNode->getUrl()); $newNode = null; } } if ($newNode == null) { $repoId = $this->computeIdentifier($oldNode->getRepository(), $oldNode->getUser()); // DELETE $this->logDebug('DELETE', $oldNode->getUrl()); dibi::query("DELETE FROM [ajxp_index] WHERE [node_path] LIKE %like~ AND [repository_identifier] = %s", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId); } else { if ($oldNode == null || $copy) { // CREATE $stat = stat($newNode->getUrl()); $newNode->setLeaf(!($stat['mode'] & 040000)); $this->logDebug('INSERT', $newNode->getUrl()); dibi::query("INSERT INTO [ajxp_index]", array("node_path" => SystemTextEncoding::toUTF8($newNode->getPath()), "bytesize" => $stat["size"], "mtime" => $stat["mtime"], "md5" => $newNode->isLeaf() ? md5_file($newNode->getUrl()) : "directory", "repository_identifier" => $repoId = $this->computeIdentifier($newNode->getRepository(), $newNode->getUser()))); } else { $repoId = $this->computeIdentifier($oldNode->getRepository(), $oldNode->getUser()); if ($oldNode->getPath() == $newNode->getPath()) { // CONTENT CHANGE clearstatcache(); $stat = stat($newNode->getUrl()); $this->logDebug("Content changed", "current stat size is : " . $stat["size"]); $this->logDebug('UPDATE CONTENT', $newNode->getUrl()); 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", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId); try { $rowCount = dibi::getAffectedRows(); if ($rowCount === 0) { $this->logError(__FUNCTION__, "There was an update event on a non-indexed node (" . $newNode->getPath() . "), creating index entry!"); $this->updateNodesIndex(null, $newNode, false); } } catch (Exception $e) { } } else { // PATH CHANGE ONLY $newNode->loadNodeInfo(); if ($newNode->isLeaf()) { $this->logDebug('UPDATE LEAF PATH', $newNode->getUrl()); dibi::query("UPDATE [ajxp_index] SET ", array("node_path" => SystemTextEncoding::toUTF8($newNode->getPath())), "WHERE [node_path] = %s AND [repository_identifier] = %s", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId); try { $rowCount = dibi::getAffectedRows(); if ($rowCount === 0) { $this->logError(__FUNCTION__, "There was an update event on a non-indexed node (" . $newNode->getPath() . "), creating index entry!"); $this->updateNodesIndex(null, $newNode, false); } } catch (Exception $e) { } } else { $this->logDebug('UPDATE FOLDER PATH', $newNode->getUrl()); 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", SystemTextEncoding::toUTF8($oldNode->getPath()), $repoId); try { $rowCount = dibi::getAffectedRows(); if ($rowCount === 0) { $this->logError(__FUNCTION__, "There was an update event on a non-indexed folder (" . $newNode->getPath() . "), relaunching a recursive indexation!"); AJXP_Controller::findActionAndApply("index", array("file" => $newNode->getPath()), array()); } } catch (Exception $e) { } } } } } } catch (Exception $e) { AJXP_Logger::error("[meta.syncable]", "Exception", $e->getTraceAsString()); AJXP_Logger::error("[meta.syncable]", "Indexation", $e->getMessage()); } }
/** * @param AJXP_Node $ajxpNode * @return void */ public function enrichNode(&$ajxpNode) { // Try both $aws = $this->getAwsService(); if ($aws == null) { return; } if (isset(self::$metaCache[$ajxpNode->getPath()])) { $data = self::$metaCache[$ajxpNode->getPath()]; } else { $this->logDebug("Should retrieve metadata for " . $ajxpNode->getPath()); $pathName = $this->updateNodeMetaPath($ajxpNode, false); if ($pathName == null) { return; } try { $response = $aws->headObject(array("Bucket" => $this->bucketName, "Key" => $pathName)); $metadata = $response["Metadata"]; if ($metadata == null) { $metadata = array(); } } catch (Aws\S3\Exception\S3Exception $e) { $metadata = array(); } self::$metaCache[$ajxpNode->getPath()] = $metadata; $data = self::$metaCache[$ajxpNode->getPath()]; } $allMeta = array(); foreach ($data as $amzKey => $value) { $parts = explode("-", $amzKey); $all[$parts[0]] = $value; } $ajxpNode->mergeMetadata($allMeta); }