function testPublicQuery() { 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); $output = $this->publicController->returnAsJson($this->userid); $data = $output->getData(); $this->assertEquals(2, count($data)); $this->cleanDB(); }
function testDeleteBookmark() { $this->cleanDB(); Bookmarks::addBookmark($this->userid, $this->db, "http://www.google.de", "Google", array("one"), "PrivateNoTag", false); $id = Bookmarks::addBookmark($this->userid, $this->db, "http://www.heise.de", "Heise", array("one", "two"), "PrivatTag", false); $this->assertNotEquals(false, Bookmarks::bookmarkExists("http://www.google.de", $this->userid, $this->db)); $this->assertNotEquals(false, Bookmarks::bookmarkExists("http://www.heise.de", $this->userid, $this->db)); Bookmarks::deleteUrl($this->userid, $this->db, $id); $this->assertFalse(Bookmarks::bookmarkExists("http://www.heise.de", $this->userid, $this->db)); }
/** * @NoAdminRequired */ public function newBookmark($url = "", $item = array(), $from_own = 0, $title = "", $is_public = false, $description = "") { // Check if it is a valid URL if (filter_var($url, FILTER_VALIDATE_URL) === FALSE) { return new JSONResponse(array('status' => 'error'), Http::STATUS_BAD_REQUEST); } $tags = isset($item['tags']) ? $item['tags'] : array(); if ($from_own == 0) { $datas = Bookmarks::getURLMetadata($url); if (isset($datas['title'])) { $title = $datas['title']; } } $id = Bookmarks::addBookmark($this->userId, $this->db, $url, $title, $tags, $description, $is_public); $bm = Bookmarks::findUniqueBookmark($id, $this->userId, $this->db); return new JSONResponse(array('item' => $bm, 'status' => 'success')); }
/** * @NoAdminRequired */ public function newBookmark($url = "", $item = array(), $from_own = 0, $title = "", $is_public = false, $description = "") { if ($from_own == 0) { // allow only http(s) and (s)ftp $protocols = '/^(https?|s?ftp)\\:\\/\\//i'; if (preg_match($protocols, $url)) { $data = Bookmarks::getURLMetadata($url); // if not (allowed) protocol is given, assume http and https (and fetch both) } else { // append https to url and fetch it $url_https = 'https://' . $url; $data_https = Bookmarks::getURLMetadata($url_https); // append http to url and fetch it $url_http = 'http://' . $url; $data_http = Bookmarks::getURLMetadata($url_http); } if ($title === '' && isset($data['title'])) { // prefer original url if working $title = $data['title']; //url remains unchanged } elseif (isset($data_https['title'])) { // test if https works $title = $title === '' ? $data_https['title'] : $title; $url = $url_https; } elseif (isset($data_http['title'])) { // otherwise test http for results $title = $title === '' ? $data_http['title'] : $title; $url = $url_http; } } // Check if it is a valid URL (after adding http(s) prefix) $urlData = parse_url($url); if ($urlData === false || !isset($urlData['scheme']) || !isset($urlData['host'])) { return new JSONResponse(array('status' => 'error'), Http::STATUS_BAD_REQUEST); } $tags = isset($item['tags']) ? $item['tags'] : array(); $id = Bookmarks::addBookmark($this->userId, $this->db, $url, $title, $tags, $description, $is_public); $bm = Bookmarks::findUniqueBookmark($id, $this->userId, $this->db); return new JSONResponse(array('item' => $bm, 'status' => 'success')); }
/** * @CORS * @NoAdminRequired * @NoCSRFRequired */ public function returnAddAsJson($url = "", $tags = array(), $title = "", $description = "") { $user = \OCP\User::getUser(); if ($tags[0] == "") { $tags = array(); } $output = Bookmarks::addBookmark($user, $this->db, $url, $title, $tags, $description, false); if (count($output) == 0) { $output["status"] = 'error'; $output["message"] = "No results from this query"; return new JSONResponse($output); } $output = Bookmarks::findUniqueBookmark($output, $user, $this->db); return new JSONResponse($output); }