mirror of
https://github.com/friendica/friendica
synced 2025-03-04 08:28:25 +00:00
Replace hooks post_local_start, post_local and post_local_end with EventDispatcher
This commit is contained in:
parent
649ddf7ab9
commit
aabf9a8b01
4 changed files with 48 additions and 22 deletions
13
mod/item.php
13
mod/item.php
|
@ -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']);
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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]);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue