mirror of
https://github.com/friendica/friendica
synced 2025-03-03 19:48:26 +00:00
Merge pull request #14799 from Art4/replace-hooks-with-eventdispatcher
Replace Hooks with EventDispatcher Part 2
This commit is contained in:
commit
afcc5a9205
34 changed files with 1044 additions and 446 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -362,7 +362,7 @@ Eine komplette Liste aller Hook-Callbacks mit den zugehörigen Dateien (am 01-Ap
|
|||
|
||||
### src/Content/ContactBlock.php
|
||||
|
||||
Hook::callAll('contact_block_end', $arr);
|
||||
Hook::callAll('contact_block_end', $text);
|
||||
|
||||
### src/Content/Text/BBCode.php
|
||||
|
||||
|
|
14
mod/item.php
14
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']);
|
||||
|
|
|
@ -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'), [
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -113,6 +113,8 @@ 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'),
|
||||
|
@ -135,7 +137,9 @@ class ContactSelector
|
|||
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);
|
||||
|
|
|
@ -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,8 +84,9 @@ 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;
|
||||
|
@ -99,7 +99,7 @@ class Conversation
|
|||
$this->args = $args;
|
||||
$this->pConfig = $pConfig;
|
||||
$this->page = $page;
|
||||
$this->appHelper = $appHelper;
|
||||
$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'],
|
||||
|
|
|
@ -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,8 +70,9 @@ 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;
|
||||
|
@ -82,6 +84,7 @@ class Item
|
|||
$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]);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -180,9 +182,15 @@ class OEmbed
|
|||
$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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -274,12 +282,11 @@ class OEmbed
|
|||
}
|
||||
}
|
||||
} elseif (!strpos($oembed->html, $oembed->embed_url)) {
|
||||
// add <a> for html2bbcode conversion
|
||||
// add <a> for html to bbcode conversion
|
||||
$ret .= '<a href="' . $oembed->embed_url . '" rel="oembed">' . $oembed->title . '</a>';
|
||||
}
|
||||
|
||||
$ret .= '</div>';
|
||||
$test = Proxy::proxifyHtml($ret, $uriid);
|
||||
|
||||
return str_replace("\n", "", $ret);
|
||||
}
|
||||
|
|
|
@ -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 '';
|
||||
|
|
|
@ -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;
|
||||
|
||||
/**
|
||||
|
@ -133,8 +133,13 @@ class Smilies
|
|||
'<a href="http://redmatrix.me/">red<img class="smiley" src="' . $baseUrl . '/images/rm-16.png" alt="red#matrix" title="red#matrix" />matrix</a>'
|
||||
];
|
||||
|
||||
$eventDispatcher = DI::eventDispatcher();
|
||||
|
||||
$params = ['texts' => $texts, 'icons' => $icons];
|
||||
Hook::callAll('smilie', $params);
|
||||
|
||||
$params = $eventDispatcher->dispatch(
|
||||
new ArrayFilterEvent(ArrayFilterEvent::SMILEY_LIST, $params),
|
||||
)->getArray();
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
@ -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'))));
|
||||
|
|
|
@ -15,10 +15,10 @@ use Friendica\Content\Item;
|
|||
use Friendica\Content\OEmbed;
|
||||
use Friendica\Content\PageInfo;
|
||||
use Friendica\Content\Smilies;
|
||||
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\Event;
|
||||
use Friendica\Model\Post;
|
||||
|
@ -1297,7 +1297,15 @@ class BBCode
|
|||
|
||||
DI::profiler()->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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -141,7 +141,9 @@ class HTML
|
|||
DI::profiler()->startRecording('rendering');
|
||||
$message = str_replace("\r", "", $message);
|
||||
|
||||
$message = Strings::performWithEscapedBlocks($message, '#<pre><code.*</code></pre>#iUs', function ($message) {
|
||||
$eventDispatcher = DI::eventDispatcher();
|
||||
|
||||
$message = Strings::performWithEscapedBlocks($message, '#<pre><code.*</code></pre>#iUs', function ($message) use ($eventDispatcher) {
|
||||
$message = str_replace(
|
||||
[
|
||||
"<li><p>",
|
||||
|
@ -314,7 +316,13 @@ class HTML
|
|||
$message = preg_replace('=\r *\r=i', "\n", $message);
|
||||
$message = str_replace("\r", "\n", $message);
|
||||
|
||||
Hook::callAll('html2bbcode', $message);
|
||||
$message_data = ['html2bbcode' => $message];
|
||||
|
||||
$message_data = $eventDispatcher->dispatch(
|
||||
new ArrayFilterEvent(ArrayFilterEvent::HTML_TO_BBCODE_END, $message_data),
|
||||
)->getArray();
|
||||
|
||||
$message = $message_data['html2bbcode'] ?? $message;
|
||||
|
||||
$message = strip_tags($message);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
@ -113,9 +112,11 @@ class ContactBlock
|
|||
'$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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -154,9 +155,11 @@ class ACL
|
|||
|
||||
$acl_contacts[] = $acl_yourself;
|
||||
|
||||
$acl_groups = Contact::selectToArray($fields,
|
||||
$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
|
||||
'network' => Protocol::FEDERATED, 'pending' => false, 'contact-type' => Contact::TYPE_COMMUNITY],
|
||||
$params
|
||||
);
|
||||
|
||||
$acl_contacts = array_merge($acl_groups, $acl_contacts);
|
||||
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
@ -35,16 +36,39 @@ final class HookEventBridge
|
|||
*/
|
||||
private static array $eventMapper = [
|
||||
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',
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -54,16 +78,39 @@ final class HookEventBridge
|
|||
{
|
||||
return [
|
||||
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(
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
41
src/Event/CollectRoutesEvent.php
Normal file
41
src/Event/CollectRoutesEvent.php
Normal file
|
@ -0,0 +1,41 @@
|
|||
<?php
|
||||
|
||||
// Copyright (C) 2010-2024, the Friendica project
|
||||
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Friendica\Event;
|
||||
|
||||
use FastRoute\RouteCollector;
|
||||
|
||||
/**
|
||||
* Allow addons to collect routes.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
final class CollectRoutesEvent extends Event
|
||||
{
|
||||
public const COLLECT_ROUTES = 'friendica.collect_routes';
|
||||
|
||||
private RouteCollector $routeCollector;
|
||||
|
||||
public function __construct(string $name, RouteCollector $routeCollector)
|
||||
{
|
||||
parent::__construct($name);
|
||||
|
||||
$this->routeCollector = $routeCollector;
|
||||
}
|
||||
|
||||
public function getRouteCollector(): RouteCollector
|
||||
{
|
||||
return $this->routeCollector;
|
||||
}
|
||||
|
||||
public function setRouteCollector(RouteCollector $routeCollector): void
|
||||
{
|
||||
$this->routeCollector = $routeCollector;
|
||||
}
|
||||
}
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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'])) {
|
||||
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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
@ -34,11 +35,11 @@ class Home extends BaseModule
|
|||
{
|
||||
$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');
|
||||
|
|
|
@ -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,8 +60,9 @@ 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);
|
||||
|
||||
|
@ -71,6 +73,7 @@ class Compose extends BaseModule
|
|||
$this->config = $config;
|
||||
$this->session = $session;
|
||||
$this->appHelper = $appHelper;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
protected function post(array $request = [])
|
||||
|
@ -136,8 +139,7 @@ class Compose extends BaseModule
|
|||
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) : [];
|
||||
|
@ -153,8 +155,9 @@ class Compose extends BaseModule
|
|||
$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 <a href="/settings/display">Theme Customization settings</a>.'),
|
||||
],
|
||||
|
||||
|
|
|
@ -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,10 +45,13 @@ 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);
|
||||
|
||||
|
@ -56,6 +60,7 @@ class Edit extends BaseModule
|
|||
$this->page = $page;
|
||||
$this->mode = $mode;
|
||||
$this->appHelper = $appHelper;
|
||||
$this->eventDispatcher = $eventDispatcher;
|
||||
}
|
||||
|
||||
|
||||
|
@ -109,9 +114,9 @@ class Edit extends BaseModule
|
|||
$item['body'] = Post\Media::addAttachmentsToBody($item['uri-id'], $item['body']);
|
||||
$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,
|
||||
|
|
|
@ -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->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]);
|
||||
|
||||
|
|
|
@ -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,8 +47,9 @@ 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);
|
||||
|
||||
|
@ -58,6 +60,7 @@ class Delegation extends BaseModule
|
|||
$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']));
|
||||
|
||||
|
|
|
@ -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'];
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -23,16 +25,39 @@ class HookEventBridgeTest extends TestCase
|
|||
{
|
||||
$expected = [
|
||||
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 '<b>changed</b>';
|
||||
});
|
||||
|
||||
HookEventBridge::onBbcodeToHtmlEvent($event);
|
||||
|
||||
$this->assertSame(
|
||||
['bbcode2html' => '<b>changed</b>'],
|
||||
$event->getArray(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testOnHtmlToBbcodeEventCallsHookWithCorrectValue(): void
|
||||
{
|
||||
$event = new ArrayFilterEvent(ArrayFilterEvent::HTML_TO_BBCODE_END, ['html2bbcode' => '<b>original</b>']);
|
||||
|
||||
$reflectionProperty = new \ReflectionProperty(HookEventBridge::class, 'mockedCallHook');
|
||||
$reflectionProperty->setAccessible(true);
|
||||
|
||||
$reflectionProperty->setValue(null, function (string $name, string $data): string {
|
||||
$this->assertSame('html2bbcode', $name);
|
||||
$this->assertSame('<b>original</b>', $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'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
|
@ -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'],
|
||||
];
|
||||
}
|
||||
|
||||
|
|
67
tests/Unit/Event/CollectRoutesEventTest.php
Normal file
67
tests/Unit/Event/CollectRoutesEventTest.php
Normal file
|
@ -0,0 +1,67 @@
|
|||
<?php
|
||||
|
||||
// Copyright (C) 2010-2024, the Friendica project
|
||||
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Friendica\Test\Unit\Event;
|
||||
|
||||
use FastRoute\RouteCollector;
|
||||
use Friendica\Event\CollectRoutesEvent;
|
||||
use Friendica\Event\NamedEvent;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class CollectRoutesEventTest extends TestCase
|
||||
{
|
||||
public function testImplementationOfInstances(): void
|
||||
{
|
||||
$event = new CollectRoutesEvent('test', $this->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());
|
||||
}
|
||||
}
|
|
@ -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,11 +22,18 @@ 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 */
|
||||
|
@ -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);
|
||||
|
@ -120,17 +128,12 @@ class SmiliesTest extends FixtureTestCase
|
|||
|
||||
/**
|
||||
* @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 = [
|
||||
|
@ -138,7 +141,7 @@ class SmiliesTest extends FixtureTestCase
|
|||
'expected' => 'alt=":-p"',
|
||||
'body' => ':-p',
|
||||
],
|
||||
'simple-1' => [
|
||||
'simple-2' => [
|
||||
'expected' => 'alt=":-p"',
|
||||
'body' => ' :-p ',
|
||||
],
|
||||
|
@ -191,6 +194,7 @@ class SmiliesTest extends FixtureTestCase
|
|||
'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) {
|
||||
|
@ -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);
|
||||
|
@ -281,12 +282,8 @@ 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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue