{
$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',
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);
$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
*
$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');
+ }
}
--- /dev/null
+/* 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
--- /dev/null
+$(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
--- /dev/null
+<?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';
+ }
+}