From 77493e8d704c5a9c986b453583f966cb976409c9 Mon Sep 17 00:00:00 2001 From: Marvin Thomas Rabe Date: Wed, 22 Feb 2012 23:52:56 +0100 Subject: [PATCH] Changed bookmarklet to read later widget --- apps/bookmarks/addBm.php | 13 ++---- apps/bookmarks/ajax/addBookmark.php | 53 ++---------------------- apps/bookmarks/bookmarksHelper.php | 52 +++++++++++++++++++++++ apps/bookmarks/css/bookmarks.css | 1 + apps/bookmarks/templates/addBm.php | 17 +++++--- apps/bookmarks/templates/bookmarklet.php | 4 +- 6 files changed, 72 insertions(+), 68 deletions(-) diff --git a/apps/bookmarks/addBm.php b/apps/bookmarks/addBm.php index d3d6ab0b1a2..0225a7aa7b3 100644 --- a/apps/bookmarks/addBm.php +++ b/apps/bookmarks/addBm.php @@ -27,14 +27,7 @@ require_once('../../lib/base.php'); OC_Util::checkLoggedIn(); OC_Util::checkAppEnabled('bookmarks'); -OC_App::setActiveNavigationEntry( 'bookmarks_index' ); +require_once('bookmarksHelper.php'); +addBookmark($_GET['url']); -OC_Util::addScript('bookmarks','addBm'); -OC_Util::addStyle('bookmarks', 'bookmarks'); - -$tmpl = new OC_Template( 'bookmarks', 'addBm', 'user' ); - -$url = isset($_GET['url']) ? urldecode($_GET['url']) : ''; -$tmpl->assign('URL', htmlentities($url,ENT_COMPAT,'utf-8')); - -$tmpl->printPage(); +include 'templates/addBm.php'; diff --git a/apps/bookmarks/ajax/addBookmark.php b/apps/bookmarks/ajax/addBookmark.php index 89446564110..8cda7f0f060 100644 --- a/apps/bookmarks/ajax/addBookmark.php +++ b/apps/bookmarks/ajax/addBookmark.php @@ -30,53 +30,6 @@ require_once('../../../lib/base.php'); OC_JSON::checkLoggedIn(); OC_JSON::checkAppEnabled('bookmarks'); -$CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); -if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){ - $_ut = "strftime('%s','now')"; -} elseif($CONFIG_DBTYPE == 'pgsql') { - $_ut = 'date_part(\'epoch\',now())::integer'; -} else { - $_ut = "UNIX_TIMESTAMP()"; -} - -//FIXME: Detect when user adds a known URL -$query = OC_DB::prepare(" - INSERT INTO *PREFIX*bookmarks - (url, title, user_id, public, added, lastmodified) - VALUES (?, ?, ?, 0, $_ut, $_ut) - "); - -if(empty($_GET["title"])) { - require_once('../bookmarksHelper.php'); - $metadata = getURLMetadata($_GET["url"]); - $_GET["title"] = $metadata['title']; -} - -$params=array( - htmlspecialchars_decode($_GET["url"]), - htmlspecialchars_decode($_GET["title"]), - OC_User::getUser() - ); -$query->execute($params); - -$b_id = OC_DB::insertid('*PREFIX*bookmarks'); - -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); - } - - OC_JSON::success(array('data' => $b_id)); -} +require_once('../bookmarksHelper.php'); +$id = addBookmark($_GET['url'], $_GET['title'], $_GET['tags']); +OC_JSON::success(array('data' => $id)); \ No newline at end of file diff --git a/apps/bookmarks/bookmarksHelper.php b/apps/bookmarks/bookmarksHelper.php index ac512fbc241..8def7401e2f 100644 --- a/apps/bookmarks/bookmarksHelper.php +++ b/apps/bookmarks/bookmarksHelper.php @@ -70,3 +70,55 @@ function getURLMetadata($url) { return $metadata; } + +function addBookmark($url, $title='', $tags='') { + $CONFIG_DBTYPE = OC_Config::getValue( "dbtype", "sqlite" ); + if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){ + $_ut = "strftime('%s','now')"; + } elseif($CONFIG_DBTYPE == 'pgsql') { + $_ut = 'date_part(\'epoch\',now())::integer'; + } else { + $_ut = "UNIX_TIMESTAMP()"; + } + + //FIXME: Detect when user adds a known URL + $query = OC_DB::prepare(" + INSERT INTO *PREFIX*bookmarks + (url, title, user_id, public, added, lastmodified) + VALUES (?, ?, ?, 0, $_ut, $_ut) + "); + + if(empty($title)) { + $metadata = getURLMetadata($url); + $title = $metadata['title']; + } + + $params=array( + htmlspecialchars_decode($url), + htmlspecialchars_decode($title), + OC_User::getUser() + ); + $query->execute($params); + + $b_id = OC_DB::insertid('*PREFIX*bookmarks'); + + if($b_id !== false) { + $query = OC_DB::prepare(" + INSERT INTO *PREFIX*bookmarks_tags + (bookmark_id, tag) + VALUES (?, ?) + "); + + $tags = explode(' ', urldecode($tags)); + foreach ($tags as $tag) { + if(empty($tag)) { + //avoid saving blankspaces + continue; + } + $params = array($b_id, trim($tag)); + $query->execute($params); + } + + return $b_id; + } +} \ No newline at end of file diff --git a/apps/bookmarks/css/bookmarks.css b/apps/bookmarks/css/bookmarks.css index 12ccf938b55..b1139f2c346 100644 --- a/apps/bookmarks/css/bookmarks.css +++ b/apps/bookmarks/css/bookmarks.css @@ -1,6 +1,7 @@ #content { overflow: auto; height: 100%; } #firstrun { width: 80%; margin: 5em auto auto auto; text-align: center; font-weight:bold; font-size:1.5em; color:#777;} #firstrun small { display: block; font-weight: normal; font-size: 0.5em; margin-bottom: 1.5em; } +#firstrun .button { font-size: 0.7em; } #firstrun #selections { font-size:0.8em; font-weight: normal; width: 100%; margin: 2em auto auto auto; clear: both; } .bookmarks_headline { diff --git a/apps/bookmarks/templates/addBm.php b/apps/bookmarks/templates/addBm.php index 9067d3481a3..dbe673f53a8 100644 --- a/apps/bookmarks/templates/addBm.php +++ b/apps/bookmarks/templates/addBm.php @@ -1,6 +1,11 @@ -
-

-

-

-

-
+ + + + + Read later - ownCloud + + + +

Saved!

+ + \ No newline at end of file diff --git a/apps/bookmarks/templates/bookmarklet.php b/apps/bookmarks/templates/bookmarklet.php index 5719603da5f..23779477cb6 100644 --- a/apps/bookmarks/templates/bookmarklet.php +++ b/apps/bookmarks/templates/bookmarklet.php @@ -3,6 +3,6 @@ function createBookmarklet() { $l = new OC_L10N('bookmarks'); echo '' . $l->t('Drag this to your browser bookmarks and click it, when you want to bookmark a webpage:') . '' - . '' - . $l->t('Add page to ownCloud') . ''; + . '' + . $l->t('Read later') . ''; } -- 2.39.5