]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/YammerImport/actions/yammeradminpanel.php
71651cdf5667050ce8738979375f517ab7df1a67
[quix0rs-gnu-social.git] / plugins / YammerImport / actions / yammeradminpanel.php
1 <?php
2 /**
3  * StatusNet, the distributed open-source microblogging tool
4  *
5  * Yammer import administration panel
6  *
7  * PHP version 5
8  *
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.
13  *
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.
18  *
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/>.
21  *
22  * @category  Settings
23  * @package   StatusNet
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/
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 class YammeradminpanelAction extends AdminPanelAction
35 {
36     private $runner;
37
38     /**
39      * Returns the page title
40      *
41      * @return string page title
42      */
43     function title()
44     {
45         return _m('Yammer Import');
46     }
47
48     /**
49      * Instructions for using this form.
50      *
51      * @return string instructions
52      */
53     function getInstructions()
54     {
55         return _m('Yammer import tool');
56     }
57
58     function prepare($args)
59     {
60         $ok = parent::prepare($args);
61
62         $this->init_auth = $this->trimmed('init_auth');
63         $this->verify_token = $this->trimmed('verify_token');
64         $this->runner = YammerRunner::init();
65
66         return $ok;
67     }
68
69     function handle($args)
70     {
71         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
72             $this->checkSessionToken();
73             if ($this->init_auth) {
74                 $url = $this->runner->requestAuth();
75                 $form = new YammerAuthVerifyForm($this, $this->runner);
76                 return $this->showAjaxForm($form);
77             } else if ($this->verify_token) {
78                 $this->runner->saveAuthToken($this->verify_token);
79                 $form = new YammerAuthProgressForm();
80                 return $this->showAjaxForm($form);
81             } else {
82                 throw new ClientException('Invalid POST');
83             }
84         } else {
85             return parent::handle($args);
86         }
87     }
88
89     function showAjaxForm($form)
90     {
91         $this->startHTML('text/xml;charset=utf-8');
92         $this->elementStart('head');
93         $this->element('title', null, _m('Yammer import'));
94         $this->elementEnd('head');
95         $this->elementStart('body');
96         $form->show();
97         $this->elementEnd('body');
98         $this->elementEnd('html');
99     }
100
101     /**
102      * Show the Yammer admin panel form
103      *
104      * @return void
105      */
106     function showForm()
107     {
108         $this->elementStart('fieldset');
109
110         switch($this->runner->state())
111         {
112             case 'init':
113                 $form = new YammerAuthInitForm($this, $this->runner);
114                 break;
115             case 'requesting-auth':
116                 $form = new YammerAuthVerifyForm($this, $this->runner);
117                 break;
118             default:
119                 $form = new YammerProgressForm($this, $this->runner);
120         }
121         $form->show();
122
123         $this->elementEnd('fieldset');
124     }
125
126     function showStylesheets()
127     {
128         parent::showStylesheets();
129         $this->cssLink('plugins/YammerImport/css/admin.css', null, 'screen, projection, tv');
130     }
131
132     function showScripts()
133     {
134         parent::showScripts();
135         $this->script('plugins/YammerImport/js/yammer-admin.js');
136     }
137 }