]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Initial support for ping service
authorEvan Prodromou <evan@controlyourself.ca>
Sat, 24 Jan 2009 17:38:12 +0000 (18:38 +0100)
committerEvan Prodromou <evan@controlyourself.ca>
Sat, 24 Jan 2009 17:38:12 +0000 (18:38 +0100)
It makes sense to use the weblogs.com ping service to alert people to
changes on the site. So, we do. Includes an extra ping queue handler.

lib/common.php
lib/ping.php [new file with mode: 0644]
lib/util.php
scripts/pingqueuehandler.php [new file with mode: 0644]

index a2f9b9bfe73f1fdf5deed09fc892997f2144ba4c..cc82f8bd73c5314b1220d3f6552657fd4223ec24 100644 (file)
@@ -128,6 +128,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 (file)
index 0000000..32c0b98
--- /dev/null
@@ -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
index b5b194519e37598b260cfba818673069c0bf0e74..419e21e828ca0700ab398e8e0b0d458b10ef8154 100644 (file)
@@ -1124,7 +1124,7 @@ function common_twitter_broadcast($notice, $flink)
 
 function common_enqueue_notice($notice)
 {
-    foreach (array('jabber', 'omb', 'sms', 'public') as $transport) {
+    foreach (array('jabber', 'omb', 'sms', 'public', 'ping') as $transport) {
         $qi = new Queue_item();
         $qi->notice_id = $notice->id;
         $qi->transport = $transport;
diff --git a/scripts/pingqueuehandler.php b/scripts/pingqueuehandler.php
new file mode 100644 (file)
index 0000000..55a266e
--- /dev/null
@@ -0,0 +1,64 @@
+#!/usr/bin/env php
+<?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/>.
+ */
+
+# Abort if called from a web server
+if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
+       print "This script must be run from the command line\n";
+       exit();
+}
+
+define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
+define('LACONICA', true);
+
+require_once(INSTALLDIR . '/lib/common.php');
+require_once(INSTALLDIR . '/lib/ping.php');
+require_once(INSTALLDIR . '/lib/queuehandler.php');
+
+set_error_handler('common_error_handler');
+
+class PingQueueHandler extends QueueHandler {
+       
+       function transport() {
+               return 'ping';
+       }
+
+       function start() {
+               $this->log(LOG_INFO, "INITIALIZE");
+               return true;
+       }
+
+       function handle_notice($notice) {
+               return ping_broadcast_notice($notice);
+       }
+       
+       function finish() {
+       }
+}
+
+ini_set("max_execution_time", "0");
+ini_set("max_input_time", "0");
+set_time_limit(0);
+mb_internal_encoding('UTF-8');
+
+$id = ($argc > 1) ? $argv[1] : NULL;
+
+$handler = new PingQueueHandler($id);
+
+$handler->runOnce();