Generic Blocks extension
This commit is contained in:
parent
f8d88c2c67
commit
3e504f8815
79
contrib/blocks/main.php
Normal file
79
contrib/blocks/main.php
Normal file
@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/*
|
||||
* Name: Generic Blocks
|
||||
* Author: Shish <webmaster@shishnet.org>
|
||||
* License: GPLv2
|
||||
* Description: Add HTML to some space
|
||||
* Documentation:
|
||||
* Any HTML is allowed
|
||||
* <br>Separate different blocks with a line of 4 dashes
|
||||
* <br>Within each block, some settings can be set.
|
||||
* <br>Example settings
|
||||
* <pre>
|
||||
* 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
|
||||
* </pre>
|
||||
*/
|
||||
|
||||
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 <a href='".make_link("ext_doc/blocks")."'>the docs</a> for formatting");
|
||||
$sb->add_longtext_option("blocks_text");
|
||||
$event->panel->add_block($sb);
|
||||
}
|
||||
}
|
||||
?>
|
24
contrib/blocks/test.php
Normal file
24
contrib/blocks/test.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php
|
||||
class BlocksTest extends SCoreWebTestCase {
|
||||
function testNews() {
|
||||
$this->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();
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user