+ }
+ return $conn;
+}
+
+/**
+ * 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)
+{
+ $entry = $notice->asAtomEntry(true, true);
+
+ $xs = new XMLStringer();
+ $xs->elementStart('html', array('xmlns' => 'http://jabber.org/protocol/xhtml-im'));
+ $xs->elementStart('body', array('xmlns' => 'http://www.w3.org/1999/xhtml'));
+ $xs->element('a', array('href' => $profile->profileurl),
+ $profile->nickname);
+ $xs->text(": ");
+ if (!empty($notice->rendered)) {
+ $xs->raw($notice->rendered);
+ } else {
+ $xs->raw(common_render_content($notice->content, $notice));
+ }
+ $xs->elementEnd('body');
+ $xs->elementEnd('html');
+
+ $html = $xs->getString();
+
+ return $html . ' ' . $entry;
+}
+
+/**
+ * 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;