public static function getNodeData($nodePath)
 {
     $basename = basename(parse_url($nodePath, PHP_URL_PATH));
     if (empty($basename)) {
         return ['stat' => stat(AJXP_Utils::getAjxpTmpDir())];
     }
     $allNodes = self::getNodes(false);
     $nodeData = $allNodes[$basename];
     if (!isset($nodeData["stat"])) {
         if (in_array(pathinfo($basename, PATHINFO_EXTENSION), array("error", "invitation"))) {
             $stat = stat(AJXP_Utils::getAjxpTmpDir());
         } else {
             $url = $nodeData["url"];
             $node = new AJXP_Node($nodeData["url"]);
             $node->getRepository()->driverInstance = null;
             try {
                 ConfService::loadDriverForRepository($node->getRepository());
                 $node->getRepository()->detectStreamWrapper(true);
                 if ($node->getRepository()->hasContentFilter()) {
                     $node->setLeaf(true);
                 }
                 AJXP_Controller::applyHook("node.read", array(&$node));
                 $stat = stat($url);
             } catch (Exception $e) {
                 $stat = stat(AJXP_Utils::getAjxpTmpDir());
             }
             if (is_array($stat) && AuthService::getLoggedUser() != null) {
                 $acl = AuthService::getLoggedUser()->mergedRole->getAcl($nodeData["meta"]["shared_repository_id"]);
                 if ($acl == "r") {
                     self::disableWriteInStat($stat);
                 }
             }
             self::$output[$basename]["stat"] = $stat;
         }
         $nodeData["stat"] = $stat;
     }
     return $nodeData;
 }
示例#2
0
 public function mkDir($crtDir, $newDirName, $ignoreExists = false)
 {
     $currentNodeDir = new AJXP_Node($this->urlBase . $crtDir);
     AJXP_Controller::applyHook("node.before_change", array(&$currentNodeDir));
     $mess = ConfService::getMessages();
     if ($newDirName == "") {
         return "{$mess['37']}";
     }
     if (file_exists($this->urlBase . "{$crtDir}/{$newDirName}")) {
         if ($ignoreExists) {
             return null;
         }
         return "{$mess['40']}";
     }
     if (!$this->isWriteable($this->urlBase . "{$crtDir}")) {
         return $mess[38] . " {$crtDir} " . $mess[99];
     }
     $dirMode = 0775;
     $chmodValue = $this->repository->getOption("CHMOD_VALUE");
     if (isset($chmodValue) && $chmodValue != "") {
         $dirMode = octdec(ltrim($chmodValue, "0"));
         if ($dirMode & 0400) {
             $dirMode |= 0100;
         }
         // User is allowed to read, allow to list the directory
         if ($dirMode & 040) {
             $dirMode |= 010;
         }
         // Group is allowed to read, allow to list the directory
         if ($dirMode & 04) {
             $dirMode |= 01;
         }
         // Other are allowed to read, allow to list the directory
     }
     $old = umask(0);
     mkdir($this->urlBase . "{$crtDir}/{$newDirName}", $dirMode);
     umask($old);
     $newNode = new AJXP_Node($this->urlBase . $crtDir . "/" . $newDirName);
     $newNode->setLeaf(false);
     AJXP_Controller::applyHook("node.change", array(null, $newNode, false));
     return null;
 }
 /**
  * @param Repository $repositoryObject
  */
 public function clearWorkspaceNodeInfos($repositoryObject)
 {
     $cDriver = ConfService::getCacheDriverImpl();
     if (empty($cDriver) || !$cDriver->supportsPatternDelete(AJXP_CACHE_SERVICE_NS_NODES)) {
         return;
     }
     $node = new AJXP_Node("pydio://" . $repositoryObject->getId() . "/");
     $node->setLeaf(false);
     $this->clearCacheForNode($node);
 }
 /**
  * @param String $destDir url of destination dir
  * @param String $srcFile url of source file
  * @param Array $error accumulator for error messages
  * @param Array $success accumulator for success messages
  * @param bool $move Whether to copy or move
  * @param array $srcRepoData Set of data concerning source repository: base_url, wrapper_name and recycle option
  * @param array $destRepoData Set of data concerning destination repository: base_url, wrapper_name and chmod option
  */
 protected function copyOrMoveFile($destDir, $srcFile, &$error, &$success, $move = false, $srcRepoData = array(), $destRepoData = array())
 {
     $srcUrlBase = $srcRepoData['base_url'];
     $srcWrapperName = $srcRepoData['wrapper_name'];
     $srcRecycle = $srcRepoData['recycle'];
     $destUrlBase = $destRepoData['base_url'];
     $destWrapperName = $destRepoData['wrapper_name'];
     $mess = ConfService::getMessages();
     $bName = basename($srcFile);
     $localName = '';
     AJXP_Controller::applyHook("dl.localname", array($srcFile, &$localName, $srcWrapperName));
     if (!empty($localName)) {
         $bName = $localName;
     }
     $destFile = $destUrlBase . $destDir . "/" . $bName;
     $realSrcFile = $srcUrlBase . $srcFile;
     if (is_dir(dirname($realSrcFile)) && strpos($destFile, rtrim($realSrcFile, "/") . "/") === 0) {
         $error[] = $mess[101];
         return;
     }
     if (!file_exists($realSrcFile)) {
         $error[] = $mess[100] . $srcFile;
         return;
     }
     if (!$move) {
         if (method_exists($this, "filesystemFileSize")) {
             $size = $this->filesystemFileSize($realSrcFile);
         } else {
             $size = filesize($realSrcFile);
         }
         AJXP_Controller::applyHook("node.before_create", array(new AJXP_Node($destFile), $size));
     }
     if (dirname($realSrcFile) == dirname($destFile)) {
         if ($move) {
             $error[] = $mess[101];
             return;
         } else {
             $base = basename($srcFile);
             $i = 1;
             if (is_file($realSrcFile)) {
                 $dotPos = strrpos($base, ".");
                 if ($dotPos > -1) {
                     $radic = substr($base, 0, $dotPos);
                     $ext = substr($base, $dotPos);
                 }
             }
             // auto rename file
             $i = 1;
             $newName = $base;
             while (file_exists($destUrlBase . $destDir . "/" . $newName)) {
                 $suffix = "-{$i}";
                 if (isset($radic)) {
                     $newName = $radic . $suffix . $ext;
                 } else {
                     $newName = $base . $suffix;
                 }
                 $i++;
             }
             $destFile = $destUrlBase . $destDir . "/" . $newName;
         }
     }
     $srcNode = new AJXP_Node($realSrcFile);
     $destNode = new AJXP_Node($destFile);
     if (!is_file($realSrcFile)) {
         $errors = array();
         $succFiles = array();
         $srcNode->setLeaf(false);
         if ($move) {
             AJXP_Controller::applyHook("node.before_path_change", array($srcNode));
             if (file_exists($destFile)) {
                 $this->deldir($destFile, $destRepoData);
             }
             $res = rename($realSrcFile, $destFile);
         } else {
             $dirRes = $this->dircopy($realSrcFile, $destFile, $errors, $succFiles, false, true, $srcRepoData, $destRepoData);
         }
         if (count($errors) || isset($res) && $res !== true) {
             $error[] = $mess[114];
             return;
         } else {
             $destNode->setLeaf(false);
             AJXP_Controller::applyHook("node.change", array($srcNode, $destNode, !$move));
         }
     } else {
         if ($move) {
             AJXP_Controller::applyHook("node.before_path_change", array($srcNode));
             if (file_exists($destFile)) {
                 unlink($destFile);
             }
             if (strcmp($srcWrapperName, $destWrapperName) === 0) {
                 $res = rename($realSrcFile, $destFile);
             } else {
                 $res = copy($realSrcFile, $destFile);
             }
             AJXP_Controller::applyHook("node.change", array($srcNode, $destNode, false));
         } else {
             try {
                 $this->filecopy($realSrcFile, $destFile, $srcWrapperName, $destWrapperName);
                 $this->changeMode($destFile, $destRepoData);
                 AJXP_Controller::applyHook("node.change", array($srcNode, $destNode, true));
             } catch (Exception $e) {
                 $error[] = $e->getMessage();
                 return;
             }
         }
     }
     if ($move) {
         // Now delete original
         // $this->deldir($realSrcFile); // both file and dir
         $messagePart = $mess[74] . " " . SystemTextEncoding::toUTF8($destDir);
         if (RecycleBinManager::recycleEnabled() && $destDir == RecycleBinManager::getRelativeRecycle()) {
             RecycleBinManager::fileToRecycle($srcFile);
             $messagePart = $mess[123] . " " . $mess[122];
         }
         if (isset($dirRes)) {
             $success[] = $mess[117] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $messagePart . " (" . SystemTextEncoding::toUTF8($dirRes) . " " . $mess[116] . ") ";
         } else {
             $success[] = $mess[34] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $messagePart;
         }
     } else {
         if (RecycleBinManager::recycleEnabled() && $destDir == "/" . $srcRecycle) {
             RecycleBinManager::fileToRecycle($srcFile);
         }
         if (isset($dirRes)) {
             $success[] = $mess[117] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $mess[73] . " " . SystemTextEncoding::toUTF8($destDir) . " (" . SystemTextEncoding::toUTF8($dirRes) . " " . $mess[116] . ")";
         } else {
             $success[] = $mess[34] . " " . SystemTextEncoding::toUTF8(basename($srcFile)) . " " . $mess[73] . " " . SystemTextEncoding::toUTF8($destDir);
         }
     }
 }
示例#5
0
 public function processReadHook(AJXP_Node $node)
 {
     $ids = $this->getWatchesOnNode($node, self::$META_WATCH_READ);
     $notif = new AJXP_Notification();
     $notif->setAction(AJXP_NOTIF_NODE_VIEW);
     $notif->setNode($node);
     if (count($ids)) {
         foreach ($ids as $id) {
             $this->notificationCenter->postNotification($notif, $id);
         }
     }
     if (!$node->isRoot()) {
         $parentNode = new AJXP_Node(dirname($node->getUrl()));
         $parentNode->setLeaf(false);
         $ids = $this->getWatchesOnNode($parentNode, self::$META_WATCH_READ);
         if (count($ids)) {
             // POST NOW : PARENT FOLDER IS AFFECTED
             $parentNotif = new AJXP_Notification();
             $parentNotif->setNode($parentNode);
             $parentNotif->setAction(AJXP_NOTIF_NODE_VIEW);
             $this->notificationCenter->prepareNotification($notif);
             $parentNotif->addRelatedNotification($notif);
             foreach ($ids as $id) {
                 $this->notificationCenter->postNotification($parentNotif, $id);
             }
         }
     }
 }
 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;
 }