2010-09-23 01:51:50 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* StatusNet, the distributed open-source microblogging tool
|
|
|
|
*
|
|
|
|
* Yammer import administration panel
|
|
|
|
*
|
|
|
|
* 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 Settings
|
|
|
|
* @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 YammeradminpanelAction extends AdminPanelAction
|
|
|
|
{
|
2010-09-27 20:24:10 +01:00
|
|
|
private $runner;
|
|
|
|
|
2010-09-23 01:51:50 +01:00
|
|
|
/**
|
|
|
|
* Returns the page title
|
|
|
|
*
|
|
|
|
* @return string page title
|
|
|
|
*/
|
|
|
|
function title()
|
|
|
|
{
|
2011-06-19 14:02:31 +01:00
|
|
|
// TRANS: Page title for Yammer import administration panel.
|
2010-09-23 01:51:50 +01:00
|
|
|
return _m('Yammer Import');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Instructions for using this form.
|
|
|
|
*
|
|
|
|
* @return string instructions
|
|
|
|
*/
|
|
|
|
function getInstructions()
|
|
|
|
{
|
2011-06-19 14:02:31 +01:00
|
|
|
// TRANS: Instructions for Yammer import administration panel.
|
2010-09-28 00:56:48 +01:00
|
|
|
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.');
|
2010-09-23 01:51:50 +01:00
|
|
|
}
|
|
|
|
|
2010-09-25 01:22:44 +01:00
|
|
|
function prepare($args)
|
2010-09-23 01:51:50 +01:00
|
|
|
{
|
2010-09-25 01:22:44 +01:00
|
|
|
$ok = parent::prepare($args);
|
2010-09-24 22:52:51 +01:00
|
|
|
|
2010-09-28 00:56:48 +01:00
|
|
|
$this->subaction = $this->trimmed('subaction');
|
2010-09-27 20:24:10 +01:00
|
|
|
$this->runner = YammerRunner::init();
|
2010-09-23 01:51:50 +01:00
|
|
|
|
2010-09-25 01:22:44 +01:00
|
|
|
return $ok;
|
2010-09-23 01:51:50 +01:00
|
|
|
}
|
|
|
|
|
2010-09-25 01:22:44 +01:00
|
|
|
function handle($args)
|
2010-09-23 01:51:50 +01:00
|
|
|
{
|
2010-09-28 00:56:48 +01:00
|
|
|
// @fixme move this to saveSettings and friends?
|
2010-09-27 20:24:10 +01:00
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
2010-09-28 23:45:00 +01:00
|
|
|
StatusNet::setApi(true); // short error pages :P
|
2010-09-27 20:24:10 +01:00
|
|
|
$this->checkSessionToken();
|
2010-09-28 00:56:48 +01:00
|
|
|
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'));
|
|
|
|
|
2010-09-27 21:34:35 +01:00
|
|
|
// Haho! Now we can make THE FUN HAPPEN
|
|
|
|
$this->runner->startBackgroundImport();
|
2010-09-28 00:56:48 +01:00
|
|
|
|
2010-09-27 20:34:01 +01:00
|
|
|
$form = new YammerProgressForm($this, $this->runner);
|
2010-09-28 23:45:00 +01:00
|
|
|
} else if ($this->subaction == 'pause-import') {
|
|
|
|
$this->runner->recordError(_m('Paused from admin panel.'));
|
|
|
|
$form = $this->statusForm();
|
|
|
|
} else if ($this->subaction == 'continue-import') {
|
|
|
|
$this->runner->clearError();
|
|
|
|
$this->runner->startBackgroundImport();
|
|
|
|
$form = $this->statusForm();
|
|
|
|
} else if ($this->subaction == 'abort-import') {
|
|
|
|
$this->runner->reset();
|
|
|
|
$form = $this->statusForm();
|
|
|
|
} else if ($this->subaction == 'progress') {
|
|
|
|
$form = $this->statusForm();
|
2010-09-27 20:24:10 +01:00
|
|
|
} else {
|
2011-06-19 14:02:31 +01:00
|
|
|
// TRANS: Client exception thrown when encountering an unhandled sub action.
|
|
|
|
throw new ClientException(_m('Invalid POST'));
|
2010-09-27 20:24:10 +01:00
|
|
|
}
|
2010-09-28 00:56:48 +01:00
|
|
|
return $this->showAjaxForm($form);
|
2010-09-25 01:22:44 +01:00
|
|
|
}
|
2010-09-28 00:56:48 +01:00
|
|
|
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);
|
2010-09-23 01:51:50 +01:00
|
|
|
}
|
|
|
|
|
2010-09-25 01:22:44 +01:00
|
|
|
function showAjaxForm($form)
|
2010-09-23 01:51:50 +01:00
|
|
|
{
|
2010-09-25 01:22:44 +01:00
|
|
|
$this->startHTML('text/xml;charset=utf-8');
|
|
|
|
$this->elementStart('head');
|
2011-06-19 14:02:31 +01:00
|
|
|
// TRANS: Page title for Yammer import administration panel.
|
2010-09-25 01:22:44 +01:00
|
|
|
$this->element('title', null, _m('Yammer import'));
|
|
|
|
$this->elementEnd('head');
|
|
|
|
$this->elementStart('body');
|
|
|
|
$form->show();
|
|
|
|
$this->elementEnd('body');
|
|
|
|
$this->elementEnd('html');
|
2010-09-23 01:51:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-09-28 00:56:48 +01:00
|
|
|
* Fetch the appropriate form for our current state.
|
|
|
|
* @return Form
|
2010-09-23 01:51:50 +01:00
|
|
|
*/
|
2010-09-28 00:56:48 +01:00
|
|
|
function statusForm()
|
2010-09-23 01:51:50 +01:00
|
|
|
{
|
2010-09-28 00:56:48 +01:00
|
|
|
if (!(common_config('yammer', 'consumer_key'))
|
|
|
|
|| !(common_config('yammer', 'consumer_secret'))) {
|
|
|
|
return new YammerApiKeyForm($this);
|
|
|
|
}
|
2010-09-27 20:24:10 +01:00
|
|
|
switch($this->runner->state())
|
2010-09-23 01:51:50 +01:00
|
|
|
{
|
2010-09-24 22:52:51 +01:00
|
|
|
case 'init':
|
2010-09-28 00:56:48 +01:00
|
|
|
return new YammerAuthInitForm($this, $this->runner);
|
2010-09-23 01:51:50 +01:00
|
|
|
case 'requesting-auth':
|
2010-09-28 00:56:48 +01:00
|
|
|
return new YammerAuthVerifyForm($this, $this->runner);
|
2010-09-24 22:52:51 +01:00
|
|
|
default:
|
2010-09-28 00:56:48 +01:00
|
|
|
return new YammerProgressForm($this, $this->runner);
|
2010-09-23 01:51:50 +01:00
|
|
|
}
|
2010-09-28 00:56:48 +01:00
|
|
|
}
|
2010-09-24 22:52:51 +01:00
|
|
|
|
2010-09-28 00:56:48 +01:00
|
|
|
/**
|
|
|
|
* Show the Yammer admin panel form
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
function showForm()
|
|
|
|
{
|
|
|
|
$this->elementStart('fieldset');
|
|
|
|
$this->statusForm()->show();
|
2010-09-25 01:22:44 +01:00
|
|
|
$this->elementEnd('fieldset');
|
2010-09-24 22:52:51 +01:00
|
|
|
}
|
|
|
|
|
2010-09-25 01:22:44 +01:00
|
|
|
function showStylesheets()
|
2010-09-24 22:52:51 +01:00
|
|
|
{
|
2010-09-25 01:22:44 +01:00
|
|
|
parent::showStylesheets();
|
2011-02-03 16:51:58 +00:00
|
|
|
$this->cssLink(Plugin::staticPath('YammerImport', 'css/admin.css'), null, 'screen, projection, tv');
|
2010-09-23 01:51:50 +01:00
|
|
|
}
|
|
|
|
|
2010-09-25 01:22:44 +01:00
|
|
|
function showScripts()
|
2010-09-23 01:51:50 +01:00
|
|
|
{
|
2010-09-25 01:22:44 +01:00
|
|
|
parent::showScripts();
|
2011-02-03 16:51:58 +00:00
|
|
|
$this->script(Plugin::staticPath('YammerImport', 'js/yammer-admin.js'));
|
2010-09-23 01:51:50 +01:00
|
|
|
}
|
|
|
|
}
|