summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZach Copley <zach@controlyourself.ca>2009-02-12 14:39:21 -0800
committerZach Copley <zach@controlyourself.ca>2009-02-12 14:39:21 -0800
commitf8e2ad0677d6eede93e3008452e36985ea999d74 (patch)
tree79f29366b182dc933b2ed28395afc3adda56ea60
parent986068d6e7119e17509f228857d55873b34da28f (diff)
The fabled twitterqueuehandler
-rw-r--r--lib/twitter.php2
-rw-r--r--lib/util.php2
-rwxr-xr-xscripts/startdaemons.sh3
-rwxr-xr-xscripts/stopdaemons.sh2
-rwxr-xr-xscripts/twitterqueuehandler.php71
5 files changed, 76 insertions, 4 deletions
diff --git a/lib/twitter.php b/lib/twitter.php
index 72212c185..deb6fd276 100644
--- a/lib/twitter.php
+++ b/lib/twitter.php
@@ -231,7 +231,7 @@ function broadcast_twitter($notice)
TWITTER_SERVICE);
// XXX: Not sure WHERE to check whether a notice should go to
- // Twitter. Should we even put in the queue if it's not? --Zach
+ // Twitter. Should we even put in the queue if it shouldn't? --Zach
if (is_twitter_bound($notice, $flink)) {
$fuser = $flink->getForeignUser();
diff --git a/lib/util.php b/lib/util.php
index 3f4fae3a5..7923fe28a 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -808,7 +808,7 @@ function common_broadcast_notice($notice, $remote=false)
function common_enqueue_notice($notice)
{
- foreach (array('jabber', 'omb', 'sms', 'public') as $transport) {
+ foreach (array('jabber', 'omb', 'sms', 'public', 'twitter') as $transport) {
$qi = new Queue_item();
$qi->notice_id = $notice->id;
$qi->transport = $transport;
diff --git a/scripts/startdaemons.sh b/scripts/startdaemons.sh
index 685bd938f..269036393 100755
--- a/scripts/startdaemons.sh
+++ b/scripts/startdaemons.sh
@@ -23,7 +23,8 @@
DIR=`dirname $0`
for f in xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php \
- xmppconfirmhandler.php smsqueuehandler.php ombqueuehandler.php; do
+ xmppconfirmhandler.php smsqueuehandler.php ombqueuehandler.php \
+ twitterqueuehandler.php; do
echo -n "Starting $f...";
php $DIR/$f
diff --git a/scripts/stopdaemons.sh b/scripts/stopdaemons.sh
index 08e1d4714..b69d296d3 100755
--- a/scripts/stopdaemons.sh
+++ b/scripts/stopdaemons.sh
@@ -24,7 +24,7 @@ SDIR=`dirname $0`
DIR=`php $SDIR/getpiddir.php`
for f in jabberhandler ombhandler publichandler smshandler \
- xmppconfirmhandler xmppdaemon; do
+ xmppconfirmhandler xmppdaemon twitterhandler ; do
FILES="$DIR/$f.*.pid"
for ff in "$FILES" ; do
diff --git a/scripts/twitterqueuehandler.php b/scripts/twitterqueuehandler.php
new file mode 100755
index 000000000..7da4f1e20
--- /dev/null
+++ b/scripts/twitterqueuehandler.php
@@ -0,0 +1,71 @@
+#!/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/twitter.php');
+require_once(INSTALLDIR . '/lib/queuehandler.php');
+
+set_error_handler('common_error_handler');
+
+class TwitterQueueHandler extends QueueHandler
+{
+
+ function transport()
+ {
+ return 'twitter';
+ }
+
+ function start()
+ {
+ $this->log(LOG_INFO, "INITIALIZE");
+ return true;
+ }
+
+ function handle_notice($notice)
+ {
+ return broadcast_twitter($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 TwitterQueueHandler($id);
+
+$handler->runOnce();