Added functionality to keep privacy settings when bookmarks exported via API.
[scuttle] / api / posts_recent.php
1
2 <?php
3 // Implements the del.icio.us API request for a user's recent posts, optionally filtered by
4 // tag and/or number of posts (default 15, max 100, just like del.icio.us).
5
6 // Set default and max number of posts
7 $countDefault = 15;
8 $countMax     = 100;
9
10 // Force HTTP authentication first!
11 require_once 'httpauth.inc.php';
12 require_once '../header.inc.php';
13
14 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
15 $userservice     =& ServiceFactory::getServiceInstance('UserService');
16
17 // Check to see if a tag was specified.
18 if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
19     $tag = trim($_REQUEST['tag']);
20 else
21     $tag = NULL;
22
23 // Check to see if the number of items was specified.
24 if (isset($_REQUEST['count']) && (intval($_REQUEST['count']) != 0))  {
25     $count = intval($_REQUEST['count']);
26     if ($count > $countMax)
27         $count = $countMax;
28     elseif ($count < 0)
29         $count = 0;
30 } else {
31     $count = $countDefault;
32 }
33
34 // Get the posts relevant to the passed-in variables.
35 $bookmarks =& $bookmarkservice->getBookmarks(0, $count, $userservice->getCurrentUserId(), $tag);
36
37 $currentuser = $userservice->getCurrentUser();
38 $currentusername = $currentuser[$userservice->getFieldName('username')];
39
40 // Set up the XML file and output all the tags.
41 header('Content-Type: text/xml');
42 echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
43 echo '<posts tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentusername, 'xml') ."\">\r\n";
44
45 foreach ($bookmarks['bookmarks'] as $row) {
46     if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
47         $description = '';
48     else
49         $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
50
51     $taglist = '';
52     if (count($row['tags']) > 0) {
53         foreach($row['tags'] as $tag)
54             $taglist .= convertTag($tag) .' ';
55         $taglist = substr($taglist, 0, -1);
56     } else {
57         $taglist = 'system:unfiled';
58     }
59     // The privacy setting in scuttle is to set bStatus to 2 in the database.
60     if(trim($row['bStatus']) == '2') {
61         $shared = "no";
62     } else {
63         $shared = "yes";
64     }
65
66     echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" shared="' . $shared . '" 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";
67 }
68
69 echo '</posts>';

Benjamin Mako Hill || Want to submit a patch?