diff options
author | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2011-08-15 22:05:07 +0200 |
---|---|---|
committer | Arthur Schiwon <blizzz@arthur-schiwon.de> | 2011-08-15 22:05:07 +0200 |
commit | 5608aaee8a8bbf913f4abb665f18fbe510da7214 (patch) | |
tree | f704a1657117af202001ddcc71a9d3ad0df338ad /apps/bookmarks/ajax | |
parent | 523b0966d22d0fc149ca64afb32995a0eb29a6d3 (diff) | |
download | nextcloud-server-5608aaee8a8bbf913f4abb665f18fbe510da7214.tar.gz nextcloud-server-5608aaee8a8bbf913f4abb665f18fbe510da7214.zip |
initial commit of Bookmarks App
Diffstat (limited to 'apps/bookmarks/ajax')
-rw-r--r-- | apps/bookmarks/ajax/addBookmark.php | 70 | ||||
-rw-r--r-- | apps/bookmarks/ajax/delBookmark.php | 52 | ||||
-rw-r--r-- | apps/bookmarks/ajax/recordClick.php | 47 | ||||
-rw-r--r-- | apps/bookmarks/ajax/updateList.php | 66 |
4 files changed, 235 insertions, 0 deletions
diff --git a/apps/bookmarks/ajax/addBookmark.php b/apps/bookmarks/ajax/addBookmark.php new file mode 100644 index 00000000000..b0d1a730897 --- /dev/null +++ b/apps/bookmarks/ajax/addBookmark.php @@ -0,0 +1,70 @@ +<?php + +/** +* ownCloud - bookmarks plugin +* +* @author Arthur Schiwon +* @copyright 2011 Arthur Schiwon blizzz@arthur-schiwon.de +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +//no apps or filesystem +$RUNTIME_NOSETUPFS=true; + +require_once('../../../lib/base.php'); + +// We send json data +header( "Content-Type: application/jsonrequest" ); + +// Check if we are a user +if( !OC_User::isLoggedIn()){ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$query = OC_DB::prepare(" + INSERT IGNORE INTO *PREFIX*bookmarks + (url, title, description, user_id, public, added, lastmodified) + VALUES (?, ?, ?, ?, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()) + "); + +$params=array( + urldecode($_GET["url"]), + urldecode($_GET["title"]), + urldecode($_GET["description"]), + OC_User::getUser() + ); +$query->execute($params); +$b_id = OC_DB::insertid(); + +if($b_id !== false) { + $query = OC_DB::prepare(" + INSERT INTO *PREFIX*bookmarks_tags + (bookmark_id, tag) + VALUES (?, ?) + "); + + $tags = explode(' ', urldecode($_GET["tags"])); + foreach ($tags as $tag) { + if(empty($tag)) { + //avoid saving blankspaces + continue; + } + $params = array($b_id, trim($tag)); + $query->execute($params); + } +} + diff --git a/apps/bookmarks/ajax/delBookmark.php b/apps/bookmarks/ajax/delBookmark.php new file mode 100644 index 00000000000..a47bd2b9ea4 --- /dev/null +++ b/apps/bookmarks/ajax/delBookmark.php @@ -0,0 +1,52 @@ +<?php + +/** +* ownCloud - bookmarks plugin +* +* @author Arthur Schiwon +* @copyright 2011 Arthur Schiwon blizzz@arthur-schiwon.de +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +//no apps or filesystem +$RUNTIME_NOSETUPFS=true; + +require_once('../../../lib/base.php'); + +// We send json data +header( "Content-Type: application/jsonrequest" ); + +// Check if we are a user +if( !OC_User::isLoggedIn()){ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$query = OC_DB::prepare(" + DELETE FROM *PREFIX*bookmarks + WHERE url LIKE ? + AND user_id = ? + "); + +$params=array( + urldecode($_GET["url"]), + OC_User::getUser() + ); +$result = $query->execute($params); + +// var_dump($params); + +echo json_encode( array( "status" => "success", "data" => array())); diff --git a/apps/bookmarks/ajax/recordClick.php b/apps/bookmarks/ajax/recordClick.php new file mode 100644 index 00000000000..4dcb0b4a0df --- /dev/null +++ b/apps/bookmarks/ajax/recordClick.php @@ -0,0 +1,47 @@ +<?php + +/** +* ownCloud - bookmarks plugin +* +* @author Arthur Schiwon +* @copyright 2011 Arthur Schiwon blizzz@arthur-schiwon.de +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +//no apps or filesystem +$RUNTIME_NOSETUPFS=true; + +require_once('../../../lib/base.php'); + +// Check if we are a user +if( !OC_User::isLoggedIn()){ + header( "Content-Type: application/jsonrequest" ); + echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$query = OC_DB::prepare(" + UPDATE *PREFIX*bookmarks + SET clickcount = clickcount + 1 + WHERE user_id = ? + AND url LIKE ? + "); + +$params=array(OC_User::getUser(), urldecode($_GET["url"])); +$bookmarks = $query->execute($params); + +header( "HTTP/1.1 204 No Content" ); + diff --git a/apps/bookmarks/ajax/updateList.php b/apps/bookmarks/ajax/updateList.php new file mode 100644 index 00000000000..d7cf05b7a60 --- /dev/null +++ b/apps/bookmarks/ajax/updateList.php @@ -0,0 +1,66 @@ +<?php + +/** +* ownCloud - bookmarks plugin +* +* @author Arthur Schiwon +* @copyright 2011 Arthur Schiwon blizzz@arthur-schiwon.de +* +* This library is free software; you can redistribute it and/or +* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE +* License as published by the Free Software Foundation; either +* version 3 of the License, or any later version. +* +* This library is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU AFFERO GENERAL PUBLIC LICENSE for more details. +* +* You should have received a copy of the GNU Lesser General Public +* License along with this library. If not, see <http://www.gnu.org/licenses/>. +* +*/ + +//no apps or filesystem +$RUNTIME_NOSETUPFS=true; + +require_once('../../../lib/base.php'); + +// We send json data +header( "Content-Type: application/jsonrequest" ); + +// Check if we are a user +if( !OC_User::isLoggedIn()){ + echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" ))); + exit(); +} + +$params=array(OC_User::getUser()); + +//Filter for tag? +$filterTag = isset($_GET["tag"]) ? urldecode($_GET["tag"]) : false; +if($filterTag){ + $sqlFilterTag = "HAVING INSTR (tags, ?) > 0"; + $params[] = $filterTag; +} else { + $sqlFilterTag = ''; +} + +$offset = isset($_GET["page"]) ? intval($_GET["page"]) * 10 : 0; +$params[] = $offset; + +//FIXME: bookmarks without tags are not being retrieved +$query = OC_DB::prepare(" + SELECT url, title, description, GROUP_CONCAT( tag SEPARATOR ' ' ) AS tags + FROM *PREFIX*bookmarks, *PREFIX*bookmarks_tags + WHERE *PREFIX*bookmarks.id = *PREFIX*bookmarks_tags.bookmark_id + AND *PREFIX*bookmarks.user_id = ? + GROUP BY url + $sqlFilterTag + ORDER BY *PREFIX*bookmarks.id DESC + LIMIT ?, 10"); + + +$bookmarks = $query->execute($params)->fetchAll(); + +echo json_encode( array( "status" => "success", "data" => $bookmarks)); |