From 332ab6641cb2402c9f5f4b216ad8687754bad3e0 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 26 Nov 2023 09:27:59 -0500 Subject: [PATCH 1/4] Pass actual string character to ctype_space in Content\Smilies::performForEachWordMatch - Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1826792949 --- src/Content/Smilies.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Content/Smilies.php b/src/Content/Smilies.php index 01ac832eac..29752701f0 100644 --- a/src/Content/Smilies.php +++ b/src/Content/Smilies.php @@ -224,10 +224,10 @@ class Smilies if (strlen($word) < 2) { continue; } - $ord1 = ord($word); + $ord1 = ord($word[0]); $ord2 = ord($word[1]); // A smiley shortcode must not begin or end with whitespaces. - if (ctype_space($ord1) || ctype_space($word[strlen($word) - 1])) { + if (ctype_space($word[0]) || ctype_space($word[strlen($word) - 1])) { continue; } $ord1_bitset |= 1 << ($ord1 & 31); From 838c73cbbafa7ced1c87f31f2042d6702386f4b6 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 26 Nov 2023 09:35:15 -0500 Subject: [PATCH 2/4] Skip empty name tags in ActivityPub\Processor::acceptIncomingMessage - Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1826792949 --- src/Protocol/ActivityPub/Processor.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index c8e8faed94..47355a4cb9 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -606,7 +606,7 @@ class Processor } catch (\Exception $exception) { Logger::notice('Error fetching url', ['url' => $url, 'exception' => $exception]); return true; - } + } // @todo To ensure that the remote system is working correctly, we can check if the "Content-Type" contains JSON if (in_array($curlResult->getReturnCode(), [401, 404])) { @@ -1114,7 +1114,7 @@ class Processor if (!empty($item['source']) && DI::config()->get('debug', 'store_source')) { Post\Activity::insert($item['uri-id'], $item['source']); } - + continue; } @@ -1613,7 +1613,7 @@ class Processor } else { return null; } - + $ldactivity['recursion-depth'] = !empty($child['recursion-depth']) ? $child['recursion-depth'] + 1 : 0; if ($object_actor != $actor) { @@ -1725,7 +1725,7 @@ class Processor $tags = Receiver::processTags(JsonLD::fetchElementArray($activity['as:object'], 'as:tag') ?? []); if (!empty($tags)) { foreach ($tags as $tag) { - if (($tag['type'] != 'Hashtag') && !strpos($tag['type'], ':Hashtag')) { + if (($tag['type'] != 'Hashtag') && !strpos($tag['type'], ':Hashtag') || empty($tag['name'])) { continue; } $messageTags[] = ltrim(mb_strtolower($tag['name']), '#'); From fb19176201773a77eb74035ca473a579d2fb27ab Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 26 Nov 2023 09:43:26 -0500 Subject: [PATCH 3/4] Remove DI dependency in Object\Api\Mastodon\Instance - Address part of https://github.com/friendica/friendica/issues/12011#issuecomment-1826792949 --- src/Module/Api/Mastodon/Instance.php | 16 ++++++++++++++-- src/Object/Api/Mastodon/Instance.php | 23 +++-------------------- 2 files changed, 17 insertions(+), 22 deletions(-) diff --git a/src/Module/Api/Mastodon/Instance.php b/src/Module/Api/Mastodon/Instance.php index 075d4a9dde..3784030c89 100644 --- a/src/Module/Api/Mastodon/Instance.php +++ b/src/Module/Api/Mastodon/Instance.php @@ -26,6 +26,8 @@ use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Database\Database; +use Friendica\Factory\Api\Mastodon\Account as AccountFactory; +use Friendica\Model\User; use Friendica\Module\Api\ApiResponse; use Friendica\Module\BaseApi; use Friendica\Object\Api\Mastodon\Instance as InstanceEntity; @@ -46,12 +48,16 @@ class Instance extends BaseApi /** @var IManageConfigValues */ private $config; - public function __construct(\Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, Database $database, IManageConfigValues $config, array $server, array $parameters = []) + /** @var AccountFactory */ + private $accountFactory; + + public function __construct(AccountFactory $accountFactory, \Friendica\Factory\Api\Mastodon\Error $errorFactory, App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, ApiResponse $response, Database $database, IManageConfigValues $config, array $server, array $parameters = []) { parent::__construct($errorFactory, $app, $l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); $this->database = $database; $this->config = $config; + $this->accountFactory = $accountFactory; } /** @@ -62,7 +68,13 @@ class Instance extends BaseApi */ protected function rawContent(array $request = []) { - $this->jsonExit(new InstanceEntity($this->config, $this->baseUrl, $this->database, System::getRules(), $this->buildConfigurationInfo())); + $administrator = User::getFirstAdmin(['nickname']); + if ($administrator) { + $adminContact = $this->database->selectFirst('contact', ['uri-id'], ['nick' => $administrator['nickname'], 'self' => true]); + $contact_account = $this->accountFactory->createFromUriId($adminContact['uri-id']); + } + + $this->jsonExit(new InstanceEntity($this->config, $this->baseUrl, $this->database, $this->buildConfigurationInfo(), $contact_account ?? null, System::getRules())); } private function buildConfigurationInfo(): InstanceV2Entity\Configuration diff --git a/src/Object/Api/Mastodon/Instance.php b/src/Object/Api/Mastodon/Instance.php index 18707356ef..6efb49c14a 100644 --- a/src/Object/Api/Mastodon/Instance.php +++ b/src/Object/Api/Mastodon/Instance.php @@ -27,10 +27,8 @@ use Friendica\BaseDataTransferObject; use Friendica\Contact\Header; use Friendica\Core\Config\Capability\IManageConfigValues; use Friendica\Database\Database; -use Friendica\DI; use Friendica\Model\User; use Friendica\Module\Register; -use Friendica\Network\HTTPException; use Friendica\Object\Api\Mastodon\InstanceV2\Configuration; /** @@ -68,23 +66,14 @@ class Instance extends BaseDataTransferObject protected $approval_required; /** @var bool */ protected $invites_enabled; - /** @var Account|null */ /** @var Configuration */ protected $configuration; + /** @var Account|null */ protected $contact_account = null; /** @var array */ protected $rules = []; - /** - * @param IManageConfigValues $config - * @param BaseURL $baseUrl - * @param Database $database - * @param array $rules - * @throws HTTPException\InternalServerErrorException - * @throws HTTPException\NotFoundException - * @throws \ImagickException - */ - public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database, array $rules = [], Configuration $configuration) + public function __construct(IManageConfigValues $config, BaseURL $baseUrl, Database $database, Configuration $configuration, ?Account $contact_account, array $rules) { $register_policy = intval($config->get('config', 'register_policy')); @@ -102,13 +91,7 @@ class Instance extends BaseDataTransferObject $this->approval_required = ($register_policy == Register::APPROVE); $this->invites_enabled = false; $this->configuration = $configuration; - $this->contact_account = []; + $this->contact_account = $contact_account ?? []; $this->rules = $rules; - - $administrator = User::getFirstAdmin(['nickname']); - if ($administrator) { - $adminContact = $database->selectFirst('contact', ['uri-id'], ['nick' => $administrator['nickname'], 'self' => true]); - $this->contact_account = DI::mstdnAccount()->createFromUriId($adminContact['uri-id']); - } } } From 3b3d0231bc6eedda373ca0904e5ab9a59dbc5e89 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Mon, 27 Nov 2023 12:07:18 -0500 Subject: [PATCH 4/4] Replace last occurrences of in_array used as a Smarty modifier - Address https://github.com/friendica/friendica/issues/13158#issuecomment-1826266366 --- view/templates/field_select.tpl | 8 ++++---- view/theme/frio/templates/field_select.tpl | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/view/templates/field_select.tpl b/view/templates/field_select.tpl index 187852e032..f02110628e 100644 --- a/view/templates/field_select.tpl +++ b/view/templates/field_select.tpl @@ -2,11 +2,11 @@
diff --git a/view/theme/frio/templates/field_select.tpl b/view/theme/frio/templates/field_select.tpl index 87cc27254b..4699ec47df 100644 --- a/view/theme/frio/templates/field_select.tpl +++ b/view/theme/frio/templates/field_select.tpl @@ -2,11 +2,11 @@