diff --git a/contrib/blocks/main.php b/contrib/blocks/main.php new file mode 100644 index 00000000..aa22e13b --- /dev/null +++ b/contrib/blocks/main.php @@ -0,0 +1,79 @@ + + * License: GPLv2 + * Description: Add HTML to some space + * Documentation: + * Any HTML is allowed + *
Separate different blocks with a line of 4 dashes + *
Within each block, some settings can be set. + *
Example settings + *
+ *  Title: some text
+ *  Area: main
+ *  Priority: 100
+ *  Pages: *
+ *  
+ *  Here is some <b>html</b>
+ *  ----
+ *  Title: another block, on the left this time
+ *  Priority: 0
+ *  Pages: post/view/*
+ *  
+ *  Area can be "left" or "main" in the default theme
+ *  other themes may have more areas. Priority has 0
+ *  near the top of the screen and 100 near the bottom
+ *  
+ */ + +class Blocks extends SimpleExtension { + public function onPageRequest($event) { + global $config, $page; + $all = $config->get_string("blocks_text"); + $blocks = explode("----", $all); + foreach($blocks as $block) { + $title = ""; + $text = ""; + $area = "left"; + $pri = 50; + $pages = "*"; + + $lines = explode("\n", $block); + foreach($lines as $line) { + if(strpos($line, ":")) { + $parts = explode(":", $line, 2); + $parts[1] = trim($parts[1]); + if($parts[0] == "Title") { + $title = $parts[1]; + continue; + } + if($parts[0] == "Area") { + $area = $parts[1]; + continue; + } + if($parts[0] == "Priority") { + $pri = (int)$parts[1]; + continue; + } + if($parts[0] == "Pages") { + $pages = $parts[1]; + continue; + } + } + $text = $text . "\n" . $line; + } + if(fnmatch($pages, implode("/", $event->args))) { + $page->add_block(new Block($title, $text, $area, $pri)); + } + } + } + + public function onSetupBuilding($event) { + $sb = new SetupBlock("Blocks"); + $sb->add_label("See the docs for formatting"); + $sb->add_longtext_option("blocks_text"); + $event->panel->add_block($sb); + } +} +?> diff --git a/contrib/blocks/test.php b/contrib/blocks/test.php new file mode 100644 index 00000000..d19e2f11 --- /dev/null +++ b/contrib/blocks/test.php @@ -0,0 +1,24 @@ +log_in_as_admin(); + + $this->get_page("setup"); + $this->set_field("_config_blocks_text", "badgers"); + $this->click("Save Settings"); + + $this->get_page("post/list"); + $this->assert_text("badgers"); + + $this->get_page("setup"); + $this->set_field("_config_blocks_text", ""); + $this->click("Save Settings"); + + $this->get_page("post/list"); + $this->assert_no_text("Note"); + $this->assert_no_text("badgers"); + + $this->log_out(); + } +} +?>