From c7d214189effac24f749da40e25b3f29b3d63d38 Mon Sep 17 00:00:00 2001 From: Shish Date: Fri, 12 Feb 2021 21:02:20 +0000 Subject: [PATCH] biography extension --- ext/biography/info.php | 13 +++++++++++++ ext/biography/main.php | 35 +++++++++++++++++++++++++++++++++++ ext/biography/test.php | 19 +++++++++++++++++++ ext/biography/theme.php | 25 +++++++++++++++++++++++++ 4 files changed, 92 insertions(+) create mode 100644 ext/biography/info.php create mode 100644 ext/biography/main.php create mode 100644 ext/biography/test.php create mode 100644 ext/biography/theme.php diff --git a/ext/biography/info.php b/ext/biography/info.php new file mode 100644 index 00000000..12147c22 --- /dev/null +++ b/ext/biography/info.php @@ -0,0 +1,13 @@ +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) + { + global $cache, $database, $page, $user, $user_config; + if ($event->page_matches("biography")) { + if ($user->check_auth_token()) { + $user_config->set_string("biography", $_POST['biography']); + $page->flash("Bio Updated"); + $page->set_mode(PageMode::REDIRECT); + $page->set_redirect(referer_or(make_link())); + } + } + } +} diff --git a/ext/biography/test.php b/ext/biography/test.php new file mode 100644 index 00000000..5b9db7b7 --- /dev/null +++ b/ext/biography/test.php @@ -0,0 +1,19 @@ +log_in_as_user(); + $this->post_page("biography", ["biography"=>"My bio goes here"]); + $this->get_page("user/" . self::$user_name); + $this->assert_text("My bio goes here"); + + $this->log_in_as_admin(); + $this->get_page("user/" . self::$user_name); + $this->assert_text("My bio goes here"); + + $this->get_page("user/" . self::$admin_name); + $this->assert_no_text("My bio goes here"); + } +} diff --git a/ext/biography/theme.php b/ext/biography/theme.php new file mode 100644 index 00000000..679a445b --- /dev/null +++ b/ext/biography/theme.php @@ -0,0 +1,25 @@ +add_block(new Block("About Me", format_text($bio), "main", 30, "about-me")); + } + + public function display_composer(Page $page, string $bio) + { + global $user; + $post_url = make_link("biography"); + $auth = $user->get_auth_html(); + + $html = SHM_SIMPLE_FORM( + $post_url, + TEXTAREA(["style"=>"width: 100%", "rows"=>"6", "name"=>"biography"], $bio), + SHM_SUBMIT("Save") + ); + + $page->add_block(new Block("About Me", (string)$html, "main", 30)); + } +}