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

- Add separate template files to several addons
- Remove superfluous addon settings CSS files
This commit is contained in:
Hypolite Petovan 2021-11-20 04:56:55 -05:00
parent f0522a998b
commit 779b38ec09
68 changed files with 444 additions and 953 deletions

View file

@ -1,19 +0,0 @@
#nsfw-label, #nsfw-enable-label {
float: left;
width: 300px;
margin-top: 10px;
}
#nsfw-words, #nsfw-enable {
float: left;
margin-top: 10px;
}
#nsfw-submit {
margin-top: 15px;
}
.nsfw-desc {
margin-top: 10px;
}

View file

@ -7,7 +7,10 @@
* Author: Mike Macgirvin <http://macgirvin.com/profile/mike>
*
*/
use Friendica\App;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\DI;
function nsfw_install()
@ -48,41 +51,27 @@ function nsfw_extract_photos($body)
return $new_body;
}
function nsfw_addon_settings(&$a, &$s)
function nsfw_addon_settings(App &$a, array &$data)
{
if (!local_user()) {
return;
}
DI::page()->registerStylesheet(__DIR__ . '/nsfw.css', 'all');
$enabled = !DI::pConfig()->get(local_user(), 'nsfw', 'disable');
$words = DI::pConfig()->get(local_user(), 'nsfw', 'words', 'nsfw,');
$t = Renderer::getMarkupTemplate('settings.tpl', 'addon/nsfw/');
$html = Renderer::replaceMacros($t, [
'$info' => DI::l10n()->t('This addon searches for specified words/text in posts and collapses them. It can be used to filter content tagged with for instance #NSFW that may be deemed inappropriate at certain times or places, such as being at work. It is also useful for hiding irrelevant or annoying content from direct view.'),
'$enabled' => ['nsfw-enable', DI::l10n()->t('Enable Content filter'), $enabled],
'$words' => ['nsfw-words', DI::l10n()->t('Comma separated list of keywords to hide'), $words, DI::l10n()->t('Use /expression/ to provide regular expressions')],
]);
$enable_checked = (intval(DI::pConfig()->get(local_user(), 'nsfw', 'disable')) ? '' : ' checked="checked" ');
$words = DI::pConfig()->get(local_user(), 'nsfw', 'words');
if (!$words) {
$words = 'nsfw,';
}
$s .= '<span id="settings_nsfw_inflated" class="settings-block fakelink" style="display: block;" onclick="openClose(\'settings_nsfw_expanded\'); openClose(\'settings_nsfw_inflated\');">';
$s .= '<h3>' . DI::l10n()->t('Content Filter (NSFW and more)') . '</h3>';
$s .= '</span>';
$s .= '<div id="settings_nsfw_expanded" class="settings-block" style="display: none;">';
$s .= '<span class="fakelink" onclick="openClose(\'settings_nsfw_expanded\'); openClose(\'settings_nsfw_inflated\');">';
$s .= '<h3>' . DI::l10n()->t('Content Filter (NSFW and more)') . '</h3>';
$s .= '</span>';
$s .= '<div id="nsfw-wrapper">';
$s .= '<p>' . DI::l10n()->t('This addon searches for specified words/text in posts and collapses them. It can be used to filter content tagged with for instance #NSFW that may be deemed inappropriate at certain times or places, such as being at work. It is also useful for hiding irrelevant or annoying content from direct view.') . '</p>';
$s .= '<label id="nsfw-enable-label" for="nsfw-enable">' . DI::l10n()->t('Enable Content filter') . ' </label>';
$s .= '<input id="nsfw-enable" type="checkbox" name="nsfw-enable" value="1"' . $enable_checked . ' />';
$s .= '<div class="clear"></div>';
$s .= '<label id="nsfw-label" for="nsfw-words">' . DI::l10n()->t('Comma separated list of keywords to hide') . ' </label>';
$s .= '<textarea id="nsfw-words" type="text" name="nsfw-words">' . $words . '</textarea>';
$s .= '</div><div class="clear"></div>';
$s .= '<div class="settings-submit-wrapper" ><input type="submit" id="nsfw-submit" name="nsfw-submit" class="settings-submit" value="' . DI::l10n()->t('Save Settings') . '" /></div>';
$s .= '<div class="nsfw-desc">' . DI::l10n()->t('Use /expression/ to provide regular expressions') . '</div></div>';
return;
$data = [
'addon' => 'nsfw',
'title' => DI::l10n()->t('Content Filter (NSFW and more)'),
'html' => $html,
];
}
function nsfw_addon_settings_post(&$a, &$b)
@ -99,7 +88,7 @@ function nsfw_addon_settings_post(&$a, &$b)
}
}
function nsfw_prepare_body_content_filter(\Friendica\App $a, &$hook_data)
function nsfw_prepare_body_content_filter(App $a, &$hook_data)
{
$words = null;
if (DI::pConfig()->get(local_user(), 'nsfw', 'disable')) {

View file

@ -0,0 +1,3 @@
<p>{{$info}}</p>
{{include file="field_checkbox.tpl" field=$enabled}}
{{include file="field_textarea.tpl" field=$words}}