summaryrefslogtreecommitdiff
path: root/www/api
diff options
context:
space:
mode:
authorcweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2009-10-03 14:00:33 +0000
committercweiske <cweiske@b3834d28-1941-0410-a4f8-b48e95affb8f>2009-10-03 14:00:33 +0000
commit29422fa55379aa61a61019b832c83dab6d450264 (patch)
treee5884ce6fed2cf1d02165a1b5667b99cd80262e5 /www/api
parentb8b1d06b2d899658fae64d0de506439ca0ea067c (diff)
downloadsemanticscuttle-29422fa55379aa61a61019b832c83dab6d450264.tar.gz
semanticscuttle-29422fa55379aa61a61019b832c83dab6d450264.tar.bz2
move files to new locations
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@386 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'www/api')
-rw-r--r--www/api/export_csv.php47
-rw-r--r--www/api/export_gcs.php66
-rw-r--r--www/api/export_html.php54
-rw-r--r--www/api/export_sioc.php90
-rw-r--r--www/api/httpauth.inc.php33
-rw-r--r--www/api/opensearch.php18
-rw-r--r--www/api/posts_add.php83
-rw-r--r--www/api/posts_all.php48
-rw-r--r--www/api/posts_dates.php40
-rw-r--r--www/api/posts_delete.php34
-rw-r--r--www/api/posts_get.php61
-rw-r--r--www/api/posts_public.php48
-rw-r--r--www/api/posts_recent.php62
-rw-r--r--www/api/posts_update.php25
-rw-r--r--www/api/tags_get.php26
-rw-r--r--www/api/tags_rename.php37
16 files changed, 772 insertions, 0 deletions
diff --git a/www/api/export_csv.php b/www/api/export_csv.php
new file mode 100644
index 0000000..2389642
--- /dev/null
+++ b/www/api/export_csv.php
@@ -0,0 +1,47 @@
+<?php
+// Export in CSV format in order to allow the import into a spreadsheet tool like Excel
+
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+// Check to see if a tag was specified.
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
+ $tag = trim($_REQUEST['tag']);
+else
+ $tag = NULL;
+
+// Get the posts relevant to the passed-in variables.
+$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag, NULL, getSortOrder());
+
+header("Content-Type: application/csv-tab-delimited-table;charset=UTF-8");
+header("Content-disposition: filename=exportBookmarks.csv");
+
+//columns titles
+echo 'url;title;tags;description';
+echo "\n";
+
+foreach($bookmarks['bookmarks'] as $row) {
+ if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
+ $description = '';
+ else
+ $description = filter(str_replace(array("\r\n", "\n", "\r"),"", $row['bDescription']), 'xml');
+
+ $taglist = '';
+ if (count($row['tags']) > 0) {
+ foreach($row['tags'] as $tag)
+ $taglist .= convertTag($tag) .',';
+ $taglist = substr($taglist, 0, -1);
+ } else {
+ $taglist = 'system:unfiled';
+ }
+
+ echo '"'.filter($row['bAddress'], 'xml') .'";"'. filter($row['bTitle'], 'xml') .'";"'. filter($taglist, 'xml') .'";"'. $description .'"';
+ echo "\n";
+}
+
+
+?>
diff --git a/www/api/export_gcs.php b/www/api/export_gcs.php
new file mode 100644
index 0000000..6f1f4c2
--- /dev/null
+++ b/www/api/export_gcs.php
@@ -0,0 +1,66 @@
+<?php
+/*
+ Export for Google Custom Search
+ */
+
+// Force HTTP authentication first!
+//require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+if($GLOBALS['enableGoogleCustomSearch'] == false) {
+ echo "Google Custom Search disabled. You can enable it into the config.inc.php file.";
+ die;
+}
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+
+/*
+ // Restrict to admins?
+ if(!$userservice->isAdmin($userservice->getCurrentUserId())) {
+ die(T_('You are not allowed to do this action (admin access)'));
+ }*/
+
+// Check if queried format is xml
+if (isset($_REQUEST['xml']) && (trim($_REQUEST['xml']) == 1))
+$xml = true;
+else
+$xml = false;
+
+// Check to see if a tag was specified.
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
+$tag = trim($_REQUEST['tag']);
+else
+$tag = NULL;
+
+// Get the posts relevant to the passed-in variables.
+$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, $tag, NULL, getSortOrder());
+
+
+// Set up the plain file and output all the posts.
+header('Content-Type: text/plain');
+if(!$xml) {
+ header('Content-Type: text/plain');
+ foreach($bookmarks['bookmarks'] as $row) {
+ if(checkUrl($row['bAddress'], false)) {
+ echo $row['bAddress']."\n";
+ }
+ }
+} else {
+ header('Content-Type: application/xml');
+ echo '<GoogleCustomizations>'."\n";
+ echo ' <Annotations>'."\n";
+ foreach($bookmarks['bookmarks'] as $row) {
+ //if(substr($row['bAddress'], 0, 7) == "http://") {
+ if(checkUrl($row['bAddress'], false)) {
+ echo ' <Annotation about="'.filter($row['bAddress']).'">'."\n";
+ echo ' <Label name="include"/>'."\n";
+ echo ' </Annotation>'."\n";
+ }
+ }
+ echo ' </Annotations>'."\n";
+ echo '</GoogleCustomizations>'."\n";
+}
+
+?>
diff --git a/www/api/export_html.php b/www/api/export_html.php
new file mode 100644
index 0000000..55553c2
--- /dev/null
+++ b/www/api/export_html.php
@@ -0,0 +1,54 @@
+<?php
+// Implements the del.icio.us API request for all a user's posts, optionally filtered by tag.
+
+// del.icio.us behavior:
+// - doesn't include the filtered tag as an attribute on the root element (we do)
+
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+// Check to see if a tag was specified.
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
+ $tag = trim($_REQUEST['tag']);
+else
+ $tag = NULL;
+
+// Get the posts relevant to the passed-in variables.
+$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag, NULL, getSortOrder());
+
+
+// Set up the XML file and output all the posts.
+echo '<!DOCTYPE NETSCAPE-Bookmark-file-1>'."\r\n";
+echo '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">';
+echo '<!-- This is an automatically generated file. -->'."\r\n";
+echo '<TITLE>Bookmarks</TITLE>'."\r\n";
+echo '<H1 LAST_MODIFIED="'. date('U') .'">Bookmarks for '. htmlspecialchars($currentUser->getUsername()) .''. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') ." from " . $sitename ."</H1>\r\n";
+echo '<DL><p>'."\r\n";
+
+
+
+foreach($bookmarks['bookmarks'] as $row) {
+ if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
+ $description = '';
+ else
+ $description = 'description="'. filter($row['bDescription'], 'xml') .'" ';
+
+ $taglist = '';
+ if (count($row['tags']) > 0) {
+ foreach($row['tags'] as $tag)
+ $taglist .= convertTag($tag) .',';
+ $taglist = substr($taglist, 0, -1);
+ } else {
+ $taglist = 'system:unfiled';
+ }
+
+ echo "\t<dt><a href=\"". filter($row['bAddress'], 'xml') .'" '. $description .' hash="'. md5($row['bAddress']) .'" tags="'. filter($taglist, 'xml') .'" ADD_DATE="'. date('U', strtotime($row['bDatetime'])) ."\" >" . filter($row['bTitle'], 'xml') ."</a>\r\n";
+}
+
+
+echo '</DL><p>';
+?>
diff --git a/www/api/export_sioc.php b/www/api/export_sioc.php
new file mode 100644
index 0000000..746d0ea
--- /dev/null
+++ b/www/api/export_sioc.php
@@ -0,0 +1,90 @@
+<?php
+/* Export data with semantic format (SIOC: http://sioc-project.org/, FOAF, SKOS, Annotea Ontology) */
+
+require_once('../header.inc.php');
+header('Content-Type: text/xml; charset=utf-8'); //we change headers html defined in headers.inc.php
+
+/* Service creation: only useful services are created */
+$userservice =& ServiceFactory::getServiceInstance('UserService');
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+?>
+<?php echo "<?xml version=\"1.0\" encoding=\"utf-8\"\n?>"; ?>
+<rdf:RDF
+ xmlns="http://xmlns.com/foaf/0.1/"
+ xmlns:foaf="http://xmlns.com/foaf/0.1/"
+ xmlns:rss="http://purl.org/rss/1.0/"
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:dcterms="http://purl.org/dc/terms/"
+ xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:sioc="http://rdfs.org/sioc/ns#"
+ xmlns:sioc_t="http://rdfs.org/sioc/types#"
+ xmlns:bm="http://www.w3.org/2002/01/bookmark#"
+ xmlns:skos="http://www.w3.org/2004/02/skos/core#">
+
+<?php
+//site and community are described using FOAF and SIOC ontology
+?>
+<sioc:Site rdf:about="<?php echo ROOT?>" >
+ <rdf:label><?php echo $GLOBALS['sitename']?></rdf:label>
+</sioc:Site>
+
+<?php //<sioc_t:BookmarkFolder />?>
+
+<?php
+//users are described using FOAF and SIOC ontology
+$users = $userservice->getObjectUsers();
+
+$usersArray = array(); // useful for bookmarks display
+foreach($users as $user) {
+ $usersArray[$user->getId()] = $user->getUserName();
+}
+?>
+
+<?php foreach($users as $user) :?>
+<sioc:User rdf:about="<?php echo createUrl('profile', $user->getUserName())?>">
+ <sioc:name><?php echo $user->getUserName() ?></sioc:name>
+ <sioc:member_of rdf:resource="<?php echo ROOT?>" />
+</sioc:User>
+<?php endforeach; ?>
+
+<?php
+/*
+No page for usergroup (users/admin) for the moment
+ <sioc:Usergroup rdf:ID="authors">
+ <sioc:name>Authors at PlanetRDF.com</sioc:name>
+ <sioc:has_member rdf:nodeID="sioc-id2245901" />
+ </sioc:Usergroup>
+*/
+?>
+
+<?php
+//bookmarks are described using Annotea ontology
+$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, NULL);
+?>
+
+<?php foreach($bookmarks['bookmarks'] as $bookmark): ?>
+<bm:Bookmark rdf:about="<?php echo createUrl('history', $bookmark['bHash']) ?>">
+ <dc:title><?php echo filter($bookmark['bTitle']) ?></dc:title>
+ <dc:created><?php echo filter($bookmark['bCreated']) ?></dc:created>
+ <dc:description><?php echo filter(strip_tags($bookmark['bDescription'])) ?></dc:description>
+ <dc:date><?php echo $bookmark['bDateTime'] ?></dc:date>
+ <bm:recalls rdf:resource="<?php echo filter($bookmark['bAddress']) ?>"/>
+ <sioc:owner_of rdf:resource="<?php echo createUrl('profile', $usersArray[$bookmark['uId']]) ?>"/>
+ <?php foreach($bookmark['tags'] as $tag): ?>
+ <sioc:topic>
+ <skos:concept rdf:about="<?php echo createUrl('bookmarks', $usersArray[$bookmark['uId']].'/'.$tag) ?>" />
+ </sioc:topic>
+ <?php endforeach; ?>
+</bm:Bookmark>
+
+<?php endforeach; ?>
+
+<?php
+// tags and concepts are described using SKOS ontology
+//concept for user/admins, preflabel, definition, top concept
+?>
+
+</rdf:RDF>
+
diff --git a/www/api/httpauth.inc.php b/www/api/httpauth.inc.php
new file mode 100644
index 0000000..5dd7444
--- /dev/null
+++ b/www/api/httpauth.inc.php
@@ -0,0 +1,33 @@
+<?php
+require_once('../header.inc.php');
+
+// Provides HTTP Basic authentication of a user, and sets two variables, sId and username,
+// with the user's info.
+
+function authenticate() {
+ header('WWW-Authenticate: Basic realm="SemanticScuttle API"');
+ header('HTTP/1.0 401 Unauthorized');
+
+ die(T_("Use of the API calls requires authentication."));
+}
+
+if(!$userservice->isLoggedOn()) {
+ /* Maybe we have caught authentication data in $_SERVER['REMOTE_USER']
+ ( Inspired by http://www.yetanothercommunitysystem.com/article-321-regle-comment-utiliser-l-authentification-http-en-php-chez-ovh ) */
+ if((!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']))
+ && preg_match('/Basic\s+(.*)$/i', $_SERVER['REMOTE_USER'], $matches)) {
+ list($name, $password) = explode(':', base64_decode($matches[1]));
+ $_SERVER['PHP_AUTH_USER'] = strip_tags($name);
+ $_SERVER['PHP_AUTH_PW'] = strip_tags($password);
+ }
+
+ if (!isset($_SERVER['PHP_AUTH_USER'])) {
+ authenticate();
+ } else {
+ $login = $userservice->login($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
+ if (!$login) {
+ authenticate();
+ }
+ }
+}
+?>
diff --git a/www/api/opensearch.php b/www/api/opensearch.php
new file mode 100644
index 0000000..a6f79f8
--- /dev/null
+++ b/www/api/opensearch.php
@@ -0,0 +1,18 @@
+<?php
+require_once('../header.inc.php');
+header("Content-type: text/xml");
+?>
+
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
+ xmlns:moz="http://www.mozilla.org/2006/browser/search/">
+ <ShortName><?php echo $GLOBALS['sitename']?></ShortName>
+ <LongName></LongName>
+ <Description><?php echo $GLOBALS['welcomeMessage']?></Description>
+ <InputEncoding>UTF-8</InputEncoding>
+ <Contact><?php echo $GLOBALS['adminemail']?></Contact>
+ <Developer>Jan Seifert "jan.seifert@uid.com"</Developer>
+ <Tags>semanticscuttle bookmark web</Tags>
+ <Image width="16" height="16">data:image/gif;base64,R0lGODlhEAAQAMZ9ANaPE9mREteTHtSXLdmXIdiXJtaYKdiYJ9iYKNeaLtKdP9CdRd2dLNWfQuWiFMqjX9+hNMykXt6jPOCkPM2oaM+paeCpQuGoR+OqOeKpR+GqS9+uWeSwU+ayS+uzOeWxVeWxWOSyWOu0POazXOS0YOm8Zee8cOy+WOm9a/jBLum+bPbCNurAbe7BYuvBc/LDV/LEV+zEdv/KKf/KLP/KLf/LLuzHe//MNP/NN/nMTv/OOf/OPP/OP/jNW//PPvnOVv/QQv7QRv/QRP/RR/HOhP/SSf/STPnRav/TT//TUPfScf/UUvzUXP/UVP/VV/bTfv/WWf/WW//WXP7XYf/XX//XYP/YZPPVmf/ZZv/ZZ/vYeP/aaf/aa//abP/abf/abvvaef/bb//bcfzbfP/ccv/cc//cdP/cdf/dd//deP/def3egP/ee//efP/efv/ffv/ggf/gg//ghP/ghfrfmv/hif/ii//ijP/jkfzjm//kkv7klv/lmP///////////yH5BAEKAH8ALAAAAAAQABAAAAergH+Cg38hhIeHIFcmiIgDLnt0Go2EE1pyd0QbjQMQDC9bZGprKBcjA4IfAQMrQUhOVFlhaGNPMRl/Aw4yMzc7QkZNUlZdZmASqAJKcW1WPDpARUtQUx0RgyR5fHpzUTU4PkMiqIMVNnh2c25lSTQpAIgqdXJvaWReXz0JiCxwbWhiuGCp8uMAohJszhw5AYMJlBwFEHFoYQHBAwUEMHgwgKjBA0QLKFAaKSgQADs=</Image>
+ <Url type="text/html" template="<?php echo $GLOBALS['root']?>search.php/all/{searchTerms}"/>
+ <moz:SearchForm><?php echo $GLOBALS['root']?></moz:SearchForm>
+</OpenSearchDescription>
diff --git a/www/api/posts_add.php b/www/api/posts_add.php
new file mode 100644
index 0000000..ba3e02c
--- /dev/null
+++ b/www/api/posts_add.php
@@ -0,0 +1,83 @@
+<?php
+// Implements the del.icio.us API request to add a new post.
+
+// del.icio.us behavior:
+// - tags can't have spaces
+// - address and description are mandatory
+
+// Scuttle behavior:
+// - Additional 'status' variable for privacy
+// - No support for 'replace' variable
+
+// Force HTTP authentication
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+// Get all the bookmark's passed-in information
+if (isset($_REQUEST['url']) && (trim($_REQUEST['url']) != ''))
+ $url = trim(urldecode($_REQUEST['url']));
+else
+ $url = NULL;
+
+if (isset($_REQUEST['description']) && (trim($_REQUEST['description']) != ''))
+ $description = trim($_REQUEST['description']);
+else
+ $description = NULL;
+
+if (isset($_REQUEST['extended']) && (trim($_REQUEST['extended']) != ""))
+ $extended = trim($_REQUEST['extended']);
+else
+ $extended = NULL;
+
+if (isset($_REQUEST['tags']) && (trim($_REQUEST['tags']) != '') && (trim($_REQUEST['tags']) != ','))
+ $tags = trim($_REQUEST['tags']);
+else
+ $tags = NULL;
+
+if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != ''))
+ $dt = trim($_REQUEST['dt']);
+else
+ $dt = NULL;
+
+$status = 0;
+if (isset($_REQUEST['status'])) {
+ $status_str = trim($_REQUEST['status']);
+ if (is_numeric($status_str)) {
+ $status = intval($status_str);
+ if($status < 0 || $status > 2) {
+ $status = 0;
+ }
+ } else {
+ switch ($status_str) {
+ case 'private':
+ $status = 2;
+ break;
+ case 'shared':
+ $status = 1;
+ break;
+ default:
+ $status = 0;
+ break;
+ }
+ }
+}
+
+// Error out if there's no address or description
+if (is_null($url) || is_null($description)) {
+ $added = false;
+} else {
+// We're good with info; now insert it!
+ if ($bookmarkservice->bookmarkExists($url, $userservice->getCurrentUserId()))
+ $added = false;
+ else
+ $added = $bookmarkservice->addBookmark($url, $description, $extended, '', $status, $tags, $dt, true);
+}
+
+// Set up the XML file and output the result.
+header('Content-Type: text/xml');
+echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
+echo '<result code="'. ($added ? 'done' : 'something went wrong') .'" />';
+?> \ No newline at end of file
diff --git a/www/api/posts_all.php b/www/api/posts_all.php
new file mode 100644
index 0000000..4ecbd7e
--- /dev/null
+++ b/www/api/posts_all.php
@@ -0,0 +1,48 @@
+<?php
+// Implements the del.icio.us API request for all a user's posts, optionally filtered by tag.
+
+// del.icio.us behavior:
+// - doesn't include the filtered tag as an attribute on the root element (we do)
+
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+
+// Check to see if a tag was specified.
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
+ $tag = trim($_REQUEST['tag']);
+else
+ $tag = NULL;
+
+// Get the posts relevant to the passed-in variables.
+$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag);
+
+// Set up the XML file and output all the posts.
+header('Content-Type: text/xml');
+echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
+echo '<posts update="'. gmdate('Y-m-d\TH:i:s\Z') .'" user="'. htmlspecialchars($currentUser->getUsername()) .'"'. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') .">\r\n";
+
+foreach($bookmarks['bookmarks'] as $row) {
+ if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
+ $description = '';
+ else
+ $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
+
+ $taglist = '';
+ if (count($row['tags']) > 0) {
+ foreach($row['tags'] as $tag)
+ $taglist .= convertTag($tag) .' ';
+ $taglist = substr($taglist, 0, -1);
+ } else {
+ $taglist = 'system:unfiled';
+ }
+
+ echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" description="'. filter($row['bTitle'], 'xml') .'" '. $description .'hash="'. md5($row['bAddress']) .'" tag="'. filter($taglist, 'xml') .'" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />\r\n";
+}
+
+echo '</posts>';
+?> \ No newline at end of file
diff --git a/www/api/posts_dates.php b/www/api/posts_dates.php
new file mode 100644
index 0000000..d4962ff
--- /dev/null
+++ b/www/api/posts_dates.php
@@ -0,0 +1,40 @@
+<?php
+// Implements the del.icio.us API request for a user's post counts by date (and optionally
+// by tag).
+
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+
+// Check to see if a tag was specified.
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
+ $tag = trim($_REQUEST['tag']);
+else
+ $tag = NULL;
+
+// Get the posts relevant to the passed-in variables.
+$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag);
+
+// Set up the XML file and output all the tags.
+header('Content-Type: text/xml');
+echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
+echo '<dates tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentUser->getUsername(), 'xml') ."\">\r\n";
+
+$lastdate = NULL;
+foreach($bookmarks['bookmarks'] as $row) {
+ $thisdate = gmdate('Y-m-d', strtotime($row['bDatetime']));
+ if ($thisdate != $lastdate && $lastdate != NULL) {
+ echo "\t<date count=\"". $count .'" date="'. $lastdate ."\" />\r\n";
+ $count = 1;
+ } else {
+ $count = $count + 1;
+ }
+ $lastdate = $thisdate;
+}
+
+echo "</dates>";
+?> \ No newline at end of file
diff --git a/www/api/posts_delete.php b/www/api/posts_delete.php
new file mode 100644
index 0000000..d24ba59
--- /dev/null
+++ b/www/api/posts_delete.php
@@ -0,0 +1,34 @@
+<?php
+// Implements the del.icio.us API request to delete a post.
+
+// del.icio.us behavior:
+// - returns "done" even if the bookmark doesn't exist;
+// - does NOT allow the hash for the url parameter;
+// - doesn't set the Content-Type to text/xml (we do).
+
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+
+// Note that del.icio.us only errors out if no URL was passed in; there's no error on attempting
+// to delete a bookmark you don't have.
+
+// Error out if there's no address
+if (is_null($_REQUEST['url'])) {
+ $deleted = false;
+} else {
+ $bookmark = $bookmarkservice->getBookmarkByAddress($_REQUEST['url']);
+ $bid = $bookmark['bId'];
+ $delete = $bookmarkservice->deleteBookmark($bid);
+ $deleted = true;
+}
+
+// Set up the XML file and output the result.
+header('Content-Type: text/xml');
+echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
+echo '<result code="'. ($deleted ? 'done' : 'something went wrong') .'" />';
+?> \ No newline at end of file
diff --git a/www/api/posts_get.php b/www/api/posts_get.php
new file mode 100644
index 0000000..34d192e
--- /dev/null
+++ b/www/api/posts_get.php
@@ -0,0 +1,61 @@
+<?php
+// Implements the del.icio.us API request for a user's posts, optionally filtered by tag and/or
+// date. Note that when using a date to select the posts returned, del.icio.us uses GMT dates --
+// so we do too.
+
+// del.icio.us behavior:
+// - includes an empty tag attribute on the root element when it hasn't been specified
+
+// Scuttle behavior:
+// - Uses today, instead of the last bookmarked date, if no date is specified
+
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+
+// Check to see if a tag was specified.
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
+ $tag = trim($_REQUEST['tag']);
+else
+ $tag = NULL;
+
+// 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');
+$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.
+header('Content-Type: text/xml');
+echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
+echo '<posts'. (is_null($dtstart) ? '' : ' dt="'. $dtstart .'"') .' tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentUser->getUsername(), 'xml') ."\">\r\n";
+
+foreach($bookmarks['bookmarks'] as $row) {
+ if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
+ $description = '';
+ else
+ $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
+
+ $taglist = '';
+ if (count($row['tags']) > 0) {
+ foreach($row['tags'] as $tag)
+ $taglist .= convertTag($tag) .' ';
+ $taglist = substr($taglist, 0, -1);
+ } else {
+ $taglist = 'system:unfiled';
+ }
+
+ echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" description="'. filter($row['bTitle'], 'xml') .'" '. $description .'hash="'. $row['bHash'] .'" others="'. $bookmarkservice->countOthers($row['bAddress']) .'" tag="'. filter($taglist, 'xml') .'" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />\r\n";
+}
+
+echo '</posts>';
+?> \ No newline at end of file
diff --git a/www/api/posts_public.php b/www/api/posts_public.php
new file mode 100644
index 0000000..f7aa955
--- /dev/null
+++ b/www/api/posts_public.php
@@ -0,0 +1,48 @@
+<?php
+// Implements the del.icio.us API request for all a user's posts, optionally filtered by tag.
+
+// del.icio.us behavior:
+// - doesn't include the filtered tag as an attribute on the root element (we do)
+
+// Force HTTP authentication first!
+//require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+
+// Check to see if a tag was specified.
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
+ $tag = trim($_REQUEST['tag']);
+else
+ $tag = NULL;
+
+// Get the posts relevant to the passed-in variables.
+$bookmarks =& $bookmarkservice->getBookmarks(0, NULL, NULL, $tag);
+
+// Set up the XML file and output all the posts.
+header('Content-Type: text/xml');
+echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
+echo '<posts update="'. gmdate('Y-m-d\TH:i:s\Z') .'" '. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') .">\r\n";
+
+foreach($bookmarks['bookmarks'] as $row) {
+ if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
+ $description = '';
+ else
+ $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
+
+ $taglist = '';
+ if (count($row['tags']) > 0) {
+ foreach($row['tags'] as $tag)
+ $taglist .= convertTag($tag) .' ';
+ $taglist = substr($taglist, 0, -1);
+ } else {
+ $taglist = 'system:unfiled';
+ }
+
+ echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" description="'. filter($row['bTitle'], 'xml') .'" '. $description .'hash="'. md5($row['bAddress']) .'" tag="'. filter($taglist, 'xml') .'" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />\r\n";
+}
+
+echo '</posts>';
+?>
diff --git a/www/api/posts_recent.php b/www/api/posts_recent.php
new file mode 100644
index 0000000..daa9d39
--- /dev/null
+++ b/www/api/posts_recent.php
@@ -0,0 +1,62 @@
+<?php
+// Implements the del.icio.us API request for a user's recent posts, optionally filtered by
+// tag and/or number of posts (default 15, max 100, just like del.icio.us).
+
+// Set default and max number of posts
+$countDefault = 15;
+$countMax = 100;
+
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+
+// Check to see if a tag was specified.
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
+ $tag = trim($_REQUEST['tag']);
+else
+ $tag = NULL;
+
+// Check to see if the number of items was specified.
+if (isset($_REQUEST['count']) && (intval($_REQUEST['count']) != 0)) {
+ $count = intval($_REQUEST['count']);
+ if ($count > $countMax)
+ $count = $countMax;
+ elseif ($count < 0)
+ $count = 0;
+} else {
+ $count = $countDefault;
+}
+
+// Get the posts relevant to the passed-in variables.
+$bookmarks =& $bookmarkservice->getBookmarks(0, $count, $userservice->getCurrentUserId(), $tag);
+
+
+// Set up the XML file and output all the tags.
+header('Content-Type: text/xml');
+echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
+echo '<posts tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentUser->getUsername(), 'xml') ."\">\r\n";
+
+foreach($bookmarks['bookmarks'] as $row) {
+ if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
+ $description = '';
+ else
+ $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
+
+ $taglist = '';
+ if (count($row['tags']) > 0) {
+ foreach($row['tags'] as $tag)
+ $taglist .= convertTag($tag) .' ';
+ $taglist = substr($taglist, 0, -1);
+ } else {
+ $taglist = 'system:unfiled';
+ }
+
+ echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" description="'. filter($row['bTitle'], 'xml') .'" '. $description .'hash="'. $row['bHash'] .'" tag="'. filter($taglist, 'xml') .'" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />\r\n";
+}
+
+echo '</posts>';
+?> \ No newline at end of file
diff --git a/www/api/posts_update.php b/www/api/posts_update.php
new file mode 100644
index 0000000..6ea50e2
--- /dev/null
+++ b/www/api/posts_update.php
@@ -0,0 +1,25 @@
+<?php
+// Implements the del.icio.us API request for a user's last update time and date.
+
+// del.icio.us behavior:
+// - doesn't set the Content-Type to text/xml (we do).
+
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
+
+
+// Get the posts relevant to the passed-in variables.
+$bookmarks =& $bookmarkservice->getBookmarks(0, 1, $userservice->getCurrentUserId());
+
+
+// Set up the XML file and output all the tags.
+header('Content-Type: text/xml');
+echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
+foreach($bookmarks['bookmarks'] as $row) {
+ echo '<update time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) .'" />';
+}
+?> \ No newline at end of file
diff --git a/www/api/tags_get.php b/www/api/tags_get.php
new file mode 100644
index 0000000..cee36ee
--- /dev/null
+++ b/www/api/tags_get.php
@@ -0,0 +1,26 @@
+<?php
+// Implements the del.icio.us API request for all a user's tags.
+
+// del.icio.us behavior:
+// - tags can't have spaces
+
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService');
+
+
+// Get the tags relevant to the passed-in variables.
+$tags =& $b2tservice->getTags($userservice->getCurrentUserId());
+
+// Set up the XML file and output all the tags.
+header('Content-Type: text/xml');
+echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
+echo "<tags>\r\n";
+foreach($tags as $row) {
+ echo "\t<tag count=\"". $row['bCount'] .'" tag="'. filter(convertTag($row['tag'], 'out'), 'xml') ."\" />\r\n";
+}
+echo "</tags>";
+?>
diff --git a/www/api/tags_rename.php b/www/api/tags_rename.php
new file mode 100644
index 0000000..dd16339
--- /dev/null
+++ b/www/api/tags_rename.php
@@ -0,0 +1,37 @@
+<?php
+// Implements the del.icio.us API request to rename a user's tag.
+
+// del.icio.us behavior:
+// - oddly, returns an entirely different result (<result></result>) than the other API calls.
+
+// Force HTTP authentication first!
+require_once('httpauth.inc.php');
+require_once('../header.inc.php');
+
+/* Service creation: only useful services are created */
+$b2tservice =& ServiceFactory::getServiceInstance('Bookmark2TagService');
+
+// Get the tag info.
+if (isset($_REQUEST['old']) && (trim($_REQUEST['old']) != ''))
+ $old = trim($_REQUEST['old']);
+else
+ $old = NULL;
+
+if (isset($_REQUEST['new']) && (trim($_REQUEST['new']) != ''))
+ $new = trim($_REQUEST['new']);
+else
+ $new = NULL;
+
+if (is_null($old) || is_null($new)) {
+ $renamed = false;
+} else {
+ // Rename the tag.
+ $result = $b2tservice->renameTag($userservice->getCurrentUserId(), $old, $new, true);
+ $renamed = $result;
+}
+
+// Set up the XML file and output the result.
+header('Content-Type: text/xml');
+echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
+echo '<result>'. ($renamed ? 'done' : 'something went wrong') .'</result>';
+?>