X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=scripts%2Fpublicqueuehandler.php;h=50a11bcba03b26332e2009f94e678aea7ded1479;hb=769e5b7622445cf49cbaf5a416fb6b250b072866;hp=0d95a489f84d07d3ea2b6fac2a41a3d9cb5490de;hpb=c4d67892751b17856b235182874c3304890dc2c3;p=quix0rs-gnu-social.git diff --git a/scripts/publicqueuehandler.php b/scripts/publicqueuehandler.php index 0d95a489f8..50a11bcba0 100755 --- a/scripts/publicqueuehandler.php +++ b/scripts/publicqueuehandler.php @@ -1,8 +1,8 @@ #!/usr/bin/env php . */ -# 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/jabber.php'); -require_once(INSTALLDIR . '/lib/queuehandler.php'); +$shortoptions = 'i::'; +$longoptions = array('id::'); -set_error_handler('common_error_handler'); +$helptext = <<conn = jabber_connect($this->_id, NULL, -1); - return !is_null($this->conn); - } + -i --id Identity (default none) - function handle_notice($notice) { - return jabber_public_notice($notice); - } - - function finish() { - } -} +END_OF_PUBLIC_HELP; -mb_internal_encoding('UTF-8'); +require_once INSTALLDIR.'/scripts/commandline.inc'; -$resource = ($argc > 1) ? $argv[1] : (common_config('xmpp','resource') . '-public'); +require_once INSTALLDIR . '/lib/jabber.php'; +require_once INSTALLDIR . '/lib/xmppqueuehandler.php'; -$handler = new XmppQueueHandler($resource); +class PublicQueueHandler extends XmppQueueHandler +{ -if ($handler->start()) { - $handler->handle_queue(); + function transport() + { + return 'public'; + } + + function handle_notice($notice) + { + try { + return jabber_public_notice($notice); + } catch (XMPPHP_Exception $e) { + $this->log(LOG_ERR, "Got an XMPPHP_Exception: " . $e->getMessage()); + die($e->getMessage()); + } + } } -$handler->finish(); +// Abort immediately if xmpp is not enabled, otherwise the daemon chews up +// lots of CPU trying to connect to unconfigured servers +if (common_config('xmpp','enabled')==false) { + print "Aborting daemon - xmpp is disabled\n"; + exit(); +} + +if (have_option('i')) { + $id = get_option_value('i'); +} else if (have_option('--id')) { + $id = get_option_value('--id'); +} else if (count($args) > 0) { + $id = $args[0]; +} else { + $id = null; +} + +$handler = new PublicQueueHandler($id); + +$handler->runOnce();