2020-08-04 11:25:22 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
namespace Config;
|
2020-05-27 18:46:16 +02:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
use App\Entities\Actor;
|
2021-08-13 11:07:29 +00:00
|
|
|
use App\Entities\Post;
|
2022-01-04 15:40:27 +00:00
|
|
|
use App\Models\EpisodeModel;
|
2023-02-22 16:29:45 +00:00
|
|
|
use CodeIgniter\Debug\Toolbar\Collectors\Database;
|
2020-05-27 18:46:16 +02:00
|
|
|
use CodeIgniter\Events\Events;
|
2021-04-02 17:20:02 +00:00
|
|
|
use CodeIgniter\Exceptions\FrameworkException;
|
2023-08-27 13:26:06 +00:00
|
|
|
use CodeIgniter\HotReloader\HotReloader;
|
2020-05-27 18:46:16 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* --------------------------------------------------------------------
|
|
|
|
* Application Events
|
|
|
|
* --------------------------------------------------------------------
|
|
|
|
* Events allow you to tap into the execution of the program without
|
|
|
|
* modifying or extending core files. This file provides a central
|
|
|
|
* location to define your events, though they can always be added
|
|
|
|
* at run-time, also, if needed.
|
|
|
|
*
|
|
|
|
* You create code that can execute by subscribing to events with
|
|
|
|
* the 'on()' method. This accepts any form of callable, including
|
|
|
|
* Closures, that will be executed when the event is triggered.
|
|
|
|
*
|
|
|
|
* Example:
|
|
|
|
* Events::on('create', [$myInstance, 'myMethod']);
|
|
|
|
*/
|
|
|
|
|
2023-09-23 14:27:40 +00:00
|
|
|
Events::on('pre_system', static function (): void {
|
2020-06-10 15:00:12 +00:00
|
|
|
if (ENVIRONMENT !== 'testing') {
|
2021-04-02 17:20:02 +00:00
|
|
|
if (ini_get('zlib.output_compression')) {
|
|
|
|
throw FrameworkException::forEnabledZlibOutputCompression();
|
2020-06-10 15:00:12 +00:00
|
|
|
}
|
2020-05-27 18:46:16 +02:00
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
while (ob_get_level() > 0) {
|
|
|
|
ob_end_flush();
|
|
|
|
}
|
|
|
|
|
2022-06-13 16:30:34 +00:00
|
|
|
ob_start(static fn ($buffer) => $buffer);
|
2020-06-10 15:00:12 +00:00
|
|
|
}
|
2020-05-27 18:46:16 +02:00
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
/*
|
|
|
|
* --------------------------------------------------------------------
|
|
|
|
* Debug Toolbar Listeners.
|
|
|
|
* --------------------------------------------------------------------
|
|
|
|
* If you delete, they will no longer be collected.
|
|
|
|
*/
|
2021-05-25 10:40:22 +00:00
|
|
|
if (CI_DEBUG && ! is_cli()) {
|
2023-02-22 16:29:45 +00:00
|
|
|
Events::on('DBQuery', Database::class . '::collect');
|
2020-06-10 15:00:12 +00:00
|
|
|
Services::toolbar()->respond();
|
2023-08-27 13:26:06 +00:00
|
|
|
|
|
|
|
// Hot Reload route - for framework use on the hot reloader.
|
|
|
|
if (ENVIRONMENT === 'development') {
|
|
|
|
Services::routes()->get('__hot-reload', static function (): void {
|
|
|
|
(new HotReloader())->run();
|
|
|
|
});
|
|
|
|
}
|
2020-06-10 15:00:12 +00:00
|
|
|
}
|
2020-05-27 18:46:16 +02:00
|
|
|
});
|
2021-04-02 17:20:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* --------------------------------------------------------------------
|
2021-08-27 10:58:22 +00:00
|
|
|
* Fediverse events
|
2021-04-02 17:20:02 +00:00
|
|
|
* --------------------------------------------------------------------
|
|
|
|
*/
|
2021-06-08 09:52:11 +00:00
|
|
|
/**
|
|
|
|
* @param Actor $actor
|
|
|
|
* @param Actor $targetActor
|
|
|
|
*/
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_follow', static function ($actor, $targetActor): void {
|
2021-06-08 09:52:11 +00:00
|
|
|
if ($actor->is_podcast) {
|
|
|
|
cache()
|
|
|
|
->deleteMatching("podcast#{$actor->podcast->id}*");
|
|
|
|
cache()
|
|
|
|
->deleteMatching("page_podcast#{$actor->podcast->id}*");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($targetActor->is_podcast) {
|
|
|
|
cache()
|
|
|
|
->deleteMatching("podcast#{$targetActor->podcast->id}*");
|
|
|
|
cache()
|
|
|
|
->deleteMatching("page_podcast#{$targetActor->podcast->id}*");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Actor $actor
|
|
|
|
* @param Actor $targetActor
|
|
|
|
*/
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_undo_follow', static function ($actor, $targetActor): void {
|
2021-06-08 09:52:11 +00:00
|
|
|
if ($actor->is_podcast) {
|
|
|
|
cache()
|
|
|
|
->deleteMatching("podcast#{$actor->podcast->id}*");
|
|
|
|
cache()
|
|
|
|
->deleteMatching("page_podcast#{$actor->podcast->id}*");
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($targetActor->is_podcast) {
|
|
|
|
cache()
|
|
|
|
->deleteMatching("podcast#{$targetActor->podcast->id}*");
|
|
|
|
cache()
|
|
|
|
->deleteMatching("page_podcast#{$targetActor->podcast->id}*");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
2021-08-13 11:07:29 +00:00
|
|
|
* @param Post $post
|
2021-06-08 09:52:11 +00:00
|
|
|
*/
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_post_add', static function ($post): void {
|
2022-07-21 13:53:29 +00:00
|
|
|
model(EpisodeModel::class, false)->builder()
|
|
|
|
->where('id', $post->episode_id)
|
|
|
|
->increment('posts_count');
|
2021-08-13 11:07:29 +00:00
|
|
|
if ($post->actor->is_podcast) {
|
2021-06-08 09:52:11 +00:00
|
|
|
// Removing all of the podcast pages is a bit overkill, but works to avoid caching bugs
|
|
|
|
// same for other events below
|
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
}
|
2021-04-02 17:20:02 +00:00
|
|
|
});
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
/**
|
2021-08-13 11:07:29 +00:00
|
|
|
* @param Post $post
|
2021-06-08 09:52:11 +00:00
|
|
|
*/
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_post_remove', static function ($post): void {
|
2021-08-13 11:07:29 +00:00
|
|
|
if ($episodeId = $post->episode_id) {
|
2022-06-13 16:30:34 +00:00
|
|
|
model(EpisodeModel::class, false)->builder()
|
2021-06-08 09:52:11 +00:00
|
|
|
->where('id', $episodeId)
|
2021-08-13 11:07:29 +00:00
|
|
|
->decrement('posts_count');
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
2021-04-22 17:20:28 +00:00
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
if ($post->actor->is_podcast) {
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_post#{$post->id}*");
|
2021-04-02 17:20:02 +00:00
|
|
|
});
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
/**
|
|
|
|
* @param Actor $actor
|
2021-08-13 11:07:29 +00:00
|
|
|
* @param Post $post
|
2021-06-08 09:52:11 +00:00
|
|
|
*/
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_post_reblog', static function ($actor, $post): void {
|
2021-08-13 11:07:29 +00:00
|
|
|
if ($post->actor->is_podcast) {
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($actor->is_podcast) {
|
|
|
|
cache()->deleteMatching("podcast#{$actor->podcast->id}*");
|
|
|
|
cache()
|
|
|
|
->deleteMatching("page_podcast#{$actor->podcast->id}*");
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_post#{$post->id}*");
|
|
|
|
if ($post->in_reply_to_id !== null) {
|
|
|
|
cache()->deleteMatching("page_post#{$post->in_reply_to_id}");
|
2021-04-22 17:20:28 +00:00
|
|
|
}
|
2021-04-02 17:20:02 +00:00
|
|
|
});
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
/**
|
2021-08-13 11:07:29 +00:00
|
|
|
* @param Post $reblogPost
|
2021-06-08 09:52:11 +00:00
|
|
|
*/
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_post_undo_reblog', static function ($reblogPost): void {
|
2021-08-13 11:07:29 +00:00
|
|
|
$post = $reblogPost->reblog_of_post;
|
|
|
|
if ($post->actor->is_podcast) {
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_post#{$post->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_post#{$reblogPost->id}*");
|
|
|
|
if ($post->in_reply_to_id !== null) {
|
|
|
|
cache()->deleteMatching("page_post#{$post->in_reply_to_id}");
|
2021-06-08 09:52:11 +00:00
|
|
|
}
|
2021-04-22 17:20:28 +00:00
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
if ($reblogPost->actor->is_podcast) {
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("podcast#{$reblogPost->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_podcast#{$reblogPost->actor->podcast->id}*");
|
2021-04-22 17:20:28 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
/**
|
2021-08-13 11:07:29 +00:00
|
|
|
* @param Post $reply
|
2021-06-08 09:52:11 +00:00
|
|
|
*/
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_post_reply', static function ($reply): void {
|
2021-08-13 11:07:29 +00:00
|
|
|
$post = $reply->reply_to_post;
|
2022-07-21 16:21:26 +00:00
|
|
|
if ($post->in_reply_to_id === null) {
|
|
|
|
model(EpisodeModel::class, false)->builder()
|
|
|
|
->where('id', $post->episode_id)
|
|
|
|
->increment('comments_count');
|
|
|
|
}
|
2022-07-21 13:53:29 +00:00
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
if ($post->actor->is_podcast) {
|
2022-07-21 16:21:26 +00:00
|
|
|
cache()
|
|
|
|
->deleteMatching("podcast-{$post->actor->podcast->handle}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_post#{$post->id}*");
|
2021-04-22 17:20:28 +00:00
|
|
|
});
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
/**
|
2021-08-13 11:07:29 +00:00
|
|
|
* @param Post $reply
|
2021-06-08 09:52:11 +00:00
|
|
|
*/
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_reply_remove', static function ($reply): void {
|
2021-08-13 11:07:29 +00:00
|
|
|
$post = $reply->reply_to_post;
|
2022-07-21 16:21:26 +00:00
|
|
|
if ($post->in_reply_to_id === null) {
|
|
|
|
model(EpisodeModel::class, false)->builder()
|
|
|
|
->where('id', $post->episode_id)
|
|
|
|
->decrement('comments_count');
|
|
|
|
}
|
2022-07-21 13:53:29 +00:00
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
if ($post->actor->is_podcast) {
|
2022-07-21 16:21:26 +00:00
|
|
|
cache()
|
|
|
|
->deleteMatching("podcast-{$post->actor->podcast->handle}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_post#{$post->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_post#{$reply->id}*");
|
2021-04-02 17:20:02 +00:00
|
|
|
});
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
/**
|
|
|
|
* @param Actor $actor
|
2021-08-13 11:07:29 +00:00
|
|
|
* @param Post $post
|
2021-06-08 09:52:11 +00:00
|
|
|
*/
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_post_favourite', static function ($actor, $post): void {
|
2021-08-13 11:07:29 +00:00
|
|
|
if ($post->actor->is_podcast) {
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_post#{$post->id}*");
|
|
|
|
if ($post->in_reply_to_id !== null) {
|
|
|
|
cache()->deleteMatching("page_post#{$post->in_reply_to_id}*");
|
2021-04-22 17:20:28 +00:00
|
|
|
}
|
2021-06-08 09:52:11 +00:00
|
|
|
|
|
|
|
if ($actor->is_podcast) {
|
|
|
|
cache()->deleteMatching("podcast#{$actor->podcast->id}*");
|
|
|
|
cache()
|
|
|
|
->deleteMatching("page_podcast#{$actor->podcast->id}*");
|
|
|
|
}
|
2021-04-02 17:20:02 +00:00
|
|
|
});
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
/**
|
|
|
|
* @param Actor $actor
|
2021-08-13 11:07:29 +00:00
|
|
|
* @param Post $post
|
2021-06-08 09:52:11 +00:00
|
|
|
*/
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_post_undo_favourite', static function ($actor, $post): void {
|
2021-08-13 11:07:29 +00:00
|
|
|
if ($post->actor->is_podcast) {
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_podcast#{$post->actor->podcast->id}*");
|
2021-06-08 09:52:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching("page_post#{$post->id}*");
|
|
|
|
if ($post->in_reply_to_id !== null) {
|
|
|
|
cache()->deleteMatching("page_post#{$post->in_reply_to_id}*");
|
2021-04-22 17:20:28 +00:00
|
|
|
}
|
2021-06-08 09:52:11 +00:00
|
|
|
|
|
|
|
if ($actor->is_podcast) {
|
|
|
|
cache()->deleteMatching("podcast#{$actor->podcast->id}*");
|
|
|
|
cache()
|
|
|
|
->deleteMatching("page_podcast#{$actor->podcast->id}*");
|
|
|
|
}
|
2021-04-22 17:20:28 +00:00
|
|
|
});
|
|
|
|
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_block_actor', static function (int $actorId): void {
|
2021-04-22 17:20:28 +00:00
|
|
|
cache()->deleteMatching('page_podcast*');
|
2021-05-25 18:00:09 +00:00
|
|
|
cache()
|
|
|
|
->deleteMatching('podcast*');
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching('page_post*');
|
2021-04-22 17:20:28 +00:00
|
|
|
});
|
|
|
|
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_unblock_actor', static function (int $actorId): void {
|
2021-04-22 17:20:28 +00:00
|
|
|
cache()->deleteMatching('page_podcast*');
|
2021-05-25 18:00:09 +00:00
|
|
|
cache()
|
|
|
|
->deleteMatching('podcast*');
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching('page_post*');
|
2021-04-22 17:20:28 +00:00
|
|
|
});
|
|
|
|
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_block_domain', static function (string $domainName): void {
|
2021-04-22 17:20:28 +00:00
|
|
|
cache()->deleteMatching('page_podcast*');
|
2021-05-25 18:00:09 +00:00
|
|
|
cache()
|
|
|
|
->deleteMatching('podcast*');
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching('page_post*');
|
2021-04-22 17:20:28 +00:00
|
|
|
});
|
|
|
|
|
2022-09-28 14:00:05 +00:00
|
|
|
Events::on('on_unblock_domain', static function (string $domainName): void {
|
2021-04-22 17:20:28 +00:00
|
|
|
cache()->deleteMatching('page_podcast*');
|
2021-05-25 18:00:09 +00:00
|
|
|
cache()
|
|
|
|
->deleteMatching('podcast*');
|
2021-05-19 16:35:13 +00:00
|
|
|
cache()
|
2021-08-13 11:07:29 +00:00
|
|
|
->deleteMatching('page_post*');
|
2021-04-02 17:20:02 +00:00
|
|
|
});
|