X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=plugins%2FYammerImport%2Factions%2Fyammeradminpanel.php;h=f8e099109eac36b4cc4d50cebec0ad2df926b1b8;hb=d594c83a5a9a9d42fce917b544c28591fcadb1aa;hp=875debac929d8df2c911a4b6a3e738fa80b7c9b1;hpb=472dab4a86c0ba365404b0994c3eb7e9979a80c2;p=quix0rs-gnu-social.git diff --git a/plugins/YammerImport/actions/yammeradminpanel.php b/plugins/YammerImport/actions/yammeradminpanel.php index 875debac92..f8e099109e 100644 --- a/plugins/YammerImport/actions/yammeradminpanel.php +++ b/plugins/YammerImport/actions/yammeradminpanel.php @@ -33,6 +33,8 @@ if (!defined('STATUSNET')) { class YammeradminpanelAction extends AdminPanelAction { + private $runner; + /** * Returns the page title * @@ -40,6 +42,7 @@ class YammeradminpanelAction extends AdminPanelAction */ function title() { + // TRANS: Page title for Yammer import administration panel. return _m('Yammer Import'); } @@ -50,104 +53,140 @@ class YammeradminpanelAction extends AdminPanelAction */ function getInstructions() { - return _m('Yammer import tool'); + // 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 ' . + 'transferred; in the future this may be supported for ' . + 'imports done by verified administrators on the Yammer side.'); } - /** - * Show the Yammer admin panel form - * - * @return void - */ - function showForm() + function prepare($args) { - $form = new YammerAdminPanelForm($this); - $form->show(); - return; + $ok = parent::prepare($args); + + $this->subaction = $this->trimmed('subaction'); + $this->runner = YammerRunner::init(); + + return $ok; } -} -class YammerAdminPanelForm extends AdminForm -{ - /** - * ID of the form - * - * @return string ID of the form - */ - function id() + function handle($args) { - return 'yammeradminpanel'; + // @fixme move this to saveSettings and friends? + if ($_SERVER['REQUEST_METHOD'] == 'POST') { + StatusNet::setApi(true); // short error pages :P + $this->checkSessionToken(); + 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); + } else if ($this->subaction == 'pause-import') { + // TRANS: Error message about an import job being paused from the admin panel. + $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(); + } else { + // TRANS: Client exception thrown when encountering an unhandled sub action. + throw new ClientException(_m('Invalid POST')); + } + return $this->showAjaxForm($form); + } + return parent::handle($args); } - /** - * class of the form - * - * @return string class of the form - */ - function formClass() + function saveKeys() { - return 'form_settings'; + $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); } - /** - * Action of the form - * - * @return string URL of the action - */ - function action() + function showAjaxForm($form) { - return common_local_url('yammeradminpanel'); + $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'); + $form->show(); + $this->elementEnd('body'); + $this->elementEnd('html'); } /** - * Data elements of the form - * - * @return void + * Fetch the appropriate form for our current state. + * @return Form */ - function formData() + function statusForm() { - $this->out->element('p', array(), 'yammer import IN DA HOUSE'); - - /* - Possible states of the yammer import process: - - null (not doing any sort of import) - - requesting-auth - - authenticated - - import-users - - import-groups - - fetch-messages - - import-messages - - done - */ - $yammerState = Yammer_state::staticGet('id', 1); - $state = $yammerState ? $yammerState->state || null; - - switch($state) + if (!(common_config('yammer', 'consumer_key')) + || !(common_config('yammer', 'consumer_secret'))) { + return new YammerApiKeyForm($this); + } + switch($this->runner->state()) { - case null: - $this->out->element('p', array(), 'Time to start auth:'); - $this->showAuthForm(); - break; + case 'init': + return new YammerAuthInitForm($this, $this->runner); case 'requesting-auth': - $this->out->element('p', array(), 'Need to finish auth!'); - $this->showAuthForm(); - break; - case 'import-users': - case 'import-groups': - case 'import-messages': - case 'save-messages': - $this->showImportState(); - break; - + return new YammerAuthVerifyForm($this, $this->runner); + default: + return new YammerProgressForm($this, $this->runner); } } /** - * Action elements + * Show the Yammer admin panel form * * @return void */ - function formActions() + function showForm() + { + $this->elementStart('fieldset'); + $this->statusForm()->show(); + $this->elementEnd('fieldset'); + } + + function showStylesheets() + { + parent::showStylesheets(); + $this->cssLink(Plugin::staticPath('YammerImport', 'css/admin.css'), null, 'screen, projection, tv'); + } + + function showScripts() { - // No submit buttons needed at bottom + parent::showScripts(); + $this->script(Plugin::staticPath('YammerImport', 'js/yammer-admin.js')); } }