Added functionality to keep privacy settings when bookmarks exported via API.
[scuttle] / api / posts_all.php
1 <?php
2 // Implements the del.icio.us API request for all a user's posts, optionally filtered by tag.
3
4 // del.icio.us behavior:
5 // - doesn't include the filtered tag as an attribute on the root element (we do)
6
7 // Force HTTP authentication first!
8 require_once 'httpauth.inc.php';
9 require_once '../header.inc.php';
10
11 // set user as logged in so private bookmarks are exported
12 $loggedon = true;
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 // Get the posts relevant to the passed-in variables.
24 $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag);
25
26 $currentuser = $userservice->getCurrentUser();
27 $currentusername = $currentuser[$userservice->getFieldName('username')];
28
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";
33
34 foreach($bookmarks['bookmarks'] as $row) {
35     if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
36         $description = '';
37     else
38         $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
39
40     $taglist = '';
41     if (count($row['tags']) > 0) {
42         foreach($row['tags'] as $tag)
43             $taglist .= convertTag($tag) .' ';
44         $taglist = substr($taglist, 0, -1);
45     } else {
46         $taglist = 'system:unfiled';
47     }
48     // The privacy setting in scuttle is to set bStatus to 2 in the database.
49     if(trim($row['bStatus']) == '2') {
50         $shared = "no";
51     } else {
52         $shared = "yes";
53     }
54
55     echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" shared="' . $shared . '" 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";
56 }
57
58 echo '</posts>';

Benjamin Mako Hill || Want to submit a patch?