*/
private static function getBlockedSQL(): string
{
- $blocked_txt = DI::config()->get('system', 'blocked_tags');
- if (empty($blocked_txt)) {
+ $blocked = Strings::getTagArrayByString(DI::config()->get('system', 'blocked_tags'));
+ if (empty($blocked)) {
return '';
}
- $blocked = explode(',', $blocked_txt);
array_walk($blocked, function (&$value) {
$value = "'" . DBA::escape(trim($value)) . "'";
});
$transactionConfig->set('system', 'explicit_content' , $explicit_content);
$transactionConfig->set('system', 'proxify_content' , $proxify_content);
$transactionConfig->set('system', 'local_search' , $local_search);
- $transactionConfig->set('system', 'blocked_tags' , $blocked_tags);
+ $transactionConfig->set('system', 'blocked_tags' , Strings::cleanTags($blocked_tags));
$transactionConfig->set('system', 'cache_contact_avatar' , $cache_contact_avatar);
$transactionConfig->set('system', 'check_new_version_url' , $check_new_version_url);
$transactionConfig->set('system', 'relay_directly' , $relay_directly);
$transactionConfig->set('system', 'relay_scope' , $relay_scope);
- $transactionConfig->set('system', 'relay_server_tags' , $relay_server_tags);
- $transactionConfig->set('system', 'relay_deny_tags' , $relay_deny_tags);
+ $transactionConfig->set('system', 'relay_server_tags' , Strings::cleanTags($relay_server_tags));
+ $transactionConfig->set('system', 'relay_deny_tags' , Strings::cleanTags($relay_deny_tags));
$transactionConfig->set('system', 'relay_max_tags' , $relay_max_tags);
$transactionConfig->set('system', 'relay_user_tags' , $relay_user_tags);
$transactionConfig->set('system', 'relay_deny_undetected_language', $relay_deny_undetected_language);
use Friendica\Module\Response;
use Friendica\Network\HTTPException;
use Friendica\Util\Profiler;
+use Friendica\Util\Strings;
use Psr\Log\LoggerInterface;
class Channels extends BaseSettings
'access-key' => substr(mb_strtolower($request['new_access_key']), 0, 1),
'uid' => $uid,
'circle' => (int)$request['new_circle'],
- 'include-tags' => $this->cleanTags($request['new_include_tags']),
- 'exclude-tags' => $this->cleanTags($request['new_exclude_tags']),
+ 'include-tags' => Strings::cleanTags($request['new_include_tags']),
+ 'exclude-tags' => Strings::cleanTags($request['new_exclude_tags']),
'full-text-search' => $request['new_text_search'],
'media-type' => ($request['new_image'] ? 1 : 0) | ($request['new_video'] ? 2 : 0) | ($request['new_audio'] ? 4 : 0),
'languages' => $request['new_languages'],
'access-key' => substr(mb_strtolower($request['access_key'][$id]), 0, 1),
'uid' => $uid,
'circle' => (int)$request['circle'][$id],
- 'include-tags' => $this->cleanTags($request['include_tags'][$id]),
- 'exclude-tags' => $this->cleanTags($request['exclude_tags'][$id]),
+ 'include-tags' => Strings::cleanTags($request['include_tags'][$id]),
+ 'exclude-tags' => Strings::cleanTags($request['exclude_tags'][$id]),
'full-text-search' => $request['text_search'][$id],
'media-type' => ($request['image'][$id] ? 1 : 0) | ($request['video'][$id] ? 2 : 0) | ($request['audio'][$id] ? 4 : 0),
'languages' => $request['languages'][$id],
'$form_security_token' => self::getFormSecurityToken('settings_channels'),
]);
}
-
- private function cleanTags(string $tag_list): string
- {
- $tags = [];
-
- $tagitems = explode(',', mb_strtolower($tag_list));
- foreach ($tagitems as $tag) {
- $tag = trim($tag, '# ');
- if (!empty($tag)) {
- $tags[] = preg_replace('#\s#u', '', $tag);
- }
- }
- return implode(',', $tags);
- }
}
namespace Friendica\Module\WellKnown;
use Friendica\BaseModule;
-use Friendica\Core\System;
use Friendica\DI;
use Friendica\Model\Search;
use Friendica\Protocol\Relay;
+use Friendica\Util\Strings;
/**
* Node subscription preferences for social relay systems
$userTags = [];
if ($scope == Relay::SCOPE_TAGS) {
- $server_tags = $config->get('system', 'relay_server_tags');
- $tagitems = explode(',', $server_tags);
-
- /// @todo Check if it was better to use "strtolower" on the tags
- foreach ($tagitems as $tag) {
- $systemTags[] = trim($tag, '# ');
- }
+ $systemTags = Strings::getTagArrayByString($config->get('system', 'relay_server_tags'));
if ($config->get('system', 'relay_user_tags')) {
$userTags = Search::getUserTags();
$body = ActivityPub\Processor::normalizeMentionLinks($body);
- $denyTags = [];
-
if ($scope == self::SCOPE_TAGS) {
$tagList = self::getSubscribedTags();
} else {
$tagList = [];
}
- $deny_tags = $config->get('system', 'relay_deny_tags');
- $tagitems = explode(',', mb_strtolower($deny_tags));
- foreach ($tagitems as $tag) {
- $tag = trim($tag, '# ');
- $denyTags[] = $tag;
- }
+ $denyTags = Strings::getTagArrayByString($config->get('system', 'relay_deny_tags'));
if (!empty($tagList) || !empty($denyTags)) {
$content = mb_strtolower(BBCode::toPlaintext($body, false));
*/
public static function getSubscribedTags(): array
{
- $tags = [];
- foreach (explode(',', mb_strtolower(DI::config()->get('system', 'relay_server_tags'))) as $tag) {
- $tags[] = trim($tag, '# ');
- }
+ $tags = Strings::getTagArrayByString(DI::config()->get('system', 'relay_server_tags'));
if (DI::config()->get('system', 'relay_user_tags')) {
$tags = array_merge($tags, Search::getUserTags());
return $styled_url;
}
+
+ /**
+ * Sort a comma separated list of hashtags, convert them to lowercase and remove duplicates
+ *
+ * @param string $tag_list
+ * @return string
+ */
+ public static function cleanTags(string $tag_list): string
+ {
+ $tags = [];
+
+ $tagitems = explode(',', str_replace([' ', ';', '#'], ',', mb_strtolower($tag_list)));
+ foreach ($tagitems as $tag) {
+ if (!empty($tag)) {
+ $tags[] = preg_replace('#\s#u', '', $tag);
+ }
+ }
+ $tags = array_unique($tags);
+ asort($tags);
+ return implode(',', $tags);
+ }
+
+ /**
+ * Get a tag array out of a comma separated list of tags
+ *
+ * @param string $tag_list
+ * @return array
+ */
+ public static function getTagArrayByString(string $tag_list): array
+ {
+ return explode(',', self::cleanTags($tag_list));
+ }
}