diff --git a/EVENTS.txt b/EVENTS.txt index 121ae175d0..2b16d43c07 100644 --- a/EVENTS.txt +++ b/EVENTS.txt @@ -254,3 +254,20 @@ StartApiRss: after the rss element is started StartApiAtom: after the element is started - $action: action object being shown +StartEnqueueNotice: about to add a notice to the queues (good place to add a new transport) +- $notice: the notice being added +- &$transports: modifiable list of transports (as strings) to queue for + +EndEnqueueNotice: after adding a notice to the queues +- $notice: the notice being added +- $transports: modifiable list of transports to use + +UnqueueHandleNotice: Handle a notice when no queue manager is available +- $notice: the notice to handle +- $queue: the "queue" that is being executed + +GetValidDaemons: Just before determining which daemons to run +- &$daemons: modifiable list of daemon scripts to run, filenames relative to scripts/ + +HandleQueuedNotice: Handle a queued notice at queue time (or immediately if no queue) +- &$notice: notice to handle diff --git a/lib/unqueuemanager.php b/lib/unqueuemanager.php index c5dc29d386..6cfe5bcbd3 100644 --- a/lib/unqueuemanager.php +++ b/lib/unqueuemanager.php @@ -72,8 +72,13 @@ class UnQueueManager require_once(INSTALLDIR.'/lib/jabber.php'); jabber_broadcast_notice($notice); break; + case 'plugin': + Event::handle('HandleQueuedNotice', array(&$notice)); + break; default: - throw ServerException("UnQueueManager: Unknown queue: $type"); + if (Event::handle('UnqueueHandleNotice', array(&$notice, $queue))) { + throw ServerException("UnQueueManager: Unknown queue: $queue"); + } } } diff --git a/lib/util.php b/lib/util.php index b74dc619c1..441dcf68e3 100644 --- a/lib/util.php +++ b/lib/util.php @@ -391,10 +391,10 @@ function common_render_content($text, $notice) { $r = common_render_text($text); $id = $notice->profile_id; - $r = preg_replace('/(^|\s+)@([A-Za-z0-9]{1,64})/e', "'\\1@'.common_at_link($id, '\\2')", $r); + $r = preg_replace('/(^|[\s\.\,\:\;]+)@([A-Za-z0-9]{1,64})/e', "'\\1@'.common_at_link($id, '\\2')", $r); $r = preg_replace('/^T ([A-Z0-9]{1,64}) /e', "'T '.common_at_link($id, '\\1').' '", $r); - $r = preg_replace('/(^|\s+)@#([A-Za-z0-9]{1,64})/e', "'\\1@#'.common_at_hash_link($id, '\\2')", $r); - $r = preg_replace('/(^|\s)!([A-Za-z0-9]{1,64})/e', "'\\1!'.common_group_link($id, '\\2')", $r); + $r = preg_replace('/(^|[\s\.\,\:\;]+)@#([A-Za-z0-9]{1,64})/e', "'\\1@#'.common_at_hash_link($id, '\\2')", $r); + $r = preg_replace('/(^|[\s\.\,\:\;]+)!([A-Za-z0-9]{1,64})/e', "'\\1!'.common_group_link($id, '\\2')", $r); return $r; } @@ -493,7 +493,7 @@ function callback_helper($matches, $callback, $notice_id) { }while($original_url!=$url); if(empty($notice_id)){ - $result = call_user_func_array($callback,$url); + $result = call_user_func_array($callback, array($url)); }else{ $result = call_user_func_array($callback, array(array($url,$notice_id)) ); } @@ -536,7 +536,7 @@ function common_linkify($url) { throw new ServerException("Can't linkify url '$url'"); } - $attrs = array('href' => $canon, 'rel' => 'external'); + $attrs = array('href' => $canon, 'title' => $longurl, 'rel' => 'external'); $is_attachment = false; $attachment_id = null; @@ -897,7 +897,8 @@ function common_enqueue_notice($notice) 'twitter', 'facebook', 'ping'); - static $allTransports = array('sms'); + + static $allTransports = array('sms', 'plugin'); $transports = $allTransports; @@ -915,11 +916,16 @@ function common_enqueue_notice($notice) } } - $qm = QueueManager::get(); + if (Event::handle('StartEnqueueNotice', array($notice, &$transports))) { - foreach ($transports as $transport) - { - $qm->enqueue($notice, $transport); + $qm = QueueManager::get(); + + foreach ($transports as $transport) + { + $qm->enqueue($notice, $transport); + } + + Event::handle('EndEnqueueNotice', array($notice, $transports)); } return true; @@ -1374,13 +1380,17 @@ function common_shorten_url($long_url) $svc = $user->urlshorteningservice; } global $_shorteners; - if(! $_shorteners[$svc]){ + if (!isset($_shorteners[$svc])) { //the user selected service doesn't exist, so default to ur1.ca $svc = 'ur1.ca'; } + if (!isset($_shorteners[$svc])) { + // no shortener plugins installed. + return $long_url; + } $reflectionObj = new ReflectionClass($_shorteners[$svc]['callInfo'][0]); - $short_url_service = $reflectionObj->newInstanceArgs($_shorteners[$svc]['callInfo'][1]); + $short_url_service = $reflectionObj->newInstanceArgs($_shorteners[$svc]['callInfo'][1]); $short_url = $short_url_service->shorten($long_url); if(substr($short_url,0,7)=='http://'){ diff --git a/plugins/PubSubHubBub/PubSubHubBubPlugin.php b/plugins/PubSubHubBub/PubSubHubBubPlugin.php index 013a234d73..e1e82e352c 100644 --- a/plugins/PubSubHubBub/PubSubHubBubPlugin.php +++ b/plugins/PubSubHubBub/PubSubHubBubPlugin.php @@ -31,7 +31,7 @@ if (!defined('STATUSNET')) { exit(1); } -define('DEFAULT_HUB','http://2pubsubhubbub.appspot.com'); +define('DEFAULT_HUB','http://pubsubhubbub.appspot.com'); require_once(INSTALLDIR.'/plugins/PubSubHubBub/publisher.php'); @@ -59,7 +59,7 @@ class PubSubHubBubPlugin extends Plugin $action->element('atom:link',array('rel'=>'hub','href'=>$this->hub),null); } - function onEndNoticeSave($notice){ + function onHandleQueuedNotice($notice){ $publisher = new Publisher($this->hub); $feeds = array(); diff --git a/scripts/getvaliddaemons.php b/scripts/getvaliddaemons.php index 8f48e8e6f0..6dd0197129 100755 --- a/scripts/getvaliddaemons.php +++ b/scripts/getvaliddaemons.php @@ -35,20 +35,36 @@ ENDOFHELP; require_once INSTALLDIR.'/scripts/commandline.inc'; +$daemons = array(); + +$daemons[] = INSTALLDIR.'/scripts/pluginqueuehandler.php'; +$daemons[] = INSTALLDIR.'/scripts/ombqueuehandler.php'; +$daemons[] = INSTALLDIR.'/scripts/facebookqueuehandler.php'; +$daemons[] = INSTALLDIR.'/scripts/pingqueuehandler.php'; + if(common_config('xmpp','enabled')) { - echo "xmppdaemon.php jabberqueuehandler.php publicqueuehandler.php "; - echo "xmppconfirmhandler.php "; + $daemons[] = INSTALLDIR.'/scripts/xmppdaemon.php'; + $daemons[] = INSTALLDIR.'/scripts/jabberqueuehandler.php'; + $daemons[] = INSTALLDIR.'/scripts/publicqueuehandler.php'; + $daemons[] = INSTALLDIR.'/scripts/xmppconfirmhandler.php'; } + if(common_config('twitterbridge','enabled')) { - echo "twitterstatusfetcher.php "; + $daemons[] = INSTALLDIR.'/scripts/twitterstatusfetcher.php'; } -echo "ombqueuehandler.php "; + if (common_config('twitter', 'enabled')) { - echo "twitterqueuehandler.php "; - echo "synctwitterfriends.php "; + $daemons[] = INSTALLDIR.'/scripts/twitterqueuehandler.php'; + $daemons[] = INSTALLDIR.'/scripts/synctwitterfriends.php'; } -echo "facebookqueuehandler.php "; -echo "pingqueuehandler.php "; + if (common_config('sms', 'enabled')) { - echo "smsqueuehandler.php "; + $daemons[] = INSTALLDIR.'/scripts/smsqueuehandler.php'; +} + +if (Event::handle('GetValidDaemons', array(&$daemons))) { + foreach ($daemons as $daemon) { + print $daemon . ' '; + } + print "\n"; } diff --git a/scripts/pluginqueuehandler.php b/scripts/pluginqueuehandler.php new file mode 100755 index 0000000000..ae807db6af --- /dev/null +++ b/scripts/pluginqueuehandler.php @@ -0,0 +1,58 @@ +#!/usr/bin/env php +. + */ + +define('INSTALLDIR', realpath(dirname(__FILE__) . '/..')); + +$shortoptions = 'i::'; +$longoptions = array('id::'); + +$helptext = <<runOnce(); diff --git a/scripts/startdaemons.sh b/scripts/startdaemons.sh index 298162673c..5fb75414d3 100755 --- a/scripts/startdaemons.sh +++ b/scripts/startdaemons.sh @@ -40,7 +40,7 @@ DAEMONS=`php $DIR/getvaliddaemons.php $ARGSG` for f in $DAEMONS; do printf "Starting $f..."; - php $DIR/$f $ARGSD + php $f $ARGSD printf "DONE.\n" done