22fc2bdef04fb60fd6b3a54b48c819cb1f9c8b26
[scuttle] / api / posts_recent.php
1 <?php
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).
4
5 // Set default and max number of posts
6 $countDefault = 15;
7 $countMax = 100;
8
9 // Force HTTP authentication first!
10 require_once('httpauth.inc.php');
11 require_once('../header.inc.php');
12
13 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
14 $userservice =& ServiceFactory::getServiceInstance('UserService');
15
16 // Check to see if a tag was specified.
17 if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
18     $tag = trim($_REQUEST['tag']);
19 else
20     $tag = NULL;
21
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)
26         $count = $countMax;
27     elseif ($count < 0)
28         $count = 0;
29 } else {
30     $count = $countDefault;
31 }
32
33 // Get the posts relevant to the passed-in variables.
34 $bookmarks =& $bookmarkservice->getBookmarks(0, $count, $userservice->getCurrentUserId(), $tag);
35
36 $currentuser = $userservice->getCurrentUser();
37 $currentusername = $currentuser[$userservice->getFieldName('username')];
38
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";
43
44 foreach($bookmarks['bookmarks'] as $row) {
45     if (is_null($row['bDescription']) || (trim($row['bDescription']) == ''))
46         $description = '';
47     else
48         $description = 'extended="'. filter($row['bDescription'], 'xml') .'" ';
49
50     $taglist = '';
51     if (count($row['tags']) > 0) {
52         foreach($row['tags'] as $tag)
53             $taglist .= convertTag($tag) .' ';
54         $taglist = substr($taglist, 0, -1);
55     } else {
56         $taglist = 'system:unfiled';
57     }
58
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";
60 }
61
62 echo '</posts>';
63 ?>

Benjamin Mako Hill || Want to submit a patch?