case 'sn_yammerclient':
case 'yammerimporter':
case 'yammerrunner':
+ case 'yammerapikeyform':
case 'yammerauthinitform':
case 'yammerauthverifyform':
case 'yammerprogressform':
*/
function getInstructions()
{
- return _m('Yammer import tool');
+ return _m('This Yammer import tool is still undergoing testing, ' .
+ 'and is incomplete in some areas. ' .
+ 'Currently user subscriptions and group memberships are not ' .
+ 'transferred; in the future this may be supported for ' .
+ 'imports done by verified administrators on the Yammer side.');
}
function prepare($args)
{
$ok = parent::prepare($args);
- $this->init_auth = $this->trimmed('init_auth');
- $this->verify_token = $this->trimmed('verify_token');
+ $this->subaction = $this->trimmed('subaction');
$this->runner = YammerRunner::init();
return $ok;
function handle($args)
{
+ // @fixme move this to saveSettings and friends?
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$this->checkSessionToken();
- if ($this->init_auth) {
- $url = $this->runner->requestAuth();
- $form = new YammerAuthVerifyForm($this, $this->runner);
- return $this->showAjaxForm($form);
- } else if ($this->verify_token) {
- $this->runner->saveAuthToken($this->verify_token);
-
+ if ($this->subaction == 'change-apikey') {
+ $form = new YammerApiKeyForm($this);
+ } else if ($this->subaction == 'apikey') {
+ if ($this->saveKeys()) {
+ $form = new YammerAuthInitForm($this, $this->runner);
+ } else {
+ $form = new YammerApiKeyForm($this);
+ }
+ } else if ($this->subaction == 'authinit') {
+ // hack
+ if ($this->arg('change-apikey')) {
+ $form = new YammerApiKeyForm($this);
+ } else {
+ $url = $this->runner->requestAuth();
+ $form = new YammerAuthVerifyForm($this, $this->runner);
+ }
+ } else if ($this->subaction == 'authverify') {
+ $this->runner->saveAuthToken($this->trimmed('verify_token'));
+
// Haho! Now we can make THE FUN HAPPEN
$this->runner->startBackgroundImport();
-
+
$form = new YammerProgressForm($this, $this->runner);
- return $this->showAjaxForm($form);
} else {
throw new ClientException('Invalid POST');
}
- } else {
- return parent::handle($args);
+ return $this->showAjaxForm($form);
}
+ return parent::handle($args);
+ }
+
+ function saveKeys()
+ {
+ $key = $this->trimmed('consumer_key');
+ $secret = $this->trimmed('consumer_secret');
+ Config::save('yammer', 'consumer_key', $key);
+ Config::save('yammer', 'consumer_secret', $secret);
+
+ return !empty($key) && !empty($secret);
}
function showAjaxForm($form)
}
/**
- * Show the Yammer admin panel form
- *
- * @return void
+ * Fetch the appropriate form for our current state.
+ * @return Form
*/
- function showForm()
+ function statusForm()
{
- $this->elementStart('fieldset');
-
+ if (!(common_config('yammer', 'consumer_key'))
+ || !(common_config('yammer', 'consumer_secret'))) {
+ return new YammerApiKeyForm($this);
+ }
switch($this->runner->state())
{
case 'init':
- $form = new YammerAuthInitForm($this, $this->runner);
- break;
+ return new YammerAuthInitForm($this, $this->runner);
case 'requesting-auth':
- $form = new YammerAuthVerifyForm($this, $this->runner);
- break;
+ return new YammerAuthVerifyForm($this, $this->runner);
default:
- $form = new YammerProgressForm($this, $this->runner);
+ return new YammerProgressForm($this, $this->runner);
}
- $form->show();
+ }
+ /**
+ * Show the Yammer admin panel form
+ *
+ * @return void
+ */
+ function showForm()
+ {
+ $this->elementStart('fieldset');
+ $this->statusForm()->show();
$this->elementEnd('fieldset');
}
/* override */
background: none !important;
}
+
+.magiclink {
+ margin-left: 40px;
+}
\ No newline at end of file
--- /dev/null
+<?php
+
+class YammerApikeyForm extends Form
+{
+ private $runner;
+
+ function __construct($out)
+ {
+ parent::__construct($out);
+ $this->runner = $runner;
+ }
+
+ /**
+ * ID of the form
+ *
+ * @return int ID of the form
+ */
+
+ function id()
+ {
+ return 'yammer-apikey-form';
+ }
+
+
+ /**
+ * class of the form
+ *
+ * @return string of the form class
+ */
+
+ function formClass()
+ {
+ return 'form_yammer_apikey form_settings';
+ }
+
+
+ /**
+ * Action of the form
+ *
+ * @return string URL of the action
+ */
+
+ function action()
+ {
+ return common_local_url('yammeradminpanel');
+ }
+
+
+ /**
+ * Legend of the Form
+ *
+ * @return void
+ */
+ function formLegend()
+ {
+ $this->out->element('legend', null, _m('Yammer API registration'));
+ }
+
+ /**
+ * Data elements of the form
+ *
+ * @return void
+ */
+
+ function formData()
+ {
+ $this->out->hidden('subaction', 'apikey');
+
+ $this->out->elementStart('fieldset');
+
+ $this->out->elementStart('p');
+ $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 registration will work only for your own network. ' .
+ 'Follow this link to register the app at Yammer; ' .
+ 'you will be prompted to log in if necessary:'));
+ $this->out->elementEnd('p');
+
+ $this->out->elementStart('p', array('class' => 'magiclink'));
+ $this->out->element('a',
+ array('href' => 'https://www.yammer.com/client_applications/new',
+ 'target' => '_blank'),
+ _m('Open Yammer application registration form'));
+ $this->out->elementEnd('p');
+
+ $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');
+ $this->out->input('consumer_key', _m('Consumer key:'), common_config('yammer', 'consumer_key'));
+ $this->out->elementEnd('li');
+ $this->out->elementStart('li');
+ $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'));
+
+ $this->out->elementEnd('fieldset');
+ }
+
+ /**
+ * Action elements
+ *
+ * @return void
+ */
+
+ function formActions()
+ {
+ }
+}
function formClass()
{
- return 'form_yammer_auth_init';
+ return 'form_yammer_auth_init form_settings';
}
function formData()
{
- $this->out->hidden('init_auth', '1');
+ $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'));
+ $this->out->elementEnd('fieldset');
}
/**
function formActions()
{
- $this->out->submit('submit', _m('Connect to Yammer'), 'submit', null, _m('Request authorization to connect to Yammer account'));
}
}
function formClass()
{
- return 'form_yammer_auth_verify';
+ return 'form_yammer_auth_verify form_settings';
}
function formData()
{
+ $this->out->hidden('subaction', 'authverify');
+
+ $this->out->elementStart('fieldset');
+
$this->out->elementStart('p');
$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->elementStart('blockquote');
+ // iframe would be nice to avoid leaving -- since they don't seem to have callback url O_O
+ /*
+ $this->out->element('iframe', array('id' => 'yammer-oauth',
+ 'src' => $this->runner->getAuthUrl()));
+ */
+ // yeah, it ignores the callback_url
+ // soo... crappy link. :(
+
+ $this->out->elementStart('p', array('class' => 'magiclink'));
$this->out->element('a',
array('href' => $this->runner->getAuthUrl(),
'target' => '_blank'),
_m('Open Yammer authentication window'));
- $this->out->elementEnd('blockquote');
+ $this->out->elementEnd('p');
- $this->out->element('p', array(), _m('Copy the verification code you are given into the form below:'));
+ $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');
$this->out->input('verify_token', _m('Verification code:'));
+ $this->out->elementEnd('li');
+ $this->out->elementEnd('ul');
- // iframe would be nice to avoid leaving -- since they don't seem to have callback url O_O
- /*
- $this->out->element('iframe', array('id' => 'yammer-oauth',
- 'src' => $this->runner->getAuthUrl()));
- */
- // yeah, it ignores the callback_url
+ $this->out->submit('submit', _m('Continue'), 'submit', null, _m('Save code and begin import'));
+ $this->out->elementEnd('fieldset');
}
/**
function formActions()
{
- $this->out->submit('submit', _m('Verify code'), 'submit', null, _m('Verification code'));
}
}
+++ /dev/null
-<?php
-
-if (php_sapi_name() != 'cli') {
- die('no');
-}
-
-define('INSTALLDIR', dirname(dirname(dirname(dirname(__FILE__)))));
-
-require INSTALLDIR . "/scripts/commandline.inc";
-
-// temp stuff
-require 'yam-config.php';
-$yam = new SN_YammerClient($consumerKey, $consumerSecret, $token, $tokenSecret);
-$imp = new YammerImporter($yam);
-
-/*
-$data = $yam->users();
-var_dump($data);
-// @fixme follow paging
-foreach ($data as $item) {
- $user = $imp->prepUser($item);
- var_dump($user);
-}
-*/
-
-$data = $yam->messages(array('newer_than' => 1));
-var_dump($data);
-// @fixme follow paging
-$messages = $data['messages'];
-$messages = array_reverse($messages);
-foreach ($messages as $message) {
- $notice = $imp->prepNotice($message);
- var_dump($notice);
-}