- Enforce minimum elapsed time on registration form
[scuttle] / api / posts_get.php
1 <?php
2 // Implements the del.icio.us API request for a user's posts, optionally filtered by tag and/or
3 // date.  Note that when using a date to select the posts returned, del.icio.us uses GMT dates --
4 // so we do too.
5
6 // del.icio.us behavior:
7 // - includes an empty tag attribute on the root element when it hasn't been specified
8
9 // Scuttle behavior:
10 // - Uses today, instead of the last bookmarked date, if no date is specified
11
12 // Force HTTP authentication first!
13 require_once 'httpauth.inc.php';
14 require_once '../header.inc.php';
15
16 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
17 $userservice     =& ServiceFactory::getServiceInstance('UserService');
18
19 // Check to see if a tag was specified.
20 if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
21     $tag = trim($_REQUEST['tag']);
22 else
23     $tag = NULL;
24
25 // Check to see if a date was specified; the format should be YYYY-MM-DD
26 if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != ""))
27     $dtstart = trim($_REQUEST['dt']);
28 else
29     $dtstart = date('Y-m-d H:i:s');
30 $dtend = date('Y-m-d H:i:s', strtotime($dtstart .'+1 day'));
31
32 // Get the posts relevant to the passed-in variables.
33 $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag, NULL, NULL, NULL, $dtstart, $dtend);
34
35 $currentuser = $userservice->getCurrentUser();
36 $currentusername = $currentuser[$userservice->getFieldName('username')];
37
38 // Set up the XML file and output all the tags.
39 header('Content-Type: text/xml');
40 echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
41 echo '<posts'. (is_null($dtstart) ? '' : ' dt="'. $dtstart .'"') .' tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentusername, 'xml') ."\">\r\n";
42
43 foreach ($bookmarks['bookmarks'] as $row) {
44     if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
45         $description = '';
46     else
47         $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
48
49     $taglist = '';
50     if (count($row['tags']) > 0) {
51         foreach($row['tags'] as $tag)
52             $taglist .= convertTag($tag) .' ';
53         $taglist = substr($taglist, 0, -1);
54     } else {
55         $taglist = 'system:unfiled';
56     }
57
58     echo "\t<post href=\"". filter($row['bAddress'], 'xml') .'" description="'. filter($row['bTitle'], 'xml') .'" '. $description .'hash="'. $row['bHash'] .'" others="'. $bookmarkservice->countOthers($row['bAddress']) .'" tag="'. filter($taglist, 'xml') .'" time="'. gmdate('Y-m-d\TH:i:s\Z', strtotime($row['bDatetime'])) ."\" />\r\n";
59 }
60
61 echo '</posts>';

Benjamin Mako Hill || Want to submit a patch?