+/**
+ * send a single notice to a given Jabber address
+ *
+ * @param string $to JID to send the notice to
+ * @param Notice $notice notice to send
+ *
+ * @return boolean success value
+ */
+
+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 information for XMPP messages, as defined by Twitter
+ *
+ * @param Profile $profile Profile of the sending user
+ * @param Notice $notice Notice being sent
+ *
+ * @return string Extra information (Atom, HTML, addresses) in string format
+ */
+
+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);
+
+ $self_url = common_local_url('userrss', array('nickname' => $profile->nickname));
+
+ $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='" . $self_url . "'/>\n";
+ $entry .= "<author><name>" . $profile->nickname . "</name></author>\n";
+ $entry .= "<icon>" . $profile->avatarUrl(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";
+ if ($notice->reply_to) {
+ $replyurl = common_local_url('shownotice',
+ array('notice' => $notice->reply_to));
+ $entry .= "<link rel='related' href='" . $replyurl . "'/>\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;
+}
+
+/**
+ * sends a single text message to a given JID
+ *
+ * @param string $to JID to send the message to
+ * @param string $body body of the message
+ * @param string $type type of the message
+ * @param string $subject subject of the message
+ *
+ * @return boolean success flag
+ */
+
+function jabber_send_message($to, $body, $type='chat', $subject=null)
+{
+ $conn = jabber_connect();
+ if (!$conn) {
+ return false;
+ }
+ $conn->message($to, $body, $type, $subject);
+ return true;
+}
+
+/**
+ * sends a presence stanza on the Jabber network
+ *
+ * @param string $status current status, free-form string
+ * @param string $show structured status value
+ * @param string $to recipient of presence, null for general
+ * @param string $type type of status message, related to $show
+ * @param int $priority priority of the presence
+ *
+ * @return boolean success value
+ */
+
+function jabber_send_presence($status, $show='available', $to=null,
+ $type = 'available', $priority=null)
+{
+ $conn = jabber_connect();
+ if (!$conn) {
+ return false;
+ }
+ $conn->presence($status, $show, $to, $type, $priority);
+ return true;