Restructure repository
[scuttle] / api / posts_dates.php
1 <?php
2 // Implements the del.icio.us API request for a user's post counts by date (and optionally
3 // by tag).
4
5 // Force HTTP authentication first!
6 require_once('httpauth.inc.php');
7 require_once('../header.inc.php');
8
9 $bookmarkservice =& ServiceFactory::getServiceInstance('BookmarkService');
10 $userservice =& ServiceFactory::getServiceInstance('UserService');
11
12 // Check to see if a tag was specified.
13 if (isset($_REQUEST['tag']) && (trim($_REQUEST['tag']) != ''))
14     $tag = trim($_REQUEST['tag']);
15 else
16     $tag = NULL;
17
18 // Get the posts relevant to the passed-in variables.
19 $bookmarks =& $bookmarkservice->getBookmarks(0, NULL, $userservice->getCurrentUserId(), $tag);
20
21 $currentuser = $userservice->getCurrentUser();
22 $currentusername = $currentuser[$userservice->getFieldName('username')];
23
24 //      Set up the XML file and output all the tags.
25 header('Content-Type: text/xml');
26 echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
27 echo '<dates tag="'. (is_null($tag) ? '' : filter($tag, 'xml')) .'" user="'. filter($currentusername, 'xml') ."\">\r\n";
28
29 $lastdate = NULL;
30 foreach($bookmarks['bookmarks'] as $row) {
31     $thisdate = gmdate('Y-m-d', strtotime($row['bDatetime']));
32     if ($thisdate != $lastdate && $lastdate != NULL) {
33         echo "\t<date count=\"". $count .'" date="'. $lastdate ."\" />\r\n";
34         $count = 1;
35     } else {
36         $count = $count + 1;
37     }
38     $lastdate = $thisdate;
39 }
40
41 echo "</dates>";
42 ?>

Benjamin Mako Hill || Want to submit a patch?