biography extension
This commit is contained in:
parent
dd94c7eda6
commit
c7d214189e
4 changed files with 92 additions and 0 deletions
13
ext/biography/info.php
Normal file
13
ext/biography/info.php
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
class BiographyInfo extends ExtensionInfo
|
||||
{
|
||||
public const KEY = "biography";
|
||||
|
||||
public $key = self::KEY;
|
||||
public $name = "User Bios";
|
||||
public $url = self::SHIMMIE_URL;
|
||||
public $authors = self::SHISH_AUTHOR;
|
||||
public $license = self::LICENSE_GPLV2;
|
||||
public $description = "Allow users to write a bit about themselves";
|
||||
}
|
35
ext/biography/main.php
Normal file
35
ext/biography/main.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
class Biography extends Extension
|
||||
{
|
||||
/** @var BiographyTheme */
|
||||
protected $theme;
|
||||
|
||||
public function onUserPageBuilding(UserPageBuildingEvent $event)
|
||||
{
|
||||
global $database, $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)
|
||||
{
|
||||
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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
19
ext/biography/test.php
Normal file
19
ext/biography/test.php
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?php declare(strict_types=1);
|
||||
class BiographyTest extends ShimmiePHPUnitTestCase
|
||||
{
|
||||
public function testBio()
|
||||
{
|
||||
global $database;
|
||||
$this->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");
|
||||
}
|
||||
}
|
25
ext/biography/theme.php
Normal file
25
ext/biography/theme.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php declare(strict_types=1);
|
||||
use function MicroHTML\TEXTAREA;
|
||||
|
||||
class BiographyTheme extends Themelet
|
||||
{
|
||||
public function display_biography(Page $page, string $bio)
|
||||
{
|
||||
$page->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));
|
||||
}
|
||||
}
|
Reference in a new issue