Setup constants

This commit is contained in:
Matthew Barbour 2019-08-02 14:40:03 -05:00 committed by matthew
parent 5ceb6f4193
commit 972b68bdd3
29 changed files with 66 additions and 55 deletions

View file

@ -60,7 +60,7 @@ class PageRequestEvent extends Event
// if path is not specified, use the default front page
if (empty($path)) { /* empty is faster than strlen */
$path = $config->get_string('front_page');
$path = $config->get_string(SetupConfig::FRONT_PAGE);
}
// break the path into parts

View file

@ -813,7 +813,7 @@ class Image
$tmpl = str_replace('$size', "{$this->width}x{$this->height}", $tmpl);
$tmpl = str_replace('$filesize', to_shorthand_int($this->filesize), $tmpl);
$tmpl = str_replace('$filename', $_escape($base_fname), $tmpl);
$tmpl = str_replace('$title', $_escape($config->get_string("title")), $tmpl);
$tmpl = str_replace('$title', $_escape($config->get_string(SetupConfig::TITLE)), $tmpl);
$tmpl = str_replace('$date', $_escape(autodate($this->posted, false)), $tmpl);
// nothing seems to use this, sending the event out to 50 exts is a lot of overhead

View file

@ -405,7 +405,7 @@ class Page
global $config;
$data_href = get_base_href();
$theme_name = $config->get_string('theme', 'default');
$theme_name = $config->get_string(SetupConfig::THEME, 'default');
$this->add_html_header("<script type='text/javascript'>base_href = '$data_href';</script>", 40);

View file

@ -14,7 +14,7 @@ function make_link(?string $page=null, ?string $query=null): string
global $config;
if (is_null($page)) {
$page = $config->get_string('main_page');
$page = $config->get_string(SetupConfig::MAIN_PAGE);
}
if (!is_null(BASE_URL)) {

View file

@ -16,7 +16,7 @@ function mtimefile(string $file): string
function get_theme(): string
{
global $config;
$theme = $config->get_string("theme", "default");
$theme = $config->get_string(SetupConfig::THEME, "default");
if (!file_exists("themes/$theme")) {
$theme = "default";
}

View file

@ -27,14 +27,14 @@ class BrowserSearch extends Extension
// Add in header code to let the browser know that the search plugin exists
// We need to build the data for the header
$search_title = $config->get_string('title');
$search_title = $config->get_string(SetupConfig::TITLE);
$search_file_url = make_link('browser_search/please_dont_use_this_tag_as_it_would_break_stuff__search.xml');
$page->add_html_header("<link rel='search' type='application/opensearchdescription+xml' title='$search_title' href='$search_file_url'>");
// The search.xml file that is generated on the fly
if ($event->page_matches("browser_search/please_dont_use_this_tag_as_it_would_break_stuff__search.xml")) {
// First, we need to build all the variables we'll need
$search_title = $config->get_string('title');
$search_title = $config->get_string(SetupConfig::TITLE);
$search_form_url = make_link('post/list/{searchTerms}');
$suggenton_url = make_link('browser_search/')."{searchTerms}";
$icon_b64 = base64_encode(file_get_contents("ext/handle_static/static/favicon.ico"));

View file

@ -65,7 +65,7 @@ class custom_html_headers extends Extension
global $config, $page;
// get config values
$site_title = $config->get_string("title");
$site_title = $config->get_string(SetupConfig::TITLE);
$sitename_in_title = $config->get_int("sitename_in_title");
// if feature is enabled & sitename isn't already in title

View file

@ -21,7 +21,7 @@ class DowntimeTheme extends Themelet
public function display_message(string $message)
{
global $config, $user, $page;
$theme_name = $config->get_string('theme');
$theme_name = $config->get_string(SetupConfig::THEME);
$data_href = get_base_href();
$login_link = make_link("user_admin/login");
$auth = $user->get_auth_html();

View file

@ -40,8 +40,8 @@ class ET extends Extension
global $config, $database;
$info = [];
$info['site_title'] = $config->get_string("title");
$info['site_theme'] = $config->get_string("theme");
$info['site_title'] = $config->get_string(SetupConfig::TITLE);
$info['site_theme'] = $config->get_string(SetupConfig::THEME);
$info['site_url'] = "http://" . $_SERVER["HTTP_HOST"] . get_base_href();
$info['sys_shimmie'] = VERSION;

View file

@ -17,7 +17,7 @@ class HandleStatic extends Extension
if ($page->mode == PageMode::PAGE && (!isset($page->blocks) || $this->count_main($page->blocks) == 0)) {
$h_pagename = html_escape(implode('/', $event->args));
$f_pagename = preg_replace("/[^a-z_\-\.]+/", "_", $h_pagename);
$theme_name = $config->get_string("theme", "default");
$theme_name = $config->get_string(SetupConfig::THEME, "default");
$theme_file = "themes/$theme_name/static/$f_pagename";
$static_file = "ext/handle_static/static/$f_pagename";

View file

@ -22,8 +22,8 @@ class Home extends Extension
global $config, $page;
if ($event->page_matches("home")) {
$base_href = get_base_href();
$sitename = $config->get_string('title');
$theme_name = $config->get_string('theme');
$sitename = $config->get_string(SetupConfig::TITLE);
$theme_name = $config->get_string(SetupConfig::THEME);
$body = $this->get_body();
@ -52,7 +52,7 @@ class Home extends Extension
// returns just the contents of the body
global $config;
$base_href = get_base_href();
$sitename = $config->get_string('title');
$sitename = $config->get_string(SetupConfig::TITLE);
$contact_link = contact_link();
if (is_null($contact_link)) {
$contact_link = "";

View file

@ -110,7 +110,7 @@ and of course start organising your images :-)
global $config;
if (count($this->search_terms) == 0) {
$page_title = $config->get_string('title');
$page_title = $config->get_string(SetupConfig::TITLE);
} else {
$search_string = implode(' ', $this->search_terms);
$page_title = html_escape($search_string);

View file

@ -87,7 +87,7 @@ class NumericScoreTheme extends Themelet
$nav_html = "<a href=".make_link().">Index</a>";
$page->set_heading($config->get_string('title'));
$page->set_heading($config->get_string(SetupConfig::TITLE));
$page->add_block(new Block("Navigation", $nav_html, "left", 10));
$page->add_block(new Block(null, $html, "main", 30));
}

View file

@ -14,7 +14,7 @@ class RSS_Comments extends Extension
public function onPostListBuilding(PostListBuildingEvent $event)
{
global $config, $page;
$title = $config->get_string('title');
$title = $config->get_string(SetupConfig::TITLE);
$page->add_html_header("<link rel=\"alternate\" type=\"application/rss+xml\" ".
"title=\"$title - Comments\" href=\"".make_link("rss/comments")."\" />");
@ -60,7 +60,7 @@ class RSS_Comments extends Extension
";
}
$title = $config->get_string('title');
$title = $config->get_string(SetupConfig::TITLE);
$base_href = make_http(get_base_href());
$version = $config->get_string('version');
$xml = <<<EOD

View file

@ -12,7 +12,7 @@ class RSS_Images extends Extension
public function onPostListBuilding(PostListBuildingEvent $event)
{
global $config, $page;
$title = $config->get_string('title');
$title = $config->get_string(SetupConfig::TITLE);
if (count($event->search_terms) > 0) {
$search = html_escape(implode(' ', $event->search_terms));
@ -47,7 +47,7 @@ class RSS_Images extends Extension
$data .= $this->thumb($image);
}
$title = $config->get_string('title');
$title = $config->get_string(SetupConfig::TITLE);
$base_href = make_http(get_base_href());
$search = "";
if (count($search_terms) > 0) {

12
ext/setup/config.php Normal file
View file

@ -0,0 +1,12 @@
<?php
class SetupConfig
{
public const TITLE = "title";
public const FRONT_PAGE = "front_page";
public const MAIN_PAGE = "main_page";
public const THEME = "theme";
public const WORD_WRAP = "word_wrap";
public const COMMENT_CAPTCHA = "comment_captcha";
}

View file

@ -6,6 +6,8 @@
* Description: Allows the site admin to configure the board to his or her taste
*/
include_once "config.php";
/* ConfigSaveEvent {{{
*
* Sent when the setup screen's 'set' button has been
@ -275,12 +277,11 @@ class Setup extends Extension
public function onInitExt(InitExtEvent $event)
{
global $config;
$config->set_default_string("title", "Shimmie");
$config->set_default_string("front_page", "post/list");
$config->set_default_string("main_page", "post/list");
$config->set_default_string("theme", "default");
$config->set_default_bool("word_wrap", true);
$config->set_default_bool("comment_captcha", false);
$config->set_default_string(SetupConfig::TITLE, "Shimmie");
$config->set_default_string(SetupConfig::FRONT_PAGE, "post/list");
$config->set_default_string(SetupConfig::MAIN_PAGE, "post/list");
$config->set_default_string(SetupConfig::THEME, "default");
$config->set_default_bool(SetupConfig::WORD_WRAP, true);
}
public function onPageRequest(PageRequestEvent $event)
@ -368,11 +369,11 @@ class Setup extends Extension
</script>";
$sb = new SetupBlock("General");
$sb->position = 0;
$sb->add_text_option("title", "Site title: ");
$sb->add_text_option("front_page", "<br>Front page: ");
$sb->add_text_option("main_page", "<br>Main page: ");
$sb->add_text_option(SetupConfig::TITLE, "Site title: ");
$sb->add_text_option(SetupConfig::FRONT_PAGE, "<br>Front page: ");
$sb->add_text_option(SetupConfig::MAIN_PAGE, "<br>Main page: ");
$sb->add_text_option("contact_link", "<br>Contact URL: ");
$sb->add_choice_option("theme", $themes, "<br>Theme: ");
$sb->add_choice_option(SetupConfig::THEME, $themes, "<br>Theme: ");
//$sb->add_multichoice_option("testarray", array("a" => "b", "c" => "d"), "<br>Test Array: ");
$sb->add_bool_option("nice_urls", "<br>Nice URLs: ");
$sb->add_label("<span id='nicetest'>(Javascript inactive, can't test!)</span>$nicescript");

View file

@ -74,7 +74,7 @@ class XMLSitemap extends Extension
// add index
$index = [];
$index[0] = $config->get_string("front_page");
$index[0] = $config->get_string(SetupConfig::FRONT_PAGE);
$this->add_sitemap_queue($index, "weekly", "1");
/* --- Add 20 most used tags --- */

View file

@ -189,7 +189,7 @@ class UploadTheme extends Themelet
global $config;
$link = make_http(make_link("upload"));
$main_page = make_http(make_link());
$title = $config->get_string('title');
$title = $config->get_string(SetupConfig::TITLE);
$max_size = $config->get_int('upload_size');
$max_kb = to_shorthand_int($max_size);
$delimiter = $config->get_bool('nice_urls') ? '?' : '&amp;';
@ -235,7 +235,7 @@ class UploadTheme extends Themelet
if (class_exists("VideoFileHandler")) {
$supported_ext .= " flv mp4 ogv webm m4v";
}
$title = "Booru to " . $config->get_string('title');
$title = "Booru to " . $config->get_string(SetupConfig::TITLE);
// CA=0: Ask to use current or new tags | CA=1: Always use current tags | CA=2: Always use new tags
$html .= '<p><a href="javascript:
var ste=&quot;'. $link . $delimiter .'url=&quot;;

View file

@ -11,7 +11,7 @@ class CustomIndexTheme extends IndexTheme
if (count($this->search_terms) == 0) {
$query = null;
$page_title = $config->get_string('title');
$page_title = $config->get_string(SetupConfig::TITLE);
} else {
$search_string = implode(' ', $this->search_terms);
$query = url_escape($search_string);

View file

@ -48,7 +48,7 @@ class Layout
{
global $config, $user;
$theme_name = $config->get_string('theme');
$theme_name = $config->get_string(SetupConfig::THEME);
//$base_href = $config->get_string('base_href');
$data_href = get_base_href();
$contact_link = contact_link();
@ -92,10 +92,9 @@ class Layout
$subheading = "<div id='subtitle'>{$this->subheading}</div>";
}
$site_name = $config->get_string('title'); // bzchan: change from normal default to get title for top of page
$main_page = $config->get_string('main_page'); // bzchan: change from normal default to get main page for top of page
$site_name = $config->get_string(SetupConfig::TITLE); // bzchan: change from normal default to get title for top of page
$main_page = $config->get_string(SetupConfig::MAIN_PAGE); // bzchan: change from normal default to get main page for top of page
// bzchan: CUSTOM LINKS are prepared here, change these to whatever you like
$custom_links = "";
if ($user->is_anonymous()) {
$custom_links .= $this->navlinks(make_link('user_admin/login'), "My Account", ["user", "user_admin", "setup", "admin"]);

View file

@ -11,7 +11,7 @@ class CustomIndexTheme extends IndexTheme
if (count($this->search_terms) == 0) {
$query = null;
$page_title = $config->get_string('title');
$page_title = $config->get_string(SetupConfig::TITLE);
} else {
$search_string = implode(' ', $this->search_terms);
$query = url_escape($search_string);

View file

@ -48,7 +48,7 @@ class Layout
{
global $config, $user;
//$theme_name = $config->get_string('theme');
//$theme_name = $config->get_string(SetupConfig::THEME);
//$base_href = $config->get_string('base_href');
//$data_href = get_base_href();
$contact_link = contact_link();
@ -92,10 +92,9 @@ class Layout
$subheading = "<div id='subtitle'>{$this->subheading}</div>";
}
$site_name = $config->get_string('title'); // bzchan: change from normal default to get title for top of page
$main_page = $config->get_string('main_page'); // bzchan: change from normal default to get main page for top of page
$site_name = $config->get_string(SetupConfig::TITLE); // bzchan: change from normal default to get title for top of page
$main_page = $config->get_string(SetupConfig::MAIN_PAGE); // bzchan: change from normal default to get main page for top of page
// bzchan: CUSTOM LINKS are prepared here, change these to whatever you like
$custom_links = "";
if ($user->is_anonymous()) {
$custom_links .= $this->navlinks(make_link('user_admin/login'), "Sign in", ["user", "user_admin", "setup", "admin"]);

View file

@ -11,7 +11,7 @@ class Layout
{
global $config;
//$theme_name = $config->get_string('theme', 'default');
//$theme_name = $config->get_string(SetupConfig::THEME, 'default');
//$data_href = get_base_href();
$contact_link = contact_link();
$header_html = $page->get_all_html_headers();

View file

@ -11,7 +11,7 @@ class CustomCommentListTheme extends CommentListTheme
//$prev = $page_number - 1;
//$next = $page_number + 1;
$page_title = $config->get_string('title');
$page_title = $config->get_string(SetupConfig::TITLE);
$page->set_title($page_title);
$page->set_heading($page_title);
$page->disable_left();

View file

@ -6,7 +6,7 @@ class Layout
{
global $config;
$theme_name = $config->get_string('theme', 'default');
$theme_name = $config->get_string(SetupConfig::THEME, 'default');
$data_href = get_base_href();
$contact_link = contact_link();
$header_html = $page->get_all_html_headers();

View file

@ -13,8 +13,8 @@ class Layout
{
global $config, $user;
$theme_name = $config->get_string('theme', 'lite');
$site_name = $config->get_string('title');
$theme_name = $config->get_string(SetupConfig::THEME, 'lite');
$site_name = $config->get_string(SetupConfig::TITLE);
$data_href = get_base_href();
$contact_link = contact_link();
$header_html = $page->get_all_html_headers();

View file

@ -11,10 +11,10 @@ class Layout
{
global $config;
$theme_name = $config->get_string('theme', 'material');
$site_name = $config->get_string('title');
$theme_name = $config->get_string(SetupConfig::THEME, 'material');
$site_name = $config->get_string(SetupConfig::TITLE);
$data_href = get_base_href();
$main_page = $config->get_string('main_page');
$main_page = $config->get_string(SetupConfig::MAIN_PAGE);
$contact_link = contact_link();
$site_link = make_link();
$header_html = $page->get_all_html_headers();

View file

@ -11,10 +11,10 @@ class Layout
{
global $config;
//$theme_name = $config->get_string('theme', 'default');
$site_name = $config->get_string('title');
//$theme_name = $config->get_string(SetupConfig::THEME, 'default');
$site_name = $config->get_string(SetupConfig::TITLE);
$data_href = get_base_href();
$main_page = $config->get_string('main_page');
$main_page = $config->get_string(SetupConfig::MAIN_PAGE);
$contact_link = contact_link();
$header_html = $page->get_all_html_headers();