+function jabber_send_notice($to, $notice) {
+ $conn = jabber_connect();
+ if (!$conn) {
+ return false;
+ }
+ $profile = Profile::staticGet($notice->profile_id);
+ if (!$profile) {
+ common_log(LOG_WARNING, 'Refusing to send notice with ' .
+ 'unknown profile ' . common_log_objstring($notice),
+ __FILE__);
+ return false;
+ }
+ $msg = jabber_format_notice($profile, $notice);
+ $entry = jabber_format_entry($profile, $notice);
+ $conn->message($to, $msg, 'chat', NULL, $entry);
+ $profile->free();
+ return true;
+}
+
+# Extra stuff defined by Twitter, needed by twitter clients
+
+function jabber_format_entry($profile, $notice) {
+
+ # FIXME: notice url might be remote
+
+ $noticeurl = common_local_url('shownotice',
+ array('notice' => $notice->id));
+ $msg = jabber_format_notice($profile, $notice);
+ $entry = "\n<entry xmlns='http://www.w3.org/2005/Atom'>\n";
+ $entry .= "<source>\n";
+ $entry .= "<title>" . $profile->nickname . " - " . common_config('site', 'name') . "</title>\n";
+ $entry .= "<link href='" . htmlspecialchars($profile->profileurl) . "'/>\n";
+ $entry .= "<link rel='self' type='application/rss+xml' href='" . common_local_url('userrss', array('nickname' => $profile->nickname)) . "'/>\n";
+ $entry .= "<author><name>" . $profile->nickname . "</name></author>\n";
+ $entry .= "<icon>" . common_profile_avatar_url($profile, AVATAR_PROFILE_SIZE) . "</icon>\n";
+ $entry .= "</source>\n";
+ $entry .= "<title>" . htmlspecialchars($msg) . "</title>\n";
+ $entry .= "<summary>" . htmlspecialchars($msg) . "</summary>\n";
+ $entry .= "<link rel='alternate' href='" . $noticeurl . "' />\n";
+ $entry .= "<id>". $notice->uri . "</id>\n";
+ $entry .= "<published>".common_date_w3dtf($notice->created)."</published>\n";
+ $entry .= "<updated>".common_date_w3dtf($notice->modified)."</updated>\n";
+ $entry .= "</entry>\n";
+
+ $html = "\n<html xmlns='http://jabber.org/protocol/xhtml-im'>\n";
+ $html .= "<body xmlns='http://www.w3.org/1999/xhtml'>\n";
+ $html .= "<a href='".htmlspecialchars($profile->profileurl)."'>".$profile->nickname."</a>: ";
+ $html .= ($notice->rendered) ? $notice->rendered : common_render_content($notice->content, $notice);
+ $html .= "\n</body>\n";
+ $html .= "\n</html>\n";
+
+ $address = "<addresses xmlns='http://jabber.org/protocol/address'>\n";
+ $address .= "<address type='replyto' jid='" . jabber_daemon_address() . "' />\n";
+ $address .= "</addresses>\n";
+
+ # FIXME: include a pubsub event, too.
+
+ return $html . $entry . $address;
+}
+