X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Ftwitterapi.php;h=378716eaadec2ba53dae9235e76b6dc86f16c4fc;hb=b3ed4e5e20523673d4005415e8d9f26bf0748659;hp=06b41fd0cc89daf39b7616ceaa421afcc5bc5398;hpb=fd576d73d095d2f1b65e09ff8a7fed5fc6e8f436;p=quix0rs-gnu-social.git diff --git a/lib/twitterapi.php b/lib/twitterapi.php index 06b41fd0cc..378716eaad 100644 --- a/lib/twitterapi.php +++ b/lib/twitterapi.php @@ -21,6 +21,8 @@ if (!defined('LACONICA')) { exit(1); } class TwitterapiAction extends Action { + var $auth_user; + function handle($args) { parent::handle($args); } @@ -53,23 +55,30 @@ class TwitterapiAction extends Action { 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; } @@ -82,8 +91,8 @@ class TwitterapiAction extends Action { $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); @@ -106,14 +115,14 @@ class TwitterapiAction extends Action { $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']; @@ -128,8 +137,8 @@ class TwitterapiAction extends Action { $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; @@ -250,13 +259,20 @@ class TwitterapiAction extends Action { $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'); @@ -278,13 +294,19 @@ class TwitterapiAction extends Action { $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)) { @@ -364,7 +386,7 @@ class TwitterapiAction extends Action { } } - function init_document($type='xml') { + function init_document($type='xml') { switch ($type) { case 'xml': header('Content-Type: application/xml; charset=utf-8'); @@ -505,11 +527,14 @@ class TwitterapiAction extends Action { 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); } } @@ -544,5 +569,5 @@ class TwitterapiAction extends Action { } return $source_name; } - + } \ No newline at end of file