2 // Implements the del.icio.us API request for a user's recent posts, optionally filtered by
3 // tag and/or number of posts (default 15, max 100, just like del.icio.us).
5 // Set default and max number of posts
9 // Force HTTP authentication first!
10 require_once('httpauth.inc.php');
11 require_once('../header.inc.php');
13 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
14 $userservice =& ServiceFactory::getServiceInstance('UserService');
16 // Check to see if a tag was specified.
17 if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
18 $tag = trim($_REQUEST['tag']);
22 // Check to see if the number of items was specified.
23 if (isset($_REQUEST['count']) && (intval($_REQUEST['count']) != 0)) {
24 $count = intval($_REQUEST['count']);
25 if ($count > $countMax)
30 $count = $countDefault;
33 // Get the posts relevant to the passed-in variables.
34 $bookmarks =& $bookmarkservice->getBookmarks(0, $count, $userservice->getCurrentUserId(), $tag);
36 $currentuser = $userservice->getCurrentUser();
37 $currentusername = $currentuser[$userservice->getFieldName('username')];
39 // Set up the XML file and output all the tags.
40 header('Content-Type: text/xml');
41 echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
42 echo '<posts tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentusername, 'xml') ."\">\r\n";
44 foreach($bookmarks['bookmarks'] as $row) {
45 if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
48 $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
51 if (count($row['tags']) > 0) {
52 foreach($row['tags'] as $tag)
53 $taglist .= convertTag($tag) .' ';
54 $taglist = substr($taglist, 0, -1);
56 $taglist = 'system:unfiled';
59 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";