consistent block rendering

This commit is contained in:
Shish 2012-03-12 04:39:04 +00:00
parent a5c8b132e7
commit c638af1d76
5 changed files with 32 additions and 68 deletions

View File

@ -9,12 +9,14 @@ class Block {
* @retval string * @retval string
*/ */
var $header; var $header;
/** /**
* The content * The content
* *
* @retval string * @retval string
*/ */
var $body; var $body;
/** /**
* Where the block should be placed. The default theme supports * Where the block should be placed. The default theme supports
* "main" and "left", other themes can add their own areas * "main" and "left", other themes can add their own areas
@ -22,6 +24,7 @@ class Block {
* @retval string * @retval string
*/ */
var $section; var $section;
/** /**
* How far down the section the block should appear, higher * How far down the section the block should appear, higher
* numbers appear lower. The scale is 0-100 by convention, * numbers appear lower. The scale is 0-100 by convention,
@ -31,11 +34,29 @@ class Block {
*/ */
var $position; 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->header = $header;
$this->body = $body; $this->body = $body;
$this->section = $section; $this->section = $section;
$this->position = $position; $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 = "<section id='$i'>";
$h_toggler = $hidable ? " shm-toggler" : "";
if(!is_null($h)) $html .= "<h3 data-toggle-sel='#$i' class='$h_toggler'>$h</h3>";
if(!is_null($b)) $html .= "<div class='blockbody'>$b</div>";
$html .= "</section>";
return $html;
} }
} }

View File

@ -66,7 +66,7 @@ class Layout {
foreach($page->blocks as $block) { foreach($page->blocks as $block) {
switch($block->section) { switch($block->section) {
case "left": case "left":
$left_block_html .= $this->block_to_html($block, true); $left_block_html .= $block->get_html(true);
break; break;
case "user": case "user":
$user_block_html .= $block->body; // $this->block_to_html($block, true); $user_block_html .= $block->body; // $this->block_to_html($block, true);
@ -78,7 +78,7 @@ class Layout {
if($block->header == "Images") { if($block->header == "Images") {
$block->header = "&nbsp;"; $block->header = "&nbsp;";
} }
$main_block_html .= $this->block_to_html($block, false); $main_block_html .= $block->get_html(false);
break; break;
default: default:
print "<p>error: {$block->header} using an unknown section ({$block->section})"; print "<p>error: {$block->header} using an unknown section ({$block->section})";
@ -234,23 +234,6 @@ $header_html
EOD; EOD;
} }
function block_to_html($block, $hidable=false) {
$h = $block->header;
$s = $block->section;
$b = $block->body;
$i = str_replace(' ', '_', $h.$s);
$html = "<section id='$i'>";
if($hidable) {
if(!is_null($h)) $html .= "\n<h3 class='shm-toggler' data-toggle-sel='#$i'>$h</h3>\n";
}
else {
if(!is_null($h)) $html .= "\n<h3>$h</h3>\n";
}
if(!is_null($b)) $html .= "<div class='blockbody'>$b</div>\n";
$html .= "</section>";
return $html;
}
private function navlinks($link, $desc, $pages_matched) { private function navlinks($link, $desc, $pages_matched) {
/** /**
* Woo! We can actually SEE THE CURRENT PAGE!! (well... see it highlighted in the menu.) * Woo! We can actually SEE THE CURRENT PAGE!! (well... see it highlighted in the menu.)

View File

@ -26,13 +26,13 @@ class Layout {
foreach($page->blocks as $block) { foreach($page->blocks as $block) {
switch($block->section) { switch($block->section) {
case "left": case "left":
$left_block_html .= $this->block_to_html($block, true, "left"); $left_block_html .= $block->get_html(true);
break; break;
case "main": case "main":
$main_block_html .= $this->block_to_html($block, false, "main"); $main_block_html .= $block->get_html(false);
break; break;
case "subheading": case "subheading":
$sub_block_html .= $this->block_to_html($block, false, "main"); $sub_block_html .= $block->get_html(false);
break; break;
default: default:
print "<p>error: {$block->header} using an unknown section ({$block->section})"; print "<p>error: {$block->header} using an unknown section ({$block->section})";
@ -85,20 +85,5 @@ $header_html
</html> </html>
EOD; 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 = "<section id='$i'>";
$h_toggler = $hidable ? " shm-toggler" : "";
if(!is_null($h)) $html .= "<h3 data-toggle-sel='#$i' class='$h_toggler'>$h</h3>";
if(!is_null($b)) $html .= "<div class='blockbody'>$b</div>";
$html .= "</section>";
return $html;
}
} }
?> ?>

View File

@ -21,10 +21,10 @@ class Layout {
foreach($page->blocks as $block) { foreach($page->blocks as $block) {
switch($block->section) { switch($block->section) {
case "left": case "left":
$left_block_html .= $this->block_to_html($block, true, "left"); $left_block_html .= $block->get_html(true);
break; break;
case "main": case "main":
$main_block_html .= $this->block_to_html($block, false, "main"); $main_block_html .= $block->get_html(false);
break; break;
case "subheading": case "subheading":
$sub_block_html .= $block->body; // $this->block_to_html($block, true); $sub_block_html .= $block->body; // $this->block_to_html($block, true);
@ -93,16 +93,5 @@ $header_html
</html> </html>
EOD; EOD;
} }
function block_to_html($block, $hidable=false, $salt="") {
$h = $block->header;
$b = $block->body;
$i = str_replace(' ', '_', $h) . $salt;
$html = "<section id='$i'>";
if(!is_null($h)) $html .= "\n<h3 data-toggle-sel='#$i' class='shm-toggler'>$h</h3>\n";
if(!is_null($b)) $html .= "<div class='blockbody'>$b</div>\n";
$html .= "</section>";
return $html;
}
} }
?> ?>

View File

@ -28,13 +28,13 @@ class Layout {
foreach($page->blocks as $block) { foreach($page->blocks as $block) {
switch($block->section) { switch($block->section) {
case "left": case "left":
$left_block_html .= $this->block_to_html($block, true, "left"); $left_block_html .= $block->get_html(true);
break; break;
case "head": case "head":
$head_block_html .= "<td width='250'><small>".$this->block_to_html($block, false, "head")."</small></td>"; $head_block_html .= "<td width='250'><small>".$block->get_html(false)."</small></td>";
break; break;
case "main": case "main":
$main_block_html .= $this->block_to_html($block, false, "main"); $main_block_html .= $block->get_html(false);
break; break;
case "subheading": case "subheading":
$sub_block_html .= $block->body; // $this->block_to_html($block, true); $sub_block_html .= $block->body; // $this->block_to_html($block, true);
@ -99,19 +99,5 @@ $header_html
</html> </html>
EOD; 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 = "<section id='$i'>";
if(!is_null($h)) $html .= "<h3 data-toggle-sel='#$i' class='shm-toggler'>$h</h3>";
if(!is_null($b)) $html .= "<div class='blockbody'>$b</div>";
$html .= "</section>";
return $html;
}
} }
?> ?>