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

View File

@ -4,7 +4,7 @@
* Copyright (C) 2011, StatusNet, Inc. * Copyright (C) 2011, StatusNet, Inc.
* *
* A channel for real-time browser data * A channel for real-time browser data
* *
* PHP version 5 * PHP version 5
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -34,7 +34,7 @@ if (!defined('STATUSNET')) {
/** /**
* A channel for real-time browser data * A channel for real-time browser data
* *
* For each user currently browsing the site, we want to know which page they're on * For each user currently browsing the site, we want to know which page they're on
* so we can send real-time updates to their browser. * so we can send real-time updates to their browser.
* *
@ -46,20 +46,19 @@ if (!defined('STATUSNET')) {
* *
* @see DB_DataObject * @see DB_DataObject
*/ */
class Realtime_channel extends Managed_DataObject class Realtime_channel extends Managed_DataObject
{ {
const TIMEOUT = 1800; // 30 minutes const TIMEOUT = 1800; // 30 minutes
public $__table = 'realtime_channel'; // table name public $__table = 'realtime_channel'; // table name
public $user_id; // int -> user.id, can be null public $user_id; // int -> user.id, can be null
public $action; // string public $action; // string
public $arg1; // argument public $arg1; // argument
public $arg2; // argument, usually null public $arg2; // argument, usually null
public $channel_key; // 128-bit shared secret key public $channel_key; // 128-bit shared secret key
public $audience; // listener count public $audience; // listener count
public $created; // created date public $created; // created date
public $modified; // modified date public $modified; // modified date
/** /**
@ -71,7 +70,6 @@ class Realtime_channel extends Managed_DataObject
* @param mixed $v Value to lookup * @param mixed $v Value to lookup
* *
* @return Realtime_channel object found, or null for no hits * @return Realtime_channel object found, or null for no hits
*
*/ */
function staticGet($k, $v=null) function staticGet($k, $v=null)
{ {
@ -84,7 +82,6 @@ class Realtime_channel extends Managed_DataObject
* @param array $kv array of key-value mappings * @param array $kv array of key-value mappings
* *
* @return Realtime_channel object found, or null for no hits * @return Realtime_channel object found, or null for no hits
*
*/ */
function pkeyGet($kv) function pkeyGet($kv)
{ {
@ -100,34 +97,34 @@ class Realtime_channel extends Managed_DataObject
'description' => 'A channel of realtime notice data', 'description' => 'A channel of realtime notice data',
'fields' => array( 'fields' => array(
'user_id' => array('type' => 'int', 'user_id' => array('type' => 'int',
'not null' => false, 'not null' => false,
'description' => 'user viewing page; can be null'), 'description' => 'user viewing page; can be null'),
'action' => array('type' => 'varchar', 'action' => array('type' => 'varchar',
'length' => 255, 'length' => 255,
'not null' => true, 'not null' => true,
'description' => 'page being viewed'), 'description' => 'page being viewed'),
'arg1' => array('type' => 'varchar', 'arg1' => array('type' => 'varchar',
'length' => 255, 'length' => 255,
'not null' => false, 'not null' => false,
'description' => 'page argument, like username or tag'), 'description' => 'page argument, like username or tag'),
'arg2' => array('type' => 'varchar', 'arg2' => array('type' => 'varchar',
'length' => 255, 'length' => 255,
'not null' => false, 'not null' => false,
'description' => 'second page argument, like tag for showstream'), 'description' => 'second page argument, like tag for showstream'),
'channel_key' => array('type' => 'varchar', 'channel_key' => array('type' => 'varchar',
'length' => 32, 'length' => 32,
'not null' => true, 'not null' => true,
'description' => 'shared secret key for this channel'), 'description' => 'shared secret key for this channel'),
'audience' => array('type' => 'integer', 'audience' => array('type' => 'integer',
'not null' => true, 'not null' => true,
'default' => 0, 'default' => 0,
'description' => 'reference count'), 'description' => 'reference count'),
'created' => array('type' => 'datetime', 'created' => array('type' => 'datetime',
'not null' => true, 'not null' => true,
'description' => 'date this record was created'), 'description' => 'date this record was created'),
'modified' => array('type' => 'datetime', 'modified' => array('type' => 'datetime',
'not null' => true, 'not null' => true,
'description' => 'date this record was modified'), 'description' => 'date this record was modified'),
), ),
'primary key' => array('channel_key'), 'primary key' => array('channel_key'),
'unique keys' => array('realtime_channel_user_page_idx' => array('user_id', 'action', 'arg1', 'arg2')), 'unique keys' => array('realtime_channel_user_page_idx' => array('user_id', 'action', 'arg1', 'arg2')),
@ -140,107 +137,107 @@ class Realtime_channel extends Managed_DataObject
), ),
); );
} }
static function saveNew($user_id, $action, $arg1, $arg2) static function saveNew($user_id, $action, $arg1, $arg2)
{ {
$channel = new Realtime_channel(); $channel = new Realtime_channel();
$channel->user_id = $user_id; $channel->user_id = $user_id;
$channel->action = $action; $channel->action = $action;
$channel->arg1 = $arg1; $channel->arg1 = $arg1;
$channel->arg2 = $arg2; $channel->arg2 = $arg2;
$channel->audience = 1; $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->created = common_sql_now();
$channel->modified = $channel->created; $channel->modified = $channel->created;
$channel->insert(); $channel->insert();
return $channel; return $channel;
} }
static function getChannel($user_id, $action, $arg1, $arg2) 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)) { if (!empty($channel)) {
$modTime = strtotime($channel->modified); $modTime = strtotime($channel->modified);
if ((time() - $modTime) > self::TIMEOUT) { if ((time() - $modTime) > self::TIMEOUT) {
$channel->delete(); $channel->delete();
$channel = null; $channel = null;
} }
} }
if (empty($channel)) { if (empty($channel)) {
$channel = self::saveNew($user_id, $action, $arg1, $arg2); $channel = self::saveNew($user_id, $action, $arg1, $arg2);
} }
return $channel; return $channel;
} }
static function getAllChannels($action, $arg1, $arg2) static function getAllChannels($action, $arg1, $arg2)
{ {
$channel = new Realtime_channel(); $channel = new Realtime_channel();
$channel->action = $action; $channel->action = $action;
if (is_null($arg1)) { if (is_null($arg1)) {
$channel->whereAdd('arg1 is null'); $channel->whereAdd('arg1 is null');
} else { } else {
$channel->arg1 = $arg1; $channel->arg1 = $arg1;
} }
if (is_null($arg2)) { if (is_null($arg2)) {
$channel->whereAdd('arg2 is null'); $channel->whereAdd('arg2 is null');
} else { } else {
$channel->arg2 = $arg2; $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()) { if ($channel->find()) {
$channels = $channel->fetchAll(); $channels = $channel->fetchAll();
} }
return $channels; return $channels;
} }
static function fetchChannel($user_id, $action, $arg1, $arg2) static function fetchChannel($user_id, $action, $arg1, $arg2)
{ {
$channel = new Realtime_channel(); $channel = new Realtime_channel();
if (is_null($user_id)) { if (is_null($user_id)) {
$channel->whereAdd('user_id is null'); $channel->whereAdd('user_id is null');
} else { } else {
$channel->user_id = $user_id; $channel->user_id = $user_id;
} }
$channel->action = $action; $channel->action = $action;
if (is_null($arg1)) { if (is_null($arg1)) {
$channel->whereAdd('arg1 is null'); $channel->whereAdd('arg1 is null');
} else { } else {
$channel->arg1 = $arg1; $channel->arg1 = $arg1;
} }
if (is_null($arg2)) { if (is_null($arg2)) {
$channel->whereAdd('arg2 is null'); $channel->whereAdd('arg2 is null');
} else { } else {
$channel->arg2 = $arg2; $channel->arg2 = $arg2;
} }
if ($channel->find(true)) { if ($channel->find(true)) {
$channel->increment(); $channel->increment();
return $channel; return $channel;
} else { } else {
return null; return null;
} }
} }
function increment() function increment()

View File

@ -4,7 +4,7 @@
* Copyright (C) 2011, StatusNet, Inc. * Copyright (C) 2011, StatusNet, Inc.
* *
* action to close a channel * action to close a channel
* *
* PHP version 5 * PHP version 5
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
@ -44,7 +44,6 @@ if (!defined('STATUSNET')) {
* @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html AGPL 3.0
* @link http://status.net/ * @link http://status.net/
*/ */
class ClosechannelAction extends Action class ClosechannelAction extends Action
{ {
protected $channelKey = null; protected $channelKey = null;
@ -57,7 +56,6 @@ class ClosechannelAction extends Action
* *
* @return boolean true * @return boolean true
*/ */
function prepare($argarray) function prepare($argarray)
{ {
parent::prepare($argarray); parent::prepare($argarray);
@ -88,7 +86,6 @@ class ClosechannelAction extends Action
* *
* @return void * @return void
*/ */
function handle($argarray=null) function handle($argarray=null)
{ {
$this->channel->decrement(); $this->channel->decrement();
@ -107,7 +104,6 @@ class ClosechannelAction extends Action
* *
* @return boolean is read only action? * @return boolean is read only action?
*/ */
function isReadOnly($args) function isReadOnly($args)
{ {
return false; return false;

View File

@ -412,7 +412,7 @@ RealtimeUpdate = {
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
url: RealtimeUpdate._keepaliveurl}); url: RealtimeUpdate._keepaliveurl});
}, 15 * 60 * 1000 ); // every 15 min; timeout in 30 min }, 15 * 60 * 1000 ); // every 15 min; timeout in 30 min
RealtimeUpdate.initPlayPause(); RealtimeUpdate.initPlayPause();