mirror of
https://git.friendi.ca/friendica/friendica-addons.git
synced 2025-07-13 03:48:49 +00:00
[nsfw] Suppress warnings about failed regexp compilation
- Add failed regexp compilation system messages on addon settings submit - Address https://github.com/friendica/friendica/issues/11992#issuecomment-1336418781
This commit is contained in:
parent
9524632cdc
commit
b1442ebfd1
2 changed files with 25 additions and 6 deletions
|
@ -81,9 +81,23 @@ function nsfw_addon_settings_post(App $a, array &$b)
|
|||
}
|
||||
|
||||
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;
|
||||
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
@ -118,7 +132,7 @@ function nsfw_prepare_body_content_filter(App $a, &$hook_data)
|
|||
$tag_search = false;
|
||||
switch ($word[0]) {
|
||||
case '/'; // Regular expression
|
||||
$found = preg_match($word, $body);
|
||||
$found = @preg_match($word, $body);
|
||||
break;
|
||||
case '#': // Hashtag-only search
|
||||
$tag_search = true;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue