diff --git a/src/SemanticScuttle/Service/Bookmark.php b/src/SemanticScuttle/Service/Bookmark.php
index 13153503..91d0c182 100644
--- a/src/SemanticScuttle/Service/Bookmark.php
+++ b/src/SemanticScuttle/Service/Bookmark.php
@@ -699,7 +699,7 @@ public function updateBookmark(
* @param integer $enddate Filter for creation date.
* SQL-DateTime value
* "YYYY-MM-DD hh:ii:ss'
- * @param string $hash Filter by URL hash
+ * @param mixed $hash Filter by URL hash, may be an array of hashes or a single hash string
*
* @return array Array with two keys: 'bookmarks' and 'total'.
* First contains an array of bookmarks, 'total'
@@ -896,7 +896,14 @@ public function getBookmarks(
// Hash
if ($hash) {
- $query_4 .= ' AND B.bHash = "'. $hash .'"';
+ if (!is_array($hash)) {
+ $hash = array($hash);
+ }
+ $hash_query = array();
+ foreach ($hash as $h) {
+ $hash_query[] = ' B.bHash = "'. $h .'" ';
+ }
+ $query_4 .= ' AND ('. implode($hash_query, ' OR ') .') ';
}
diff --git a/www/api/posts_add.php b/www/api/posts_add.php
index 80d65155..121325f8 100644
--- a/www/api/posts_add.php
+++ b/www/api/posts_add.php
@@ -6,8 +6,8 @@
* @param string $url URL of the bookmark (required)
* @param string $description Bookmark title (required)
* @param string $extended Extended bookmark description (optional)
- * @param string $tags Space-separated list of tags (optional)
- * @param string $dt Date and time of bookmark creation (optional)
+ * @param string $tags comma delimited list of tags (optional)
+ * @param string $dt UTC Date and time of bookmark creation (optional)
* Must be of format YYYY-MM-DDTHH:II:SSZ
* @param integer $status Visibility status (optional):
* - 2 or 'private': Bookmark is totally private
@@ -20,7 +20,6 @@
* same URL (optional)
*
* Notes:
- * - tags cannot have spaces
* - URL and description (title) are mandatory
* - delicious "description" is the "title" in SemanticScuttle
* - delicious "extended" is the "description" in SemanticScuttle
@@ -74,7 +73,8 @@
}
if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != '')) {
- $dt = trim($_REQUEST['dt']);
+ $date = new DateTime( trim($_REQUEST['dt']) , new DateTimeZone('UTC')); //adjust to UTC
+ $dt = date('Y-m-d\TH:i:s\Z', $date->getTimestamp());
} else {
$dt = null;
}
@@ -134,7 +134,7 @@
if (!$exists) {
$added = $bs->addBookmark(
- $url, $description, $extended, '', $status, $tags, null, $dt, true
+ $url, $description, $extended, '', $status, $tags, null, $dt, false //false, because new API uses comma separated tags
);
$msg = 'done';
}
@@ -143,4 +143,4 @@
// Set up the XML file and output the result.
echo '\r\n";
echo '';
-?>
\ No newline at end of file
+?>
diff --git a/www/api/posts_all.php b/www/api/posts_all.php
index c70d14c4..eff53496 100644
--- a/www/api/posts_all.php
+++ b/www/api/posts_all.php
@@ -1,19 +1,62 @@
';
+ exit();
+}
+
+// no_bookmarks: indicate, that there are no bookmarks using these filters
+function no_bookmarks() {
+ echo '';
+ exit();
+}
// Force HTTP authentication first!
$httpContentType = 'text/xml';
require_once 'httpauth.inc.php';
+// xml header
+echo '\r\n";
+
/* Service creation: only useful services are created */
$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
+// special case - hashes: only return url hash and meta (change indicator)
+if ( isset($_REQUEST['hashes']) ) {
+ // get all bookmarks
+ $bookmarks = $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId());
+
+ // output:
+ // Set up the XML file and output all the posts.
+ echo "\r\n";
+ foreach($bookmarks['bookmarks'] as $row) {
+ $url = md5($row['bAddress']);
+ //create a meta, which changes, when the bookmark changes in the form of a md5 hash (as delicious does it).
+ $meta = md5($row['bModified']);
+
+ echo "\t\r\n";
+ }
+
+ echo '';
+ exit();
+}
// Check to see if a tag was specified.
if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
@@ -21,12 +64,63 @@
else
$tag = NULL;
+// 'tag separator' option
+if (isset($_REQUEST['tag_separator']) && (trim($_REQUEST['tag_separator']) == 'comma'))
+ $tag_separator = ',';
+else
+ $tag_separator = ' ';
+
+// 'start' option
+if (isset($_REQUEST['start']) && (intval($_REQUEST['start']) > 0))
+ $start = intval($_REQUEST['start']);
+else
+ $start = 0; //default in delicious api
+
+// 'results' option
+// upper limit of delicious api is 100000. There is no upper limit here. TODO: implement upper limit?
+if (isset($_REQUEST['results'])) {
+ if( $_REQUEST['results'] < 0 )
+ fail(); //like delicious
+ elseif( $_REQUEST['results'] == 0 )
+ no_bookmarks();
+ else
+ $results = intval($_REQUEST['results']);
+} else {
+ $results = 1000; //default, as in delicious api
+}
+
+// 'fromdt' option: filter result by date
+if (isset($_REQUEST['fromdt'])) {
+ $date = new DateTime( $_REQUEST['fromdt'] , new DateTimeZone('UTC')); //adjust to UTC
+ $fromdt = date('Y-m-d\TH:i:s\Z', $date->getTimestamp());
+} else {
+ $fromdt = NULL;
+}
+
+// 'todt' option: filter result by date
+if (isset($_REQUEST['todt'])) {
+ $date = new DateTime( $_REQUEST['todt'] , new DateTimeZone('UTC')); //adjust to UTC
+ $todt = date('Y-m-d\TH:i:s\Z', $date->getTimestamp());
+} else {
+ $todt = NULL;
+}
+
+// 'meta' option: get meta (change indicator)
+if (isset($_REQUEST['meta']) && (trim($_REQUEST['meta']) == 'yes'))
+ $meta = true;
+else
+ $meta = false;
+
// Get the posts relevant to the passed-in variables.
-$bookmarks = $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag);
+$bookmarks = $bookmarkservice->getBookmarks($start, $results, $userservice->getCurrentUserId(), $tag, NULL, NULL, NULL, $fromdt, $todt);
+
+// check for empty result
+if (count($bookmarks['bookmarks'])==0) {
+ no_bookmarks();
+}
// Set up the XML file and output all the posts.
-echo '\r\n";
-echo '\r\n";
+echo '\r\n";
foreach($bookmarks['bookmarks'] as $row) {
if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
@@ -37,13 +131,19 @@
$taglist = '';
if (count($row['tags']) > 0) {
foreach($row['tags'] as $tag)
- $taglist .= convertTag($tag) .' ';
+ $taglist .= convertTag($tag) . $tag_separator;
$taglist = substr($taglist, 0, -1);
} else {
$taglist = 'system:unfiled';
}
- echo "\t\r\n";
+ if( $meta ) {
+ $meta_print = ' meta="'. md5($row['bModified']) .'" ';
+ } else {
+ $meta_print = '';
+ }
+
+ echo "\t\r\n";
}
echo '';
diff --git a/www/api/posts_get.php b/www/api/posts_get.php
index e39058b5..fa16b868 100644
--- a/www/api/posts_get.php
+++ b/www/api/posts_get.php
@@ -32,32 +32,70 @@
/* Service creation: only useful services are created */
$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
+//// 'meta' argument
+$includeMeta = (isset($_REQUEST['meta']) && (trim($_REQUEST['meta']) == 'yes'));
-// Check to see if a tag was specified.
-if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) {
- $tag = trim($_REQUEST['tag']);
+//// 'tag_separator' argument
+if (isset($_REQUEST['tag_separator']) && (trim($_REQUEST['tag_separator']) == 'comma')) {
+ $tag_separator = ',';
} else {
- $tag = null;
+ $tag_separator = ' ';
}
-// Check to see if a date was specified; the format should be YYYY-MM-DD
-if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != '')) {
- $dtstart = trim($_REQUEST['dt']);
-} else {
- $dtstart = date('Y-m-d H:i:s');
+//// 'url' argument
+if (isset($_REQUEST['url']) && (trim($_REQUEST['url']) != '')) {
+ $_REQUEST['hashes'] = md5($_REQUEST['url']);
}
-$dtend = date('Y-m-d H:i:s', strtotime($dtstart .'+1 day'));
-// Get the posts relevant to the passed-in variables.
-$bookmarks = $bookmarkservice->getBookmarks(
- 0, null, $userservice->getCurrentUserId(), $tag,
- null, null, null, $dtstart, $dtend
-);
+//// 'hashes' argument
+if (isset($_REQUEST['hashes']) && (trim($_REQUEST['hashes']) != '')) {
+ $hashes = explode(' ', trim($_REQUEST['hashes']) );
+ // directly get the bookmarks for these hashes
+ //TODO: getBookmarks can't handle multiple hashes
+ $bookmarks = $bookmarkservice->getBookmarks(
+ 0, null, $userservice->getCurrentUserId(), null,
+ null, null, null, null, null, $hashes
+ );
+} else {
+
+ //// 'tag' argument
+ // Check to see if a tag was specified.
+ if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) {
+ // convert spaces back to '+' and explode
+ $tag = str_replace(' ', '+', trim($_REQUEST['tag']));
+ $tag = explode('+', $tag);
+ } else {
+ $tag = null;
+ }
+
+ //// 'dt' argument
+ // Check to see if a date was specified; the format should be YYYY-MM-DD in GMT/UTC
+ if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != '')) {
+ $dtstart = trim($_REQUEST['dt']);
+ } else {
+ $dtstart = gmdate('Y-m-d') . ' 00:00:00'; //Default: Today midnight (UTC)
+ }
+ //adjust from UTC to server time
+ $date = new DateTime( $dtstart , new DateTimeZone('UTC'));
+ $dtstart = date('Y-m-d H:i:s', $date->getTimestamp());
+ $dtstart_day = date('Y-m-d', $date->getTimestamp());
+
+ $dtend = date('Y-m-d H:i:s', strtotime($dtstart .'+1 day'));
+
+ //
+
+ // Get the posts relevant to the passed-in variables.
+ $bookmarks = $bookmarkservice->getBookmarks(
+ 0, null, $userservice->getCurrentUserId(), $tag,
+ null, null, null, $dtstart, $dtend
+ );
+
+}
// Set up the XML file and output all the tags.
-echo '\r\n";
-echo '\r\n";
+echo '\r\n";
+echo '\r\n";
foreach ($bookmarks['bookmarks'] as $row) {
if (is_null($row['bDescription']) || (trim($row['bDescription']) == '')) {
@@ -69,14 +107,14 @@
$taglist = '';
if (count($row['tags']) > 0) {
foreach ($row['tags'] as $tag) {
- $taglist .= convertTag($tag) . ' ';
+ $taglist .= convertTag($tag) . $tag_separator;
}
$taglist = substr($taglist, 0, -1);
} else {
$taglist = 'system:unfiled';
}
- echo "\t\r\n";
+ echo "\t\r\n";
}
echo '';