diff options
author | Evan Prodromou <evan@prodromou.name> | 2008-07-13 23:45:03 -0400 |
---|---|---|
committer | Evan Prodromou <evan@prodromou.name> | 2008-07-13 23:45:03 -0400 |
commit | fb007082841f1a23da5427063e00ceb7c93f3ac2 (patch) | |
tree | a4d99e89b91b7a2a1b366dd01b96abeef5d77a75 | |
parent | 8c42fac88a7fbceeabded35303b4a0ad0d677346 (diff) |
add extra Twitter cruft to jabber messages
darcs-hash:20080714034503-84dde-c06198f9d7b8b1c11f6c57e518dcf49b863ee6f3.gz
-rw-r--r-- | lib/jabber.php | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/lib/jabber.php b/lib/jabber.php index a36e19044..d8cc38dd5 100644 --- a/lib/jabber.php +++ b/lib/jabber.php @@ -67,6 +67,53 @@ function jabber_connect($resource=NULL) { return $conn; } +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', $entry); + return true; +} + +# Extra stuff defined by Twitter, needed by twitter clients + +function jabber_format_entry($profile, $notice) { + $noticeurl = common_local_url('shownotice', + array('notice' => $notice->id)); + $entry = "<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='" . $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_STREAM_SIZE) . "</icon>\n"; + $entry .= "</source>\n"; + $entry .= "<title>" . $msg . "</title>\n"; + $entry .= "<summary>" . $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"; + $entry .= "<event xmlns='http://jabber.org/protocol/pubsub#event'>\n"; + $entry .= "<items xmlns='http://jabber.org/protocol/pubsub' "; + $entry .= "node='" . common_local_url('public') . "'>\n"; + $entry .= "<item id='" . $notice->uri ."' />\n"; + $entry .= "</items>\n"; + $entry .= "</event>\n"; + return $entry; +} + function jabber_send_message($to, $body, $type='chat', $subject=NULL) { $conn = jabber_connect(); if (!$conn) { |