2021-12-14 18:32:47 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2007-08-02 17:10:17 +00:00
|
|
|
|
2023-01-10 22:44:09 +00:00
|
|
|
namespace Shimmie2;
|
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
class Home extends Extension
|
|
|
|
{
|
2020-01-26 13:19:35 +00:00
|
|
|
/** @var HomeTheme */
|
2023-06-27 14:56:49 +00:00
|
|
|
protected Themelet $theme;
|
2020-01-26 13:19:35 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onPageRequest(PageRequestEvent $event)
|
|
|
|
{
|
|
|
|
global $config, $page;
|
|
|
|
if ($event->page_matches("home")) {
|
|
|
|
$base_href = get_base_href();
|
2019-08-02 19:40:03 +00:00
|
|
|
$sitename = $config->get_string(SetupConfig::TITLE);
|
|
|
|
$theme_name = $config->get_string(SetupConfig::THEME);
|
2007-08-02 17:10:17 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$body = $this->get_body();
|
2007-08-02 17:10:17 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
$this->theme->display_page($page, $sitename, $base_href, $theme_name, $body);
|
|
|
|
}
|
|
|
|
}
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
public function onSetupBuilding(SetupBuildingEvent $event)
|
|
|
|
{
|
|
|
|
$counters = [];
|
2023-06-26 03:36:30 +00:00
|
|
|
$counters["None"] = "none";
|
|
|
|
$counters["Text-only"] = "text-only";
|
2019-05-28 16:59:38 +00:00
|
|
|
foreach (glob("ext/home/counters/*") as $counter_dirname) {
|
|
|
|
$name = str_replace("ext/home/counters/", "", $counter_dirname);
|
|
|
|
$counters[ucfirst($name)] = $name;
|
|
|
|
}
|
2009-05-11 21:09:24 +00:00
|
|
|
|
2020-10-26 15:13:28 +00:00
|
|
|
$sb = $event->panel->create_new_block("Home Page");
|
2019-05-28 16:59:38 +00:00
|
|
|
$sb->add_longtext_option("home_links", 'Page Links (Use BBCode, leave blank for defaults)');
|
|
|
|
$sb->add_longtext_option("home_text", "<br>Page Text:<br>");
|
|
|
|
$sb->add_choice_option("home_counter", $counters, "<br>Counter: ");
|
|
|
|
}
|
2007-08-02 17:10:17 +00:00
|
|
|
|
2009-05-11 21:09:24 +00:00
|
|
|
|
2021-03-14 23:43:50 +00:00
|
|
|
private function get_body(): string
|
2019-05-28 16:59:38 +00:00
|
|
|
{
|
|
|
|
// returns just the contents of the body
|
|
|
|
global $config;
|
|
|
|
$base_href = get_base_href();
|
2019-08-02 19:40:03 +00:00
|
|
|
$sitename = $config->get_string(SetupConfig::TITLE);
|
2019-05-28 16:59:38 +00:00
|
|
|
$contact_link = contact_link();
|
|
|
|
if (is_null($contact_link)) {
|
|
|
|
$contact_link = "";
|
|
|
|
}
|
|
|
|
$counter_dir = $config->get_string('home_counter', 'default');
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2023-06-26 03:36:30 +00:00
|
|
|
$num_comma = "";
|
2019-05-28 16:59:38 +00:00
|
|
|
$counter_text = "";
|
2023-06-26 03:36:30 +00:00
|
|
|
if ($counter_dir != 'none') {
|
|
|
|
$total = Image::count_images();
|
|
|
|
$num_comma = number_format($total);
|
|
|
|
|
|
|
|
if ($counter_dir != 'text-only') {
|
|
|
|
$strtotal = "$total";
|
|
|
|
$length = strlen($strtotal);
|
|
|
|
for ($n=0; $n<$length; $n++) {
|
|
|
|
$cur = $strtotal[$n];
|
|
|
|
$counter_text .= "<img alt='$cur' src='$base_href/ext/home/counters/$counter_dir/$cur.gif' />";
|
|
|
|
}
|
|
|
|
}
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2009-01-04 19:18:37 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
// get the homelinks and process them
|
|
|
|
if (strlen($config->get_string('home_links', '')) > 0) {
|
|
|
|
$main_links = $config->get_string('home_links');
|
|
|
|
} else {
|
2020-07-06 18:01:02 +00:00
|
|
|
$main_links = '[url=site://post/list]Posts[/url][url=site://comment/list]Comments[/url][url=site://tags]Tags[/url]';
|
2023-01-10 22:44:09 +00:00
|
|
|
if (class_exists("Shimmie2\Pools")) {
|
2021-12-19 21:38:09 +00:00
|
|
|
$main_links .= '[url=site://pool/list]Pools[/url]';
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2023-01-10 22:44:09 +00:00
|
|
|
if (class_exists("Shimmie2\Wiki")) {
|
2020-07-06 18:01:02 +00:00
|
|
|
$main_links .= '[url=site://wiki]Wiki[/url]';
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
2020-07-06 18:01:02 +00:00
|
|
|
$main_links .= '[url=site://ext_doc]Documentation[/url]';
|
2019-05-28 16:59:38 +00:00
|
|
|
}
|
|
|
|
$main_links = format_text($main_links);
|
|
|
|
$main_text = $config->get_string('home_text', '');
|
2009-08-24 01:15:08 +00:00
|
|
|
|
2019-05-28 16:59:38 +00:00
|
|
|
return $this->theme->build_body($sitename, $main_links, $main_text, $contact_link, $num_comma, $counter_text);
|
|
|
|
}
|
2007-08-02 17:10:17 +00:00
|
|
|
}
|