diff --git a/doc/Addons.md b/doc/Addons.md
index 70b51c3066..7b7e97e701 100644
--- a/doc/Addons.md
+++ b/doc/Addons.md
@@ -661,7 +661,7 @@ Called when a custom storage is used (e.g. webdav_storage)
Hook data:
- **name** (input): the name of the used storage backend
-- **data['storage']** (output): the storage instance to use (**must** implement `\Friendica\Core\Storage\IWritableStorage`)
+- **data['storage']** (output): the storage instance to use (**must** implement `\Friendica\Core\Storage\IWritableStorage`)
### storage_config
@@ -876,7 +876,7 @@ Here is a complete list of all hook callbacks with file locations (as of 24-Sep-
### src/Content/ContactBlock.php
- Hook::callAll('contact_block_end', $arr);
+ Hook::callAll('contact_block_end', $text);
### src/Content/Text/BBCode.php
diff --git a/doc/de/Addons.md b/doc/de/Addons.md
index 607f2d50dc..bfc0107528 100644
--- a/doc/de/Addons.md
+++ b/doc/de/Addons.md
@@ -359,10 +359,10 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap
Hook::callAll('register_account', $uid);
Hook::callAll('remove_user', $user);
-
+
### src/Content/ContactBlock.php
- Hook::callAll('contact_block_end', $arr);
+ Hook::callAll('contact_block_end', $text);
### src/Content/Text/BBCode.php
diff --git a/mod/item.php b/mod/item.php
index de9a51915a..46f2a219e3 100644
--- a/mod/item.php
+++ b/mod/item.php
@@ -18,12 +18,12 @@
use Friendica\Content\Conversation;
use Friendica\Content\Text\BBCode;
-use Friendica\Core\Hook;
use Friendica\Core\Protocol;
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 +43,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 +279,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']);
diff --git a/mod/photos.php b/mod/photos.php
index 1294406761..82b5e43960 100644
--- a/mod/photos.php
+++ b/mod/photos.php
@@ -11,12 +11,12 @@ use Friendica\Content\Nav;
use Friendica\Content\Pager;
use Friendica\Content\Text\BBCode;
use Friendica\Core\ACL;
-use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\Database\DBStructure;
use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\Photo;
@@ -647,7 +647,11 @@ function photos_content()
'default_upload' => true
];
- Hook::callAll('photo_upload_form', $ret);
+ $eventDispatcher = DI::eventDispatcher();
+
+ $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::PHOTO_UPLOAD_FORM, $ret)
+ );
$default_upload_box = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_box.tpl'), []);
$default_upload_submit = Renderer::replaceMacros(Renderer::getMarkupTemplate('photos_default_uploader_submit.tpl'), [
diff --git a/src/App/Router.php b/src/App/Router.php
index c5abd56c5c..439b0a743b 100644
--- a/src/App/Router.php
+++ b/src/App/Router.php
@@ -19,6 +19,7 @@ use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Lock\Capability\ICanLock;
use Friendica\Core\Session\Capability\IHandleUserSessions;
+use Friendica\Event\CollectRoutesEvent;
use Friendica\LegacyModule;
use Friendica\Module\HTTPException\MethodNotAllowed;
use Friendica\Module\HTTPException\PageNotFound;
@@ -28,6 +29,7 @@ use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Network\HTTPException\MethodNotAllowedException;
use Friendica\Network\HTTPException\NotFoundException;
use Friendica\Util\Router\FriendicaGroupCountBased;
+use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -84,6 +86,8 @@ class Router
/** @var LoggerInterface */
private $logger;
+ private EventDispatcherInterface $eventDispatcher;
+
private AddonHelper $addonHelper;
/** @var bool */
@@ -110,7 +114,7 @@ class Router
* @param IHandleUserSessions $userSession
* @param RouteCollector|null $routeCollector
*/
- public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, IManageConfigValues $config, Arguments $args, LoggerInterface $logger, AddonHelper $addonHelper, IHandleUserSessions $userSession, RouteCollector $routeCollector = null)
+ public function __construct(array $server, string $baseRoutesFilepath, L10n $l10n, ICanCache $cache, ICanLock $lock, IManageConfigValues $config, Arguments $args, LoggerInterface $logger, EventDispatcherInterface $eventDispatcher, AddonHelper $addonHelper, IHandleUserSessions $userSession, RouteCollector $routeCollector = null)
{
$this->baseRoutesFilepath = $baseRoutesFilepath;
$this->l10n = $l10n;
@@ -120,6 +124,7 @@ class Router
$this->config = $config;
$this->server = $server;
$this->logger = $logger;
+ $this->eventDispatcher = $eventDispatcher;
$this->addonHelper = $addonHelper;
$this->isLocalUser = !empty($userSession->getLocalUserId());
@@ -148,10 +153,12 @@ class Router
$this->addRoutes($routeCollector, $routes);
- $this->routeCollector = $routeCollector;
-
// Add routes from addons
- Hook::callAll('route_collection', $this->routeCollector);
+ $routeCollector = $this->eventDispatcher->dispatch(
+ new CollectRoutesEvent(CollectRoutesEvent::COLLECT_ROUTES, $routeCollector),
+ )->getRouteCollector();
+
+ $this->routeCollector = $routeCollector;
return $this;
}
diff --git a/src/Content/ContactSelector.php b/src/Content/ContactSelector.php
index 1bd891a844..c864f159bb 100644
--- a/src/Content/ContactSelector.php
+++ b/src/Content/ContactSelector.php
@@ -7,10 +7,10 @@
namespace Friendica\Content;
-use Friendica\Core\Hook;
use Friendica\Core\Protocol;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
use Friendica\Util\Strings;
/**
@@ -24,8 +24,8 @@ class ContactSelector
const SVG_COLOR_WHITE = 2;
const SVG_WHITE = 3;
- static $serverdata = [];
- static $server_id = [];
+ public static $serverdata = [];
+ public static $server_id = [];
/**
* @param string $current current
@@ -35,7 +35,7 @@ class ContactSelector
public static function pollInterval(string $current, bool $disabled = false): string
{
$dis = (($disabled) ? ' disabled="disabled" ' : '');
- $o = '';
+ $o = '';
$o .= "" . "\r\n";
$rep = [
@@ -113,29 +113,33 @@ class ContactSelector
*/
public static function networkToName(string $network, string $protocol = '', int $gsid = null): string
{
+ $eventDispatcher = DI::eventDispatcher();
+
$nets = [
- Protocol::DFRN => DI::l10n()->t('DFRN'),
- Protocol::OSTATUS => DI::l10n()->t('OStatus'),
- Protocol::FEED => DI::l10n()->t('RSS/Atom'),
- Protocol::MAIL => DI::l10n()->t('Email'),
- Protocol::DIASPORA => DI::l10n()->t('Diaspora'),
- Protocol::ZOT => DI::l10n()->t('Zot!'),
- Protocol::LINKEDIN => DI::l10n()->t('LinkedIn'),
- Protocol::XMPP => DI::l10n()->t('XMPP/IM'),
- Protocol::MYSPACE => DI::l10n()->t('MySpace'),
- Protocol::GPLUS => DI::l10n()->t('Google+'),
- Protocol::PUMPIO => DI::l10n()->t('pump.io'),
- Protocol::TWITTER => DI::l10n()->t('Twitter'),
- Protocol::DISCOURSE => DI::l10n()->t('Discourse'),
- Protocol::DIASPORA2 => DI::l10n()->t('Diaspora Connector'),
- Protocol::STATUSNET => DI::l10n()->t('GNU Social Connector'),
+ Protocol::DFRN => DI::l10n()->t('DFRN'),
+ Protocol::OSTATUS => DI::l10n()->t('OStatus'),
+ Protocol::FEED => DI::l10n()->t('RSS/Atom'),
+ Protocol::MAIL => DI::l10n()->t('Email'),
+ Protocol::DIASPORA => DI::l10n()->t('Diaspora'),
+ Protocol::ZOT => DI::l10n()->t('Zot!'),
+ Protocol::LINKEDIN => DI::l10n()->t('LinkedIn'),
+ Protocol::XMPP => DI::l10n()->t('XMPP/IM'),
+ Protocol::MYSPACE => DI::l10n()->t('MySpace'),
+ Protocol::GPLUS => DI::l10n()->t('Google+'),
+ Protocol::PUMPIO => DI::l10n()->t('pump.io'),
+ Protocol::TWITTER => DI::l10n()->t('Twitter'),
+ Protocol::DISCOURSE => DI::l10n()->t('Discourse'),
+ Protocol::DIASPORA2 => DI::l10n()->t('Diaspora Connector'),
+ Protocol::STATUSNET => DI::l10n()->t('GNU Social Connector'),
Protocol::ACTIVITYPUB => DI::l10n()->t('ActivityPub'),
- Protocol::PNUT => DI::l10n()->t('pnut'),
- Protocol::TUMBLR => DI::l10n()->t('Tumblr'),
- Protocol::BLUESKY => DI::l10n()->t('Bluesky'),
+ Protocol::PNUT => DI::l10n()->t('pnut'),
+ Protocol::TUMBLR => DI::l10n()->t('Tumblr'),
+ Protocol::BLUESKY => DI::l10n()->t('Bluesky'),
];
- Hook::callAll('network_to_name', $nets);
+ $nets = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::NETWORK_TO_NAME, $nets),
+ )->getArray();
$search = array_keys($nets);
$replace = array_values($nets);
@@ -212,7 +216,7 @@ class ContactSelector
$network_svg = str_replace($search, $replace, $network);
if (in_array($network, Protocol::FEDERATED) && !empty($gsid)) {
- $gserver = self::getServerForId($gsid);
+ $gserver = self::getServerForId($gsid);
$platform = $gserver['platform'];
}
@@ -233,7 +237,7 @@ class ContactSelector
'takahē', 'takesama', 'threads', 'tumblr', 'vernissage', 'vervis', 'vidzy', 'vocata', 'wafrn',
'wildebeest', 'wordpress', 'write.as', 'writefreely', 'wxwclub', 'xwiki', 'zap'];
- if (in_array($platform_icon_style,[self::SVG_WHITE, self::SVG_COLOR_WHITE])) {
+ if (in_array($platform_icon_style, [self::SVG_WHITE, self::SVG_COLOR_WHITE])) {
$svg = ['activitypub', 'akkoma', 'andstatus', 'bluesky', 'bonfire', 'bookwyrm', 'bridgy_fed',
'calckey', 'castopod', 'diaspora', 'discourse', 'dolphin', 'drupal', 'email', 'firefish',
'flipboard', 'flohmarkt', 'forgejo', 'friendica', 'funkwhale', 'ghost', 'gitlab',
diff --git a/src/Content/Conversation.php b/src/Content/Conversation.php
index 3394b3c798..722aaf27b5 100644
--- a/src/Content/Conversation.php
+++ b/src/Content/Conversation.php
@@ -11,11 +11,9 @@ use Friendica\App\Arguments;
use Friendica\App\BaseURL;
use Friendica\App\Mode;
use Friendica\App\Page;
-use Friendica\AppHelper;
use Friendica\BaseModule;
use Friendica\Core\ACL;
use Friendica\Core\Config\Capability\IManageConfigValues;
-use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Protocol;
@@ -23,6 +21,8 @@ use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Core\Theme;
use Friendica\Database\DBA;
+use Friendica\Event\ArrayFilterEvent;
+use Friendica\Event\HtmlFilterEvent;
use Friendica\Model\Contact;
use Friendica\Model\Item as ItemModel;
use Friendica\Model\Post;
@@ -42,6 +42,7 @@ use Friendica\Util\Profiler;
use Friendica\Util\Strings;
use Friendica\Util\Temporal;
use ImagickException;
+use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
class Conversation
@@ -75,8 +76,6 @@ class Conversation
private $baseURL;
/** @var IManageConfigValues */
private $config;
- /** @var AppHelper */
- private $appHelper;
/** @var Page */
private $page;
/** @var Mode */
@@ -85,23 +84,24 @@ class Conversation
private $session;
/** @var UserGServerRepository */
private $userGServer;
+ private EventDispatcherInterface $eventDispatcher;
- public function __construct(UserGServerRepository $userGServer, LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, Page $page, Mode $mode, AppHelper $appHelper, IHandleUserSessions $session)
+ public function __construct(UserGServerRepository $userGServer, LoggerInterface $logger, Profiler $profiler, Activity $activity, L10n $l10n, Item $item, Arguments $args, BaseURL $baseURL, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, Page $page, Mode $mode, EventDispatcherInterface $eventDispatcher, IHandleUserSessions $session)
{
- $this->activity = $activity;
- $this->item = $item;
- $this->config = $config;
- $this->mode = $mode;
- $this->baseURL = $baseURL;
- $this->profiler = $profiler;
- $this->logger = $logger;
- $this->l10n = $l10n;
- $this->args = $args;
- $this->pConfig = $pConfig;
- $this->page = $page;
- $this->appHelper = $appHelper;
- $this->session = $session;
- $this->userGServer = $userGServer;
+ $this->activity = $activity;
+ $this->item = $item;
+ $this->config = $config;
+ $this->mode = $mode;
+ $this->baseURL = $baseURL;
+ $this->profiler = $profiler;
+ $this->logger = $logger;
+ $this->l10n = $l10n;
+ $this->args = $args;
+ $this->pConfig = $pConfig;
+ $this->page = $page;
+ $this->eventDispatcher = $eventDispatcher;
+ $this->session = $session;
+ $this->userGServer = $userGServer;
}
/**
@@ -332,8 +332,9 @@ class Conversation
'$is_mobile' => $this->mode->isMobile(),
]);
- $jotplugins = '';
- Hook::callAll('jot_tool', $jotplugins);
+ $jotplugins = $this->eventDispatcher->dispatch(
+ new HtmlFilterEvent(HtmlFilterEvent::JOT_TOOL, ''),
+ )->getHtml();
if ($this->config->get('system', 'set_creation_date')) {
$created_at = Temporal::getDateTimeField(
@@ -563,7 +564,10 @@ class Conversation
}
$cb = ['items' => $items, 'mode' => $mode, 'update' => $update, 'preview' => $preview];
- Hook::callAll('conversation_start', $cb);
+
+ $cb = $this->eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::CONVERSATION_START, $cb),
+ )->getArray();
$items = $cb['items'];
@@ -654,10 +658,6 @@ class Conversation
continue;
}
- /// @todo Check if this call is needed or not
- $arr = ['item' => $item];
- Hook::callAll('display_item', $arr);
-
$item['pagedrop'] = $pagedrop;
if ($item['gravity'] == ItemModel::GRAVITY_PARENT) {
@@ -1471,7 +1471,11 @@ class Conversation
}
$locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
- Hook::callAll('render_location', $locate);
+
+ $locate = $this->eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::RENDER_LOCATION, $locate),
+ )->getArray();
+
$location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
$this->item->localize($item);
@@ -1567,7 +1571,10 @@ class Conversation
];
$arr = ['item' => $item, 'output' => $tmp_item];
- Hook::callAll('display_item', $arr);
+
+ $arr = $this->eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::DISPLAY_ITEM, $arr),
+ )->getArray();
$threads[] = [
'id' => $item['id'],
diff --git a/src/Content/Item.php b/src/Content/Item.php
index aec01ae292..9c9cd10bed 100644
--- a/src/Content/Item.php
+++ b/src/Content/Item.php
@@ -12,7 +12,6 @@ use Friendica\AppHelper;
use Friendica\Content\Text\BBCode;
use Friendica\Content\Text\BBCode\Video;
use Friendica\Content\Text\HTML;
-use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Protocol;
@@ -20,6 +19,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 +43,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 +70,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;
}
/**
@@ -445,7 +448,9 @@ class Item
$args = ['item' => $item, 'menu' => $menu];
- Hook::callAll('item_photo_menu', $args);
+ $args = $this->eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::ITEM_PHOTO_MENU, $args),
+ )->getArray();
$menu = $args['menu'];
@@ -1006,7 +1011,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]);
diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php
index 599d3dc8f7..69a08526e1 100644
--- a/src/Content/OEmbed.php
+++ b/src/Content/OEmbed.php
@@ -13,11 +13,11 @@ use DOMXPath;
use Exception;
use Friendica\Content\Text\BBCode;
use Friendica\Core\Cache\Enum\Duration;
-use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
use Friendica\Network\HTTPClient\Client\HttpClientAccept;
use Friendica\Network\HTTPClient\Client\HttpClientOptions;
use Friendica\Network\HTTPClient\Client\HttpClientRequest;
@@ -53,7 +53,7 @@ class OEmbed
$cache_key = 'oembed:' . $appHelper->getThemeInfoValue('videowidth') . ':' . $embedurl;
- $condition = ['url' => Strings::normaliseLink($embedurl), 'maxwidth' => $appHelper->getThemeInfoValue('videowidth')];
+ $condition = ['url' => Strings::normaliseLink($embedurl), 'maxwidth' => $appHelper->getThemeInfoValue('videowidth')];
$oembed_record = DBA::selectFirst('oembed', ['content'], $condition);
if (DBA::isResult($oembed_record)) {
$json_string = $oembed_record['content'];
@@ -64,7 +64,7 @@ class OEmbed
// These media files should now be caught in bbcode.php
// left here as a fallback in case this is called from another source
$noexts = ['mp3', 'mp4', 'ogg', 'ogv', 'oga', 'ogm', 'webm'];
- $ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION);
+ $ext = pathinfo(strtolower($embedurl), PATHINFO_EXTENSION);
$oembed = new \Friendica\Object\OEmbed($embedurl);
@@ -81,15 +81,17 @@ class OEmbed
if (@$dom->loadHTML($html_text)) {
$xpath = new DOMXPath($dom);
foreach (
- $xpath->query("//link[@type='application/json+oembed'] | //link[@type='text/json+oembed']")
- as $link)
- {
+ $xpath->query("//link[@type='application/json+oembed'] | //link[@type='text/json+oembed']") as $link
+ ) {
/** @var DOMElement $link */
$href = $link->getAttributeNode('href')->nodeValue;
// Both Youtube and Vimeo output OEmbed endpoint URL with HTTP
// but their OEmbed endpoint is only accessible by HTTPS ¯\_(ツ)_/¯
- $href = str_replace(['http://www.youtube.com/', 'http://player.vimeo.com/'],
- ['https://www.youtube.com/', 'https://player.vimeo.com/'], $href);
+ $href = str_replace(
+ ['http://www.youtube.com/', 'http://player.vimeo.com/'],
+ ['https://www.youtube.com/', 'https://player.vimeo.com/'],
+ $href
+ );
$result = DI::httpClient()->get($href . '&maxwidth=' . $appHelper->getThemeInfoValue('videowidth'), HttpClientAccept::DEFAULT, [HttpClientOptions::REQUEST => HttpClientRequest::SITEINFO]);
if ($result->isSuccess()) {
$json_string = $result->getBodyString();
@@ -110,10 +112,10 @@ class OEmbed
if (!empty($oembed->type) && $oembed->type != 'error') {
DBA::insert('oembed', [
- 'url' => Strings::normaliseLink($embedurl),
+ 'url' => Strings::normaliseLink($embedurl),
'maxwidth' => $appHelper->getThemeInfoValue('videowidth'),
- 'content' => $json_string,
- 'created' => DateTimeFormat::utcNow()
+ 'content' => $json_string,
+ 'created' => DateTimeFormat::utcNow()
], Database::INSERT_UPDATE);
$cache_ttl = Duration::DAY;
} else {
@@ -141,8 +143,8 @@ class OEmbed
if ($oembed->type == 'photo') {
if (!empty($data['images'])) {
- $oembed->url = $data['images'][0]['src'];
- $oembed->width = $data['images'][0]['width'];
+ $oembed->url = $data['images'][0]['src'];
+ $oembed->width = $data['images'][0]['width'];
$oembed->height = $data['images'][0]['height'];
} else {
$oembed->type = 'link';
@@ -175,14 +177,20 @@ class OEmbed
}
if (!empty($data['images']) && ($oembed->type != 'photo')) {
- $oembed->thumbnail_url = $data['images'][0]['src'];
- $oembed->thumbnail_width = $data['images'][0]['width'];
+ $oembed->thumbnail_url = $data['images'][0]['src'];
+ $oembed->thumbnail_width = $data['images'][0]['width'];
$oembed->thumbnail_height = $data['images'][0]['height'];
}
- Hook::callAll('oembed_fetch_url', $embedurl);
+ $eventDispatcher = DI::eventDispatcher();
- return $oembed;
+ $oembed_data = ['url' => $embedurl];
+
+ $oembed_data = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::OEMBED_FETCH_END, $oembed_data),
+ )->getArray();
+
+ return $oembed_data['url'] ?? $embedurl;
}
/**
@@ -204,15 +212,15 @@ class OEmbed
// make sure we don't attempt divide by zero, fallback is a 1:1 ratio
$tr = (($th) ? $tw / $th : 1);
- $th = 120;
- $tw = $th * $tr;
+ $th = 120;
+ $tw = $th * $tr;
$tpl = Renderer::getMarkupTemplate('oembed_video.tpl');
$ret .= Renderer::replaceMacros($tpl, [
- '$embedurl' => $oembed->embed_url,
+ '$embedurl' => $oembed->embed_url,
'$escapedhtml' => base64_encode($oembed->html),
- '$tw' => $tw,
- '$th' => $th,
- '$turl' => BBCode::proxyUrl($oembed->thumbnail_url, BBCode::INTERNAL, $uriid, Proxy::SIZE_SMALL),
+ '$tw' => $tw,
+ '$th' => $th,
+ '$turl' => BBCode::proxyUrl($oembed->thumbnail_url, BBCode::INTERNAL, $uriid, Proxy::SIZE_SMALL),
]);
} else {
$ret .= Proxy::proxifyHtml($oembed->html, $uriid);
@@ -274,12 +282,11 @@ class OEmbed
}
}
} elseif (!strpos($oembed->html, $oembed->embed_url)) {
- // add for html2bbcode conversion
+ // add for html to bbcode conversion
$ret .= '' . $oembed->title . '';
}
$ret .= '';
-$test = Proxy::proxifyHtml($ret, $uriid);
return str_replace("\n", "", $ret);
}
diff --git a/src/Content/PageInfo.php b/src/Content/PageInfo.php
index 93d2e46750..4d2a1180d3 100644
--- a/src/Content/PageInfo.php
+++ b/src/Content/PageInfo.php
@@ -7,8 +7,8 @@
namespace Friendica\Content;
-use Friendica\Core\Hook;
use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
use Friendica\Network\HTTPException;
use Friendica\Util\ParseUrl;
use Friendica\Util\Strings;
@@ -90,7 +90,11 @@ class PageInfo
*/
public static function getFooterFromData(array $data, bool $no_photos = false): string
{
- Hook::callAll('page_info_data', $data);
+ $eventDispatcher = DI::eventDispatcher();
+
+ $data = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::PAGE_INFO, $data),
+ )->getArray();
if (empty($data['type'])) {
return '';
diff --git a/src/Content/Smilies.php b/src/Content/Smilies.php
index f6b69065d7..1a058f6375 100644
--- a/src/Content/Smilies.php
+++ b/src/Content/Smilies.php
@@ -8,8 +8,8 @@
namespace Friendica\Content;
use Friendica\Content\Text\BBCode;
-use Friendica\Core\Hook;
use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
use Friendica\Util\Strings;
/**
@@ -93,48 +93,53 @@ class Smilies
];
- $baseUrl = (string)DI::baseUrl();
+ $baseUrl = (string) DI::baseUrl();
$icons = [
- '',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '
',
- '~friendica
',
- 'red
matrix',
- 'red
matrix'
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '
',
+ '~friendica
',
+ 'red
matrix',
+ 'red
matrix'
];
+ $eventDispatcher = DI::eventDispatcher();
+
$params = ['texts' => $texts, 'icons' => $icons];
- Hook::callAll('smilie', $params);
+
+ $params = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::SMILEY_LIST, $params),
+ )->getArray();
return $params;
}
@@ -155,12 +160,12 @@ class Smilies
if (strpos($text, '[nosmile]') !== false || self::noSmilies()) {
return $text;
}
- $smilies = self::getList();
+ $smilies = self::getList();
$normalized = [];
return self::performForEachWordMatch(
array_combine($smilies['texts'], $smilies['icons']),
$text,
- function (string $name, string $image) use($normalized, &$emojis) {
+ function (string $name, string $image) use ($normalized, &$emojis) {
if (array_key_exists($name, $normalized)) {
return $normalized[$name];
}
@@ -176,9 +181,9 @@ class Smilies
$norm = 'smiley' . count($normalized);
}
}
- $shortcode = ':' . $norm . ':';
+ $shortcode = ':' . $norm . ':';
$normalized[$name] = $shortcode;
- $emojis[$norm] = $url;
+ $emojis[$norm] = $url;
return $shortcode;
} else {
$normalized[$name] = $image;
@@ -205,7 +210,7 @@ class Smilies
{
$ord1_bitset = 0;
$ord2_bitset = 0;
- $prefixes = [];
+ $prefixes = [];
foreach ($words as $word => $_) {
if (strlen($word) < 2) {
continue;
@@ -225,7 +230,7 @@ class Smilies
}
$slength = strlen($subject);
- $result = '';
+ $result = '';
// $processed is used to delay string concatenation since appending a char every loop is inefficient.
$processed = 0;
// Find possible starting points for smilies.
@@ -311,7 +316,8 @@ class Smilies
return $s;
}
- private static function noSmilies(): bool {
+ private static function noSmilies(): bool
+ {
return (intval(DI::config()->get('system', 'no_smilies')) ||
(DI::userSession()->getLocalUserId() &&
intval(DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'no_smilies'))));
@@ -339,7 +345,7 @@ class Smilies
if ($no_images) {
$cleaned = ['texts' => [], 'icons' => []];
- $icons = $smilies['icons'];
+ $icons = $smilies['icons'];
foreach ($icons as $key => $icon) {
if (!strstr($icon, '
startRecording('rendering');
- Hook::callAll('bbcode', $text);
+ $eventDispatcher = DI::eventDispatcher();
+
+ $text_data = ['bbcode2html' => $text];
+
+ $text_data = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::BBCODE_TO_HTML_START, $text_data),
+ )->getArray();
+
+ $text = $text_data['bbcode2html'] ?? $text;
$ev = Event::fromBBCode($text);
@@ -2375,9 +2383,18 @@ class BBCode
);
}
- Hook::callAll('bb2diaspora', $text);
+ $eventDispatcher = DI::eventDispatcher();
+
+ $text_data = ['bbcode2markdown' => $text];
+
+ $text_data = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::BBCODE_TO_MARKDOWN_END, $text_data),
+ )->getArray();
+
+ $text = $text_data['bbcode2markdown'] ?? $text;
DI::profiler()->stopRecording();
+
return $text;
}
diff --git a/src/Content/Text/HTML.php b/src/Content/Text/HTML.php
index ba992e4a8f..f5cf2c6eca 100644
--- a/src/Content/Text/HTML.php
+++ b/src/Content/Text/HTML.php
@@ -10,10 +10,10 @@ namespace Friendica\Content\Text;
use DOMDocument;
use DOMXPath;
use Friendica\Protocol\HTTP\MediaType;
-use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\Core\Search;
use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
use Friendica\Model\Contact;
use Friendica\Util\Strings;
use Friendica\Util\XML;
@@ -51,7 +51,7 @@ class HTML
private static function tagToBBCodeSub(DOMDocument $doc, string $tag, array $attributes, string $startbb, string $endbb, bool $ignoreChildren = false): bool
{
$savestart = str_replace('$', '\x01', $startbb);
- $replace = false;
+ $replace = false;
$xpath = new DOMXPath($doc);
@@ -93,7 +93,7 @@ class HTML
if ($replace) {
$StartCode = $doc->createTextNode($startbb);
- $EndCode = $doc->createTextNode($endbb);
+ $EndCode = $doc->createTextNode($endbb);
$node->parentNode->insertBefore($StartCode, $node);
@@ -141,7 +141,9 @@ class HTML
DI::profiler()->startRecording('rendering');
$message = str_replace("\r", "", $message);
- $message = Strings::performWithEscapedBlocks($message, '#
#iUs', function ($message) { + $eventDispatcher = DI::eventDispatcher(); + + $message = Strings::performWithEscapedBlocks($message, '#
#iUs', function ($message) use ($eventDispatcher) { $message = str_replace( [ "
",
@@ -158,7 +160,7 @@ class HTML
$message = preg_replace('=<(\w+):(.+?)>=', ']*) src=\"(?!http|https)([^\"]*)\"/";
$replace = "
DI::l10n()->t('Loading more entries...'),
- 'end' => DI::l10n()->t('The end')
+ 'end' => DI::l10n()->t('The end')
]);
}
@@ -799,9 +807,9 @@ class HTML
$contact["addr"] = $contact["url"];
}
- $url = $contact['url'];
+ $url = $contact['url'];
$sparkle = '';
- $redir = false;
+ $redir = false;
if ($redirect) {
$url = Contact::magicLinkByContact($contact);
@@ -816,14 +824,14 @@ class HTML
}
return Renderer::replaceMacros(Renderer::getMarkupTemplate($textmode ? 'micropro_txt.tpl' : 'micropro_img.tpl'), [
- '$click' => $contact['click'] ?? '',
- '$class' => $class,
- '$url' => $url,
- '$photo' => Contact::getThumb($contact),
- '$name' => $contact['name'],
- 'title' => $contact['name'] . ' [' . $contact['addr'] . ']',
+ '$click' => $contact['click'] ?? '',
+ '$class' => $class,
+ '$url' => $url,
+ '$photo' => Contact::getThumb($contact),
+ '$name' => $contact['name'],
+ 'title' => $contact['name'] . ' [' . $contact['addr'] . ']',
'$parkle' => $sparkle,
- '$redir' => $redir
+ '$redir' => $redir
]);
}
@@ -885,7 +893,7 @@ class HTML
public static function applyContentFilter(string $html, array $reasons): string
{
if (count($reasons)) {
- $tpl = Renderer::getMarkupTemplate('wall/content_filter.tpl');
+ $tpl = Renderer::getMarkupTemplate('wall/content_filter.tpl');
$html = Renderer::replaceMacros($tpl, [
'$reasons' => $reasons,
'$rnd' => Strings::getRandomHex(8),
@@ -943,8 +951,8 @@ class HTML
$config->set('Attr.AllowedRel', [
'noreferrer' => true,
- 'noopener' => true,
- 'tag' => true,
+ 'noopener' => true,
+ 'tag' => true,
]);
$config->set('Attr.AllowedFrameTargets', [
'_blank' => true,
@@ -1038,7 +1046,7 @@ class HTML
// This expression looks for a meta tag with the http-equiv attribute set to "content-type" ignoring case
// whose content attribute contains a "charset" string and returns its value
$expression = "string(//meta[@http-equiv][translate(@http-equiv, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz') = 'content-type'][contains(translate(@content, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'), 'charset')]/@content)";
- $mediaType = MediaType::fromContentType($xpath->evaluate($expression));
+ $mediaType = MediaType::fromContentType($xpath->evaluate($expression));
if (isset($mediaType->parameters['charset'])) {
return strtolower($mediaType->parameters['charset']);
}
diff --git a/src/Content/Widget/ContactBlock.php b/src/Content/Widget/ContactBlock.php
index b1d80653d4..aa11a258b2 100644
--- a/src/Content/Widget/ContactBlock.php
+++ b/src/Content/Widget/ContactBlock.php
@@ -8,11 +8,11 @@
namespace Friendica\Content\Widget;
use Friendica\Content\Text\HTML;
-use Friendica\Core\Hook;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Event\HtmlFilterEvent;
use Friendica\Model\Contact;
use Friendica\Model\User;
@@ -26,7 +26,6 @@ class ContactBlock
/**
* Get HTML for contact block
*
- * @hook contact_block_end (contacts=>array, output=>string)
* @return string Formatted HTML code or empty string
*/
public static function getHTML(array $profile, int $visitor_uid = null): string
@@ -93,7 +92,7 @@ class ContactBlock
if (DBA::isResult($contacts_stmt)) {
$contacts_title = DI::l10n()->tt('%d Contact', '%d Contacts', $total);
- $micropro = [];
+ $micropro = [];
while ($contact = DBA::fetch($contacts_stmt)) {
$contacts[] = $contact;
@@ -106,16 +105,18 @@ class ContactBlock
}
$tpl = Renderer::getMarkupTemplate('widget/contacts.tpl');
- $o = Renderer::replaceMacros($tpl, [
- '$contacts' => $contacts_title,
- '$nickname' => $profile['nickname'],
+ $o = Renderer::replaceMacros($tpl, [
+ '$contacts' => $contacts_title,
+ '$nickname' => $profile['nickname'],
'$viewcontacts' => DI::l10n()->t('View Contacts'),
- '$micropro' => $micropro,
+ '$micropro' => $micropro,
]);
- $arr = ['contacts' => $contacts, 'output' => $o];
+ $eventDispatcher = DI::eventDispatcher();
- Hook::callAll('contact_block_end', $arr);
+ $o = $eventDispatcher->dispatch(
+ new HtmlFilterEvent(HtmlFilterEvent::CONTACT_BLOCK_END, $o),
+ )->getHtml();
return $o;
}
diff --git a/src/Core/ACL.php b/src/Core/ACL.php
index e0ff7e9e6a..b383591d30 100644
--- a/src/Core/ACL.php
+++ b/src/Core/ACL.php
@@ -11,6 +11,7 @@ use Exception;
use Friendica\App\Page;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
use Friendica\Model\Contact;
use Friendica\Model\Circle;
use Friendica\Model\User;
@@ -52,7 +53,7 @@ class ACL
$contacts = self::getValidMessageRecipientsForUser(DI::userSession()->getLocalUserId());
$tpl = Renderer::getMarkupTemplate('acl/message_recipient.tpl');
- $o = Renderer::replaceMacros($tpl, [
+ $o = Renderer::replaceMacros($tpl, [
'$contacts' => $contacts,
'$contacts_json' => json_encode($contacts),
'$selected' => $selected,
@@ -95,9 +96,9 @@ class ACL
$selfPublicContactId = Contact::getPublicIdByUserId($localUserId);
$tpl = Renderer::getMarkupTemplate('acl/self_only.tpl');
- $o = Renderer::replaceMacros($tpl, [
+ $o = Renderer::replaceMacros($tpl, [
'$selfPublicContactId' => $selfPublicContactId,
- '$explanation' => $explanation,
+ '$explanation' => $explanation,
]);
return $o;
@@ -117,8 +118,8 @@ class ACL
return [
'allow_cid' => Contact::pruneUnavailable($aclFormatter->expand($user['allow_cid'] ?? '')),
'allow_gid' => $aclFormatter->expand($user['allow_gid'] ?? ''),
- 'deny_cid' => $aclFormatter->expand($user['deny_cid'] ?? ''),
- 'deny_gid' => $aclFormatter->expand($user['deny_gid'] ?? ''),
+ 'deny_cid' => $aclFormatter->expand($user['deny_cid'] ?? ''),
+ 'deny_gid' => $aclFormatter->expand($user['deny_gid'] ?? ''),
];
}
@@ -132,31 +133,33 @@ class ACL
*/
public static function getContactListByUserId(int $user_id, array $condition = [])
{
- $fields = ['id', 'name', 'addr', 'micro'];
- $params = ['order' => ['name']];
+ $fields = ['id', 'name', 'addr', 'micro'];
+ $params = ['order' => ['name']];
$acl_contacts = Contact::selectToArray(
$fields,
array_merge([
- 'uid' => $user_id,
- 'self' => false,
+ 'uid' => $user_id,
+ 'self' => false,
'blocked' => false,
'archive' => false,
'deleted' => false,
'pending' => false,
'network' => Protocol::FEDERATED,
- 'rel' => [Contact::FOLLOWER, Contact::FRIEND]
+ 'rel' => [Contact::FOLLOWER, Contact::FRIEND]
], $condition),
$params
);
- $acl_yourself = Contact::selectFirst($fields, ['uid' => $user_id, 'self' => true]);
+ $acl_yourself = Contact::selectFirst($fields, ['uid' => $user_id, 'self' => true]);
$acl_yourself['name'] = DI::l10n()->t('Yourself');
$acl_contacts[] = $acl_yourself;
- $acl_groups = Contact::selectToArray($fields,
- ['uid' => $user_id, 'self' => false, 'blocked' => false, 'archive' => false, 'deleted' => false,
- 'network' => Protocol::FEDERATED, 'pending' => false, 'contact-type' => Contact::TYPE_COMMUNITY], $params
+ $acl_groups = Contact::selectToArray(
+ $fields,
+ ['uid' => $user_id, 'self' => false, 'blocked' => false, 'archive' => false, 'deleted' => false,
+ 'network' => Protocol::FEDERATED, 'pending' => false, 'contact-type' => Contact::TYPE_COMMUNITY],
+ $params
);
$acl_contacts = array_merge($acl_groups, $acl_contacts);
@@ -178,27 +181,27 @@ class ACL
{
$acl_circles = [
[
- 'id' => Circle::FOLLOWERS,
- 'name' => DI::l10n()->t('Followers'),
- 'addr' => '',
+ 'id' => Circle::FOLLOWERS,
+ 'name' => DI::l10n()->t('Followers'),
+ 'addr' => '',
'micro' => 'images/twopeople.png',
- 'type' => 'circle',
+ 'type' => 'circle',
],
[
- 'id' => Circle::MUTUALS,
- 'name' => DI::l10n()->t('Mutuals'),
- 'addr' => '',
+ 'id' => Circle::MUTUALS,
+ 'name' => DI::l10n()->t('Mutuals'),
+ 'addr' => '',
'micro' => 'images/twopeople.png',
- 'type' => 'circle',
+ 'type' => 'circle',
]
];
foreach (Circle::getByUserId($user_id) as $circle) {
$acl_circles[] = [
- 'id' => $circle['id'],
- 'name' => $circle['name'],
- 'addr' => '',
+ 'id' => $circle['id'],
+ 'name' => $circle['name'],
+ 'addr' => '',
'micro' => 'images/twopeople.png',
- 'type' => 'circle',
+ 'type' => 'circle',
];
}
@@ -275,7 +278,7 @@ class ACL
$mailacct = DBA::selectFirst('mailacct', ['pubmail'], ['`uid` = ? AND `server` != ""', $user['uid']]);
if (DBA::isResult($mailacct)) {
$jotnets_fields[] = [
- 'type' => 'checkbox',
+ 'type' => 'checkbox',
'field' => [
'pubmail_enable',
DI::l10n()->t('Post to Email'),
@@ -285,7 +288,12 @@ class ACL
}
}
- Hook::callAll('jot_networks', $jotnets_fields);
+
+ $eventDispatcher = DI::eventDispatcher();
+
+ $jotnets_fields = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::JOT_NETWORKS, $jotnets_fields),
+ )->getArray();
}
$acl_contacts = self::getContactListByUserId($user['uid'], $condition);
@@ -304,28 +312,28 @@ class ACL
];
$tpl = Renderer::getMarkupTemplate('acl/full_selector.tpl');
- $o = Renderer::replaceMacros($tpl, [
- '$public_title' => DI::l10n()->t('Public'),
- '$public_desc' => DI::l10n()->t('This content will be shown to all your followers and can be seen in the community pages and by anyone with its link.'),
- '$custom_title' => DI::l10n()->t('Limited/Private'),
- '$custom_desc' => DI::l10n()->t('This content will be shown only to the people in the first box, to the exception of the people mentioned in the second box. It won\'t appear anywhere public.') . DI::l10n()->t('Start typing the name of a contact or a circle to show a filtered list. You can also mention the special circles "Followers" and "Mutuals".'),
- '$allow_label' => DI::l10n()->t('Show to:'),
- '$deny_label' => DI::l10n()->t('Except to:'),
- '$emailcc' => DI::l10n()->t('CC: email addresses'),
- '$emtitle' => DI::l10n()->t('Example: bob@example.com, mary@example.com'),
+ $o = Renderer::replaceMacros($tpl, [
+ '$public_title' => DI::l10n()->t('Public'),
+ '$public_desc' => DI::l10n()->t('This content will be shown to all your followers and can be seen in the community pages and by anyone with its link.'),
+ '$custom_title' => DI::l10n()->t('Limited/Private'),
+ '$custom_desc' => DI::l10n()->t('This content will be shown only to the people in the first box, to the exception of the people mentioned in the second box. It won\'t appear anywhere public.') . DI::l10n()->t('Start typing the name of a contact or a circle to show a filtered list. You can also mention the special circles "Followers" and "Mutuals".'),
+ '$allow_label' => DI::l10n()->t('Show to:'),
+ '$deny_label' => DI::l10n()->t('Except to:'),
+ '$emailcc' => DI::l10n()->t('CC: email addresses'),
+ '$emtitle' => DI::l10n()->t('Example: bob@example.com, mary@example.com'),
'$jotnets_summary' => DI::l10n()->t('Connectors'),
- '$visibility' => $visibility,
- '$acl_contacts' => json_encode($acl_contacts),
- '$acl_circles' => json_encode($acl_circles),
- '$acl_list' => json_encode($acl_list),
- '$contact_allow' => implode(',', $default_permissions['allow_cid']),
- '$circle_allow' => implode(',', $default_permissions['allow_gid']),
- '$contact_deny' => implode(',', $default_permissions['deny_cid']),
- '$circle_deny' => implode(',', $default_permissions['deny_gid']),
- '$for_federation' => $for_federation,
- '$jotnets_fields' => $jotnets_fields,
- '$input_names' => $input_names,
- '$input_group_id' => $input_group_id,
+ '$visibility' => $visibility,
+ '$acl_contacts' => json_encode($acl_contacts),
+ '$acl_circles' => json_encode($acl_circles),
+ '$acl_list' => json_encode($acl_list),
+ '$contact_allow' => implode(',', $default_permissions['allow_cid']),
+ '$circle_allow' => implode(',', $default_permissions['allow_gid']),
+ '$contact_deny' => implode(',', $default_permissions['deny_cid']),
+ '$circle_deny' => implode(',', $default_permissions['deny_gid']),
+ '$for_federation' => $for_federation,
+ '$jotnets_fields' => $jotnets_fields,
+ '$input_names' => $input_names,
+ '$input_group_id' => $input_group_id,
]);
return $o;
diff --git a/src/Core/Hooks/HookEventBridge.php b/src/Core/Hooks/HookEventBridge.php
index 2dad2d2b23..2f1e51a297 100644
--- a/src/Core/Hooks/HookEventBridge.php
+++ b/src/Core/Hooks/HookEventBridge.php
@@ -11,6 +11,7 @@ namespace Friendica\Core\Hooks;
use Friendica\Core\Hook;
use Friendica\Event\ArrayFilterEvent;
+use Friendica\Event\CollectRoutesEvent;
use Friendica\Event\ConfigLoadedEvent;
use Friendica\Event\Event;
use Friendica\Event\HtmlFilterEvent;
@@ -34,17 +35,40 @@ final class HookEventBridge
* This maps the new event names to the legacy Hook names.
*/
private static array $eventMapper = [
- Event::INIT => 'init_1',
- ConfigLoadedEvent::CONFIG_LOADED => 'load_config',
- ArrayFilterEvent::APP_MENU => 'app_menu',
- ArrayFilterEvent::NAV_INFO => 'nav_info',
- ArrayFilterEvent::FEATURE_ENABLED => 'isEnabled',
- ArrayFilterEvent::FEATURE_GET => 'get',
- HtmlFilterEvent::HEAD => 'head',
- HtmlFilterEvent::FOOTER => 'footer',
- HtmlFilterEvent::PAGE_HEADER => 'page_header',
- HtmlFilterEvent::PAGE_CONTENT_TOP => 'page_content_top',
- HtmlFilterEvent::PAGE_END => 'page_end',
+ Event::INIT => 'init_1',
+ Event::HOME_INIT => 'home_init',
+ ConfigLoadedEvent::CONFIG_LOADED => 'load_config',
+ CollectRoutesEvent::COLLECT_ROUTES => 'route_collection',
+ ArrayFilterEvent::APP_MENU => 'app_menu',
+ ArrayFilterEvent::NAV_INFO => 'nav_info',
+ ArrayFilterEvent::FEATURE_ENABLED => 'isEnabled',
+ ArrayFilterEvent::FEATURE_GET => 'get',
+ ArrayFilterEvent::POST_LOCAL_START => 'post_local_start',
+ ArrayFilterEvent::POST_LOCAL => 'post_local',
+ ArrayFilterEvent::POST_LOCAL_END => 'post_local_end',
+ ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'photo_upload_form',
+ ArrayFilterEvent::NETWORK_TO_NAME => 'network_to_name',
+ ArrayFilterEvent::CONVERSATION_START => 'conversation_start',
+ ArrayFilterEvent::DISPLAY_ITEM => 'display_item',
+ ArrayFilterEvent::RENDER_LOCATION => 'render_location',
+ ArrayFilterEvent::ITEM_PHOTO_MENU => 'item_photo_menu',
+ ArrayFilterEvent::OEMBED_FETCH_END => 'oembed_fetch_url',
+ ArrayFilterEvent::PAGE_INFO => 'page_info_data',
+ ArrayFilterEvent::SMILEY_LIST => 'smilie',
+ ArrayFilterEvent::BBCODE_TO_HTML_START => 'bbcode',
+ ArrayFilterEvent::HTML_TO_BBCODE_END => 'html2bbcode',
+ ArrayFilterEvent::BBCODE_TO_MARKDOWN_END => 'bb2diaspora',
+ ArrayFilterEvent::JOT_NETWORKS => 'jot_networks',
+ ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'support_follow',
+ ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'support_revoke_follow',
+ ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE => 'support_probe',
+ HtmlFilterEvent::HEAD => 'head',
+ HtmlFilterEvent::FOOTER => 'footer',
+ HtmlFilterEvent::PAGE_HEADER => 'page_header',
+ HtmlFilterEvent::PAGE_CONTENT_TOP => 'page_content_top',
+ HtmlFilterEvent::PAGE_END => 'page_end',
+ HtmlFilterEvent::JOT_TOOL => 'jot_tool',
+ HtmlFilterEvent::CONTACT_BLOCK_END => 'contact_block_end',
];
/**
@@ -53,17 +77,40 @@ final class HookEventBridge
public static function getStaticSubscribedEvents(): array
{
return [
- Event::INIT => 'onNamedEvent',
- ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
- ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
- ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
- ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
- ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
- HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
- HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
- HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
- HtmlFilterEvent::PAGE_CONTENT_TOP => 'onHtmlFilterEvent',
- HtmlFilterEvent::PAGE_END => 'onHtmlFilterEvent',
+ Event::INIT => 'onNamedEvent',
+ Event::HOME_INIT => 'onNamedEvent',
+ ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
+ CollectRoutesEvent::COLLECT_ROUTES => 'onCollectRoutesEvent',
+ ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
+ ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
+ ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
+ ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
+ ArrayFilterEvent::POST_LOCAL_START => 'onArrayFilterEvent',
+ ArrayFilterEvent::POST_LOCAL => 'onArrayFilterEvent',
+ ArrayFilterEvent::POST_LOCAL_END => 'onArrayFilterEvent',
+ ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'onArrayFilterEvent',
+ ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent',
+ ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent',
+ ArrayFilterEvent::DISPLAY_ITEM => 'onArrayFilterEvent',
+ ArrayFilterEvent::RENDER_LOCATION => 'onArrayFilterEvent',
+ ArrayFilterEvent::ITEM_PHOTO_MENU => 'onArrayFilterEvent',
+ ArrayFilterEvent::OEMBED_FETCH_END => 'onOembedFetchEndEvent',
+ ArrayFilterEvent::PAGE_INFO => 'onArrayFilterEvent',
+ ArrayFilterEvent::SMILEY_LIST => 'onArrayFilterEvent',
+ ArrayFilterEvent::BBCODE_TO_HTML_START => 'onBbcodeToHtmlEvent',
+ ArrayFilterEvent::HTML_TO_BBCODE_END => 'onHtmlToBbcodeEvent',
+ ArrayFilterEvent::BBCODE_TO_MARKDOWN_END => 'onBbcodeToMarkdownEvent',
+ ArrayFilterEvent::JOT_NETWORKS => 'onArrayFilterEvent',
+ ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'onArrayFilterEvent',
+ ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'onArrayFilterEvent',
+ ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE => 'onArrayFilterEvent',
+ HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
+ HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
+ HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
+ HtmlFilterEvent::PAGE_CONTENT_TOP => 'onHtmlFilterEvent',
+ HtmlFilterEvent::PAGE_END => 'onHtmlFilterEvent',
+ HtmlFilterEvent::JOT_TOOL => 'onHtmlFilterEvent',
+ HtmlFilterEvent::CONTACT_BLOCK_END => 'onHtmlFilterEvent',
];
}
@@ -77,6 +124,69 @@ final class HookEventBridge
static::callHook($event->getName(), $event->getConfig());
}
+ public static function onCollectRoutesEvent(CollectRoutesEvent $event): void
+ {
+ $event->setRouteCollector(
+ static::callHook($event->getName(), $event->getRouteCollector())
+ );
+ }
+
+ /**
+ * Map the OEMBED_FETCH_END event to `oembed_fetch_url` hook
+ */
+ public static function onOembedFetchEndEvent(ArrayFilterEvent $event): void
+ {
+ $data = $event->getArray();
+
+ $url = (string) $data['url'] ?? '';
+
+ $data['url'] = static::callHook($event->getName(), $url);
+
+ $event->setArray($data);
+ }
+
+ /**
+ * Map the BBCODE_TO_HTML_START event to `bbcode` hook
+ */
+ public static function onBbcodeToHtmlEvent(ArrayFilterEvent $event): void
+ {
+ $data = $event->getArray();
+
+ $bbcode2html = (string) $data['bbcode2html'] ?? '';
+
+ $data['bbcode2html'] = static::callHook($event->getName(), $bbcode2html);
+
+ $event->setArray($data);
+ }
+
+ /**
+ * Map the HTML_TO_BBCODE_END event to `html2bbcode` hook
+ */
+ public static function onHtmlToBbcodeEvent(ArrayFilterEvent $event): void
+ {
+ $data = $event->getArray();
+
+ $html2bbcode = (string) $data['html2bbcode'] ?? '';
+
+ $data['html2bbcode'] = static::callHook($event->getName(), $html2bbcode);
+
+ $event->setArray($data);
+ }
+
+ /**
+ * Map the BBCODE_TO_MARKDOWN_END event to `bb2diaspora` hook
+ */
+ public static function onBbcodeToMarkdownEvent(ArrayFilterEvent $event): void
+ {
+ $data = $event->getArray();
+
+ $bbcode2markdown = (string) $data['bbcode2markdown'] ?? '';
+
+ $data['bbcode2markdown'] = static::callHook($event->getName(), $bbcode2markdown);
+
+ $event->setArray($data);
+ }
+
public static function onArrayFilterEvent(ArrayFilterEvent $event): void
{
$event->setArray(
diff --git a/src/Core/Protocol.php b/src/Core/Protocol.php
index 53f69bc509..1e5b7e7f21 100644
--- a/src/Core/Protocol.php
+++ b/src/Core/Protocol.php
@@ -9,6 +9,7 @@ namespace Friendica\Core;
use Friendica\Database\DBA;
use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
use Friendica\Model\User;
use Friendica\Network\HTTPException;
use Friendica\Protocol\ActivityPub;
@@ -76,7 +77,12 @@ class Protocol
'protocol' => $protocol,
'result' => null
];
- Hook::callAll('support_follow', $hook_data);
+
+ $eventDispatcher = DI::eventDispatcher();
+
+ $hook_data = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, $hook_data),
+ )->getArray();
return $hook_data['result'] === true;
}
@@ -98,7 +104,12 @@ class Protocol
'protocol' => $protocol,
'result' => null
];
- Hook::callAll('support_revoke_follow', $hook_data);
+
+ $eventDispatcher = DI::eventDispatcher();
+
+ $hook_data = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, $hook_data),
+ )->getArray();
return $hook_data['result'] === true;
}
@@ -311,7 +322,12 @@ class Protocol
'protocol' => $protocol,
'result' => null
];
- Hook::callAll('support_probe', $hook_data);
+
+ $eventDispatcher = DI::eventDispatcher();
+
+ $hook_data = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, $hook_data),
+ )->getArray();
return $hook_data['result'] === true;
}
diff --git a/src/Event/ArrayFilterEvent.php b/src/Event/ArrayFilterEvent.php
index 839aa40b75..d21c6f8d78 100644
--- a/src/Event/ArrayFilterEvent.php
+++ b/src/Event/ArrayFilterEvent.php
@@ -24,6 +24,44 @@ final class ArrayFilterEvent extends Event
public const FEATURE_GET = 'friendica.data.feature_get';
+ public const POST_LOCAL_START = 'friendica.data.post_local_start';
+
+ public const POST_LOCAL = 'friendica.data.post_local';
+
+ public const POST_LOCAL_END = 'friendica.data.post_local_end';
+
+ public const PHOTO_UPLOAD_FORM = 'friendica.data.photo_upload_form';
+
+ public const NETWORK_TO_NAME = 'friendica.data.network_to_name';
+
+ public const CONVERSATION_START = 'friendica.data.conversation_start';
+
+ public const DISPLAY_ITEM = 'friendica.data.display_item';
+
+ public const RENDER_LOCATION = 'friendica.data.render_location';
+
+ public const ITEM_PHOTO_MENU = 'friendica.data.item_photo_menu';
+
+ public const OEMBED_FETCH_END = 'friendica.data.oembed_fetch_end';
+
+ public const PAGE_INFO = 'friendica.data.page_info';
+
+ public const SMILEY_LIST = 'friendica.data.smiley_list';
+
+ public const BBCODE_TO_HTML_START = 'friendica.data.bbcode_to_html_start';
+
+ public const HTML_TO_BBCODE_END = 'friendica.data.html_to_bbcode_end';
+
+ public const BBCODE_TO_MARKDOWN_END = 'friendica.data.bbcode_to_markdown_end';
+
+ public const JOT_NETWORKS = 'friendica.data.jot_networks';
+
+ public const PROTOCOL_SUPPORTS_FOLLOW = 'friendica.data.protocol_supports_follow';
+
+ public const PROTOCOL_SUPPORTS_REVOKE_FOLLOW = 'friendica.data.protocol_supports_revoke_follow';
+
+ public const PROTOCOL_SUPPORTS_PROBE = 'friendica.data.protocol_supports_probe';
+
private array $array;
public function __construct(string $name, array $array)
diff --git a/src/Event/CollectRoutesEvent.php b/src/Event/CollectRoutesEvent.php
new file mode 100644
index 0000000000..61e481ba9e
--- /dev/null
+++ b/src/Event/CollectRoutesEvent.php
@@ -0,0 +1,41 @@
+routeCollector = $routeCollector;
+ }
+
+ public function getRouteCollector(): RouteCollector
+ {
+ return $this->routeCollector;
+ }
+
+ public function setRouteCollector(RouteCollector $routeCollector): void
+ {
+ $this->routeCollector = $routeCollector;
+ }
+}
diff --git a/src/Event/Event.php b/src/Event/Event.php
index 90defc3204..7a6fca3840 100644
--- a/src/Event/Event.php
+++ b/src/Event/Event.php
@@ -21,6 +21,8 @@ class Event implements NamedEvent
*/
public const INIT = 'friendica.init';
+ public const HOME_INIT = 'friendica.home_init';
+
private string $name;
public function __construct(string $name)
diff --git a/src/Event/HtmlFilterEvent.php b/src/Event/HtmlFilterEvent.php
index 7d1bbb2b55..cb8a3992df 100644
--- a/src/Event/HtmlFilterEvent.php
+++ b/src/Event/HtmlFilterEvent.php
@@ -26,6 +26,10 @@ final class HtmlFilterEvent extends Event
public const PAGE_END = 'friendica.html.page_end';
+ public const JOT_TOOL = 'friendica.html.jot_tool';
+
+ public const CONTACT_BLOCK_END = 'friendica.html.contact_block_end';
+
private string $html;
public function __construct(string $name, string $html)
diff --git a/src/Model/Item.php b/src/Model/Item.php
index 53184bb1d7..31f8a8e22e 100644
--- a/src/Model/Item.php
+++ b/src/Model/Item.php
@@ -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;
@@ -825,6 +826,8 @@ class Item
$item['private'] = self::PRIVATE;
}
+ $eventDispatcher = DI::eventDispatcher();
+
if ($notify && $post_local) {
$item['edit'] = false;
$item['parent'] = $parent_id;
@@ -843,7 +846,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']);
@@ -943,7 +948,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'])) {
@@ -2694,9 +2701,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
{
diff --git a/src/Module/Home.php b/src/Module/Home.php
index 9c72398f7a..7e7d59d760 100644
--- a/src/Module/Home.php
+++ b/src/Module/Home.php
@@ -11,6 +11,7 @@ use Friendica\BaseModule;
use Friendica\Core\Hook;
use Friendica\Core\Renderer;
use Friendica\DI;
+use Friendica\Event\Event;
use Friendica\Model\User;
use Friendica\Module\Security\Login;
use Friendica\Protocol\ActivityPub;
@@ -32,13 +33,13 @@ class Home extends BaseModule
protected function content(array $request = []): string
{
- $basePath = DI::appHelper()->getBasePath();
- $config = DI::config();
+ $basePath = DI::appHelper()->getBasePath();
+ $config = DI::config();
+ $eventDispatcher = DI::eventDispatcher();
- // currently no returned data is used
- $ret = [];
-
- Hook::callAll('home_init', $ret);
+ $eventDispatcher->dispatch(
+ new Event(Event::HOME_INIT)
+ );
if (DI::userSession()->getLocalUserId() && (DI::userSession()->getLocalUserNickname())) {
DI::baseUrl()->redirect('network');
@@ -48,11 +49,11 @@ class Home extends BaseModule
DI::baseUrl()->redirect('/profile/' . $config->get('system', 'singleuser'));
}
- $customHome = '';
+ $customHome = '';
$defaultHeader = ($config->get('config', 'sitename') ? DI::l10n()->t('Welcome to %s', $config->get('config', 'sitename')) : '');
$homeFilePath = $basePath . '/home.html';
- $cssFilePath = $basePath . '/home.css';
+ $cssFilePath = $basePath . '/home.css';
if (file_exists($homeFilePath)) {
$customHome = $homeFilePath;
diff --git a/src/Module/Item/Compose.php b/src/Module/Item/Compose.php
index 727b8ba04f..af58c8ead7 100644
--- a/src/Module/Item/Compose.php
+++ b/src/Module/Item/Compose.php
@@ -16,13 +16,13 @@ use Friendica\BaseModule;
use Friendica\Content\Feature;
use Friendica\Core\ACL;
use Friendica\Core\Config\Capability\IManageConfigValues;
-use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Model\UserSession;
use Friendica\Core\Theme;
use Friendica\Database\DBA;
+use Friendica\Event\HtmlFilterEvent;
use Friendica\Model\Contact;
use Friendica\Model\Item;
use Friendica\Model\User;
@@ -34,6 +34,7 @@ use Friendica\Util\ACLFormatter;
use Friendica\Util\Crypto;
use Friendica\Util\Profiler;
use Friendica\Util\Temporal;
+use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
class Compose extends BaseModule
@@ -59,18 +60,20 @@ class Compose extends BaseModule
/** @var AppHelper */
private $appHelper;
+ private EventDispatcherInterface $eventDispatcher;
- public function __construct(AppHelper $appHelper, UserSession $session, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, Page $page, ACLFormatter $ACLFormatter, SystemMessages $systemMessages, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
+ public function __construct(EventDispatcherInterface $eventDispatcher, AppHelper $appHelper, UserSession $session, IManageConfigValues $config, IManagePersonalConfigValues $pConfig, Page $page, ACLFormatter $ACLFormatter, SystemMessages $systemMessages, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
- $this->systemMessages = $systemMessages;
- $this->ACLFormatter = $ACLFormatter;
- $this->page = $page;
- $this->pConfig = $pConfig;
- $this->config = $config;
- $this->session = $session;
- $this->appHelper = $appHelper;
+ $this->systemMessages = $systemMessages;
+ $this->ACLFormatter = $ACLFormatter;
+ $this->page = $page;
+ $this->pConfig = $pConfig;
+ $this->config = $config;
+ $this->session = $session;
+ $this->appHelper = $appHelper;
+ $this->eventDispatcher = $eventDispatcher;
}
protected function post(array $request = [])
@@ -115,29 +118,28 @@ class Compose extends BaseModule
switch ($posttype) {
case Item::PT_PERSONAL_NOTE:
- $compose_title = $this->l10n->t('Compose new personal note');
- $type = 'note';
- $doesFederate = false;
+ $compose_title = $this->l10n->t('Compose new personal note');
+ $type = 'note';
+ $doesFederate = false;
$contact_allow_list = [$this->appHelper->getContactId()];
- $circle_allow_list = [];
- $contact_deny_list = [];
- $circle_deny_list = [];
+ $circle_allow_list = [];
+ $contact_deny_list = [];
+ $circle_deny_list = [];
break;
default:
$compose_title = $this->l10n->t('Compose new post');
- $type = 'post';
- $doesFederate = true;
+ $type = 'post';
+ $doesFederate = true;
$contact_allow = $_REQUEST['contact_allow'] ?? '';
- $circle_allow = $_REQUEST['circle_allow'] ?? '';
- $contact_deny = $_REQUEST['contact_deny'] ?? '';
- $circle_deny = $_REQUEST['circle_deny'] ?? '';
+ $circle_allow = $_REQUEST['circle_allow'] ?? '';
+ $contact_deny = $_REQUEST['contact_deny'] ?? '';
+ $circle_deny = $_REQUEST['circle_deny'] ?? '';
if ($contact_allow
. $circle_allow
. $contact_deny
- . $circle_deny)
- {
+ . $circle_deny) {
$contact_allow_list = $contact_allow ? explode(',', $contact_allow) : [];
$circle_allow_list = $circle_allow ? explode(',', $circle_allow) : [];
$contact_deny_list = $contact_deny ? explode(',', $contact_deny) : [];
@@ -147,14 +149,15 @@ class Compose extends BaseModule
break;
}
- $title = $_REQUEST['title'] ?? '';
- $category = $_REQUEST['category'] ?? '';
- $body = $_REQUEST['body'] ?? '';
- $location = $_REQUEST['location'] ?? $user['default-location'];
- $wall = $_REQUEST['wall'] ?? $type == 'post';
+ $title = $_REQUEST['title'] ?? '';
+ $category = $_REQUEST['category'] ?? '';
+ $body = $_REQUEST['body'] ?? '';
+ $location = $_REQUEST['location'] ?? $user['default-location'];
+ $wall = $_REQUEST['wall'] ?? $type == 'post';
- $jotplugins = '';
- Hook::callAll('jot_tool', $jotplugins);
+ $jotplugins = $this->eventDispatcher->dispatch(
+ new HtmlFilterEvent(HtmlFilterEvent::JOT_TOOL, ''),
+ )->getHtml();
// Output
$this->page->registerFooterScript(Theme::getPathForFile('js/ajaxupload.js'));
@@ -202,8 +205,12 @@ class Compose extends BaseModule
'wait' => $this->l10n->t('Please wait'),
'placeholdertitle' => $this->l10n->t('Set title'),
'placeholdercategory' => Feature::isEnabled($this->session->getLocalUserId(), Feature::CATEGORIES) ? $this->l10n->t('Categories (comma-separated list)') : '',
- 'always_open_compose' => $this->pConfig->get($this->session->getLocalUserId(), 'frio', 'always_open_compose',
- $this->config->get('frio', 'always_open_compose', false)) ? '' :
+ 'always_open_compose' => $this->pConfig->get(
+ $this->session->getLocalUserId(),
+ 'frio',
+ 'always_open_compose',
+ $this->config->get('frio', 'always_open_compose', false)
+ ) ? '' :
$this->l10n->t('You can make this page always open when you use the New Post button in the Theme Customization settings.'),
],
@@ -220,11 +227,11 @@ class Compose extends BaseModule
$this->l10n->t('Scheduled at'),
'scheduled_at'
),
- '$created_at' => $created_at,
- '$title' => $title,
- '$category' => $category,
- '$body' => $body,
- '$location' => $location,
+ '$created_at' => $created_at,
+ '$title' => $title,
+ '$category' => $category,
+ '$body' => $body,
+ '$location' => $location,
'$contact_allow' => implode(',', $contact_allow_list),
'$circle_allow' => implode(',', $circle_allow_list),
@@ -233,7 +240,7 @@ class Compose extends BaseModule
'$jotplugins' => $jotplugins,
'$rand_num' => Crypto::randomDigits(12),
- '$acl_selector' => ACL::getFullSelectorHTML($this->page, $this->session->getLocalUserId(), $doesFederate, [
+ '$acl_selector' => ACL::getFullSelectorHTML($this->page, $this->session->getLocalUserId(), $doesFederate, [
'allow_cid' => $contact_allow_list,
'allow_gid' => $circle_allow_list,
'deny_cid' => $contact_deny_list,
diff --git a/src/Module/Post/Edit.php b/src/Module/Post/Edit.php
index c07ba9d78f..937ebcae5a 100644
--- a/src/Module/Post/Edit.php
+++ b/src/Module/Post/Edit.php
@@ -15,10 +15,10 @@ use Friendica\App\Page;
use Friendica\AppHelper;
use Friendica\BaseModule;
use Friendica\Content\Feature;
-use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions;
+use Friendica\Event\HtmlFilterEvent;
use Friendica\Model\Contact;
use Friendica\Model\Post;
use Friendica\Model\User;
@@ -27,6 +27,7 @@ use Friendica\Navigation\SystemMessages;
use Friendica\Network\HTTPException;
use Friendica\Util\Crypto;
use Friendica\Util\Profiler;
+use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -44,18 +45,22 @@ class Edit extends BaseModule
protected $mode;
/** @var AppHelper */
protected $appHelper;
+
+ private EventDispatcherInterface $eventDispatcher;
+
/** @var bool */
protected $isModal = false;
- public function __construct(L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, Page $page, Mode $mode, AppHelper $appHelper, array $server, array $parameters = [])
+ public function __construct(L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, Page $page, Mode $mode, AppHelper $appHelper, EventDispatcherInterface $eventDispatcher, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
- $this->session = $session;
- $this->sysMessages = $sysMessages;
- $this->page = $page;
- $this->mode = $mode;
- $this->appHelper = $appHelper;
+ $this->session = $session;
+ $this->sysMessages = $sysMessages;
+ $this->page = $page;
+ $this->mode = $mode;
+ $this->appHelper = $appHelper;
+ $this->eventDispatcher = $eventDispatcher;
}
@@ -107,11 +112,11 @@ class Edit extends BaseModule
}
$item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
- $item = Post\Media::addHTMLAttachmentToItem($item);
+ $item = Post\Media::addHTMLAttachmentToItem($item);
- $jotplugins = '';
-
- Hook::callAll('jot_tool', $jotplugins);
+ $jotplugins = $this->eventDispatcher->dispatch(
+ new HtmlFilterEvent(HtmlFilterEvent::JOT_TOOL, ''),
+ )->getHtml();
$output .= Renderer::replaceMacros(Renderer::getMarkupTemplate('jot.tpl'), [
'$is_edit' => true,
diff --git a/src/Module/Post/Tag/Add.php b/src/Module/Post/Tag/Add.php
index b536ef848d..bf704a50c0 100644
--- a/src/Module/Post/Tag/Add.php
+++ b/src/Module/Post/Tag/Add.php
@@ -8,11 +8,11 @@
namespace Friendica\Module\Post\Tag;
use Friendica\App;
-use Friendica\Core\Hook;
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 +22,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 +32,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 +152,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]);
diff --git a/src/Module/User/Delegation.php b/src/Module/User/Delegation.php
index 2c13891348..935ac83a6b 100644
--- a/src/Module/User/Delegation.php
+++ b/src/Module/User/Delegation.php
@@ -12,11 +12,11 @@ use Friendica\App\BaseURL;
use Friendica\AppHelper;
use Friendica\BaseModule;
use Friendica\Contact\Introduction\Repository\Introduction;
-use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Database\Database;
+use Friendica\Event\Event;
use Friendica\Model\Notification;
use Friendica\Model\User;
use Friendica\Module\Response;
@@ -25,6 +25,7 @@ use Friendica\Navigation\SystemMessages;
use Friendica\Network\HTTPException\ForbiddenException;
use Friendica\Security\Authentication;
use Friendica\Util;
+use Psr\EventDispatcher\EventDispatcherInterface;
use Psr\Log\LoggerInterface;
/**
@@ -46,18 +47,20 @@ class Delegation extends BaseModule
private $intro;
/** @var AppHelper */
private $appHelper;
+ private EventDispatcherInterface $eventDispatcher;
- public function __construct(AppHelper $appHelper, Introduction $intro, Notify $notify, SystemMessages $systemMessages, Authentication $auth, Database $db, IHandleUserSessions $session, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
+ public function __construct(EventDispatcherInterface $eventDispatcher, AppHelper $appHelper, Introduction $intro, Notify $notify, SystemMessages $systemMessages, Authentication $auth, Database $db, IHandleUserSessions $session, L10n $l10n, BaseURL $baseUrl, Arguments $args, LoggerInterface $logger, Util\Profiler $profiler, Response $response, array $server, array $parameters = [])
{
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
- $this->session = $session;
- $this->db = $db;
- $this->auth = $auth;
- $this->systemMessages = $systemMessages;
- $this->notify = $notify;
- $this->intro = $intro;
- $this->appHelper = $appHelper;
+ $this->session = $session;
+ $this->db = $db;
+ $this->auth = $auth;
+ $this->systemMessages = $systemMessages;
+ $this->notify = $notify;
+ $this->intro = $intro;
+ $this->appHelper = $appHelper;
+ $this->eventDispatcher = $eventDispatcher;
}
protected function post(array $request = [])
@@ -128,8 +131,9 @@ class Delegation extends BaseModule
$this->session->setSubManagedUserId($original_id);
}
- $ret = [];
- Hook::callAll('home_init', $ret);
+ $this->eventDispatcher->dispatch(
+ new Event(Event::HOME_INIT)
+ );
$this->systemMessages->addNotice($this->t('You are now logged in as %s', $user['username']));
diff --git a/src/Object/Post.php b/src/Object/Post.php
index b5ad33f56e..d4b381a115 100644
--- a/src/Object/Post.php
+++ b/src/Object/Post.php
@@ -10,10 +10,10 @@ namespace Friendica\Object;
use Friendica\Content\ContactSelector;
use Friendica\Content\Feature;
use Friendica\Core\Addon;
-use Friendica\Core\Hook;
use Friendica\Core\Protocol;
use Friendica\Core\Renderer;
use Friendica\DI;
+use Friendica\Event\ArrayFilterEvent;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\Item;
@@ -314,8 +314,14 @@ class Post
$sparkle = ' sparkle';
}
+ $eventDispatcher = DI::eventDispatcher();
+
$locate = ['location' => $item['location'], 'coord' => $item['coord'], 'html' => ''];
- Hook::callAll('render_location', $locate);
+
+ $locate = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::RENDER_LOCATION, $locate),
+ )->getArray();
+
$location_html = $locate['html'] ?: Strings::escapeHtml($locate['location'] ?: $locate['coord'] ?: '');
// process action responses - e.g. like/dislike/attend/agree/whatever
@@ -631,7 +637,10 @@ class Post
];
$arr = ['item' => $item, 'output' => $tmp_item];
- Hook::callAll('display_item', $arr);
+
+ $arr = $eventDispatcher->dispatch(
+ new ArrayFilterEvent(ArrayFilterEvent::DISPLAY_ITEM, $arr),
+ )->getArray();
$result = $arr['output'];
diff --git a/tests/Unit/Core/Hooks/HookEventBridgeTest.php b/tests/Unit/Core/Hooks/HookEventBridgeTest.php
index 671eb23e94..cdd3e0d61b 100644
--- a/tests/Unit/Core/Hooks/HookEventBridgeTest.php
+++ b/tests/Unit/Core/Hooks/HookEventBridgeTest.php
@@ -9,9 +9,11 @@ declare(strict_types=1);
namespace Friendica\Test\Unit\Core\Hooks;
+use FastRoute\RouteCollector;
use Friendica\Core\Config\Util\ConfigFileManager;
use Friendica\Core\Hooks\HookEventBridge;
use Friendica\Event\ArrayFilterEvent;
+use Friendica\Event\CollectRoutesEvent;
use Friendica\Event\ConfigLoadedEvent;
use Friendica\Event\Event;
use Friendica\Event\HtmlFilterEvent;
@@ -22,17 +24,40 @@ class HookEventBridgeTest extends TestCase
public function testGetStaticSubscribedEventsReturnsStaticMethods(): void
{
$expected = [
- Event::INIT => 'onNamedEvent',
- ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
- ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
- ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
- ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
- ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
- HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
- HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
- HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
- HtmlFilterEvent::PAGE_CONTENT_TOP => 'onHtmlFilterEvent',
- HtmlFilterEvent::PAGE_END => 'onHtmlFilterEvent',
+ Event::INIT => 'onNamedEvent',
+ Event::HOME_INIT => 'onNamedEvent',
+ ConfigLoadedEvent::CONFIG_LOADED => 'onConfigLoadedEvent',
+ CollectRoutesEvent::COLLECT_ROUTES => 'onCollectRoutesEvent',
+ ArrayFilterEvent::APP_MENU => 'onArrayFilterEvent',
+ ArrayFilterEvent::NAV_INFO => 'onArrayFilterEvent',
+ ArrayFilterEvent::FEATURE_ENABLED => 'onArrayFilterEvent',
+ ArrayFilterEvent::FEATURE_GET => 'onArrayFilterEvent',
+ ArrayFilterEvent::POST_LOCAL_START => 'onArrayFilterEvent',
+ ArrayFilterEvent::POST_LOCAL => 'onArrayFilterEvent',
+ ArrayFilterEvent::POST_LOCAL_END => 'onArrayFilterEvent',
+ ArrayFilterEvent::PHOTO_UPLOAD_FORM => 'onArrayFilterEvent',
+ ArrayFilterEvent::NETWORK_TO_NAME => 'onArrayFilterEvent',
+ ArrayFilterEvent::CONVERSATION_START => 'onArrayFilterEvent',
+ ArrayFilterEvent::DISPLAY_ITEM => 'onArrayFilterEvent',
+ ArrayFilterEvent::RENDER_LOCATION => 'onArrayFilterEvent',
+ ArrayFilterEvent::ITEM_PHOTO_MENU => 'onArrayFilterEvent',
+ ArrayFilterEvent::OEMBED_FETCH_END => 'onOembedFetchEndEvent',
+ ArrayFilterEvent::PAGE_INFO => 'onArrayFilterEvent',
+ ArrayFilterEvent::SMILEY_LIST => 'onArrayFilterEvent',
+ ArrayFilterEvent::BBCODE_TO_HTML_START => 'onBbcodeToHtmlEvent',
+ ArrayFilterEvent::HTML_TO_BBCODE_END => 'onHtmlToBbcodeEvent',
+ ArrayFilterEvent::BBCODE_TO_MARKDOWN_END => 'onBbcodeToMarkdownEvent',
+ ArrayFilterEvent::JOT_NETWORKS => 'onArrayFilterEvent',
+ ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW => 'onArrayFilterEvent',
+ ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW => 'onArrayFilterEvent',
+ ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE => 'onArrayFilterEvent',
+ HtmlFilterEvent::HEAD => 'onHtmlFilterEvent',
+ HtmlFilterEvent::FOOTER => 'onHtmlFilterEvent',
+ HtmlFilterEvent::PAGE_HEADER => 'onHtmlFilterEvent',
+ HtmlFilterEvent::PAGE_CONTENT_TOP => 'onHtmlFilterEvent',
+ HtmlFilterEvent::PAGE_END => 'onHtmlFilterEvent',
+ HtmlFilterEvent::JOT_TOOL => 'onHtmlFilterEvent',
+ HtmlFilterEvent::CONTACT_BLOCK_END => 'onHtmlFilterEvent',
];
$this->assertSame(
@@ -58,6 +83,7 @@ class HookEventBridgeTest extends TestCase
return [
['test', 'test'],
[Event::INIT, 'init_1'],
+ [Event::HOME_INIT, 'home_init'],
];
}
@@ -111,6 +137,124 @@ class HookEventBridgeTest extends TestCase
HookEventBridge::onConfigLoadedEvent($event);
}
+ public static function getCollectRoutesEventData(): array
+ {
+ return [
+ ['test', 'test'],
+ [CollectRoutesEvent::COLLECT_ROUTES, 'route_collection'],
+ ];
+ }
+
+ /**
+ * @dataProvider getCollectRoutesEventData
+ */
+ public function testOnCollectRoutesEventCallsHookWithCorrectValue($name, $expected): void
+ {
+ $routeCollector = $this->createStub(RouteCollector::class);
+
+ $event = new CollectRoutesEvent($name, $routeCollector);
+
+ $reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
+ $reflectionProperty->setAccessible(true);
+
+ $reflectionProperty->setValue(null, function (string $name, $data) use ($expected, $routeCollector) {
+ $this->assertSame($expected, $name);
+ $this->assertSame($routeCollector, $data);
+
+ return $data;
+ });
+
+ HookEventBridge::onCollectRoutesEvent($event);
+ }
+
+ public function testOnOembedFetchEndEventCallsHookWithCorrectValue(): void
+ {
+ $event = new ArrayFilterEvent(ArrayFilterEvent::OEMBED_FETCH_END, ['url' => 'original_url']);
+
+ $reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
+ $reflectionProperty->setAccessible(true);
+
+ $reflectionProperty->setValue(null, function (string $name, string $data): string {
+ $this->assertSame('oembed_fetch_url', $name);
+ $this->assertSame('original_url', $data);
+
+ return 'changed_url';
+ });
+
+ HookEventBridge::onOembedFetchEndEvent($event);
+
+ $this->assertSame(
+ ['url' => 'changed_url'],
+ $event->getArray(),
+ );
+ }
+
+ public function testOnBbcodeToHtmlEventCallsHookWithCorrectValue(): void
+ {
+ $event = new ArrayFilterEvent(ArrayFilterEvent::BBCODE_TO_HTML_START, ['bbcode2html' => '[b]original[/b]']);
+
+ $reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
+ $reflectionProperty->setAccessible(true);
+
+ $reflectionProperty->setValue(null, function (string $name, string $data): string {
+ $this->assertSame('bbcode', $name);
+ $this->assertSame('[b]original[/b]', $data);
+
+ return 'changed';
+ });
+
+ HookEventBridge::onBbcodeToHtmlEvent($event);
+
+ $this->assertSame(
+ ['bbcode2html' => 'changed'],
+ $event->getArray(),
+ );
+ }
+
+ public function testOnHtmlToBbcodeEventCallsHookWithCorrectValue(): void
+ {
+ $event = new ArrayFilterEvent(ArrayFilterEvent::HTML_TO_BBCODE_END, ['html2bbcode' => 'original']);
+
+ $reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
+ $reflectionProperty->setAccessible(true);
+
+ $reflectionProperty->setValue(null, function (string $name, string $data): string {
+ $this->assertSame('html2bbcode', $name);
+ $this->assertSame('original', $data);
+
+ return '[b]changed[/b]';
+ });
+
+ HookEventBridge::onHtmlToBbcodeEvent($event);
+
+ $this->assertSame(
+ ['html2bbcode' => '[b]changed[/b]'],
+ $event->getArray(),
+ );
+ }
+
+ public function testOnBbcodeToMarkdownEventCallsHookWithCorrectValue(): void
+ {
+ $event = new ArrayFilterEvent(ArrayFilterEvent::BBCODE_TO_MARKDOWN_END, ['bbcode2markdown' => '[b]original[/b]']);
+
+ $reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
+ $reflectionProperty->setAccessible(true);
+
+ $reflectionProperty->setValue(null, function (string $name, string $data): string {
+ $this->assertSame('bb2diaspora', $name);
+ $this->assertSame('[b]original[/b]', $data);
+
+ return '**changed**';
+ });
+
+ HookEventBridge::onBbcodeToMarkdownEvent($event);
+
+ $this->assertSame(
+ ['bbcode2markdown' => '**changed**'],
+ $event->getArray(),
+ );
+ }
+
public static function getArrayFilterEventData(): array
{
return [
@@ -119,6 +263,21 @@ class HookEventBridgeTest extends TestCase
[ArrayFilterEvent::NAV_INFO, 'nav_info'],
[ArrayFilterEvent::FEATURE_ENABLED, 'isEnabled'],
[ArrayFilterEvent::FEATURE_GET, 'get'],
+ [ArrayFilterEvent::POST_LOCAL_START, 'post_local_start'],
+ [ArrayFilterEvent::POST_LOCAL, 'post_local'],
+ [ArrayFilterEvent::POST_LOCAL_END, 'post_local_end'],
+ [ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'photo_upload_form'],
+ [ArrayFilterEvent::NETWORK_TO_NAME, 'network_to_name'],
+ [ArrayFilterEvent::CONVERSATION_START, 'conversation_start'],
+ [ArrayFilterEvent::DISPLAY_ITEM, 'display_item'],
+ [ArrayFilterEvent::RENDER_LOCATION, 'render_location'],
+ [ArrayFilterEvent::ITEM_PHOTO_MENU, 'item_photo_menu'],
+ [ArrayFilterEvent::PAGE_INFO, 'page_info_data'],
+ [ArrayFilterEvent::SMILEY_LIST, 'smilie'],
+ [ArrayFilterEvent::JOT_NETWORKS, 'jot_networks'],
+ [ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'support_follow'],
+ [ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'support_revoke_follow'],
+ [ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, 'support_probe'],
];
}
@@ -151,6 +310,8 @@ class HookEventBridgeTest extends TestCase
[HtmlFilterEvent::PAGE_HEADER, 'page_header'],
[HtmlFilterEvent::PAGE_CONTENT_TOP, 'page_content_top'],
[HtmlFilterEvent::PAGE_END, 'page_end'],
+ [HtmlFilterEvent::JOT_TOOL, 'jot_tool'],
+ [HtmlFilterEvent::CONTACT_BLOCK_END, 'contact_block_end'],
];
}
diff --git a/tests/Unit/Event/ArrayFilterEventTest.php b/tests/Unit/Event/ArrayFilterEventTest.php
index c709e0ff0a..2d396e6760 100644
--- a/tests/Unit/Event/ArrayFilterEventTest.php
+++ b/tests/Unit/Event/ArrayFilterEventTest.php
@@ -26,6 +26,27 @@ class ArrayFilterEventTest extends TestCase
{
return [
[ArrayFilterEvent::APP_MENU, 'friendica.data.app_menu'],
+ [ArrayFilterEvent::NAV_INFO, 'friendica.data.nav_info'],
+ [ArrayFilterEvent::FEATURE_ENABLED, 'friendica.data.feature_enabled'],
+ [ArrayFilterEvent::FEATURE_GET, 'friendica.data.feature_get'],
+ [ArrayFilterEvent::POST_LOCAL_START, 'friendica.data.post_local_start'],
+ [ArrayFilterEvent::POST_LOCAL, 'friendica.data.post_local'],
+ [ArrayFilterEvent::POST_LOCAL_END, 'friendica.data.post_local_end'],
+ [ArrayFilterEvent::PHOTO_UPLOAD_FORM, 'friendica.data.photo_upload_form'],
+ [ArrayFilterEvent::NETWORK_TO_NAME, 'friendica.data.network_to_name'],
+ [ArrayFilterEvent::CONVERSATION_START, 'friendica.data.conversation_start'],
+ [ArrayFilterEvent::DISPLAY_ITEM, 'friendica.data.display_item'],
+ [ArrayFilterEvent::RENDER_LOCATION, 'friendica.data.render_location'],
+ [ArrayFilterEvent::ITEM_PHOTO_MENU, 'friendica.data.item_photo_menu'],
+ [ArrayFilterEvent::OEMBED_FETCH_END, 'friendica.data.oembed_fetch_end'],
+ [ArrayFilterEvent::PAGE_INFO, 'friendica.data.page_info'],
+ [ArrayFilterEvent::SMILEY_LIST, 'friendica.data.smiley_list'],
+ [ArrayFilterEvent::BBCODE_TO_HTML_START, 'friendica.data.bbcode_to_html_start'],
+ [ArrayFilterEvent::BBCODE_TO_MARKDOWN_END, 'friendica.data.bbcode_to_markdown_end'],
+ [ArrayFilterEvent::JOT_NETWORKS, 'friendica.data.jot_networks'],
+ [ArrayFilterEvent::PROTOCOL_SUPPORTS_FOLLOW, 'friendica.data.protocol_supports_follow'],
+ [ArrayFilterEvent::PROTOCOL_SUPPORTS_REVOKE_FOLLOW, 'friendica.data.protocol_supports_revoke_follow'],
+ [ArrayFilterEvent::PROTOCOL_SUPPORTS_PROBE, 'friendica.data.protocol_supports_probe'],
];
}
diff --git a/tests/Unit/Event/CollectRoutesEventTest.php b/tests/Unit/Event/CollectRoutesEventTest.php
new file mode 100644
index 0000000000..0a1bb88d59
--- /dev/null
+++ b/tests/Unit/Event/CollectRoutesEventTest.php
@@ -0,0 +1,67 @@
+createStub(RouteCollector::class));
+
+ $this->assertInstanceOf(NamedEvent::class, $event);
+ }
+
+ public static function getPublicConstants(): array
+ {
+ return [
+ [CollectRoutesEvent::COLLECT_ROUTES, 'friendica.collect_routes'],
+ ];
+ }
+
+ /**
+ * @dataProvider getPublicConstants
+ */
+ public function testPublicConstantsAreAvailable($value, $expected): void
+ {
+ $this->assertSame($expected, $value);
+ }
+
+ public function testGetNameReturnsName(): void
+ {
+ $event = new CollectRoutesEvent('test', $this->createStub(RouteCollector::class));
+
+ $this->assertSame('test', $event->getName());
+ }
+
+ public function testGetRouteCollectorReturnsCorrectString(): void
+ {
+ $routeCollector = $this->createStub(RouteCollector::class);
+
+ $event = new CollectRoutesEvent('test', $routeCollector);
+
+ $this->assertSame($routeCollector, $event->getRouteCollector());
+ }
+
+ public function testSetRouteCollector(): void
+ {
+ $event = new CollectRoutesEvent('test', $this->createStub(RouteCollector::class));
+
+ $routeCollector = $this->createStub(RouteCollector::class);
+
+ $event->setRouteCollector($routeCollector);
+
+ $this->assertSame($routeCollector, $event->getRouteCollector());
+ }
+}
diff --git a/tests/src/Content/SmiliesTest.php b/tests/src/Content/SmiliesTest.php
index 441176fd73..69236efe2d 100644
--- a/tests/src/Content/SmiliesTest.php
+++ b/tests/src/Content/SmiliesTest.php
@@ -9,6 +9,7 @@ namespace Friendica\Test\src\Content;
use Friendica\Content\Smilies;
use Friendica\Core\Hook;
+use Friendica\Core\Hooks\HookEventBridge;
use Friendica\DI;
use Friendica\Network\HTTPException\InternalServerErrorException;
use Friendica\Test\FixtureTestCase;
@@ -21,22 +22,29 @@ class SmiliesTest extends FixtureTestCase
DI::config()->set('system', 'no_smilies', false);
+ /** @var \Friendica\Event\EventDispatcher */
+ $eventDispatcher = DI::eventDispatcher();
+
+ foreach (HookEventBridge::getStaticSubscribedEvents() as $eventName => $methodName) {
+ $eventDispatcher->addListener($eventName, [HookEventBridge::class, $methodName]);
+ }
+
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
Hook::loadHooks();
}
- public function dataLinks()
+ public function dataLinks(): array
{
return [
/** @see https://github.com/friendica/friendica/pull/6933 */
'bug-6933-1' => [
- 'data' => '
/
',
- 'smilies' => ['texts' => [], 'icons' => []],
+ 'data' => '/
',
+ 'smilies' => ['texts' => [], 'icons' => []],
'expected' => '/
',
],
'bug-6933-2' => [
- 'data' => 'code
',
- 'smilies' => ['texts' => [], 'icons' => []],
+ 'data' => 'code
',
+ 'smilies' => ['texts' => [], 'icons' => []],
'expected' => 'code
',
],
];
@@ -53,7 +61,7 @@ class SmiliesTest extends FixtureTestCase
*
* @throws InternalServerErrorException
*/
- public function testReplaceFromArray(string $text, array $smilies, string $expected)
+ public function testReplaceFromArray(string $text, array $smilies, string $expected): void
{
$output = Smilies::replaceFromArray($text, $smilies);
self::assertEquals($expected, $output);
@@ -64,141 +72,137 @@ class SmiliesTest extends FixtureTestCase
return [
'emoji' => [
'expected' => true,
- 'body' => '👀',
+ 'body' => '👀',
],
'emojis' => [
'expected' => true,
- 'body' => '👀🤷',
+ 'body' => '👀🤷',
],
'emoji+whitespace' => [
'expected' => true,
- 'body' => ' 👀 ',
+ 'body' => ' 👀 ',
],
'empty' => [
'expected' => false,
- 'body' => '',
+ 'body' => '',
],
'whitespace' => [
'expected' => false,
- 'body' => '
+ 'body' => '
',
],
'emoji+ASCII' => [
'expected' => false,
- 'body' => '🤷a',
+ 'body' => '🤷a',
],
'HTML entity whitespace' => [
'expected' => false,
- 'body' => ' ',
+ 'body' => ' ',
],
'HTML entity else' => [
'expected' => false,
- 'body' => '°',
+ 'body' => '°',
],
'emojis+HTML whitespace' => [
'expected' => true,
- 'body' => '👀 🤷',
+ 'body' => '👀 🤷',
],
'emojis+HTML else' => [
'expected' => false,
- 'body' => '👀<🤷',
+ 'body' => '👀<🤷',
],
'zwj' => [
'expected' => true,
- 'body' => '👨👨👧',
+ 'body' => '👨👨👧',
],
'zwj+whitespace' => [
'expected' => true,
- 'body' => ' 👨👨👧 ',
+ 'body' => ' 👨👨👧 ',
],
'zwj+HTML whitespace' => [
'expected' => true,
- 'body' => ' 👨👨👧 ',
+ 'body' => ' 👨👨👧 ',
],
];
}
/**
* @dataProvider dataIsEmojiPost
- *
- * @param bool $expected
- * @param string $body
- * @return void
*/
- public function testIsEmojiPost(bool $expected, string $body)
+ public function testIsEmojiPost(bool $expected, string $body): void
{
$this->assertEquals($expected, Smilies::isEmojiPost($body));
}
-
public function dataReplace(): array
{
$data = [
'simple-1' => [
'expected' => 'alt=":-p"',
- 'body' => ':-p',
+ 'body' => ':-p',
],
- 'simple-1' => [
+ 'simple-2' => [
'expected' => 'alt=":-p"',
- 'body' => ' :-p ',
+ 'body' => ' :-p ',
],
'word-boundary-1' => [
'expected' => ':-pppp',
- 'body' => ':-pppp',
+ 'body' => ':-pppp',
],
'word-boundary-2' => [
'expected' => '~friendicaca',
- 'body' => '~friendicaca',
+ 'body' => '~friendicaca',
],
'symbol-boundary-1' => [
'expected' => 'alt=":-p"',
- 'body' => '(:-p)',
+ 'body' => '(:-p)',
],
'hearts-1' => [
'expected' => '❤ (❤) ❤',
- 'body' => '<3 (<3) <3',
+ 'body' => '<3 (<3) <3',
],
'hearts-8' => [
'expected' => '(❤❤❤❤❤❤❤❤)',
- 'body' => '(<33333333)',
+ 'body' => '(<33333333)',
],
'no-hearts-1' => [
'expected' => '(<30)',
- 'body' => '(<30)',
+ 'body' => '(<30)',
],
'no-hearts-2' => [
'expected' => '(3<33)',
- 'body' => '(3<33)',
+ 'body' => '(3<33)',
],
'space' => [
'expected' => 'alt="smiley-heart"',
- 'body' => ':smiley heart 333:',
+ 'body' => ':smiley heart 333:',
],
'substitution-1' => [
'expected' => '🔥',
- 'body' => '⽕',
+ 'body' => '⽕',
],
'substitution-2' => [
'expected' => '🤗',
- 'body' => ':hugging face:',
+ 'body' => ':hugging face:',
],
'substitution-3' => [
'expected' => '🤭',
- 'body' => ':face with hand over mouth:',
+ 'body' => ':face with hand over mouth:',
],
'mixed' => [
'expected' => '🔥 🤭 invalid:hugging face: 🤗',
- 'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
+ 'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
],
];
+
foreach ([':-[', ':-D', 'o.O'] as $emoji) {
foreach (['A', '_', ':', '-'] as $prefix) {
foreach (['', ' ', 'A', ':', '-'] as $suffix) {
$no_smile = ($prefix !== '' && ctype_alnum($prefix)) || ($suffix !== '' && ctype_alnum($suffix));
- $s = $prefix . $emoji . $suffix;
- $data[] = [
+ $s = $prefix . $emoji . $suffix;
+ $data[] = [
'expected' => $no_smile ? $s : 'alt="' . $emoji . '"',
- 'body' => $s,
+ 'body' => $s,
];
}
}
@@ -208,11 +212,8 @@ class SmiliesTest extends FixtureTestCase
/**
* @dataProvider dataReplace
- *
- * @param string $expected
- * @param string $body
*/
- public function testReplace(string $expected, string $body)
+ public function testReplace(string $expected, string $body): void
{
$result = Smilies::replace($body);
$this->assertStringContainsString($expected, $result);
@@ -222,58 +223,58 @@ class SmiliesTest extends FixtureTestCase
{
return [
'symbols' => [
- 'expected' => ['p', 'heart', 'embarrassed', 'kiss'],
- 'body' => ':-p <3 ":-[:-"',
+ 'expected' => ['p', 'heart', 'embarrassed', 'kiss'],
+ 'body' => ':-p <3 ":-[:-"',
'normalized' => ':p: :heart: ":embarrassed::kiss:',
],
'single-smiley' => [
- 'expected' => ['like'],
- 'body' => ':like',
+ 'expected' => ['like'],
+ 'body' => ':like',
'normalized' => ':like:',
],
'multiple-smilies' => [
- 'expected' => ['like', 'dislike'],
- 'body' => ':like :dislike',
+ 'expected' => ['like', 'dislike'],
+ 'body' => ':like :dislike',
'normalized' => ':like: :dislike:',
],
'nosmile' => [
- 'expected' => [],
- 'body' => '[nosmile] :like :like',
+ 'expected' => [],
+ 'body' => '[nosmile] :like :like',
'normalized' => '[nosmile] :like :like'
],
'in-code' => [
- 'expected' => [],
- 'body' => '[code]:like :like :like[/code]',
+ 'expected' => [],
+ 'body' => '[code]:like :like :like[/code]',
'normalized' => '[code]:like :like :like[/code]'
],
'~friendica' => [
- 'expected' => ['friendica'],
- 'body' => '~friendica',
+ 'expected' => ['friendica'],
+ 'body' => '~friendica',
'normalized' => ':friendica:'
],
'space' => [
- 'expected' => ['smileyheart333'],
- 'body' => ':smiley heart 333:',
+ 'expected' => ['smileyheart333'],
+ 'body' => ':smiley heart 333:',
'normalized' => ':smileyheart333:'
],
'substitution-1' => [
- 'expected' => [],
- 'body' => '⽕',
+ 'expected' => [],
+ 'body' => '⽕',
'normalized' => '🔥',
],
'substitution-2' => [
- 'expected' => [],
- 'body' => ':hugging face:',
+ 'expected' => [],
+ 'body' => ':hugging face:',
'normalized' => '🤗',
],
'substitution-3' => [
- 'expected' => [],
- 'body' => ':face with hand over mouth:',
+ 'expected' => [],
+ 'body' => ':face with hand over mouth:',
'normalized' => '🤭',
],
'mixed' => [
- 'expected' => [],
- 'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
+ 'expected' => [],
+ 'body' => '⽕ :face with hand over mouth: invalid:hugging face: :hugging face:',
'normalized' => '🔥 🤭 invalid:hugging face: 🤗',
],
];
@@ -281,15 +282,11 @@ class SmiliesTest extends FixtureTestCase
/**
* @dataProvider dataExtractUsedSmilies
- *
- * @param array $expected
- * @param string $body
- * @param stirng $normalized
*/
- public function testExtractUsedSmilies(array $expected, string $body, string $normalized)
+ public function testExtractUsedSmilies(array $expected, string $body, string $normalized): void
{
$extracted = Smilies::extractUsedSmilies($body, $converted);
- $expected = array_fill_keys($expected, true);
+ $expected = array_fill_keys($expected, true);
$this->assertEquals($normalized, $converted);
foreach (array_keys($extracted) as $shortcode) {
$this->assertArrayHasKey($shortcode, $expected);
diff --git a/tests/src/Factory/Api/Mastodon/StatusTest.php b/tests/src/Factory/Api/Mastodon/StatusTest.php
index 314195bb5a..030c1605d4 100644
--- a/tests/src/Factory/Api/Mastodon/StatusTest.php
+++ b/tests/src/Factory/Api/Mastodon/StatusTest.php
@@ -8,6 +8,7 @@
namespace Friendica\Test\src\Factory\Api\Mastodon;
use Friendica\Core\Hook;
+use Friendica\Core\Hooks\HookEventBridge;
use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Test\FixtureTestCase;
@@ -21,13 +22,21 @@ class StatusTest extends FixtureTestCase
parent::setUp();
DI::config()->set('system', 'no_smilies', false);
+
$this->status = DI::mstdnStatus();
+ /** @var \Friendica\Event\EventDispatcher */
+ $eventDispatcher = DI::eventDispatcher();
+
+ foreach (HookEventBridge::getStaticSubscribedEvents() as $eventName => $methodName) {
+ $eventDispatcher->addListener($eventName, [HookEventBridge::class, $methodName]);
+ }
+
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
Hook::loadHooks();
}
- public function testSimpleStatus()
+ public function testSimpleStatus(): void
{
$post = Post::selectFirst([], ['id' => 13]);
$this->assertNotNull($post);
@@ -35,7 +44,7 @@ class StatusTest extends FixtureTestCase
$this->assertNotNull($result);
}
- public function testSimpleEmojiStatus()
+ public function testSimpleEmojiStatus(): void
{
$post = Post::selectFirst([], ['id' => 14]);
$this->assertNotNull($post);
diff --git a/tests/src/Protocol/ActivityPub/TransmitterTest.php b/tests/src/Protocol/ActivityPub/TransmitterTest.php
index 8b71aa130b..f9ef18a1a5 100644
--- a/tests/src/Protocol/ActivityPub/TransmitterTest.php
+++ b/tests/src/Protocol/ActivityPub/TransmitterTest.php
@@ -8,6 +8,7 @@
namespace Friendica\Test\src\Protocol\ActivityPub;
use Friendica\Core\Hook;
+use Friendica\Core\Hooks\HookEventBridge;
use Friendica\DI;
use Friendica\Model\Post;
use Friendica\Protocol\ActivityPub\Transmitter;
@@ -21,11 +22,18 @@ class TransmitterTest extends FixtureTestCase
DI::config()->set('system', 'no_smilies', false);
+ /** @var \Friendica\Event\EventDispatcher */
+ $eventDispatcher = DI::eventDispatcher();
+
+ foreach (HookEventBridge::getStaticSubscribedEvents() as $eventName => $methodName) {
+ $eventDispatcher->addListener($eventName, [HookEventBridge::class, $methodName]);
+ }
+
Hook::register('smilie', 'tests/Util/SmileyWhitespaceAddon.php', 'add_test_unicode_smilies');
Hook::loadHooks();
}
- public function testEmojiPost()
+ public function testEmojiPost(): void
{
$post = Post::selectFirst([], ['id' => 14]);
$this->assertNotNull($post);