Disable PubSubHubBub hub pings automatically on private site (hub wouldn't be able to read feeds anyway)

[Might be good to think of a core way to mark a plugin as disabled when it initializes.]
This commit is contained in:
Brion Vibber 2010-01-25 09:07:24 -08:00
parent 73f6250b9d
commit c10d5320dd

View File

@ -79,6 +79,21 @@ class PubSubHubBubPlugin extends Plugin
parent::__construct(); parent::__construct();
} }
/**
* Check if plugin should be active; may be mass-enabled.
* @return boolean
*/
function enabled()
{
if (common_config('site', 'private')) {
// PuSH relies on public feeds
return false;
}
// @fixme check for being on a private network?
return true;
}
/** /**
* Hooks the StartApiAtom event * Hooks the StartApiAtom event
* *
@ -92,8 +107,9 @@ class PubSubHubBubPlugin extends Plugin
function onStartApiAtom($action) function onStartApiAtom($action)
{ {
$action->element('link', array('rel' => 'hub', 'href' => $this->hub), null); if ($this->enabled()) {
$action->element('link', array('rel' => 'hub', 'href' => $this->hub), null);
}
return true; return true;
} }
@ -110,9 +126,11 @@ class PubSubHubBubPlugin extends Plugin
function onStartApiRss($action) function onStartApiRss($action)
{ {
$action->element('atom:link', array('rel' => 'hub', if ($this->enabled()) {
'href' => $this->hub), $action->element('atom:link', array('rel' => 'hub',
null); 'href' => $this->hub),
null);
}
return true; return true;
} }
@ -130,6 +148,9 @@ class PubSubHubBubPlugin extends Plugin
function onHandleQueuedNotice($notice) function onHandleQueuedNotice($notice)
{ {
if (!$this->enabled()) {
return false;
}
$publisher = new Publisher($this->hub); $publisher = new Publisher($this->hub);
$feeds = array(); $feeds = array();
@ -243,16 +264,21 @@ class PubSubHubBubPlugin extends Plugin
function onPluginVersion(&$versions) function onPluginVersion(&$versions)
{ {
$about = _m('The PubSubHubBub plugin pushes RSS/Atom updates '.
'to a <a href = "'.
'http://pubsubhubbub.googlecode.com/'.
'">PubSubHubBub</a> hub.');
if (!$this->enabled()) {
$about = '<span class="disabled" style="color:gray">' . $about . '</span> ' .
_m('(inactive on private site)');
}
$versions[] = array('name' => 'PubSubHubBub', $versions[] = array('name' => 'PubSubHubBub',
'version' => STATUSNET_VERSION, 'version' => STATUSNET_VERSION,
'author' => 'Craig Andrews', 'author' => 'Craig Andrews',
'homepage' => 'homepage' =>
'http://status.net/wiki/Plugin:PubSubHubBub', 'http://status.net/wiki/Plugin:PubSubHubBub',
'rawdescription' => 'rawdescription' =>
_m('The PubSubHubBub plugin pushes RSS/Atom updates '. $about);
'to a <a href = "'.
'http://pubsubhubbub.googlecode.com/'.
'">PubSubHubBub</a> hub.'));
return true; return true;
} }