Merge pull request #1330 from MrPetovan/bug/warnings

[nsfw] Suppress warnings about failed regexp compilation
This commit is contained in:
Michael Vogel 2022-12-10 20:53:48 +01:00 committed by GitHub
commit e553b6cc9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 6 deletions

View file

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-18 11:57-0500\n" "POT-Creation-Date: 2022-12-10 14:42-0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -43,12 +43,17 @@ msgstr ""
msgid "Content Filter (NSFW and more)" msgid "Content Filter (NSFW and more)"
msgstr "" msgstr ""
#: nsfw.php:140 #: nsfw.php:96
#, php-format
msgid "Regular expression \"%s\" fails to compile"
msgstr ""
#: nsfw.php:154
#, php-format #, php-format
msgid "Filtered tag: %s" msgid "Filtered tag: %s"
msgstr "" msgstr ""
#: nsfw.php:142 #: nsfw.php:156
#, php-format #, php-format
msgid "Filtered word: %s" msgid "Filtered word: %s"
msgstr "" msgstr ""

View file

@ -81,9 +81,23 @@ function nsfw_addon_settings_post(App $a, array &$b)
} }
if (!empty($_POST['nsfw-submit'])) { if (!empty($_POST['nsfw-submit'])) {
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'nsfw', 'words', trim($_POST['nsfw-words'])); $enable = !empty($_POST['nsfw-enable']) ? intval($_POST['nsfw-enable']) : 0;
$enable = (!empty($_POST['nsfw-enable']) ? intval($_POST['nsfw-enable']) : 0);
$disable = 1 - $enable; $disable = 1 - $enable;
$words = trim($_POST['nsfw-words']);
$word_list = explode(',', $words);
foreach ($word_list as $word) {
$word = trim($word);
if (!$words || $word[0] != '/') {
continue;
}
if (@preg_match($word, '') === false) {
DI::sysmsg()->addNotice(DI::l10n()->t('Regular expression "%s" fails to compile', $word));
};
}
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'nsfw', 'words', $words);
DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'nsfw', 'disable', $disable); DI::pConfig()->set(DI::userSession()->getLocalUserId(), 'nsfw', 'disable', $disable);
} }
} }
@ -118,7 +132,7 @@ function nsfw_prepare_body_content_filter(App $a, &$hook_data)
$tag_search = false; $tag_search = false;
switch ($word[0]) { switch ($word[0]) {
case '/'; // Regular expression case '/'; // Regular expression
$found = preg_match($word, $body); $found = @preg_match($word, $body);
break; break;
case '#': // Hashtag-only search case '#': // Hashtag-only search
$tag_search = true; $tag_search = true;