- Enforce minimum elapsed time on registration form
[scuttle] / api / posts_add.php
1 <?php
2 // Implements the del.icio.us API request to add a new post.
3
4 // del.icio.us behavior:
5 // - tags can't have spaces
6 // - address and description are mandatory
7
8 // Scuttle behavior:
9 // - Additional 'status' variable for privacy
10 // - No support for 'replace' variable
11
12 // Force HTTP authentication
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 // Get all the bookmark's passed-in information
20 if (isset($_REQUEST['url']) && (trim($_REQUEST['url']) != ''))
21     $url = trim(urldecode($_REQUEST['url']));
22 else
23     $url = NULL;
24
25 if (isset($_REQUEST['description']) && (trim($_REQUEST['description']) != ''))
26     $description = trim($_REQUEST['description']);
27 else
28     $description = NULL;
29
30 if (isset($_REQUEST['extended']) && (trim($_REQUEST['extended']) != ""))
31     $extended = trim($_REQUEST['extended']);
32 else
33     $extended = NULL;
34
35 if (isset($_REQUEST['tags']) && (trim($_REQUEST['tags']) != '') && (trim($_REQUEST['tags']) != ','))
36     $tags = trim($_REQUEST['tags']);
37 else
38     $tags = NULL;
39
40 if (isset($_REQUEST['dt']) && (trim($_REQUEST['dt']) != ''))
41     $dt = trim($_REQUEST['dt']);
42 else
43     $dt = NULL;
44
45 $status = 0;
46 if (isset($_REQUEST['status'])) {
47     $status_str = trim($_REQUEST['status']);
48     if (is_numeric($status_str)) {
49         $status = intval($status_str);
50         if($status < 0 || $status > 2) {
51             $status = 0;
52         }
53     } else {
54         switch ($status_str) {
55             case 'private':
56                 $status = 2;
57                 break;
58             case 'shared':
59                 $status = 1;
60                 break;
61             default:
62                 $status = 0;
63                 break;
64         }
65     }
66 }
67
68 // Error out if there's no address or description
69 if (is_null($url) || is_null($description)) {
70     $added = FALSE;
71 } else {
72 // We're good with info; now insert it!
73     if ($bookmarkservice->bookmarkExists($url, $userservice->getCurrentUserId()))
74         $added = FALSE;
75     else
76         $added = $bookmarkservice->addBookmark($url, $description, $extended, $status, $tags, $dt, TRUE);
77 }
78
79 // Set up the XML file and output the result.
80 header('Content-Type: text/xml');
81 echo '<?xml version="1.0" standalone="yes" ?'.">\r\n";
82 echo '<result code="'. ($added ? 'done' : 'something went wrong') .'" />';

Benjamin Mako Hill || Want to submit a patch?