예제 #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);
 }
 /**
  * @param AJXP_Node $ajxpNode
  * @return null|string
  */
 protected function extractIndexableContent($ajxpNode)
 {
     $ext = strtolower(pathinfo($ajxpNode->getLabel(), PATHINFO_EXTENSION));
     if (in_array($ext, explode(",", $this->getFilteredOption("PARSE_CONTENT_TXT")))) {
         return file_get_contents($ajxpNode->getUrl());
     }
     $unoconv = $this->getFilteredOption("UNOCONV");
     $pipe = false;
     if (!empty($unoconv) && in_array($ext, array("doc", "odt", "xls", "ods"))) {
         $targetExt = "txt";
         if (in_array($ext, array("xls", "ods"))) {
             $targetExt = "csv";
         } else {
             if (in_array($ext, array("odp", "ppt"))) {
                 $targetExt = "pdf";
                 $pipe = true;
             }
         }
         $realFile = call_user_func(array($ajxpNode->wrapperClassName, "getRealFSReference"), $ajxpNode->getUrl());
         $unoconv = "HOME=" . AJXP_Utils::getAjxpTmpDir() . " " . $unoconv . " --stdout -f {$targetExt} " . escapeshellarg($realFile);
         if ($pipe) {
             $newTarget = str_replace(".{$ext}", ".pdf", $realFile);
             $unoconv .= " > {$newTarget}";
             register_shutdown_function("unlink", $newTarget);
         }
         $output = array();
         exec($unoconv, $output, $return);
         if (!$pipe) {
             $out = implode("\n", $output);
             $enc = 'ISO-8859-1';
             $asciiString = iconv($enc, 'ASCII//TRANSLIT//IGNORE', $out);
             return $asciiString;
         } else {
             $ext = "pdf";
         }
     }
     $pdftotext = $this->getFilteredOption("PDFTOTEXT");
     if (!empty($pdftotext) && in_array($ext, array("pdf"))) {
         $realFile = call_user_func(array($ajxpNode->wrapperClassName, "getRealFSReference"), $ajxpNode->getUrl());
         if ($pipe && isset($newTarget) && is_file($newTarget)) {
             $realFile = $newTarget;
         }
         $cmd = $pdftotext . " " . escapeshellarg($realFile) . " -";
         $output = array();
         exec($cmd, $output, $return);
         $out = implode("\n", $output);
         $enc = 'UTF8';
         $asciiString = iconv($enc, 'ASCII//TRANSLIT//IGNORE', $out);
         return $asciiString;
     }
     return null;
 }
 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);
 }
예제 #4
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);
 }
예제 #5
0
 /**
  * @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);
 }
 /**
  * @param AJXP_Node $node
  */
 public function checkFileLock($node)
 {
     AJXP_Logger::debug("SHOULD CHECK LOCK METADATA FOR ", $node->getLabel());
     $lock = $this->metaStore->retrieveMetadata($node, SimpleLockManager::METADATA_LOCK_NAMESPACE, false, AJXP_METADATA_SCOPE_GLOBAL);
     if (is_array($lock) && array_key_exists("lock_user", $lock) && $lock["lock_user"] != AuthService::getLoggedUser()->getId()) {
         $mess = ConfService::getMessages();
         throw new Exception($mess["meta.simple_lock.5"]);
     }
 }
예제 #7
0
 /**
  * @param array $httpVars
  * @param AJXP_Node $ajxpNode
  */
 public function filterHttpVarsFromUniqueNode(&$httpVars, $ajxpNode)
 {
     $httpVars["minisite"] = true;
     $httpVars["selection"] = true;
     if ($ajxpNode->isLeaf()) {
         $httpVars["filter_nodes"] = [$ajxpNode];
         $httpVars["file"] = "/";
         $httpVars["nodes"] = array("/");
     }
     if (!isset($httpVars["repo_label"])) {
         $httpVars["repo_label"] = SystemTextEncoding::toUTF8($ajxpNode->getLabel());
     }
 }
예제 #8
0
 /**
  * @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 AJXP_Node $ajxpNode
  * @throws Exception
  */
 public function createIndexedDocument($ajxpNode)
 {
     $ajxpNode->loadNodeInfo();
     $parseContent = $this->indexContent;
     if ($parseContent && $ajxpNode->bytesize > $this->getFilteredOption("PARSE_CONTENT_MAX_SIZE")) {
         $parseContent = false;
     }
     $data = array();
     $data["node_url"] = $ajxpNode->getUrl();
     $data["node_path"] = str_replace("/", "AJXPFAKESEP", $ajxpNode->getPath());
     $data["basename"] = basename($ajxpNode->getPath());
     $data["ajxp_node"] = "yes";
     $data["ajxp_scope"] = "shared";
     $data["serialized_metadata"] = base64_encode(serialize($ajxpNode->metadata));
     $data["ajxp_modiftime"] = date("Ymd", $ajxpNode->ajxp_modiftime);
     $data["ajxp_bytesize"] = $ajxpNode->bytesize;
     $ajxpMime = $ajxpNode->ajxp_mime;
     if (empty($ajxpMime)) {
         $data["ajxp_mime"] = pathinfo($ajxpNode->getLabel(), PATHINFO_EXTENSION);
     } else {
         $data["ajxp_mime"] = $ajxpNode->ajxp_mime;
     }
     if (isset($ajxpNode->indexableMetaKeys["shared"])) {
         foreach ($ajxpNode->indexableMetaKeys["shared"] as $sharedField) {
             if ($ajxpNode->{$sharedField}) {
                 $data[$sharedField] = $ajxpNode->{$sharedField};
             }
         }
     }
     foreach ($this->metaFields as $field) {
         if ($ajxpNode->{$field} != null) {
             $data["ajxp_meta_{$field}"] = $ajxpNode->{$field};
         }
     }
     if ($parseContent) {
         $body = $this->extractIndexableContent($ajxpNode);
         if (!empty($body)) {
             $data["body"] = $body;
         }
     }
     $mapping = new Elastica\Type\Mapping();
     $mapping->setType($this->currentType);
     $mapping->setProperties($this->dataToMappingProperties($data));
     $mapping->send();
     $doc = new Elastica\Document($this->nextId, $data);
     $this->currentType->addDocument($doc);
     $this->nextId++;
     if (isset($ajxpNode->indexableMetaKeys["user"]) && count($ajxpNode->indexableMetaKeys["user"]) && AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
         $userData = array("ajxp_scope" => "user", "user" => AuthService::getLoggedUser()->getId(), "serialized_metadata" => $data["serialized_metadata"], "node_url" => $data["node_url"], "node_path" => $data["node_path"]);
         $userData["ajxp_user"] = AuthService::getLoggedUser()->getId();
         foreach ($ajxpNode->indexableMetaKeys["user"] as $userField) {
             if ($ajxpNode->{$userField}) {
                 $userData[$userField] = $ajxpNode->{$userField};
             }
         }
         $mapping = new Elastica\Type\Mapping();
         $mapping->setType($this->currentType);
         $mapping->setProperties($this->dataToMappingProperties($userData));
         $mapping->send();
         $doc = new Elastica\Document($this->nextId, $userData);
         $this->currentType->addDocument($doc);
         $this->nextId++;
     }
     /* we update the last id in the file */
     $file = fopen($this->lastIdPath, "w");
     fputs($file, $this->nextId - 1);
     fclose($file);
 }
 /**
  * @param AJXP_Node $ajxpNode
  * @param Zend_Search_Lucene_Interface $index
  * @throws Exception
  * @return Zend_Search_Lucene_Document
  */
 public function createIndexedDocument($ajxpNode, &$index)
 {
     if (!empty($this->metaFields)) {
         $ajxpNode->loadNodeInfo(false, false, "all");
     } else {
         $ajxpNode->loadNodeInfo();
     }
     $ext = strtolower(pathinfo($ajxpNode->getLabel(), PATHINFO_EXTENSION));
     $parseContent = $this->indexContent;
     if ($parseContent && $ajxpNode->bytesize > $this->getFilteredOption("PARSE_CONTENT_MAX_SIZE")) {
         $parseContent = false;
     }
     if ($parseContent && in_array($ext, explode(",", $this->getFilteredOption("PARSE_CONTENT_HTML")))) {
         $doc = @Zend_Search_Lucene_Document_Html::loadHTMLFile($ajxpNode->getUrl());
     } elseif ($parseContent && $ext == "docx" && class_exists("Zend_Search_Lucene_Document_Docx")) {
         $realFile = call_user_func(array($ajxpNode->wrapperClassName, "getRealFSReference"), $ajxpNode->getUrl());
         $doc = @Zend_Search_Lucene_Document_Docx::loadDocxFile($realFile);
     } elseif ($parseContent && $ext == "docx" && class_exists("Zend_Search_Lucene_Document_Pptx")) {
         $realFile = call_user_func(array($ajxpNode->wrapperClassName, "getRealFSReference"), $ajxpNode->getUrl());
         $doc = @Zend_Search_Lucene_Document_Pptx::loadPptxFile($realFile);
     } elseif ($parseContent && $ext == "xlsx" && class_exists("Zend_Search_Lucene_Document_Xlsx")) {
         $realFile = call_user_func(array($ajxpNode->wrapperClassName, "getRealFSReference"), $ajxpNode->getUrl());
         $doc = @Zend_Search_Lucene_Document_Xlsx::loadXlsxFile($realFile);
     } else {
         $doc = new Zend_Search_Lucene_Document();
     }
     if ($doc == null) {
         throw new Exception("Could not load document");
     }
     $doc->addField(Zend_Search_Lucene_Field::Keyword("node_url", $ajxpNode->getUrl()), SystemTextEncoding::getEncoding());
     $doc->addField(Zend_Search_Lucene_Field::Keyword("node_path", str_replace("/", "AJXPFAKESEP", $ajxpNode->getPath())), SystemTextEncoding::getEncoding());
     $doc->addField(Zend_Search_Lucene_Field::Text("basename", basename($ajxpNode->getPath())), SystemTextEncoding::getEncoding());
     $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_node", "yes"), SystemTextEncoding::getEncoding());
     $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_scope", "shared"));
     $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_modiftime", date("Ymd", $ajxpNode->ajxp_modiftime)));
     $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_bytesize", $ajxpNode->bytesize));
     $ajxpMime = $ajxpNode->ajxp_mime;
     if (empty($ajxpMime)) {
         $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_mime", pathinfo($ajxpNode->getLabel(), PATHINFO_EXTENSION)));
     } else {
         $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_mime", $ajxpNode->ajxp_mime));
     }
     // Store a cached copy of the metadata
     $serializedMeta = base64_encode(serialize($ajxpNode->metadata));
     $doc->addField(Zend_Search_Lucene_Field::Binary("serialized_metadata", $serializedMeta));
     if (isset($ajxpNode->indexableMetaKeys["shared"])) {
         foreach ($ajxpNode->indexableMetaKeys["shared"] as $sharedField) {
             if ($ajxpNode->{$sharedField}) {
                 $doc->addField(Zend_search_Lucene_Field::keyword($sharedField, $ajxpNode->{$sharedField}));
             }
         }
     }
     foreach ($this->metaFields as $field) {
         if ($ajxpNode->{$field} != null) {
             $doc->addField(Zend_Search_Lucene_Field::Text("ajxp_meta_{$field}", $ajxpNode->{$field}), SystemTextEncoding::getEncoding());
         }
     }
     if (isset($ajxpNode->indexableMetaKeys["user"]) && count($ajxpNode->indexableMetaKeys["user"]) && AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
         $privateDoc = new Zend_Search_Lucene_Document();
         $privateDoc->addField(Zend_Search_Lucene_Field::Keyword("node_url", $ajxpNode->getUrl(), SystemTextEncoding::getEncoding()));
         $privateDoc->addField(Zend_Search_Lucene_Field::Keyword("node_path", str_replace("/", "AJXPFAKESEP", $ajxpNode->getPath()), SystemTextEncoding::getEncoding()));
         $privateDoc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_scope", "user"));
         $privateDoc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_user", AuthService::getLoggedUser()->getId()));
         foreach ($ajxpNode->indexableMetaKeys["user"] as $userField) {
             if ($ajxpNode->{$userField}) {
                 $privateDoc->addField(Zend_search_Lucene_Field::keyword($userField, $ajxpNode->{$userField}));
             }
         }
         $privateDoc->addField(Zend_Search_Lucene_Field::Binary("serialized_metadata", $serializedMeta));
         $index->addDocument($privateDoc);
     }
     if ($parseContent) {
         $body = $this->extractIndexableContent($ajxpNode);
         if (!empty($body)) {
             $doc->addField(Zend_Search_Lucene_Field::unStored("body", $body));
         }
     }
     $index->addDocument($doc);
     return $doc;
 }
예제 #11
0
 /**
  * @param AJXP_Node $ajxpNode
  * @param Zend_Search_Lucene_Interface $index
  * @throws Exception
  * @return Zend_Search_Lucene_Document
  */
 public function createIndexedDocument($ajxpNode, &$index)
 {
     $ajxpNode->loadNodeInfo();
     $ext = strtolower(pathinfo($ajxpNode->getLabel(), PATHINFO_EXTENSION));
     $parseContent = $this->indexContent;
     if ($parseContent && $ajxpNode->bytesize > $this->getFilteredOption("PARSE_CONTENT_MAX_SIZE")) {
         $parseContent = false;
     }
     if ($parseContent && in_array($ext, explode(",", $this->getFilteredOption("PARSE_CONTENT_HTML")))) {
         $doc = @Zend_Search_Lucene_Document_Html::loadHTMLFile($ajxpNode->getUrl());
     } elseif ($parseContent && $ext == "docx" && class_exists("Zend_Search_Lucene_Document_Docx")) {
         $realFile = call_user_func(array($ajxpNode->wrapperClassName, "getRealFSReference"), $ajxpNode->getUrl());
         $doc = @Zend_Search_Lucene_Document_Docx::loadDocxFile($realFile);
     } elseif ($parseContent && $ext == "docx" && class_exists("Zend_Search_Lucene_Document_Pptx")) {
         $realFile = call_user_func(array($ajxpNode->wrapperClassName, "getRealFSReference"), $ajxpNode->getUrl());
         $doc = @Zend_Search_Lucene_Document_Pptx::loadPptxFile($realFile);
     } elseif ($parseContent && $ext == "xlsx" && class_exists("Zend_Search_Lucene_Document_Xlsx")) {
         $realFile = call_user_func(array($ajxpNode->wrapperClassName, "getRealFSReference"), $ajxpNode->getUrl());
         $doc = @Zend_Search_Lucene_Document_Xlsx::loadXlsxFile($realFile);
     } else {
         $doc = new Zend_Search_Lucene_Document();
     }
     if ($doc == null) {
         throw new Exception("Could not load document");
     }
     $doc->addField(Zend_Search_Lucene_Field::Keyword("node_url", $ajxpNode->getUrl()), SystemTextEncoding::getEncoding());
     $doc->addField(Zend_Search_Lucene_Field::Keyword("node_path", str_replace("/", "AJXPFAKESEP", $ajxpNode->getPath())), SystemTextEncoding::getEncoding());
     $doc->addField(Zend_Search_Lucene_Field::Text("basename", basename($ajxpNode->getPath())), SystemTextEncoding::getEncoding());
     $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_node", "yes"), SystemTextEncoding::getEncoding());
     $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_scope", "shared"));
     $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_modiftime", date("Ymd", $ajxpNode->ajxp_modiftime)));
     $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_bytesize", $ajxpNode->bytesize));
     $ajxpMime = $ajxpNode->ajxp_mime;
     if (empty($ajxpMime)) {
         $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_mime", pathinfo($ajxpNode->getLabel(), PATHINFO_EXTENSION)));
     } else {
         $doc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_mime", $ajxpNode->ajxp_mime));
     }
     // Store a cached copy of the metadata
     $serializedMeta = base64_encode(serialize($ajxpNode->metadata));
     $doc->addField(Zend_Search_Lucene_Field::Binary("serialized_metadata", $serializedMeta));
     if (isset($ajxpNode->indexableMetaKeys["shared"])) {
         foreach ($ajxpNode->indexableMetaKeys["shared"] as $sharedField) {
             if ($ajxpNode->{$sharedField}) {
                 $doc->addField(Zend_search_Lucene_Field::keyword($sharedField, $ajxpNode->{$sharedField}));
             }
         }
     }
     foreach ($this->metaFields as $field) {
         if ($ajxpNode->{$field} != null) {
             $doc->addField(Zend_Search_Lucene_Field::Text("ajxp_meta_{$field}", $ajxpNode->{$field}), SystemTextEncoding::getEncoding());
         }
     }
     if (isset($ajxpNode->indexableMetaKeys["user"]) && count($ajxpNode->indexableMetaKeys["user"]) && AuthService::usersEnabled() && AuthService::getLoggedUser() != null) {
         $privateDoc = new Zend_Search_Lucene_Document();
         $privateDoc->addField(Zend_Search_Lucene_Field::Keyword("node_url", $ajxpNode->getUrl(), SystemTextEncoding::getEncoding()));
         $privateDoc->addField(Zend_Search_Lucene_Field::Keyword("node_path", str_replace("/", "AJXPFAKESEP", $ajxpNode->getPath()), SystemTextEncoding::getEncoding()));
         $privateDoc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_scope", "user"));
         $privateDoc->addField(Zend_Search_Lucene_Field::Keyword("ajxp_user", AuthService::getLoggedUser()->getId()));
         foreach ($ajxpNode->indexableMetaKeys["user"] as $userField) {
             if ($ajxpNode->{$userField}) {
                 $privateDoc->addField(Zend_search_Lucene_Field::keyword($userField, $ajxpNode->{$userField}));
             }
         }
         $privateDoc->addField(Zend_Search_Lucene_Field::Binary("serialized_metadata", $serializedMeta));
         $index->addDocument($privateDoc);
     }
     if ($parseContent && in_array($ext, explode(",", $this->getFilteredOption("PARSE_CONTENT_TXT")))) {
         $doc->addField(Zend_Search_Lucene_Field::unStored("body", file_get_contents($ajxpNode->getUrl())));
     }
     $unoconv = $this->getFilteredOption("UNOCONV");
     $pipe = false;
     if ($parseContent && !empty($unoconv) && in_array($ext, array("doc", "odt", "xls", "ods"))) {
         $targetExt = "txt";
         if (in_array($ext, array("xls", "ods"))) {
             $targetExt = "csv";
         } else {
             if (in_array($ext, array("odp", "ppt"))) {
                 $targetExt = "pdf";
                 $pipe = true;
             }
         }
         $realFile = call_user_func(array($ajxpNode->wrapperClassName, "getRealFSReference"), $ajxpNode->getUrl());
         $unoconv = "HOME=" . AJXP_Utils::getAjxpTmpDir() . " " . $unoconv . " --stdout -f {$targetExt} " . escapeshellarg($realFile);
         if ($pipe) {
             $newTarget = str_replace(".{$ext}", ".pdf", $realFile);
             $unoconv .= " > {$newTarget}";
             register_shutdown_function("unlink", $newTarget);
         }
         $output = array();
         exec($unoconv, $output, $return);
         if (!$pipe) {
             $out = implode("\n", $output);
             $enc = 'ISO-8859-1';
             $asciiString = iconv($enc, 'ASCII//TRANSLIT//IGNORE', $out);
             $doc->addField(Zend_Search_Lucene_Field::unStored("body", $asciiString));
         } else {
             $ext = "pdf";
         }
     }
     $pdftotext = $this->getFilteredOption("PDFTOTEXT");
     if ($parseContent && !empty($pdftotext) && in_array($ext, array("pdf"))) {
         $realFile = call_user_func(array($ajxpNode->wrapperClassName, "getRealFSReference"), $ajxpNode->getUrl());
         if ($pipe && isset($newTarget) && is_file($newTarget)) {
             $realFile = $newTarget;
         }
         $cmd = $pdftotext . " " . escapeshellarg($realFile) . " -";
         $output = array();
         exec($cmd, $output, $return);
         $out = implode("\n", $output);
         $enc = 'UTF8';
         $asciiString = iconv($enc, 'ASCII//TRANSLIT//IGNORE', $out);
         $doc->addField(Zend_Search_Lucene_Field::unStored("body", $asciiString));
     }
     $index->addDocument($doc);
     return $doc;
 }
예제 #12
0
 /**
  * @param AJXP_Node $ajxpNode
  * @param AJXP_Node|bool $parentNode
  * @param bool $details
  */
 public function filterENCFS(&$ajxpNode, $parentNode = false, $details = false)
 {
     if (substr($ajxpNode->getLabel(), 0, strlen("ENCFS_RAW_")) == "ENCFS_RAW_") {
         $ajxpNode->hidden = true;
     } else {
         if (substr($ajxpNode->getLabel(), 0, strlen("ENCFS_CLEAR_")) == "ENCFS_CLEAR_") {
             $ajxpNode->ENCFS_clear_folder = true;
             $ajxpNode->overlay_icon = "cypher.encfs/overlay_ICON_SIZE.png";
             $ajxpNode->overlay_class = "icon-lock";
             if (is_file($ajxpNode->getUrl() . "/.ajxp_mount")) {
                 $ajxpNode->setLabel(substr($ajxpNode->getLabel(), strlen("ENCFS_CLEAR_")));
                 $ajxpNode->ENCFS_clear_folder_mounted = true;
             } else {
                 $ajxpNode->setLabel(substr($ajxpNode->getLabel(), strlen("ENCFS_CLEAR_")) . " (encrypted)");
             }
         }
     }
 }
 /**
  * @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);
 }