/** * @CORS * @NoAdminRequired * @NoCSRFRequired * @PublicPage */ public function returnAsJson($user, $password = null, $tags = array(), $conjunction = "or", $select = null, $sortby = "") { if ($user == null || $this->userManager->userExists($user) == false) { return $this->newJsonErrorMessage("User could not be identified"); } if ($tags[0] == "") { $tags = array(); } $public = true; if ($password != null) { $public = false; } if (!$public && !$this->userManager->checkPassword($user, $password)) { $msg = 'REST API accessed with wrong password'; \OCP\Util::writeLog('bookmarks', $msg, \OCP\Util::WARN); return $this->newJsonErrorMessage("Wrong password for user " . $user); } $attributesToSelect = array('url', 'title'); if ($select != null) { $attributesToSelect = array_merge($attributesToSelect, $select); $attributesToSelect = array_unique($attributesToSelect); } $output = Bookmarks::findBookmarks($user, $this->db, 0, $sortby, $tags, true, -1, $public, $attributesToSelect, $conjunction); if (count($output) == 0) { $output["status"] = 'error'; $output["message"] = "No results from this query"; return new JSONResponse($output); } return new JSONResponse($output); }
function testFindBookmarksSelectAndOrFilteredTags() { $this->cleanDB(); $secondUser = $this->userid . "andHisClone435"; Bookmarks::addBookmark($this->userid, $this->db, "http://www.google.de", "Google", array("one"), "PrivateNoTag", false); Bookmarks::addBookmark($this->userid, $this->db, "http://www.heise.de", "Heise", array("one", "two"), "PrivatTag", false); Bookmarks::addBookmark($this->userid, $this->db, "http://www.golem.de", "Golem", array("four"), "PublicNoTag", true); Bookmarks::addBookmark($this->userid, $this->db, "http://www.9gag.com", "9gag", array("two", "three"), "PublicTag", true); Bookmarks::addBookmark($secondUser, $this->db, "http://www.google.de", "Google", array("one"), "PrivateNoTag", false); Bookmarks::addBookmark($secondUser, $this->db, "http://www.heise.de", "Heise", array("one", "two"), "PrivatTag", false); Bookmarks::addBookmark($secondUser, $this->db, "http://www.golem.de", "Golem", array("four"), "PublicNoTag", true); Bookmarks::addBookmark($secondUser, $this->db, "http://www.9gag.com", "9gag", array("two", "three"), "PublicTag", true); $resultSetOne = Bookmarks::findBookmarks($this->userid, $this->db, 0, 'lastmodified', array('one', 'three'), true, -1, false, array('url', 'title'), 'or'); $this->assertEquals(3, count($resultSetOne)); $resultOne = $resultSetOne[0]; $this->assertFalse(isset($resultOne['lastmodified'])); $this->assertFalse(isset($resultOne['tags'])); }
function search($query) { $results = array(); if (substr_count($query, ' ') > 0) { $search_words = explode(' ', $query); } else { $search_words = $query; } $db = \OC::$server->getDb(); $user = \OCP\User::getUser(); $bookmarks = Bookmarks::findBookmarks($user, $db, 0, 'id', $search_words, false); $l = new \OC_l10n('bookmarks'); //resulttype can't be localized, javascript relies on that type foreach ($bookmarks as $bookmark) { $results[] = new \OC_Search_Result($bookmark['title'], $bookmark['title'], $bookmark['url'], (string) $l->t('Bookm.')); } return $results; }
/** * @CORS * @NoAdminRequired * @NoCSRFRequired */ public function returnPrivateAsJson($tags = array(), $conjunction = "or", $select = null, $sortby = "") { $user = \OCP\User::getUser(); if ($tags != null && $tags[0] == "") { $tags = array(); } $attributesToSelect = array('url', 'title'); if ($select != null) { $attributesToSelect = array_merge($attributesToSelect, $select); $attributesToSelect = array_unique($attributesToSelect); } $output = Bookmarks::findBookmarks($user, $this->db, 0, $sortby, $tags, true, -1, false, $attributesToSelect, $conjunction); if (count($output) == 0) { $output["status"] = 'error'; $output["message"] = "No results from this query"; return new JSONResponse($output); } return new JSONResponse($output); }
/** @NoAdminRequired * * @return \OCP\AppFramework\Http\JSONResponse */ public function exportBookmark() { $file = <<<EOT <!DOCTYPE NETSCAPE-Bookmark-file-1> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> <!-- This is an automatically generated file. It will be read and overwritten. Do Not Edit! --> <TITLE>Bookmarks</TITLE> <H1>Bookmarks</H1> <DL><p> EOT; $bookmarks = Bookmarks::findBookmarks($this->userId, $this->db, 0, 'id', array(), true, -1); foreach ($bookmarks as $bm) { $title = $bm['title']; if (trim($title) === '') { $url_parts = parse_url($bm['url']); $title = isset($url_parts['host']) ? OCA\Bookmarks\Controller\Lib\Helper::getDomainWithoutExt($url_parts['host']) : $bm['url']; } $file .= '<DT><A HREF="' . \OC_Util::sanitizeHTML($bm['url']) . '" TAGS="' . implode(',', \OC_Util::sanitizeHTML($bm['tags'])) . '">'; $file .= htmlspecialchars($title, ENT_QUOTES, 'UTF-8') . '</A>'; if ($bm['description']) { $file .= '<DD>' . htmlspecialchars($bm['description'], ENT_QUOTES, 'UTF-8'); } $file .= "\n"; } return new ExportResponse($file); }