- Enforce minimum elapsed time on registration form
[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 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
12 $userservice     =& ServiceFactory::getServiceInstance('UserService');
13
14 // Check to see if a tag was specified.
15 if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
16     $tag = trim($_REQUEST['tag']);
17 else
18     $tag = NULL;
19
20 // Get the posts relevant to the passed-in variables.
21 $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag);
22
23 $currentuser = $userservice->getCurrentUser();
24 $currentusername = $currentuser[$userservice->getFieldName('username')];
25
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";
30
31 foreach($bookmarks['bookmarks'] as $row) {
32     if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
33         $description = '';
34     else
35         $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
36
37     $taglist = '';
38     if (count($row['tags']) > 0) {
39         foreach($row['tags'] as $tag)
40             $taglist .= convertTag($tag) .' ';
41         $taglist = substr($taglist, 0, -1);
42     } else {
43         $taglist = 'system:unfiled';
44     }
45
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";
47 }
48
49 echo '</posts>';

Benjamin Mako Hill || Want to submit a patch?