}
$accounts = PluginHost::getInstance()->get($this, 'accounts', []);
+ if (isset($_REQUEST['accordion'])
+ && $_REQUEST['accordion'] == 'micropub'
+ ) {
+ $accordionActive = 'selected="true"';
+ } else {
+ $accordionActive = '';
+ }
//FIXME: default identity
include __DIR__ . '/settings.phtml';
}
+ public function get_prefs_js()
+ {
+ return file_get_contents(__DIR__ . '/settings.js');
+ }
+
/**
* CLI command
*/
return $this->authreturnAction();
} else if ($mode == 'post') {
return $this->postAction();
+ } else if ($mode == 'deleteIdentity') {
+ return $this->deleteIdentityAction();
} else {
return $this->errorOut('Unsupported mode');
}
if (!isset($_POST['me'])) {
return $this->errorOut('"me" parameter missing');
}
- $me = $_POST['me'];
+ $me = trim($_POST['me']);
if (!isset($_POST['replyTo'])) {
return $this->errorOut('"replyTo" parameter missing');
}
- $replyTo = $_POST['replyTo'];
+ $replyTo = trim($_POST['replyTo']);
if (!isset($_POST['content'])) {
return $this->errorOut('"content" parameter missing');
}
- $content = $_POST['content'];
+ $content = trim($_POST['content']);
$accounts = PluginHost::getInstance()->get($this, 'accounts', []);
if (!isset($accounts[$me])) {
$host->set($this, 'accounts', $accounts);
//all fine now.
- header('Location: prefs.php');
+ //the accordion parameter will never work
+ // because fox has serious mental problems
+ // https://discourse.tt-rss.org/t/open-a-certain-accordion-in-preferences-by-url-parameter/234
+ header('Location: prefs.php?accordion=micropub');
+ }
+
+ /**
+ * Backend preferences action: Remove a given account
+ */
+ protected function deleteIdentityAction()
+ {
+ if (!isset($_POST['me'])) {
+ return $this->errorOut('"me" parameter missing');
+ }
+ $me = trim($_POST['me']);
+
+ $host = PluginHost::getInstance();
+ $accounts = $host->get($this, 'accounts', []);
+ if (!isset($accounts[$me])) {
+ return $this->errorOut('Unknown identity');
+ }
+
+ unset($accounts[$me]);
+ $host->set($this, 'accounts', $accounts);
+ header('Content-type: application/json');
+
+ echo json_encode(
+ [
+ 'code' => '200',
+ 'message' => 'Identity removed',
+ ]
+ );
+ exit();
}
/**
--- /dev/null
+/**
+ * Delete a given account
+ */
+function micropubDeleteIdentity(accountUrl)
+{
+ new Ajax.Request('backend.php', {
+ parameters: {
+ 'op': 'pluginhandler',
+ 'plugin': 'micropub',
+ 'method': 'action',
+ 'mode': 'deleteIdentity',
+ 'me': accountUrl,
+ },
+ onSuccess: function(transport) {
+ notify_info('Account removed');
+ var elems = dojo.query('tr[data-url="' + accountUrl + '"]');
+ if (elems.length > 0) {
+ elems.first().remove();
+ }
+ },
+ onFailure: function(transport) {
+ notify_error(transport.responseText);
+ }
+ });
+}
-<div dojoType="dijit.layout.AccordionPane" title="Micropub">
+<div dojoType="dijit.layout.AccordionPane" title="Micropub" id="micropub" <?= $accordionActive ?>>
<div>
<h2>Registered identities</h2>
<table width="100%">
<tr class="title">
<td width="5%">Default</td>
<td>Identity URL</td>
+ <td width="5%"></td>
</tr>
</thead>
<tbody>
<?php foreach ($accounts as $accurl => $account) { ?>
- <tr>
+ <tr data-url="<?= htmlspecialchars($accurl) ?>">
<td align='center'>
<input disabled='1' dojoType="dijit.form.CheckBox" type="checkbox"/>
</td>
<td>
<a href="<?= htmlspecialchars($accurl) ?>"><?= htmlspecialchars($accurl) ?></a>
</td>
+ <td>
+ <a href="#" onclick='javascript:micropubDeleteIdentity(<?= json_encode($accurl) ?>)'>Remove</a>
+ </td>
</tr>
<?php } ?>
</tbody>