debug_str, 2 = echo() out line by line var $debug_str = ""; var $throttled = false; // set to true if server returns 503, deny any future requests var $incoming_headers = array(); var $request = ""; var $response = ""; var $cookie = false; // constructor function delicious($username,$password) { $this->username = $username; $this->password = $password; } // send http message, return parsed response function send($path) { // throttle check if($this->throttled) { $this->setError(DEL_ERR_THROTTLED); return false; } // check that credentials have been set if(!$this->username || !$this->password) { $this->setError(DEL_ERR_NOCREDENTIALS); return false; } // build http request message $msg = "GET http://".$this->host."$path HTTP/1.0\r\n" .'User-Agent: '.$this->title.'/'.$this->version."\r\n"; // cookie or credentials $msg .= 'Authorization: Basic '.base64_encode($this->username.':'.$this->password)."\r\n"; /* if(!$this->cookie) { $msg .= 'Authorization: Basic '.base64_encode($this->username.':'.$this->password)."\r\n"; } else { $msg .= 'Cookie:'.$this->cookie."\r\n"; } */ // close message $msg .= "\r\n"; $this->request = $msg; //$this->debug('REQUEST:'); //$this->debug('
'.$str.''; } /* function: http://del.icio.us/api/posts/dates? &tag= filter by this tag - optional returns a list of dates with the number of posts at each date. [tag] adds a filter */ function get_post_dates($tag=false) { // build path and query string $queryString = '/api/posts/dates?'; // action if($tag) { $queryString .= '&tag='.urlencode($tag); } // send return $this->send($queryString); } /* function: http://del.icio.us/api/tags/get? returns a list of tags the user has used. */ function get_tags() { // build path and query string $queryString = '/api/tags/get?'; // action // send return $this->send($queryString); } /* function: http://del.icio.us/api/posts/get? &tag= filter by this tag - optional &dt= filter by this date returns a list of posts on a given date, filtered by tag. if no date is supplied, most recent date will be used */ function get_posts($tag=false,$dt=false) { // build path and query string $queryString = '/api/posts/get?'; // action if($tag) { $queryString .= '&tag='.urlencode($tag); } if($dt) { $queryString .= '&dt='.urlencode($dt); } // send return $this->send($queryString); } /* function: http://del.icio.us/api/posts/recent? &tag= filter by this tag - optional &count= number of items to retrieve - optional (defaults to 15) returns a list of most recent posts, possibly filtered by tag. */ function get_recent_posts($tag=false,$count=false) { // build path and query string $queryString = '/api/posts/recent?'; // action if($tag) { $queryString .= '&tag='.urlencode($tag); } if($count) { $queryString .= '&count='.urlencode($count); } // send return $this->send($queryString); } /* function: http://del.icio.us/api/posts/all returns all posts. use sparingly. */ function get_all_posts() { // build path and query string $queryString = '/api/posts/all'; // action // send return $this->send($queryString); } /* function: http://del.icio.us/api/posts/add? &url= url for post &description= description for post &extended= extended for post &tags= space-delimited list of tags &dt= datestamp for post, format "CCYY-MM-DDThh:mm:ssZ" makes a post to delicious */ function add_post($link, $title, $content, $category, $date) { // prep data //$date = date('Y-m-d\TH:i:s\Z', strtotime($date) ); // build path and query string $queryString = '/api/posts/add?' // action .'&url='.$link // link for post .'&description='.urlencode($title) // description for post .'&extended='.urlencode($content) // extended for post .'&tags='.urlencode($category) // space-delimited list of tags .'&dt='.urlencode($date); // datestamp for post, format "CCYY-MM-DDThh:mm:ssZ" // send return $this->send($queryString); } /* function: http://del.icio.us/api/tags/rename? &old= old tag &new= new tag renames tags across all posts */ function rename_tag($old_tag,$new_tag) { // build path and query string $queryString = '/api/tags/rename?' // action .'&old='.urlencode($old_tag) .'&new='.urlencode($new_tag); // send return $this->send($queryString); } /* function: http://del.icio.us/api/inbox/get? &dt= filter by this date returns a list of inbox entries */ function get_inbox($dt) { // build path and query string $queryString = '/api/inbox/get?' // action .'&dt='.urlencode($dt); // send return $this->send($queryString); } /* function: http://del.icio.us/api/inbox/dates? returns a list of dates containing inbox entries */ function get_inbox_dates() { // build path and query string $queryString = '/api/inbox/dates?'; // action // send return $this->send($queryString); } /* function: http://del.icio.us/api/inbox/subs? returns a list of your subscriptions */ function get_subscriptions() { // build path and query string $queryString = '/api/inbox/subs?'; // action // send return $this->send($queryString); } /* function: http://del.icio.us/api/inbox/sub? &user= username &tag = tag - optional, leave blank for all posts adds a subscription */ function subscribe($user,$tag=false) { // build path and query string $queryString = '/api/inbox/sub?' // action .'&user='.urlencode($user); if($tag) { $queryString .= '&tag='.urlencode($tag); } // send return $this->send($queryString); } /* function: http://del.icio.us/api/inbox/unsub? &user= username &tag = tag - optional, leave blank for all posts removes a subscription */ function unsubscribe($user,$tag=false) { // build path and query string $queryString = '/api/inbox/unsub?' // action .'&user='.urlencode($user); if($tag) { $queryString .= '&tag='.urlencode($tag); } // send return $this->send($queryString); } /* function: http://del.icio.us/api/posts/delete?url= deletes a post */ function delete_post($url) { // build path and query string $queryString = '/api/posts/delete' .'?url='.urlencode($url); // send return $this->send($queryString); } } ?>