diff --git a/core/testcase.php b/core/testcase.php index 839c6f63..b49eec03 100644 --- a/core/testcase.php +++ b/core/testcase.php @@ -110,6 +110,7 @@ if(class_exists("\\PHPUnit\\Framework\\TestCase")) { $_SERVER['REQUEST_URI'] = make_link($page_name, http_build_query($get_args)); $_GET = $get_args; $_POST = $post_args; + $_COOKIE['shm_accepted_terms'] = "true"; $page = new Page(); send_event(new PageRequestEvent($method, $page_name, $get_args, $post_args)); if ($page->mode == PageMode::REDIRECT) { diff --git a/ext/terms/info.php b/ext/terms/info.php new file mode 100644 index 00000000..466d25df --- /dev/null +++ b/ext/terms/info.php @@ -0,0 +1,16 @@ + ""]; + public string $license = "GPLv2"; + public string $description = "Show a page of terms which must be accepted before continuing"; +} diff --git a/ext/terms/main.php b/ext/terms/main.php new file mode 100644 index 00000000..14c30bfc --- /dev/null +++ b/ext/terms/main.php @@ -0,0 +1,40 @@ +set_default_string("terms_message", "Cookies may be used. Please read our [url=site://wiki/privacy]privacy policy[/url] for more information.\nBy accepting to enter you agree to our [url=site://wiki/rules]rules[/url] and [url=site://wiki/terms_of_service]terms of service[/url]."); + } + + public function onSetupBuilding(SetupBuildingEvent $event): void + { + $sb = $event->panel->create_new_block("Terms & Conditions Gate"); + $sb->add_longtext_option("terms_message", 'Message (Use BBCode)'); + } + + public function onPageRequest(PageRequestEvent $event): void + { + global $config, $page, $user; + if ($event->page_starts_with("accept_terms")) { + $page->add_cookie("accepted_terms", "true", time() + 60 * 60 * 24 * $config->get_int('login_memory'), "/"); + $page->set_mode(PageMode::REDIRECT); + $page->set_redirect(make_link(explode('/', $event->path, 2)[1])); + } else { + // run on all pages unless logged in or cookie exists + if ($user->is_anonymous() && !isset($_COOKIE[$config->get_string('cookie_prefix', 'shm') . '_' . 'accepted_terms'])) { + $sitename = $config->get_string(SetupConfig::TITLE); + $body = format_text($config->get_string("terms_message")); + $this->theme->display_page($page, $sitename, $event->path, $body); + } + } + } +} diff --git a/ext/terms/theme.php b/ext/terms/theme.php new file mode 100644 index 00000000..7708c4cc --- /dev/null +++ b/ext/terms/theme.php @@ -0,0 +1,37 @@ +set_mode(PageMode::DATA); + $page->add_auto_html_headers(); + $hh = $page->get_all_html_headers(); + $page->set_data( + << + + + $sitename + + + $hh + + +
+

$sitename

+ $body +
+ +
+
+ + +EOD + ); + } +}