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 = array();
$twitter_status['text'] = $notice->content;
$twitter_status['truncated'] = 'false'; # Not possible on Laconica
$twitter_status['created_at'] = $this->date_twitter($notice->created);
$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 ($get_user) {
- $profile = $notice->getProfile();
+ 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 ($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'];
function show_twitter_xml_status($twitter_status) {
common_element_start('status');
foreach($twitter_status as $element => $value) {
- if ($element == 'user') {
+ switch ($element) {
+ case 'user':
$this->show_twitter_xml_user($twitter_status['user']);
- } else {
+ break;
+ case 'text':
+ common_element($element, NULL, common_xml_safe_str($value));
+ break;
+ default:
common_element($element, NULL, $value);
}
}
function show_twitter_xml_dmsg($twitter_dm) {
common_element_start('direct_message');
foreach($twitter_dm as $element => $value) {
- if ($element == 'sender' || $element == 'recipient') {
+ switch ($element) {
+ case 'sender':
+ case 'recipient':
$this->show_twitter_xml_user($value, $element);
- } else {
+ break;
+ case 'text':
+ common_element($element, NULL, common_xml_safe_str($value));
+ break;
+ default:
common_element($element, NULL, $value);
}
}
$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)) {
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);
}
}