consistent block rendering
This commit is contained in:
parent
a5c8b132e7
commit
c638af1d76
5 changed files with 32 additions and 68 deletions
|
@ -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 = "<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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 "<p>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 = "<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) {
|
||||
/**
|
||||
* Woo! We can actually SEE THE CURRENT PAGE!! (well... see it highlighted in the menu.)
|
||||
|
|
|
@ -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 "<p>error: {$block->header} using an unknown section ({$block->section})";
|
||||
|
@ -85,20 +85,5 @@ $header_html
|
|||
</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 = "<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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -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
|
|||
</html>
|
||||
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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
|
@ -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 .= "<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;
|
||||
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
|
|||
</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 = "<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;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
|
Reference in a new issue