aboutsummaryrefslogtreecommitdiff
path: root/www/api
diff options
context:
space:
mode:
Diffstat (limited to 'www/api')
-rw-r--r--www/api/export_csv.php63
-rw-r--r--www/api/export_gcs.php67
-rw-r--r--www/api/export_html.php81
-rw-r--r--www/api/export_sioc.php90
-rw-r--r--www/api/httpauth.inc.php58
-rw-r--r--www/api/opensearch.php16
-rw-r--r--www/api/posts_add.php146
-rw-r--r--www/api/posts_all.php50
-rw-r--r--www/api/posts_dates.php60
-rw-r--r--www/api/posts_delete.php57
-rw-r--r--www/api/posts_get.php83
-rw-r--r--www/api/posts_public.php51
-rw-r--r--www/api/posts_recent.php85
-rw-r--r--www/api/posts_update.php58
-rw-r--r--www/api/tags_get.php25
-rw-r--r--www/api/tags_rename.php36
16 files changed, 1026 insertions, 0 deletions
diff --git a/www/api/export_csv.php b/www/api/export_csv.php
new file mode 100644
index 0000000..bb469b1
--- /dev/null
+++ b/www/api/export_csv.php
@@ -0,0 +1,63 @@
+<?php
+/**
+ * Export own bookmarks in CSV format in order to allow the import
+ * into a spreadsheet tool like Excel
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+// Force HTTP authentication first!
+$httpContentType = 'application/csv-tab-delimited-table';
+require_once 'httpauth.inc.php';
+header("Content-disposition: filename=exportBookmarks.csv");
+
+/* Service creation: only useful services are created */
+$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
+
+// Check to see if a tag was specified.
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) {
+ //$_GET vars have + replaced to " " automatically
+ $tag = str_replace(' ', '+', 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()
+);
+
+//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..06ab217
--- /dev/null
+++ b/www/api/export_gcs.php
@@ -0,0 +1,67 @@
+<?php
+/*
+ Export for Google Custom Search
+ */
+
+// Force HTTP authentication first!
+//require_once('httpauth.inc.php');
+$httpContentType = false;
+require_once '../www-header.php';
+
+if($GLOBALS['enableGoogleCustomSearch'] == false) {
+ echo "Google Custom Search disabled. You can enable it into the config.php file.";
+ die;
+}
+
+/* Service creation: only useful services are created */
+$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
+
+
+/*
+ // 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; charset=utf-8');
+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: text/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..33401e7
--- /dev/null
+++ b/www/api/export_html.php
@@ -0,0 +1,81 @@
+<?php
+/**
+ * Implements the del.icio.us API request for all a user's posts,
+ * optionally filtered by tag.
+ *
+ * Netscape bookmark file format is documented at
+ * http://msdn.microsoft.com/en-us/library/aa753582(VS.85).aspx
+ *
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+// del.icio.us behavior:
+// - doesn't include the filtered tag as an attribute on the root element (we do)
+
+//this page here is really not valid in any way
+$httpContentType = 'text/html';
+// Force HTTP authentication first!
+require_once 'httpauth.inc.php';
+
+/* Service creation: only useful services are created */
+$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
+
+// Check to see if a tag was specified.
+if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != '')) {
+ //$_GET vars have + replaced to " " automatically
+ $tag = str_replace(' ', '+', 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>'."\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>';
+?>
diff --git a/www/api/export_sioc.php b/www/api/export_sioc.php
new file mode 100644
index 0000000..45cbf14
--- /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) */
+
+$httpContentType = 'text/xml';
+require_once '../www-header.php';
+
+/* Service creation: only useful services are created */
+$userservice =SemanticScuttle_Service_Factory::get('User');
+$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
+
+?>
+<?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['bDatetime']) ?></dc:created>
+ <dc:description><?php echo filter(strip_tags($bookmark['bDescription'])) ?></dc:description>
+ <dc:date><?php echo $bookmark['bModified'] ?></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..ee5c7f2
--- /dev/null
+++ b/www/api/httpauth.inc.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * Checks if the user is logged on and sends a HTTP basic auth
+ * request to the browser if not. In that case the script ends.
+ * If username and password are available, the user service's
+ * login method is used to log the user in.
+ *
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+require_once '../www-header.php';
+
+/**
+ * Sends HTTP auth headers to the browser
+ */
+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']))
+ && isset($_SERVER['REMOTE_USER'])
+ && 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) {
+ $currentUser = $userservice->getCurrentObjectUser();
+ } else {
+ authenticate();
+ }
+ }
+}
+?>
diff --git a/www/api/opensearch.php b/www/api/opensearch.php
new file mode 100644
index 0000000..9d3eae7
--- /dev/null
+++ b/www/api/opensearch.php
@@ -0,0 +1,16 @@
+<?php
+$httpContentType = 'text/xml';
+require_once '../www-header.php';
+echo '<' . '?xml version="1.0" encoding="utf-8" ?' . ">\n";
+?>
+<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
+ <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 if ($GLOBALS['root'] != null) { echo $GLOBALS['root']; } else { echo $_SERVER['SERVER_PROTOCOL'] .'://'. $_SERVER['HTTP_HOST'] . '/'; } ?>search.php/all/{searchTerms}"/>
+</OpenSearchDescription>
diff --git a/www/api/posts_add.php b/www/api/posts_add.php
new file mode 100644
index 0000000..80d6515
--- /dev/null
+++ b/www/api/posts_add.php
@@ -0,0 +1,146 @@
+<?php
+/**
+ * API for adding a new bookmark.
+ *
+ * The following POST and GET parameters are accepted:
+ * @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)
+ * Must be of format YYYY-MM-DDTHH:II:SSZ
+ * @param integer $status Visibility status (optional):
+ * - 2 or 'private': Bookmark is totally private
+ * - 1 or 'shared': People on the user's watchlist
+ * can see it
+ * - 0 or 'public': Everyone can see the bookmark
+ * @param string $shared "no" or "yes": Switches between private and
+ * public (optional)
+ * @param string $replace "yes" or "no" - replaces a bookmark with the
+ * 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
+ * - "status" is a SemanticScuttle addition to this API method
+ *
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ * @link http://www.delicious.com/help/api
+ */
+
+// Force HTTP authentication
+$httpContentType = 'text/xml';
+require_once 'httpauth.inc.php';
+
+$bs = SemanticScuttle_Service_Factory::get('Bookmark');
+
+// 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;
+}
+
+$replace = isset($_REQUEST['replace']) && ($_REQUEST['replace'] == 'yes');
+
+$status = $GLOBALS['defaults']['privacy'];
+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;
+ }
+ }
+}
+
+if (isset($_REQUEST['shared']) && (trim($_REQUEST['shared']) == 'no')) {
+ $status = 2;
+}
+
+// Error out if there's no address or description
+if (is_null($url)) {
+ header('HTTP/1.0 400 Bad Request');
+ $msg = 'URL missing';
+} else if (is_null($description)) {
+ header('HTTP/1.0 400 Bad Request');
+ $msg = 'Description missing';
+} else {
+ // We're good with info; now insert it!
+ $exists = $bs->bookmarkExists($url, $userservice->getCurrentUserId());
+ if ($exists) {
+ if (!$replace) {
+ header('HTTP/1.0 409 Conflict');
+ $msg = 'bookmark does already exist';
+ } else {
+ //delete it before we re-add it
+ $bookmark = $bs->getBookmarkByAddress($url, false);
+ $bId = $bookmark['bId'];
+ $bs->deleteBookmark($bId);
+
+ $exists = false;
+ }
+ }
+
+ if (!$exists) {
+ $added = $bs->addBookmark(
+ $url, $description, $extended, '', $status, $tags, null, $dt, true
+ );
+ $msg = 'done';
+ }
+}
+
+// Set up the XML file and output the result.
+echo '<?xml version="1.0" standalone="yes" ?' . ">\r\n";
+echo '<result code="' . $msg .'" />';
+?> \ 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..c70d14c
--- /dev/null
+++ b/www/api/posts_all.php
@@ -0,0 +1,50 @@
+<?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)
+
+// Scuttle behavior:
+// - returns privacy status of each bookmark.
+
+// Force HTTP authentication first!
+$httpContentType = 'text/xml';
+require_once 'httpauth.inc.php';
+
+/* Service creation: only useful services are created */
+$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
+
+
+// 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.
+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'])) . '" status="'. filter($row['bStatus'], 'xml') ."\" />\r\n";
+}
+
+echo '</posts>';
+?>
diff --git a/www/api/posts_dates.php b/www/api/posts_dates.php
new file mode 100644
index 0000000..508c46a
--- /dev/null
+++ b/www/api/posts_dates.php
@@ -0,0 +1,60 @@
+<?php
+/**
+ * Implements the del.icio.us API request for a user's post counts by date
+ * (and optionally by tag).
+ *
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+// Force HTTP authentication first!
+$httpContentType = 'text/xml';
+require_once 'httpauth.inc.php';
+
+/* Service creation: only useful services are created */
+$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
+
+
+// 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.
+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;
+$count = 0;
+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;
+ }
+ $lastdate = $thisdate;
+}
+if ($lastdate !== null) {
+ echo "\t<date count=\"". $count .'" date="'. $lastdate ."\" />\r\n";
+}
+
+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..69b2429
--- /dev/null
+++ b/www/api/posts_delete.php
@@ -0,0 +1,57 @@
+<?php
+/**
+ * API for deleting a bookmark.
+ * The delicious API is implemented here.
+ *
+ * The delicious API behaves like that:
+ * - does NOT allow the hash for the url parameter
+ * - doesn't set the Content-Type to text/xml
+ * - we do it correctly, too
+ *
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ * @link http://www.delicious.com/help/api
+ */
+
+// Force HTTP authentication first!
+$httpContentType = 'text/xml';
+require_once 'httpauth.inc.php';
+
+$bs = SemanticScuttle_Service_Factory::get('Bookmark');
+$uId = $userservice->getCurrentUserId();
+
+
+// Error out if there's no address
+if (!isset($_REQUEST['url'])
+ || $_REQUEST['url'] == ''
+) {
+ $msg = 'something went wrong';
+} else if (!$bs->bookmarkExists($_REQUEST['url'], $uId)) {
+ //the user does not have such a bookmark
+ header('HTTP/1.0 404 Not Found');
+ $msg = 'item not found';
+} else {
+ $bookmark = $bs->getBookmarkByAddress($_REQUEST['url'], false);
+ $bId = $bookmark['bId'];
+ $deleted = $bs->deleteBookmark($bId);
+ $msg = 'done';
+ if (!$deleted) {
+ //something really went wrong
+ header('HTTP/1.0 500 Internal Server Error');
+ $msg = 'something really went wrong';
+ }
+}
+
+// Set up the XML file and output the result.
+echo '<?xml version="1.0" standalone="yes" ?' . ">\r\n";
+echo '<result code="' . $msg . '" />';
+?> \ 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..e39058b
--- /dev/null
+++ b/www/api/posts_get.php
@@ -0,0 +1,83 @@
+<?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
+ * - returns privacy status of each bookmark.
+ *
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+// Force HTTP authentication first!
+$httpContentType = 'text/xml';
+require_once 'httpauth.inc.php';
+
+/* Service creation: only useful services are created */
+$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
+
+
+// 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.
+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'])) . '" status="'. filter($row['bStatus'], 'xml') ."\" />\r\n";
+}
+
+echo '</posts>';
+?>
diff --git a/www/api/posts_public.php b/www/api/posts_public.php
new file mode 100644
index 0000000..e4086b2
--- /dev/null
+++ b/www/api/posts_public.php
@@ -0,0 +1,51 @@
+<?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)
+
+// Scuttle behavior:
+// - returns privacy status of each bookmark.
+
+// Force HTTP authentication first!
+//require_once('httpauth.inc.php');
+$httpContentType = 'text/xml';
+require_once '../www-header.php';
+
+/* Service creation: only useful services are created */
+$bookmarkservice =SemanticScuttle_Service_Factory::get('Bookmark');
+
+
+// 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.
+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'])) . '" status="'. filter($row['bStatus'], 'xml') ."\" />\r\n";
+}
+
+echo '</posts>';
+?>
diff --git a/www/api/posts_recent.php b/www/api/posts_recent.php
new file mode 100644
index 0000000..5fca30d
--- /dev/null
+++ b/www/api/posts_recent.php
@@ -0,0 +1,85 @@
+<?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).
+ *
+ * Scuttle behavior:
+ * - returns privacy status of each bookmark.
+ *
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ */
+
+// Set default and max number of posts
+$countDefault = 15;
+$countMax = 100;
+
+// Force HTTP authentication first!
+$httpContentType = 'text/xml';
+require_once 'httpauth.inc.php';
+
+/* Service creation: only useful services are created */
+$bookmarkservice = SemanticScuttle_Service_Factory::get('Bookmark');
+
+
+// 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;
+ } else if ($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.
+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'])) . '" status="'. filter($row['bStatus'], 'xml') ."\" />\r\n";
+}
+
+echo '</posts>';
+?>
diff --git a/www/api/posts_update.php b/www/api/posts_update.php
new file mode 100644
index 0000000..0e08ee7
--- /dev/null
+++ b/www/api/posts_update.php
@@ -0,0 +1,58 @@
+<?php
+/**
+ * API for retrieving a user's last update time.
+ * That is the time the user changed a bookmark lastly.
+ * The delicious API is implemented here.
+ *
+ * Delicious also returns "the number of new items in
+ * the user's inbox since it was last visited." - we do
+ * that too, so we are as close at the API as possible,
+ * not breaking delicious clients.
+ *
+ * SemanticScuttle supports an extra parameter:
+ * - ?datemode=modified
+ * - sorts by modified date and returns modification time
+ * instead of creation time
+ *
+ * SemanticScuttle - your social bookmark manager.
+ *
+ * PHP version 5.
+ *
+ * @category Bookmarking
+ * @package SemanticScuttle
+ * @author Benjamin Huynh-Kim-Bang <mensonge@users.sourceforge.net>
+ * @author Christian Weiske <cweiske@cweiske.de>
+ * @author Eric Dane <ericdane@users.sourceforge.net>
+ * @license GPL http://www.gnu.org/licenses/gpl.html
+ * @link http://sourceforge.net/projects/semanticscuttle
+ * @link http://www.delicious.com/help/api
+ */
+
+// Force HTTP authentication first!
+$httpContentType = 'text/xml';
+require_once 'httpauth.inc.php';
+
+// parameter "datemode=modified" will get last modified date
+// instead of last created date
+$orderby = null;
+$timeField = 'bDatetime';
+if (isset($_GET['datemode']) && $_GET['datemode'] == 'modified') {
+ $orderby = 'modified_desc';
+ $timeField = 'bModified';
+}
+
+$bs = SemanticScuttle_Service_Factory::get('Bookmark');
+
+$bookmarks = $bs->getBookmarks(0, 1, $userservice->getCurrentUserId(), null, null, $orderby);
+
+// Set up the XML file and output all the tags.
+echo '<?xml version="1.0" standalone="yes" ?' . ">\r\n";
+//foreach is used in case there are no bookmarks
+foreach ($bookmarks['bookmarks'] as $row) {
+ echo '<update time="'
+ . gmdate('Y-m-d\TH:i:s\Z', strtotime($row[$timeField]))
+ . '"'
+ . ' inboxnew="0"'
+ . ' />';
+}
+?>
diff --git a/www/api/tags_get.php b/www/api/tags_get.php
new file mode 100644
index 0000000..c0fb83d
--- /dev/null
+++ b/www/api/tags_get.php
@@ -0,0 +1,25 @@
+<?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!
+$httpContentType = 'text/xml';
+require_once 'httpauth.inc.php';
+
+/* Service creation: only useful services are created */
+$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag');
+
+
+// Get the tags relevant to the passed-in variables.
+$tags = $b2tservice->getTags($userservice->getCurrentUserId());
+
+// Set up the XML file and output all the tags.
+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..cf56c83
--- /dev/null
+++ b/www/api/tags_rename.php
@@ -0,0 +1,36 @@
+<?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!
+$httpContentType = 'text/xml';
+require_once 'httpauth.inc.php';
+
+/* Service creation: only useful services are created */
+$b2tservice =SemanticScuttle_Service_Factory::get('Bookmark2Tag');
+
+// 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.
+echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
+echo '<result>'. ($renamed ? 'done' : 'something went wrong') .'</result>';
+?>