3 * StatusNet, the distributed open-source microblogging tool
5 * Yammer import administration panel
9 * LICENCE: This program is free software: you can redistribute it and/or modify
10 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation, either version 3 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Affero General Public License for more details.
19 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * @author Zach Copley <zach@status.net>
25 * @copyright 2010 StatusNet, Inc.
26 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
27 * @link http://status.net/
30 if (!defined('STATUSNET')) {
34 class YammeradminpanelAction extends AdminPanelAction
39 * Returns the page title
41 * @return string page title
45 return _m('Yammer Import');
49 * Instructions for using this form.
51 * @return string instructions
53 function getInstructions()
55 return _m('This Yammer import tool is still undergoing testing, ' .
56 'and is incomplete in some areas. ' .
57 'Currently user subscriptions and group memberships are not ' .
58 'transferred; in the future this may be supported for ' .
59 'imports done by verified administrators on the Yammer side.');
62 function prepare($args)
64 $ok = parent::prepare($args);
66 $this->subaction = $this->trimmed('subaction');
67 $this->runner = YammerRunner::init();
72 function handle($args)
74 // @fixme move this to saveSettings and friends?
75 if ($_SERVER['REQUEST_METHOD'] == 'POST') {
76 $this->checkSessionToken();
77 if ($this->subaction == 'change-apikey') {
78 $form = new YammerApiKeyForm($this);
79 } else if ($this->subaction == 'apikey') {
80 if ($this->saveKeys()) {
81 $form = new YammerAuthInitForm($this, $this->runner);
83 $form = new YammerApiKeyForm($this);
85 } else if ($this->subaction == 'authinit') {
87 if ($this->arg('change-apikey')) {
88 $form = new YammerApiKeyForm($this);
90 $url = $this->runner->requestAuth();
91 $form = new YammerAuthVerifyForm($this, $this->runner);
93 } else if ($this->subaction == 'authverify') {
94 $this->runner->saveAuthToken($this->trimmed('verify_token'));
96 // Haho! Now we can make THE FUN HAPPEN
97 $this->runner->startBackgroundImport();
99 $form = new YammerProgressForm($this, $this->runner);
101 throw new ClientException('Invalid POST');
103 return $this->showAjaxForm($form);
105 return parent::handle($args);
110 $key = $this->trimmed('consumer_key');
111 $secret = $this->trimmed('consumer_secret');
112 Config::save('yammer', 'consumer_key', $key);
113 Config::save('yammer', 'consumer_secret', $secret);
115 return !empty($key) && !empty($secret);
118 function showAjaxForm($form)
120 $this->startHTML('text/xml;charset=utf-8');
121 $this->elementStart('head');
122 $this->element('title', null, _m('Yammer import'));
123 $this->elementEnd('head');
124 $this->elementStart('body');
126 $this->elementEnd('body');
127 $this->elementEnd('html');
131 * Fetch the appropriate form for our current state.
134 function statusForm()
136 if (!(common_config('yammer', 'consumer_key'))
137 || !(common_config('yammer', 'consumer_secret'))) {
138 return new YammerApiKeyForm($this);
140 switch($this->runner->state())
143 return new YammerAuthInitForm($this, $this->runner);
144 case 'requesting-auth':
145 return new YammerAuthVerifyForm($this, $this->runner);
147 return new YammerProgressForm($this, $this->runner);
152 * Show the Yammer admin panel form
158 $this->elementStart('fieldset');
159 $this->statusForm()->show();
160 $this->elementEnd('fieldset');
163 function showStylesheets()
165 parent::showStylesheets();
166 $this->cssLink('plugins/YammerImport/css/admin.css', null, 'screen, projection, tv');
169 function showScripts()
171 parent::showScripts();
172 $this->script('plugins/YammerImport/js/yammer-admin.js');