This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/ext/biography/main.php
2024-06-29 18:44:56 +01:00

38 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace Shimmie2;
class Biography extends Extension
{
/** @var BiographyTheme */
protected Themelet $theme;
public function onUserPageBuilding(UserPageBuildingEvent $event): void
{
global $page, $user;
$duser = $event->display_user;
$duser_config = UserConfig::get_for_user($event->display_user->id);
$bio = $duser_config->get_string("biography", "");
if ($user->id == $duser->id) {
$this->theme->display_composer($page, $bio);
} else {
$this->theme->display_biography($page, $bio);
}
}
public function onPageRequest(PageRequestEvent $event): void
{
global $page, $user, $user_config;
if ($event->page_matches("biography", method: "POST")) {
$bio = $event->get_POST('biography');
log_info("biography", "Set biography to $bio");
$user_config->set_string("biography", $bio);
$page->flash("Bio Updated");
$page->set_mode(PageMode::REDIRECT);
$page->set_redirect(referer_or(make_link()));
}
}
}