diff --git a/core/block.class.php b/core/block.class.php index 0beab722..1c33aed7 100644 --- a/core/block.class.php +++ b/core/block.class.php @@ -9,12 +9,14 @@ class Block { * @retval string */ var $header; + /** * The content * * @retval string */ var $body; + /** * Where the block should be placed. The default theme supports * "main" and "left", other themes can add their own areas @@ -22,6 +24,7 @@ class Block { * @retval string */ var $section; + /** * How far down the section the block should appear, higher * numbers appear lower. The scale is 0-100 by convention, @@ -31,11 +34,29 @@ class Block { */ var $position; - public function __construct($header, $body, /*string*/ $section="main", /*int*/ $position=50) { + /** + * + */ + var $id; + + public function __construct($header, $body, /*string*/ $section="main", /*int*/ $position=50, $id=null) { $this->header = $header; $this->body = $body; $this->section = $section; $this->position = $position; + $this->id = str_replace(' ', '_', is_null($id) ? (is_null($header) ? md5($body) : $header) . $section : $id); + } + + public function get_html($hidable=false) { + $h = $this->header; + $b = $this->body; + $i = $this->id; + $html = "
"; + $h_toggler = $hidable ? " shm-toggler" : ""; + if(!is_null($h)) $html .= "

$h

"; + if(!is_null($b)) $html .= "
$b
"; + $html .= "
"; + return $html; } } diff --git a/themes/danbooru/layout.class.php b/themes/danbooru/layout.class.php index cb782ff3..935d1522 100644 --- a/themes/danbooru/layout.class.php +++ b/themes/danbooru/layout.class.php @@ -66,7 +66,7 @@ class Layout { foreach($page->blocks as $block) { switch($block->section) { case "left": - $left_block_html .= $this->block_to_html($block, true); + $left_block_html .= $block->get_html(true); break; case "user": $user_block_html .= $block->body; // $this->block_to_html($block, true); @@ -78,7 +78,7 @@ class Layout { if($block->header == "Images") { $block->header = " "; } - $main_block_html .= $this->block_to_html($block, false); + $main_block_html .= $block->get_html(false); break; default: print "

error: {$block->header} using an unknown section ({$block->section})"; @@ -234,23 +234,6 @@ $header_html EOD; } - function block_to_html($block, $hidable=false) { - $h = $block->header; - $s = $block->section; - $b = $block->body; - $i = str_replace(' ', '_', $h.$s); - $html = "

"; - if($hidable) { - if(!is_null($h)) $html .= "\n

$h

\n"; - } - else { - if(!is_null($h)) $html .= "\n

$h

\n"; - } - if(!is_null($b)) $html .= "
$b
\n"; - $html .= "
"; - return $html; - } - private function navlinks($link, $desc, $pages_matched) { /** * Woo! We can actually SEE THE CURRENT PAGE!! (well... see it highlighted in the menu.) diff --git a/themes/default/layout.class.php b/themes/default/layout.class.php index c918a4c9..b2e4a67e 100644 --- a/themes/default/layout.class.php +++ b/themes/default/layout.class.php @@ -26,13 +26,13 @@ class Layout { foreach($page->blocks as $block) { switch($block->section) { case "left": - $left_block_html .= $this->block_to_html($block, true, "left"); + $left_block_html .= $block->get_html(true); break; case "main": - $main_block_html .= $this->block_to_html($block, false, "main"); + $main_block_html .= $block->get_html(false); break; case "subheading": - $sub_block_html .= $this->block_to_html($block, false, "main"); + $sub_block_html .= $block->get_html(false); break; default: print "

error: {$block->header} using an unknown section ({$block->section})"; @@ -85,20 +85,5 @@ $header_html EOD; } - - /** - * A handy function which does exactly what it says in the method name - */ - private function block_to_html($block, $hidable=false, $salt="") { - $h = $block->header; - $b = $block->body; - $i = str_replace(' ', '_', $h) . $salt; - $html = "

"; - $h_toggler = $hidable ? " shm-toggler" : ""; - if(!is_null($h)) $html .= "

$h

"; - if(!is_null($b)) $html .= "
$b
"; - $html .= "
"; - return $html; - } } ?> diff --git a/themes/futaba/layout.class.php b/themes/futaba/layout.class.php index c4136b5e..d540a20c 100644 --- a/themes/futaba/layout.class.php +++ b/themes/futaba/layout.class.php @@ -21,10 +21,10 @@ class Layout { foreach($page->blocks as $block) { switch($block->section) { case "left": - $left_block_html .= $this->block_to_html($block, true, "left"); + $left_block_html .= $block->get_html(true); break; case "main": - $main_block_html .= $this->block_to_html($block, false, "main"); + $main_block_html .= $block->get_html(false); break; case "subheading": $sub_block_html .= $block->body; // $this->block_to_html($block, true); @@ -93,16 +93,5 @@ $header_html EOD; } - - function block_to_html($block, $hidable=false, $salt="") { - $h = $block->header; - $b = $block->body; - $i = str_replace(' ', '_', $h) . $salt; - $html = "
"; - if(!is_null($h)) $html .= "\n

$h

\n"; - if(!is_null($b)) $html .= "
$b
\n"; - $html .= "
"; - return $html; - } } ?> diff --git a/themes/warm/layout.class.php b/themes/warm/layout.class.php index 3b9ea966..7ddb363a 100644 --- a/themes/warm/layout.class.php +++ b/themes/warm/layout.class.php @@ -28,13 +28,13 @@ class Layout { foreach($page->blocks as $block) { switch($block->section) { case "left": - $left_block_html .= $this->block_to_html($block, true, "left"); + $left_block_html .= $block->get_html(true); break; case "head": - $head_block_html .= "".$this->block_to_html($block, false, "head").""; + $head_block_html .= "".$block->get_html(false).""; break; case "main": - $main_block_html .= $this->block_to_html($block, false, "main"); + $main_block_html .= $block->get_html(false); break; case "subheading": $sub_block_html .= $block->body; // $this->block_to_html($block, true); @@ -99,19 +99,5 @@ $header_html EOD; } - - /** - * A handy function which does exactly what it says in the method name - */ - private function block_to_html($block, $hidable=false, $salt="") { - $h = $block->header; - $b = $block->body; - $i = str_replace(' ', '_', $h) . $salt; - $html = "
"; - if(!is_null($h)) $html .= "

$h

"; - if(!is_null($b)) $html .= "
$b
"; - $html .= "
"; - return $html; - } } ?>