]> git.mxchange.org Git - friendica.git/commitdiff
create event for parse_link hook
authorArt4 <art4@wlabs.de>
Wed, 26 Mar 2025 08:30:20 +0000 (08:30 +0000)
committerArt4 <art4@wlabs.de>
Wed, 26 Mar 2025 08:30:20 +0000 (08:30 +0000)
src/Core/Hooks/HookEventBridge.php
src/Event/ArrayFilterEvent.php
src/Module/ParseUrl.php
tests/Unit/Core/Hooks/HookEventBridgeTest.php
tests/Unit/Event/ArrayFilterEventTest.php

index 84835dc7806b59d5479c90af0ac5fe7e6197086d..0beeec8667f29a23a703c93ab846dff21f852467 100644 (file)
@@ -54,6 +54,7 @@ final class HookEventBridge
                ArrayFilterEvent::PREPARE_POST_END                => 'prepare_body_final',
                ArrayFilterEvent::PHOTO_UPLOAD_FORM               => 'photo_upload_form',
                ArrayFilterEvent::NETWORK_TO_NAME                 => 'network_to_name',
+               ArrayFilterEvent::PARSE_LINK                      => 'parse_link',
                ArrayFilterEvent::CONVERSATION_START              => 'conversation_start',
                ArrayFilterEvent::FETCH_ITEM_BY_LINK              => 'item_by_link',
                ArrayFilterEvent::ITEM_TAGGED                     => 'tagged',
@@ -130,6 +131,7 @@ final class HookEventBridge
                        ArrayFilterEvent::PREPARE_POST_END                => 'onArrayFilterEvent',
                        ArrayFilterEvent::PHOTO_UPLOAD_FORM               => 'onArrayFilterEvent',
                        ArrayFilterEvent::NETWORK_TO_NAME                 => 'onArrayFilterEvent',
+                       ArrayFilterEvent::PARSE_LINK                      => 'onArrayFilterEvent',
                        ArrayFilterEvent::CONVERSATION_START              => 'onArrayFilterEvent',
                        ArrayFilterEvent::FETCH_ITEM_BY_LINK              => 'onArrayFilterEvent',
                        ArrayFilterEvent::ITEM_TAGGED                     => 'onArrayFilterEvent',
index de92599ee353a795e6dcf31f22a0f6154316e3dc..c9ae0fabe189c898aa207382c2fddc95d03e7a1f 100644 (file)
@@ -58,6 +58,8 @@ final class ArrayFilterEvent extends Event
 
        public const NETWORK_TO_NAME = 'friendica.data.network_to_name';
 
+       public const PARSE_LINK = 'friendica.data.parse_link';
+
        public const CONVERSATION_START = 'friendica.data.conversation_start';
 
        public const FETCH_ITEM_BY_LINK = 'friendica.data.fetch_item_by_link';
index 8da72c742c6c5963e71c5bdd658c8f790acd4f1b..508e5d987d586d1f6354c2ea7584b6d102b3d2b8 100644 (file)
@@ -11,12 +11,13 @@ use Friendica\App\Arguments;
 use Friendica\App\BaseURL;
 use Friendica\BaseModule;
 use Friendica\Content\Text\BBCode;
-use Friendica\Core\Hook;
 use Friendica\Core\L10n;
 use Friendica\Core\Session\Capability\IHandleUserSessions;
+use Friendica\Event\ArrayFilterEvent;
 use Friendica\Network\HTTPException\BadRequestException;
 use Friendica\Util;
 use Friendica\Util\Profiler;
+use Psr\EventDispatcher\EventDispatcherInterface;
 use Psr\Log\LoggerInterface;
 
 class ParseUrl extends BaseModule
@@ -24,11 +25,14 @@ class ParseUrl extends BaseModule
        /** @var IHandleUserSessions */
        protected $userSession;
 
-       public function __construct(L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $userSession, $server, array $parameters = [])
+       private EventDispatcherInterface $eventDispatcher;
+
+       public function __construct(L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $userSession, EventDispatcherInterface $eventDispatcher, $server, array $parameters = [])
        {
                parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
 
                $this->userSession = $userSession;
+               $this->eventDispatcher = $eventDispatcher;
        }
 
        protected function rawContent(array $request = [])
@@ -80,15 +84,21 @@ class ParseUrl extends BaseModule
                        }
                }
 
-               $arr = ['url' => $url, 'format' => $format, 'text' => null];
+               $hook_data = [
+                       'url' => $url,
+                       'format' => $format,
+                       'text' => null,
+               ];
 
-               Hook::callAll('parse_link', $arr);
+               $hook_data = $this->eventDispatcher->dispatch(
+                       new ArrayFilterEvent(ArrayFilterEvent::PARSE_LINK, $hook_data),
+               )->getArray();
 
-               if ($arr['text']) {
+               if ($hook_data['text']) {
                        if ($format == 'json') {
-                               $this->jsonExit($arr['text']);
+                               $this->jsonExit($hook_data['text']);
                        } else {
-                               $this->httpExit($arr['text']);
+                               $this->httpExit($hook_data['text']);
                        }
                }
 
index 075630da1c88e7c4aad750a91809ec60e744d07e..bdfe5d5508badd3fdd959463378ecf32d1b08054 100644 (file)
@@ -43,6 +43,7 @@ class HookEventBridgeTest extends TestCase
                        ArrayFilterEvent::PREPARE_POST_END                => 'onArrayFilterEvent',
                        ArrayFilterEvent::PHOTO_UPLOAD_FORM               => 'onArrayFilterEvent',
                        ArrayFilterEvent::NETWORK_TO_NAME                 => 'onArrayFilterEvent',
+                       ArrayFilterEvent::PARSE_LINK                      => 'onArrayFilterEvent',
                        ArrayFilterEvent::CONVERSATION_START              => 'onArrayFilterEvent',
                        ArrayFilterEvent::FETCH_ITEM_BY_LINK              => 'onArrayFilterEvent',
                        ArrayFilterEvent::ITEM_TAGGED                     => 'onArrayFilterEvent',
@@ -460,6 +461,7 @@ class HookEventBridgeTest extends TestCase
                        [ArrayFilterEvent::PREPARE_POST_END, 'prepare_body_final'],
                        [ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'photo_upload_form'],
                        [ArrayFilterEvent::NETWORK_TO_NAME, 'network_to_name'],
+                       [ArrayFilterEvent::PARSE_LINK, 'parse_link'],
                        [ArrayFilterEvent::CONVERSATION_START, 'conversation_start'],
                        [ArrayFilterEvent::FETCH_ITEM_BY_LINK, 'item_by_link'],
                        [ArrayFilterEvent::ITEM_TAGGED, 'tagged'],
index 881deacd434b6e8a2cdaf9b277079abff2407844..fafd1a66e076a4c9e80ba11f4512d6851d982482 100644 (file)
@@ -40,6 +40,7 @@ class ArrayFilterEventTest extends TestCase
                        [ArrayFilterEvent::PREPARE_POST_END, 'friendica.data.prepare_post_end'],
                        [ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'friendica.data.photo_upload_form'],
                        [ArrayFilterEvent::NETWORK_TO_NAME, 'friendica.data.network_to_name'],
+                       [ArrayFilterEvent::PARSE_LINK, 'friendica.data.parse_link'],
                        [ArrayFilterEvent::CONVERSATION_START, 'friendica.data.conversation_start'],
                        [ArrayFilterEvent::FETCH_ITEM_BY_LINK, 'friendica.data.fetch_item_by_link'],
                        [ArrayFilterEvent::ITEM_TAGGED, 'friendica.data.item_tagged'],