summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-03-05 14:34:53 -0800
committerEvan Prodromou <evan@controlyourself.ca>2009-03-05 14:34:53 -0800
commiteaac9350dd0ff02dda975f48e0be0c6ad1e7a56d (patch)
treef838d5a0e80ae5ee534b3daba7ab1b47abfdd5d3 /lib
parent6ce7d0c567b23d3bec035a9c4428399bdfdb896b (diff)
parent32f81b3c0e7be3da35d5813e5409fa3b65dc220e (diff)
Merge branch 'ping' of /var/www/mublog.corrupt into corrupt/ping
Conflicts: lib/util.php
Diffstat (limited to 'lib')
-rw-r--r--lib/common.php2
-rw-r--r--lib/ping.php79
-rw-r--r--lib/util.php2
3 files changed, 82 insertions, 1 deletions
diff --git a/lib/common.php b/lib/common.php
index f215192f4..0355d01e3 100644
--- a/lib/common.php
+++ b/lib/common.php
@@ -144,6 +144,8 @@ $config =
array('enabled' => false,
'server' => 'localhost',
'port' => 11211),
+ 'ping' =>
+ array('notify' => array()),
'inboxes' =>
array('enabled' => true), # on by default for new sites
);
diff --git a/lib/ping.php b/lib/ping.php
new file mode 100644
index 000000000..32c0b9806
--- /dev/null
+++ b/lib/ping.php
@@ -0,0 +1,79 @@
+<?php
+/*
+ * Laconica - a distributed open-source microblogging tool
+ * Copyright (C) 2008, Controlez-Vous, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+if (!defined('LACONICA')) { exit(1); }
+
+function ping_broadcast_notice($notice) {
+ if (!$notice->is_local) {
+ return;
+ }
+
+ # Array of servers, URL => type
+ $notify = common_config('ping', 'notify');
+ $profile = $notice->getProfile();
+ $tags = ping_notice_tags($notice);
+
+ foreach ($notify as $notify_url => $type) {
+ switch ($type) {
+ case 'xmlrpc':
+ case 'extended':
+ $req = xmlrpc_encode_request('weblogUpdates.ping',
+ array($profile->nickname, # site name
+ common_local_url('showstream',
+ array('nickname' => $profile->nickname)),
+ common_local_url('shownotice',
+ array('notice' => $notice->id)),
+ common_local_url('userrss',
+ array('nickname' => $profile->nickname)),
+ $tags));
+
+ # We re-use this tool's fetcher, since it's pretty good
+
+ $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
+
+ if (!$fetcher) {
+ common_log(LOG_WARNING, 'Failed to initialize Yadis fetcher.', __FILE__);
+ return false;
+ }
+
+ $result = $fetcher->post($notify_url,
+ $req);
+
+ case 'get':
+ case 'post':
+ default:
+ common_log(LOG_WARNING, 'Unknown notify type for ' . $notify_url . ': ' . $type);
+ }
+ }
+}
+
+function ping_notice_tags($notice) {
+ $tag = new Notice_tag();
+ $tag->notice_id = $notice->id;
+ $tags = array();
+ if ($tag->find()) {
+ while ($tag->fetch()) {
+ $tags[] = $tag->tag;
+ }
+ $tag->free();
+ unset($tag);
+ return implode('|', $tags);
+ }
+ return NULL;
+} \ No newline at end of file
diff --git a/lib/util.php b/lib/util.php
index 167508d2b..9637dc506 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -852,7 +852,7 @@ function common_broadcast_notice($notice, $remote=false)
function common_enqueue_notice($notice)
{
- foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook') as $transport) {
+ foreach (array('jabber', 'omb', 'sms', 'public', 'twitter', 'facebook', 'ping') as $transport) {
$qi = new Queue_item();
$qi->notice_id = $notice->id;
$qi->transport = $transport;