]> git.mxchange.org Git - friendica.git/commitdiff
Replace hooks post_local_start, post_local and post_local_end with EventDispatcher
authorArt4 <art4@wlabs.de>
Sat, 8 Feb 2025 08:17:30 +0000 (08:17 +0000)
committerArt4 <art4@wlabs.de>
Sat, 8 Feb 2025 08:17:30 +0000 (08:17 +0000)
mod/item.php
src/Content/Item.php
src/Model/Item.php
src/Module/Post/Tag/Add.php

index de9a51915a5d9b9472b183baf9ad44713ed6557a..98528b59b1ace4c76471a2dc7ebb1fd26a4877af 100644 (file)
@@ -24,6 +24,7 @@ use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\ItemURI;
@@ -43,7 +44,11 @@ function item_post()
                item_drop($uid, $_REQUEST['dropitems']);
        }
 
-       Hook::callAll('post_local_start', $_REQUEST);
+       $eventDispatcher = DI::eventDispatcher();
+
+       $_REQUEST = $eventDispatcher->dispatch(
+               new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL_START, $_REQUEST)
+       )->getArray();
 
        $return_path = $_REQUEST['return'] ?? '';
        $preview     = intval($_REQUEST['preview'] ?? 0);
@@ -275,7 +280,11 @@ function item_process(array $post, array $request, bool $preview, string $return
                System::jsonExit(['preview' => $o]);
        }
 
-       Hook::callAll('post_local', $post);
+       $eventDispatcher = DI::eventDispatcher();
+
+       $post = $eventDispatcher->dispatch(
+               new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL, $post)
+       )->getArray();
 
        unset($post['edit']);
        unset($post['self']);
index aec01ae292ec9786f76b447a80a09fbc0f5fbfbc..ee20e3d168fb12a1dc5cd5149217355ccc25c200 100644 (file)
@@ -20,6 +20,7 @@ use Friendica\Core\Session\Capability\IHandleUserSessions;
 use Friendica\Core\System;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
 use Friendica\Model\Attach;
 use Friendica\Model\Circle;
 use Friendica\Model\Contact;
@@ -43,6 +44,7 @@ use Friendica\Util\Proxy;
 use Friendica\Util\XML;
 use GuzzleHttp\Psr7\Uri;
 use ImagickException;
+use Psr\EventDispatcher\EventDispatcherInterface;
 
 /**
  * A content helper class for displaying items
@@ -69,19 +71,21 @@ class Item
        private $emailer;
        /** @var AppHelper */
        private $appHelper;
+       private EventDispatcherInterface $eventDispatcher;
 
-       public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession, Video $bbCodeVideo, ACLFormatter $aclFormatter, IManagePersonalConfigValues $pConfig, BaseURL $baseURL, Emailer $emailer, AppHelper $appHelper)
+       public function __construct(Profiler $profiler, Activity $activity, L10n $l10n, IHandleUserSessions $userSession, Video $bbCodeVideo, ACLFormatter $aclFormatter, IManagePersonalConfigValues $pConfig, BaseURL $baseURL, Emailer $emailer, AppHelper $appHelper, EventDispatcherInterface $eventDispatcher)
        {
-               $this->profiler     = $profiler;
-               $this->activity     = $activity;
-               $this->l10n         = $l10n;
-               $this->userSession  = $userSession;
-               $this->bbCodeVideo  = $bbCodeVideo;
-               $this->aclFormatter = $aclFormatter;
-               $this->baseURL      = $baseURL;
-               $this->pConfig      = $pConfig;
-               $this->emailer      = $emailer;
-               $this->appHelper    = $appHelper;
+               $this->profiler        = $profiler;
+               $this->activity        = $activity;
+               $this->l10n            = $l10n;
+               $this->userSession     = $userSession;
+               $this->bbCodeVideo     = $bbCodeVideo;
+               $this->aclFormatter    = $aclFormatter;
+               $this->baseURL         = $baseURL;
+               $this->pConfig         = $pConfig;
+               $this->emailer         = $emailer;
+               $this->appHelper       = $appHelper;
+               $this->eventDispatcher = $eventDispatcher;
        }
 
        /**
@@ -1006,7 +1010,9 @@ class Item
                        Tag::createImplicitMentions($post['uri-id'], $post['thr-parent-id']);
                }
 
-               Hook::callAll('post_local_end', $post);
+               $post = $this->eventDispatcher->dispatch(
+                       new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL_END, $post)
+               )->getArray();
 
                $author = DBA::selectFirst('contact', ['thumb'], ['uid' => $post['uid'], 'self' => true]);
 
index 00435e2d4d66d865c01fe444602e869eb629e37f..c796a1e5bf74ed59a66319d3354c04476bcd01c5 100644 (file)
@@ -22,6 +22,7 @@ use Friendica\Core\System;
 use Friendica\Core\Worker;
 use Friendica\Database\DBA;
 use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
 use Friendica\Model\Post\Category;
 use Friendica\Network\HTTPClient\Client\HttpClientAccept;
 use Friendica\Network\HTTPClient\Client\HttpClientOptions;
@@ -1119,6 +1120,8 @@ class Item
                        $item['private'] = self::PRIVATE;
                }
 
+               $eventDispatcher = DI::eventDispatcher();
+
                if ($notify && $post_local) {
                        $item['edit']   = false;
                        $item['parent'] = $parent_id;
@@ -1137,7 +1140,9 @@ class Item
                                $dummy_session = false;
                        }
 
-                       Hook::callAll('post_local', $item);
+                       $item = $eventDispatcher->dispatch(
+                               new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL, $item)
+                       )->getArray();
 
                        if ($dummy_session) {
                                unset($_SESSION['authenticated']);
@@ -1237,7 +1242,9 @@ class Item
                }
 
                if (empty($item['event-id'])) {
-                       unset($item['event-id']);
+                       if (array_key_exists('event-id', $item)) {
+                               unset($item['event-id']);
+                       }
 
                        $ev = Event::fromBBCode($item['body']);
                        if ((!empty($ev['desc']) || !empty($ev['summary'])) && !empty($ev['start'])) {
@@ -3010,9 +3017,6 @@ class Item
         * @return bool
         * @throws \Friendica\Network\HTTPException\InternalServerErrorException
         * @throws \ImagickException
-        * @hook  'post_local_end'
-        *            array $arr
-        *            'post_id' => ID of posted item
         */
        public static function performActivity(int $item_id, string $verb, int $uid, string $allow_cid = null, string $allow_gid = null, string $deny_cid = null, string $deny_gid = null): bool
        {
index b536ef848d9bb8e7929ba7346740d385eee78152..f1fa23a082113d349f257e474fafeac1b5526186 100644 (file)
@@ -13,6 +13,7 @@ use Friendica\Core\L10n;
 use Friendica\Core\Session\Capability\IHandleUserSessions;
 use Friendica\Core\System;
 use Friendica\Core\Worker;
+use Friendica\Event\ArrayFilterEvent;
 use Friendica\Model\Contact;
 use Friendica\Model\Item;
 use Friendica\Model\Post;
@@ -22,6 +23,7 @@ use Friendica\Protocol\Activity;
 use Friendica\Protocol\Delivery;
 use Friendica\Util\Profiler;
 use Friendica\Util\XML;
+use Psr\EventDispatcher\EventDispatcherInterface;
 use Psr\Log\LoggerInterface;
 
 /**
@@ -31,12 +33,14 @@ class Add extends \Friendica\BaseModule
 {
        /** @var IHandleUserSessions */
        private $session;
+       private EventDispatcherInterface $eventDispatcher;
 
-       public function __construct(IHandleUserSessions $session, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
+       public function __construct(IHandleUserSessions $session, EventDispatcherInterface $eventDispatcher, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
        {
                parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
 
-               $this->session = $session;
+               $this->session         = $session;
+               $this->eventDispatcher = $eventDispatcher;
        }
 
        protected function post(array $request = [])
@@ -149,7 +153,10 @@ EOT;
                Tag::store($item['uri-id'], Tag::HASHTAG, $term);
 
                $post['id'] = $post_id;
-               Hook::callAll('post_local_end', $post);
+
+               $post = $this->eventDispatcher->dispatch(
+                       new ArrayFilterEvent(ArrayFilterEvent::POST_LOCAL_END, $post)
+               )->getArray();
 
                $post = Post::selectFirst(['uri-id', 'uid'], ['id' => $post_id]);