Compare commits

..

No commits in common. "d4b7e990ce18bef4571012e270594fb559678927" and "539104ec332a912b41916645915872528d9bda71" have entirely different histories.

63 changed files with 248 additions and 387 deletions

View File

@ -34,11 +34,10 @@ use Component\Attachment\Entity as E;
use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use EventResult;
class Attachment extends Component
{
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('note_attachment_show', '/object/note/{note_id<\d+>}/attachment/{attachment_id<\d+>}', [C\Attachment::class, 'attachmentShowWithNote']);
$r->connect('note_attachment_view', '/object/note/{note_id<\d+>}/attachment/{attachment_id<\d+>}/view', [C\Attachment::class, 'attachmentViewWithNote']);
@ -52,13 +51,13 @@ class Attachment extends Component
*
* This can be used in the future to deduplicate images by visual content
*/
public function onHashFile(string $filename, ?string &$out_hash): EventResult
public function onHashFile(string $filename, ?string &$out_hash): bool
{
$out_hash = hash_file(E\Attachment::FILEHASH_ALGO, $filename);
return Event::stop;
}
public function onNoteDeleteRelated(Note &$note, Actor $actor): EventResult
public function onNoteDeleteRelated(Note &$note, Actor $actor): bool
{
Cache::delete("note-attachments-{$note->getId()}");
foreach ($note->getAttachments() as $attachment) {
@ -69,7 +68,7 @@ class Attachment extends Component
return Event::next;
}
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): EventResult
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): bool
{
if (!\in_array('attachment_to_note', $note_qb->getAllAliases())) {
$note_qb->leftJoin(
@ -85,7 +84,7 @@ class Attachment extends Component
/**
* Populate $note_expr with the criteria for looking for notes with attachments
*/
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): bool
{
$include_term = str_contains($term, ':') ? explode(':', $term)[1] : $term;
if (Formatting::startsWith($term, ['note-types:', 'notes-incude:', 'note-filter:'])) {

View File

@ -32,17 +32,15 @@ use Component\Attachment\Entity\Attachment;
use Component\Attachment\Entity\AttachmentThumbnail;
use Component\Avatar\Controller as C;
use Component\Avatar\Exception\NoAvatarException;
use EventResult;
use Symfony\Component\HttpFoundation\Request;
class Avatar extends Component
{
public function onInitializeComponent(): EventResult
public function onInitializeComponent()
{
return EventResult::next;
}
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('avatar_actor', '/actor/{actor_id<\d+>}/avatar/{size<full|big|medium|small>?medium}', [Controller\Avatar::class, 'avatar_view']);
$r->connect('avatar_default', '/avatar/default/{size<full|big|medium|small>?medium}', [Controller\Avatar::class, 'default_avatar_view']);
@ -53,7 +51,7 @@ class Avatar extends Component
/**
* @throws \App\Util\Exception\ClientException
*/
public function onPopulateSettingsTabs(Request $request, string $section, &$tabs): EventResult
public function onPopulateSettingsTabs(Request $request, string $section, &$tabs): bool
{
if ($section === 'profile') {
$tabs[] = [
@ -66,7 +64,7 @@ class Avatar extends Component
return Event::next;
}
public function onAvatarUpdate(int $actor_id): EventResult
public function onAvatarUpdate(int $actor_id): bool
{
Cache::delete("avatar-{$actor_id}");
foreach (['full', 'big', 'medium', 'small'] as $size) {

View File

@ -39,7 +39,6 @@ use Component\Circle\Entity\ActorCircleSubscription;
use Component\Circle\Entity\ActorTag;
use Component\Collection\Util\MetaCollectionTrait;
use Component\Tag\Tag;
use EventResult;
use Functional as F;
use Symfony\Component\HttpFoundation\Request;
@ -59,7 +58,7 @@ class Circle extends Component
protected const SLUG = 'circle';
protected const PLURAL_SLUG = 'circles';
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('actor_circle_view_by_circle_id', '/circle/{circle_id<\d+>}', [CircleController\Circle::class, 'circleById']);
// View circle members by (tagger id or nickname) and tag
@ -94,7 +93,7 @@ class Circle extends Component
];
}
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool
{
if ($section === 'profile' && \in_array($request->get('_route'), ['person_actor_settings', 'group_actor_settings'])) {
$tabs[] = [
@ -107,7 +106,7 @@ class Circle extends Component
return Event::next;
}
public function onPostingFillTargetChoices(Request $request, Actor $actor, array &$targets): EventResult
public function onPostingFillTargetChoices(Request $request, Actor $actor, array &$targets): bool
{
$circles = $actor->getCircles();
foreach ($circles as $circle) {
@ -219,7 +218,7 @@ class Circle extends Component
return $ids_only ? array_map(fn ($x) => $x->getId(), $circles) : $circles;
}
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): EventResult
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering)
{
DB::persist(Feed::create([
'actor_id' => $actor_id,

View File

@ -14,7 +14,6 @@ use Component\Subscription\Entity\ActorSubscription;
use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use EventResult;
class Collection extends Component
{
@ -65,7 +64,7 @@ class Collection extends Component
return ['notes' => $notes ?? null, 'actors' => $actors ?? null];
}
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): EventResult
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): bool
{
$note_aliases = $note_qb->getAllAliases();
if (!\in_array('subscription', $note_aliases)) {
@ -81,7 +80,7 @@ class Collection extends Component
* Convert $term to $note_expr and $actor_expr, search criteria. Handles searching for text
* notes, for different types of actors and for the content of text notes
*/
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr)
{
if (str_contains($term, ':')) {
$term = explode(':', $term);

View File

@ -39,7 +39,6 @@ use App\Entity\Actor;
use App\Util\Common;
use App\Util\Exception\RedirectException;
use App\Util\Formatting;
use EventResult;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
@ -95,7 +94,7 @@ trait MetaCollectionTrait
* It's compose of two forms: one to select collections to add
* the current item to, and another to create a new collection.
*/
public function onAppendRightPanelBlock(Request $request, $vars, &$res): EventResult
public function onAppendRightPanelBlock(Request $request, $vars, &$res): bool
{
$user = Common::actor();
if (\is_null($user)) {
@ -187,7 +186,7 @@ trait MetaCollectionTrait
return Event::next;
}
public function onEndShowStyles(array &$styles, string $route): EventResult
public function onEndShowStyles(array &$styles, string $route): bool
{
$styles[] = 'components/Collection/assets/css/widget.css';
$styles[] = 'components/Collection/assets/css/pages.css';

View File

@ -40,13 +40,12 @@ use App\Util\Common;
use App\Util\Formatting;
use Component\Conversation\Entity\Conversation as ConversationEntity;
use Component\Conversation\Entity\ConversationMute;
use EventResult;
use Functional as F;
use Symfony\Component\HttpFoundation\Request;
class Conversation extends Component
{
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('conversation', '/conversation/{conversation_id<\d+>}', [Controller\Conversation::class, 'showConversation']);
$r->connect('conversation_mute', '/conversation/{conversation_id<\d+>}/mute', [Controller\Conversation::class, 'muteConversation']);
@ -105,7 +104,7 @@ class Conversation extends Component
*
* @return bool EventHook
*/
public function onAddNoteActions(Request $request, Note $note, array &$actions): EventResult
public function onAddNoteActions(Request $request, Note $note, array &$actions): bool
{
if (\is_null(Common::user())) {
return Event::next;
@ -145,7 +144,7 @@ class Conversation extends Component
*
* @return bool EventHook
*/
public function onAppendCardNote(array $vars, array &$result): EventResult
public function onAppendCardNote(array $vars, array &$result): bool
{
if (str_contains($vars['request']->getPathInfo(), 'conversation')) {
return Event::next;
@ -198,7 +197,7 @@ class Conversation extends Component
*
* @return bool EventHook
*/
public function onPostingGetContextActor(Request $request, Actor $actor, ?Actor &$context_actor): EventResult
public function onPostingGetContextActor(Request $request, Actor $actor, ?Actor &$context_actor): bool
{
$to_note_id = $this->getReplyToIdFromRequest($request);
if (!\is_null($to_note_id)) {
@ -219,7 +218,7 @@ class Conversation extends Component
*
* @return bool EventHook
*/
public function onPostingModifyData(Request $request, Actor $actor, array &$data): EventResult
public function onPostingModifyData(Request $request, Actor $actor, array &$data): bool
{
$to_note_id = $this->getReplyToIdFromRequest($request);
if (!\is_null($to_note_id)) {
@ -233,7 +232,7 @@ class Conversation extends Component
/**
* Add minimal Note card to RightPanel template
*/
public function onPrependPostingForm(Request $request, array &$elements): EventResult
public function onPrependPostingForm(Request $request, array &$elements): bool
{
$elements[] = Formatting::twigRenderFile('cards/blocks/note_compact_wrapper.html.twig', ['note' => Note::getById((int) $request->query->get('reply_to_id'))]);
return Event::next;
@ -248,7 +247,7 @@ class Conversation extends Component
*
* @return bool EventHook
*/
public function onNoteDeleteRelated(Note &$note, Actor $actor): EventResult
public function onNoteDeleteRelated(Note &$note, Actor $actor): bool
{
// Ensure we have the most up to date replies
Cache::delete(Note::cacheKeys($note->getId())['replies']);
@ -267,7 +266,7 @@ class Conversation extends Component
*
* @return bool EventHook
*/
public function onAddExtraNoteActions(Request $request, Note $note, array &$actions): EventResult
public function onAddExtraNoteActions(Request $request, Note $note, array &$actions): bool
{
if (\is_null($user = Common::user())) {
return Event::next;
@ -303,7 +302,7 @@ class Conversation extends Component
*
* @return bool EventHook
*/
public function onNewNotificationShould(Activity $activity, Actor $actor): EventResult
public function onNewNotificationShould(Activity $activity, Actor $actor): bool
{
if ($activity->getObjectType() === 'note' && ConversationMute::isMuted($activity, $actor)) {
return Event::stop;

View File

@ -27,11 +27,10 @@ use App\Core\Event;
use App\Core\Modules\Component;
use App\Core\Router;
use Component\Feed\Controller as C;
use EventResult;
class Feed extends Component
{
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('feed_public', '/feed/public', [C\Feeds::class, 'public']);
$r->connect('feed_home', '/feed/home', [C\Feeds::class, 'home']);

View File

@ -54,7 +54,6 @@ use Component\FreeNetwork\Util\WebfingerResource;
use Component\FreeNetwork\Util\WebfingerResource\WebfingerResourceActor;
use Component\FreeNetwork\Util\WebfingerResource\WebfingerResourceNote;
use Doctrine\Common\Collections\ExpressionBuilder;
use EventResult;
use Exception;
use const PREG_SET_ORDER;
use Symfony\Component\HttpFoundation\JsonResponse;
@ -80,13 +79,13 @@ class FreeNetwork extends Component
public const OAUTH_AUTHORIZE_REL = 'http://apinamespace.org/oauth/authorize';
private static array $protocols = [];
public function onInitializeComponent(): EventResult
public function onInitializeComponent(): bool
{
Event::handle('AddFreeNetworkProtocol', [&self::$protocols]);
return Event::next;
}
public function onAddRoute(Router $m): EventResult
public function onAddRoute(Router $m): bool
{
// Feeds
$m->connect('feed_network', '/feed/network', [Feeds::class, 'network']);
@ -112,7 +111,7 @@ class FreeNetwork extends Component
return Event::next;
}
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): EventResult
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering)
{
DB::persist(\App\Entity\Feed::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_network'), 'route' => $route, 'title' => _m('Meteorites'), 'ordering' => $ordering++]));
DB::persist(\App\Entity\Feed::create(['actor_id' => $actor_id, 'url' => Router::url($route = 'feed_clique'), 'route' => $route, 'title' => _m('Planetary System'), 'ordering' => $ordering++]));
@ -120,7 +119,7 @@ class FreeNetwork extends Component
return Event::next;
}
public function onStartGetProfileAcctUri(Actor $profile, &$acct): EventResult
public function onStartGetProfileAcctUri(Actor $profile, &$acct): bool
{
$wfr = new WebFingerResourceActor($profile);
try {
@ -148,7 +147,7 @@ class FreeNetwork extends Component
* @throws NoSuchActorException
* @throws ServerException
*/
public function onEndGetWebFingerResource(string $resource, ?WebfingerResource &$target = null, array $args = []): EventResult
public function onEndGetWebFingerResource(string $resource, ?WebfingerResource &$target = null, array $args = []): bool
{
// * Either we didn't find the profile, then we want to make
// the $profile variable null for clarity.
@ -224,7 +223,7 @@ class FreeNetwork extends Component
return Event::next;
}
public function onStartHostMetaLinks(array &$links): EventResult
public function onStartHostMetaLinks(array &$links): bool
{
foreach (Discovery::supportedMimeTypes() as $type) {
$links[] = new XML_XRD_Element_Link(
@ -245,7 +244,7 @@ class FreeNetwork extends Component
/**
* Add a link header for LRDD Discovery
*/
public function onStartShowHTML($action): EventResult
public function onStartShowHTML($action): bool
{
if ($action instanceof ShowstreamAction) {
$resource = $action->getTarget()->getUri();
@ -258,13 +257,13 @@ class FreeNetwork extends Component
return Event::next;
}
public function onStartDiscoveryMethodRegistration(Discovery $disco): EventResult
public function onStartDiscoveryMethodRegistration(Discovery $disco): bool
{
$disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodWebfinger');
return Event::next;
}
public function onEndDiscoveryMethodRegistration(Discovery $disco): EventResult
public function onEndDiscoveryMethodRegistration(Discovery $disco): bool
{
$disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodHostMeta');
$disco->registerMethod('\Component\FreeNetwork\Util\LrddMethod\LrddMethodLinkHeader');
@ -276,7 +275,7 @@ class FreeNetwork extends Component
* @throws ClientException
* @throws ServerException
*/
public function onControllerResponseInFormat(string $route, array $accept_header, array $vars, ?Response &$response = null): EventResult
public function onControllerResponseInFormat(string $route, array $accept_header, array $vars, ?Response &$response = null): bool
{
if (!\in_array($route, ['freenetwork_hostmeta', 'freenetwork_hostmeta_format', 'freenetwork_webfinger', 'freenetwork_webfinger_format', 'freenetwork_ownerxrd'])) {
return Event::next;
@ -377,7 +376,7 @@ class FreeNetwork extends Component
* @return bool hook return value
* @example.com/mublog/user
*/
public function onEndFindMentions(Actor $sender, string $text, array &$mentions): EventResult
public function onEndFindMentions(Actor $sender, string $text, array &$mentions): bool
{
$matches = [];
@ -518,7 +517,7 @@ class FreeNetwork extends Component
* Add fediverse: query expression
* // TODO: adding WebFinger would probably be nice
*/
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): bool
{
if (Formatting::startsWith($term, ['fediverse:'])) {
foreach (self::$protocols as $protocol) {
@ -531,7 +530,7 @@ class FreeNetwork extends Component
return Event::next;
}
public function onPluginVersion(array &$versions): EventResult
public function onPluginVersion(array &$versions): bool
{
$versions[] = [
'name' => 'WebFinger',

View File

@ -33,12 +33,11 @@ use App\Util\Nickname;
use Component\Group\Controller as C;
use Component\Group\Entity\LocalGroup;
use Component\Notification\Notification;
use EventResult;
use Symfony\Component\HttpFoundation\Request;
class Group extends Component
{
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect(id: 'group_actor_view_id', uri_path: '/group/{id<\d+>}', target: [C\GroupFeed::class, 'groupViewId']);
$r->connect(id: 'group_actor_view_nickname', uri_path: '/!{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\GroupFeed::class, 'groupViewNickname']);
@ -51,7 +50,7 @@ class Group extends Component
* Enqueues a notification for an Actor (such as person or group) which means
* it shows up in their home feed and such.
*/
public function onNewNotificationStart(Actor $sender, Activity $activity, array $targets = [], ?string $reason = null): EventResult
public function onNewNotificationStart(Actor $sender, Activity $activity, array $targets = [], ?string $reason = null): bool
{
foreach ($targets as $target) {
if ($target->isGroup()) {
@ -71,7 +70,7 @@ class Group extends Component
/**
* Add an <a href=group_actor_settings> to the profile card for groups, if the current actor can access them
*/
public function onAppendCardProfile(array $vars, array &$res): EventResult
public function onAppendCardProfile(array $vars, array &$res): bool
{
$actor = Common::actor();
$group = $vars['actor'];
@ -109,7 +108,7 @@ class Group extends Component
return null;
}
public function onPostingFillTargetChoices(Request $request, Actor $actor, array &$targets): EventResult
public function onPostingFillTargetChoices(Request $request, Actor $actor, array &$targets): bool
{
$group = $this->getGroupFromContext($request);
if (!\is_null($group)) {
@ -128,7 +127,7 @@ class Group extends Component
*
* @param null|Actor $context_actor Actor group, if current route is part of an existing Group set of routes
*/
public function onPostingGetContextActor(Request $request, Actor $actor, ?Actor &$context_actor): EventResult
public function onPostingGetContextActor(Request $request, Actor $actor, ?Actor &$context_actor): bool
{
$ctx = $this->getGroupFromContext($request);
if (!\is_null($ctx)) {

View File

@ -33,19 +33,18 @@ use Component\Language\Entity\ActorLanguage;
use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use EventResult;
use Functional as F;
use Symfony\Component\HttpFoundation\Request;
class Language extends Component
{
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('settings_sort_languages', '/settings/sort_languages', [C\Language::class, 'sortLanguages']);
return Event::next;
}
public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): EventResult
public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): bool
{
if (\is_null($actor)) {
return Event::next;
@ -61,7 +60,7 @@ class Language extends Component
/**
* Populate $note_expr or $actor_expr with an expression to match a language
*/
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): bool
{
$search_term = str_contains($term, ':') ? explode(':', $term)[1] : $term;
@ -104,7 +103,7 @@ class Language extends Component
return Event::next;
}
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): EventResult
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): bool
{
$note_aliases = $note_qb->getAllAliases();
if (!\in_array('note_language', $note_aliases)) {

View File

@ -32,11 +32,10 @@ use App\Entity\Feed;
use App\Util\Exception\ClientException;
use App\Util\Exception\NotFoundException;
use Component\LeftPanel\Controller as C;
use EventResult;
class LeftPanel extends Component
{
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('edit_feeds', '/edit-feeds', C\EditFeeds::class);
return Event::next;
@ -47,7 +46,7 @@ class LeftPanel extends Component
* @throws \App\Util\Exception\ServerException
* @throws ClientException
*/
public function onAppendFeed(Actor $actor, string $title, string $route, array $route_params): EventResult
public function onAppendFeed(Actor $actor, string $title, string $route, array $route_params): bool
{
$cache_key = Feed::cacheKey($actor);
$feeds = Feed::getFeeds($actor);

View File

@ -31,7 +31,6 @@ use App\Entity\Note;
use App\Util\Common;
use App\Util\HTML;
use Component\Link\Entity\NoteToLink;
use EventResult;
use InvalidArgumentException;
class Link extends Component
@ -55,7 +54,7 @@ class Link extends Component
/**
* Extract URLs from $content and create the appropriate Link and NoteToLink entities
*/
public function onProcessNoteContent(Note $note, string $content, string $content_type, array $process_note_content_extra_args = []): EventResult
public function onProcessNoteContent(Note $note, string $content, string $content_type, array $process_note_content_extra_args = []): bool
{
$ignore = $process_note_content_extra_args['ignoreLinks'] ?? [];
if (Common::config('attachments', 'process_links')) {
@ -72,7 +71,7 @@ class Link extends Component
return Event::next;
}
public function onRenderPlainTextNoteContent(string &$text): EventResult
public function onRenderPlainTextNoteContent(string &$text): bool
{
$text = $this->replaceURLs($text);
return Event::next;
@ -276,7 +275,7 @@ class Link extends Component
return HTML::html(['a' => ['attrs' => $attrs, $url]], options: ['indent' => false]);
}
public function onNoteDeleteRelated(Note &$note, Actor $actor): EventResult
public function onNoteDeleteRelated(Note &$note, Actor $actor): bool
{
DB::wrapInTransaction(fn () => NoteToLink::removeWhereNoteId($note->getId()));
return Event::next;

View File

@ -34,13 +34,12 @@ use App\Entity\LocalUser;
use App\Util\Exception\ServerException;
use Component\FreeNetwork\FreeNetwork;
use Component\Notification\Controller\Feed;
use EventResult;
use Exception;
use Throwable;
class Notification extends Component
{
public function onAddRoute(Router $m): EventResult
public function onAddRoute(Router $m): bool
{
$m->connect('feed_notifications', '/feed/notifications', [Feed::class, 'notifications']);
return Event::next;
@ -49,7 +48,7 @@ class Notification extends Component
/**
* @throws ServerException
*/
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): EventResult
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): bool
{
DB::persist(\App\Entity\Feed::create([
'actor_id' => $actor_id,
@ -76,7 +75,7 @@ class Notification extends Component
* @param array $targets Attentions, Mentions, any other source. Should never be empty, you usually want to register an attention to every $sender->getSubscribers()
* @param null|string $reason An optional reason explaining why this notification exists
*/
public function onNewNotification(Actor $sender, Activity $activity, array $targets, ?string $reason = null): EventResult
public function onNewNotification(Actor $sender, Activity $activity, array $targets, ?string $reason = null): bool
{
// Ensure targets are all actor objects and unique
$effective_targets = [];
@ -103,13 +102,13 @@ class Notification extends Component
return Event::next;
}
public function onQueueNotificationLocal(Actor $sender, Activity $activity, Actor $target, ?string $reason, array &$retry_args): EventResult
public function onQueueNotificationLocal(Actor $sender, Activity $activity, Actor $target, ?string $reason, array &$retry_args): bool
{
// TODO: use https://symfony.com/doc/current/notifier.html
return Event::stop;
}
public function onQueueNotificationRemote(Actor $sender, Activity $activity, array $targets, ?string $reason, array &$retry_args): EventResult
public function onQueueNotificationRemote(Actor $sender, Activity $activity, array $targets, ?string $reason, array &$retry_args): bool
{
if (FreeNetwork::notify($sender, $activity, $targets, $reason)) {
return Event::stop;

View File

@ -26,11 +26,10 @@ use App\Core\Modules\Component;
use App\Core\Router;
use App\Util\Nickname;
use Component\Person\Controller as C;
use EventResult;
class Person extends Component
{
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect(id: 'person_actor_view_id', uri_path: '/person/{id<\d+>}', target: [C\PersonFeed::class, 'personViewId']);
$r->connect(id: 'person_actor_view_nickname', uri_path: '/@{nickname<' . Nickname::DISPLAY_FMT . '>}', target: [C\PersonFeed::class, 'personViewNickname'], options: ['is_system_path' => false]);

View File

@ -47,7 +47,6 @@ use Component\Attachment\Entity\AttachmentToNote;
use Component\Conversation\Conversation;
use Component\Language\Entity\Language;
use Component\Notification\Entity\Attention;
use EventResult;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
@ -55,7 +54,7 @@ class Posting extends Component
{
public const route = 'posting_form_action';
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect(self::route, '/form/posting', Controller\Posting::class);
return Event::next;
@ -71,7 +70,7 @@ class Posting extends Component
* @throws RedirectException
* @throws ServerException
*/
public function onAddMainRightPanelBlock(Request $request, array &$res): EventResult
public function onAddMainRightPanelBlock(Request $request, array &$res): bool
{
if (\is_null($user = Common::user()) || preg_match('(feed|conversation|group|view)', $request->get('_route')) === 0) {
return Event::next;
@ -299,7 +298,7 @@ class Posting extends Component
return [$activity, $note, $effective_attentions];
}
public function onRenderNoteContent(string $content, string $content_type, ?string &$rendered, Actor $author, ?string $language = null, array &$mentions = []): EventResult
public function onRenderNoteContent(string $content, string $content_type, ?string &$rendered, Actor $author, ?string $language = null, array &$mentions = [])
{
switch ($content_type) {
case 'text/plain':

View File

@ -27,12 +27,10 @@ use App\Core\Event;
use App\Core\Form;
use function App\Core\I18n\_m;
use App\Core\Modules\Component;
use App\Core\Router;
use App\Util\Common;
use App\Util\Exception\ClientException;
use App\Util\Exception\RedirectException;
use App\Util\Formatting;
use EventResult;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormView;
@ -41,10 +39,9 @@ use Symfony\Component\HttpFoundation\Request;
class Search extends Component
{
public function onAddRoute(Router $r): EventResult
public function onAddRoute($r)
{
$r->connect('search', '/search', Controller\Search::class);
return EventResult::next;
}
/**
@ -136,7 +133,7 @@ class Search extends Component
*
* @throws RedirectException
*/
public function onPrependRightPanelBlock(Request $request, array &$elements): EventResult
public function onPrependRightPanelBlock(Request $request, array &$elements): bool
{
$elements[] = Formatting::twigRenderFile('cards/search/view.html.twig', ['search' => self::searchForm($request)]);
return Event::next;
@ -149,7 +146,7 @@ class Search extends Component
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onEndShowStyles(array &$styles, string $route): EventResult
public function onEndShowStyles(array &$styles, string $route): bool
{
$styles[] = 'components/Search/assets/css/view.css';
return Event::next;

View File

@ -39,12 +39,11 @@ use App\Util\Exception\ServerException;
use Component\Notification\Entity\Attention;
use Component\Subscription\Controller\Subscribers as SubscribersController;
use Component\Subscription\Controller\Subscriptions as SubscriptionsController;
use EventResult;
use Symfony\Component\HttpFoundation\Request;
class Subscription extends Component
{
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect(id: 'actor_subscribe_add', uri_path: '/actor/subscribe/{object_id<\d+>}', target: [SubscribersController::class, 'subscribersAdd']);
$r->connect(id: 'actor_subscribe_remove', uri_path: '/actor/unsubscribe/{object_id<\d+>}', target: [SubscribersController::class, 'subscribersRemove']);
@ -187,7 +186,7 @@ class Subscription extends Component
*
* @return bool EventHook
*/
public function onAddProfileActions(Request $request, Actor $object, array &$actions): EventResult
public function onAddProfileActions(Request $request, Actor $object, array &$actions): bool
{
// Action requires a user to be logged in
// We know it's a LocalUser, which has the same id as Actor

View File

@ -42,7 +42,6 @@ use Component\Tag\Entity\NoteTag;
use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use EventResult;
use Functional as F;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\HttpFoundation\Request;
@ -61,7 +60,7 @@ class Tag extends Component
public const TAG_REGEX = '/(^|\\s)(#[\\pL\\pN_\\-]{1,64})/u'; // Brion Vibber 2011-02-23 v2:classes/Notice.php:367 function saveTags
public const TAG_SLUG_REGEX = '[A-Za-z0-9]{1,64}';
public function onAddRoute($r): EventResult
public function onAddRoute($r): bool
{
$r->connect('single_note_tag', '/note-tag/{tag<' . self::TAG_SLUG_REGEX . '>}', [Controller\Tag::class, 'single_note_tag']);
$r->connect('multi_note_tags', '/note-tags/{tags<(' . self::TAG_SLUG_REGEX . ',)+' . self::TAG_SLUG_REGEX . '>}', [Controller\Tag::class, 'multi_note_tags']);
@ -119,7 +118,7 @@ class Tag extends Component
/**
* Process note by extracting any tags present
*/
public function onProcessNoteContent(Note $note, string $content, string $content_type, array $extra_args): EventResult
public function onProcessNoteContent(Note $note, string $content, string $content_type, array $extra_args): bool
{
if ($extra_args['TagProcessed'] ?? false) {
return Event::next;
@ -136,7 +135,7 @@ class Tag extends Component
return Event::next;
}
public function onRenderPlainTextNoteContent(string &$text, ?string $locale = null): EventResult
public function onRenderPlainTextNoteContent(string &$text, ?string $locale = null): bool
{
$text = preg_replace_callback(self::TAG_REGEX, fn ($m) => $m[1] . self::tagLink($m[2], $locale), $text);
return Event::next;
@ -214,7 +213,7 @@ class Tag extends Component
*
* $term /^(note|tag|people|actor)/ means we want to match only either a note or an actor
*/
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $locale, ?Actor $actor, &$note_expr, &$actor_expr): bool
{
if (!str_contains($term, ':')) {
return Event::next;
@ -253,7 +252,7 @@ class Tag extends Component
return Event::next;
}
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): EventResult
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): bool
{
if (!\in_array('note_tag', $note_qb->getAllAliases())) {
$note_qb->leftJoin(NoteTag::class, 'note_tag', Expr\Join::WITH, 'note_tag.note_id = note.id');
@ -264,13 +263,13 @@ class Tag extends Component
return Event::next;
}
public function onPostingAddFormEntries(Request $request, Actor $actor, array &$form_params): EventResult
public function onPostingAddFormEntries(Request $request, Actor $actor, array &$form_params): bool
{
$form_params[] = ['tag_use_canonical', CheckboxType::class, ['required' => false, 'data' => true, 'label' => _m('Make note tags canonical'), 'help' => _m('Canonical tags will be treated as a version of an existing tag with the same root/stem (e.g. \'#great_tag\' will be considered as a version of \'#great\', if it already exists)')]];
return Event::next;
}
public function onAddExtraArgsToNoteContent(Request $request, Actor $actor, array $data, array &$extra_args): EventResult
public function onAddExtraArgsToNoteContent(Request $request, Actor $actor, array $data, array &$extra_args): bool
{
if (!isset($data['tag_use_canonical'])) {
throw new ClientException(_m('Missing Use Canonical preference for Tags.'));

View File

@ -103,9 +103,6 @@
"files": [
"src/Core/I18n/I18n.php"
],
"classmap": [
"src/Core/Event/EventResult.php"
],
"psr-4": {
"App\\": "src/",
"Plugin\\": "plugins/",

View File

@ -13,7 +13,7 @@ services:
# this creates a service per class whose id is the fully-qualified class name
App\:
resource: '../src/*'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php,Routes,Core/Event/EventResult.php}'
exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php,Routes}'
App\Test\Fixtures\:
resource: '../tests/fixtures/*'

View File

@ -50,7 +50,6 @@ use App\Util\Exception\BugFoundException;
use Component\Collection\Util\Controller\OrderedCollection;
use Component\FreeNetwork\Entity\FreeNetworkActorProtocol;
use Component\FreeNetwork\Util\Discovery;
use EventResult;
use Exception;
use InvalidArgumentException;
use Plugin\ActivityPub\Controller\Inbox;
@ -123,14 +122,14 @@ class ActivityPub extends Plugin
],
];
public function onInitializePlugin(): EventResult
public function onInitializePlugin(): bool
{
Event::handle('ActivityStreamsTwoContext', [&self::$activity_streams_two_context]);
self::$activity_streams_two_context = array_unique(self::$activity_streams_two_context, \SORT_REGULAR);
return Event::next;
}
public function onQueueActivitypubInbox(ActivitypubActor $ap_actor, Actor $actor, string|AbstractObject $type): EventResult
public function onQueueActivitypubInbox(ActivitypubActor $ap_actor, Actor $actor, string|AbstractObject $type): bool
{
// TODO: Check if Actor has authority over payload
@ -158,7 +157,7 @@ class ActivityPub extends Plugin
*
* @param Router $r the router that was initialized
*/
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect(
'activitypub_inbox',
@ -184,7 +183,7 @@ class ActivityPub extends Plugin
/**
* Fill Actor->getUrl() calls with correct URL coming from ActivityPub
*/
public function onStartGetActorUri(Actor $actor, int $type, ?string &$url): EventResult
public function onStartGetActorUri(Actor $actor, int $type, ?string &$url): bool
{
if (
// Is remote?
@ -204,7 +203,7 @@ class ActivityPub extends Plugin
/**
* Fill Actor->canAdmin() for Actors that came from ActivityPub
*/
public function onFreeNetworkActorCanAdmin(Actor $actor, Actor $other, bool &$canAdmin): EventResult
public function onFreeNetworkActorCanAdmin(Actor $actor, Actor $other, bool &$canAdmin): bool
{
// Are both in AP?
if (
@ -224,7 +223,7 @@ class ActivityPub extends Plugin
*
* @throws Exception
*/
public function onControllerResponseInFormat(string $route, array $accept_header, array $vars, ?TypeResponse &$response = null): EventResult
public function onControllerResponseInFormat(string $route, array $accept_header, array $vars, ?TypeResponse &$response = null): bool
{
if (\count(array_intersect(self::$accept_headers, $accept_header)) === 0) {
return Event::next;
@ -263,7 +262,7 @@ class ActivityPub extends Plugin
/**
* Add ActivityStreams 2 Extensions
*/
public function onActivityPubValidateActivityStreamsTwoData(string $type_name, array &$validators): EventResult
public function onActivityPubValidateActivityStreamsTwoData(string $type_name, array &$validators): bool
{
switch ($type_name) {
case 'Person':
@ -281,7 +280,7 @@ class ActivityPub extends Plugin
/**
* Let FreeNetwork Component know we exist and which class to use to call the freeNetworkDistribute method
*/
public function onAddFreeNetworkProtocol(array &$protocols): EventResult
public function onAddFreeNetworkProtocol(array &$protocols): bool
{
$protocols[] = '\Plugin\ActivityPub\ActivityPub';
return Event::next;
@ -322,7 +321,7 @@ class ActivityPub extends Plugin
string $inbox,
array $to_actors,
array &$retry_args,
): EventResult {
): bool {
try {
$data = Model::toType($activity);
if ($sender->isGroup()) { // When the sender is a group,
@ -427,7 +426,7 @@ class ActivityPub extends Plugin
/**
* Add activity+json mimetype to WebFinger
*/
public function onEndWebFingerProfileLinks(XML_XRD $xrd, Actor $object): EventResult
public function onEndWebFingerProfileLinks(XML_XRD $xrd, Actor $object): bool
{
if ($object->isPerson()) {
$link = new XML_XRD_Element_Link(
@ -443,7 +442,7 @@ class ActivityPub extends Plugin
/**
* When FreeNetwork component asks us to help with identifying Actors from XRDs
*/
public function onFreeNetworkFoundXrd(XML_XRD $xrd, ?Actor &$actor = null): EventResult
public function onFreeNetworkFoundXrd(XML_XRD $xrd, ?Actor &$actor = null): bool
{
$addr = null;
foreach ($xrd->aliases as $alias) {
@ -474,7 +473,7 @@ class ActivityPub extends Plugin
/**
* When FreeNetwork component asks us to help with identifying Actors from URIs
*/
public function onFreeNetworkFindMentions(string $target, ?Actor &$actor = null): EventResult
public function onFreeNetworkFindMentions(string $target, ?Actor &$actor = null): bool
{
try {
if (FreeNetworkActorProtocol::canIAddr('activitypub', $addr = Discovery::normalize($target))) {

View File

@ -41,7 +41,6 @@ use App\Entity\Feed;
use App\Entity\LocalUser;
use App\Util\Nickname;
use Component\Collection\Util\MetaCollectionTrait;
use EventResult;
use Plugin\AttachmentCollections\Controller\AttachmentCollections as AttachmentCollectionsController;
use Plugin\AttachmentCollections\Entity\AttachmentCollection;
use Plugin\AttachmentCollections\Entity\AttachmentCollectionEntry;
@ -123,7 +122,7 @@ class AttachmentCollections extends Plugin
return array_map(fn ($x) => $x['attachment_collection_id'], $res);
}
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
// View all collections by actor id and nickname
$r->connect(
@ -150,7 +149,7 @@ class AttachmentCollections extends Plugin
return Event::next;
}
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): EventResult
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering)
{
DB::persist(Feed::create([
'actor_id' => $actor_id,

View File

@ -28,12 +28,11 @@ use App\Core\Event;
use App\Core\Modules\Plugin;
use App\Util\Common;
use App\Util\Formatting;
use EventResult;
use Symfony\Component\HttpFoundation\Request;
class AttachmentShowRelated extends Plugin
{
public function onAppendRightPanelBlock(Request $request, $vars, &$res): EventResult
public function onAppendRightPanelBlock(Request $request, $vars, &$res): bool
{
if ($vars['path'] === 'note_attachment_show') {
$related_notes = DB::dql('select n from attachment_to_note an '
@ -55,7 +54,7 @@ class AttachmentShowRelated extends Plugin
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onEndShowStyles(array &$styles, string $path): EventResult
public function onEndShowStyles(array &$styles, string $path): bool
{
if ($path === 'note_attachment_show') {
$styles[] = '/assets/default_theme/pages/feeds.css';

View File

@ -38,7 +38,6 @@ use function App\Core\I18n\_m;
use App\Core\Modules\Plugin;
use App\Util\Exception\ServerException;
use App\Util\Formatting;
use EventResult;
use FFMpeg\FFProbe as ffprobe;
use SplFileInfo;
@ -54,7 +53,7 @@ class AudioEncoder extends Plugin
return GSFile::mimetypeMajor($mimetype) === 'audio';
}
public function onFileMetaAvailable(array &$event_map, string $mimetype): EventResult
public function onFileMetaAvailable(array &$event_map, string $mimetype): bool
{
if (!self::shouldHandle($mimetype)) {
return Event::next;
@ -91,7 +90,7 @@ class AudioEncoder extends Plugin
/**
* Generates the view for attachments of type Video
*/
public function onViewAttachment(array $vars, array &$res): EventResult
public function onViewAttachment(array $vars, array &$res): bool
{
if (!self::shouldHandle($vars['attachment']->getMimetype())) {
return Event::next;
@ -111,7 +110,7 @@ class AudioEncoder extends Plugin
/**
* @throws ServerException
*/
public function onPluginVersion(array &$versions): EventResult
public function onPluginVersion(array &$versions): bool
{
$versions[] = [
'name' => 'AudioEncoder',

View File

@ -23,23 +23,22 @@ declare(strict_types = 1);
namespace Plugin\Blog;
use App\Core\Event;
use function App\Core\I18n\_m;
use App\Core\Modules\Plugin;
use App\Core\Router;
use App\Util\Common;
use App\Util\HTML;
use EventResult;
use Plugin\Blog\Controller as C;
use function App\Core\I18n\_m;
class Blog extends Plugin
{
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect(id: 'blog_post', uri_path: '/blog/post', target: [C\Post::class, 'makePost']);
return Event::next;
}
public function onAppendCardProfile(array $vars, array &$res): EventResult
public function onAppendCardProfile(array $vars, array &$res): bool
{
$actor = Common::actor();
$group = $vars['actor'];

View File

@ -27,7 +27,6 @@ use App\Core\Event;
use App\Core\Modules\Plugin;
use App\Core\Router;
use App\Util\Common;
use EventResult;
use Plugin\Cover\Controller as C;
use Symfony\Component\HttpFoundation\Request;
@ -48,14 +47,14 @@ class Cover extends Plugin
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('settings_profile_cover', 'settings/cover', [Controller\Cover::class, 'coversettings']);
$r->connect('cover', '/cover', [Controller\Cover::class, 'cover']);
return Event::next;
}
public function onPopulateSettingsTabs(Request $request, string $section, &$tabs): EventResult
public function onPopulateSettingsTabs(Request $request, string $section, &$tabs)
{
if ($section === 'profile') {
$tabs[] = [
@ -73,7 +72,7 @@ class Cover extends Plugin
*
* @return bool hook value; true means continue processing, false means stop.
*
* public function onStartTwigPopulateVars(array &$vars): \EventResult
* public function onStartTwigPopulateVars(array &$vars): bool
* {
* if (Common::user() != null) {
* $cover = DB::find('cover', ['actor_id' => Common::user()->getId()]);
@ -93,7 +92,7 @@ class Cover extends Plugin
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onStartShowStyles(array &$styles): EventResult
public function onStartShowStyles(array &$styles): bool
{
$styles[] = 'assets/css/cover.css';
return Event::next;

View File

@ -34,7 +34,6 @@ use App\Entity\Note;
use App\Util\Common;
use App\Util\Exception\ClientException;
use DateTime;
use EventResult;
use Plugin\ActivityPub\Entity\ActivitypubActivity;
use Symfony\Component\HttpFoundation\Request;
@ -136,7 +135,7 @@ class DeleteNote extends NoteHandlerPlugin
*
* @return bool Event hook
*/
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r)
{
$r->connect(id: 'delete_note_action', uri_path: '/object/note/{note_id<\d+>}/delete', target: Controller\DeleteNote::class);
@ -155,7 +154,7 @@ class DeleteNote extends NoteHandlerPlugin
*
* @return bool Event hook
*/
public function onAddExtraNoteActions(Request $request, Note $note, array &$actions): EventResult
public function onAddExtraNoteActions(Request $request, Note $note, array &$actions)
{
if (\is_null($actor = Common::actor())) {
return Event::next;
@ -228,7 +227,7 @@ class DeleteNote extends NoteHandlerPlugin
*
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
*/
public function onNewActivityPubActivity(Actor $actor, AbstractObject $type_activity, AbstractObject $type_object, ?ActivitypubActivity &$ap_act): EventResult
public function onNewActivityPubActivity(Actor $actor, AbstractObject $type_activity, AbstractObject $type_object, ?ActivitypubActivity &$ap_act): bool
{
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
}
@ -243,7 +242,7 @@ class DeleteNote extends NoteHandlerPlugin
*
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
*/
public function onNewActivityPubActivityWithObject(Actor $actor, AbstractObject $type_activity, mixed $type_object, ?ActivitypubActivity &$ap_act): EventResult
public function onNewActivityPubActivityWithObject(Actor $actor, AbstractObject $type_activity, mixed $type_object, ?ActivitypubActivity &$ap_act): bool
{
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
}
@ -256,7 +255,7 @@ class DeleteNote extends NoteHandlerPlugin
*
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
*/
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): EventResult
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
{
if ($verb === 'delete') {
$gs_verb_to_activity_stream_two_verb = 'Delete';

View File

@ -31,7 +31,6 @@ use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException;
use App\Util\Formatting;
use Component\Group\Controller as ComponentGroupController;
use EventResult;
use Symfony\Component\HttpFoundation\Request;
class Directory extends Plugin
@ -41,7 +40,7 @@ class Directory extends Plugin
*
* @return bool
*/
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r)
{
$r->connect('directory_people', '/directory/people', [Controller\Directory::class, 'people']);
$r->connect('directory_groups', '/directory/groups', [Controller\Directory::class, 'groups']);
@ -56,7 +55,7 @@ class Directory extends Plugin
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onAddMainNavigationItem(array $vars, array &$res): EventResult
public function onAddMainNavigationItem(array $vars, array &$res): bool
{
$res[] = ['title' => 'People', 'path' => Router::url($path_id = 'directory_people', []), 'path_id' => $path_id];
$res[] = ['title' => 'Groups', 'path' => Router::url($path_id = 'directory_groups', []), 'path_id' => $path_id];
@ -73,7 +72,7 @@ class Directory extends Plugin
*
* @return bool EventHook
*/
public function onPrependActorsCollection(Request $request, array &$elements): EventResult
public function onPrependActorsCollection(Request $request, array &$elements): bool
{
if (\is_null($actor = Common::actor())) {
return Event::next;

View File

@ -36,11 +36,10 @@ namespace Plugin\EmailNotifications;
use App\Core\Event;
use App\Core\Modules\Plugin;
use EventResult;
class EmailNotifications extends Plugin
{
public function onAddNotificationTransport(&$form_defs): EventResult
public function onAddNotificationTransport(&$form_defs): bool
{
$form_defs['Email'] = $form_defs['placeholder'];
$form_defs['Email'][] = $form_defs['placeholder']['save']('Email', 'save_email');

View File

@ -57,7 +57,6 @@ use App\Util\TemporaryFile;
use Component\Attachment\Entity\Attachment;
use Component\Link\Entity\Link;
use Embed\Embed as LibEmbed;
use EventResult;
use Exception;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
@ -112,7 +111,7 @@ class Embed extends Plugin
*
* @throws Exception
*/
public function onAddRoute(Router $m): EventResult
public function onAddRoute(Router $m): bool
{
$m->connect('oembed', 'main/oembed', Controller\OEmbed::class);
return Event::next;
@ -121,7 +120,7 @@ class Embed extends Plugin
/**
* Insert oembed and opengraph tags in all HTML head elements
*/
public function onShowHeadElements(Request $request, array &$result): EventResult
public function onShowHeadElements(Request $request, array &$result): bool
{
$matches = [];
preg_match(',/?([^/]+)/?(.*),', $request->getPathInfo(), $matches);
@ -147,7 +146,7 @@ class Embed extends Plugin
/**
* Show this attachment enhanced with the corresponding Embed data, if available
*/
public function onViewLink(array $vars, array &$res): EventResult
public function onViewLink(array $vars, array &$res): bool
{
$link = $vars['link'];
try {
@ -178,7 +177,7 @@ class Embed extends Plugin
*
* @throws DuplicateFoundException
*/
public function onNewLinkFromNote(Link $link, Note $note): EventResult
public function onNewLinkFromNote(Link $link, Note $note): bool
{
// Only handle text mime
$mimetype = $link->getMimetype();
@ -369,7 +368,7 @@ class Embed extends Plugin
return HTTPClient::get($url)->getContent();
}
public function onAttachmentGetBestTitle(Attachment $attachment, Note $note, ?string &$title): EventResult
public function onAttachmentGetBestTitle(Attachment $attachment, Note $note, ?string &$title)
{
try {
$embed = DB::findOneBy('attachment_embed', ['attachment_id' => $attachment->getId()]);
@ -390,7 +389,7 @@ class Embed extends Plugin
*
* @return bool true hook value
*/
public function onPluginVersion(array &$versions): EventResult
public function onPluginVersion(array &$versions): bool
{
$versions[] = [
'name' => 'Embed',

View File

@ -45,7 +45,6 @@ use App\Util\Common;
use App\Util\Nickname;
use Component\Notification\Entity\Attention;
use DateTime;
use EventResult;
use Plugin\Favourite\Entity\NoteFavourite;
use Symfony\Component\HttpFoundation\Request;
@ -126,7 +125,7 @@ class Favourite extends NoteHandlerPlugin
*
* @return bool Event hook, Event::next (true) is returned to allow Event to be handled by other handlers
*/
public function onAddNoteActions(Request $request, Note $note, array &$actions): EventResult
public function onAddNoteActions(Request $request, Note $note, array &$actions): bool
{
if (\is_null($user = Common::user())) {
return Event::next;
@ -172,7 +171,7 @@ class Favourite extends NoteHandlerPlugin
*
* @return bool Event hook, Event::next (true) is returned to allow Event to be handled by other handlers
*/
public function onAppendCardNote(array $vars, array &$result): EventResult
public function onAppendCardNote(array $vars, array &$result): bool
{
// If note is the original and user isn't the one who repeated, append on end "user repeated this"
// If user is the one who repeated, append on end "you repeated this, remove repeat?"
@ -198,7 +197,7 @@ class Favourite extends NoteHandlerPlugin
/**
* Deletes every favourite entity in table related to a deleted Note
*/
public function onNoteDeleteRelated(Note &$note, Actor $actor): EventResult
public function onNoteDeleteRelated(Note &$note, Actor $actor): bool
{
$note_favourites_list = NoteFavourite::getNoteFavourites($note);
foreach ($note_favourites_list as $favourite_entity) {
@ -211,7 +210,7 @@ class Favourite extends NoteHandlerPlugin
/**
* Maps Routes to their respective Controllers
*/
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
// Add/remove note to/from favourites
$r->connect(id: 'favourite_add', uri_path: '/object/note/{id<\d+>}/favour', target: [Controller\Favourite::class, 'favouriteAddNote']);
@ -234,7 +233,7 @@ class Favourite extends NoteHandlerPlugin
*
* @throws \App\Util\Exception\ServerException
*/
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): EventResult
public function onCreateDefaultFeeds(int $actor_id, LocalUser $user, int &$ordering): bool
{
DB::persist(Feed::create([
'actor_id' => $actor_id,
@ -330,7 +329,7 @@ class Favourite extends NoteHandlerPlugin
return Event::stop;
}
public function onActivityPubNewNotification(Actor $sender, Activity $activity, array $targets, ?string $reason = null): EventResult
public function onActivityPubNewNotification(Actor $sender, Activity $activity, array $targets, ?string $reason = null): bool
{
switch ($activity->getVerb()) {
case 'favourite':
@ -367,7 +366,7 @@ class Favourite extends NoteHandlerPlugin
*
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
*/
public function onNewActivityPubActivity(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, \ActivityPhp\Type\AbstractObject $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): EventResult
public function onNewActivityPubActivity(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, \ActivityPhp\Type\AbstractObject $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
{
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
}
@ -391,7 +390,7 @@ class Favourite extends NoteHandlerPlugin
*
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
*/
public function onNewActivityPubActivityWithObject(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, mixed $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): EventResult
public function onNewActivityPubActivityWithObject(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, mixed $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
{
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
}
@ -404,7 +403,7 @@ class Favourite extends NoteHandlerPlugin
*
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
*/
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): EventResult
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
{
if ($verb === 'favourite') {
$gs_verb_to_activity_stream_two_verb = 'Like';

View File

@ -31,7 +31,6 @@ use App\Core\Modules\Plugin;
use App\Util\Common;
use App\Util\Exception\ClientException;
use App\Util\Exception\ServerException;
use EventResult;
/**
* Check attachment file size quotas
@ -58,7 +57,7 @@ class FileQuota extends Plugin
* @throws ClientException
* @throws ServerException
*/
public function onEnforceUserFileQuota(int $filesize, int $user_id): EventResult
public function onEnforceUserFileQuota(int $filesize, int $user_id): bool
{
$query = <<<'END'
select sum(at.size) as total
@ -105,7 +104,7 @@ class FileQuota extends Plugin
*
* @return bool true hook value
*/
public function onPluginVersion(array &$versions): EventResult
public function onPluginVersion(array &$versions): bool
{
$versions[] = [
'name' => 'FileQuota',

View File

@ -32,7 +32,6 @@ use App\Util\Exception\ServerException;
use App\Util\Exception\TemporaryFileException;
use App\Util\Formatting;
use App\Util\TemporaryFile;
use EventResult;
use Exception;
use Jcupitt\Vips;
use SplFileInfo;
@ -60,7 +59,7 @@ class ImageEncoder extends Plugin
return GSFile::mimetypeMajor($mimetype) === 'image';
}
public function onFileMetaAvailable(array &$event_map, string $mimetype): EventResult
public function onFileMetaAvailable(array &$event_map, string $mimetype): bool
{
if (!self::shouldHandle($mimetype)) {
return Event::next;
@ -69,7 +68,7 @@ class ImageEncoder extends Plugin
return Event::next;
}
public function onFileSanitizerAvailable(array &$event_map, string $mimetype): EventResult
public function onFileSanitizerAvailable(array &$event_map, string $mimetype): bool
{
if (!self::shouldHandle($mimetype)) {
return Event::next;
@ -78,7 +77,7 @@ class ImageEncoder extends Plugin
return Event::next;
}
public function onFileResizerAvailable(array &$event_map, string $mimetype): EventResult
public function onFileResizerAvailable(array &$event_map, string $mimetype): bool
{
if (!self::shouldHandle($mimetype)) {
return Event::next;
@ -180,7 +179,7 @@ class ImageEncoder extends Plugin
/**
* Generates the view for attachments of type Image
*/
public function onViewAttachment(array $vars, array &$res): EventResult
public function onViewAttachment(array $vars, array &$res): bool
{
if (!self::shouldHandle($vars['attachment']->getMimetype())) {
return Event::next;
@ -261,7 +260,7 @@ class ImageEncoder extends Plugin
*
* @return bool true hook value
*/
public function onPluginVersion(array &$versions): EventResult
public function onPluginVersion(array &$versions): bool
{
$versions[] = [
'name' => 'ImageEncoder',

View File

@ -33,18 +33,17 @@ namespace Plugin\LatexNotes;
use App\Core\Event;
use App\Core\Modules\Plugin;
use EventResult;
use PhpLatex_Parser;
use PhpLatex_Renderer_Html;
class LatexNotes extends Plugin
{
public function onPostingAvailableContentTypes(array &$types): EventResult
public function onPostingAvailableContentTypes(array &$types): bool
{
$types['LaTeX'] = 'application/x-latex';
return Event::next;
}
public function onRenderNoteContent($content, $content_type, &$rendered): EventResult
public function onRenderNoteContent($content, $content_type, &$rendered): bool
{
if ($content_type !== 'application/x-latex') {
return Event::next;

View File

@ -33,17 +33,16 @@ namespace Plugin\MarkdownNotes;
use App\Core\Event;
use App\Core\Modules\Plugin;
use EventResult;
use Parsedown;
class MarkdownNotes extends Plugin
{
public function onPostingAvailableContentTypes(array &$types): EventResult
public function onPostingAvailableContentTypes(array &$types): bool
{
$types['Markdown'] = 'text/markdown';
return Event::next;
}
public function onRenderNoteContent($content, $content_type, &$rendered): EventResult
public function onRenderNoteContent($content, $content_type, &$rendered): bool
{
if ($content_type !== 'text/markdown') {
return Event::next;

View File

@ -40,7 +40,6 @@ use App\Util\Exception\BugFoundException;
use App\Util\Exception\ClientException;
use App\Util\Formatting;
use App\Util\Functional as GSF;
use EventResult;
use Functional as F;
use Symfony\Component\HttpFoundation\Request;
@ -95,7 +94,7 @@ class NoteTypeFeedFilter extends Plugin
*
* Includes if any positive type matches, but removes if any negated matches
*/
public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): EventResult
public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): bool
{
$types = $this->normalizeTypesList(\is_null($request->get('note-types')) ? [] : explode(',', $request->get('note-types')));
$notes = F\select(
@ -109,7 +108,7 @@ class NoteTypeFeedFilter extends Plugin
$include = false;
foreach ($types as $type) {
$is_negate = $type[0] === '!';
$type = Formatting::removePrefix($type, '!');
$type = Formatting::removePrefix($type, '!');
switch ($type) {
case 'text':
$ret = !\is_null($note->getContent());
@ -140,7 +139,7 @@ class NoteTypeFeedFilter extends Plugin
/**
* Draw the media feed navigation.
*/
public function onAddFeedActions(Request $request, bool $is_not_empty, &$res): EventResult
public function onAddFeedActions(Request $request, bool $is_not_empty, &$res): bool
{
$qs = [];
$query_string = $request->getQueryString();
@ -185,7 +184,7 @@ class NoteTypeFeedFilter extends Plugin
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onEndShowStyles(array &$styles, string $route): EventResult
public function onEndShowStyles(array &$styles, string $route): bool
{
$styles[] = 'plugins/NoteTypeFeedFilter/assets/css/noteTypeFeedFilter.css';
return Event::next;

View File

@ -38,7 +38,6 @@ use App\Core\Modules\Plugin;
use App\Core\Router;
use App\Util\Common;
use DateInterval;
use EventResult;
use Exception;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\CryptKey;
@ -68,7 +67,7 @@ class OAuth2 extends Plugin
/**
* @throws Exception
*/
public function onInitializePlugin(): EventResult
public function onInitializePlugin()
{
self::$authorization_server = new AuthorizationServer(
new Repository\Client,
@ -87,7 +86,6 @@ class OAuth2 extends Plugin
),
new DateInterval('PT1H'),
);
return Event::next;
}
/**
@ -96,7 +94,7 @@ class OAuth2 extends Plugin
*
* @param Router $r the router that was initialized
*/
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('oauth2_mastodon_api_apps', '/api/v1/apps', C\Client::class, ['http-methods' => ['POST']]);
$r->connect('oauth2_client', '/oauth/client', C\Client::class, ['http-methods' => ['POST']]);
@ -105,7 +103,7 @@ class OAuth2 extends Plugin
return Event::next;
}
public function onEndHostMetaLinks(array &$links): EventResult
public function onEndHostMetaLinks(array &$links): bool
{
$links[] = new XML_XRD_Element_Link(self::OAUTH_REQUEST_TOKEN_REL, Router::url('oauth2_client', type: Router::ABSOLUTE_URL));
$links[] = new XML_XRD_Element_Link(self::OAUTH_AUTHORIZE_REL, Router::url('oauth2_authorize', type: Router::ABSOLUTE_URL));

View File

@ -32,7 +32,6 @@ use App\Util\Common;
use App\Util\Exception\NotFoundException;
use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException;
use EventResult;
use Plugin\Oomox\Controller as C;
use Symfony\Component\HttpFoundation\Request;
@ -51,7 +50,7 @@ class Oomox extends Plugin
/**
* Maps Routes to their respective Controllers
*/
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('oomox_settings', 'settings/oomox', [Controller\Oomox::class, 'oomoxSettings']);
$r->connect('oomox_css', 'plugins/oomox/colours', [Controller\Oomox::class, 'oomoxCSS']);
@ -66,7 +65,7 @@ class Oomox extends Plugin
* @throws RedirectException
* @throws ServerException
*/
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool
{
if ($section === 'colours') {
$tabs[] = [
@ -109,7 +108,7 @@ class Oomox extends Plugin
/**
* Adds to array $styles the generated CSS according to user settings, if any are present.
*/
public function onEndShowStyles(array &$styles, string $route): EventResult
public function onEndShowStyles(array &$styles, string $route): bool
{
$user = Common::user();
if ($user && Cache::get(self::cacheKey($user), static fn () => self::getEntity($user))) {

View File

@ -393,26 +393,21 @@ class APIv1 extends Controller
$user = $check;
}
// Convert the list of all tags to a map from canon to
// variations (i.e. tags that canonicalize to the same)
$canon_to_variations = [];
$tags_freq = [];
foreach ($user->getActor()->getNoteTags(Pin::note_type) as $tag) {
if (!isset($canon_to_variations[$tag->getCanonical()])) {
$canon_to_variations[$tag->getCanonical()] = [];
if (!isset($tags_freq[$tag->getCanonical()])) {
$tags_freq[$tag->getCanonical()] = [];
}
$canon_to_variations[$tag->getCanonical()][] = $tag->getTag();
$tags_freq[$tag->getCanonical()][] = $tag->getTag();
}
// Pick the most common variation and assign to it the count
// of all the variations of each canon tag
$most_common_variant_frequencies = [];
foreach ($canon_to_variations as $variations) {
foreach ($tags_freq as $canon => $variations) {
$freqs = array_count_values($variations);
arsort($freqs);
$most_common_variant_frequencies[array_key_first($freqs)] = \count($variations);
$tags_freq[$canon] = $freqs[array_key_first($freqs)];
}
return self::respond($most_common_variant_frequencies);
return self::respond($tags_freq);
}
public function unimplmented(Request $request)

View File

@ -35,7 +35,6 @@ namespace Plugin\Pinboard;
use App\Core\Event;
use App\Core\Modules\Plugin;
use App\Core\Router;
use EventResult;
use Plugin\Pinboard\Controller as C;
use Symfony\Component\HttpFoundation\Request;
@ -43,7 +42,7 @@ class Pinboard extends Plugin
{
public const controller_route = 'pinboard_settings';
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect(self::controller_route, '/pinboard/settings', C\Settings::class, options: ['method' => 'post']);
@ -69,7 +68,7 @@ class Pinboard extends Plugin
return Event::next;
}
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool
{
if ($section === 'api') {
$tabs[] = [

View File

@ -46,15 +46,14 @@ use Doctrine\Common\Collections\ExpressionBuilder;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\QueryBuilder;
use EventResult;
use Plugin\PinnedNotes\Controller as C;
use Plugin\PinnedNotes\Entity as E;
use Symfony\Component\HttpFoundation\Request;
class PinnedNotes extends Plugin
{
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
// Pin and unpin notes
$r->connect(id: 'toggle_note_pin', uri_path: '/object/note/{id<\d+>}/pin', target: [C\PinnedNotes::class, 'togglePin']);
@ -74,7 +73,7 @@ class PinnedNotes extends Plugin
return Event::next;
}
public function onBeforeFeed(Request $request, &$res): EventResult
public function onBeforeFeed(Request $request, &$res): bool
{
$path = $request->attributes->get('_route');
if ($path === 'actor_view_nickname') {
@ -93,7 +92,7 @@ class PinnedNotes extends Plugin
return Event::next;
}
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): EventResult
public function onCollectionQueryAddJoins(QueryBuilder &$note_qb, QueryBuilder &$actor_qb): bool
{
if (!\in_array('pinned_notes', $note_qb->getAllAliases())) {
$note_qb->leftJoin(E\PinnedNotes::class, 'pinned_notes', Expr\Join::WITH, 'note.id = pinned_notes.note_id');
@ -101,7 +100,7 @@ class PinnedNotes extends Plugin
return Event::next;
}
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $language, ?Actor $actor, &$note_expr, &$actor_expr): EventResult
public function onCollectionQueryCreateExpression(ExpressionBuilder $eb, string $term, ?string $language, ?Actor $actor, &$note_expr, &$actor_expr): bool
{
if ($term === 'pinned:true') {
$note_expr = $eb->neq('pinned_notes', null);
@ -115,7 +114,7 @@ class PinnedNotes extends Plugin
return Event::next;
}
public function onAddNoteActions(Request $request, Note $note, array &$actions): EventResult
public function onAddNoteActions(Request $request, Note $note, array &$actions): bool
{
$user = Common::user();
if ($user->getId() !== $note->getActorId()) {
@ -140,7 +139,7 @@ class PinnedNotes extends Plugin
return Event::next;
}
public function onEndShowStyles(array &$styles, string $route): EventResult
public function onEndShowStyles(array &$styles, string $route): bool
{
$styles[] = 'plugins/PinnedNotes/assets/css/pinned-notes.css';
return Event::next;
@ -148,7 +147,7 @@ class PinnedNotes extends Plugin
// Activity Pub handling stuff
public function onActivityStreamsTwoContext(array &$activity_streams_two_context): EventResult
public function onActivityStreamsTwoContext(array &$activity_streams_two_context): bool
{
$activity_streams_two_context[] = ['toot' => 'http://joinmastodon.org/ns#'];
$activity_streams_two_context[] = [
@ -160,7 +159,7 @@ class PinnedNotes extends Plugin
return Event::next;
}
public function onActivityPubAddActivityStreamsTwoData(string $type_name, &$type): EventResult
public function onActivityPubAddActivityStreamsTwoData(string $type_name, &$type): bool
{
if ($type_name === 'Person') {
$actor = \Plugin\ActivityPub\Util\Explorer::getOneFromUri($type->get('id'));

View File

@ -34,7 +34,6 @@ use App\Util\Exception\InvalidFormException;
use App\Util\Exception\NotFoundException;
use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException;
use EventResult;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
@ -58,7 +57,7 @@ class Poll extends NoteHandlerPlugin
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('newpoll', 'main/poll/new/{num<\\d+>?3}', [Controller\NewPoll::class, 'newpoll']);
@ -70,7 +69,7 @@ class Poll extends NoteHandlerPlugin
*
* @return bool hook value; true means continue processing, false means stop.
*
* public function onStartTwigPopulateVars(array &$vars): \EventResult
* public function onStartTwigPopulateVars(array &$vars): bool
* {
* $vars['tabs'][] = ['title' => 'Poll',
* 'href' => 'newpoll',
@ -85,7 +84,7 @@ class Poll extends NoteHandlerPlugin
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onStartShowStyles(array &$styles): EventResult
public function onStartShowStyles(array &$styles): bool
{
$styles[] = 'poll/poll.css';
return Event::next;
@ -103,7 +102,7 @@ class Poll extends NoteHandlerPlugin
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onShowNoteContent(Request $request, Note $note, array &$otherContent): EventResult
public function onShowNoteContent(Request $request, Note $note, array &$otherContent): bool
{
$responses = null;
$formView = null;

View File

@ -30,7 +30,6 @@ use App\Core\Router;
use App\Util\Exception\RedirectException;
use App\Util\Exception\ServerException;
use App\Util\Formatting;
use EventResult;
use Plugin\ProfileColor\Controller as C;
use Symfony\Component\HttpFoundation\Request;
@ -52,7 +51,7 @@ class ProfileColor extends Plugin
*
* @return bool hook value; true means continue processing, false means stop
*/
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
$r->connect('settings_profile_color', 'settings/color', [Controller\ProfileColor::class, 'profileColorSettings']);
return Event::next;
@ -62,7 +61,7 @@ class ProfileColor extends Plugin
* @throws RedirectException
* @throws ServerException
*/
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool
{
if ($section === 'colours') {
$tabs[] = [
@ -78,7 +77,7 @@ class ProfileColor extends Plugin
/**
* Renders profileColorView, which changes the background color of that profile.
*/
public function onAppendCardProfile(array $vars, array &$res): EventResult
public function onAppendCardProfile(array $vars, array &$res): bool
{
$actor = $vars['actor'];
if ($actor !== null) {

View File

@ -27,7 +27,6 @@ use App\Core\Event;
use App\Core\Modules\Plugin;
use Component\Circle\Entity\ActorTag;
use Component\Tag\Entity\NoteTag;
use EventResult;
use Symfony\Component\HttpFoundation\Request;
class RelatedTags extends Plugin
@ -35,7 +34,7 @@ class RelatedTags extends Plugin
/**
* Add a pinnned block containing tags related to the current page, be it note tags or actor tags
*/
public function onAddPinnedFeedContent(Request $request, array &$pinned): EventResult
public function onAddPinnedFeedContent(Request $request, array &$pinned)
{
// Lets not use language, probably wouldn't make it more helpful
//$locale = $request->attributes->get('locale');

View File

@ -45,7 +45,6 @@ use Component\Language\Entity\Language;
use Component\Notification\Entity\Attention;
use Component\Posting\Posting;
use DateTime;
use EventResult;
use Plugin\RepeatNote\Entity\NoteRepeat as RepeatEntity;
use const SORT_REGULAR;
use Symfony\Component\HttpFoundation\Request;
@ -212,7 +211,7 @@ class RepeatNote extends NoteHandlerPlugin
*
* @return bool Event hook, Event::next (true) is returned to allow Event to be handled by other handlers
*/
public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): EventResult
public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): bool
{
// Replaces repeat with original note on Actor feed
// it's pretty cool
@ -237,7 +236,7 @@ class RepeatNote extends NoteHandlerPlugin
*
* @return bool Event hook, Event::next (true) is returned to allow Event to be handled by other handlers
*/
public function onAddNoteActions(Request $request, Note $note, array &$actions): EventResult
public function onAddNoteActions(Request $request, Note $note, array &$actions): bool
{
// Only logged users can repeat notes
if (\is_null($user = Common::user())) {
@ -281,7 +280,7 @@ class RepeatNote extends NoteHandlerPlugin
*
* @return bool Event hook, Event::next (true) is returned to allow Event to be handled by other handlers
*/
public function onAppendCardNote(array $vars, array &$result): EventResult
public function onAppendCardNote(array $vars, array &$result)
{
// If note is the original and user isn't the one who repeated, append on end "user repeated this"
// If user is the one who repeated, append on end "you repeated this, remove repeat?"
@ -319,7 +318,7 @@ class RepeatNote extends NoteHandlerPlugin
*
* @return bool Event hook, Event::next (true) is returned to allow Event to be handled by other handlers
*/
public function onNoteDeleteRelated(Note &$note, Actor $actor): EventResult
public function onNoteDeleteRelated(Note &$note, Actor $actor): bool
{
$note_repeats_list = RepeatEntity::getNoteRepeats($note);
foreach ($note_repeats_list as $note_repeat) {
@ -341,7 +340,7 @@ class RepeatNote extends NoteHandlerPlugin
*
* @return bool Event hook, Event::next (true) is returned to allow Event to be handled by other handlers
*/
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r): bool
{
// Add/remove note to/from repeats
$r->connect(id: 'repeat_add', uri_path: '/object/note/{note_id<\d+>}/repeat', target: [Controller\Repeat::class, 'repeatAddNote']);
@ -428,7 +427,7 @@ class RepeatNote extends NoteHandlerPlugin
return Event::stop;
}
public function onActivityPubNewNotification(Actor $sender, Activity $activity, array $targets, ?string $reason = null): EventResult
public function onActivityPubNewNotification(Actor $sender, Activity $activity, array $targets, ?string $reason = null): bool
{
switch ($activity->getVerb()) {
case 'repeat':
@ -466,7 +465,7 @@ class RepeatNote extends NoteHandlerPlugin
*
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
*/
public function onNewActivityPubActivity(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, \ActivityPhp\Type\AbstractObject $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): EventResult
public function onNewActivityPubActivity(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, \ActivityPhp\Type\AbstractObject $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
{
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
}
@ -491,7 +490,7 @@ class RepeatNote extends NoteHandlerPlugin
*
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
*/
public function onNewActivityPubActivityWithObject(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, mixed $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): EventResult
public function onNewActivityPubActivityWithObject(Actor $actor, \ActivityPhp\Type\AbstractObject $type_activity, mixed $type_object, ?\Plugin\ActivityPub\Entity\ActivitypubActivity &$ap_act): bool
{
return $this->activitypub_handler($actor, $type_activity, $type_object, $ap_act);
}
@ -504,7 +503,7 @@ class RepeatNote extends NoteHandlerPlugin
*
* @return bool Returns `Event::stop` if handled, `Event::next` otherwise
*/
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): EventResult
public function onGSVerbToActivityStreamsTwoActivityType(string $verb, ?string &$gs_verb_to_activity_stream_two_verb): bool
{
if ($verb === 'repeat') {
$gs_verb_to_activity_stream_two_verb = 'Announce';

View File

@ -25,13 +25,12 @@ namespace Plugin\StemWord;
use App\Core\Event;
use App\Core\Modules\Plugin;
use EventResult;
use Wamania\Snowball\NotFoundException;
use Wamania\Snowball\StemmerFactory;
class StemWord extends Plugin
{
public function onStemWord(string $language, string $word, ?string &$out): EventResult
public function onStemWord(string $language, string $word, ?string &$out)
{
$language = explode('_', $language)[0];
try {

View File

@ -37,7 +37,6 @@ use Component\Attachment\Entity\AttachmentThumbnail;
use Component\Attachment\Entity\AttachmentToLink;
use Component\Attachment\Entity\AttachmentToNote;
use Component\Link\Entity\Link;
use EventResult;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
@ -96,7 +95,7 @@ class StoreRemoteMedia extends Plugin
* @throws ServerException
* @throws TemporaryFileException
*/
public function onNewLinkFromNote(Link $link, Note $note): EventResult
public function onNewLinkFromNote(Link $link, Note $note): bool
{
// Embed is the plugin to handle these
if ($link->getMimetypeMajor() === 'text') {
@ -237,7 +236,7 @@ class StoreRemoteMedia extends Plugin
*
* @return bool true hook value
*/
public function onPluginVersion(array &$versions): EventResult
public function onPluginVersion(array &$versions): bool
{
$versions[] = [
'name' => 'StoreRemoteMedia',

View File

@ -34,7 +34,6 @@ use App\Entity\LocalUser;
use App\Entity\Note;
use Component\Tag\Entity\NoteTag;
use Component\Tag\Entity\NoteTagBlock;
use EventResult;
use Functional as F;
use Plugin\TagBasedFiltering\Controller as C;
use Symfony\Component\HttpFoundation\Request;
@ -52,14 +51,14 @@ class TagBasedFiltering extends Plugin
return ['note' => "blocked-note-tags-{$actor_id}", 'actor' => "blocked-actor-tags-{$actor_id}"];
}
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r)
{
$r->connect(id: self::NOTE_TAG_FILTER_ROUTE, uri_path: '/filter/edit-blocked-note-tags/{note_id<\d+>}', target: [Controller\AddBlocked::class, 'addBlockedNoteTags']);
$r->connect(id: self::ACTOR_TAG_FILTER_ROUTE, uri_path: '/filter/edit-blocked-actor-tags/{actor_id<\d+>}', target: [Controller\AddBlocked::class, 'addBlockedActorTags']);
return Event::next;
}
public function onAddExtraNoteActions(Request $request, Note $note, array &$actions): EventResult
public function onAddExtraNoteActions(Request $request, Note $note, array &$actions)
{
$actions[] = [
'title' => _m('Block note tags'),
@ -72,13 +71,12 @@ class TagBasedFiltering extends Plugin
'classes' => '',
'url' => Router::url(self::ACTOR_TAG_FILTER_ROUTE, ['actor_id' => $note->getActor()->getId()]),
];
return Event::next;
}
/**
* Filter out tags from notes or actors, per the user request
*/
public function onFilterNoteList(?Actor $actor, array &$notes, Request $request): EventResult
public function onFilterNoteList(?Actor $actor, array &$notes, Request $request)
{
if (\is_null($actor)) {
return Event::next;
@ -104,7 +102,7 @@ class TagBasedFiltering extends Plugin
return Event::next;
}
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool
{
if ($section === 'muting') {
$tabs[] = [

View File

@ -26,7 +26,6 @@ use App\Core\Modules\Plugin;
use App\Entity\Note;
use App\Util\Common;
use App\Util\Formatting;
use EventResult;
use Symfony\Component\HttpFoundation\Request;
class TreeNotes extends Plugin
@ -35,7 +34,7 @@ class TreeNotes extends Plugin
* Formatting notes without taking a direct reply out of context
* Show whole conversation in conversation related routes.
*/
public function onFormatNoteList(array $notes_in, array &$notes_out, Request $request): EventResult
public function onFormatNoteList(array $notes_in, array &$notes_out, Request $request)
{
if (str_starts_with($request->get('_route'), 'conversation')) {
$parents = $this->conversationFormat($notes_in);
@ -43,7 +42,6 @@ class TreeNotes extends Plugin
} else {
$notes_out = $this->feedFormatTree($notes_in);
}
return Event::stop;
}
/**
@ -124,7 +122,7 @@ class TreeNotes extends Plugin
];
}
public function onAppendNoteBlock(Request $request, array $conversation, array &$res): EventResult
public function onAppendNoteBlock(Request $request, array $conversation, array &$res): bool
{
if (\array_key_exists('replies', $conversation)) {
$res[] = Formatting::twigRenderFile(

View File

@ -36,7 +36,6 @@ use App\Core\DB;
use App\Core\Event;
use App\Core\Modules\Plugin;
use App\Entity\Actor;
use EventResult;
use Plugin\ActivityPub\Entity\ActivitypubActor;
use Plugin\UnboundGroup\Controller\GroupSettings;
use Plugin\UnboundGroup\Entity\activitypubGroupUnbound;
@ -50,7 +49,7 @@ use Symfony\Component\HttpFoundation\Request;
*/
class UnboundGroup extends Plugin
{
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool
{
if ($section === 'profile' && $request->get('_route') === 'group_actor_settings') {
$tabs[] = [
@ -69,7 +68,7 @@ class UnboundGroup extends Plugin
return Event::next;
}
public function onActivityStreamsTwoContext(array &$activity_streams_two_context): EventResult
public function onActivityStreamsTwoContext(array &$activity_streams_two_context): bool
{
$activity_streams_two_context[] = [
'unbound' => [
@ -80,7 +79,7 @@ class UnboundGroup extends Plugin
return Event::next;
}
public function onActivityPubAddActivityStreamsTwoData(string $type_name, &$type): EventResult
public function onActivityPubAddActivityStreamsTwoData(string $type_name, &$type): bool
{
if ($type_name === 'Group' || $type_name === 'Organization') {
$actor = \Plugin\ActivityPub\Util\Explorer::getOneFromUri($type->getId());
@ -93,7 +92,7 @@ class UnboundGroup extends Plugin
return Event::next;
}
public function onActivityPubCreateOrUpdateActor(\ActivityPhp\Type\AbstractObject $object, Actor $actor, ActivitypubActor $ap_actor): EventResult
public function onActivityPubCreateOrUpdateActor(\ActivityPhp\Type\AbstractObject $object, Actor $actor, ActivitypubActor $ap_actor): bool
{
if ($object->has('unbound')) {
$obj = DB::findOneBy(activitypubGroupUnbound::class, ['actor_id' => $actor->getId()], return_null: true);

View File

@ -42,7 +42,6 @@ use App\Util\Exception\ServerException;
use App\Util\Exception\TemporaryFileException;
use App\Util\Formatting;
use App\Util\TemporaryFile;
use EventResult;
use Exception;
use FFMpeg\FFMpeg as ffmpeg;
use FFMpeg\FFProbe as ffprobe;
@ -60,7 +59,7 @@ class VideoEncoder extends Plugin
return GSFile::mimetypeMajor($mimetype) === 'video' || $mimetype === 'image/gif';
}
public function onFileMetaAvailable(array &$event_map, string $mimetype): EventResult
public function onFileMetaAvailable(array &$event_map, string $mimetype): bool
{
if (!self::shouldHandle($mimetype)) {
return Event::next;
@ -70,7 +69,7 @@ class VideoEncoder extends Plugin
return Event::next;
}
public function onFileSanitizerAvailable(array &$event_map, string $mimetype): EventResult
public function onFileSanitizerAvailable(array &$event_map, string $mimetype): bool
{
if ($mimetype !== 'image/gif') {
return Event::next;
@ -80,7 +79,7 @@ class VideoEncoder extends Plugin
return Event::next;
}
public function onFileResizerAvailable(array &$event_map, string $mimetype): EventResult
public function onFileResizerAvailable(array &$event_map, string $mimetype): bool
{
if ($mimetype !== 'image/gif') {
return Event::next;
@ -140,7 +139,7 @@ class VideoEncoder extends Plugin
/**
* Generates the view for attachments of type Video
*/
public function onViewAttachment(array $vars, array &$res): EventResult
public function onViewAttachment(array $vars, array &$res): bool
{
if ($vars['attachment']->getMimetypeMajor() !== 'video') {
return Event::next;
@ -290,7 +289,7 @@ class VideoEncoder extends Plugin
/**
* @throws ServerException
*/
public function onPluginVersion(array &$versions): EventResult
public function onPluginVersion(array &$versions): bool
{
$versions[] = ['name' => 'FFmpeg',
'version' => self::version(),

View File

@ -33,7 +33,6 @@ use App\Entity\Actor;
use App\Entity\LocalUser;
use App\Util\Common;
use App\Util\Exception\ServerException;
use EventResult;
use Exception;
use Functional as F;
use Plugin\WebHooks\Controller as C;
@ -44,13 +43,12 @@ class WebHooks extends Plugin
{
public const controller_route = 'webhook';
public function onAddRoute(Router $r): EventResult
public function onAddRoute(Router $r)
{
$r->connect(self::controller_route, '/webhook-settings', C\WebHooks::class, options: ['method' => 'post']);
return EventResult::next;
}
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): EventResult
public function onPopulateSettingsTabs(Request $request, string $section, array &$tabs): bool
{
if ($section === 'api') {
$tabs[] = [
@ -71,7 +69,7 @@ class WebHooks extends Plugin
}
}
public function onNewNotificationEnd(Actor $sender, Activity $activity, array $effective_targets, ?string $reason): EventResult
public function onNewNotificationEnd(Actor $sender, Activity $activity, array $effective_targets, ?string $reason)
{
foreach ($effective_targets as $actor) {
$this->maybeEnqueue($actor, 'notifications', [$sender, $activity, $effective_targets, $reason]);
@ -79,7 +77,7 @@ class WebHooks extends Plugin
return Event::next;
}
public function onNewSubscriptionEnd(LocalUser|Actor $subscriber, Activity $activity, Actor $hook_target, ?string $reason): EventResult
public function onNewSubscriptionEnd(LocalUser|Actor $subscriber, Activity $activity, Actor $hook_target, ?string $reason)
{
$this->maybeEnqueue($hook_target, 'subscriptions', [$subscriber, $activity, $hook_target, $reason]);
return Event::next;
@ -88,7 +86,7 @@ class WebHooks extends Plugin
/**
* @param array<Actor $sender, Activity $activity, array $effective_targets, ?string $reason> $args
*/
public function onQueueWebhook(string $type, string $hook_target, Actor $actor, array $args): EventResult
public function onQueueWebhook(string $type, string $hook_target, Actor $actor, array $args)
{
switch ($type) {
case 'notifications':

View File

@ -43,7 +43,6 @@ use App\Entity\LocalUser;
use App\Util\Common;
use App\Util\Exception\RedirectException;
use App\Util\Formatting;
use EventResult;
use Plugin\ActivityPub\Entity\ActivitypubActor;
use Plugin\WebMonetization\Entity\Wallet;
use Plugin\WebMonetization\Entity\WebMonetization as Monetization;
@ -53,7 +52,7 @@ use Symfony\Component\HttpFoundation\Request;
class WebMonetization extends Plugin
{
public function onAppendRightPanelBlock(Request $request, $vars, &$res): EventResult
public function onAppendRightPanelBlock(Request $request, $vars, &$res): bool
{
$user = Common::actor();
if (\is_null($user)) {
@ -210,7 +209,7 @@ class WebMonetization extends Plugin
];
}
public function onAppendToHead(Request $request, &$res): EventResult
public function onAppendToHead(Request $request, &$res): bool
{
$user = Common::user();
if (\is_null($user)) {
@ -242,7 +241,7 @@ class WebMonetization extends Plugin
return Event::next;
}
public function onActivityStreamsTwoContext(array &$activity_streams_two_context): EventResult
public function onActivityStreamsTwoContext(array &$activity_streams_two_context): bool
{
$activity_streams_two_context[] = [
'webmonetizationWallet' => [
@ -253,7 +252,7 @@ class WebMonetization extends Plugin
return Event::next;
}
public function onActivityPubAddActivityStreamsTwoData(string $type_name, &$type): EventResult
public function onActivityPubAddActivityStreamsTwoData(string $type_name, &$type): bool
{
if ($type_name === 'Person') {
$actor = \Plugin\ActivityPub\Util\Explorer::getOneFromUri($type->getId());
@ -266,7 +265,7 @@ class WebMonetization extends Plugin
return Event::next;
}
public function onActivityPubCreateOrUpdateActor(\ActivityPhp\Type\AbstractObject $object, Actor $actor, ActivitypubActor $ap_actor): EventResult
public function onActivityPubCreateOrUpdateActor(\ActivityPhp\Type\AbstractObject $object, Actor $actor, ActivitypubActor $ap_actor): bool
{
if ($object->has('webmonetizationWallet')) {
$attr = ['actor_id' => $actor->getId(), 'address' => $object->get('webmonetizationWallet')];

View File

@ -36,11 +36,10 @@ namespace Plugin\XMPPNotifications;
use App\Core\Event;
use App\Core\Modules\Plugin;
use EventResult;
class XMPPNotifications extends Plugin
{
public function onAddNotificationTransport(&$form_defs): EventResult
public function onAddNotificationTransport(&$form_defs): bool
{
$form_defs['XMPP'] = $form_defs['placeholder'];
$form_defs['XMPP'][] = $form_defs['placeholder']['save']('XMPP', 'save_xmpp');

View File

@ -33,7 +33,7 @@ declare(strict_types = 1);
use App\CacheKernel;
use App\Kernel;
use App\Core\Security;
use App\Util\Formatting;
use Symfony\Component\ErrorHandler\Debug;
use Symfony\Component\HttpFoundation\Request;
@ -70,9 +70,11 @@ if ('prod' === $kernel->getEnvironment() || isset($_ENV['CONFIG_USE_CACHE_KERNEL
}
$request = Request::createFromGlobals();
Security::harden();
$_ENV = array_filter(
$_ENV,
fn (string $key) => Formatting::startsWith($key, ['HTTP', 'APP', 'CONFIG']) && $key !== 'APP_SECRET',
\ARRAY_FILTER_USE_KEY,
);
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

View File

@ -33,22 +33,20 @@ declare(strict_types = 1);
namespace App\Core;
use App\Core\Event\GSEvent;
use App\Util\Exception\BugFoundException;
use EventResult;
use ReflectionFunction;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\EventDispatcher\GenericEvent;
abstract class Event
{
/**
* Constants to be returned from event handlers
* Constants to be returned from event handlers, for increased clarity
*
* EventResult::stop - Stop other handlers from processing the event
* EventResult::next - Allow the other handlers to process the event
* bool stop - Stop other handlers from processing the event
* bool next - Allow the other handlers to process the event
*/
public const stop = EventResult::stop;
public const next = EventResult::next;
public const stop = false;
public const next = true;
private static EventDispatcherInterface $dispatcher;
@ -85,18 +83,20 @@ abstract class Event
): void {
self::$dispatcher->addListener(
$ns . $name,
function ($event, $event_name, $dispatcher) use ($handler) {
$result = $handler(...$event->getArguments());
if (\is_null($result) || !isset($result)) {
dd($handler, $event_name);
throw new BugFoundException("Events must return an \\EventResult, which a handler for {$event_name} does not");
function ($event, $event_name, $dispatcher) use ($handler, $name) {
// Old style of events (preferred)
if ($event instanceof GenericEvent) {
if ($handler(...$event->getArguments()) === self::stop) {
$event->stopPropagation();
}
return $event;
}
// @codeCoverageIgnoreStart
// Symfony style of events
Log::warning("Event::addHandler for {$name} doesn't Conform to GNU social guidelines. Use of this style of event is discouraged.");
$handler($event, $event_name, $dispatcher);
$event->setResult($result);
if ($result === EventResult::stop) {
$event->stopPropagation();
}
return $event;
// @codeCoverageIgnoreEnd
},
$priority,
);
@ -119,9 +119,9 @@ abstract class Event
* @return bool flag saying whether to continue processing, based
* on results of handlers
*/
public static function handle(string $name, array $args = [], string $ns = 'GNUsocial.'): EventResult
public static function handle(string $name, array $args = [], string $ns = 'GNUsocial.'): bool
{
return self::$dispatcher->dispatch(new GSEvent($name, $args), $ns . $name)->getResult();
return !(self::$dispatcher->dispatch(new GenericEvent($name, $args), $ns . $name)->isPropagationStopped());
}
/**

View File

@ -1,13 +0,0 @@
<?php
declare(strict_types = 1);
/**
* An event must return a value from this enum, which is in the global namespace as \EventResult
*/
enum EventResult
{
case stop;
case next;
case unhandled;
}

View File

@ -1,23 +0,0 @@
<?php
declare(strict_types = 1);
namespace App\Core\Event;
use EventResult;
use Symfony\Component\EventDispatcher\GenericEvent;
class GSEvent extends GenericEvent
{
protected mixed $result;
public function setResult(mixed $result): void
{
$this->result = $result;
}
public function getResult(): mixed
{
return $this->result ?? EventResult::next;
}
}

View File

@ -37,9 +37,8 @@ declare(strict_types = 1);
* @author Diogo Cordeiro <diogo@fc.up.pt>
*
* GNU social 3
* @author Diogo Cordeiro <mail@diogo.site>
* @author Hugo Sales <hugo@hsal.es>
* @copyright 2018-2022 Free Software Foundation, Inc http://www.fsf.org
* @copyright 2018-2021 Free Software Foundation, Inc http://www.fsf.org
* @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
*/

View File

@ -36,7 +36,6 @@ declare(strict_types = 1);
namespace App\Core;
use App\Kernel;
use App\Util\Exception\BugFoundException;
use App\Util\Formatting;
use AppendIterator;
use Exception;
@ -44,7 +43,6 @@ use FilesystemIterator;
use Functional as F;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use ReflectionMethod;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Resource\GlobResource;
use Symfony\Component\DependencyInjection\ContainerBuilder;
@ -87,15 +85,10 @@ class ModuleManager
get_class_methods($obj),
F\ary(F\partial_right('App\Util\Formatting::startsWith', 'on'), 1),
),
function (string $method) use ($obj) {
if (((string) (new ReflectionMethod($obj, $method))->getReturnType()) !== 'EventResult') {
$class = $obj::class;
dd("Return type of {$class}::{$method} is not the required EventResult");
throw new BugFoundException("Return type of {$class}::{$method} is not the required EventResult");
}
$event_name = mb_substr($method, 2);
$this->events[$event_name] ??= [];
$this->events[$event_name][] = [$obj, $method];
function (string $m) use ($obj) {
$ev = mb_substr($m, 2);
$this->events[$ev] ??= [];
$this->events[$ev][] = [$obj, $m];
},
);
}

View File

@ -22,7 +22,6 @@ declare(strict_types = 1);
namespace App\Core\Modules;
use App\Util\Common;
use EventResult;
/**
* Base class for all GNU social modules (plugins and components)
@ -65,23 +64,22 @@ abstract class Module
// ------- Module initialize and cleanup ----------
private function defer(string $cycle): EventResult
private function defer(string $cycle)
{
$type = ucfirst(static::MODULE_TYPE);
if (method_exists($this, $method = "on{$cycle}{$type}")) {
$this->{$method}();
}
return EventResult::next;
}
// Can't use __call or it won't be found by our event function finder
public function onInitializeModule(): EventResult
public function onInitializeModule()
{
return $this->defer('Initialize');
$this->defer('Initialize');
}
public function onCleanupModule(): EventResult
public function onCleanupModule()
{
return $this->defer('Cleanup');
$this->defer('Cleanup');
}
}

View File

@ -6,7 +6,6 @@ namespace App\Core\Modules;
use App\Core\Event;
use function App\Core\I18n\_m;
use EventResult;
/**
* TODO Plugins aren't tested yet
@ -22,7 +21,7 @@ abstract class Plugin extends Module
return GNUSOCIAL_BASE_VERSION;
}
public function onPluginVersion(array &$versions): EventResult
public function onPluginVersion(array &$versions): bool
{
$name = $this->name();

View File

@ -33,9 +33,7 @@ declare(strict_types = 1);
namespace App\Core;
use App\Entity\LocalUser;
use App\Util\Formatting;
use BadMethodCallException;
use Functional as F;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Security as SymfonySecurity;
use Symfony\Component\Security\Http\Event\LoginFailureEvent;
@ -78,32 +76,6 @@ class Security implements EventSubscriberInterface //implements AuthenticatorInt
];
}
/**
* Harden running instance. Called once from `index.php`
*/
public static function harden(): void
{
// Remove sensitive information from the
[$_ENV, $to_remove] = F\partition(
$_ENV,
fn ($_, string $key) => Formatting::startsWith($key, ['HTTP', 'APP', 'CONFIG']) && $key !== 'APP_SECRET',
);
F\each($to_remove, fn (mixed $value, string $key) => putenv($key)); // Unset
// Disable stream wrappers, that could be used in things like
// `file_get_contents('https://gnu.org')`. This is done
// because this is a unexpected feature for most developers,
// and some wrappers can be abused. For instance, `phar://`
// can be used to essentially override any class when such a
// file is opened and thus provide code execution to an
// attacker. Not a complete solution, since `file://`,
// `php://` and `glob://`, 'compress.zlib' (symfony profiler) get used _somewhere_, so we can't
// disable them
F\each(
['http', 'https', 'ftp', 'ftps', 'data', 'phar'], // Making this configurable might be a nice feature, but it's tricky because this happens before general initialization
fn (string $protocol) => stream_wrapper_unregister($protocol),
);
}
public static function __callStatic(string $name, array $args)
{
if (method_exists(self::$security, $name)) {