mirror of
https://github.com/owncloud/bookmarks.git
synced 2025-02-07 06:54:15 +01:00
Add description column for bookmarks and correct adding public link
This commit is contained in:
parent
150f2a3f27
commit
bd759557ce
@ -39,7 +39,8 @@ if(!isset($_GET['url']) || trim($_GET['url']) == '') {
|
|||||||
exit;
|
exit;
|
||||||
}elseif(isset($_POST['url'])) {
|
}elseif(isset($_POST['url'])) {
|
||||||
$tags = isset($_POST['item']['tags']) ? $_POST['item']['tags'] : array();
|
$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));
|
OCP\JSON::success(array('id'=>$bm));
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
@ -61,7 +62,7 @@ $bm = array('title'=> $title,
|
|||||||
'url'=> $_GET['url'],
|
'url'=> $_GET['url'],
|
||||||
'tags'=> array(),
|
'tags'=> array(),
|
||||||
'desc'=>'',
|
'desc'=>'',
|
||||||
'is_public'=>1,
|
'is_public'=>0,
|
||||||
);
|
);
|
||||||
|
|
||||||
//Find All Tags
|
//Find All Tags
|
||||||
|
@ -36,6 +36,13 @@
|
|||||||
<notnull>true</notnull>
|
<notnull>true</notnull>
|
||||||
<length>64</length>
|
<length>64</length>
|
||||||
</field>
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>description</name>
|
||||||
|
<type>text</type>
|
||||||
|
<default></default>
|
||||||
|
<notnull>true</notnull>
|
||||||
|
<length>4096</length>
|
||||||
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>public</name>
|
<name>public</name>
|
||||||
<type>integer</type>
|
<type>integer</type>
|
||||||
|
@ -1 +1 @@
|
|||||||
0.2
|
0.3
|
@ -54,7 +54,7 @@ function getURLMetadata($url) {
|
|||||||
//if not (allowed) protocol is given, assume http
|
//if not (allowed) protocol is given, assume http
|
||||||
if(preg_match($protocols, $url) == 0) {
|
if(preg_match($protocols, $url) == 0) {
|
||||||
$url = 'http://' . $url;
|
$url = 'http://' . $url;
|
||||||
}
|
}
|
||||||
$metadata['url'] = $url;
|
$metadata['url'] = $url;
|
||||||
if (!function_exists('curl_init')){
|
if (!function_exists('curl_init')){
|
||||||
return $metadata;
|
return $metadata;
|
||||||
@ -66,11 +66,11 @@ function getURLMetadata($url) {
|
|||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
|
|
||||||
@preg_match( "/<title>(.*)<\/title>/sUi", $page, $match );
|
@preg_match( "/<title>(.*)<\/title>/sUi", $page, $match );
|
||||||
$metadata['title'] = htmlspecialchars_decode(@$match[1]);
|
$metadata['title'] = htmlspecialchars_decode(@$match[1]);
|
||||||
return $metadata;
|
return $metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addBookmark($url, $title, $tags='') {
|
function addBookmark($url, $title, $tags='', $description='', $is_public=false) {
|
||||||
$CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" );
|
$CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" );
|
||||||
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
|
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
|
||||||
$_ut = "strftime('%s','now')";
|
$_ut = "strftime('%s','now')";
|
||||||
@ -79,41 +79,33 @@ function addBookmark($url, $title, $tags='') {
|
|||||||
} else {
|
} else {
|
||||||
$_ut = "UNIX_TIMESTAMP()";
|
$_ut = "UNIX_TIMESTAMP()";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$is_public = $is_public ? 1 : 0;
|
||||||
//FIXME: Detect when user adds a known URL
|
//FIXME: Detect when user adds a known URL
|
||||||
$query = OCP\DB::prepare("
|
$query = OCP\DB::prepare("
|
||||||
INSERT INTO `*PREFIX*bookmarks`
|
INSERT INTO `*PREFIX*bookmarks`
|
||||||
(`url`, `title`, `user_id`, `public`, `added`, `lastmodified`)
|
(url, title, user_id, public, added, lastmodified, description)
|
||||||
VALUES (?, ?, ?, 0, $_ut, $_ut)
|
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(
|
$params=array(
|
||||||
htmlspecialchars_decode($url),
|
htmlspecialchars_decode($url),
|
||||||
htmlspecialchars_decode($title),
|
htmlspecialchars_decode($title),
|
||||||
OCP\USER::getUser()
|
OCP\USER::getUser(),
|
||||||
|
$is_public,
|
||||||
|
$description,
|
||||||
);
|
);
|
||||||
$query->execute($params);
|
$query->execute($params);
|
||||||
|
|
||||||
$b_id = OCP\DB::insertid('*PREFIX*bookmarks');
|
$b_id = OCP\DB::insertid('*PREFIX*bookmarks');
|
||||||
|
|
||||||
if($b_id !== false) {
|
if($b_id !== false) {
|
||||||
$query = OCP\DB::prepare("
|
$query = OCP\DB::prepare("
|
||||||
INSERT INTO `*PREFIX*bookmarks_tags`
|
INSERT INTO `*PREFIX*bookmarks_tags`
|
||||||
(`bookmark_id`, `tag`)
|
(`bookmark_id`, `tag`)
|
||||||
VALUES (?, ?)
|
VALUES (?, ?)
|
||||||
");
|
");
|
||||||
|
|
||||||
$tags = explode(' ', urldecode($tags));
|
$tags = explode(' ', urldecode($tags));
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
if(empty($tag)) {
|
if(empty($tag)) {
|
||||||
@ -123,7 +115,7 @@ function addBookmark($url, $title, $tags='') {
|
|||||||
$params = array($b_id, trim($tag));
|
$params = array($b_id, trim($tag));
|
||||||
$query->execute($params);
|
$query->execute($params);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $b_id;
|
return $b_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
41
bookmarksHelper.php.rej
Normal file
41
bookmarksHelper.php.rej
Normal 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);
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user