From: Hypolite Petovan Date: Sun, 21 Nov 2021 22:10:13 +0000 (-0500) Subject: [various] Convert connector_settings hook functions to the new data array format X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=9acfdb409020ee678cfa07dc81a4f731ce5f17e0;p=friendica-addons.git [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 --- diff --git a/diaspora/diaspora.css b/diaspora/diaspora.css deleted file mode 100644 index 21ef9bc5..00000000 --- a/diaspora/diaspora.css +++ /dev/null @@ -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; -} - diff --git a/diaspora/diaspora.php b/diaspora/diaspora.php index 7b747bef..82042fc9 100644 --- a/diaspora/diaspora.php +++ b/diaspora/diaspora.php @@ -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 %s. ', 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 %s', $handle); + $info = DI::l10n()->t('Connected with your Diaspora account %s', $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, + ]; } diff --git a/diaspora/templates/connector_settings.tpl b/diaspora/templates/connector_settings.tpl new file mode 100644 index 00000000..9f8e270e --- /dev/null +++ b/diaspora/templates/connector_settings.tpl @@ -0,0 +1,32 @@ +{{if $info}} +
+
+

{{$l10n.info_header}}

+
+

+ {{$info nofilter}} +

+
+{{/if}} +{{if $error}} +
+
+

{{$l10n.error_header}}

+
+

+ {{$error nofilter}} +

+
+{{/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}} diff --git a/diaspora/templates/settings.tpl b/diaspora/templates/settings.tpl deleted file mode 100644 index dadebe44..00000000 --- a/diaspora/templates/settings.tpl +++ /dev/null @@ -1,47 +0,0 @@ - - -

{{$header}}

-
- \ No newline at end of file diff --git a/discourse/discourse.php b/discourse/discourse.php index 35ec9be5..3d085d92 100644 --- a/discourse/discourse.php +++ b/discourse/discourse.php @@ -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) diff --git a/discourse/templates/connector_settings.tpl b/discourse/templates/connector_settings.tpl new file mode 100644 index 00000000..2f3f4ce7 --- /dev/null +++ b/discourse/templates/connector_settings.tpl @@ -0,0 +1 @@ +{{include file="field_checkbox.tpl" field=$enabled}} diff --git a/discourse/templates/settings.tpl b/discourse/templates/settings.tpl deleted file mode 100644 index d4b0bf8c..00000000 --- a/discourse/templates/settings.tpl +++ /dev/null @@ -1,15 +0,0 @@ - -

{{$title}}

-
- diff --git a/dwpost/dwpost.css b/dwpost/dwpost.css deleted file mode 100644 index 3b0ee32a..00000000 --- a/dwpost/dwpost.css +++ /dev/null @@ -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; -} diff --git a/dwpost/dwpost.php b/dwpost/dwpost.php index 397dc88f..286d8012 100644 --- a/dwpost/dwpost.php +++ b/dwpost/dwpost.php @@ -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'] .= '' . "\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 .= ''; - $s .= '

'. DI::l10n()->t("Dreamwidth Export").'

'; - $s .= '
'; - $s .= ''; + $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, + ]; } diff --git a/dwpost/templates/connector_settings.tpl b/dwpost/templates/connector_settings.tpl new file mode 100644 index 00000000..0abcd24e --- /dev/null +++ b/dwpost/templates/connector_settings.tpl @@ -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}} diff --git a/ifttt/ifttt.php b/ifttt/ifttt.php index 813ebad5..5962e2ae 100644 --- a/ifttt/ifttt.php +++ b/ifttt/ifttt.php @@ -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 .= ''; - $s .= '

' . DI::l10n()->t('IFTTT Mirror') . '

'; - $s .= '
'; - $s .= ''; + $t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/ifttt/'); + $html = Renderer::replaceMacros($t, [ + '$l10n' => [ + 'intro' => DI::l10n()->t('Create an account at IFTTT. Create three Facebook recipes that are connected with Maker (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'); } } diff --git a/ifttt/templates/connector_settings.tpl b/ifttt/templates/connector_settings.tpl new file mode 100644 index 00000000..dfa824c0 --- /dev/null +++ b/ifttt/templates/connector_settings.tpl @@ -0,0 +1,15 @@ +

{{$l10n.intro nofilter}}

+
+
{{$l10n.url}}
+
{{$url}}
+
{{$l10n.method}}
+
POST
+
{{$l10n.content_type}}
+
application/x-www-form-urlencoded
+
{{$l10n.new_status_message_body}}
+
{{$new_status_message_body}}
+
{{$l10n.new_photo_upload_body}}
+
{{$new_photo_upload_body}}
+
{{$l10n.new_link_post_body}}
+
{{$new_link_post_body}}
+
diff --git a/ijpost/ijpost.css b/ijpost/ijpost.css deleted file mode 100644 index 8b424917..00000000 --- a/ijpost/ijpost.css +++ /dev/null @@ -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; -} diff --git a/ijpost/ijpost.php b/ijpost/ijpost.php index 7ead0fb8..79cd75c8 100644 --- a/ijpost/ijpost.php +++ b/ijpost/ijpost.php @@ -8,9 +8,11 @@ * Author: Cat Gray */ +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'] .= '' . "\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 .= ''; - $s .= '

'. DI::l10n()->t("InsaneJournal Export").'

'; - $s .= '
'; - $s .= ''; + $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) diff --git a/ijpost/templates/connector_settings.tpl b/ijpost/templates/connector_settings.tpl new file mode 100644 index 00000000..0abcd24e --- /dev/null +++ b/ijpost/templates/connector_settings.tpl @@ -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}} diff --git a/libertree/libertree.css b/libertree/libertree.css deleted file mode 100644 index 1554048b..00000000 --- a/libertree/libertree.css +++ /dev/null @@ -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; -} - diff --git a/libertree/libertree.php b/libertree/libertree.php index 90910a39..df53aa18 100644 --- a/libertree/libertree.php +++ b/libertree/libertree.php @@ -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'] .= '' . "\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 .= ''; - $s .= '

'. DI::l10n()->t('libertree Export').'

'; - $s .= '
'; - $s .= ''; +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, + ]; } diff --git a/libertree/templates/connector_settings.tpl b/libertree/templates/connector_settings.tpl new file mode 100644 index 00000000..63aa52fc --- /dev/null +++ b/libertree/templates/connector_settings.tpl @@ -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}} diff --git a/ljpost/livejournal.png b/ljpost/livejournal.png new file mode 100644 index 00000000..ecf004fa Binary files /dev/null and b/ljpost/livejournal.png differ diff --git a/ljpost/ljpost.php b/ljpost/ljpost.php index 6174a461..073a977e 100644 --- a/ljpost/ljpost.php +++ b/ljpost/ljpost.php @@ -8,9 +8,11 @@ * Author: Cat Gray */ +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'] .= '' . "\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 .= '
'; - $s .= '

' . DI::l10n()->t('LiveJournal Post Settings') . '

'; - $s .= '
'; - $s .= ''; - $s .= ''; - $s .= '
'; - - $s .= '
'; - $s .= ''; - $s .= ''; - $s .= '
'; - - $s .= '
'; - $s .= ''; - $s .= ''; - $s .= '
'; - - $s .= '
'; - $s .= ''; - $s .= ''; - $s .= '
'; - - /* provide a submit button */ - - $s .= '
'; +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, + ]; } diff --git a/ljpost/templates/connector_settings.tpl b/ljpost/templates/connector_settings.tpl new file mode 100644 index 00000000..0abcd24e --- /dev/null +++ b/ljpost/templates/connector_settings.tpl @@ -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}} diff --git a/pumpio/pumpio.css b/pumpio/pumpio.css deleted file mode 100644 index 86dc5a0d..00000000 --- a/pumpio/pumpio.css +++ /dev/null @@ -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; -} - diff --git a/pumpio/pumpio.php b/pumpio/pumpio.php index e9084534..62ad7712 100644 --- a/pumpio/pumpio.php +++ b/pumpio/pumpio.php @@ -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'] .= '' . "\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 .= ''; - $s .= '

'. DI::l10n()->t('Pump.io Import/Export/Mirror').'

'; - $s .= '
'; - $s .= ''; + $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'); } } } diff --git a/pumpio/templates/connector_settings.tpl b/pumpio/templates/connector_settings.tpl new file mode 100644 index 00000000..6c688ad4 --- /dev/null +++ b/pumpio/templates/connector_settings.tpl @@ -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}} + +{{/if}} diff --git a/statusnet/statusnet.css b/statusnet/statusnet.css index f50d9c05..21f4733f 100644 --- a/statusnet/statusnet.css +++ b/statusnet/statusnet.css @@ -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; -} diff --git a/statusnet/statusnet.php b/statusnet/statusnet.php index 75e44151..b2582b86 100644 --- a/statusnet/statusnet.php +++ b/statusnet/statusnet.php @@ -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'] .= '' . "\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 .= ''; - $s .= '

' . DI::l10n()->t('GNU Social Import/Export/Mirror') . '

'; - $s .= '
'; - $s .= '
'; + + + $t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/statusnet/'); + $html = Renderer::replaceMacros($t, [ + '$l10n' => [ + 'global_title' => DI::l10n()->t('Globally Available GNU Social OAuthKeys'), + 'global_info' => DI::l10n()->t(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 (see below).')), + 'credentials_title' => DI::l10n()->t('Provide your own OAuth Credentials'), + 'credentials_info' => DI::l10n()->t('No consumer key pair for GNU Social found. Register your Friendica Account as a desktop application on your GNU Social account, copy the consumer key pair here and enter the API base root.
Before you register your own OAuth key pair ask the administrator if there is already a key pair for this Friendica installation at your favorite GNU Social installation.'), + 'oauth_info' => 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 public posts will be posted to GNU Social.'), + 'oauth_alt' => DI::l10n()->t('Log in with GNU Social'), + 'oauth_cancel' => DI::l10n()->t('Cancel Connection Process'), + 'oauth_api' => DI::l10n()->t('Current GNU Social API is: %s', $baseapi), + 'connected_account' => $connected_account ?? '', + 'privacy_warning' => $privacy_warning ?? '', + ], + + '$ckey' => $ckey, + '$csecret' => $csecret, + '$otoken' => $otoken, + '$osecret' => $osecret, + '$sites' => $sites, + + '$authorize_url' => $authorize_url ?? '', + '$request_token' => $request_token ?? null, + '$account' => $account ?? null, + + '$authenticate_url' => DI::baseUrl()->get() . '/statusnet/connect', + + '$consumerkey' => ['statusnet-consumerkey', DI::l10n()->t('OAuth Consumer Key'), '', '', false, ' size="35'], + '$consumersecret' => ['statusnet-consumersecret', DI::l10n()->t('OAuth Consumer Secret'), '', '', false, ' size="35'], + + '$baseapi' => ['statusnet-baseapi', DI::l10n()->t('Base API Path (remember the trailing /)'), '', '', false, ' size="35'], + '$pin' => ['statusnet-pin', DI::l10n()->t('Copy the security code from GNU Social here')], + + '$enable' => ['statusnet-enabled', DI::l10n()->t('Allow posting to GNU Social'), $enabled, DI::l10n()->t('If enabled all your public 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.')], + '$default' => ['statusnet-default', DI::l10n()->t('Post to GNU Social by default'), $def_enabled], + '$mirror' => ['statusnet-mirror', DI::l10n()->t('Mirror all public posts'), $mirror_enabled], + '$create_user' => ['statusnet-create_user', DI::l10n()->t('Automatically create contacts'), $createuser_enabled], + '$import' => ['statusnet-import', DI::l10n()->t('Import the remote timeline'), $import, '', [ + 0 => DI::l10n()->t('Disabled'), + 1 => DI::l10n()->t('Full Timeline'), + 2 => DI::l10n()->t('Only Mentions'), + ]], + ]); + + $data = [ + 'connector' => 'statusnet', + 'title' => DI::l10n()->t('GNU Social Import/Export/Mirror'), + 'image' => 'images/gnusocial.png', + 'enabled' => $enabled, + 'html' => $html, + 'submit' => $submit, + ]; } function statusnet_hook_fork(App $a, array &$b) diff --git a/statusnet/templates/connector_settings.tpl b/statusnet/templates/connector_settings.tpl new file mode 100644 index 00000000..b5a497a8 --- /dev/null +++ b/statusnet/templates/connector_settings.tpl @@ -0,0 +1,50 @@ +{{if $ckey && $csecret}} + {{if $otoken && $osecret}} + {{if $account}} +
+ +

+ {{$l10n.connected_account nofilter}}
+ {{$account->description}} +

+
+ {{/if}} + {{include file="field_checkbox.tpl" field=$enable}} +

{{$l10n.connected_public nofilter}}

+ {{if $l10n.privacy_warning}} +

{{$l10n.privacy_warning nofilter}}

+ {{/if}} + + {{include file="field_checkbox.tpl" field=$default}} + {{include file="field_checkbox.tpl" field=$mirror}} + {{include file="field_checkbox.tpl" field=$import}} + {{*include file="field_checkbox.tpl" field=$create_user*}} + {{else}} +

{{$l10n.oauth_info}}

+ {{$l10n.oauth_alt}} +
+ + + {{include file="field_input.tpl" field=$pin}} +
+ +

{{$l10n.oauth_api}}

+ {{/if}} +{{else}} + {{if $sites}} +

{{$l10n.global_title}}

+

{{$l10n.global_info}}

+
+ {{foreach $sites as $site}} + {{include file="field_radio.tpl" field=$site}} + {{/foreach}} +
+ {{/if}} +

{{$l10n.credentials_title}}

+

{{$l10n.credentials_info nofilter}}

+
+ {{include file="field_input.tpl" field=$consumerkey}} + {{include file="field_input.tpl" field=$consumersecret}} + {{include file="field_input.tpl" field=$baseapi}} +
+{{/if}} \ No newline at end of file diff --git a/tumblr/templates/connector_settings.tpl b/tumblr/templates/connector_settings.tpl new file mode 100644 index 00000000..d28fab9d --- /dev/null +++ b/tumblr/templates/connector_settings.tpl @@ -0,0 +1,10 @@ +

{{$l10n.connect}}

+ +{{include file="field_checkbox.tpl" field=$enable}} +{{include file="field_checkbox.tpl" field=$bydefault}} + +{{if $page_select}} + {{include file="field_select.tpl" field=$page_select}} +{{else}} + {{$l10n.noconnect}} +{{/if}} diff --git a/tumblr/tumblr.css b/tumblr/tumblr.css deleted file mode 100644 index c76fb61e..00000000 --- a/tumblr/tumblr.css +++ /dev/null @@ -1,16 +0,0 @@ - -#tumblr-enable-label, #tumblr-username-label, #tumblr-page-label, #tumblr-bydefault-label { - float: left; - width: 200px; - margin-top: 10px; -} - -#tumblr-checkbox, #tumblr-username, #tumblr-page, #tumblr-bydefault { - float: left; - margin-top: 10px; -} - -#tumblr-submit { - margin-top: 15px; -} - diff --git a/tumblr/tumblr.php b/tumblr/tumblr.php index e664ed7b..5ae0dd1b 100644 --- a/tumblr/tumblr.php +++ b/tumblr/tumblr.php @@ -198,89 +198,54 @@ function tumblr_jot_nets(App $a, array &$jotnets_fields) } } -function tumblr_settings(App $a, &$s) +function tumblr_settings(App $a, array &$data) { - if (! local_user()) { + if (!local_user()) { return; } - /* Add our stylesheet to the page so we can make our settings look nice */ - - DI::page()['htmlhead'] .= '' . "\r\n"; - - /* Get the current state of our config variables */ - - $enabled = DI::pConfig()->get(local_user(), 'tumblr', 'post'); - $checked = (($enabled) ? ' checked="checked" ' : ''); - $css = (($enabled) ? '' : '-disabled'); - - $def_enabled = DI::pConfig()->get(local_user(), 'tumblr', 'post_by_default'); - - $def_checked = (($def_enabled) ? ' checked="checked" ' : ''); - - /* Add some HTML to the existing form */ - - $s .= ''; - $s .= '

'. DI::l10n()->t('Tumblr Export').'

'; - $s .= '
'; - $s .= ''; + $data = [ + 'connector' => 'tumblr', + 'title' => DI::l10n()->t('Tumblr Export'), + 'image' => 'images/tumblr.png', + 'enabled' => $enabled, + 'html' => $html, + ]; } function tumblr_settings_post(App $a, array &$b) diff --git a/twitter/templates/connector_settings.tpl b/twitter/templates/connector_settings.tpl new file mode 100644 index 00000000..1c6b7131 --- /dev/null +++ b/twitter/templates/connector_settings.tpl @@ -0,0 +1,23 @@ +
+{{if $l10n.connected}} +

{{$l10n.connected nofilter}}

+

+ + {{$account->description}} +

+{{else}} +

{{$l10n.invalid}}

+ +{{/if}} +
+ +
+ +{{include file="field_checkbox.tpl" field=$enable}} +{{if $l10n.privacy_warning}} +

{{$l10n.privacy_warning nofilter}}

+{{/if}} +{{include file="field_checkbox.tpl" field=$default}} +{{include file="field_checkbox.tpl" field=$mirror}} +{{include file="field_checkbox.tpl" field=$import}} +{{include file="field_checkbox.tpl" field=$create_user}} diff --git a/twitter/twitter.css b/twitter/twitter.css index 99ee0bef..480ce28d 100644 --- a/twitter/twitter.css +++ b/twitter/twitter.css @@ -10,34 +10,3 @@ height: 52px; vertical-align: middle; } -#twitter-disconnect-label { - float: left; - width: 250px; - margin-bottom: 25px; -} - -#twitter-disconnect { - float: left; -} -#twitter-default-label, -#twitter-sendtaglinks-label, -#twitter-enable-label, -#twitter-shortening-label, -#twitter-mirror-label, -#twitter-import-label, -#twitter-create_user-label, -#twitter-pin-label { - float: left; - width: 250px; - margin-bottom: 10px; -} - -#twitter-checkbox { - float: left; -} - -#twitter-pin { - float: left; -} - - diff --git a/twitter/twitter.php b/twitter/twitter.php index e3e664f3..33af5663 100644 --- a/twitter/twitter.php +++ b/twitter/twitter.php @@ -269,8 +269,6 @@ function twitter_settings_post(App $a) } catch(TwitterOAuthException $e) { notice($e->getMessage()); } - // 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 tweet for every new __public__ posting to the wall @@ -287,7 +285,7 @@ function twitter_settings_post(App $a) } } -function twitter_settings(App $a, &$s) +function twitter_settings(App $a, array &$data) { if (!local_user()) { return; @@ -295,7 +293,8 @@ function twitter_settings(App $a, &$s) $user = User::getById(local_user()); - DI::page()['htmlhead'] .= '' . "\r\n"; + DI::page()->registerStylesheet(__DIR__ . '/twitter.css', 'all'); + /* * * * 1) Check that we have global consumer key & secret * 2) If no OAuthtoken & stuff is present, generate button to get some @@ -312,21 +311,14 @@ function twitter_settings(App $a, &$s) $importenabled = intval(DI::pConfig()->get(local_user(), 'twitter', 'import')); $create_userenabled = intval(DI::pConfig()->get(local_user(), 'twitter', 'create_user')); - $css = (($enabled) ? '' : '-disabled'); - - $s .= ''; - $s .= '

' . DI::l10n()->t('Twitter Import/Export/Mirror') . '

'; - $s .= '
'; - $s .= '
'; + + $data = [ + 'connector' => 'twitter', + 'title' => DI::l10n()->t('Twitter Import/Export/Mirror'), + 'enabled' => $enabled, + 'image' => 'images/twitter.png', + 'html' => $html, + 'submit' => $submit ?? null, + ]; } function twitter_hook_fork(App $a, array &$b) diff --git a/wppost/templates/connector_settings.tpl b/wppost/templates/connector_settings.tpl new file mode 100644 index 00000000..0afd676c --- /dev/null +++ b/wppost/templates/connector_settings.tpl @@ -0,0 +1,5 @@ +{{include file="field_checkbox.tpl" field=$enabled}} +{{include file="field_input.tpl" field=$username}} +{{include file="field_password.tpl" field=$password}} +{{include file="field_input.tpl" field=$blog}} +{{include file="field_checkbox.tpl" field=$bydefault}} diff --git a/wppost/wppost.css b/wppost/wppost.css deleted file mode 100644 index d5a39fde..00000000 --- a/wppost/wppost.css +++ /dev/null @@ -1,20 +0,0 @@ - -#wppost-enable-label, #wppost-username-label, #wppost-password-label, -#wppost-blog-label, #wppost-bydefault-label, -#wppost-backlink-label, #wppost-shortcheck-label { - float: left; - width: 200px; - margin-top: 10px; -} - -#wppost-checkbox, #wppost-username, #wppost-password, -#wppost-blog, #wppost-bydefault, -#wppost-shortcheck, #wppost-backlink { - float: left; - margin-top: 10px; -} - -#wppost-submit { - margin-top: 15px; -} - diff --git a/wppost/wppost.php b/wppost/wppost.php index c78157c8..f57772d3 100644 --- a/wppost/wppost.php +++ b/wppost/wppost.php @@ -6,10 +6,12 @@ * Author: Mike Macgirvin */ +use Friendica\App; use Friendica\Content\Text\BBCode; use Friendica\Content\Text\HTML; use Friendica\Core\Hook; use Friendica\Core\Logger; +use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\DI; use Friendica\Model\Post; @@ -25,7 +27,7 @@ function wppost_install() Hook::register('connector_settings_post', 'addon/wppost/wppost.php', 'wppost_settings_post'); } -function wppost_jot_nets(\Friendica\App &$a, array &$jotnets_fields) +function wppost_jot_nets(App &$a, array &$jotnets_fields) { if (!local_user()) { return; @@ -44,92 +46,39 @@ function wppost_jot_nets(\Friendica\App &$a, array &$jotnets_fields) } -function wppost_settings(&$a, &$s) { - - if(! local_user()) +function wppost_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'] .= '' . "\r\n"; - - /* Get the current state of our config variables */ - - $enabled = DI::pConfig()->get(local_user(),'wppost','post'); - $checked = (($enabled) ? ' checked="checked" ' : ''); - - $css = (($enabled) ? '' : '-disabled'); - - $def_enabled = DI::pConfig()->get(local_user(),'wppost','post_by_default'); - $back_enabled = DI::pConfig()->get(local_user(),'wppost','backlink'); - $shortcheck_enabled = DI::pConfig()->get(local_user(),'wppost','shortcheck'); - - $def_checked = (($def_enabled) ? ' checked="checked" ' : ''); - $back_checked = (($back_enabled) ? ' checked="checked" ' : ''); - $shortcheck_checked = (($shortcheck_enabled) ? ' checked="checked" ' : ''); - - $wp_username = DI::pConfig()->get(local_user(), 'wppost', 'wp_username'); - $wp_password = DI::pConfig()->get(local_user(), 'wppost', 'wp_password'); - $wp_blog = DI::pConfig()->get(local_user(), 'wppost', 'wp_blog'); - $wp_backlink_text = DI::pConfig()->get(local_user(), 'wppost', 'wp_backlink_text'); - - - /* Add some HTML to the existing form */ - - $s .= ''; - $s .= '

'. DI::l10n()->t('Wordpress Export').'

'; - $s .= '
'; - $s .= ''; - + $enabled = DI::pConfig()->get(local_user(), 'wppost', 'post', false); + $wp_username = DI::pConfig()->get(local_user(), 'wppost', 'wp_username'); + $wp_blog = DI::pConfig()->get(local_user(), 'wppost', 'wp_blog'); + $def_enabled = DI::pConfig()->get(local_user(), 'wppost', 'post_by_default', false); + $back_enabled = DI::pConfig()->get(local_user(), 'wppost', 'backlink', false); + $wp_backlink_text = DI::pConfig()->get(local_user(), 'wppost', 'wp_backlink_text'); + $shortcheck_enabled = DI::pConfig()->get(local_user(), 'wppost', 'shortcheck', false); + + $t = Renderer::getMarkupTemplate('connector_settings.tpl', 'addon/wppost/'); + $html = Renderer::replaceMacros($t, [ + '$enabled' => ['wppost', DI::l10n()->t('Enable Wordpress Post Addon'), $enabled], + '$username' => ['wp_username', DI::l10n()->t('Wordpress username'), $wp_username], + '$password' => ['wp_password', DI::l10n()->t('Wordpress password')], + '$blog' => ['wp_blog', DI::l10n()->t('WordPress API URL'), $wp_blog], + '$bydefault' => ['wp_bydefault', DI::l10n()->t('Post to Wordpress by default'), $def_enabled], + '$backlink' => ['wp_backlink', DI::l10n()->t('Provide a backlink to the Friendica post'), $back_enabled], + '$backlink_text' => ['wp_backlink_text', DI::l10n()->t('Text for the backlink, e.g. Read the original post and comment stream on Friendica.'), $wp_backlink_text], + '$shortcheck' => ['wp_shortcheck', DI::l10n()->t('Don\'t post messages that are too short'), $shortcheck_enabled], + ]); + + $data = [ + 'connector' => 'wppost', + 'title' => DI::l10n()->t('Wordpress Export'), + 'image' => 'images/wordpress.png', + 'enabled' => $enabled, + 'html' => $html, + ]; }