Whitespace updates (including leading tabs to spaces).

Fixed i18n.
This commit is contained in:
Siebrand Mazeland 2011-08-19 17:06:03 +02:00
parent 700b46317a
commit 4b0dd8384f
4 changed files with 169 additions and 178 deletions

View File

@ -51,7 +51,6 @@ class RealtimePlugin extends Plugin
* When it's time to initialize the plugin, calculate and
* pass the URLs we need.
*/
function onInitializePlugin()
{
// FIXME: need to find a better way to pass this pattern in
@ -244,25 +243,25 @@ class RealtimePlugin extends Plugin
foreach ($paths as $path) {
list($action, $arg1, $arg2) = $path;
list($action, $arg1, $arg2) = $path;
$channels = Realtime_channel::getAllChannels($action, $arg1, $arg2);
$channels = Realtime_channel::getAllChannels($action, $arg1, $arg2);
foreach ($channels as $channel) {
foreach ($channels as $channel) {
// XXX: We should probably fan-out here and do a
// new queue item for each user/path combo
// XXX: We should probably fan-out here and do a
// new queue item for each user/path combo
if (is_null($channel->user_id)) {
$profile = null;
} else {
$profile = Profile::staticGet('id', $channel->user_id);
}
if ($notice->inScope($profile)) {
$timeline = $this->_pathToChannel(array($channel->channel_key));
$this->_publish($timeline, $json);
}
}
if (is_null($channel->user_id)) {
$profile = null;
} else {
$profile = Profile::staticGet('id', $channel->user_id);
}
if ($notice->inScope($profile)) {
$timeline = $this->_pathToChannel(array($channel->channel_key));
$this->_publish($timeline, $json);
}
}
}
$this->_disconnect();
@ -367,12 +366,11 @@ class RealtimePlugin extends Plugin
$convurl = $conv->uri;
if(empty($convurl)) {
$msg = sprintf(
"Couldn't find Conversation ID %d to make 'in context'"
. "link for Notice ID %d",
$msg = sprintf( _m("Could not find Conversation ID %d to make 'in context'"
. "link for Notice ID %d.",
$notice->conversation,
$notice->id
);
));
common_log(LOG_WARNING, $msg);
} else {
@ -455,26 +453,26 @@ class RealtimePlugin extends Plugin
function _getChannel($action)
{
$timeline = null;
$arg1 = null;
$arg2 = null;
$arg1 = null;
$arg2 = null;
$action_name = $action->trimmed('action');
// FIXME: lists
// FIXME: search (!)
// FIXME: profile + tag
// FIXME: lists
// FIXME: search (!)
// FIXME: profile + tag
switch ($action_name) {
case 'public':
// no arguments
// no arguments
break;
case 'tag':
$tag = $action->trimmed('tag');
if (empty($tag)) {
$arg1 = $tag;
} else {
$this->log(LOG_NOTICE, "Unexpected 'tag' action without tag argument");
return null;
$this->log(LOG_NOTICE, "Unexpected 'tag' action without tag argument");
return null;
}
break;
case 'showstream':
@ -485,29 +483,29 @@ class RealtimePlugin extends Plugin
if (!empty($nickname)) {
$arg1 = $nickname;
} else {
$this->log(LOG_NOTICE, "Unexpected $action_name action without nickname argument.");
return null;
$this->log(LOG_NOTICE, "Unexpected $action_name action without nickname argument.");
return null;
}
break;
default:
return null;
}
$user = common_current_user();
$user = common_current_user();
$user_id = (!empty($user)) ? $user->id : null;
$user_id = (!empty($user)) ? $user->id : null;
$channel = Realtime_channel::getChannel($user_id,
$action_name,
$arg1,
$arg2);
$channel = Realtime_channel::getChannel($user_id,
$action_name,
$arg1,
$arg2);
return $channel;
}
function onStartReadWriteTables(&$alwaysRW, &$rwdb)
{
$alwaysRW[] = 'realtime_channel';
return true;
$alwaysRW[] = 'realtime_channel';
return true;
}
}

View File

@ -46,10 +46,9 @@ if (!defined('STATUSNET')) {
*
* @see DB_DataObject
*/
class Realtime_channel extends Managed_DataObject
{
const TIMEOUT = 1800; // 30 minutes
const TIMEOUT = 1800; // 30 minutes
public $__table = 'realtime_channel'; // table name
@ -59,7 +58,7 @@ class Realtime_channel extends Managed_DataObject
public $arg2; // argument, usually null
public $channel_key; // 128-bit shared secret key
public $audience; // listener count
public $created; // created date
public $created; // created date
public $modified; // modified date
/**
@ -71,7 +70,6 @@ class Realtime_channel extends Managed_DataObject
* @param mixed $v Value to lookup
*
* @return Realtime_channel object found, or null for no hits
*
*/
function staticGet($k, $v=null)
{
@ -84,7 +82,6 @@ class Realtime_channel extends Managed_DataObject
* @param array $kv array of key-value mappings
*
* @return Realtime_channel object found, or null for no hits
*
*/
function pkeyGet($kv)
{
@ -100,34 +97,34 @@ class Realtime_channel extends Managed_DataObject
'description' => 'A channel of realtime notice data',
'fields' => array(
'user_id' => array('type' => 'int',
'not null' => false,
'description' => 'user viewing page; can be null'),
'not null' => false,
'description' => 'user viewing page; can be null'),
'action' => array('type' => 'varchar',
'length' => 255,
'not null' => true,
'description' => 'page being viewed'),
'arg1' => array('type' => 'varchar',
'length' => 255,
'not null' => false,
'description' => 'page argument, like username or tag'),
'arg2' => array('type' => 'varchar',
'length' => 255,
'not null' => false,
'description' => 'second page argument, like tag for showstream'),
'channel_key' => array('type' => 'varchar',
'length' => 32,
'not null' => true,
'description' => 'shared secret key for this channel'),
'audience' => array('type' => 'integer',
'length' => 255,
'not null' => true,
'description' => 'page being viewed'),
'arg1' => array('type' => 'varchar',
'length' => 255,
'not null' => false,
'description' => 'page argument, like username or tag'),
'arg2' => array('type' => 'varchar',
'length' => 255,
'not null' => false,
'description' => 'second page argument, like tag for showstream'),
'channel_key' => array('type' => 'varchar',
'length' => 32,
'not null' => true,
'description' => 'shared secret key for this channel'),
'audience' => array('type' => 'integer',
'not null' => true,
'default' => 0,
'description' => 'reference count'),
'created' => array('type' => 'datetime',
'not null' => true,
'description' => 'date this record was created'),
'not null' => true,
'description' => 'date this record was created'),
'modified' => array('type' => 'datetime',
'not null' => true,
'description' => 'date this record was modified'),
'not null' => true,
'description' => 'date this record was modified'),
),
'primary key' => array('channel_key'),
'unique keys' => array('realtime_channel_user_page_idx' => array('user_id', 'action', 'arg1', 'arg2')),
@ -143,104 +140,104 @@ class Realtime_channel extends Managed_DataObject
static function saveNew($user_id, $action, $arg1, $arg2)
{
$channel = new Realtime_channel();
$channel = new Realtime_channel();
$channel->user_id = $user_id;
$channel->action = $action;
$channel->arg1 = $arg1;
$channel->arg2 = $arg2;
$channel->audience = 1;
$channel->user_id = $user_id;
$channel->action = $action;
$channel->arg1 = $arg1;
$channel->arg2 = $arg2;
$channel->audience = 1;
$channel->channel_key = common_good_rand(16); // 128-bit key, 32 hex chars
$channel->channel_key = common_good_rand(16); // 128-bit key, 32 hex chars
$channel->created = common_sql_now();
$channel->modified = $channel->created;
$channel->created = common_sql_now();
$channel->modified = $channel->created;
$channel->insert();
$channel->insert();
return $channel;
return $channel;
}
static function getChannel($user_id, $action, $arg1, $arg2)
{
$channel = self::fetchChannel($user_id, $action, $arg1, $arg2);
$channel = self::fetchChannel($user_id, $action, $arg1, $arg2);
// Ignore (and delete!) old channels
// Ignore (and delete!) old channels
if (!empty($channel)) {
$modTime = strtotime($channel->modified);
if ((time() - $modTime) > self::TIMEOUT) {
$channel->delete();
$channel = null;
}
}
if (!empty($channel)) {
$modTime = strtotime($channel->modified);
if ((time() - $modTime) > self::TIMEOUT) {
$channel->delete();
$channel = null;
}
}
if (empty($channel)) {
$channel = self::saveNew($user_id, $action, $arg1, $arg2);
}
if (empty($channel)) {
$channel = self::saveNew($user_id, $action, $arg1, $arg2);
}
return $channel;
return $channel;
}
static function getAllChannels($action, $arg1, $arg2)
{
$channel = new Realtime_channel();
$channel = new Realtime_channel();
$channel->action = $action;
$channel->action = $action;
if (is_null($arg1)) {
$channel->whereAdd('arg1 is null');
} else {
$channel->arg1 = $arg1;
}
if (is_null($arg1)) {
$channel->whereAdd('arg1 is null');
} else {
$channel->arg1 = $arg1;
}
if (is_null($arg2)) {
$channel->whereAdd('arg2 is null');
} else {
$channel->arg2 = $arg2;
}
if (is_null($arg2)) {
$channel->whereAdd('arg2 is null');
} else {
$channel->arg2 = $arg2;
}
$channel->whereAdd('modified > "' . common_sql_date(time() - self::TIMEOUT) . '"');
$channel->whereAdd('modified > "' . common_sql_date(time() - self::TIMEOUT) . '"');
$channels = array();
$channels = array();
if ($channel->find()) {
$channels = $channel->fetchAll();
}
if ($channel->find()) {
$channels = $channel->fetchAll();
}
return $channels;
return $channels;
}
static function fetchChannel($user_id, $action, $arg1, $arg2)
{
$channel = new Realtime_channel();
$channel = new Realtime_channel();
if (is_null($user_id)) {
$channel->whereAdd('user_id is null');
} else {
$channel->user_id = $user_id;
}
if (is_null($user_id)) {
$channel->whereAdd('user_id is null');
} else {
$channel->user_id = $user_id;
}
$channel->action = $action;
$channel->action = $action;
if (is_null($arg1)) {
$channel->whereAdd('arg1 is null');
} else {
$channel->arg1 = $arg1;
}
if (is_null($arg1)) {
$channel->whereAdd('arg1 is null');
} else {
$channel->arg1 = $arg1;
}
if (is_null($arg2)) {
$channel->whereAdd('arg2 is null');
} else {
$channel->arg2 = $arg2;
}
if (is_null($arg2)) {
$channel->whereAdd('arg2 is null');
} else {
$channel->arg2 = $arg2;
}
if ($channel->find(true)) {
if ($channel->find(true)) {
$channel->increment();
return $channel;
} else {
return null;
}
return $channel;
} else {
return null;
}
}
function increment()

View File

@ -44,7 +44,6 @@ if (!defined('STATUSNET')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/
*/
class ClosechannelAction extends Action
{
protected $channelKey = null;
@ -57,7 +56,6 @@ class ClosechannelAction extends Action
*
* @return boolean true
*/
function prepare($argarray)
{
parent::prepare($argarray);
@ -88,7 +86,6 @@ class ClosechannelAction extends Action
*
* @return void
*/
function handle($argarray=null)
{
$this->channel->decrement();
@ -107,7 +104,6 @@ class ClosechannelAction extends Action
*
* @return boolean is read only action?
*/
function isReadOnly($args)
{
return false;