$message->find();
+ $title = 'Direct messages to ' . $user->nickname;
+ $subtitle = 'All the direct messages sent to ' . $user->nickname;
+
+ $server = common_root_url();
+ $link = $server . $user->nickname . '/inbox';
+
switch($apidata['content-type']) {
case 'xml':
- $this->show_xml_direct_messages($message);
+ $this->show_xml_dmsgs($message);
break;
case 'rss':
- //$this->show_rss_timeline($notice, $title, $id, $link, $subtitle);
+ $this->show_rss_dmsgs($message, $title, $link, $subtitle);
break;
case 'atom':
- //$this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
+ $this->show_atom_dmsgs($message, $title, $link, $subtitle);
break;
case 'json':
- $this->show_json_direct_messages($message);
+ $this->show_json_dmsgs($message);
break;
default:
common_user_error(_('API method not found!'), $code = 404);
exit();
}
- function show_xml_direct_messages($message) {
+ function show_xml_dmsgs($message) {
$this->init_document('xml');
common_element_start('direct-messages', array('type' => 'array'));
$this->end_document('xml');
}
- function show_json_direct_messages($message) {
+ function show_json_dmsgs($message) {
$this->init_document('json');
$this->end_document('json');
}
+ function show_rss_dmsgs($message, $title, $link, $subtitle) {
+
+ $this->init_document('rss');
+
+ common_element_start('channel');
+ common_element('title', NULL, $title);
+
+ common_element('link', NULL, $link);
+ common_element('description', NULL, $subtitle);
+ common_element('language', NULL, 'en-us');
+ common_element('ttl', NULL, '40');
+
+ if (is_array($message)) {
+ foreach ($message as $m) {
+ $entry = $this->twitter_rss_dmsg_array($m);
+ $this->show_twitter_rss_item($entry);
+ }
+ } else {
+ while ($message->fetch()) {
+ $entry = $this->twitter_rss_dmsg_array($message);
+ $this->show_twitter_rss_item($entry);
+ }
+ }
+
+ common_element_end('channel');
+ $this->end_twitter_rss();
+ }
+
+ function show_atom_dmsgs($message, $title, $link, $subtitle) {
+
+ $this->init_document('atom');
+
+ common_element('title', NULL, $title);
+ $siteserver = common_config('site', 'server');
+ common_element('id', NULL, "tag:$siteserver,2008:DirectMessage");
+ common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL);
+ common_element('updated', NULL, common_date_iso8601(strftime('%c')));
+ common_element('subtitle', NULL, $subtitle);
+
+ if (is_array($message)) {
+ foreach ($message as $m) {
+ $entry = $this->twitter_rss_dmsg_array($m);
+ $this->show_twitter_atom_entry($entry);
+ }
+ } else {
+ while ($message->fetch()) {
+ $entry = $this->twitter_rss_dmsg_array($message);
+ $this->show_twitter_atom_entry($entry);
+ }
+ }
+
+ $this->end_document('atom');
+ }
}
\ No newline at end of file
$this->show_xml_timeline($notice);
break;
case 'rss':
- $this->show_rss_timeline($notice, $title, $id, $link, $subtitle);
+ $this->show_rss_timeline($notice, $title, $link, $subtitle);
break;
case 'atom':
$this->show_atom_timeline($notice, $title, $id, $link, $subtitle);
$this->end_document('xml');
}
- function show_rss_timeline($notice, $title, $id, $link, $subtitle) {
+ function show_rss_timeline($notice, $title, $link, $subtitle) {
$this->init_document('rss');
$reply_to = NULL;
if ($in_reply_to_status_id) {
-
+
// check whether notice actually exists
$reply = Notice::staticGet($in_reply_to_status_id);
-
+
if ($reply) {
$reply_to = $in_reply_to_status_id;
} else {
exit();
}
}
-
+
$notice = Notice::saveNew($user->id, $status, $source, 1, $reply_to);
if (is_string($notice)) {
function show($args, $apidata) {
parent::handle($args);
-
- $notice_id = $apidata['api_arg'];
+
+ $notice_id = $apidata['api_arg'];
$notice = Notice::staticGet($notice_id);
if ($notice) {
- if ($apidata['content-type'] == 'xml') {
+ if ($apidata['content-type'] == 'xml') {
$this->show_single_xml_status($notice);
} elseif ($apidata['content-type'] == 'json') {
$this->show_single_json_status($notice);
// XXX: Twitter just sets a 404 header and doens't bother to return an err msg
$this->client_error(_('No status with that ID found.'), 404, $apidata['content-type']);
}
-
+
exit();
}
*/
function destroy($args, $apidata) {
-
+
parent::handle($args);
common_debug($_SERVER['REQUEST_METHOD']);
-
- // Check for RESTfulness
+
+ // Check for RESTfulness
if (!in_array($_SERVER['REQUEST_METHOD'], array('POST', 'DELETE'))) {
// XXX: Twitter just prints the err msg, no XML / JSON.
$this->client_error(_('This method requires a POST or DELETE.'), 400, $apidata['content-type']);
exit();
- }
-
- $user = $apidata['user'];
- $notice_id = $apidata['api_arg'];
+ }
+
+ $user = $apidata['user'];
+ $notice_id = $apidata['api_arg'];
$notice = Notice::staticGet($notice_id);
-
+
if (!$notice) {
$this->client_error(_('No status found with that ID.'), 404, $apidata['content-type']);
exit();
}
-
+
if ($user->id == $notice->profile_id) {
$replies = new Reply;
$replies->get('notice_id', $notice_id);
common_dequeue_notice($notice);
$replies->delete();
$notice->delete();
-
- if ($apidata['content-type'] == 'xml') {
+
+ if ($apidata['content-type'] == 'xml') {
$this->show_single_xml_status($notice);
} elseif ($apidata['content-type'] == 'json') {
$this->show_single_json_status($notice);
- }
+ }
} else {
$this->client_error(_('You may not delete another user\'s status.'), 403, $apidata['content-type']);
}
-
+
exit();
}
$entry['content'] = $profile->nickname . ': ' . $notice->content;
$entry['title'] = $entry['content'];
- $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));;
+ $entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));
$entry['published'] = common_date_iso8601($notice->created);
- $entry['id'] = "tag:$server,$entry[published]:$entry[link]";
+ $entry['id'] = "tag:$server,2008:$entry[link]";
$entry['updated'] = $entry['published'];
# RSS Item specific
return $entry;
}
+ function twitter_rss_dmsg_array($message) {
+
+ $server = common_config('site', 'server');
+ $entry = array();
+
+ $entry['title'] = sprintf('Message from %s to %s',
+ $message->getFrom()->nickname, $message->getTo()->nickname);
+
+ $entry['content'] = $message->content;
+ $entry['link'] = $message->uri;
+ $entry['published'] = common_date_iso8601($message->created);
+ $entry['id'] = "tag:$server,2008:$entry[link]";
+ $entry['updated'] = $entry['published'];
+
+ # RSS Item specific
+ $entry['description'] = $message->content;
+ $entry['pubDate'] = common_date_rfc2822($message->created);
+ $entry['guid'] = $entry['link'];
+
+ return $entry;
+ }
+
+
function twitter_dm_array($message) {
$twitter_dm = array();