]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - plugins/YammerImport/actions/yammeradminpanel.php
Fix mising require_once (now required here because of rearranging)
[quix0rs-gnu-social.git] / plugins / YammerImport / actions / yammeradminpanel.php
index 56e721d03c6766668c6a303583fffb468e02f6d1..4714154290781bb6df6c64aa5f7f8b7e7197b879 100644 (file)
@@ -33,6 +33,8 @@ if (!defined('STATUSNET')) {
 
 class YammeradminpanelAction extends AdminPanelAction
 {
+    private $runner;
+
     /**
      * Returns the page title
      *
@@ -50,34 +52,82 @@ class YammeradminpanelAction extends AdminPanelAction
      */
     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)
     {
-        if ($this->init_auth) {
-            $url = $runner->requestAuth();
-            $form = new YammerAuthVerifyForm($this, $url);
-            return $this->showAjaxForm($form);
-        } else if ($this->verify_token) {
-            $runner->saveAuthToken($this->verify_token);
-            $form = new YammerAuthProgressForm();
+        // @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') {
+                $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 {
+                throw new ClientException('Invalid POST');
+            }
             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)
     {
         $this->startHTML('text/xml;charset=utf-8');
@@ -91,41 +141,47 @@ class YammeradminpanelAction extends AdminPanelAction
     }
 
     /**
-     * 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');
-
-        $runner = YammerRunner::init();
-
-        switch($runner->state())
+        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);
-                break;
+                return new YammerAuthInitForm($this, $this->runner);
             case 'requesting-auth':
-                $form = new YammerAuthVerifyForm($this, $runner);
-                break;
+                return new YammerAuthVerifyForm($this, $this->runner);
             default:
-                $form = new YammerProgressForm($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');
     }
 
     function showStylesheets()
     {
         parent::showStylesheets();
-        $this->cssLink('plugins/YammerImport/css/admin.css', null, 'screen, projection, tv');
+        $this->cssLink(Plugin::staticPath('YammerImport', 'css/admin.css'), null, 'screen, projection, tv');
     }
 
     function showScripts()
     {
         parent::showScripts();
-        $this->script('plugins/YammerImport/js/yammer-admin.js');
+        $this->script(Plugin::staticPath('YammerImport', 'js/yammer-admin.js'));
     }
 }