]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Yammer import API keys can now be overridden by the admin.
authorBrion Vibber <brion@pobox.com>
Mon, 27 Sep 2010 23:56:48 +0000 (16:56 -0700)
committerBrion Vibber <brion@pobox.com>
Tue, 28 Sep 2010 14:44:25 +0000 (07:44 -0700)
plugins/YammerImport/YammerImportPlugin.php
plugins/YammerImport/actions/yammeradminpanel.php
plugins/YammerImport/css/admin.css
plugins/YammerImport/lib/yammerapikeyform.php [new file with mode: 0644]
plugins/YammerImport/lib/yammerauthinitform.php
plugins/YammerImport/lib/yammerauthverifyform.php
plugins/YammerImport/scripts/yamdump.php [deleted file]

index 547870936b7d776200b0e71145f1990c1dfc9d9e..98c6ecd0ab13349f97fb884a47eb713039489aa7 100644 (file)
@@ -119,6 +119,7 @@ class YammerImportPlugin extends Plugin
         case 'sn_yammerclient':
         case 'yammerimporter':
         case 'yammerrunner':
+        case 'yammerapikeyform':
         case 'yammerauthinitform':
         case 'yammerauthverifyform':
         case 'yammerprogressform':
index 04ef26d512f86cee3c6f1a35a50de4269951c87a..13960d905109a103cab1f5c7060cf004c95a5b91 100644 (file)
@@ -52,15 +52,18 @@ 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;
@@ -68,26 +71,48 @@ class YammeradminpanelAction extends AdminPanelAction
 
     function handle($args)
     {
+        // @fixme move this to saveSettings and friends?
         if ($_SERVER['REQUEST_METHOD'] == 'POST') {
             $this->checkSessionToken();
-            if ($this->init_auth) {
-                $url = $this->runner->requestAuth();
-                $form = new YammerAuthVerifyForm($this, $this->runner);
-                return $this->showAjaxForm($form);
-            } else if ($this->verify_token) {
-                $this->runner->saveAuthToken($this->verify_token);
-                
+            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);
-                return $this->showAjaxForm($form);
             } else {
                 throw new ClientException('Invalid POST');
             }
-        } else {
-            return parent::handle($args);
+            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)
@@ -103,27 +128,35 @@ 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');
-
+        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, $this->runner);
-                break;
+                return new YammerAuthInitForm($this, $this->runner);
             case 'requesting-auth':
-                $form = new YammerAuthVerifyForm($this, $this->runner);
-                break;
+                return new YammerAuthVerifyForm($this, $this->runner);
             default:
-                $form = new YammerProgressForm($this, $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');
     }
 
index 4c1aaacd64fcb19aee6901997f6110b20238ae50..9c99a0b880f9d6d57c20f79b5a4acd9d7a160f70 100644 (file)
@@ -49,3 +49,7 @@
     /* override */
     background: none !important;
 }
+
+.magiclink {
+    margin-left: 40px;
+}
\ No newline at end of file
diff --git a/plugins/YammerImport/lib/yammerapikeyform.php b/plugins/YammerImport/lib/yammerapikeyform.php
new file mode 100644 (file)
index 0000000..b2acec4
--- /dev/null
@@ -0,0 +1,112 @@
+<?php
+
+class YammerApikeyForm extends Form
+{
+    private $runner;
+
+    function __construct($out)
+    {
+        parent::__construct($out);
+        $this->runner = $runner;
+    }
+
+    /**
+     * ID of the form
+     *
+     * @return int ID of the form
+     */
+
+    function id()
+    {
+        return 'yammer-apikey-form';
+    }
+
+
+    /**
+     * class of the form
+     *
+     * @return string of the form class
+     */
+
+    function formClass()
+    {
+        return 'form_yammer_apikey form_settings';
+    }
+
+
+    /**
+     * Action of the form
+     *
+     * @return string URL of the action
+     */
+
+    function action()
+    {
+        return common_local_url('yammeradminpanel');
+    }
+
+
+    /**
+     * Legend of the Form
+     *
+     * @return void
+     */
+    function formLegend()
+    {
+        $this->out->element('legend', null, _m('Yammer API registration'));
+    }
+
+    /**
+     * Data elements of the form
+     *
+     * @return void
+     */
+
+    function formData()
+    {
+        $this->out->hidden('subaction', 'apikey');
+
+        $this->out->elementStart('fieldset');
+
+        $this->out->elementStart('p');
+        $this->out->text(_m('Before we can connect to your Yammer network, ' .
+                            'you will need to register the importer as an ' .
+                            'application authorized to pull data on your behalf. ' .
+                            'This registration will work only for your own network. ' .
+                            'Follow this link to register the app at Yammer; ' .
+                            'you will be prompted to log in if necessary:'));
+        $this->out->elementEnd('p');
+
+        $this->out->elementStart('p', array('class' => 'magiclink'));
+        $this->out->element('a',
+            array('href' => 'https://www.yammer.com/client_applications/new',
+                  'target' => '_blank'),
+            _m('Open Yammer application registration form'));
+        $this->out->elementEnd('p');
+
+        $this->out->element('p', array(), _m('Copy the consumer key and secret you are given into the form below:'));
+
+        $this->out->elementStart('ul', array('class' => 'form_data'));
+        $this->out->elementStart('li');
+        $this->out->input('consumer_key', _m('Consumer key:'), common_config('yammer', 'consumer_key'));
+        $this->out->elementEnd('li');
+        $this->out->elementStart('li');
+        $this->out->input('consumer_secret', _m('Consumer secret:'), common_config('yammer', 'consumer_secret'));
+        $this->out->elementEnd('li');
+        $this->out->elementEnd('ul');
+
+        $this->out->submit('submit', _m('Save'), 'submit', null, _m('Save these consumer keys'));
+
+        $this->out->elementEnd('fieldset');
+    }
+
+    /**
+     * Action elements
+     *
+     * @return void
+     */
+
+    function formActions()
+    {
+    }
+}
index 5a83a06c2132f7c217d3b775b649585797b0c8b1..9f48fd82a5b7992af2db51c598e171f5e36d4f97 100644 (file)
@@ -22,7 +22,7 @@ class YammerAuthInitForm extends Form
 
     function formClass()
     {
-        return 'form_yammer_auth_init';
+        return 'form_yammer_auth_init form_settings';
     }
 
 
@@ -56,7 +56,12 @@ class YammerAuthInitForm extends Form
 
     function formData()
     {
-        $this->out->hidden('init_auth', '1');
+        $this->out->hidden('subaction', 'authinit');
+
+        $this->out->elementStart('fieldset');
+        $this->out->submit('submit', _m('Start authentication'), 'submit', null, _m('Request authorization to connect to Yammer account'));
+        $this->out->submit('change-apikey', _m('Change API key'));
+        $this->out->elementEnd('fieldset');
     }
 
     /**
@@ -67,6 +72,5 @@ class YammerAuthInitForm extends Form
 
     function formActions()
     {
-        $this->out->submit('submit', _m('Connect to Yammer'), 'submit', null, _m('Request authorization to connect to Yammer account'));
     }
 }
index 2b3efbcb1a0bfc404c546086e7ad9212d3f7fdf4..e119be96f72f53069959c6af818002417fc6722e 100644 (file)
@@ -30,7 +30,7 @@ class YammerAuthVerifyForm extends Form
 
     function formClass()
     {
-        return 'form_yammer_auth_verify';
+        return 'form_yammer_auth_verify form_settings';
     }
 
 
@@ -64,27 +64,39 @@ class YammerAuthVerifyForm extends Form
 
     function formData()
     {
+        $this->out->hidden('subaction', 'authverify');
+
+        $this->out->elementStart('fieldset');
+
         $this->out->elementStart('p');
         $this->out->text(_m('Follow this link to confirm authorization at Yammer; you will be prompted to log in if necessary:'));
         $this->out->elementEnd('p');
 
-        $this->out->elementStart('blockquote');
+        // iframe would be nice to avoid leaving -- since they don't seem to have callback url O_O
+        /*
+        $this->out->element('iframe', array('id' => 'yammer-oauth',
+                                            'src' => $this->runner->getAuthUrl()));
+        */
+        // yeah, it ignores the callback_url
+        // soo... crappy link. :(
+
+        $this->out->elementStart('p', array('class' => 'magiclink'));
         $this->out->element('a',
             array('href' => $this->runner->getAuthUrl(),
                   'target' => '_blank'),
             _m('Open Yammer authentication window'));
-        $this->out->elementEnd('blockquote');
+        $this->out->elementEnd('p');
         
-        $this->out->element('p', array(), _m('Copy the verification code you are given into the form below:'));
+        $this->out->element('p', array(), _m('Copy the verification code you are given below:'));
 
+        $this->out->elementStart('ul', array('class' => 'form_data'));
+        $this->out->elementStart('li');
         $this->out->input('verify_token', _m('Verification code:'));
+        $this->out->elementEnd('li');
+        $this->out->elementEnd('ul');
         
-        // iframe would be nice to avoid leaving -- since they don't seem to have callback url O_O
-        /*
-        $this->out->element('iframe', array('id' => 'yammer-oauth',
-                                            'src' => $this->runner->getAuthUrl()));
-        */
-        // yeah, it ignores the callback_url
+        $this->out->submit('submit', _m('Continue'), 'submit', null, _m('Save code and begin import'));
+        $this->out->elementEnd('fieldset');
     }
 
     /**
@@ -95,6 +107,5 @@ class YammerAuthVerifyForm extends Form
 
     function formActions()
     {
-        $this->out->submit('submit', _m('Verify code'), 'submit', null, _m('Verification code'));
     }
 }
diff --git a/plugins/YammerImport/scripts/yamdump.php b/plugins/YammerImport/scripts/yamdump.php
deleted file mode 100644 (file)
index 944ee2e..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-<?php
-
-if (php_sapi_name() != 'cli') {
-    die('no');
-}
-
-define('INSTALLDIR', dirname(dirname(dirname(dirname(__FILE__)))));
-
-require INSTALLDIR . "/scripts/commandline.inc";
-
-// temp stuff
-require 'yam-config.php';
-$yam = new SN_YammerClient($consumerKey, $consumerSecret, $token, $tokenSecret);
-$imp = new YammerImporter($yam);
-
-/*
-$data = $yam->users();
-var_dump($data);
-// @fixme follow paging
-foreach ($data as $item) {
-    $user = $imp->prepUser($item);
-    var_dump($user);
-}
-*/
-
-$data = $yam->messages(array('newer_than' => 1));
-var_dump($data);
-// @fixme follow paging
-$messages = $data['messages'];
-$messages = array_reverse($messages);
-foreach ($messages as $message) {
-    $notice = $imp->prepNotice($message);
-    var_dump($notice);
-}