Broke a few long lines.
i18n/L10n updates.
Whitespace updates.
attachments may not make it through.
-
-
Code structure
==============
Yammer_user,
Yammer_group,
Yammer_notice: data objects mapping original Yammer item IDs to their local copies.
-
*/
function title()
{
+ // TRANS: Page title for Yammer import administration panel.
return _m('Yammer Import');
}
*/
function getInstructions()
{
+ // TRANS: Instructions for Yammer import administration panel.
return _m('This Yammer import tool is still undergoing testing, ' .
'and is incomplete in some areas. ' .
'Currently user subscriptions and group memberships are not ' .
} else if ($this->subaction == 'progress') {
$form = $this->statusForm();
} else {
- throw new ClientException('Invalid POST');
+ // TRANS: Client exception thrown when encountering an unhandled sub action.
+ throw new ClientException(_m('Invalid POST'));
}
return $this->showAjaxForm($form);
}
{
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
+ // TRANS: Page title for Yammer import administration panel.
$this->element('title', null, _m('Yammer import'));
$this->elementEnd('head');
$this->elementStart('body');
class YammerauthAction extends AdminPanelAction
{
-
/**
* Show the Yammer admin panel form
*
function prepare($args)
{
parent::prepare($args);
-
+
$this->verify_token = $this->trim('verify_token');
}
*
* @return void
*/
-
function handle($args)
{
if ($this->verify_token) {
$this->startHTML('text/xml;charset=utf-8');
$this->elementStart('head');
+ // TRANS: Page title for Yammer administration panel.
$this->element('title', null, _m('Connect to Yammer'));
$this->elementEnd('head');
$this->elementStart('body');
$this->elementEnd('html');
}
}
-
* - schemaDef (call self::doSchemaDef)
* - record (call self::doRecord)
*/
-
class Yammer_common extends Memcached_DataObject
{
public $__table = 'yammer_XXXX'; // table name
public $created; // datetime
/**
- * @fixme add a 'references' thing for the foreign key when we support that
+ * @todo FIXME: Add a 'references' thing for the foreign key when we support that
*/
protected static function doSchemaDef($field)
{
*
* @return array list of key field names
*/
-
function keys()
{
return array_keys($this->keyTypes());
* 'K' for primary key: for compound keys, add an entry for each component;
* 'U' for unique keys: compound keys are not well supported here.
*/
-
function keyTypes()
{
return array('id' => 'K', $this->__field => 'U');
*
* @return array magic three-false array that stops auto-incrementing.
*/
-
function sequenceKey()
{
return array(false, false, false);
*
* @return Yammer_common new object for this value
*/
-
protected static function doRecord($class, $field, $orig_id, $local_id)
{
$map = parent::staticGet($class, 'id', $orig_id);
* @return Yammer_group object found, or null for no hits
*
*/
-
function staticGet($k, $v=null)
{
return Memcached_DataObject::staticGet('Yammer_group', $k, $v);
/**
* Return schema definition to set this table up in onCheckSchema
*/
-
static function schemaDef()
{
return self::doSchemaDef('group_id');
*
* @return Yammer_group new object for this value
*/
-
static function record($orig_id, $group_id)
{
return self::doRecord('Yammer_group', 'group_id', $orig_id, $group_id);
* @return Yammer_notice object found, or null for no hits
*
*/
-
function staticGet($k, $v=null)
{
return Memcached_DataObject::staticGet('Yammer_notice', $k, $v);
/**
* Return schema definition to set this table up in onCheckSchema
*/
-
static function schemaDef()
{
return self::doSchemaDef('notice_id');
*
* @return Yammer_notice new object for this value
*/
-
static function record($orig_id, $notice_id)
{
return self::doRecord('Yammer_notice', 'notice_id', $orig_id, $notice_id);
* down in reverse chronological order, then go back over them from oldest to
* newest and actually save them into our notice table.
*/
-
class Yammer_notice_stub extends Memcached_DataObject
{
public $__table = 'yammer_notice_stub'; // table name
* @param mixed $v Value to lookup
*
* @return Yammer_notice_stub object found, or null for no hits
- *
*/
-
function staticGet($k, $v=null)
{
return Memcached_DataObject::staticGet('Yammer_notice_stub', $k, $v);
*
* @return array array of column definitions
*/
-
function table()
{
return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
* 'K' for primary key: for compound keys, add an entry for each component;
* 'U' for unique keys: compound keys are not well supported here.
*/
-
function keyTypes()
{
return array('id' => 'K');
*
* @return array magic three-false array that stops auto-incrementing.
*/
-
function sequenceKey()
{
return array(false, false, false);
* @param mixed $v Value to lookup
*
* @return Yammer_state object found, or null for no hits
- *
*/
-
function staticGet($k, $v=null)
{
return Memcached_DataObject::staticGet('Yammer_state', $k, $v);
*
* @return array array of column definitions
*/
-
function table()
{
return array('id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
*
* @return array list of key field names
*/
-
function keys()
{
return array_keys($this->keyTypes());
* 'K' for primary key: for compound keys, add an entry for each component;
* 'U' for unique keys: compound keys are not well supported here.
*/
-
function keyTypes()
{
return array('id' => 'K');
*
* @return array magic three-false array that stops auto-incrementing.
*/
-
function sequenceKey()
{
return array(false, false, false);
* @return Yammer_user object found, or null for no hits
*
*/
-
function staticGet($k, $v=null)
{
return Memcached_DataObject::staticGet('Yammer_user', $k, $v);
/**
* Return schema definition to set this table up in onCheckSchema
*/
-
static function schemaDef()
{
return self::doSchemaDef('user_id');
*
* @return Yammer_user new object for this value
*/
-
static function record($orig_id, $user_id)
{
return self::doRecord('Yammer_user', 'user_id', $orig_id, $user_id);
/**
* Basic client class for Yammer's OAuth/JSON API.
- *
+ *
* @package YammerImportPlugin
* @author Brion Vibber <brion@status.net>
*/
if ($response->isOk()) {
return $response->getBody();
} else {
- throw new Exception("Yammer API returned HTTP code " . $response->getStatus() . ': ' . $response->getBody());
+ // TRANS: Exeption thrown when an external Yammer system gives an error.
+ // TRANS: %1$s is an HTTP error code, %2$s is the error message body.
+ throw new Exception(sprintf(_m('Yammer API returned HTTP code %1$s: %2$s'),
+ $response->getStatus(),
+ $response->getBody()));
}
}
$data = json_decode($body, true);
if ($data === null) {
common_log(LOG_ERR, "Invalid JSON response from Yammer API: " . $body);
- throw new Exception("Invalid JSON response from Yammer API");
+ // TRANS: Exeption thrown when an external Yammer system an invalid JSON response.
+ throw new Exception(_m('Invalid JSON response from Yammer API.'));
}
return $data;
}
public function requestToken()
{
if ($this->token || $this->tokenSecret) {
- throw new Exception("Requesting a token, but already set up with a token");
+ // TRANS: Exeption thrown when a trust relationship has already been established.
+ throw new Exception(_m('Requesting a token, but already set up with a token.'));
}
$data = $this->fetchApi('oauth/request_token');
$arr = array();
*/
function formLegend()
{
+ // TRANS: Form legend for adding details to connect to a remote Yammer API.
$this->out->element('legend', null, _m('Yammer API registration'));
}
$this->out->elementStart('fieldset');
$this->out->elementStart('p');
+ // TRANS: Explanation of what needs to be done to connect to a Yammer network.
$this->out->text(_m('Before we can connect to your Yammer network, ' .
'you will need to register the importer as an ' .
'application authorized to pull data on your behalf. ' .
$this->out->element('a',
array('href' => 'https://www.yammer.com/client_applications/new',
'target' => '_blank'),
+ // TRANS: Link description to a Yammer application registration form.
_m('Open Yammer application registration form'));
$this->out->elementEnd('p');
+ // TRANS: Instructions.
$this->out->element('p', array(), _m('Copy the consumer key and secret you are given into the form below:'));
$this->out->elementStart('ul', array('class' => 'form_data'));
$this->out->elementStart('li');
+ // TRANS: Field label for a Yammer consumer key.
$this->out->input('consumer_key', _m('Consumer key:'), common_config('yammer', 'consumer_key'));
$this->out->elementEnd('li');
$this->out->elementStart('li');
+ // TRANS: Field label for a Yammer consumer secret.
$this->out->input('consumer_secret', _m('Consumer secret:'), common_config('yammer', 'consumer_secret'));
$this->out->elementEnd('li');
$this->out->elementEnd('ul');
- $this->out->submit('submit', _m('Save'), 'submit', null, _m('Save these consumer keys'));
+ // TRANS: Button text for saving a Yammer API registration.
+ $this->out->submit('submit', _m('BUTTON','Save'),
+ // TRANS: Button title for saving a Yammer API registration.
+ 'submit', null, _m('Save the entered consumer key and consumer secret.'));
$this->out->elementEnd('fieldset');
}
*/
function formLegend()
{
+ // TRANS: Form legend.
$this->out->element('legend', null, _m('Connect to Yammer'));
}
$this->out->hidden('subaction', 'authinit');
$this->out->elementStart('fieldset');
- $this->out->submit('submit', _m('Start authentication'), 'submit', null, _m('Request authorization to connect to Yammer account'));
- $this->out->submit('change-apikey', _m('Change API key'));
+ // TRANS: Button text for starting Yammer authentication.
+ $this->out->submit('submit', _m('BUTTON','Start authentication'),
+ // TRANS: Button title for starting Yammer authentication.
+ 'submit', null, _m('Request authorization to connect to a Yammer account.'));
+ // TRANS: Button text for starting changing a Yammer API key.
+ $this->out->submit('change-apikey', _m('BUTTON','Change API key'));
$this->out->elementEnd('fieldset');
}
*/
function formLegend()
{
+ // TRANS: Form legend.
$this->out->element('legend', null, _m('Connect to Yammer'));
}
$this->out->elementStart('fieldset');
$this->out->elementStart('p');
+ // TRANS: Form instructions.
$this->out->text(_m('Follow this link to confirm authorization at Yammer; you will be prompted to log in if necessary:'));
$this->out->elementEnd('p');
$this->out->element('a',
array('href' => $this->runner->getAuthUrl(),
'target' => '_blank'),
+ // TRANS: Link description for a link in an external Yammer system.
_m('Open Yammer authentication window'));
$this->out->elementEnd('p');
-
+
+ // TRANS: Form instructions.
$this->out->element('p', array(), _m('Copy the verification code you are given below:'));
$this->out->elementStart('ul', array('class' => 'form_data'));
$this->out->elementStart('li');
+ // TRANS: Field label.
$this->out->input('verify_token', _m('Verification code:'));
$this->out->elementEnd('li');
$this->out->elementEnd('ul');
-
- $this->out->submit('submit', _m('Continue'), 'submit', null, _m('Save code and begin import'));
+
+ // TRANS: Button text for saving Yammer authorisation data and starting Yammer import.
+ $this->out->submit('submit', _m('BUTTON','Continue'),
+ // TRANS: Button title for saving Yammer authorisation data and starting Yammer import.
+ 'submit', null, _m('Save the verification code and begin import.'));
$this->out->elementEnd('fieldset');
}
/**
* Load or create an imported profile from Yammer data.
- *
+ *
* @param object $item loaded JSON data for Yammer importer
* @return Profile
*/
function prepUser($item)
{
if ($item['type'] != 'user') {
- throw new Exception('Wrong item type sent to Yammer user import processing.');
+ // TRANS: Exception thrown when a non-user item type is used, but expected.
+ throw new Exception(_m('Wrong item type sent to Yammer user import processing.'));
}
$origId = $item['id'];
$bio[] = $item['summary'];
}
if (!empty($item['expertise'])) {
+ // TRANS: Used as a prefix for the Yammer expertise field contents.
$bio[] = _m('Expertise:') . ' ' . $item['expertise'];
}
$options['bio'] = implode("\n\n", $bio);
function prepGroup($item)
{
if ($item['type'] != 'group') {
- throw new Exception('Wrong item type sent to Yammer group import processing.');
+ // TRANS: Exception thrown when a non-group item type is used, but expected.
+ throw new Exception(_m('Wrong item type sent to Yammer group import processing.'));
}
$origId = $item['id'];
$avatar = $item['mugshot_url']; // as with user profiles...
-
$options['mainpage'] = common_local_url('showgroup',
array('nickname' => $options['nickname']));
$options['homepage'] = '';
$options['location'] = '';
$options['aliases'] = array();
- // @fixme what about admin user for the group?
+ // @todo FIXME: What about admin user for the group?
$options['local'] = true;
return array('orig_id' => $origId,
function prepNotice($item)
{
if (isset($item['type']) && $item['type'] != 'message') {
- throw new Exception('Wrong item type sent to Yammer message import processing.');
+ // TRANS: Exception thrown when a non-message item type is used, but expected.
+ throw new Exception(_m('Wrong item type sent to Yammer message import processing.'));
}
$origId = $item['id'];
$url = preg_replace('/_small(\..*?)$/', '$1', $url);
if (!common_valid_http_url($url)) {
- throw new ServerException(sprintf(_m("Invalid avatar URL %s."), $url));
+ // TRANS: Server exception thrown when an avatar URL is invalid.
+ // TRANS: %s is the invalid avatar URL.
+ throw new ServerException(sprintf(_m('Invalid avatar URL %s.'), $url));
}
// @fixme this should be better encapsulated
$temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
try {
if (!copy($url, $temp_filename)) {
- throw new ServerException(sprintf(_m("Unable to fetch avatar from %s."), $url));
+ // TRANS: Server exception thrown when an avatar could not be fetched.
+ // TRANS: %s is the failed avatar URL.
+ throw new ServerException(sprintf(_m('Unable to fetch avatar from %s.'), $url));
}
$id = $dest->id;
$labels = array(
'init' => array(
- 'label' => _m("Initialize"),
+ // TRANS: Field label for a Yammer import initialise step.
+ 'label' => _m('Initialize'),
+ // TRANS: "In progress" description.
'progress' => _m('No import running'),
+ // TRANS: "Complete" description for initialize state.
'complete' => _m('Initiated Yammer server connection...'),
),
'requesting-auth' => array(
+ // TRANS: Field label for a Yammer import connect step.
'label' => _m('Connect to Yammer'),
+ // TRANS: "In progress" description.
'progress' => _m('Awaiting authorization...'),
+ // TRANS: "Complete" description for connect state.
'complete' => _m('Connected.'),
),
'import-users' => array(
+ // TRANS: Field label for a Yammer user import users step.
'label' => _m('Import user accounts'),
- 'progress' => sprintf(_m("Importing %d user...", "Importing %d users...", $userCount), $userCount),
- 'complete' => sprintf(_m("Imported %d user.", "Imported %d users.", $userCount), $userCount),
+ // TRANS: "In progress" description.
+ // TRANS: %d is the number of users to be imported.
+ 'progress' => sprintf(_m('Importing %d user...',
+ 'Importing %d users...',
+ $userCount),
+ $userCount),
+ // TRANS: "Complete" description for step.
+ // TRANS: %d is the number of users imported.
+ 'complete' => sprintf(_m('Imported %d user.',
+ 'Imported %d users.',
+ $userCount),
+ $userCount),
),
'import-groups' => array(
+ // TRANS: Field label for a Yammer group import step.
'label' => _m('Import user groups'),
- 'progress' => sprintf(_m("Importing %d group...", "Importing %d groups...", $groupCount), $groupCount),
- 'complete' => sprintf(_m("Imported %d group.", "Imported %d groups.", $groupCount), $groupCount),
+ // TRANS: "In progress" description.
+ // TRANS: %d is the number of groups to be imported.
+ 'progress' => sprintf(_m('Importing %d group...',
+ 'Importing %d groups...',
+ $groupCount),
+ $groupCount),
+ // TRANS: "Complete" description for step.
+ // TRANS: %d is the number of groups imported.
+ 'complete' => sprintf(_m('Imported %d group.',
+ 'Imported %d groups.',
+ $groupCount),
+ $groupCount),
),
'fetch-messages' => array(
+ // TRANS: Field label for a Yammer import prepare notices step.
'label' => _m('Prepare public notices for import'),
- 'progress' => sprintf(_m("Preparing %d notice...", "Preparing %d notices...", $fetchedCount), $fetchedCount),
- 'complete' => sprintf(_m("Prepared %d notice.", "Prepared %d notices.", $fetchedCount), $fetchedCount),
+ // TRANS: "In progress" description.
+ // TRANS: %d is the number of notices to be prepared for import.
+ 'progress' => sprintf(_m('Preparing %d notice...',
+ 'Preparing %d notices...',
+ $fetchedCount),
+ $fetchedCount),
+ // TRANS: "Complete" description for step.
+ // TRANS: %d is the number of notices prepared for import.
+ 'complete' => sprintf(_m('Prepared %d notice.',
+ 'Prepared %d notices.',
+ $fetchedCount),
+ $fetchedCount),
),
'save-messages' => array(
+ // TRANS: Field label for a Yammer import notices step.
'label' => _m('Import public notices'),
- 'progress' => sprintf(_m("Importing %d notice...", "Importing %d notices...", $savedCount), $savedCount),
- 'complete' => sprintf(_m("Imported %d notice.", "Imported %d notices.", $savedCount), $savedCount),
+ // TRANS: "In progress" description.
+ // TRANS: %d is the number of notices to be imported.
+ 'progress' => sprintf(_m('Importing %d notice...',
+ 'Importing %d notices...',
+ $savedCount),
+ $savedCount),
+ // TRANS: "Complete" description for step.
+ // TRANS: %d is the number of notices imported.
+ 'complete' => sprintf(_m('Imported %d notice.',
+ 'Imported %d notices.',
+ $savedCount),
+ $savedCount),
),
'done' => array(
+ // TRANS: Field label for a Yammer import done step.
'label' => _m('Done'),
- 'progress' => sprintf(_m("Import is complete!")),
- 'complete' => sprintf(_m("Import is complete!")),
+ // TRANS: "In progress" description for done step.
+ 'progress' => sprintf(_m('Import is complete!')),
+ // TRANS: "Complete" description for done step.
+ 'complete' => sprintf(_m('Import is complete!')),
)
);
$steps = array_keys($labels);
$classes[] = 'yammer-running';
}
$this->out->elementStart('fieldset', array('class' => implode(' ', $classes)));
+ // TRANS: Fieldset legend.
$this->out->element('legend', array(), _m('Import status'));
foreach ($steps as $step => $state) {
if ($state == 'init') {
$this->progressBar($state,
'waiting',
$labels[$state]['label'],
- _m("Waiting..."));
+ // TRANS: Progress bar status.
+ _m('Waiting...'));
}
}
$this->out->elementEnd('fieldset');
$this->out->element('div', array('class' => 'import-status'), $status);
if ($class == 'progress') {
if ($state == 'done') {
+ // TRANS: Button text for resetting the import state.
$this->out->submit('abort-import', _m('Reset import state'));
} else {
if ($error) {
$this->errorBox($error);
} else {
+ // TRANS: Button text for pausing an import.
$this->out->submit('pause-import', _m('Pause import'));
}
}
private function errorBox($msg)
{
- $errline = sprintf(_m('Encountered error "%s"'), $msg);
+ // TRANS: Error message. %s are the error details.
+ $errline = sprintf(_m('Encountered error "%s".'), $msg);
$this->out->elementStart('fieldset', array('class' => 'import-error'));
+ // TRANS: Fieldset legend for a paused import.
$this->out->element('legend', array(), _m('Paused'));
$this->out->element('p', array(), $errline);
+ // TRANS: Button text for continuing a paused import.
$this->out->submit('continue-import', _m('Continue'));
+ // TRANS: Button text for aborting a paused import.
$this->out->submit('abort-import', _m('Abort import'));
$this->out->elementEnd('fieldset');
}
public function requestAuth()
{
if ($this->state->state != 'init') {
- throw new ServerException("Cannot request Yammer auth; already there!");
+ // TRANS: Server exception thrown if a Yammer authentication request is already present.
+ throw new ServerException(_m('Cannot request Yammer auth; already there!'));
}
$data = $this->client->requestToken();
if ($this->state() == 'requesting-auth') {
return $this->client->authorizeUrl($this->state->oauth_token);
} else {
- throw new ServerException('Cannot get Yammer auth URL when not in requesting-auth state!');
+ // TRANS: Server exception thrown when requesting a Yammer authentication URL while in an incorrect state.
+ throw new ServerException(_m('Cannot get Yammer auth URL when not in requesting-auth state!'));
}
}
public function saveAuthToken($verifier)
{
if ($this->state->state != 'requesting-auth') {
- throw new ServerException("Cannot save auth token in Yammer import state {$this->state->state}");
+ // TRANS: Server exception thrown if a Yammer authentication token could not be saved in a certain import state.
+ // TRANS: %s is the import state in the which the error occurred.
+ throw new ServerException(_m('Cannot save auth token in Yammer import state %s.',$this->state->state));
}
$data = $this->client->accessToken($verifier);
$stub->limit(20);
$stub->orderBy('id');
$stub->find();
-
+
if ($stub->N == 0) {
common_log(LOG_INFO, "Finished saving Yammer messages; import complete!");
$this->state->state = 'done';
return $map->count();
}
-
/**
* Count the number of Yammer groups we've mapped into our system!
*
return $map->count();
}
-
/**
* Count the number of Yammer notices we've pulled down for pending import...
*
return $map->count();
}
-
/**
* Count the number of Yammer notices we've mapped into our system!
*
/**
* Record an error condition from a background run, which we should
* display in progress state for the admin.
- *
- * @param string $msg
+ *
+ * @param string $msg
*/
public function recordError($msg)
{
/**
* Get the last recorded background error message, if any.
- *
+ *
* @return string
*/
public function lastError()
die('no');
}
-
define('INSTALLDIR', dirname(dirname(dirname(dirname(__FILE__)))));
$longoptions = array('verify=', 'reset');