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 // set user as logged in so private bookmarks are exported
14 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
15 $userservice =& ServiceFactory::getServiceInstance('UserService');
17 // Check to see if a tag was specified.
18 if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
19 $tag = trim($_REQUEST['tag']);
23 // Get the posts relevant to the passed-in variables.
24 $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag);
26 $currentuser = $userservice->getCurrentUser();
27 $currentusername = $currentuser[$userservice->getFieldName('username')];
29 // Set up the XML file and output all the posts.
30 header('Content-Type: text/xml');
31 echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
32 echo '<posts update="'. gmdate('Y-m-d\TH:i:s\Z') .'" user="'. htmlspecialchars($currentusername) .'"'. (is_null($tag) ? '' : ' tag="'. htmlspecialchars($tag) .'"') .">\r\n";
34 foreach($bookmarks['bookmarks'] as $row) {
35 if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
38 $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
41 if (count($row['tags']) > 0) {
42 foreach($row['tags'] as $tag)
43 $taglist .= convertTag($tag) .' ';
44 $taglist = substr($taglist, 0, -1);
46 $taglist = 'system:unfiled';
49 echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" description="'. filter($row['bTitle'], 'xml') .'" '. $description .'hash="'. md5($row['bAddress']) . ($row['bStatus'] ? '" shared="no' : '') .'" tag="'. filter($taglist, 'xml') .'" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />\r\n";