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/contrib/home/main.php

95 lines
3.2 KiB
PHP
Raw Normal View History

<?php
2009-08-20 22:37:17 +00:00
/*
2009-01-16 08:18:41 +00:00
* Name: Home Page
* Author: Bzchan <bzchan@animemahou.com>
* License: GPLv2
* Visibility: admin
2009-01-16 08:18:41 +00:00
* Description: Displays a front page with logo, search box and image count
* Documentation:
* Once enabled, the page will show up at the URL "home", so if you want
* this to be the front page of your site, you should go to "Board Config"
* and set "Front Page" to "home".
* <p>The images used for the numbers can be changed from the board config
* page. If you want to use your own numbers, upload them into a new folder
* in <code>/ext/home/counters</code>, and they'll become available
* alongside the default choices.
*/
class Home extends Extension {
2010-05-15 11:17:32 +00:00
public function onInitExt(InitExtEvent $event) {
2009-08-24 01:15:08 +00:00
global $config;
2009-08-24 04:33:51 +00:00
$config->set_default_string("home_links", '[$base/post/list|Posts]
[$base/comment/list|Comments]
[$base/tags|Tags]
[$base/ext_doc|&raquo;]');
2009-08-24 01:15:08 +00:00
}
2010-05-15 11:17:32 +00:00
public function onPageRequest(PageRequestEvent $event) {
2009-05-11 21:09:24 +00:00
global $config, $page;
if($event->page_matches("home")) {
$base_href = get_base_href();
2009-05-11 21:09:24 +00:00
$sitename = $config->get_string('title');
$theme_name = $config->get_string('theme');
2009-05-11 21:09:24 +00:00
$body = $this->get_body();
$this->theme->display_page($page, $sitename, $base_href, $theme_name, $body);
}
2009-05-11 21:09:24 +00:00
}
2009-01-04 19:18:37 +00:00
2010-05-15 11:17:32 +00:00
public function onSetupBuilding(SetupBuildingEvent $event) {
2009-05-11 21:09:24 +00:00
$counters = array();
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
$sb = new SetupBlock("Home Page");
$sb->add_bool_option("home_choice", "Use custom page links: ");
$sb->add_longtext_option("home_links", '<br>Page Links - Example: [/post/list|Posts]<br>');
2009-08-24 01:15:08 +00:00
$sb->add_longtext_option("home_text", "<br>Page Text:<br>");
2009-05-11 21:09:24 +00:00
$sb->add_choice_option("home_counter", $counters, "<br>Counter: ");
$event->panel->add_block($sb);
}
2009-05-11 21:09:24 +00:00
2010-05-15 11:17:32 +00:00
private function get_body() {
// returns just the contents of the body
global $database;
global $config;
$base_href = get_base_href();
$sitename = $config->get_string('title');
$contact_link = $config->get_string('contact_link');
$counter_dir = $config->get_string('home_counter', 'default');
2009-01-04 19:18:37 +00:00
$total = Image::count_images();
$strtotal = "$total";
$num_comma = number_format($total);
2009-01-04 19:18:37 +00:00
$counter_text = "";
$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' /> ";
}
2009-01-04 19:18:37 +00:00
// get the homelinks and process them
if($config->get_bool('home_choice')){
$main_links = $config->get_string('home_links');
}else{
$main_links = '[$base/post/list|Posts] [$base/comment/list|Comments] [$base/tags|Tags]';
if(file_exists("ext/pools")){$main_links .= ' [$base/pools|Pools]';}
if(file_exists("ext/wiki")){$main_links .= ' [$base/wiki|Wiki]';}
$main_links .= ' [$base/ext_doc|&raquo;]';
}
$main_links = str_replace('$base', $base_href, $main_links);
$main_links = preg_replace('#\[(.*?)\|(.*?)\]#', "<a href='\\1'>\\2</a>", $main_links);
$main_links = str_replace('//', "/", $main_links);
2009-08-24 01:15:08 +00:00
$main_text = $config->get_string('home_text');
return $this->theme->build_body($sitename, $main_links, $main_text, $contact_link, $num_comma, $counter_text);
}
}
?>