Skip to content

Commit

Permalink
[various] Convert connector_settings hook functions to the new data a…
Browse files Browse the repository at this point in the history
…rray format

- Add separate template files to several addons
- Remove superfluous addon settings CSS files
  • Loading branch information
MrPetovan committed Nov 29, 2021
1 parent 779b38e commit 9acfdb4
Show file tree
Hide file tree
Showing 36 changed files with 631 additions and 1,031 deletions.
16 changes: 0 additions & 16 deletions diaspora/diaspora.css

This file was deleted.

61 changes: 33 additions & 28 deletions diaspora/diaspora.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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 [email protected]) 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="[email protected]"'],
'$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="[email protected]"'],
'$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,
];
}


Expand Down
32 changes: 32 additions & 0 deletions diaspora/templates/connector_settings.tpl
Original file line number Diff line number Diff line change
@@ -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}}
47 changes: 0 additions & 47 deletions diaspora/templates/settings.tpl

This file was deleted.

16 changes: 11 additions & 5 deletions discourse/discourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,26 @@ 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;
}

$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)
Expand Down
1 change: 1 addition & 0 deletions discourse/templates/connector_settings.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{include file="field_checkbox.tpl" field=$enabled}}
15 changes: 0 additions & 15 deletions discourse/templates/settings.tpl

This file was deleted.

15 changes: 0 additions & 15 deletions dwpost/dwpost.css

This file was deleted.

65 changes: 19 additions & 46 deletions dwpost/dwpost.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
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;
Expand Down Expand Up @@ -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,
];
}


Expand Down
4 changes: 4 additions & 0 deletions dwpost/templates/connector_settings.tpl
Original file line number Diff line number Diff line change
@@ -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}}
Loading

0 comments on commit 9acfdb4

Please sign in to comment.