class TwitterapiAction extends Action {
+ var $auth_user;
+
function handle($args) {
parent::handle($args);
}
return $twitter_user;
}
- function twitter_status_array($notice, $get_user=true) {
+ function twitter_status_array($notice, $include_user=true) {
- $twitter_status = array();
+ $profile = $notice->getProfile();
- $twitter_status['text'] = $notice->content;
+ $twitter_status = array();
+ $twitter_status['text'] = common_xml_safe_str($notice->content);
$twitter_status['truncated'] = 'false'; # Not possible on Laconica
$twitter_status['created_at'] = $this->date_twitter($notice->created);
$twitter_status['in_reply_to_status_id'] = ($notice->reply_to) ? intval($notice->reply_to) : NULL;
$twitter_status['source'] = $this->source_link($notice->source);
$twitter_status['id'] = intval($notice->id);
$twitter_status['in_reply_to_user_id'] = ($notice->reply_to) ? $this->replier_by_reply(intval($notice->reply_to)) : NULL;
- $twitter_status['favorited'] = NULL; # XXX: Not implemented on Laconica yet.
+
+ if (isset($this->auth_user)) {
+ common_debug("auth user set: " . $this->auth_user->nickname);
+ $twitter_status['favorited'] = ($this->auth_user->hasFave($notice)) ? 'true' : 'false';
+ } else {
+ common_debug("no auth user set");
+ $twitter_status['favorited'] = 'false';
+ }
- if ($get_user) {
- $profile = $notice->getProfile();
+ if ($include_user) {
# Don't get notice (recursive!)
- $twitter_user = $this->twitter_user_array($profile, false);
+ $twitter_user = $this->twitter_user_array($profile, false, $user);
$twitter_status['user'] = $twitter_user;
}
$server = common_config('site', 'server');
$entry = array();
-
- $entry['content'] = $profile->nickname . ': ' . $notice->content;
+
+ $entry['content'] = $profile->nickname . ': ' . common_xml_safe_str($notice->content);
$entry['title'] = $entry['content'];
$entry['link'] = common_local_url('shownotice', array('notice' => $notice->id));
$entry['published'] = common_date_iso8601($notice->created);
$entry['title'] = sprintf('Message from %s to %s',
$message->getFrom()->nickname, $message->getTo()->nickname);
- $entry['content'] = $message->content;
+ $entry['content'] = common_xml_safe_str($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['description'] = $entry['content'];
$entry['pubDate'] = common_date_rfc2822($message->created);
$entry['guid'] = $entry['link'];
$to_profile = $message->getTo();
$twitter_dm['id'] = $message->id;
- $twitter_dm['sender_id'] = $message->from_profile;
- $twitter_dm['text'] = $message->content;
+ $twitter_dm['sender_id'] = $message->from_profile;
+ $twitter_dm['text'] = common_xml_safe_str($message->content);
$twitter_dm['recipient_id'] = $message->to_profile;
$twitter_dm['created_at'] = $this->date_twitter($message->created);
$twitter_dm['sender_screen_name'] = $from_profile->nickname;
$this->end_document('xml');
}
- function show_rss_timeline($notice, $title, $link, $subtitle) {
+ function show_rss_timeline($notice, $title, $link, $subtitle, $suplink=NULL) {
$this->init_document('rss');
common_element_start('channel');
common_element('title', NULL, $title);
common_element('link', NULL, $link);
+ if (!is_null($suplink)) {
+ # For FriendFeed's SUP protocol
+ common_element('link', array('xmlns' => 'http://www.w3.org/2005/Atom',
+ 'rel' => 'http://api.friendfeed.com/2008/03#sup',
+ 'href' => $suplink,
+ 'type' => 'application/json'));
+ }
common_element('description', NULL, $subtitle);
common_element('language', NULL, 'en-us');
common_element('ttl', NULL, '40');
$this->end_twitter_rss();
}
- function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL) {
+ function show_atom_timeline($notice, $title, $id, $link, $subtitle=NULL, $suplink=NULL) {
$this->init_document('atom');
common_element('title', NULL, $title);
common_element('id', NULL, $id);
common_element('link', array('href' => $link, 'rel' => 'alternate', 'type' => 'text/html'), NULL);
+ if (!is_null($suplink)) {
+ # For FriendFeed's SUP protocol
+ common_element('link', array('rel' => 'http://api.friendfeed.com/2008/03#sup',
+ 'href' => $suplink,
+ 'type' => 'application/json'));
+ }
common_element('subtitle', NULL, $subtitle);
if (is_array($notice)) {
}
}
- function init_document($type='xml') {
+ function init_document($type='xml') {
switch ($type) {
case 'xml':
header('Content-Type: application/xml; charset=utf-8');
return;
}
- function get_user($id) {
- if (is_numeric($id)) {
+ function get_user($id, $apidata=NULL) {
+ if (!$id) {
+ return $apidata['user'];
+ } else if (is_numeric($id)) {
return User::staticGet($id);
} else {
- return User::staticGet('nickname', $id);
+ $nickname = common_canonical_nickname($id);
+ return User::staticGet('nickname', $nickname);
}
}
}
return $source_name;
}
-
+
}
\ No newline at end of file