[various] Convert connector_settings hook functions to the new data array format

- Add separate template files to several addons
- Remove superfluous addon settings CSS files
pull/1210/head
Hypolite Petovan 1 year ago
parent 779b38ec09
commit 9acfdb4090

@ -1,16 +0,0 @@
#diaspora-enable-label, #diaspora-username-label, #diaspora-password-label, #diaspora-bydefault-label, #diaspora-aspect-label {
float: left;
width: 200px;
margin-top: 10px;
}
#diaspora-checkbox, #diaspora-username, #diaspora-password, #diaspora-bydefault, #diaspora-aspect {
float: left;
margin-top: 10px;
}
#diaspora-submit {
margin-top: 15px;
}

@ -48,22 +48,20 @@ function diaspora_jot_nets(App $a, array &$jotnets_fields)
}
}
function diaspora_settings(App $a, &$s)
function diaspora_settings(App $a, array &$data)
{
if (! local_user()) {
if (!local_user()) {
return;
}
/* Get the current state of our config variables */
$enabled = DI::pConfig()->get(local_user(),'diaspora','post');
$def_enabled = DI::pConfig()->get(local_user(),'diaspora','post_by_default');
$enabled = DI::pConfig()->get(local_user(), 'diaspora', 'post', false);
$def_enabled = DI::pConfig()->get(local_user(), 'diaspora', 'post_by_default');
$handle = DI::pConfig()->get(local_user(), 'diaspora', 'handle');
$handle = DI::pConfig()->get(local_user(), 'diaspora', 'handle');
$password = DI::pConfig()->get(local_user(), 'diaspora', 'password');
$aspect = DI::pConfig()->get(local_user(),'diaspora','aspect');
$aspect = DI::pConfig()->get(local_user(), 'diaspora', 'aspect');
$info = '';
$info = '';
$error = '';
if (Session::get('my_address')) {
$info = DI::l10n()->t('Please remember: You can always be reached from Diaspora with your Friendica handle <strong>%s</strong>. ', Session::get('my_address'));
@ -79,37 +77,44 @@ function diaspora_settings(App $a, &$s)
if ($rawAspects) {
$availableAspects = [
'all_aspects' => DI::l10n()->t('All aspects'),
'public' => DI::l10n()->t('Public'),
'public' => DI::l10n()->t('Public'),
];
foreach ($rawAspects as $rawAspect) {
$availableAspects[$rawAspect->id] = $rawAspect->name;
}
$aspect_select = ['aspect', DI::l10n()->t('Post to aspect:'), $aspect, '', $availableAspects];
$info = DI::l10n()->t('Connected with your Diaspora account <strong>%s</strong>', $handle);
$info = DI::l10n()->t('Connected with your Diaspora account <strong>%s</strong>', $handle);
} else {
$info = '';
$info = '';
$error = DI::l10n()->t("Can't login to your Diaspora account. Please check handle (in the format user@domain.tld) and password.");
}
}
DI::page()->registerStylesheet(__DIR__ . '/diaspora.css');
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/diaspora/');
$s .= Renderer::replaceMacros($t, [
'$header' => DI::l10n()->t('Diaspora Export'),
'$info_header' => DI::l10n()->t('Information'),
'$error_header' => DI::l10n()->t('Error'),
'$submit' => DI::l10n()->t('Save Settings'),
'$info' => $info,
'$error' => $error,
'$enabled' => $enabled,
'$enabled_checkbox' => ['enabled', DI::l10n()->t('Enable Diaspora Post Addon'), $enabled],
'$handle' => ['handle', DI::l10n()->t('Diaspora handle'), $handle, null, null, 'placeholder="user@domain.tld"'],
'$password' => ['password', DI::l10n()->t('Diaspora password'), '', DI::l10n()->t('Privacy notice: Your Diaspora password will be stored unencrypted to authenticate you with your Diaspora pod. This means your Friendica node administrator can have access to it.')],
'$aspect_select' => $aspect_select,
'$post_by_default' => ['post_by_default', DI::l10n()->t('Post to Diaspora by default'), $def_enabled],
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/diaspora/');
$html = Renderer::replaceMacros($t, [
'$l10n' => [
'info_header' => DI::l10n()->t('Information'),
'error_header' => DI::l10n()->t('Error'),
],
'$info' => $info,
'$error' => $error,
'$enabled' => ['enabled', DI::l10n()->t('Enable Diaspora Post Addon'), $enabled],
'$handle' => ['handle', DI::l10n()->t('Diaspora handle'), $handle, null, null, 'placeholder="user@domain.tld"'],
'$password' => ['password', DI::l10n()->t('Diaspora password'), '', DI::l10n()->t('Privacy notice: Your Diaspora password will be stored unencrypted to authenticate you with your Diaspora pod. This means your Friendica node administrator can have access to it.')],
'$aspect_select' => $aspect_select,
'$post_by_default' => ['post_by_default', DI::l10n()->t('Post to Diaspora by default'), $def_enabled],
]);
$data = [
'connector' => 'diaspora',
'title' => DI::l10n()->t('Diaspora Export'),
'image' => 'images/diaspora-logo.png',
'enabled' => $enabled,
'html' => $html,
];
}

@ -0,0 +1,32 @@
{{if $info}}
<div class="panel panel-info">
<div class="panel-heading">
<h4 class="panel-title">{{$l10n.info_header}}</h4>
</div>
<p class="panel-body">
{{$info nofilter}}
</p>
</div>
{{/if}}
{{if $error}}
<div class="panel panel-danger">
<div class="panel-heading">
<h4 class="panel-title">{{$l10n.error_header}}</h4>
</div>
<p class="panel-body">
{{$error nofilter}}
</p>
</div>
{{/if}}
{{include file="field_checkbox.tpl" field=$enabled}}
{{if $aspect_select}}
{{include file="field_select.tpl" field=$aspect_select}}
{{include file="field_checkbox.tpl" field=$post_by_default}}
{{else}}
{{include file="field_input.tpl" field=$handle}}
{{include file="field_password.tpl" field=$password}}
{{/if}}

@ -1,47 +0,0 @@
<span id="settings_diaspora_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose('settings_diaspora_expanded'); openClose('settings_diaspora_inflated');">
<img class="connector{{if !$enabled}}-disabled{{/if}}" src="images/diaspora-logo.png">
<h3 class="connector">{{$header}}</h3>
</span>
<div id="settings_diaspora_expanded" class="settings-block" style="display: none;">
<span class="fakelink" onclick="openClose('settings_diaspora_expanded'); openClose('settings_diaspora_inflated');">
<img class="connector{{if !$enabled}}-disabled{{/if}}" src="images/diaspora-logo.png">
<h3 class="connector">{{$header}}</h3>
</span>
{{if $info}}
<div class="panel panel-info">
<div class="panel-heading">
<h4 class="panel-title">{{$info_header}}</h4>
</div>
<p class="panel-body">
{{$info nofilter}}
</p>
</div>
{{/if}}
{{if $error}}
<div class="panel panel-danger">
<div class="panel-heading">
<h4 class="panel-title">{{$error_header}}</h4>
</div>
<p class="panel-body">
{{$error nofilter}}
</p>
</div>
{{/if}}
{{include file="field_checkbox.tpl" field=$enabled_checkbox}}
{{if $aspect_select}}
{{include file="field_select.tpl" field=$aspect_select}}
{{include file="field_checkbox.tpl" field=$post_by_default}}
{{else}}
{{include file="field_input.tpl" field=$handle}}
{{include file="field_password.tpl" field=$password}}
{{/if}}
<div class="settings-submit-wrapper">
<button type="submit" class="btn btn-primary settings-submit" id="diaspora-submit" name="diaspora-submit" value="diaspora-submit">{{$submit}}</button>
</div>
</div>

@ -36,7 +36,7 @@ function discourse_install()
Hook::register('connector_settings_post', __FILE__, 'discourse_settings_post');
}
function discourse_settings(App $a, &$s)
function discourse_settings(App $a, array &$data)
{
if (!local_user()) {
return;
@ -44,12 +44,18 @@ function discourse_settings(App $a, &$s)
$enabled = intval(DI::pConfig()->get(local_user(), 'discourse', 'enabled'));
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/discourse/');
$s .= Renderer::replaceMacros($t, [
'$title' => DI::l10n()->t('Discourse'),
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/discourse/');
$html = Renderer::replaceMacros($t, [
'$enabled' => ['enabled', DI::l10n()->t('Enable processing of Discourse mailing list mails'), $enabled, DI::l10n()->t('If enabled, incoming mails from Discourse will be improved so they look much better. To make it work, you have to configure the e-mail settings in Friendica. You also have to enable the mailing list mode in Discourse. Then you have to add the Discourse mail account as contact.')],
'$submit' => DI::l10n()->t('Save Settings'),
]);
$data = [
'connector' => 'discourse',
'title' => DI::l10n()->t('Discourse'),
'image' => 'images/discourse.png',
'enabled' => $enabled,
'html' => $html,
];
}
function discourse_settings_post(App $a)

@ -0,0 +1 @@
{{include file="field_checkbox.tpl" field=$enabled}}

@ -1,15 +0,0 @@
<span id="settings_discourse_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose('settings_discourse_expanded'); openClose('settings_discourse_inflated');">
<img class="connector{{if ! $enabled.2}}-disabled{{/if}}" src="images/discourse.png" /><h3 class="connector">{{$title}}</h3>
</span>
<div id="settings_discourse_expanded" class="settings-block" style="display: none;">
<span class="fakelink" onclick="openClose('settings_discourse_expanded'); openClose('settings_discourse_inflated');">
<img class="connector{{if ! $enabled.2}}-disabled{{/if}}" src="images/discourse.png" /><h3 class="connector">{{$title}}</h3>
</span>
<div id="discourse-wrapper">
{{include file="field_checkbox.tpl" field=$enabled}}
</div>
<div class="settings-submit-wrapper" >
<input type="submit" id="discourse-submit" name="discourse-submit" class="settings-submit" value="{{$submit}}" />
</div>
</div>

@ -1,15 +0,0 @@
#dwpost-enable-label, #dwpost-username-label, #dwpost-password-label, #dwpost-bydefault-label {
float: left;
width: 200px;
margin-top: 10px;
}
#dwpost-checkbox, #dwpost-username, #dwpost-password, #dwpost-bydefault {
float: left;
margin-top: 10px;
}
#dwpost-submit {
margin-top: 15px;
}

@ -12,7 +12,7 @@ use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Database\DBA;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Model\Tag;
@ -48,58 +48,31 @@ function dwpost_jot_nets(App $a, array &$jotnets_fields)
}
function dwpost_settings(App $a, &$s)
function dwpost_settings(App $a, array &$data)
{
if (!local_user()) {
return;
}
/* Add our stylesheet to the page so we can make our settings look nice */
DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/dwpost/dwpost.css' . '" media="all" />' . "\r\n";
/* Get the current state of our config variables */
$enabled = DI::pConfig()->get(local_user(), 'dwpost', 'post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$enabled = DI::pConfig()->get(local_user(), 'dwpost', 'post', false);
$dw_username = DI::pConfig()->get(local_user(), 'dwpost', 'dw_username');
$def_enabled = DI::pConfig()->get(local_user(), 'dwpost', 'post_by_default');
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
$dw_username = DI::pConfig()->get(local_user(), 'dwpost', 'dw_username');
$dw_password = DI::pConfig()->get(local_user(), 'dwpost', 'dw_password');
/* Add some HTML to the existing form */
$s .= '<span id="settings_dwpost_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_dwpost_expanded\'); openClose(\'settings_dwpost_inflated\');">';
$s .= '<img class="connector" src="images/dreamwidth.png" /><h3 class="connector">'. DI::l10n()->t("Dreamwidth Export").'</h3>';
$s .= '</span>';
$s .= '<div id="settings_dwpost_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_dwpost_expanded\'); openClose(\'settings_dwpost_inflated\');">';
$s .= '<img class="connector" src="images/dreamwidth.png" /><h3 class="connector">'. DI::l10n()->t("Dreamwidth Export").'</h3>';
$s .= '</span>';
$s .= '<div id="dwpost-enable-wrapper">';
$s .= '<label id="dwpost-enable-label" for="dwpost-checkbox">' . DI::l10n()->t('Enable dreamwidth Post Addon') . '</label>';
$s .= '<input id="dwpost-checkbox" type="checkbox" name="dwpost" value="1" ' . $checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="dwpost-username-wrapper">';
$s .= '<label id="dwpost-username-label" for="dwpost-username">' . DI::l10n()->t('dreamwidth username') . '</label>';
$s .= '<input id="dwpost-username" type="text" name="dw_username" value="' . $dw_username . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="dwpost-password-wrapper">';
$s .= '<label id="dwpost-password-label" for="dwpost-password">' . DI::l10n()->t('dreamwidth password') . '</label>';
$s .= '<input id="dwpost-password" type="password" name="dw_password" value="' . $dw_password . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="dwpost-bydefault-wrapper">';
$s .= '<label id="dwpost-bydefault-label" for="dwpost-bydefault">' . DI::l10n()->t('Post to dreamwidth by default') . '</label>';
$s .= '<input id="dwpost-bydefault" type="checkbox" name="dw_bydefault" value="1" ' . $def_checked . '/>';
$s .= '</div><div class="clear"></div>';
/* provide a submit button */
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="dwpost-submit" name="dwpost-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div></div>';
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/dwpost/');
$html = Renderer::replaceMacros($t, [
'$enabled' => ['dwpost', DI::l10n()->t('Enable Dreamwidth Post Addon'), $enabled],
'$username' => ['dw_username', DI::l10n()->t('Dreamwidth username'), $dw_username],
'$password' => ['dw_password', DI::l10n()->t('Dreamwidth password')],
'$bydefault' => ['dw_bydefault', DI::l10n()->t('Post to Dreamwidth by default'), $def_enabled],
]);
$data = [
'connector' => 'dwpost',
'title' => DI::l10n()->t('Dreamwidth Export'),
'image' => 'images/dreamwidth.png',
'enabled' => $enabled,
'html' => $html,
];
}

@ -0,0 +1,4 @@
{{include file="field_checkbox.tpl" field=$enabled}}
{{include file="field_input.tpl" field=$username}}
{{include file="field_password.tpl" field=$password}}
{{include file="field_checkbox.tpl" field=$bydefault}}

@ -11,6 +11,7 @@ use Friendica\Content\PageInfo;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
@ -33,55 +34,47 @@ function ifttt_content()
}
function ifttt_settings(App $a, &$s)
function ifttt_settings(App $a, array &$data)
{
if (!local_user()) {
return;
}
$key = DI::pConfig()->get(local_user(), 'ifttt', 'key');
if (!$key) {
$key = Strings::getRandomHex(20);
DI::pConfig()->set(local_user(), 'ifttt', 'key', $key);
}
$s .= '<span id="settings_ifttt_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_ifttt_expanded\'); openClose(\'settings_ifttt_inflated\');">';
$s .= '<img class="connector" src="addon/ifttt/ifttt.png" /><h3 class="connector">' . DI::l10n()->t('IFTTT Mirror') . '</h3>';
$s .= '</span>';
$s .= '<div id="settings_ifttt_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_ifttt_expanded\'); openClose(\'settings_ifttt_inflated\');">';
$s .= '<img class="connector" src="addon/ifttt/ifttt.png" /><h3 class="connector">' . DI::l10n()->t('IFTTT Mirror') . '</h3>';
$s .= '</span>';
$s .= '<div id="ifttt-configuration-wrapper">';
$s .= '<p>' . DI::l10n()->t('Create an account at <a href="http://www.ifttt.com">IFTTT</a>. Create three Facebook recipes that are connected with <a href="https://ifttt.com/maker">Maker</a> (In the form "if Facebook then Maker") with the following parameters:') . '</p>';
$s .= '<h4>URL</h4>';
$s .= '<p>' . DI::baseUrl()->get() . '/ifttt/' . $a->getLoggedInUserNickname() . '</p>';
$s .= '<h4>Method</h4>';
$s .= '<p>POST</p>';
$s .= '<h4>Content Type</h4>';
$s .= '<p>application/x-www-form-urlencoded</p>';
$s .= '<h4>' . DI::l10n()->t('Body for "new status message"') . '</h4>';
$s .= '<p><code>' . htmlentities('key=' . $key . '&type=status&msg=<<<{{Message}}>>>&date=<<<{{UpdatedAt}}>>>&url=<<<{{PageUrl}}>>>') . '</code></p>';
$s .= '<h4>' . DI::l10n()->t('Body for "new photo upload"') . '</h4>';
$s .= '<p><code>' . htmlentities('key=' . $key . '&type=photo&link=<<<{{Link}}>>>&image=<<<{{ImageSource}}>>>&msg=<<<{{Caption}}>>>&date=<<<{{CreatedAt}}>>>&url=<<<{{PageUrl}}>>>') . '</code></p>';
$s .= '<h4>' . DI::l10n()->t('Body for "new link post"') . '</h4>';
$s .= '<p><code>' . htmlentities('key=' . $key . '&type=link&link=<<<{{Link}}>>>&title=<<<{{Title}}>>>&msg=<<<{{Message}}>>>&description=<<<{{Description}}>>>&date=<<<{{CreatedAt}}>>>&url=<<<{{PageUrl}}>>>') . '</code></p>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="ifttt-rekey-wrapper">';
$s .= '<label id="ifttt-rekey-label" for="ifttt-checkbox">' . DI::l10n()->t('Generate new key') . '</label>';
$s .= '<input id="ifttt-checkbox" type="checkbox" name="ifttt-rekey" value="1" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="ifttt-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div>';
$s .= '</div>';
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/ifttt/');
$html = Renderer::replaceMacros($t, [
'$l10n' => [
'intro' => DI::l10n()->t('Create an account at <a href="http://www.ifttt.com">IFTTT</a>. Create three Facebook recipes that are connected with <a href="https://ifttt.com/maker">Maker</a> (In the form "if Facebook then Maker") with the following parameters:'),
'url' => DI::l10n()->t('URL'),
'method' => DI::l10n()->t('Method'),
'content_type' => DI::l10n()->t('Content Type'),
'new_status_message_body' => DI::l10n()->t('Body for "new status message"'),
'new_photo_upload_body' => DI::l10n()->t('Body for "new photo upload"'),
'new_link_post_body' => DI::l10n()->t('Body for "new link post"'),
],
'$url' => DI::baseUrl()->get() . '/ifttt/' . $a->getLoggedInUserNickname(),
'$new_status_message_body' => 'key=' . $key . '&type=status&msg=<<<{{Message}}>>>&date=<<<{{UpdatedAt}}>>>&url=<<<{{PageUrl}}>>>',
'$new_photo_upload_body' => 'key=' . $key . '&type=photo&link=<<<{{Link}}>>>&image=<<<{{ImageSource}}>>>&msg=<<<{{Caption}}>>>&date=<<<{{CreatedAt}}>>>&url=<<<{{PageUrl}}>>>',
'$new_link_post_body' => 'key=' . $key . '&type=link&link=<<<{{Link}}>>>&title=<<<{{Title}}>>>&msg=<<<{{Message}}>>>&description=<<<{{Description}}>>>&date=<<<{{CreatedAt}}>>>&url=<<<{{PageUrl}}>>>',
]);
$data = [
'connector' => 'ifttt',
'title' => DI::l10n()->t('IFTTT Mirror'),
'image' => 'addon/ifttt/ifttt.png',
'html' => $html,
'submit' => DI::l10n()->t('Generate new key'),
];
}
function ifttt_settings_post()
{
if (!empty($_POST['ifttt-submit']) && isset($_POST['ifttt-rekey'])) {
if (!empty($_POST['ifttt-submit'])) {
DI::pConfig()->delete(local_user(), 'ifttt', 'key');
}
}

@ -0,0 +1,15 @@
<p>{{$l10n.intro nofilter}}</p>
<dl>
<dt>{{$l10n.url}}</dt>
<dd>{{$url}}</dd>
<dt>{{$l10n.method}}</dt>
<dd>POST</dd>
<dt>{{$l10n.content_type}}</dt>
<dd>application/x-www-form-urlencoded</dd>
<dt>{{$l10n.new_status_message_body}}</dt>
<dd><code>{{$new_status_message_body}}</code></dd>
<dt>{{$l10n.new_photo_upload_body}}</dt>
<dd><code>{{$new_photo_upload_body}}</code></dd>
<dt>{{$l10n.new_link_post_body}}</dt>
<dd><code>{{$new_link_post_body}}</code></dd>
</dl>

@ -1,15 +0,0 @@
#ijpost-enable-label, #ijpost-username-label, #ijpost-password-label, #ijpost-bydefault-label {
float: left;
width: 200px;
margin-top: 10px;
}
#ijpost-checkbox, #ijpost-username, #ijpost-password, #ijpost-bydefault {
float: left;
margin-top: 10px;
}
#ijpost-submit {
margin-top: 15px;
}

@ -8,9 +8,11 @@
* Author: Cat Gray <https://free-haven.org/profile/catness>
*/
use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\Tag;
use Friendica\Model\User;
@ -26,7 +28,7 @@ function ijpost_install()
Hook::register('connector_settings_post', 'addon/ijpost/ijpost.php', 'ijpost_settings_post');
}
function ijpost_jot_nets(\Friendica\App &$a, array &$jotnets_fields)
function ijpost_jot_nets(App &$a, array &$jotnets_fields)
{
if (!local_user()) {
return;
@ -44,60 +46,31 @@ function ijpost_jot_nets(\Friendica\App &$a, array &$jotnets_fields)
}
}
function ijpost_settings(&$a, &$s)
function ijpost_settings(App &$a, array &$data)
{
if (!local_user()) {
return;
}
/* Add our stylesheet to the page so we can make our settings look nice */
DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/ijpost/ijpost.css' . '" media="all" />' . "\r\n";
/* Get the current state of our config variables */
$enabled = DI::pConfig()->get(local_user(), 'ijpost', 'post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$enabled = DI::pConfig()->get(local_user(), 'ijpost', 'post', false);
$ij_username = DI::pConfig()->get(local_user(), 'ijpost', 'ij_username');
$def_enabled = DI::pConfig()->get(local_user(), 'ijpost', 'post_by_default');
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
$ij_username = DI::pConfig()->get(local_user(), 'ijpost', 'ij_username');
$ij_password = DI::pConfig()->get(local_user(), 'ijpost', 'ij_password');
/* Add some HTML to the existing form */
$s .= '<span id="settings_ijpost_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_ijpost_expanded\'); openClose(\'settings_ijpost_inflated\');">';
$s .= '<img class="connector" src="images/insanejournal.gif" /><h3 class="connector">'. DI::l10n()->t("InsaneJournal Export").'</h3>';
$s .= '</span>';
$s .= '<div id="settings_ijpost_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_ijpost_expanded\'); openClose(\'settings_ijpost_inflated\');">';
$s .= '<img class="connector" src="images/insanejournal.gif" /><h3 class="connector">'. DI::l10n()->t("InsaneJournal Export").'</h3>';
$s .= '</span>';
$s .= '<div id="ijpost-enable-wrapper">';
$s .= '<label id="ijpost-enable-label" for="ijpost-checkbox">' . DI::l10n()->t('Enable InsaneJournal Post Addon') . '</label>';
$s .= '<input id="ijpost-checkbox" type="checkbox" name="ijpost" value="1" ' . $checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="ijpost-username-wrapper">';
$s .= '<label id="ijpost-username-label" for="ijpost-username">' . DI::l10n()->t('InsaneJournal username') . '</label>';
$s .= '<input id="ijpost-username" type="text" name="ij_username" value="' . $ij_username . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="ijpost-password-wrapper">';
$s .= '<label id="ijpost-password-label" for="ijpost-password">' . DI::l10n()->t('InsaneJournal password') . '</label>';
$s .= '<input id="ijpost-password" type="password" name="ij_password" value="' . $ij_password . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="ijpost-bydefault-wrapper">';
$s .= '<label id="ijpost-bydefault-label" for="ijpost-bydefault">' . DI::l10n()->t('Post to InsaneJournal by default') . '</label>';
$s .= '<input id="ijpost-bydefault" type="checkbox" name="ij_bydefault" value="1" ' . $def_checked . '/>';
$s .= '</div><div class="clear"></div>';
/* provide a submit button */
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="ijpost-submit" name="ijpost-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div></div>';
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/ijpost/');
$html = Renderer::replaceMacros($t, [
'$enabled' => ['ijpost', DI::l10n()->t('Enable InsaneJournal Post Addon'), $enabled],
'$username' => ['ij_username', DI::l10n()->t('InsaneJournal username'), $ij_username],
'$password' => ['ij_password', DI::l10n()->t('InsaneJournal password')],
'$bydefault' => ['ij_bydefault', DI::l10n()->t('Post to InsaneJournal by default'), $def_enabled],
]);
$data = [
'connector' => 'ijpost',
'title' => DI::l10n()->t('InsaneJournal Export'),
'image' => 'images/insanejournal.gif',
'enabled' => $enabled,
'html' => $html,
];
}
function ijpost_settings_post(&$a, &$b)

@ -0,0 +1,4 @@
{{include file="field_checkbox.tpl" field=$enabled}}
{{include file="field_input.tpl" field=$username}}
{{include file="field_password.tpl" field=$password}}
{{include file="field_checkbox.tpl" field=$bydefault}}

@ -1,16 +0,0 @@
#libertree-enable-label, #libertree-api_token-label, #libertree-url-label, #libertree-bydefault-label {
float: left;
width: 200px;
margin-top: 10px;
}
#libertree-checkbox, #libertree-api_token, #libertree-url, #libertree-bydefault {
float: left;
margin-top: 10px;
}
#libertree-submit {
margin-top: 15px;
}

@ -10,6 +10,7 @@ use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Post;
@ -43,63 +44,32 @@ function libertree_jot_nets(App &$a, array &$jotnets_fields)
}
function libertree_settings(&$a,&$s) {
if(! local_user())
return;
/* Add our stylesheet to the page so we can make our settings look nice */
DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/libertree/libertree.css' . '" media="all" />' . "\r\n";
/* Get the current state of our config variables */
$enabled = DI::pConfig()->get(local_user(),'libertree','post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$css = (($enabled) ? '' : '-disabled');
$def_enabled = DI::pConfig()->get(local_user(),'libertree','post_by_default');
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
$ltree_api_token = DI::pConfig()->get(local_user(), 'libertree', 'libertree_api_token');
$ltree_url = DI::pConfig()->get(local_user(), 'libertree', 'libertree_url');
/* Add some HTML to the existing form */
$s .= '<span id="settings_libertree_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_libertree_expanded\'); openClose(\'settings_libertree_inflated\');">';
$s .= '<img class="connector'.$css.'" src="images/libertree.png" /><h3 class="connector">'. DI::l10n()->t('libertree Export').'</h3>';
$s .= '</span>';
$s .= '<div id="settings_libertree_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_libertree_expanded\'); openClose(\'settings_libertree_inflated\');">';
$s .= '<img class="connector'.$css.'" src="images/libertree.png" /><h3 class="connector">'. DI::l10n()->t('libertree Export').'</h3>';
$s .= '</span>';
$s .= '<div id="libertree-enable-wrapper">';
$s .= '<label id="libertree-enable-label" for="libertree-checkbox">' . DI::l10n()->t('Enable Libertree Post Addon') . '</label>';
$s .= '<input id="libertree-checkbox" type="checkbox" name="libertree" value="1" ' . $checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="libertree-api_token-wrapper">';
$s .= '<label id="libertree-api_token-label" for="libertree-api_token">' . DI::l10n()->t('Libertree API token') . '</label>';
$s .= '<input id="libertree-api_token" type="text" name="libertree_api_token" value="' . $ltree_api_token . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="libertree-url-wrapper">';
$s .= '<label id="libertree-url-label" for="libertree-url">' . DI::l10n()->t('Libertree site URL') . '</label>';
$s .= '<input id="libertree-url" type="text" name="libertree_url" value="' . $ltree_url . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="libertree-bydefault-wrapper">';
$s .= '<label id="libertree-bydefault-label" for="libertree-bydefault">' . DI::l10n()->t('Post to Libertree by default') . '</label>';
$s .= '<input id="libertree-bydefault" type="checkbox" name="libertree_bydefault" value="1" ' . $def_checked . '/>';
$s .= '</div><div class="clear"></div>';
/* provide a submit button */
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="libertree-submit" name="libertree-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div></div>';
function libertree_settings(App $a, array &$data)
{
if (!local_user()) {
return;
}
$enabled = DI::pConfig()->get(local_user(), 'libertree', 'post', false);
$ltree_api_token = DI::pConfig()->get(local_user(), 'libertree', 'libertree_api_token');
$ltree_url = DI::pConfig()->get(local_user(), 'libertree', 'libertree_url');
$def_enabled = DI::pConfig()->get(local_user(), 'libertree', 'post_by_default');
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/libertree/');
$html = Renderer::replaceMacros($t, [
'$enabled' => ['libertree', DI::l10n()->t('Enable Libertree Post Addon'), $enabled],
'$ltree_url' => ['libertree_url', DI::l10n()->t('Libertree site URL'), $ltree_url],
'$ltree_api_token' => ['libertree_api_token', DI::l10n()->t('Libertree API token'), $ltree_api_token],
'$bydefault' => ['ij_bydefault', DI::l10n()->t('Post to Libertree by default'), $def_enabled],
]);
$data = [
'connector' => 'libertree',
'title' => DI::l10n()->t('Libertree Export'),
'image' => 'images/libertree.png',
'enabled' => $enabled,
'html' => $html,
];
}

@ -0,0 +1,4 @@
{{include file="field_checkbox.tpl" field=$enabled}}
{{include file="field_input.tpl" field=$ltree_url}}
{{include file="field_input.tpl" field=$ltree_api_token}}
{{include file="field_checkbox.tpl" field=$bydefault}}

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

@ -8,9 +8,11 @@
* Author: Cat Gray <https://free-haven.org/profile/catness>
*/
use Friendica\App;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Model\Tag;
@ -27,7 +29,7 @@ function ljpost_install() {
}
function ljpost_jot_nets(\Friendica\App &$a, array &$jotnets_fields)
function ljpost_jot_nets(App &$a, array &$jotnets_fields)
{
if(! local_user()) {
return;
@ -46,57 +48,31 @@ function ljpost_jot_nets(\Friendica\App &$a, array &$jotnets_fields)
}
function ljpost_settings(&$a,&$s) {
if(! local_user())
return;
/* Add our stylesheet to the page so we can make our settings look nice */
DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/ljpost/ljpost.css' . '" media="all" />' . "\r\n";
/* Get the current state of our config variables */
$enabled = DI::pConfig()->get(local_user(),'ljpost','post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$def_enabled = DI::pConfig()->get(local_user(),'ljpost','post_by_default');
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
$lj_username = DI::pConfig()->get(local_user(), 'ljpost', 'lj_username');
$lj_password = DI::pConfig()->get(local_user(), 'ljpost', 'lj_password');
/* Add some HTML to the existing form */
$s .= '<div class="settings-block">';
$s .= '<h3>' . DI::l10n()->t('LiveJournal Post Settings') . '</h3>';
$s .= '<div id="ljpost-enable-wrapper">';
$s .= '<label id="ljpost-enable-label" for="ljpost-checkbox">' . DI::l10n()->t('Enable LiveJournal Post Addon') . '</label>';
$s .= '<input id="ljpost-checkbox" type="checkbox" name="ljpost" value="1" ' . $checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="ljpost-username-wrapper">';
$s .= '<label id="ljpost-username-label" for="ljpost-username">' . DI::l10n()->t('LiveJournal username') . '</label>';
$s .= '<input id="ljpost-username" type="text" name="lj_username" value="' . $lj_username . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="ljpost-password-wrapper">';
$s .= '<label id="ljpost-password-label" for="ljpost-password">' . DI::l10n()->t('LiveJournal password') . '</label>';
$s .= '<input id="ljpost-password" type="password" name="lj_password" value="' . $lj_password . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="ljpost-bydefault-wrapper">';
$s .= '<label id="ljpost-bydefault-label" for="ljpost-bydefault">' . DI::l10n()->t('Post to LiveJournal by default') . '</label>';
$s .= '<input id="ljpost-bydefault" type="checkbox" name="lj_bydefault" value="1" ' . $def_checked . '/>';
$s .= '</div><div class="clear"></div>';
/* provide a submit button */
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="ljpost-submit" name="ljpost-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div></div>';
function ljpost_settings(App &$a, array &$data)
{
if (!local_user()) {
return;
}
$enabled = DI::pConfig()->get(local_user(), 'ljpost', 'post', false);
$ij_username = DI::pConfig()->get(local_user(), 'ljpost', 'ij_username');
$def_enabled = DI::pConfig()->get(local_user(), 'ljpost', 'post_by_default');
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/ljpost/');
$html = Renderer::replaceMacros($t, [
'$enabled' => ['ljpost', DI::l10n()->t('Enable LiveJournal Post Addon'), $enabled],
'$username' => ['ij_username', DI::l10n()->t('LiveJournal username'), $ij_username],
'$password' => ['ij_password', DI::l10n()->t('LiveJournal password')],
'$bydefault' => ['ij_bydefault', DI::l10n()->t('Post to LiveJournal by default'), $def_enabled],
]);
$data = [
'connector' => 'ljpost',
'title' => DI::l10n()->t('LiveJournal Export'),
'image' => 'addon/ljpost/livejournal.png',
'enabled' => $enabled,
'html' => $html,
];
}

@ -0,0 +1,4 @@
{{include file="field_checkbox.tpl" field=$enabled}}
{{include file="field_input.tpl" field=$username}}
{{include file="field_password.tpl" field=$password}}
{{include file="field_checkbox.tpl" field=$bydefault}}

@ -1,16 +0,0 @@
#pumpio-import-label,#pumpio-mirror-label,#pumpio-public-label, #pumpio-enable-label, #pumpio-username-label, #pumpio-servername-label, #pumpio-bydefault-label, #pumpio-delete-label {
float: left;
width: 200px;
margin-top: 10px;
}
#pumpio-import,#pumpio-mirror,#pumpio-public, #pumpio-checkbox, #pumpio-username, #pumpio-servername, #pumpio-bydefault, #pumpio-delete {
float: left;
margin-top: 10px;
}
#pumpio-submit {
margin-top: 15px;
}

@ -13,6 +13,7 @@ use Friendica\Core\Addon;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
use Friendica\DI;
@ -216,150 +217,99 @@ function pumpio_jot_nets(App $a, array &$jotnets_fields)
}
}
function pumpio_settings(App $a, &$s)
function pumpio_settings(App $a, array &$data)
{
if (!local_user()) {
return;
}
/* Add our stylesheet to the page so we can make our settings look nice */
$pumpio_host = DI::pConfig()->get(local_user(), 'pumpio', 'host');
$pumpio_user = DI::pConfig()->get(local_user(), 'pumpio', 'user');
$oauth_token = DI::pConfig()->get(local_user(), 'pumpio', 'oauth_token');
$oauth_token_secret = DI::pConfig()->get(local_user(), 'pumpio', 'oauth_token_secret');
DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/pumpio/pumpio.css' . '" media="all" />' . "\r\n";
$import_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'import', false);
$enabled = DI::pConfig()->get(local_user(), 'pumpio', 'post', false);
$def_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'post_by_default', false);
$public_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'public', false);
$mirror_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'mirror', false);
/* Get the current state of our config variables */
$import_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'import');
$import_checked = (($import_enabled) ? ' checked="checked" ' : '');
$enabled = DI::pConfig()->get(local_user(), 'pumpio', 'post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$css = (($enabled) ? '' : '-disabled');
$def_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'post_by_default');
$def_checked = (($def_enabled) ? ' checked="checked" ' : '');
$public_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'public');
$public_checked = (($public_enabled) ? ' checked="checked" ' : '');
$mirror_enabled = DI::pConfig()->get(local_user(), 'pumpio', 'mirror');
$mirror_checked = (($mirror_enabled) ? ' checked="checked" ' : '');
$servername = DI::pConfig()->get(local_user(), "pumpio", "host");
$username = DI::pConfig()->get(local_user(), "pumpio", "user");
/* Add some HTML to the existing form */
$s .= '<span id="settings_pumpio_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_pumpio_expanded\'); openClose(\'settings_pumpio_inflated\');">';
$s .= '<img class="connector'.$css.'" src="images/pumpio.png" /><h3 class="connector">'. DI::l10n()->t('Pump.io Import/Export/Mirror').'</h3>';
$s .= '</span>';
$s .= '<div id="settings_pumpio_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_pumpio_expanded\'); openClose(\'settings_pumpio_inflated\');">';
$s .= '<img class="connector'.$css.'" src="images/pumpio.png" /><h3 class="connector">'. DI::l10n()->t('Pump.io Import/Export/Mirror').'</h3>';
$s .= '</span>';
$s .= '<div id="pumpio-username-wrapper">';
$s .= '<label id="pumpio-username-label" for="pumpio-username">'.DI::l10n()->t('pump.io username (without the servername)').'</label>';
$s .= '<input id="pumpio-username" type="text" name="pumpio_user" value="'.$username.'" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-servername-wrapper">';
$s .= '<label id="pumpio-servername-label" for="pumpio-servername">'.DI::l10n()->t('pump.io servername (without "http://" or "https://" )').'</label>';
$s .= '<input id="pumpio-servername" type="text" name="pumpio_host" value="'.$servername.'" />';
$s .= '</div><div class="clear"></div>';
if (($username != '') && ($servername != '')) {
$oauth_token = DI::pConfig()->get(local_user(), "pumpio", "oauth_token");
$oauth_token_secret = DI::pConfig()->get(local_user(), "pumpio", "oauth_token_secret");
$s .= '<div id="pumpio-password-wrapper">';
if (($oauth_token == "") || ($oauth_token_secret == "")) {
$s .= '<div id="pumpio-authenticate-wrapper">';
$s .= '<a href="'.DI::baseUrl()->get().'/pumpio/connect">'.DI::l10n()->t("Authenticate your pump.io connection").'</a>';
$s .= '</div><div class="clear"></div>';
} else {
$s .= '<div id="pumpio-import-wrapper">';
$s .= '<label id="pumpio-import-label" for="pumpio-import">' . DI::l10n()->t('Import the remote timeline') . '</label>';
$s .= '<input id="pumpio-import" type="checkbox" name="pumpio_import" value="1" ' . $import_checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-enable-wrapper">';
$s .= '<label id="pumpio-enable-label" for="pumpio-checkbox">' . DI::l10n()->t('Enable pump.io Post Addon') . '</label>';
$s .= '<input id="pumpio-checkbox" type="checkbox" name="pumpio" value="1" ' . $checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-bydefault-wrapper">';
$s .= '<label id="pumpio-bydefault-label" for="pumpio-bydefault">' . DI::l10n()->t('Post to pump.io by default') . '</label>';
$s .= '<input id="pumpio-bydefault" type="checkbox" name="pumpio_bydefault" value="1" ' . $def_checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-public-wrapper">';
$s .= '<label id="pumpio-public-label" for="pumpio-public">' . DI::l10n()->t('Should posts be public?') . '</label>';
$s .= '<input id="pumpio-public" type="checkbox" name="pumpio_public" value="1" ' . $public_checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-mirror-wrapper">';
$s .= '<label id="pumpio-mirror-label" for="pumpio-mirror">' . DI::l10n()->t('Mirror all public posts') . '</label>';
$s .= '<input id="pumpio-mirror" type="checkbox" name="pumpio_mirror" value="1" ' . $mirror_checked . '/>';
$s .= '</div><div class="clear"></div>';
$s .= '<div id="pumpio-delete-wrapper">';
$s .= '<label id="pumpio-delete-label" for="pumpio-delete">' . DI::l10n()->t('Check to delete this preset') . '</label>';
$s .= '<input id="pumpio-delete" type="checkbox" name="pumpio_delete" value="1" />';
$s .= '</div><div class="clear"></div>';
}
$s .= '</div><div class="clear"></div>';
}
/* provide a submit button */
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="pumpio-submit" name="pumpio-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div></div>';
$submit = ['pumpio-submit' => DI::l10n()->t('Save Settings')];
if ($oauth_token && $oauth_token_secret) {
$submit['pumpio-delete'] = DI::l10n()->t('Delete this preset');
}
$t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/pumpio/');
$html = Renderer::replaceMacros($t, [
'$l10n' => [
'authenticate' => DI::l10n()->t('Authenticate your pump.io connection'),
],
'$pumpio_host' => $pumpio_host,
'$pumpio_user' => $pumpio_user,
'$oauth_token' => $oauth_token,
'$oauth_token_secret' => $oauth_token_secret,
'$authenticate_url' => DI::baseUrl()->get() . '/pumpio/connect',
'$servername' => ['pumpio_host', DI::l10n()->t('Pump.io servername (without "http://" or "https://" )'), $pumpio_host],
'$username' => ['pumpio_user', DI::l10n()->t('Pump.io username (without the servername)'), $pumpio_user],
'$import' => ['pumpio_import', DI::l10n()->t('Import the remote timeline'), $import_enabled],
'$enabled' => ['pumpio', DI::l10n()->t('Enable Pump.io Post Addon'), $enabled],
'$bydefault' => ['pumpio_bydefault', DI::l10n()->t('Post to Pump.io by default'), $def_enabled],
'$public' => ['pumpio_public', DI::l10n()->t('Should posts be public?'), $public_enabled],
'$mirror' => ['pumpio_mirror', DI::l10n()->t('Mirror all public posts'), $mirror_enabled],
]);
$data = [
'connector' => 'pumpio',
'title' => DI::l10n()->t('Pump.io Import/Export/Mirror'),
'image' => 'images/pumpio.png',
'enabled' => $enabled,
'html' => $html,
'submit' => $submit,
];
}
function pumpio_settings_post(App $a, array &$b)
{
if (!empty($_POST['pumpio-submit'])) {
if (!empty($_POST['pumpio_delete'])) {
DI::pConfig()->set(local_user(), 'pumpio', 'consumer_key' , '');
DI::pConfig()->set(local_user(), 'pumpio', 'consumer_secret' , '');
DI::pConfig()->set(local_user(), 'pumpio', 'oauth_token' , '');
DI::pConfig()->set(local_user(), 'pumpio', 'oauth_token_secret', '');
DI::pConfig()->set(local_user(), 'pumpio', 'post' , false);
DI::pConfig()->set(local_user(), 'pumpio', 'import' , false);
DI::pConfig()->set(local_user(), 'pumpio', 'host' , '');
DI::pConfig()->set(local_user(), 'pumpio', 'user' , '');
DI::pConfig()->set(local_user(), 'pumpio', 'public' , false);
DI::pConfig()->set(local_user(), 'pumpio', 'mirror' , false);
DI::pConfig()->set(local_user(), 'pumpio', 'post_by_default' , false);
DI::pConfig()->set(local_user(), 'pumpio', 'lastdate' , 0);
DI::pConfig()->set(local_user(), 'pumpio', 'last_id' , '');
} else {
// filtering the username if it is filled wrong
$user = $_POST['pumpio_user'];
if (strstr($user, "@")) {
$pos = strpos($user, "@");
if ($pos > 0) {
$user = substr($user, 0, $pos);
}
if (!empty($_POST['pumpio_delete'])) {
DI::pConfig()->set(local_user(), 'pumpio', 'consumer_key' , '');
DI::pConfig()->set(local_user(), 'pumpio', 'consumer_secret' , '');
DI::pConfig()->set(local_user(), 'pumpio', 'oauth_token' , '');
DI::pConfig()->set(local_user(), 'pumpio', 'oauth_token_secret', '');
DI::pConfig()->set(local_user(), 'pumpio', 'post' , false);
DI::pConfig()->set(local_user(), 'pumpio', 'import' , false);
DI::pConfig()->set(local_user(), 'pumpio', 'host' , '');
DI::pConfig()->set(local_user(), 'pumpio', 'user' , '');
DI::pConfig()->set(local_user(), 'pumpio', 'public' , false);
DI::pConfig()->set(local_user(), 'pumpio', 'mirror' , false);
DI::pConfig()->set(local_user(), 'pumpio', 'post_by_default' , false);
DI::pConfig()->set(local_user(), 'pumpio', 'lastdate' , 0);
DI::pConfig()->set(local_user(), 'pumpio', 'last_id' , '');
} elseif (!empty($_POST['pumpio-submit'])) {
// filtering the username if it is filled wrong
$user = $_POST['pumpio_user'];
if (strstr($user, "@")) {
$pos = strpos($user, "@");
if ($pos > 0) {
$user = substr($user, 0, $pos);
}
}
// Filtering the hostname if someone is entering it with "http"
$host = $_POST['pumpio_host'];
$host = trim($host);
$host = str_replace(["https://", "http://"], ["", ""], $host);
DI::pConfig()->set(local_user(), 'pumpio', 'post' , $_POST['pumpio'] ?? false);
DI::pConfig()->set(local_user(), 'pumpio', 'import' , $_POST['pumpio_import'] ?? false);
DI::pConfig()->set(local_user(), 'pumpio', 'host' , $host);
DI::pConfig()->set(local_user(), 'pumpio', 'user' , $user);
DI::pConfig()->set(local_user(), 'pumpio', 'public' , $_POST['pumpio_public'] ?? false);
DI::pConfig()->set(local_user(), 'pumpio', 'mirror' , $_POST['pumpio_mirror'] ?? false);
DI::pConfig()->set(local_user(), 'pumpio', 'post_by_default', $_POST['pumpio_bydefault'] ?? false);
if (!empty($_POST['pumpio_mirror'])) {
DI::pConfig()->delete(local_user(), 'pumpio', 'lastdate');
}
// Filtering the hostname if someone is entering it with "http"
$host = $_POST['pumpio_host'];
$host = trim($host);
$host = str_replace(["https://", "http://"], ["", ""], $host);
DI::pConfig()->set(local_user(), 'pumpio', 'post' , $_POST['pumpio'] ?? false);
DI::pConfig()->set(local_user(), 'pumpio', 'import' , $_POST['pumpio_import'] ?? false);
DI::pConfig()->set(local_user(), 'pumpio', 'host' , $host);
DI::pConfig()->set(local_user(), 'pumpio', 'user' , $user);
DI::pConfig()->set(local_user(), 'pumpio', 'public' , $_POST['pumpio_public'] ?? false);
DI::pConfig()->set(local_user(), 'pumpio', 'mirror' , $_POST['pumpio_mirror'] ?? false);
DI::pConfig()->set(local_user(), 'pumpio', 'post_by_default', $_POST['pumpio_bydefault'] ?? false);
if (!empty($_POST['pumpio_mirror'])) {
DI::pConfig()->delete(local_user(), 'pumpio', 'lastdate');
}
}
}

@ -0,0 +1,13 @@
{{include file="field_input.tpl" field=$servername}}
{{include file="field_input.tpl" field=$username}}
{{if $oauth_token && $oauth_token_secret}}
{{include file="field_checkbox.tpl" field=$enabled}}
{{include file="field_checkbox.tpl" field=$bydefault}}
{{include file="field_checkbox.tpl" field=$public}}
{{include file="field_checkbox.tpl" field=$mirror}}
{{elseif $pumpio_host && $pumpio_user}}
<div id="pumpio-authenticate-wrapper">
<a href="{{$authenticate_url}}">{{$l10n.authenticate}}</a>
</div>
{{/if}}

@ -10,62 +10,3 @@
height: 52px;
vertical-align: middle;
}
#statusnet-disconnect-label {
float: left;
width: 250px;
margin-bottom: 25px;
}
#statusnet-disconnect {
float: left;
}
#statusnet-default-label,
#statusnet-applicationname-label,
#statusnet-sendtaglinks-label,
#statusnet-shortening-label,
#statusnet-mirror-label,
#statusnet-import-label,
#statusnet-create_user-label,
#statusnet-pin-label,
#statusnet-enable-label {
float: left;
width: 250px;
margin-bottom: 5px;
}
#statusnet-checkbox {
float: left;
}
#statusnet-pin {
float: left;
}
#statusnet-consumerkey-label {
float: left;
width: 250px;
margin-bottom: 8px;
}
#statusnet-consumerkey {
float: left;
margin-bottom: 8px;
}
#statusnet-consumersecret-label {
float: left;
width: 250px;
margin-bottom: 8px;
}
#statusnet-consumersecret {
float: left;
margin-bottom: 8px;
}
#statusnet-baseapi-label {
float: left;
width: 250px;
margin-bottom: 25px;
}
#statusnet-baseapi {
float: left;
margin-bottom: 8px;
}

@ -107,13 +107,13 @@ function statusnet_settings_post(App $a, $post)
return;
}
// don't check GNU Social settings if GNU Social submit button is not clicked
if (empty($_POST['statusnet-submit'])) {
if (empty($_POST['statusnet-submit']) && empty($_POST['statusnet-disconnect'])) {
return;
}
if (isset($_POST['statusnet-disconnect'])) {
if (!empty($_POST['statusnet-disconnect'])) {
/* * *
* if the GNU Social-disconnect checkbox is set, clear the GNU Social configuration
* if the GNU Social-disconnect button is clicked, clear the GNU Social configuration
*/
DI::pConfig()->delete(local_user(), 'statusnet', 'consumerkey');
DI::pConfig()->delete(local_user(), 'statusnet', 'consumersecret');
@ -149,7 +149,6 @@ function statusnet_settings_post(App $a, $post)
}
}
}
DI::baseUrl()->redirect('settings/connectors');
} else {
if (isset($_POST['statusnet-consumersecret'])) {
// check if we can reach the API of the GNU Social server
@ -177,7 +176,6 @@ function statusnet_settings_post(App $a, $post)
notice(DI::l10n()->t('We could not contact the GNU Social API with the Path you entered.') . EOL);
}
}
DI::baseUrl()->redirect('settings/connectors');
} else {
if (isset($_POST['statusnet-pin'])) {
// if the user supplied us with a PIN from GNU Social, let the magic of OAuth happen
@ -195,7 +193,6 @@ function statusnet_settings_post(App $a, $post)
DI::pConfig()->set(local_user(), 'statusnet', 'post', 1);
DI::pConfig()->set(local_user(), 'statusnet', 'post_taglinks', 1);
// reload the Addon Settings page, if we don't do it see Bug #42
DI::baseUrl()->redirect('settings/connectors');
} else {
// if no PIN is supplied in the POST variables, the user has changed the setting
// to post a dent for every new __public__ posting to the wall
@ -213,171 +210,125 @@ function statusnet_settings_post(App $a, $post)
}
}
function statusnet_settings(App $a, &$s)
function statusnet_settings(App $a, array &$data)
{
if (!local_user()) {
return;
}
$user = User::getById(local_user());
DI::page()->registerStylesheet(__DIR__ . '/statusnet.css', 'all');
DI::page()['htmlhead'] .= '<link rel="stylesheet" type="text/css" href="' . DI::baseUrl()->get() . '/addon/statusnet/statusnet.css' . '" media="all" />' . "\r\n";
/* * *
* 1) Check that we have a base api url and a consumer key & secret
* 2) If no OAuthtoken & stuff is present, generate button to get some
* allow the user to cancel the connection process at this step
* 3) Checkbox for "Send public notices (respect size limitation)
*/
$api = DI::pConfig()->get(local_user(), 'statusnet', 'baseapi');
$ckey = DI::pConfig()->get(local_user(), 'statusnet', 'consumerkey');
$csecret = DI::pConfig()->get(local_user(), 'statusnet', 'consumersecret');
$otoken = DI::pConfig()->get(local_user(), 'statusnet', 'oauthtoken');
$osecret = DI::pConfig()->get(local_user(), 'statusnet', 'oauthsecret');
$enabled = DI::pConfig()->get(local_user(), 'statusnet', 'post');
$checked = (($enabled) ? ' checked="checked" ' : '');
$defenabled = DI::pConfig()->get(local_user(), 'statusnet', 'post_by_default');
$defchecked = (($defenabled) ? ' checked="checked" ' : '');
$mirrorenabled = DI::pConfig()->get(local_user(), 'statusnet', 'mirror_posts');
$mirrorchecked = (($mirrorenabled) ? ' checked="checked" ' : '');
$import = DI::pConfig()->get(local_user(), 'statusnet', 'import');
$importselected = ["", "", ""];
$importselected[$import] = ' selected="selected"';
//$importenabled = DI::pConfig()->get(local_user(),'statusnet','import');
//$importchecked = (($importenabled) ? ' checked="checked" ' : '');
$create_userenabled = DI::pConfig()->get(local_user(), 'statusnet', 'create_user');
$create_userchecked = (($create_userenabled) ? ' checked="checked" ' : '');
$css = (($enabled) ? '' : '-disabled');
$s .= '<span id="settings_statusnet_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_statusnet_expanded\'); openClose(\'settings_statusnet_inflated\');">';
$s .= '<img class="connector' . $css . '" src="images/gnusocial.png" /><h3 class="connector">' . DI::l10n()->t('GNU Social Import/Export/Mirror') . '</h3>';
$s .= '</span>';
$s .= '<div id="settings_statusnet_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_statusnet_expanded\'); openClose(\'settings_statusnet_inflated\');">';
$s .= '<img class="connector' . $css . '" src="images/gnusocial.png" /><h3 class="connector">' . DI::l10n()->t('GNU Social Import/Export/Mirror') . '</h3>';
$s .= '</span>';
if ((!$ckey) && (!$csecret)) {
/* * *
* no consumer keys
*/
$globalsn = DI::config()->get('statusnet', 'sites');
/* * *
* lets check if we have one or more globally configured GNU Social
* server OAuth credentials in the configuration. If so offer them
* with a little explanation to the user as choice - otherwise
* ignore this option entirely.
*/
if (!$globalsn == null) {
$s .= '<h4>' . DI::l10n()->t('Globally Available GNU Social OAuthKeys') . '</h4>';
$s .= '<p>' . DI::l10n()->t("There are preconfigured OAuth key pairs for some GNU Social servers available. If you are using one of them, please use these credentials. If not feel free to connect to any other GNU Social instance \x28see below\x29.") . '</p>';
$s .= '<div id="statusnet-preconf-wrapper">';
foreach ($globalsn as $asn) {
$s .= '<input type="radio" name="statusnet-preconf-apiurl" value="' . $asn['apiurl'] . '">' . $asn['sitename'] . '<br />';
}
$s .= '<p></p><div class="clear"></div></div>';
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="statusnet-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div>';
}
$s .= '<h4>' . DI::l10n()->t('Provide your own OAuth Credentials') . '</h4>';
$s .= '<p>' . DI::l10n()->t('No consumer key pair for GNU Social found. Register your Friendica Account as an desktop client on your GNU Social account, copy the consumer key pair here and enter the API base root.<br />Before you register your own OAuth key pair ask the administrator if there is already a key pair for this Friendica installation at your favorited GNU Social installation.') . '</p>';
$s .= '<div id="statusnet-consumer-wrapper">';
$s .= '<label id="statusnet-consumerkey-label" for="statusnet-consumerkey">' . DI::l10n()->t('OAuth Consumer Key') . '</label>';
$s .= '<input id="statusnet-consumerkey" type="text" name="statusnet-consumerkey" size="35" /><br />';
$s .= '<div class="clear"></div>';
$s .= '<label id="statusnet-consumersecret-label" for="statusnet-consumersecret">' . DI::l10n()->t('OAuth Consumer Secret') . '</label>';
$s .= '<input id="statusnet-consumersecret" type="text" name="statusnet-consumersecret" size="35" /><br />';
$s .= '<div class="clear"></div>';
$s .= '<label id="statusnet-baseapi-label" for="statusnet-baseapi">' . DI::l10n()->t("Base API Path \x28remember the trailing /\x29") . '</label>';
$s .= '<input id="statusnet-baseapi" type="text" name="statusnet-baseapi" size="35" /><br />';
$s .= '<div class="clear"></div>';
//$s .= '<label id="statusnet-applicationname-label" for="statusnet-applicationname">'.DI::l10n()->t('GNU Socialapplication name').'</label>';
//$s .= '<input id="statusnet-applicationname" type="text" name="statusnet-applicationname" size="35" /><br />';
$s .= '<p></p><div class="clear"></div>';
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="statusnet-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div>';
$s .= '</div>';
} else {
/* * *
* ok we have a consumer key pair now look into the OAuth stuff
*/
if ((!$otoken) && (!$osecret)) {
/* * *
* the user has not yet connected the account to GNU Social
* get a temporary OAuth key/secret pair and display a button with
* which the user can request a PIN to connect the account to a
* account at GNU Social
*/
$connection = new StatusNetOAuth($api, $ckey, $csecret);
$request_token = $connection->getRequestToken('oob');
$token = $request_token['oauth_token'];
/* * *
* make some nice form
*/
$s .= '<p>' . DI::l10n()->t('To connect to your GNU Social account click the button below to get a security code from GNU Social which you have to copy into the input box below and submit the form. Only your <strong>public</strong> posts will be posted to GNU Social.') . '</p>';
$s .= '<a href="' . $connection->getAuthorizeURL($token, False) . '" target="_statusnet"><img src="addon/statusnet/signinwithstatusnet.png" alt="' . DI::l10n()->t('Log in with GNU Social') . '"></a>';
$s .= '<div id="statusnet-pin-wrapper">';
$s .= '<label id="statusnet-pin-label" for="statusnet-pin">' . DI::l10n()->t('Copy the security code from GNU Social here') . '</label>';
$s .= '<input id="statusnet-pin" type="text" name="statusnet-pin" />';
$s .= '<input id="statusnet-token" type="hidden" name="statusnet-token" value="' . $token . '" />';
$s .= '<input id="statusnet-token2" type="hidden" name="statusnet-token2" value="' . $request_token['oauth_token_secret'] . '" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="statusnet-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div>';
$s .= '<h4>' . DI::l10n()->t('Cancel Connection Process') . '</h4>';
$s .= '<div id="statusnet-cancel-wrapper">';
$s .= '<p>' . DI::l10n()->t('Current GNU Social API is') . ': ' . $api . '</p>';
$s .= '<label id="statusnet-cancel-label" for="statusnet-cancel">' . DI::l10n()->t('Cancel GNU Social Connection') . '</label>';
$s .= '<input id="statusnet-cancel" type="checkbox" name="statusnet-disconnect" value="1" />';
$s .= '</div><div class="clear"></div>';
$s .= '<div class="settings-submit-wrapper" ><input type="submit" name="statusnet-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div>';
} else {
$baseapi = DI::pConfig()->get(local_user(), 'statusnet', 'baseapi');
$ckey = DI::pConfig()->get(local_user(), 'statusnet', 'consumerkey');
$csecret = DI::pConfig()->get(local_user(), 'statusnet', 'consumersecret');
$otoken = DI::pConfig()->get(local_user(), 'statusnet', 'oauthtoken');
$osecret = DI::pConfig()->get(local_user(), 'statusnet', 'oauthsecret');
$enabled = DI::pConfig()->get(local_user(), 'statusnet', 'post', false);
$def_enabled = DI::pConfig()->get(local_user(), 'statusnet', 'post_by_default', false);
$mirror_enabled = DI::pConfig()->get(local_user(), 'statusnet', 'mirror_posts', false);
$createuser_enabled = DI::pConfig()->get(local_user(), 'statusnet', 'create_user', false);
$import = DI::pConfig()->get(local_user(), 'statusnet', 'import');
// Radio button list to select existing application credentials
$sites = array_map(function ($site) {
return ['statusnet-preconf-apiurl', $site['sitename'], $site['apiurl']];
}, DI::config()->get('statusnet', 'sites', []));
$submit = ['statusnet-submit' => DI::l10n()->t('Save Settings')];
if ($ckey && $csecret) {
if ($otoken && $osecret) {
/* * *
* we have an OAuth key / secret pair for the user
* so let's give a chance to disable the postings to GNU Social
*/
$connection = new StatusNetOAuth($api, $ckey, $csecret, $otoken, $osecret);
$details = $connection->get('account/verify_credentials');
if (!empty($details)) {
$s .= '<div id="statusnet-info" ><img id="statusnet-avatar" src="' . $details->profile_image_url . '" /><p id="statusnet-info-block">' . DI::l10n()->t('Currently connected to: ') . '<a href="' . $details->statusnet_profile_url . '" target="_statusnet">' . $details->screen_name . '</a><br /><em>' . $details->description . '</em></p></div>';
$connection = new StatusNetOAuth($baseapi, $ckey, $csecret, $otoken, $osecret);
$account = $connection->get('account/verify_credentials');
if (!empty($account)) {
$connected_account = DI::l10n()->t('Currently connected to: <a href="%s" target="_statusnet">%s</a>', $account->statusnet_profile_url, $account->screen_name);
}
$s .= '<p>' . DI::l10n()->t('If enabled all your <strong>public</strong> postings can be posted to the associated GNU Social account. You can choose to do so by default (here) or for every posting separately in the posting options when writing the entry.') . '</p>';
$user = User::getById(local_user());
if ($user['hidewall']) {
$s .= '<p>' . DI::l10n()->t('<strong>Note</strong>: Due your privacy settings (<em>Hide your profile details from unknown viewers?</em>) the link potentially included in public postings relayed to GNU Social will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.') . '</p>';
$privacy_warning = DI::l10n()->t('<strong>Note</strong>: Due your privacy settings (<em>Hide your profile details from unknown viewers?</em>) the link potentially included in public postings relayed to GNU Social will lead the visitor to a blank page informing the visitor that the access to your profile has been restricted.');
}
$s .= '<div id="statusnet-enable-wrapper">';
$s .= '<label id="statusnet-enable-label" for="statusnet-checkbox">' . DI::l10n()->t('Allow posting to GNU Social') . '</label>';
$s .= '<input id="statusnet-checkbox" type="checkbox" name="statusnet-enable" value="1" ' . $checked . '/>';
$s .= '<div class="clear"></div>';
$s .= '<label id="statusnet-default-label" for="statusnet-default">' . DI::l10n()->t('Send public postings to GNU Social by default') . '</label>';
$s .= '<input id="statusnet-default" type="checkbox" name="statusnet-default" value="1" ' . $defchecked . '/>';
$s .= '<div class="clear"></div>';
$s .= '<label id="statusnet-mirror-label" for="statusnet-mirror">' . DI::l10n()->t('Mirror all posts from GNU Social that are no replies or repeated messages') . '</label>';
$s .= '<input id="statusnet-mirror" type="checkbox" name="statusnet-mirror" value="1" ' . $mirrorchecked . '/>';
$s .= '<div class="clear"></div>';
$s .= '</div>';
$s .= '<label id="statusnet-import-label" for="statusnet-import">' . DI::l10n()->t('Import the remote timeline') . '</label>';
//$s .= '<input id="statusnet-import" type="checkbox" name="statusnet-import" value="1" '. $importchecked . '/>';
$s .= '<select name="statusnet-import" id="statusnet-import" />';
$s .= '<option value="0" ' . $importselected[0] . '>' . DI::l10n()->t("Disabled") . '</option>';
$s .= '<option value="1" ' . $importselected[1] . '>' . DI::l10n()->t("Full Timeline") . '</option>';
$s .= '<option value="2" ' . $importselected[2] . '>' . DI::l10n()->t("Only Mentions") . '</option>';
$s .= '</select>';
$s .= '<div class="clear"></div>';
/*