Merge branch '0.9.x' into 1.0.x

Conflicts:
	lib/queuemanager.php
	lib/xmppmanager.php
	plugins/Xmpp/Fake_XMPP.php
	scripts/imdaemon.php
This commit is contained in:
Craig Andrews 2010-02-16 13:15:09 -05:00
commit 20d6a7caed
55 changed files with 1719 additions and 543 deletions

View File

@ -1,4 +1,4 @@
InitializePlugin: a chance to initialize a plugin in a complete environment
\InitializePlugin: a chance to initialize a plugin in a complete environment
CleanupPlugin: a chance to cleanup a plugin at the end of a program
@ -355,6 +355,14 @@ EndShowHeadElements: Right before the </head> tag; put <script>s here if you nee
CheckSchema: chance to check the schema
StartProfileRemoteSubscribe: Before showing the link to remote subscription
- $userprofile: UserProfile widget
- &$profile: the profile being shown
EndProfileRemoteSubscribe: After showing the link to remote subscription
- $userprofile: UserProfile widget
- &$profile: the profile being shown
StartProfilePageProfileSection: Starting to show the section of the
profile page with the actual profile data;
hook to prevent showing the profile (e.g.)

19
README
View File

@ -1192,6 +1192,8 @@ server: If set, defines another server where avatars are stored in the
typically only make 2 connections to a single server at a
time <http://ur1.ca/6ih>, so this can parallelize the job.
Defaults to null.
ssl: Whether to access avatars using HTTPS. Defaults to null, meaning
to guess based on site-wide SSL settings.
public
------
@ -1221,6 +1223,19 @@ path: Path part of theme URLs, before the theme name. Relative to the
(using version numbers as the path) to make sure that all files are
reloaded by caching clients or proxies. Defaults to null,
which means to use the site path + '/theme'.
ssl: Whether to use SSL for theme elements. Default is null, which means
guess based on site SSL settings.
javascript
----------
server: You can speed up page loading by pointing the
theme file lookup to another server (virtual or real).
Defaults to NULL, meaning to use the site server.
path: Path part of Javascript URLs. Defaults to null,
which means to use the site path + '/js/'.
ssl: Whether to use SSL for JavaScript files. Default is null, which means
guess based on site SSL settings.
xmpp
----
@ -1447,6 +1462,8 @@ server: server name to use when creating URLs for uploaded files.
a virtual server here can speed up Web performance.
path: URL path, relative to the server, to find files. Defaults to
main path + '/file/'.
ssl: whether to use HTTPS for file URLs. Defaults to null, meaning to
guess based on other SSL settings.
filecommand: command to use for determining the type of a file. May be
skipped if fileinfo extension is installed. Defaults to
'/usr/bin/file'.
@ -1506,6 +1523,8 @@ dir: directory to write backgrounds too. Default is '/background/'
subdir of install dir.
path: path to backgrounds. Default is sub-path of install path; note
that you may need to change this if you change site-path too.
ssl: Whether or not to use HTTPS for background files. Defaults to
null, meaning to guess from site-wide SSL settings.
ping
----

View File

@ -138,7 +138,19 @@ class ApiTimelineGroupAction extends ApiPrivateAuthAction
try {
$atom = new AtomNoticeFeed();
// If this was called using an integer ID, i.e.: using the canonical
// URL for this group's feed, then pass the Group object into the feed,
// so the OStatus plugin, and possibly other plugins, can access it.
// Feels sorta hacky. -- Z
$atom = null;
$id = $this->arg('id');
if (strval(intval($id)) === strval($id)) {
$atom = new AtomGroupNoticeFeed($this->group);
} else {
$atom = new AtomGroupNoticeFeed();
}
$atom->setId($id);
$atom->setTitle($title);

View File

@ -148,7 +148,19 @@ class ApiTimelineUserAction extends ApiBareAuthAction
header('Content-Type: application/atom+xml; charset=utf-8');
$atom = new AtomNoticeFeed();
// If this was called using an integer ID, i.e.: using the canonical
// URL for this user's feed, then pass the User object into the feed,
// so the OStatus plugin, and possibly other plugins, can access it.
// Feels sorta hacky. -- Z
$atom = null;
$id = $this->arg('id');
if (strval(intval($id)) === strval($id)) {
$atom = new AtomUserNoticeFeed($this->user);
} else {
$atom = new AtomUserNoticeFeed();
}
$atom->setId($id);
$atom->setTitle($title);

View File

@ -82,9 +82,20 @@ class Avatar extends Memcached_DataObject
$server = common_config('site', 'server');
}
// XXX: protocol
$ssl = common_config('avatar', 'ssl');
return 'http://'.$server.$path.$filename;
if (is_null($ssl)) { // null -> guess
if (common_config('site', 'ssl') == 'always' &&
!common_config('avatar', 'server')) {
$ssl = true;
} else {
$ssl = false;
}
}
$protocol = ($ssl) ? 'https' : 'http';
return $protocol.'://'.$server.$path.$filename;
}
function displayUrl()

View File

@ -155,9 +155,20 @@ class Design extends Memcached_DataObject
$server = common_config('site', 'server');
}
// XXX: protocol
$ssl = common_config('background', 'ssl');
return 'http://'.$server.$path.$filename;
if (is_null($ssl)) { // null -> guess
if (common_config('site', 'ssl') == 'always' &&
!common_config('background', 'server')) {
$ssl = true;
} else {
$ssl = false;
}
}
$protocol = ($ssl) ? 'https' : 'http';
return $protocol.'://'.$server.$path.$filename;
}
function setDisposition($on, $off, $tile)

View File

@ -228,9 +228,20 @@ class File extends Memcached_DataObject
$server = common_config('site', 'server');
}
// XXX: protocol
$ssl = common_config('attachments', 'ssl');
return 'http://'.$server.$path.$filename;
if (is_null($ssl)) { // null -> guess
if (common_config('site', 'ssl') == 'always' &&
!common_config('attachments', 'server')) {
$ssl = true;
} else {
$ssl = false;
}
}
$protocol = ($ssl) ? 'https' : 'http';
return $protocol.'://'.$server.$path.$filename;
}
}

View File

@ -19,57 +19,8 @@
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
class Memcached_DataObject extends DB_DataObject
class Memcached_DataObject extends Safe_DataObject
{
/**
* Destructor to free global memory resources associated with
* this data object when it's unset or goes out of scope.
* DB_DataObject doesn't do this yet by itself.
*/
function __destruct()
{
$this->free();
if (method_exists('DB_DataObject', '__destruct')) {
parent::__destruct();
}
}
/**
* Magic function called at serialize() time.
*
* We use this to drop a couple process-specific references
* from DB_DataObject which can cause trouble in future
* processes.
*
* @return array of variable names to include in serialization.
*/
function __sleep()
{
$vars = array_keys(get_object_vars($this));
$skip = array('_DB_resultid', '_link_loaded');
return array_diff($vars, $skip);
}
/**
* Magic function called at unserialize() time.
*
* Clean out some process-specific variables which might
* be floating around from a previous process's cached
* objects.
*
* Old cached objects may still have them.
*/
function __wakeup()
{
// Refers to global state info from a previous process.
// Clear this out so we don't accidentally break global
// state in *this* process.
$this->_DB_resultid = null;
// We don't have any local DBO refs, so clear these out.
$this->_link_loaded = false;
}
/**
* Wrapper for DB_DataObject's static lookup using memcached
* as backing instead of an in-process cache array.
@ -579,3 +530,4 @@ class Memcached_DataObject extends DB_DataObject
return $c->set($cacheKey, $value);
}
}

250
classes/Safe_DataObject.php Normal file
View File

@ -0,0 +1,250 @@
<?php
/*
* StatusNet - the distributed open-source microblogging tool
* Copyright (C) 2010, StatusNet, 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('STATUSNET') && !defined('LACONICA')) { exit(1); }
/**
* Extended DB_DataObject to improve a few things:
* - free global resources from destructor
* - remove bogus global references from serialized objects
* - don't leak memory when loading already-used .ini files
* (eg when using the same schema on thousands of databases)
*/
class Safe_DataObject extends DB_DataObject
{
/**
* Destructor to free global memory resources associated with
* this data object when it's unset or goes out of scope.
* DB_DataObject doesn't do this yet by itself.
*/
function __destruct()
{
$this->free();
if (method_exists('DB_DataObject', '__destruct')) {
parent::__destruct();
}
}
/**
* Magic function called at serialize() time.
*
* We use this to drop a couple process-specific references
* from DB_DataObject which can cause trouble in future
* processes.
*
* @return array of variable names to include in serialization.
*/
function __sleep()
{
$vars = array_keys(get_object_vars($this));
$skip = array('_DB_resultid', '_link_loaded');
return array_diff($vars, $skip);
}
/**
* Magic function called at unserialize() time.
*
* Clean out some process-specific variables which might
* be floating around from a previous process's cached
* objects.
*
* Old cached objects may still have them.
*/
function __wakeup()
{
// Refers to global state info from a previous process.
// Clear this out so we don't accidentally break global
// state in *this* process.
$this->_DB_resultid = null;
// We don't have any local DBO refs, so clear these out.
$this->_link_loaded = false;
}
/**
* Work around memory-leak bugs...
* Had to copy-paste the whole function in order to patch a couple lines of it.
* Would be nice if this code was better factored.
*
* @param optional string name of database to assign / read
* @param optional array structure of database, and keys
* @param optional array table links
*
* @access public
* @return true or PEAR:error on wrong paramenters.. or false if no file exists..
* or the array(tablename => array(column_name=>type)) if called with 1 argument.. (databasename)
*/
function databaseStructure()
{
global $_DB_DATAOBJECT;
// Assignment code
if ($args = func_get_args()) {
if (count($args) == 1) {
// this returns all the tables and their structure..
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug("Loading Generator as databaseStructure called with args",1);
}
$x = new DB_DataObject;
$x->_database = $args[0];
$this->_connect();
$DB = &$_DB_DATAOBJECT['CONNECTIONS'][$this->_database_dsn_md5];
$tables = $DB->getListOf('tables');
class_exists('DB_DataObject_Generator') ? '' :
require_once 'DB/DataObject/Generator.php';
foreach($tables as $table) {
$y = new DB_DataObject_Generator;
$y->fillTableSchema($x->_database,$table);
}
return $_DB_DATAOBJECT['INI'][$x->_database];
} else {
$_DB_DATAOBJECT['INI'][$args[0]] = isset($_DB_DATAOBJECT['INI'][$args[0]]) ?
$_DB_DATAOBJECT['INI'][$args[0]] + $args[1] : $args[1];
if (isset($args[1])) {
$_DB_DATAOBJECT['LINKS'][$args[0]] = isset($_DB_DATAOBJECT['LINKS'][$args[0]]) ?
$_DB_DATAOBJECT['LINKS'][$args[0]] + $args[2] : $args[2];
}
return true;
}
}
if (!$this->_database) {
$this->_connect();
}
// loaded already?
if (!empty($_DB_DATAOBJECT['INI'][$this->_database])) {
// database loaded - but this is table is not available..
if (
empty($_DB_DATAOBJECT['INI'][$this->_database][$this->__table])
&& !empty($_DB_DATAOBJECT['CONFIG']['proxy'])
) {
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug("Loading Generator to fetch Schema",1);
}
class_exists('DB_DataObject_Generator') ? '' :
require_once 'DB/DataObject/Generator.php';
$x = new DB_DataObject_Generator;
$x->fillTableSchema($this->_database,$this->__table);
}
return true;
}
if (empty($_DB_DATAOBJECT['CONFIG'])) {
DB_DataObject::_loadConfig();
}
// if you supply this with arguments, then it will take those
// as the database and links array...
$schemas = isset($_DB_DATAOBJECT['CONFIG']['schema_location']) ?
array("{$_DB_DATAOBJECT['CONFIG']['schema_location']}/{$this->_database}.ini") :
array() ;
if (isset($_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"])) {
$schemas = is_array($_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"]) ?
$_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"] :
explode(PATH_SEPARATOR,$_DB_DATAOBJECT['CONFIG']["ini_{$this->_database}"]);
}
/* BEGIN CHANGED FROM UPSTREAM */
$_DB_DATAOBJECT['INI'][$this->_database] = $this->parseIniFiles($schemas);
/* END CHANGED FROM UPSTREAM */
// now have we loaded the structure..
if (!empty($_DB_DATAOBJECT['INI'][$this->_database][$this->__table])) {
return true;
}
// - if not try building it..
if (!empty($_DB_DATAOBJECT['CONFIG']['proxy'])) {
class_exists('DB_DataObject_Generator') ? '' :
require_once 'DB/DataObject/Generator.php';
$x = new DB_DataObject_Generator;
$x->fillTableSchema($this->_database,$this->__table);
// should this fail!!!???
return true;
}
$this->debug("Cant find database schema: {$this->_database}/{$this->__table} \n".
"in links file data: " . print_r($_DB_DATAOBJECT['INI'],true),"databaseStructure",5);
// we have to die here!! - it causes chaos if we dont (including looping forever!)
$this->raiseError( "Unable to load schema for database and table (turn debugging up to 5 for full error message)", DB_DATAOBJECT_ERROR_INVALIDARGS, PEAR_ERROR_DIE);
return false;
}
/** For parseIniFiles */
protected static $iniCache = array();
/**
* When switching site configurations, DB_DataObject was loading its
* .ini files over and over, leaking gobs of memory.
* This refactored helper function uses a local cache of .ini files
* to minimize the leaks.
*
* @param array of .ini file names $schemas
* @return array
*/
protected function parseIniFiles($schemas)
{
$key = implode("|", $schemas);
if (!isset(Safe_DataObject::$iniCache[$key])) {
$data = array();
foreach ($schemas as $ini) {
if (file_exists($ini) && is_file($ini)) {
$data = array_merge($data, parse_ini_file($ini, true));
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
if (!is_readable ($ini)) {
$this->debug("ini file is not readable: $ini","databaseStructure",1);
} else {
$this->debug("Loaded ini file: $ini","databaseStructure",1);
}
}
} else {
if (!empty($_DB_DATAOBJECT['CONFIG']['debug'])) {
$this->debug("Missing ini file: $ini","databaseStructure",1);
}
}
}
Safe_DataObject::$iniCache[$key] = $data;
}
return Safe_DataObject::$iniCache[$key];
}
}

View File

@ -21,7 +21,7 @@
if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
class Status_network extends DB_DataObject
class Status_network extends Safe_DataObject
{
###START_AUTOCODE
/* the code below is auto generated do not remove the above tag */
@ -57,6 +57,7 @@ class Status_network extends DB_DataObject
###END_AUTOCODE
static $cache = null;
static $cacheInitialized = false;
static $base = null;
static $wildcard = null;
@ -78,11 +79,15 @@ class Status_network extends DB_DataObject
if (class_exists('Memcache')) {
self::$cache = new Memcache();
// Can't close persistent connections, making forking painful.
// If we're a parent command-line process we need
// to be able to close out the connection after
// forking, so disable persistence.
//
// @fixme only do this in *parent* CLI processes.
// single-process and child-processes *should* use persistent.
$persist = php_sapi_name() != 'cli';
// We'll turn it back on again the second time
// through which will either be in a child process,
// or a single-process script which is switching
// configurations.
$persist = php_sapi_name() != 'cli' || self::$cacheInitialized;
if (is_array($servers)) {
foreach($servers as $server) {
self::$cache->addServer($server, 11211, $persist);
@ -90,6 +95,7 @@ class Status_network extends DB_DataObject
} else {
self::$cache->addServer($servers, 11211, $persist);
}
self::$cacheInitialized = true;
}
self::$base = $dbname;

View File

@ -285,6 +285,10 @@ class OMB_Service_Provider {
list($consumer, $token) = $this->getOAuthServer()->verify_request($req);
} catch (OAuthException $e) {
header('HTTP/1.1 403 Forbidden');
// @debug hack
throw OMB_RemoteServiceException::forRequest($uri,
'Revoked accesstoken for ' . $listenee . ': ' . $e->getMessage());
// @end debug
throw OMB_RemoteServiceException::forRequest($uri,
'Revoked accesstoken for ' . $listenee);
}

View File

@ -404,12 +404,10 @@ var SN = { // StatusNet
},
NoticeWithAttachment: function(notice) {
if ($('.attachment', notice).length === 0) {
if (notice.find('.attachment').length === 0) {
return;
}
var notice_id = notice.attr('id');
$.fn.jOverlay.options = {
method : 'GET',
data : '',
@ -429,35 +427,37 @@ var SN = { // StatusNet
css : {'max-width':'542px', 'top':'5%', 'left':'32.5%'}
};
$('#'+notice_id+' a.attachment').click(function() {
notice.find('a.attachment').click(function() {
$().jOverlay({url: $('address .url')[0].href+'attachment/' + ($(this).attr('id').substring('attachment'.length + 1)) + '/ajax'});
return false;
});
var t;
$("body:not(#shownotice) #"+notice_id+" a.thumbnail").hover(
function() {
var anchor = $(this);
$("a.thumbnail").children('img').hide();
anchor.closest(".entry-title").addClass('ov');
if ($('#shownotice').length == 0) {
var t;
notice.find('a.thumbnail').hover(
function() {
var anchor = $(this);
$('a.thumbnail').children('img').hide();
anchor.closest(".entry-title").addClass('ov');
if (anchor.children('img').length === 0) {
t = setTimeout(function() {
$.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
anchor.append(data);
});
}, 500);
if (anchor.children('img').length === 0) {
t = setTimeout(function() {
$.get($('address .url')[0].href+'attachment/' + (anchor.attr('id').substring('attachment'.length + 1)) + '/thumbnail', null, function(data) {
anchor.append(data);
});
}, 500);
}
else {
anchor.children('img').show();
}
},
function() {
clearTimeout(t);
$('a.thumbnail').children('img').hide();
$(this).closest('.entry-title').removeClass('ov');
}
else {
anchor.children('img').show();
}
},
function() {
clearTimeout(t);
$("a.thumbnail").children('img').hide();
$(this).closest(".entry-title").removeClass('ov');
}
);
);
}
},
NoticeDataAttach: function() {

View File

@ -405,6 +405,7 @@ class Action extends HTMLOutputter // lawsuit
'src' => (common_config('site', 'logo')) ? common_config('site', 'logo') : Theme::path('logo.png'),
'alt' => common_config('site', 'name')));
}
$this->text(' ');
$this->element('span', array('class' => 'fn org'), common_config('site', 'name'));
$this->elementEnd('a');
Event::handle('EndAddressData', array($this));
@ -822,12 +823,14 @@ class Action extends HTMLOutputter // lawsuit
'alt' => common_config('license', 'title'),
'width' => '80',
'height' => '15'));
$this->text(' ');
//TODO: This is dirty: i18n
$this->text(_('All '.common_config('site', 'name').' content and data are available under the '));
$this->element('a', array('class' => 'license',
'rel' => 'external license',
'href' => common_config('license', 'url')),
common_config('license', 'title'));
$this->text(' ');
$this->text(_('license.'));
$this->elementEnd('p');
break;

View File

@ -1155,7 +1155,6 @@ class ApiAction extends Action
$this->elementStart('feed', array('xmlns' => 'http://www.w3.org/2005/Atom',
'xml:lang' => 'en-US',
'xmlns:thr' => 'http://purl.org/syndication/thread/1.0'));
Event::handle('StartApiAtom', array($this));
}
function endTwitterAtom()

View File

@ -175,6 +175,8 @@ class Atom10Feed extends XMLStringer
$this->element('updated', null, $this->updated);
$this->renderAuthors();
$this->renderLinks();
}
@ -221,18 +223,21 @@ class Atom10Feed extends XMLStringer
function getString()
{
$this->validate();
if (Event::handle('StartApiAtom', array($this))) {
$this->initFeed();
$this->renderAuthors();
$this->validate();
$this->initFeed();
if (!empty($this->subject)) {
$this->raw($this->subject);
if (!empty($this->subject)) {
$this->raw($this->subject);
}
$this->renderEntries();
$this->endFeed();
Event::handle('EndApiAtom', array($this));
}
$this->renderEntries();
$this->endFeed();
return $this->xw->outputMemory();
}

View File

@ -0,0 +1,67 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Class for building an in-memory Atom feed for a particular group's
* timeline.
*
* PHP version 5
*
* LICENCE: 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/>.
*
* @category Feed
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET'))
{
exit(1);
}
/**
* Class for group notice feeds. May contains a reference to the group.
*
* @category Feed
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
class AtomGroupNoticeFeed extends AtomNoticeFeed
{
private $group;
/**
* Constructor
*
* @param Group $group the group for the feed (optional)
* @param boolean $indent flag to turn indenting on or off
*
* @return void
*/
function __construct($group = null, $indent = true) {
parent::__construct($indent);
$this->group = $group;
}
function getGroup()
{
return $this->group;
}
}

View File

@ -2,7 +2,7 @@
/**
* StatusNet, the distributed open-source microblogging tool
*
* Class for building and Atom feed from a collection of notices
* Class for building an Atom feed from a collection of notices
*
* PHP version 5
*
@ -101,3 +101,5 @@ class AtomNoticeFeed extends Atom10Feed
}
}

View File

@ -0,0 +1,66 @@
<?php
/**
* StatusNet, the distributed open-source microblogging tool
*
* Class for building an in-memory Atom feed for a particular user's
* timeline.
*
* PHP version 5
*
* LICENCE: 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/>.
*
* @category Feed
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
if (!defined('STATUSNET'))
{
exit(1);
}
/**
* Class for user notice feeds. May contain a reference to the user.
*
* @category Feed
* @package StatusNet
* @author Zach Copley <zach@status.net>
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
class AtomUserNoticeFeed extends AtomNoticeFeed
{
private $user;
/**
* Constructor
*
* @param User $user the user for the feed (optional)
* @param boolean $indent flag to turn indenting on or off
*
* @return void
*/
function __construct($user = null, $indent = true) {
parent::__construct($indent);
$this->user = $user;
}
function getUser()
{
return $this->user;
}
}

View File

@ -159,6 +159,32 @@ class Cache
return $success;
}
/**
* Atomically increment an existing numeric value.
* Existing expiration time should remain unchanged, if any.
*
* @param string $key The key to use for lookups
* @param int $step Amount to increment (default 1)
*
* @return mixed incremented value, or false if not set.
*/
function increment($key, $step=1)
{
$value = false;
if (Event::handle('StartCacheIncrement', array(&$key, &$step, &$value))) {
// Fallback is not guaranteed to be atomic,
// and may original expiry value.
$value = $this->get($key);
if ($value !== false) {
$value += $step;
$ok = $this->set($key, $value);
$got = $this->get($key);
}
Event::handle('EndCacheIncrement', array($key, $step, $value));
}
return $value;
}
/**
* Delete the value associated with a key
*

View File

@ -72,7 +72,7 @@ class DBQueueManager extends QueueManager
public function poll()
{
$this->_log(LOG_DEBUG, 'Checking for notices...');
$qi = Queue_item::top($this->getQueues());
$qi = Queue_item::top($this->activeQueues());
if (empty($qi)) {
$this->_log(LOG_DEBUG, 'No notices waiting; idling.');
return false;
@ -142,9 +142,4 @@ class DBQueueManager extends QueueManager
$this->stats('error', $queue);
}
protected function _log($level, $msg)
{
common_log($level, 'DBQueueManager: '.$msg);
}
}

View File

@ -81,7 +81,7 @@ $default =
'subsystem' => 'db', # default to database, or 'stomp'
'stomp_server' => null,
'queue_basename' => '/queue/statusnet/',
'control_channel' => '/topic/statusnet-control', // broadcasts to all queue daemons
'control_channel' => '/topic/statusnet/control', // broadcasts to all queue daemons
'stomp_username' => null,
'stomp_password' => null,
'stomp_persistent' => true, // keep items across queue server restart, if persistence is enabled
@ -91,6 +91,12 @@ $default =
'spawndelay' => 1, // Wait at least N seconds between (re)spawns of child processes to avoid slamming the queue server with subscription startup
'debug_memory' => false, // true to spit memory usage to log
'inboxes' => true, // true to do inbox distribution & output queueing from in background via 'distrib' queue
'breakout' => array('*' => 'shared'), // set global or per-handler queue breakout
// 'shared': use a shared queue for all sites
// 'handler': share each/this handler over multiple sites
// 'site': break out for each/this handler on this site
'max_retries' => 10, // drop messages after N failed attempts to process (Stomp)
'dead_letter_dir' => false, // set to directory to save dropped messages into (Stomp)
),
'license' =>
array('type' => 'cc', # can be 'cc', 'allrightsreserved', 'private'
@ -111,11 +117,13 @@ $default =
'avatar' =>
array('server' => null,
'dir' => INSTALLDIR . '/avatar/',
'path' => $_path . '/avatar/'),
'path' => $_path . '/avatar/',
'ssl' => null),
'background' =>
array('server' => null,
'dir' => INSTALLDIR . '/background/',
'path' => $_path . '/background/'),
'path' => $_path . '/background/',
'ssl' => null),
'public' =>
array('localonly' => true,
'blacklist' => array(),
@ -123,10 +131,12 @@ $default =
'theme' =>
array('server' => null,
'dir' => null,
'path'=> null),
'path'=> null,
'ssl' => null),
'javascript' =>
array('server' => null,
'path'=> null),
'path'=> null,
'ssl' => null),
'throttle' =>
array('enabled' => false, // whether to throttle edits; false by default
'count' => 20, // number of allowed messages in timespan
@ -184,6 +194,7 @@ $default =
array('server' => null,
'dir' => INSTALLDIR . '/file/',
'path' => $_path . '/file/',
'ssl' => null,
'supported' => array('image/png',
'image/jpeg',
'image/gif',

View File

@ -105,6 +105,7 @@ class GroupList extends Widget
'alt' =>
($this->group->fullname) ? $this->group->fullname :
$this->group->nickname));
$this->out->text(' ');
$hasFN = ($this->group->fullname) ? 'nickname' : 'fn org nickname';
$this->out->elementStart('span', $hasFN);
$this->out->raw($this->highlight($this->group->nickname));
@ -112,16 +113,19 @@ class GroupList extends Widget
$this->out->elementEnd('a');
if ($this->group->fullname) {
$this->out->text(' ');
$this->out->elementStart('span', 'fn org');
$this->out->raw($this->highlight($this->group->fullname));
$this->out->elementEnd('span');
}
if ($this->group->location) {
$this->out->text(' ');
$this->out->elementStart('span', 'label');
$this->out->raw($this->highlight($this->group->location));
$this->out->elementEnd('span');
}
if ($this->group->homepage) {
$this->out->text(' ');
$this->out->elementStart('a', array('href' => $this->group->homepage,
'class' => 'url'));
$this->out->raw($this->highlight($this->group->homepage));

View File

@ -85,9 +85,9 @@ class GroupSection extends Section
'href' => $group->homeUrl(),
'rel' => 'contact group',
'class' => 'url'));
$this->out->text(' ');
$logo = ($group->stream_logo) ?
$group->stream_logo : User_group::defaultLogo(AVATAR_STREAM_SIZE);
$this->out->element('img', array('src' => $logo,
'width' => AVATAR_MINI_SIZE,
'height' => AVATAR_MINI_SIZE,
@ -95,6 +95,7 @@ class GroupSection extends Section
'alt' => ($group->fullname) ?
$group->fullname :
$group->nickname));
$this->out->text(' ');
$this->out->element('span', 'fn org nickname', $group->nickname);
$this->out->elementEnd('a');
$this->out->elementEnd('span');

View File

@ -376,9 +376,20 @@ class HTMLOutputter extends XMLOutputter
$server = common_config('site', 'server');
}
// XXX: protocol
$ssl = common_config('javascript', 'ssl');
$src = 'http://'.$server.$path.$src . '?version=' . STATUSNET_VERSION;
if (is_null($ssl)) { // null -> guess
if (common_config('site', 'ssl') == 'always' &&
!common_config('javascript', 'server')) {
$ssl = true;
} else {
$ssl = false;
}
}
$protocol = ($ssl) ? 'https' : 'http';
$src = $protocol.'://'.$server.$path.$src . '?version=' . STATUSNET_VERSION;
}
$this->element('script', array('type' => $type,

View File

@ -42,8 +42,7 @@ abstract class ImManager extends IoManager
function __construct($imPlugin)
{
$this->plugin = $imPlugin;
//TODO We only really want to register this event if this is the thread that runs the ImManager
Event::addHandler('EndInitializeQueueManager', array($this, 'onEndInitializeQueueManager'));
$this->plugin->imManager = $this;
}
/**
@ -54,17 +53,4 @@ abstract class ImManager extends IoManager
{
throw new Exception('ImManager should be created using it\'s constructor, not the static get method');
}
/**
* Register notice queue handler
*
* @param QueueManager $manager
*
* @return boolean hook return
*/
function onEndInitializeQueueManager($manager)
{
$manager->connect($this->plugin->transport . '-out', new ImSenderQueueHandler($this->plugin, $this), 'imdaemon');
return true;
}
}

View File

@ -507,8 +507,9 @@ abstract class ImPlugin extends Plugin
*/
function onEndInitializeQueueManager($manager)
{
$manager->connect($this->transport . '-in', new ImReceiverQueueHandler($this));
$manager->connect($this->transport . '-in', new ImReceiverQueueHandler($this), 'im');
$manager->connect($this->transport, new ImQueueHandler($this));
$manager->connect($this->transport . '-out', new ImSenderQueueHandler($this), 'im');
return true;
}

View File

@ -25,10 +25,9 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
class ImSenderQueueHandler extends QueueHandler
{
function __construct($plugin, $immanager)
function __construct($plugin)
{
$this->plugin = $plugin;
$this->immanager = $immanager;
}
/**
@ -38,7 +37,7 @@ class ImSenderQueueHandler extends QueueHandler
*/
function handle($data)
{
return $this->immanager->send_raw_message($data);
return $this->plugin->imManager->send_raw_message($data);
}
}

View File

@ -59,9 +59,10 @@ abstract class IoManager
* your manager about each site you'll have to handle so you
* can do any necessary per-site setup.
*
* @param string $site target site server name
* The new site will be the currently live configuration during
* this call.
*/
public function addSite($site)
public function addSite()
{
/* no-op */
}

View File

@ -56,9 +56,9 @@ abstract class IoMaster
$this->multiSite = $multiSite;
}
if ($this->multiSite) {
$this->sites = $this->findAllSites();
$this->sites = StatusNet::findAllSites();
} else {
$this->sites = array(common_config('site', 'server'));
$this->sites = array(StatusNet::currentSite());
}
if (empty($this->sites)) {
@ -66,9 +66,7 @@ abstract class IoMaster
}
foreach ($this->sites as $site) {
if ($site != common_config('site', 'server')) {
StatusNet::init($site);
}
StatusNet::switchSite($site);
$this->initManagers();
}
}
@ -81,61 +79,31 @@ abstract class IoMaster
*/
abstract function initManagers();
/**
* Pull all local sites from status_network table.
* @return array of hostnames
*/
protected function findAllSites()
{
$hosts = array();
$sn = new Status_network();
$sn->find();
while ($sn->fetch()) {
$hosts[] = $sn->getServerName();
}
return $hosts;
}
/**
* Instantiate an i/o manager class for the current site.
* If a multi-site capable handler is already present,
* we don't need to build a new one.
*
* @param string $class
* @param mixed $manager class name (to run $class::get()) or object
*/
protected function instantiate($class)
protected function instantiate($manager)
{
if (is_string($class) && isset($this->singletons[$class])) {
// Already instantiated a multi-site-capable handler.
// Just let it know it should listen to this site too!
$this->singletons[$class]->addSite(common_config('site', 'server'));
return;
if (is_string($manager)) {
$manager = call_user_func(array($class, 'get'));
}
$manager = $this->getManager($class);
if ($this->multiSite) {
$caps = $manager->multiSite();
if ($caps == IoManager::SINGLE_ONLY) {
$caps = $manager->multiSite();
if ($caps == IoManager::SINGLE_ONLY) {
if ($this->multiSite) {
throw new Exception("$class can't run with --all; aborting.");
}
if ($caps == IoManager::INSTANCE_PER_PROCESS) {
// Save this guy for later!
// We'll only need the one to cover multiple sites.
$this->singletons[$class] = $manager;
$manager->addSite(common_config('site', 'server'));
}
} else if ($caps == IoManager::INSTANCE_PER_PROCESS) {
$manager->addSite();
}
$this->managers[] = $manager;
}
protected function getManager($class)
{
if(is_object($class)){
return $class;
} else {
return call_user_func(array($class, 'get'));
if (!in_array($manager, $this->managers, true)) {
// Only need to save singletons once
$this->managers[] = $manager;
}
}
@ -150,6 +118,7 @@ abstract class IoMaster
{
$this->logState('init');
$this->start();
$this->checkMemory(false);
while (!$this->shutdown) {
$timeouts = array_values($this->pollTimeouts);
@ -213,17 +182,24 @@ abstract class IoMaster
/**
* Check runtime memory usage, possibly triggering a graceful shutdown
* and thread respawn if we've crossed the soft limit.
*
* @param boolean $respawn if false we'll shut down instead of respawning
*/
protected function checkMemory()
protected function checkMemory($respawn=true)
{
$memoryLimit = $this->softMemoryLimit();
if ($memoryLimit > 0) {
$usage = memory_get_usage();
if ($usage > $memoryLimit) {
common_log(LOG_INFO, "Queue thread hit soft memory limit ($usage > $memoryLimit); gracefully restarting.");
$this->requestRestart();
if ($respawn) {
$this->requestRestart();
} else {
$this->requestShutdown();
}
} else if (common_config('queue', 'debug_memory')) {
common_log(LOG_DEBUG, "Memory usage $usage");
$fmt = number_format($usage);
common_log(LOG_DEBUG, "Memory usage $fmt");
}
}
}

View File

@ -294,6 +294,7 @@ class NoticeListItem extends Widget
}
$this->out->elementStart('a', $attrs);
$this->showAvatar();
$this->out->text(' ');
$this->showNickname();
$this->out->elementEnd('a');
$this->out->elementEnd('span');
@ -432,8 +433,10 @@ class NoticeListItem extends Widget
$url = $location->getUrl();
$this->out->text(' ');
$this->out->elementStart('span', array('class' => 'location'));
$this->out->text(_('at'));
$this->out->text(' ');
if (empty($url)) {
$this->out->element('span', array('class' => 'geo',
'title' => $latlon),
@ -473,9 +476,11 @@ class NoticeListItem extends Widget
function showNoticeSource()
{
if ($this->notice->source) {
$this->out->text(' ');
$this->out->elementStart('span', 'source');
$this->out->text(_('from'));
$source_name = _($this->notice->source);
$this->out->text(' ');
switch ($this->notice->source) {
case 'web':
case 'xmpp':
@ -540,6 +545,7 @@ class NoticeListItem extends Widget
}
}
if ($hasConversation){
$this->out->text(' ');
$convurl = common_local_url('conversation',
array('id' => $this->notice->conversation));
$this->out->element('a', array('href' => $convurl.'#notice-'.$this->notice->id,
@ -591,12 +597,14 @@ class NoticeListItem extends Widget
function showReplyLink()
{
if (common_logged_in()) {
$this->out->text(' ');
$reply_url = common_local_url('newnotice',
array('replyto' => $this->profile->nickname, 'inreplyto' => $this->notice->id));
$this->out->elementStart('a', array('href' => $reply_url,
'class' => 'notice_reply',
'title' => _('Reply to this notice')));
$this->out->text(_('Reply'));
$this->out->text(' ');
$this->out->element('span', 'notice_id', $this->notice->id);
$this->out->elementEnd('a');
}
@ -616,7 +624,7 @@ class NoticeListItem extends Widget
if (!empty($user) &&
($todel->profile_id == $user->id || $user->hasRight(Right::DELETEOTHERSNOTICE))) {
$this->out->text(' ');
$deleteurl = common_local_url('deletenotice',
array('notice' => $todel->id));
$this->out->element('a', array('href' => $deleteurl,
@ -635,6 +643,7 @@ class NoticeListItem extends Widget
{
$user = common_current_user();
if ($user && $user->id != $this->notice->profile_id) {
$this->out->text(' ');
$profile = $user->getProfile();
if ($profile->hasRepeated($this->notice->id)) {
$this->out->element('span', array('class' => 'repeated',

View File

@ -90,6 +90,7 @@ class NoticeSection extends Section
'alt' => ($profile->fullname) ?
$profile->fullname :
$profile->nickname));
$this->out->text(' ');
$this->out->element('span', 'fn nickname', $profile->nickname);
$this->out->elementEnd('a');
$this->out->elementEnd('span');

View File

@ -191,6 +191,7 @@ class ProfileListItem extends Widget
'alt' =>
($this->profile->fullname) ? $this->profile->fullname :
$this->profile->nickname));
$this->out->text(' ');
$hasFN = (!empty($this->profile->fullname)) ? 'nickname' : 'fn nickname';
$this->out->elementStart('span', $hasFN);
$this->out->raw($this->highlight($this->profile->nickname));
@ -201,6 +202,7 @@ class ProfileListItem extends Widget
function showFullName()
{
if (!empty($this->profile->fullname)) {
$this->out->text(' ');
$this->out->elementStart('span', 'fn');
$this->out->raw($this->highlight($this->profile->fullname));
$this->out->elementEnd('span');
@ -210,6 +212,7 @@ class ProfileListItem extends Widget
function showLocation()
{
if (!empty($this->profile->location)) {
$this->out->text(' ');
$this->out->elementStart('span', 'location');
$this->out->raw($this->highlight($this->profile->location));
$this->out->elementEnd('span');
@ -219,6 +222,7 @@ class ProfileListItem extends Widget
function showHomepage()
{
if (!empty($this->profile->homepage)) {
$this->out->text(' ');
$this->out->elementStart('a', array('href' => $this->profile->homepage,
'class' => 'url'));
$this->out->raw($this->highlight($this->profile->homepage));

View File

@ -85,6 +85,7 @@ class ProfileSection extends Section
'href' => $profile->profileurl,
'rel' => 'contact member',
'class' => 'url'));
$this->out->text(' ');
$avatar = $profile->getAvatar(AVATAR_MINI_SIZE);
$this->out->element('img', array('src' => (($avatar) ? $avatar->displayUrl() : Avatar::defaultImage(AVATAR_MINI_SIZE)),
'width' => AVATAR_MINI_SIZE,
@ -93,6 +94,7 @@ class ProfileSection extends Section
'alt' => ($profile->fullname) ?
$profile->fullname :
$profile->nickname));
$this->out->text(' ');
$this->out->element('span', 'fn nickname', $profile->nickname);
$this->out->elementEnd('a');
$this->out->elementEnd('span');

View File

@ -39,9 +39,10 @@ abstract class QueueManager extends IoManager
{
static $qm = null;
public $master = null;
public $handlers = array();
public $groups = array();
protected $master = null;
protected $handlers = array();
protected $groups = array();
protected $activeGroups = array();
/**
* Factory function to pull the appropriate QueueManager object
@ -162,7 +163,7 @@ abstract class QueueManager extends IoManager
*/
protected function encode($item)
{
return serialize($object);
return serialize($item);
}
/**
@ -192,40 +193,48 @@ abstract class QueueManager extends IoManager
} else if (class_exists($class)) {
return new $class();
} else {
common_log(LOG_ERR, "Nonexistent handler class '$class' for queue '$queue'");
$this->_log(LOG_ERR, "Nonexistent handler class '$class' for queue '$queue'");
}
} else {
common_log(LOG_ERR, "Requested handler for unkown queue '$queue'");
$this->_log(LOG_ERR, "Requested handler for unkown queue '$queue'");
}
return null;
}
/**
* Get a list of registered queue transport names to be used
* for this daemon.
* for listening in this daemon.
*
* @return array of strings
*/
function getQueues()
function activeQueues()
{
$group = $this->activeGroup();
return array_keys($this->groups[$group]);
$queues = array();
foreach ($this->activeGroups as $group) {
if (isset($this->groups[$group])) {
$queues = array_merge($queues, $this->groups[$group]);
}
}
return array_keys($queues);
}
/**
* Initialize the list of queue handlers
* Initialize the list of queue handlers for the current site.
*
* @event StartInitializeQueueManager
* @event EndInitializeQueueManager
*/
function initialize()
{
// @fixme we'll want to be able to listen to particular queues...
$this->handlers = array();
$this->groups = array();
$this->groupsByTransport = array();
if (Event::handle('StartInitializeQueueManager', array($this))) {
$this->connect('plugin', 'PluginQueueHandler');
$this->connect('distrib', 'DistribQueueHandler');
$this->connect('omb', 'OmbQueueHandler');
$this->connect('ping', 'PingQueueHandler');
$this->connect('distrib', 'DistribQueueHandler');
if (common_config('sms', 'enabled')) {
$this->connect('sms', 'SmsQueueHandler');
}
@ -244,25 +253,41 @@ abstract class QueueManager extends IoManager
* @param string $class class name or object instance
* @param string $group
*/
public function connect($transport, $class, $group='queuedaemon')
public function connect($transport, $class, $group='main')
{
$this->handlers[$transport] = $class;
$this->groups[$group][$transport] = $class;
$this->groupsByTransport[$transport] = $group;
}
/**
* @return string queue group to use for this request
* Set the active group which will be used for listening.
* @param string $group
*/
function activeGroup()
function setActiveGroup($group)
{
$group = 'queuedaemon';
if ($this->master) {
// hack hack
if ($this->master instanceof ImMaster) {
return 'imdaemon';
}
$this->activeGroups = array($group);
}
/**
* Set the active group(s) which will be used for listening.
* @param array $groups
*/
function setActiveGroups($groups)
{
$this->activeGroups = $groups;
}
/**
* @return string queue group for this queue
*/
function queueGroup($queue)
{
if (isset($this->groupsByTransport[$queue])) {
return $this->groupsByTransport[$queue];
} else {
throw new Exception("Requested group for unregistered transport $queue");
}
return $group;
}
/**
@ -286,4 +311,15 @@ abstract class QueueManager extends IoManager
$monitor->stats($key, $owners);
}
}
protected function _log($level, $msg)
{
$class = get_class($this);
if ($this->activeGroups) {
$groups = ' (' . implode(',', $this->activeGroups) . ')';
} else {
$groups = '';
}
common_log($level, "$class$groups: $msg");
}
}

View File

@ -90,18 +90,24 @@ abstract class SpawningDaemon extends Daemon
while (count($children) > 0) {
$status = null;
$pid = pcntl_wait($status);
if ($pid > 0 && pcntl_wifexited($status)) {
$exitCode = pcntl_wexitstatus($status);
if ($pid > 0) {
$i = array_search($pid, $children);
if ($i === false) {
$this->log(LOG_ERR, "Unrecognized child pid $pid exited with status $exitCode");
$this->log(LOG_ERR, "Ignoring exit of unrecognized child pid $pid");
continue;
}
if (pcntl_wifexited($status)) {
$exitCode = pcntl_wexitstatus($status);
$info = "status $exitCode";
} else if (pcntl_wifsignaled($status)) {
$exitCode = self::EXIT_ERR;
$signal = pcntl_wtermsig($status);
$info = "signal $signal";
}
unset($children[$i]);
if ($this->shouldRespawn($exitCode)) {
$this->log(LOG_INFO, "Thread $i pid $pid exited with status $exitCode; respawing.");
$this->log(LOG_INFO, "Thread $i pid $pid exited with $info; respawing.");
$pid = pcntl_fork();
if ($pid < 0) {

View File

@ -102,6 +102,60 @@ class StatusNet
self::initPlugins();
}
/**
* Get identifier of the currently active site configuration
* @return string
*/
public static function currentSite()
{
return common_config('site', 'nickname');
}
/**
* Change site configuration to site specified by nickname,
* if set up via Status_network. If not, sites other than
* the current will fail horribly.
*
* May throw exception or trigger a fatal error if the given
* site is missing or configured incorrectly.
*
* @param string $nickname
*/
public static function switchSite($nickname)
{
if ($nickname == StatusNet::currentSite()) {
return true;
}
$sn = Status_network::staticGet($nickname);
if (empty($sn)) {
return false;
throw new Exception("No such site nickname '$nickname'");
}
$server = $sn->getServerName();
StatusNet::init($server);
}
/**
* Pull all local sites from status_network table.
*
* Behavior undefined if site is not configured via Status_network.
*
* @return array of nicknames
*/
public static function findAllSites()
{
$sites = array();
$sn = new Status_network();
$sn->find();
while ($sn->fetch()) {
$sites[] = $sn->nickname;
}
return $sites;
}
/**
* Fire initialization events for all instantiated plugins.
*/

View File

@ -63,6 +63,7 @@ class StompQueueManager extends QueueManager
$this->password = common_config('queue', 'stomp_password');
$this->base = common_config('queue', 'queue_basename');
$this->control = common_config('queue', 'control_channel');
$this->subscriptions = array($this->control => $this->control);
}
/**
@ -75,17 +76,25 @@ class StompQueueManager extends QueueManager
}
/**
* Record each site we'll be handling input for in this process,
* so we can listen to the necessary queues for it.
*
* @fixme possibly actually do subscription here to save another
* loop over all sites later?
* @fixme possibly don't assume it's the current site
* Record queue subscriptions we'll need to handle the current site.
*/
public function addSite($server)
public function addSite()
{
$this->sites[] = $server;
$this->sites[] = StatusNet::currentSite();
// Set up handlers active for this site...
$this->initialize();
foreach ($this->activeGroups as $group) {
if (isset($this->groups[$group])) {
// Actual queues may be broken out or consolidated...
// Subscribe to all the target queues we'll need.
foreach ($this->groups[$group] as $transport => $class) {
$target = $this->queueName($transport);
$this->subscriptions[$target] = $target;
}
}
}
}
/**
@ -121,59 +130,11 @@ class StompQueueManager extends QueueManager
}
/**
* Instantiate the appropriate QueueHandler class for the given queue.
* Saves an object into the queue item table.
*
* @param mixed $object
* @param string $queue
* @return mixed QueueHandler or null
*/
function getHandler($queue)
{
$handlers = $this->handlers[$this->currentSite()];
if (isset($handlers[$queue])) {
$class = $handlers[$queue];
if (class_exists($class)) {
return new $class();
} else {
common_log(LOG_ERR, "Nonexistent handler class '$class' for queue '$queue'");
}
} else {
common_log(LOG_ERR, "Requested handler for unkown queue '$queue'");
}
return null;
}
/**
* Get a list of all registered queue transport names.
*
* @return array of strings
*/
function getQueues()
{
$group = $this->activeGroup();
$site = $this->currentSite();
if (empty($this->groups[$site][$group])) {
return array();
} else {
return array_keys($this->groups[$site][$group]);
}
}
/**
* Register a queue transport name and handler class for your plugin.
* Only registered transports will be reliably picked up!
*
* @param string $transport
* @param string $class
* @param string $group
*/
public function connect($transport, $class, $group='queuedaemon')
{
$this->handlers[$this->currentSite()][$transport] = $class;
$this->groups[$this->currentSite()][$group][$transport] = $class;
}
/**
* Saves a notice object reference into the queue item table.
* @return boolean true on success
* @throws StompException on connection or send error
*/
@ -192,8 +153,11 @@ class StompQueueManager extends QueueManager
*/
protected function _doEnqueue($object, $queue, $idx)
{
$msg = $this->encode($object);
$rep = $this->logrep($object);
$envelope = array('site' => common_config('site', 'nickname'),
'handler' => $queue,
'payload' => $this->encode($object));
$msg = serialize($envelope);
$props = array('created' => common_sql_now());
if ($this->isPersistent($queue)) {
@ -205,11 +169,11 @@ class StompQueueManager extends QueueManager
$result = $con->send($this->queueName($queue), $msg, $props);
if (!$result) {
common_log(LOG_ERR, "Error sending $rep to $queue queue on $host");
$this->_log(LOG_ERR, "Error sending $rep to $queue queue on $host");
return false;
}
common_log(LOG_DEBUG, "complete remote queueing $rep for $queue on $host");
$this->_log(LOG_DEBUG, "complete remote queueing $rep for $queue on $host");
$this->stats('enqueued', $queue);
return true;
}
@ -275,12 +239,14 @@ class StompQueueManager extends QueueManager
$idx = $this->connectionFromSocket($socket);
$con = $this->cons[$idx];
$host = $con->getServer();
$this->defaultIdx = $idx;
$ok = true;
try {
$frames = $con->readFrames();
} catch (StompException $e) {
common_log(LOG_ERR, "Lost connection to $host: " . $e->getMessage());
$this->_log(LOG_ERR, "Lost connection to $host: " . $e->getMessage());
fclose($socket); // ???
$this->cons[$idx] = null;
$this->transaction[$idx] = null;
$this->disconnect[$idx] = time();
@ -289,14 +255,17 @@ class StompQueueManager extends QueueManager
foreach ($frames as $frame) {
$dest = $frame->headers['destination'];
if ($dest == $this->control) {
if (!$this->handleControlSignal($idx, $frame)) {
if (!$this->handleControlSignal($frame)) {
// We got a control event that requests a shutdown;
// close out and stop handling anything else!
break;
}
} else {
$ok = $ok && $this->handleItem($idx, $frame);
$ok = $this->handleItem($frame) && $ok;
}
$this->ack($idx, $frame);
$this->commit($idx);
$this->begin($idx);
}
return $ok;
}
@ -333,22 +302,9 @@ class StompQueueManager extends QueueManager
parent::start($master);
$this->_connectAll();
common_log(LOG_INFO, "Subscribing to $this->control");
foreach ($this->cons as $con) {
if ($con) {
$con->subscribe($this->control);
}
}
if ($this->sites) {
foreach ($this->sites as $server) {
StatusNet::init($server);
$this->doSubscribe();
}
} else {
$this->doSubscribe();
}
foreach ($this->cons as $i => $con) {
if ($con) {
$this->doSubscribe($con);
$this->begin($i);
}
}
@ -356,9 +312,7 @@ class StompQueueManager extends QueueManager
}
/**
* Subscribe to all the queues we're going to need to handle...
*
* Side effects: in multi-site mode, may reset site configuration.
* Close out any active connections.
*
* @return bool return false on failure
*/
@ -376,15 +330,6 @@ class StompQueueManager extends QueueManager
return true;
}
/**
* Get identifier of the currently active site configuration
* @return string
*/
protected function currentSite()
{
return common_config('site', 'server'); // @fixme switch to nickname
}
/**
* Lazy open a single connection to Stomp queue server.
* If multiple servers are configured, we let the Stomp client library
@ -441,6 +386,10 @@ class StompQueueManager extends QueueManager
}
}
/**
* Attempt to manually reconnect to the Stomp server for the given
* slot. If successful, set up our subscriptions on it.
*/
protected function _reconnect($idx)
{
try {
@ -453,17 +402,7 @@ class StompQueueManager extends QueueManager
$this->cons[$idx] = $con;
$this->disconnect[$idx] = null;
// now we have to listen to everything...
// @fixme refactor this nicer. :P
$host = $con->getServer();
$this->_log(LOG_INFO, "Resubscribing to $this->control on $host");
$con->subscribe($this->control);
foreach ($this->subscriptions as $site => $queues) {
foreach ($queues as $queue) {
$this->_log(LOG_INFO, "Resubscribing to $queue on $host");
$con->subscribe($queue);
}
}
$this->doSubscribe($con);
$this->begin($idx);
} else {
// Try again later...
@ -487,41 +426,15 @@ class StompQueueManager extends QueueManager
}
/**
* Subscribe to all enabled notice queues for the current site.
* Set up all our raw queue subscriptions on the given connection
* @param LiberalStomp $con
*/
protected function doSubscribe()
protected function doSubscribe(LiberalStomp $con)
{
$site = $this->currentSite();
$this->_connect();
foreach ($this->getQueues() as $queue) {
$rawqueue = $this->queueName($queue);
$this->subscriptions[$site][$queue] = $rawqueue;
$this->_log(LOG_INFO, "Subscribing to $rawqueue");
foreach ($this->cons as $con) {
if ($con) {
$con->subscribe($rawqueue);
}
}
}
}
/**
* Subscribe from all enabled notice queues for the current site.
*/
protected function doUnsubscribe()
{
$site = $this->currentSite();
$this->_connect();
if (!empty($this->subscriptions[$site])) {
foreach ($this->subscriptions[$site] as $queue => $rawqueue) {
$this->_log(LOG_INFO, "Unsubscribing from $rawqueue");
foreach ($this->cons as $con) {
if ($con) {
$con->unsubscribe($rawqueue);
}
}
unset($this->subscriptions[$site][$queue]);
}
$host = $con->getServer();
foreach ($this->subscriptions as $queue) {
$this->_log(LOG_INFO, "Subscribing to $queue on $host");
$con->subscribe($queue);
}
}
@ -534,25 +447,29 @@ class StompQueueManager extends QueueManager
* Side effects: in multi-site mode, may reset site configuration to
* match the site that queued the event.
*
* @param int $idx connection index
* @param StompFrame $frame
* @return bool
* @return bool success
*/
protected function handleItem($idx, $frame)
protected function handleItem($frame)
{
$this->defaultIdx = $idx;
$host = $this->cons[$this->defaultIdx]->getServer();
$message = unserialize($frame->body);
$site = $message['site'];
$queue = $message['handler'];
list($site, $queue) = $this->parseDestination($frame->headers['destination']);
if ($site != $this->currentSite()) {
$this->stats('switch');
StatusNet::init($site);
if ($this->isDeadletter($frame, $message)) {
$this->stats('deadletter', $queue);
return false;
}
$host = $this->cons[$idx]->getServer();
$item = $this->decode($frame->body);
// @fixme detect failing site switches
$this->switchSite($site);
$item = $this->decode($message['payload']);
if (empty($item)) {
$this->_log(LOG_ERR, "Skipping empty or deleted item in queue $queue from $host");
return true;
$this->stats('baditem', $queue);
return false;
}
$info = $this->logrep($item) . " posted at " .
$frame->headers['created'] . " in queue $queue from $host";
@ -561,16 +478,10 @@ class StompQueueManager extends QueueManager
$handler = $this->getHandler($queue);
if (!$handler) {
$this->_log(LOG_ERR, "Missing handler class; skipping $info");
$this->ack($idx, $frame);
$this->commit($idx);
$this->begin($idx);
$this->stats('badhandler', $queue);
return false;
}
// If there's an exception when handling,
// log the error and let it get requeued.
try {
$ok = $handler->handle($item);
} catch (Exception $e) {
@ -578,25 +489,80 @@ class StompQueueManager extends QueueManager
$ok = false;
}
if (!$ok) {
if ($ok) {
$this->_log(LOG_INFO, "Successfully handled $info");
$this->stats('handled', $queue);
} else {
$this->_log(LOG_WARNING, "Failed handling $info");
// FIXME we probably shouldn't have to do
// this kind of queue management ourselves;
// if we don't ack, it should resend...
$this->ack($idx, $frame);
// Requeing moves the item to the end of the line for its next try.
// @fixme add a manual retry count
$this->enqueue($item, $queue);
$this->commit($idx);
$this->begin($idx);
$this->stats('requeued', $queue);
return false;
}
$this->_log(LOG_INFO, "Successfully handled $info");
$this->ack($idx, $frame);
$this->commit($idx);
$this->begin($idx);
$this->stats('handled', $queue);
return true;
return $ok;
}
/**
* Check if a redelivered message has been run through enough
* that we're going to give up on it.
*
* @param StompFrame $frame
* @param array $message unserialized message body
* @return boolean true if we should discard
*/
protected function isDeadLetter($frame, $message)
{
if (isset($frame->headers['redelivered']) && $frame->headers['redelivered'] == 'true') {
// Message was redelivered, possibly indicating a previous failure.
$msgId = $frame->headers['message-id'];
$site = $message['site'];
$queue = $message['handler'];
$msgInfo = "message $msgId for $site in queue $queue";
$deliveries = $this->incDeliveryCount($msgId);
if ($deliveries > common_config('queue', 'max_retries')) {
$info = "DEAD-LETTER FILE: Gave up after retry $deliveries on $msgInfo";
$outdir = common_config('queue', 'dead_letter_dir');
if ($outdir) {
$filename = $outdir . "/$site-$queue-" . rawurlencode($msgId);
$info .= ": dumping to $filename";
file_put_contents($filename, $message['payload']);
}
common_log(LOG_ERR, $info);
return true;
} else {
common_log(LOG_INFO, "retry $deliveries on $msgInfo");
}
}
return false;
}
/**
* Update count of times we've re-encountered this message recently,
* triggered when we get a message marked as 'redelivered'.
*
* Requires a CLI-friendly cache configuration.
*
* @param string $msgId message-id header from message
* @return int number of retries recorded
*/
function incDeliveryCount($msgId)
{
$count = 0;
$cache = common_memcache();
if ($cache) {
$key = 'statusnet:stomp:message-retries:' . $msgId;
$count = $cache->increment($key);
if (!$count) {
$count = 1;
$cache->set($key, $count, null, 3600);
$got = $cache->get($key);
}
}
return $count;
}
/**
@ -629,13 +595,22 @@ class StompQueueManager extends QueueManager
} else {
$this->_log(LOG_ERR, "Ignoring unrecognized control message: $message");
}
$this->ack($idx, $frame);
$this->commit($idx);
$this->begin($idx);
return $shutdown;
}
/**
* Switch site, if necessary, and reset current handler assignments
* @param string $site
*/
function switchSite($site)
{
if ($site != StatusNet::currentSite()) {
$this->stats('switch');
StatusNet::switchSite($site);
$this->initialize();
}
}
/**
* Set us up with queue subscriptions for a new site added at runtime,
* triggered by a broadcast to the 'statusnet-control' topic.
@ -648,22 +623,17 @@ class StompQueueManager extends QueueManager
if (empty($this->sites)) {
if ($nickname == common_config('site', 'nickname')) {
StatusNet::init(common_config('site', 'server'));
$this->doUnsubscribe();
$this->doSubscribe();
} else {
$this->_log(LOG_INFO, "Ignoring update ping for other site $nickname");
}
} else {
$sn = Status_network::staticGet($nickname);
if ($sn) {
$server = $sn->getServerName(); // @fixme do config-by-nick
StatusNet::init($server);
if (empty($this->sites[$server])) {
$this->addSite($server);
$this->switchSite($nickname);
if (!in_array($nickname, $this->sites)) {
$this->addSite();
}
$this->_log(LOG_INFO, "(Re)subscribing to queues for site $nickname / $server");
$this->doUnsubscribe();
$this->doSubscribe();
// @fixme update subscriptions, if applicable
$this->stats('siteupdate');
} else {
$this->_log(LOG_ERR, "Ignoring ping for unrecognized new site $nickname");
@ -673,42 +643,47 @@ class StompQueueManager extends QueueManager
/**
* Combines the queue_basename from configuration with the
* site server name and queue name to give eg:
* group name for this queue to give eg:
*
* /queue/statusnet/identi.ca/sms
* /queue/statusnet/main
*
* @param string $queue
* @return string
*/
protected function queueName($queue)
{
return common_config('queue', 'queue_basename') .
$this->currentSite() . '/' . $queue;
$base = common_config('queue', 'queue_basename');
$group = $this->queueGroup($queue);
$breakout = $this->breakoutMode($queue);
if ($breakout == 'shared') {
return $base . "$group";
} else if ($breakout == 'handler') {
return $base . "$group/$queue";
} else if ($breakout == 'site') {
$site = StatusNet::currentSite();
return $base . "$group/$queue/$site";
}
throw Exception("Unrecognized queue breakout mode '$breakout' for '$queue'");
}
/**
* Returns the site and queue name from the server-side queue.
* Get the breakout mode for the given queue on the current site.
*
* @param string queue destination (eg '/queue/statusnet/identi.ca/sms')
* @return array of site and queue: ('identi.ca','sms') or false if unrecognized
* @param string $queue
* @return string one of 'shared', 'handler', 'site'
*/
protected function parseDestination($dest)
protected function breakoutMode($queue)
{
$prefix = common_config('queue', 'queue_basename');
if (substr($dest, 0, strlen($prefix)) == $prefix) {
$rest = substr($dest, strlen($prefix));
return explode("/", $rest, 2);
$breakout = common_config('queue', 'breakout');
if (isset($breakout[$queue])) {
return $breakout[$queue];
} else if (isset($breakout['*'])) {
return $breakout['*'];
} else {
common_log(LOG_ERR, "Got a message from unrecognized stomp queue: $dest");
return array(false, false);
return 'shared';
}
}
function _log($level, $msg)
{
common_log($level, 'StompQueueManager: '.$msg);
}
protected function begin($idx)
{
if ($this->useTransactions) {

View File

@ -110,9 +110,20 @@ class Theme
$server = common_config('site', 'server');
}
// XXX: protocol
$ssl = common_config('theme', 'ssl');
$this->path = 'http://'.$server.$path.$name;
if (is_null($ssl)) { // null -> guess
if (common_config('site', 'ssl') == 'always' &&
!common_config('theme', 'server')) {
$ssl = true;
} else {
$ssl = false;
}
}
$protocol = ($ssl) ? 'https' : 'http';
$this->path = $protocol . '://'.$server.$path.$name;
}
}

View File

@ -238,9 +238,12 @@ class UserProfile extends Widget
if (Event::handle('StartProfilePageActionsElements', array(&$this->out, $this->profile))) {
if (empty($cur)) { // not logged in
$this->out->elementStart('li', 'entity_subscribe');
$this->showRemoteSubscribeLink();
$this->out->elementEnd('li');
if (Event::handle('StartProfileRemoteSubscribe', array(&$this->out, $this->profile))) {
$this->out->elementStart('li', 'entity_subscribe');
$this->showRemoteSubscribeLink();
$this->out->elementEnd('li');
Event::handle('EndProfileRemoteSubscribe', array(&$this->out, $this->profile));
}
} else {
if ($cur->id == $this->profile->id) { // your own page
$this->out->elementStart('li', 'entity_edit');

View File

@ -1000,7 +1000,6 @@ function common_enqueue_notice($notice)
if (Event::hasHandler('HandleQueuedNotice')) {
$transports[] = 'plugin';
}
// @fixme move these checks into QueueManager and/or individual handlers
if ($notice->is_local == Notice::LOCAL_PUBLIC ||
@ -1558,3 +1557,56 @@ function common_client_ip()
return array($proxy, $ip);
}
function common_url_to_nickname($url)
{
static $bad = array('query', 'user', 'password', 'port', 'fragment');
$parts = parse_url($url);
# If any of these parts exist, this won't work
foreach ($bad as $badpart) {
if (array_key_exists($badpart, $parts)) {
return null;
}
}
# We just have host and/or path
# If it's just a host...
if (array_key_exists('host', $parts) &&
(!array_key_exists('path', $parts) || strcmp($parts['path'], '/') == 0))
{
$hostparts = explode('.', $parts['host']);
# Try to catch common idiom of nickname.service.tld
if ((count($hostparts) > 2) &&
(strlen($hostparts[count($hostparts) - 2]) > 3) && # try to skip .co.uk, .com.au
(strcmp($hostparts[0], 'www') != 0))
{
return common_nicknamize($hostparts[0]);
} else {
# Do the whole hostname
return common_nicknamize($parts['host']);
}
} else {
if (array_key_exists('path', $parts)) {
# Strip starting, ending slashes
$path = preg_replace('@/$@', '', $parts['path']);
$path = preg_replace('@^/@', '', $path);
if (strpos($path, '/') === false) {
return common_nicknamize($path);
}
}
}
return null;
}
function common_nicknamize($str)
{
$str = preg_replace('/\W/', '', $str);
return strtolower($str);
}

View File

@ -51,6 +51,8 @@ if (!defined('STATUSNET')) {
class MemcachePlugin extends Plugin
{
static $cacheInitialized = false;
private $_conn = null;
public $servers = array('127.0.0.1;11211');
@ -71,10 +73,21 @@ class MemcachePlugin extends Plugin
function onInitializePlugin()
{
if (is_null($this->persistent)) {
if (self::$cacheInitialized) {
$this->persistent = true;
} else {
// If we're a parent command-line process we need
// to be able to close out the connection after
// forking, so disable persistence.
//
// We'll turn it back on again the second time
// through which will either be in a child process,
// or a single-process script which is switching
// configurations.
$this->persistent = (php_sapi_name() == 'cli') ? false : true;
}
$this->_ensureConn();
self::$cacheInitialized = true;
return true;
}
@ -121,6 +134,24 @@ class MemcachePlugin extends Plugin
return false;
}
/**
* Atomically increment an existing numeric key value.
* Existing expiration time will not be changed.
*
* @param string &$key in; Key to use for lookups
* @param int &$step in; Amount to increment (default 1)
* @param mixed &$value out; Incremented value, or false if key not set.
*
* @return boolean hook success
*/
function onStartCacheIncrement(&$key, &$step, &$value)
{
$this->_ensureConn();
$value = $this->_conn->increment($key, $step);
Event::handle('EndCacheIncrement', array($key, $step, $value));
return false;
}
/**
* Delete a value associated with a key
*

View File

@ -63,9 +63,9 @@ class OStatusPlugin extends Plugin
$m->connect('main/ostatus?nickname=:nickname',
array('action' => 'ostatusinit'), array('nickname' => '[A-Za-z0-9_-]+'));
$m->connect('main/ostatussub',
array('action' => 'ostatussub'));
array('action' => 'ostatussub'));
$m->connect('main/ostatussub',
array('action' => 'ostatussub'), array('feed' => '[A-Za-z0-9\.\/\:]+'));
array('action' => 'ostatussub'), array('feed' => '[A-Za-z0-9\.\/\:]+'));
// PuSH actions
$m->connect('main/push/hub', array('action' => 'pushhub'));
@ -112,35 +112,34 @@ class OStatusPlugin extends Plugin
* Set up a PuSH hub link to our internal link for canonical timeline
* Atom feeds for users and groups.
*/
function onStartApiAtom(Action $action)
function onStartApiAtom(AtomNoticeFeed $feed)
{
if ($action instanceof ApiTimelineUserAction) {
$id = null;
if ($feed instanceof AtomUserNoticeFeed) {
$salmonAction = 'salmon';
} else if ($action instanceof ApiTimelineGroupAction) {
$id = $feed->getUser()->id;
} else if ($feed instanceof AtomGroupNoticeFeed) {
$salmonAction = 'salmongroup';
$id = $feed->getGroup()->id;
} else {
return;
}
$id = $action->arg('id');
if (strval(intval($id)) === strval($id)) {
// Canonical form of id in URL? These are used for OStatus syndication.
if (!empty($id)) {
$hub = common_config('ostatus', 'hub');
if (empty($hub)) {
// Updates will be handled through our internal PuSH hub.
$hub = common_local_url('pushhub');
}
$action->element('link', array('rel' => 'hub',
'href' => $hub));
$feed->addLink($hub, array('rel' => 'hub'));
// Also, we'll add in the salmon link
$salmon = common_local_url($salmonAction, array('id' => $id));
$action->element('link', array('rel' => 'salmon',
'href' => $salmon));
$feed->addLink($salmon, array('rel' => 'salmon'));
}
}
/**
* Add the feed settings page to the Connect Settings menu
*
@ -189,7 +188,7 @@ class OStatusPlugin extends Plugin
/**
* Add in an OStatus subscribe button
*/
function onStartProfilePageActionsElements($output, $profile)
function onStartProfileRemoteSubscribe($output, $profile)
{
$cur = common_current_user();
@ -200,10 +199,12 @@ class OStatusPlugin extends Plugin
array('nickname' => $profile->nickname));
$output->element('a', array('href' => $url,
'class' => 'entity_remote_subscribe'),
_m('OStatus'));
_m('Subscribe'));
$output->elementEnd('li');
}
return false;
}
/**
@ -217,29 +218,34 @@ class OStatusPlugin extends Plugin
$count = preg_match_all('/(\w+\.)*\w+@(\w+\.)*\w+(\w+\-\w+)*\.\w+/', $notice->content, $matches);
if ($count) {
foreach ($matches[0] as $webfinger) {
// FIXME: look up locally first
// Check to see if we've got an actual webfinger
$w = new Webfinger;
$endpoint_uri = '';
$result = $w->lookup($webfinger);
if (empty($result)) {
continue;
}
foreach ($result->links as $link) {
if ($link['rel'] == 'salmon') {
$endpoint_uri = $link['href'];
}
}
if (empty($endpoint_uri)) {
continue;
}
// FIXME: this needs to go out in a queue handler
$xml = '<?xml version="1.0" encoding="UTF-8" ?>';
$xml .= $notice->asAtomEntry();
$salmon = new Salmon();
$salmon->post($endpoint_uri, $xml);
}
@ -273,4 +279,14 @@ class OStatusPlugin extends Plugin
$schema->ensureTable('hubsub', HubSub::schemaDef());
return true;
}
function onEndShowStatusNetStyles($action) {
$action->cssLink(common_path('plugins/OStatus/theme/base/css/ostatus.css'));
return true;
}
function onEndShowStatusNetScripts($action) {
$action->script(common_path('plugins/OStatus/js/ostatus.js'));
return true;
}
}

View File

@ -67,9 +67,21 @@ class OStatusInitAction extends Action
function showForm($err = null)
{
$this->err = $err;
$this->showPage();
$this->err = $err;
if ($this->boolean('ajax')) {
header('Content-Type: text/xml;charset=utf-8');
$this->xw->startDocument('1.0', 'UTF-8');
$this->elementStart('html');
$this->elementStart('head');
$this->element('title', null, _('Subscribe to user'));
$this->elementEnd('head');
$this->elementStart('body');
$this->showContent();
$this->elementEnd('body');
$this->elementEnd('html');
} else {
$this->showPage();
}
}
function showContent()
@ -79,15 +91,15 @@ class OStatusInitAction extends Action
'class' => 'form_settings',
'action' => common_local_url('ostatusinit')));
$this->elementStart('fieldset');
$this->element('legend', _('Subscribe to a remote user'));
$this->element('legend', null, sprintf(_('Subscribe to %s'), $this->nickname));
$this->hidden('token', common_session_token());
$this->elementStart('ul', 'form_data');
$this->elementStart('li');
$this->elementStart('li', array('id' => 'ostatus_nickname'));
$this->input('nickname', _('User nickname'), $this->nickname,
_('Nickname of the user you want to follow'));
$this->elementEnd('li');
$this->elementStart('li');
$this->elementStart('li', array('id' => 'ostatus_profile'));
$this->input('acct', _('Profile Account'), $this->acct,
_('Your account id (i.e. user@identi.ca)'));
$this->elementEnd('li');
@ -95,7 +107,7 @@ class OStatusInitAction extends Action
$this->submit('submit', _('Subscribe'));
$this->elementEnd('fieldset');
$this->elementEnd('form');
}
}
function ostatusConnect()
{
@ -125,4 +137,4 @@ class OStatusInitAction extends Action
return _('OStatus Connect');
}
}
}

View File

@ -76,7 +76,7 @@ class OStatusSubAction extends Action
$this->elementStart('fieldset', array('id' => 'settings_feeds'));
$this->elementStart('ul', 'form_data');
$this->elementStart('li', array('id' => 'settings_twitter_login_button'));
$this->elementStart('li');
$this->input('feedurl', _('Feed URL'), $this->feedurl, _('Enter the URL of a PubSubHubbub-enabled feed'));
$this->elementEnd('li');
$this->elementEnd('ul');
@ -223,4 +223,4 @@ class OStatusSubAction extends Action
}
}
}

View File

@ -61,7 +61,7 @@ class SalmonAction extends Action
// XXX: check that document element is Atom entry
// XXX: check the signature
$this->act = Activity::fromAtomEntry($dom->documentElement);
$this->act = new Activity($dom->documentElement);
}
function handle($args)

View File

@ -29,15 +29,15 @@ PuSH subscription flow:
generate random verification token
save to verify_token
sends a sub request to the hub...
main/push/callback
hub sends confirmation back to us via GET
We verify the request, then echo back the challenge.
On our end, we save the time we subscribed and the lease expiration
main/push/callback
hub sends us updates via POST
*/
class FeedDBException extends FeedSubException
@ -75,7 +75,6 @@ class Ostatus_profile extends Memcached_DataObject
public $created;
public $lastupdate;
public /*static*/ function staticGet($k, $v=null)
{
return parent::staticGet(__CLASS__, $k, $v);
@ -107,7 +106,7 @@ class Ostatus_profile extends Memcached_DataObject
'created' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL,
'lastupdate' => DB_DATAOBJECT_STR + DB_DATAOBJECT_DATE + DB_DATAOBJECT_TIME + DB_DATAOBJECT_NOTNULL);
}
static function schemaDef()
{
return array(new ColumnDef('id', 'integer',
@ -486,7 +485,7 @@ class Ostatus_profile extends Memcached_DataObject
}
if ($this->salmonuri) {
$text = 'update'; // @fixme
$id = 'tag:' . common_config('site', 'server') .
$id = 'tag:' . common_config('site', 'server') .
':' . $verb .
':' . $actor->id .
':' . time(); // @fixme
@ -589,7 +588,7 @@ class Ostatus_profile extends Memcached_DataObject
require_once "XML/Feed/Parser.php";
$feed = new XML_Feed_Parser($xml, false, false, true);
$munger = new FeedMunger($feed);
$hits = 0;
foreach ($feed as $index => $entry) {
// @fixme this might sort in wrong order if we get multiple updates
@ -598,9 +597,10 @@ class Ostatus_profile extends Memcached_DataObject
// Double-check for oldies
// @fixme this could explode horribly for multiple feeds on a blog. sigh
$dupe = new Notice();
$dupe->uri = $notice->uri;
if ($dupe->find(true)) {
$dupe = Notice::staticGet('uri', $notice->uri);
if (!empty($dupe)) {
common_log(LOG_WARNING, __METHOD__ . ": tried to save dupe notice for entry {$notice->uri} of feed {$this->feeduri}");
continue;
}

View File

@ -0,0 +1,60 @@
SN.U.DialogBox = {
Subscribe: function(a) {
var f = a.parent().find('#form_ostatus_connect');
if (f.length > 0) {
f.show();
}
else {
$.ajax({
type: 'GET',
dataType: 'xml',
url: a[0].href+'&ajax=1',
beforeSend: function(formData) {
a.addClass('processing');
},
error: function (xhr, textStatus, errorThrown) {
alert(errorThrown || textStatus);
},
success: function(data, textStatus, xhr) {
if (typeof($('form', data)[0]) != 'undefined') {
a.after(document._importNode($('form', data)[0], true));
var form = a.parent().find('#form_ostatus_connect');
form
.addClass('dialogbox')
.append('<button class="close">&#215;</button>');
form
.find('.submit')
.addClass('submit_dialogbox')
.removeClass('submit')
.bind('click', function() {
form.addClass('processing');
});
form.find('button.close').click(function(){
form.hide();
return false;
});
form.find('#acct').focus();
}
a.removeClass('processing');
}
});
}
}
};
SN.Init.Subscribe = function() {
$('.entity_subscribe a').live('click', function() { SN.U.DialogBox.Subscribe($(this)); return false; });
};
$(document).ready(function() {
if ($('.entity_subscribe .entity_remote_subscribe').length > 0) {
SN.Init.Subscribe();
}
});

View File

@ -31,7 +31,75 @@ if (!defined('STATUSNET')) {
exit(1);
}
class ActivityNoun
/**
* Utilities for turning DOMish things into Activityish things
*
* Some common functions that I didn't have the bandwidth to try to factor
* into some kind of reasonable superclass, so just dumped here. Might
* be useful to have an ActivityObject parent class or something.
*
* @category OStatus
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/
*/
class ActivityUtils
{
const ATOM = 'http://www.w3.org/2005/Atom';
const LINK = 'link';
const REL = 'rel';
const TYPE = 'type';
const HREF = 'href';
/**
* Get the permalink for an Activity object
*
* @param DOMElement $element A DOM element
*
* @return string related link, if any
*/
static function getLink($element)
{
$links = $element->getElementsByTagnameNS(self::ATOM, self::LINK);
foreach ($links as $link) {
$rel = $link->getAttribute(self::REL);
$type = $link->getAttribute(self::TYPE);
if ($rel == 'alternate' && $type == 'text/html') {
return $link->getAttribute(self::HREF);
}
}
return null;
}
}
/**
* A noun-ish thing in the activity universe
*
* The activity streams spec talks about activity objects, while also having
* a tag activity:object, which is in fact an activity object. Aaaaaah!
*
* This is just a thing in the activity universe. Can be the subject, object,
* or indirect object (target!) of an activity verb. Rotten name, and I'm
* propagating it. *sigh*
*
* @category OStatus
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/
*/
class ActivityObject
{
const ARTICLE = 'http://activitystrea.ms/schema/1.0/article';
const BLOGENTRY = 'http://activitystrea.ms/schema/1.0/blog-entry';
@ -47,19 +115,114 @@ class ActivityNoun
const PERSON = 'http://activitystrea.ms/schema/1.0/person';
const GROUP = 'http://activitystrea.ms/schema/1.0/group';
const PLACE = 'http://activitystrea.ms/schema/1.0/place';
const COMMENT = 'http://activitystrea.ms/schema/1.0/comment'; // tea
const COMMENT = 'http://activitystrea.ms/schema/1.0/comment';
// ^^^^^^^^^^ tea!
// Atom elements we snarf
const TITLE = 'title';
const SUMMARY = 'summary';
const CONTENT = 'content';
const ID = 'id';
const SOURCE = 'source';
const NAME = 'name';
const URI = 'uri';
const EMAIL = 'email';
public $type;
public $id;
public $title;
public $summary;
public $content;
public $link;
public $source;
/**
* Constructor
*
* This probably needs to be refactored
* to generate a local class (ActivityPerson, ActivityFile, ...)
* based on the object type.
*
* @param DOMElement $element DOM thing to turn into an Activity thing
*/
function __construct($element)
{
$this->source = $element;
if ($element->tagName == 'author') {
$this->type = self::PERSON; // XXX: is this fair?
$this->title = $this->_childContent($element, self::NAME);
$this->id = $this->_childContent($element, self::URI);
if (empty($this->id)) {
$email = $this->_childContent($element, self::EMAIL);
if (!empty($email)) {
// XXX: acct: ?
$this->id = 'mailto:'.$email;
}
}
} else {
$this->type = $this->_childContent($element, Activity::OBJECTTYPE,
Activity::SPEC);
if (empty($this->type)) {
$this->type = ActivityObject::NOTE;
}
$this->id = $this->_childContent($element, self::ID);
$this->title = $this->_childContent($element, self::TITLE);
$this->summary = $this->_childContent($element, self::SUMMARY);
$this->content = $this->_childContent($element, self::CONTENT);
$this->source = $this->_childContent($element, self::SOURCE);
$this->link = ActivityUtils::getLink($element);
// XXX: grab PoCo stuff
}
}
/**
* Grab the text content of a DOM element child of the current element
*
* @param DOMElement $element Element whose children we examine
* @param string $tag Tag to look up
* @param string $namespace Namespace to use, defaults to Atom
*
* @return string content of the child
*/
private function _childContent($element, $tag, $namespace=Activity::ATOM)
{
$els = $element->getElementsByTagnameNS($namespace, $tag);
if (empty($els) || $els->length == 0) {
return null;
} else {
$el = $els->item(0);
return $el->textContent;
}
}
}
class Activity
{
const NAMESPACE = 'http://activitystrea.ms/schema/1.0/';
/**
* Utility class to hold a bunch of constant defining default verb types
*
* @category OStatus
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/
*/
class ActivityVerb
{
const POST = 'http://activitystrea.ms/schema/1.0/post';
const SHARE = 'http://activitystrea.ms/schema/1.0/share';
const SAVE = 'http://activitystrea.ms/schema/1.0/save';
@ -69,17 +232,162 @@ class Activity
const FRIEND = 'http://activitystrea.ms/schema/1.0/make-friend';
const JOIN = 'http://activitystrea.ms/schema/1.0/join';
const TAG = 'http://activitystrea.ms/schema/1.0/tag';
}
public $actor; // an ActivityNoun
public $verb; // a string (the URL)
public $object; // an ActivityNoun
public $target; // an ActivityNoun
/**
* An activity in the ActivityStrea.ms world
*
* An activity is kind of like a sentence: someone did something
* to something else.
*
* 'someone' is the 'actor'; 'did something' is the verb;
* 'something else' is the object.
*
* @category OStatus
* @package StatusNet
* @author Evan Prodromou <evan@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPLv3
* @link http://status.net/
*/
static function fromAtomEntry($domEntry)
class Activity
{
const SPEC = 'http://activitystrea.ms/spec/1.0/';
const SCHEMA = 'http://activitystrea.ms/schema/1.0/';
const VERB = 'verb';
const OBJECT = 'object';
const ACTOR = 'actor';
const SUBJECT = 'subject';
const OBJECTTYPE = 'object-type';
const CONTEXT = 'context';
const TARGET = 'target';
const ATOM = 'http://www.w3.org/2005/Atom';
const AUTHOR = 'author';
const PUBLISHED = 'published';
const UPDATED = 'updated';
public $actor; // an ActivityObject
public $verb; // a string (the URL)
public $object; // an ActivityObject
public $target; // an ActivityObject
public $context; // an ActivityObject
public $time; // Time of the activity
public $link; // an ActivityObject
public $entry; // the source entry
public $feed; // the source feed
/**
* Turns a regular old Atom <entry> into a magical activity
*
* @param DOMElement $entry Atom entry to poke at
* @param DOMElement $feed Atom feed, for context
*/
function __construct($entry, $feed = null)
{
$this->entry = $entry;
$this->feed = $feed;
$pubEl = $this->_child($entry, self::PUBLISHED, self::ATOM);
if (!empty($pubEl)) {
$this->time = strtotime($pubEl->textContent);
} else {
// XXX technically an error; being liberal. Good idea...?
$updateEl = $this->_child($entry, self::UPDATED, self::ATOM);
if (!empty($updateEl)) {
$this->time = strtotime($updateEl->textContent);
} else {
$this->time = null;
}
}
$this->link = ActivityUtils::getLink($entry);
$verbEl = $this->_child($entry, self::VERB);
if (!empty($verbEl)) {
$this->verb = trim($verbEl->textContent);
} else {
$this->verb = ActivityVerb::POST;
// XXX: do other implied stuff here
}
$objectEl = $this->_child($entry, self::OBJECT);
if (!empty($objectEl)) {
$this->object = new ActivityObject($objectEl);
} else {
$this->object = new ActivityObject($entry);
}
$actorEl = $this->_child($entry, self::ACTOR);
if (!empty($actorEl)) {
$this->actor = new ActivityObject($actorEl);
} else if (!empty($feed) &&
$subjectEl = $this->_child($feed, self::SUBJECT)) {
$this->actor = new ActivityObject($subjectEl);
} else if ($authorEl = $this->_child($entry, self::AUTHOR, self::ATOM)) {
$this->actor = new ActivityObject($authorEl);
} else if (!empty($feed) && $authorEl = $this->_child($feed, self::AUTHOR,
self::ATOM)) {
$this->actor = new ActivityObject($authorEl);
}
$contextEl = $this->_child($entry, self::CONTEXT);
if (!empty($contextEl)) {
$this->context = new ActivityObject($contextEl);
}
$targetEl = $this->_child($entry, self::TARGET);
if (!empty($targetEl)) {
$this->target = new ActivityObject($targetEl);
}
}
/**
* Returns an Atom <entry> based on this activity
*
* @return DOMElement Atom entry
*/
function toAtomEntry()
{
return null;
}
}
/**
* Gets the first child element with the given tag
*
* @param DOMElement $element element to pick at
* @param string $tag tag to look for
* @param string $namespace Namespace to look under
*
* @return DOMElement found element or null
*/
private function _child($element, $tag, $namespace=self::SPEC)
{
$els = $element->getElementsByTagnameNS($namespace, $tag);
if (empty($els) || $els->length == 0) {
return null;
} else {
return $els->item(0);
}
}
}

View File

@ -0,0 +1,147 @@
<?php
if (isset($_SERVER) && array_key_exists('REQUEST_METHOD', $_SERVER)) {
print "This script must be run from the command line\n";
exit();
}
// XXX: we should probably have some common source for this stuff
define('INSTALLDIR', realpath(dirname(__FILE__) . '/../../..'));
define('STATUSNET', true);
require_once INSTALLDIR . '/lib/common.php';
require_once INSTALLDIR . '/plugins/OStatus/lib/activity.php';
class ActivityParseTests extends PHPUnit_Framework_TestCase
{
public function testExample1()
{
global $_example1;
$dom = DOMDocument::loadXML($_example1);
$act = new Activity($dom->documentElement);
$this->assertFalse(empty($act));
$this->assertEquals($act->time, 1243860840);
$this->assertEquals($act->verb, ActivityVerb::POST);
}
public function testExample3()
{
global $_example3;
$dom = DOMDocument::loadXML($_example3);
$feed = $dom->documentElement;
$entries = $feed->getElementsByTagName('entry');
$entry = $entries->item(0);
$act = new Activity($entry, $feed);
$this->assertFalse(empty($act));
$this->assertEquals($act->time, 1071340202);
$this->assertEquals($act->link, 'http://example.org/2003/12/13/atom03.html');
$this->assertEquals($act->verb, ActivityVerb::POST);
$this->assertFalse(empty($act->actor));
$this->assertEquals($act->actor->type, ActivityObject::PERSON);
$this->assertEquals($act->actor->title, 'John Doe');
$this->assertEquals($act->actor->id, 'mailto:johndoe@example.com');
$this->assertFalse(empty($act->object));
$this->assertEquals($act->object->type, ActivityObject::NOTE);
$this->assertEquals($act->object->id, 'urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a');
$this->assertEquals($act->object->title, 'Atom-Powered Robots Run Amok');
$this->assertEquals($act->object->summary, 'Some text.');
$this->assertEquals($act->object->link, 'http://example.org/2003/12/13/atom03.html');
$this->assertTrue(empty($act->context));
$this->assertTrue(empty($act->target));
$this->assertEquals($act->entry, $entry);
$this->assertEquals($act->feed, $feed);
}
}
$_example1 = <<<EXAMPLE1
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:activity='http://activitystrea.ms/spec/1.0/'>
<id>tag:versioncentral.example.org,2009:/commit/1643245</id>
<published>2009-06-01T12:54:00Z</published>
<title>Geraldine committed a change to yate</title>
<content type="xhtml">Geraldine just committed a change to yate on VersionCentral</content>
<link rel="alternate" type="text/html"
href="http://versioncentral.example.org/geraldine/yate/commit/1643245" />
<activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
<activity:verb>http://versioncentral.example.org/activity/commit</activity:verb>
<activity:object>
<activity:object-type>http://versioncentral.example.org/activity/changeset</activity:object-type>
<id>tag:versioncentral.example.org,2009:/change/1643245</id>
<title>Punctuation Changeset</title>
<summary>Fixing punctuation because it makes it more readable.</summary>
<link rel="alternate" type="text/html" href="..." />
</activity:object>
</entry>
EXAMPLE1;
$_example2 = <<<EXAMPLE2
<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:activity='http://activitystrea.ms/spec/1.0/'>
<id>tag:photopanic.example.com,2008:activity01</id>
<title>Geraldine posted a Photo on PhotoPanic</title>
<published>2008-11-02T15:29:00Z</published>
<link rel="alternate" type="text/html" href="/geraldine/activities/1" />
<activity:verb>
http://activitystrea.ms/schema/1.0/post
</activity:verb>
<activity:object>
<id>tag:photopanic.example.com,2008:photo01</id>
<title>My Cat</title>
<published>2008-11-02T15:29:00Z</published>
<link rel="alternate" type="text/html" href="/geraldine/photos/1" />
<activity:object-type>
tag:atomactivity.example.com,2008:photo
</activity:object-type>
<source>
<title>Geraldine's Photos</title>
<link rel="self" type="application/atom+xml" href="/geraldine/photofeed.xml" />
<link rel="alternate" type="text/html" href="/geraldine/" />
</source>
</activity:object>
<content type="html">
&lt;p&gt;Geraldine posted a Photo on PhotoPanic&lt;/p&gt;
&lt;img src="/geraldine/photo1.jpg"&gt;
</content>
</entry>
EXAMPLE2;
$_example3 = <<<EXAMPLE3
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<subtitle>A subtitle.</subtitle>
<link href="http://example.org/feed/" rel="self" />
<link href="http://example.org/" />
<id>urn:uuid:60a76c80-d399-11d9-b91C-0003939e0af6</id>
<updated>2003-12-13T18:30:02Z</updated>
<author>
<name>John Doe</name>
<email>johndoe@example.com</email>
</author>
<entry>
<title>Atom-Powered Robots Run Amok</title>
<link href="http://example.org/2003/12/13/atom03" />
<link rel="alternate" type="text/html" href="http://example.org/2003/12/13/atom03.html"/>
<link rel="edit" href="http://example.org/2003/12/13/atom03/edit"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
</feed>
EXAMPLE3;

View File

@ -0,0 +1,30 @@
/** theme: base for OStatus
*
* @package StatusNet
* @author Sarven Capadisli <csarven@status.net>
* @copyright 2010 StatusNet, Inc.
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
* @link http://status.net/
*/
#form_ostatus_connect.dialogbox {
width:70%;
background-image:none;
}
#form_ostatus_connect.dialogbox .form_data label {
width:34%;
}
#form_ostatus_connect.dialogbox .form_data input {
width:57%;
}
#form_ostatus_connect.dialogbox .form_data .form_guide {
margin-left:36%;
}
#form_ostatus_connect.dialogbox #ostatus_nickname {
display:none;
}
#form_ostatus_connect.dialogbox .submit_dialogbox {
min-width:96px;
}

View File

@ -438,49 +438,7 @@ class FinishopenidloginAction extends Action
function urlToNickname($openid)
{
static $bad = array('query', 'user', 'password', 'port', 'fragment');
$parts = parse_url($openid);
# If any of these parts exist, this won't work
foreach ($bad as $badpart) {
if (array_key_exists($badpart, $parts)) {
return null;
}
}
# We just have host and/or path
# If it's just a host...
if (array_key_exists('host', $parts) &&
(!array_key_exists('path', $parts) || strcmp($parts['path'], '/') == 0))
{
$hostparts = explode('.', $parts['host']);
# Try to catch common idiom of nickname.service.tld
if ((count($hostparts) > 2) &&
(strlen($hostparts[count($hostparts) - 2]) > 3) && # try to skip .co.uk, .com.au
(strcmp($hostparts[0], 'www') != 0))
{
return $this->nicknamize($hostparts[0]);
} else {
# Do the whole hostname
return $this->nicknamize($parts['host']);
}
} else {
if (array_key_exists('path', $parts)) {
# Strip starting, ending slashes
$path = preg_replace('@/$@', '', $parts['path']);
$path = preg_replace('@^/@', '', $path);
if (strpos($path, '/') === false) {
return $this->nicknamize($path);
}
}
}
return null;
return common_url_to_nickname($openid);
}
function xriToNickname($xri)
@ -510,7 +468,6 @@ class FinishopenidloginAction extends Action
function nicknamize($str)
{
$str = preg_replace('/\W/', '', $str);
return strtolower($str);
return common_nicknamize($str);
}
}

View File

@ -45,6 +45,7 @@ class PoweredByStatusNetPlugin extends Plugin
{
function onEndAddressData($action)
{
$action->text(' ');
$action->elementStart('span', 'poweredby');
$action->raw(sprintf(_m('powered by %s'),
sprintf('<a href="http://status.net/">%s</a>',

View File

@ -20,13 +20,15 @@
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
$shortoptions = 'fi::';
$longoptions = array('id::', 'foreground');
$shortoptions = 'fi::a';
$longoptions = array('id::', 'foreground', 'all');
$helptext = <<<END_OF_IM_HELP
Daemon script for receiving new notices from IM users.
-i --id Identity (default none)
-a --all Handle XMPP for all local sites
(requires Stomp queue handler, status_network setup)
-f --foreground Stay in the foreground (default background)
END_OF_IM_HELP;
@ -35,13 +37,16 @@ require_once INSTALLDIR.'/scripts/commandline.inc';
class ImDaemon extends SpawningDaemon
{
function __construct($id=null, $daemonize=true, $threads=1)
protected $allsites = false;
function __construct($id=null, $daemonize=true, $threads=1, $allsites=false)
{
if ($threads != 1) {
// This should never happen. :)
throw new Exception("IMDaemon can must run single-threaded");
}
parent::__construct($id, $daemonize, $threads);
$this->allsites = $allsites;
}
function runThread()
@ -49,7 +54,7 @@ class ImDaemon extends SpawningDaemon
common_log(LOG_INFO, 'Waiting to listen to IM connections and queues');
$master = new ImMaster($this->get_id());
$master->init();
$master->init($this->allsites);
$master->service();
common_log(LOG_INFO, 'terminating normally');
@ -69,7 +74,9 @@ class ImMaster extends IoMaster
{
$classes = array();
if (Event::handle('StartImDaemonIoManagers', array(&$classes))) {
$classes[] = 'QueueManager';
$qm = QueueManager::get();
$qm->setActiveGroup('im');
$classes[] = $qm;
}
Event::handle('EndImDaemonIoManagers', array(&$classes));
foreach ($classes as $class) {
@ -87,7 +94,8 @@ if (have_option('i', 'id')) {
}
$foreground = have_option('f', 'foreground');
$all = have_option('a') || have_option('--all');
$daemon = new ImDaemon($id, !$foreground);
$daemon = new ImDaemon($id, !$foreground, 1, $all);
$daemon->runOnce();

View File

@ -74,8 +74,6 @@ require_once(INSTALLDIR.'/lib/daemon.php');
require_once(INSTALLDIR.'/classes/Queue_item.php');
require_once(INSTALLDIR.'/classes/Notice.php');
define('CLAIM_TIMEOUT', 1200);
/**
* Queue handling daemon...
*
@ -92,7 +90,7 @@ class QueueDaemon extends SpawningDaemon
function __construct($id=null, $daemonize=true, $threads=1, $allsites=false)
{
parent::__construct($id, $daemonize, $threads);
$this->all = $allsites;
$this->allsites = $allsites;
}
/**
@ -108,7 +106,7 @@ class QueueDaemon extends SpawningDaemon
$this->log(LOG_INFO, 'checking for queued notices');
$master = new QueueMaster($this->get_id());
$master->init($this->all);
$master->init($this->allsites);
try {
$master->service();
} catch (Exception $e) {
@ -133,14 +131,16 @@ class QueueMaster extends IoMaster
*/
function initManagers()
{
$classes = array();
if (Event::handle('StartQueueDaemonIoManagers', array(&$classes))) {
$classes[] = 'QueueManager';
$managers = array();
if (Event::handle('StartQueueDaemonIoManagers', array(&$managers))) {
$qm = QueueManager::get();
$qm->setActiveGroup('main');
$managers[] = $qm;
}
Event::handle('EndQueueDaemonIoManagers', array(&$classes));
Event::handle('EndQueueDaemonIoManagers', array(&$managers));
foreach ($classes as $class) {
$this->instantiate($class);
foreach ($managers as $manager) {
$this->instantiate($manager);
}
}
}

View File

@ -288,7 +288,7 @@ margin-left:18px;
}
#site_nav_global_primary li {
display:inline;
margin-left:11px;
margin-left:18px;
}
.system_notice dt {
@ -370,7 +370,7 @@ margin-bottom:11px;
#site_nav_global_secondary ul li {
display:inline;
margin-right:11px;
margin-right:18px;
}
#export_data li a {
padding-left:20px;
@ -383,15 +383,13 @@ padding-left:28px;
}
#export_data ul {
display:inline;
width:100%;
float:left;
}
#export_data li {
list-style-type:none;
display:inline;
margin-left:11px;
}
#export_data li:first-child {
margin-left:0;
float:left;
margin-right:11px;
}
#licenses {
@ -801,8 +799,8 @@ list-style-type:none;
display:inline;
}
.entity_tags li {
display:inline;
margin-right:4px;
float:left;
margin-right:11px;
}
.aside .section {
@ -820,6 +818,7 @@ font-size:1em;
#entity_statistics dt,
#entity_statistics dd {
display:inline;
margin-right:11px;
}
#entity_statistics dt:after {
content: ":";
@ -1496,6 +1495,11 @@ display:inline;
margin-right:7px;
line-height:1.25;
}
.tag-cloud li:before {
content:'\0009';
}
.aside .tag-cloud li {
line-height:1.5;
}