2 // Implements the del.icio.us API request for all a user's posts, optionally filtered by tag.
4 // del.icio.us behavior:
5 // - doesn't include the filtered tag as an attribute on the root element (we do)
7 // Force HTTP authentication first!
8 require_once('httpauth.inc.php');
9 require_once('../header.inc.php');
11 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
12 $userservice =& ServiceFactory::getServiceInstance('UserService');
14 // Check to see if a tag was specified.
15 if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
16 $tag = trim($_REQUEST['tag']);
20 // Get the posts relevant to the passed-in variables.
21 $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag);
23 $currentuser = $userservice->getCurrentUser();
24 $currentusername = $currentuser[$userservice->getFieldName('username')];
26 // Set up the XML file and output all the posts.
27 header('Content-Type: text/xml');
28 echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
29 echo '<posts update="'. gmdate('Y-m-d\TH:i:s\Z') .'" user="'. htmlspecialchars($currentusername) .'"'. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') .">\r\n";
31 foreach($bookmarks['bookmarks'] as $row) {
32 if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
35 $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
38 if (count($row['tags']) > 0) {
39 foreach($row['tags'] as $tag)
40 $taglist .= convertTag($tag) .' ';
41 $taglist = substr($taglist, 0, -1);
43 $taglist = 'system:unfiled';
46 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";