1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2025-01-31 01:52:11 +01:00

Add description column for bookmarks and correct adding public link

This commit is contained in:
Brice Maron 2012-06-27 11:20:51 +02:00
parent 150f2a3f27
commit bd759557ce
5 changed files with 69 additions and 28 deletions

View File

@ -39,7 +39,8 @@ if(!isset($_GET['url']) || trim($_GET['url']) == '') {
exit;
}elseif(isset($_POST['url'])) {
$tags = isset($_POST['item']['tags']) ? $_POST['item']['tags'] : array();
$bm = addBookmark($_POST['url'], $_POST['title'], implode(' ',$tags),$_POST['desc'], $_POST['is_public']);
$pub = isset($_POST['is_public']) ? true : false;
$bm = addBookmark($_POST['url'], $_POST['title'], implode(' ',$tags),$_POST['desc'], $pub);
OCP\JSON::success(array('id'=>$bm));
exit();
}
@ -61,7 +62,7 @@ $bm = array('title'=> $title,
'url'=> $_GET['url'],
'tags'=> array(),
'desc'=>'',
'is_public'=>1,
'is_public'=>0,
);
//Find All Tags

View File

@ -36,6 +36,13 @@
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>description</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>4096</length>
</field>
<field>
<name>public</name>
<type>integer</type>

View File

@ -1 +1 @@
0.2
0.3

View File

@ -54,7 +54,7 @@ function getURLMetadata($url) {
//if not (allowed) protocol is given, assume http
if(preg_match($protocols, $url) == 0) {
$url = 'http://' . $url;
}
}
$metadata['url'] = $url;
if (!function_exists('curl_init')){
return $metadata;
@ -66,11 +66,11 @@ function getURLMetadata($url) {
curl_close($ch);
@preg_match( "/<title>(.*)<\/title>/sUi", $page, $match );
$metadata['title'] = htmlspecialchars_decode(@$match[1]);
$metadata['title'] = htmlspecialchars_decode(@$match[1]);
return $metadata;
}
function addBookmark($url, $title, $tags='') {
function addBookmark($url, $title, $tags='', $description='', $is_public=false) {
$CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" );
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
$_ut = "strftime('%s','now')";
@ -79,41 +79,33 @@ function addBookmark($url, $title, $tags='') {
} else {
$_ut = "UNIX_TIMESTAMP()";
}
$is_public = $is_public ? 1 : 0;
//FIXME: Detect when user adds a known URL
$query = OCP\DB::prepare("
INSERT INTO `*PREFIX*bookmarks`
(`url`, `title`, `user_id`, `public`, `added`, `lastmodified`)
VALUES (?, ?, ?, 0, $_ut, $_ut)
(url, title, user_id, public, added, lastmodified, description)
VALUES (?, ?, ?, ?, $_ut, $_ut, ?)
");
if(empty($title)) {
$metadata = getURLMetadata($url);
if(isset($metadata['title'])) // Check for problems fetching the title
$title = $metadata['title'];
}
if(empty($title)) {
$l = OC_L10N::get('bookmarks');
$title = $l->t('unnamed');
}
$params=array(
htmlspecialchars_decode($url),
htmlspecialchars_decode($title),
OCP\USER::getUser()
htmlspecialchars_decode($url),
htmlspecialchars_decode($title),
OCP\USER::getUser(),
$is_public,
$description,
);
$query->execute($params);
$b_id = OCP\DB::insertid('*PREFIX*bookmarks');
if($b_id !== false) {
$query = OCP\DB::prepare("
INSERT INTO `*PREFIX*bookmarks_tags`
(`bookmark_id`, `tag`)
VALUES (?, ?)
");
$tags = explode(' ', urldecode($tags));
foreach ($tags as $tag) {
if(empty($tag)) {
@ -123,7 +115,7 @@ function addBookmark($url, $title, $tags='') {
$params = array($b_id, trim($tag));
$query->execute($params);
}
return $b_id;
}
}

41
bookmarksHelper.php.rej Normal file
View File

@ -0,0 +1,41 @@
diff a/bookmarks/bookmarksHelper.php b/bookmarks/bookmarksHelper.php (rejected hunks)
@@ -79,29 +79,21 @@ function addBookmark($url, $title, $tags='') {
} else {
$_ut = "UNIX_TIMESTAMP()";
}
-
+
+ $is_public = $is_public ? 1 : 0;
//FIXME: Detect when user adds a known URL
$query = OCP\DB::prepare("
INSERT INTO *PREFIX*bookmarks
- (url, title, user_id, public, added, lastmodified)
- VALUES (?, ?, ?, 0, $_ut, $_ut)
+ (url, title, user_id, public, added, lastmodified, description)
+ VALUES (?, ?, ?, ?, $_ut, $_ut, ?)
");
-
- if(empty($title)) {
- $metadata = getURLMetadata($url);
- if(isset($metadata['title'])) // Check for problems fetching the title
- $title = $metadata['title'];
- }
-
- if(empty($title)) {
- $l = OC_L10N::get('bookmarks');
- $title = $l->t('unnamed');
- }
-
+
$params=array(
- htmlspecialchars_decode($url),
- htmlspecialchars_decode($title),
- OCP\USER::getUser()
+ htmlspecialchars_decode($url),
+ htmlspecialchars_decode($title),
+ OCP\USER::getUser(),
+ $is_public,
+ $description,
);
$query->execute($params);