]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Merge branch '1.0.x' into feedsub-wizard
authorBrion Vibber <brion@pobox.com>
Tue, 15 Mar 2011 23:17:48 +0000 (16:17 -0700)
committerBrion Vibber <brion@pobox.com>
Tue, 15 Mar 2011 23:17:48 +0000 (16:17 -0700)
plugins/SubMirror/SubMirrorPlugin.php
plugins/SubMirror/actions/mirrorsettings.php
plugins/SubMirror/css/mirrorsettings.css [new file with mode: 0644]
plugins/SubMirror/images/providers/facebook.png [new file with mode: 0644]
plugins/SubMirror/images/providers/feed.png [new file with mode: 0644]
plugins/SubMirror/images/providers/linkedin.png [new file with mode: 0644]
plugins/SubMirror/images/providers/statusnet.png [new file with mode: 0644]
plugins/SubMirror/images/providers/twitter.png [new file with mode: 0644]
plugins/SubMirror/images/providers/wordpress.png [new file with mode: 0644]
plugins/SubMirror/js/mirrorsettings.js [new file with mode: 0644]
plugins/SubMirror/lib/addmirrorwizard.php [new file with mode: 0644]

index 38a4c40d481aeea69e3f5a15e426221f65d7acb6..a9cb2315b45e040cb1726914b41dafc10e7e1c86 100644 (file)
@@ -35,6 +35,9 @@ class SubMirrorPlugin extends Plugin
     {
         $m->connect('settings/mirror',
                     array('action' => 'mirrorsettings'));
+        $m->connect('settings/mirror/add/:provider',
+                    array('action' => 'mirrorsettings'),
+                    array('provider' => '[A-Za-z0-9_-]+'));
         $m->connect('settings/mirror/add',
                     array('action' => 'addmirror'));
         $m->connect('settings/mirror/edit',
index 856099afa3c6aadebdb24ab4ff6dab07c9d056e6..ae09111ec4981b4b2ddf04af06ea4100bc50a2c7 100644 (file)
@@ -65,18 +65,30 @@ class MirrorSettingsAction extends SettingsAction
     function showContent()
     {
         $user = common_current_user();
+        $provider = $this->trimmed('provider');
+        if ($provider) {
+            $this->showAddFeedForm($provider);
+        } else {
+            $this->elementStart('div', array('id' => 'add-mirror'));
+            $this->showAddWizard();
+            $this->elementEnd('div');
 
-        $this->showAddFeedForm();
-
-        $mirror = new SubMirror();
-        $mirror->subscriber = $user->id;
-        if ($mirror->find()) {
-            while ($mirror->fetch()) {
-                $this->showFeedForm($mirror);
+            $mirror = new SubMirror();
+            $mirror->subscriber = $user->id;
+            if ($mirror->find()) {
+                while ($mirror->fetch()) {
+                    $this->showFeedForm($mirror);
+                }
             }
         }
     }
 
+    function showAddWizard()
+    {
+        $form = new AddMirrorWizard($this);
+        $form->show();
+    }
+
     function showFeedForm($mirror)
     {
         $profile = Profile::staticGet('id', $mirror->subscribed);
@@ -92,6 +104,30 @@ class MirrorSettingsAction extends SettingsAction
         $form->show();
     }
 
+    /**
+     *
+     * @param array $args
+     *
+     * @todo move the ajax display handling to common code
+     */
+    function handle($args)
+    {
+        if ($this->boolean('ajax')) {
+            header('Content-Type: text/html;charset=utf-8');
+            $this->elementStart('html');
+            $this->elementStart('head');
+            $this->element('title', null, _('Provider add'));
+            $this->elementEnd('head');
+            $this->elementStart('body');
+
+            $this->showAddFeedForm();
+
+            $this->elementEnd('body');
+            $this->elementEnd('html');
+        } else {
+            return parent::handle($args);
+        }
+    }
     /**
      * Handle a POST request
      *
@@ -108,4 +144,16 @@ class MirrorSettingsAction extends SettingsAction
         $nav = new SubGroupNav($this, common_current_user());
         $nav->show();
     }
+
+    function showScripts()
+    {
+        parent::showScripts();
+        $this->script('plugins/SubMirror/js/mirrorsettings.js');
+    }
+
+    function showStylesheets()
+    {
+        parent::showStylesheets();
+        $this->cssLink('plugins/SubMirror/css/mirrorsettings.css');
+    }
 }
diff --git a/plugins/SubMirror/css/mirrorsettings.css b/plugins/SubMirror/css/mirrorsettings.css
new file mode 100644 (file)
index 0000000..c91bb73
--- /dev/null
@@ -0,0 +1,26 @@
+/* undo insane stuff from core styles */
+#add-mirror-wizard img {
+    display: inline;
+}
+
+/* we need #something to override most of the #content crap */
+
+#add-mirror-wizard {
+    margin-left: 20px;
+    margin-right: 20px;
+}
+
+#add-mirror-wizard .provider-list table {
+    width: 100%;
+}
+
+#add-mirror-wizard .provider-heading img {
+    vertical-align: middle;
+}
+#add-mirror-wizard .provider-heading {
+    cursor: pointer;
+}
+#add-mirror-wizard .provider-detail fieldset {
+    margin-top: 8px; /* hack */
+    margin-bottom: 8px; /* hack */
+}
\ No newline at end of file
diff --git a/plugins/SubMirror/images/providers/facebook.png b/plugins/SubMirror/images/providers/facebook.png
new file mode 100644 (file)
index 0000000..13a53aa
Binary files /dev/null and b/plugins/SubMirror/images/providers/facebook.png differ
diff --git a/plugins/SubMirror/images/providers/feed.png b/plugins/SubMirror/images/providers/feed.png
new file mode 100644 (file)
index 0000000..bd1da4f
Binary files /dev/null and b/plugins/SubMirror/images/providers/feed.png differ
diff --git a/plugins/SubMirror/images/providers/linkedin.png b/plugins/SubMirror/images/providers/linkedin.png
new file mode 100644 (file)
index 0000000..82103d1
Binary files /dev/null and b/plugins/SubMirror/images/providers/linkedin.png differ
diff --git a/plugins/SubMirror/images/providers/statusnet.png b/plugins/SubMirror/images/providers/statusnet.png
new file mode 100644 (file)
index 0000000..6edca21
Binary files /dev/null and b/plugins/SubMirror/images/providers/statusnet.png differ
diff --git a/plugins/SubMirror/images/providers/twitter.png b/plugins/SubMirror/images/providers/twitter.png
new file mode 100644 (file)
index 0000000..41dabc8
Binary files /dev/null and b/plugins/SubMirror/images/providers/twitter.png differ
diff --git a/plugins/SubMirror/images/providers/wordpress.png b/plugins/SubMirror/images/providers/wordpress.png
new file mode 100644 (file)
index 0000000..dfafc75
Binary files /dev/null and b/plugins/SubMirror/images/providers/wordpress.png differ
diff --git a/plugins/SubMirror/js/mirrorsettings.js b/plugins/SubMirror/js/mirrorsettings.js
new file mode 100644 (file)
index 0000000..a27abe7
--- /dev/null
@@ -0,0 +1,47 @@
+$(function() {
+    /**
+     * Append 'ajax=1' parameter onto URL.
+     */
+    function ajaxize(url) {
+        if (url.indexOf('?') == '-1') {
+            return url + '?ajax=1';
+        } else {
+            return url + '&ajax=1';
+        }
+    }
+
+    var addMirror = $('#add-mirror');
+    var wizard = $('#add-mirror-wizard');
+    if (wizard.length > 0) {
+        var list = wizard.find('.provider-list');
+        var providers = list.find('.provider-heading');
+        providers.click(function(event) {
+            console.log(this);
+            var targetUrl = $(this).find('a').attr('href');
+            if (targetUrl) {
+                // Make sure we don't accidentally follow the direct link
+                event.preventDefault();
+
+                var node = this;
+                function showNew() {
+                    var detail = $('<div class="provider-detail" style="display: none"></div>').insertAfter(node);
+                    detail.load(ajaxize(targetUrl), function(responseText, testStatus, xhr) {
+                        detail.slideDown('fast', function() {
+                            detail.find('input[type="text"]').focus();
+                        });
+                    });
+                }
+
+                var old = addMirror.find('.provider-detail');
+                if (old.length) {
+                    old.slideUp('fast', function() {
+                        old.remove();
+                        showNew();
+                    });
+                } else {
+                    showNew();
+                }
+            }
+        });
+    }
+});
\ No newline at end of file
diff --git a/plugins/SubMirror/lib/addmirrorwizard.php b/plugins/SubMirror/lib/addmirrorwizard.php
new file mode 100644 (file)
index 0000000..7a63f83
--- /dev/null
@@ -0,0 +1,159 @@
+<?php
+/**
+ * StatusNet, the distributed open-source microblogging tool
+ * PHP version 5
+ *
+ * LICENCE: This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * @package   StatusNet
+ * @copyright 2010-2011 StatusNet, Inc.
+ * @license   http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
+ * @link      http://status.net/
+ */
+
+if (!defined('STATUSNET') && !defined('LACONICA')) {
+    exit(1);
+}
+
+class AddMirrorWizard extends Widget
+{
+    /**
+     * Name of the form
+     *
+     * Sub-classes should overload this with the name of their form.
+     *
+     * @return void
+     */
+    function formLegend()
+    {
+    }
+
+    /**
+     * Visible or invisible data elements
+     *
+     * Display the form fields that make up the data of the form.
+     * Sub-classes should overload this to show their data.
+     *
+     * @return void
+     */
+    function show()
+    {
+        $this->out->elementStart('div', array('id' => 'add-mirror-wizard'));
+
+        $providers = $this->providers();
+        $this->showProviders($providers);
+
+        $this->out->elementEnd('div');
+    }
+
+    function providers()
+    {
+        return array(
+            array(
+                'id' => 'statusnet',
+                'name' => _m('StatusNet'),
+            ),
+            array(
+                'id' => 'twitter',
+                'name' => _m('Twitter'),
+            ),
+            array(
+                'id' => 'wordpress',
+                'name' => _m('WordPress'),
+            ),
+            array(
+                'id' => 'linkedin',
+                'name' => _m('LinkedIn'),
+            ),
+            array(
+                'id' => 'feed',
+                'name' => _m('RSS or Atom feed'),
+            ),
+        );
+    }
+
+    function showProviders(array $providers)
+    {
+        $out = $this->out;
+
+        $out->elementStart('div', 'provider-list');
+        $out->element('h2', null, _m('Select a feed provider'));
+        $out->elementStart('table');
+        foreach ($providers as $provider) {
+            $icon = common_path('plugins/SubMirror/images/providers/' . $provider['id'] . '.png');
+            $targetUrl = common_local_url('mirrorsettings', array('provider' => $provider['id']));
+
+            $out->elementStart('tr', array('class' => 'provider'));
+            $out->elementStart('td');
+
+            $out->elementStart('div', 'provider-heading');
+            $out->element('img', array('src' => $icon));
+            $out->element('a', array('href' => $targetUrl), $provider['name']);
+            $out->elementEnd('div');
+
+            $out->elementEnd('td');
+            $out->elementEnd('tr');
+        }
+        $out->elementEnd('table');
+        $out->elementEnd('div');
+    }
+
+    /**
+     * Buttons for form actions
+     *
+     * Submit and cancel buttons (or whatever)
+     * Sub-classes should overload this to show their own buttons.
+     *
+     * @return void
+     */
+    function formActions()
+    {
+    }
+
+    /**
+     * ID of the form
+     *
+     * Should be unique on the page. Sub-classes should overload this
+     * to show their own IDs.
+     *
+     * @return string ID of the form
+     */
+    function id()
+    {
+        return 'add-mirror-wizard';
+    }
+
+    /**
+     * Action of the form.
+     *
+     * URL to post to. Should be overloaded by subclasses to give
+     * somewhere to post to.
+     *
+     * @return string URL to post to
+     */
+    function action()
+    {
+        return common_local_url('addmirror');
+    }
+
+    /**
+     * Class of the form.
+     *
+     * @return string the form's class
+     */
+    function formClass()
+    {
+        return 'form_settings';
+    }
+}