This repository has been archived on 2024-09-05. You can view files and clone it, but cannot push or open issues or pull requests.
shimmie2/themes/default/layout.class.php

127 lines
3.1 KiB
PHP
Raw Normal View History

2009-07-06 11:31:40 +00:00
<?php
/**
* A class to turn a Page data structure into a blob of HTML
*/
2009-07-06 11:31:40 +00:00
class Layout {
/**
* turns the Page into HTML
*/
public function display_page(Page $page) {
2009-07-06 11:31:40 +00:00
global $config;
$theme_name = $config->get_string('theme', 'default');
$data_href = get_base_href();
$contact_link = $config->get_string('contact_link');
$header_html = "";
ksort($page->html_headers);
foreach($page->html_headers as $line) {
$header_html .= "\t\t$line\n";
2009-07-06 11:31:40 +00:00
}
$left_block_html = "";
$main_block_html = "";
$sub_block_html = "";
2009-07-06 11:31:40 +00:00
foreach($page->blocks as $block) {
switch($block->section) {
case "left":
$left_block_html .= $this->block_to_html($block, true, "left");
break;
case "main":
$main_block_html .= $this->block_to_html($block, false, "main");
break;
case "subheading":
$sub_block_html .= $this->block_to_html($block, false, "main");
break;
2009-07-06 11:31:40 +00:00
default:
print "<p>error: {$block->header} using an unknown section ({$block->section})";
break;
}
}
$debug = get_debug_info();
$contact = empty($contact_link) ? "" : "<br><a href='$contact_link'>Contact</a>";
$wrapper = "";
if(strlen($page->heading) > 100) {
$wrapper = ' style="height: 3em; overflow: auto;"';
}
print <<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>{$page->title}</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link rel="stylesheet" href="$data_href/themes/$theme_name/style.css" type="text/css">
<script src='$data_href/themes/$theme_name/sidebar.js' type='text/javascript'></script>
2009-07-06 11:31:40 +00:00
$header_html
</head>
<body>
<h1$wrapper>{$page->heading}</h1>
2010-04-26 05:04:36 +00:00
$sub_block_html
2009-07-06 11:31:40 +00:00
<div id="nav">$left_block_html</div>
<div id="body">$main_block_html</div>
<div id="footer">
Images &copy; their respective owners,
2010-01-03 09:41:31 +00:00
<a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy;
2011-01-01 15:58:44 +00:00
<a href="http://www.shishnet.org/">Shish</a> &amp; Co 2007-2011,
2009-07-06 11:31:40 +00:00
based on the Danbooru concept.
$debug
$contact
</div>
</body>
</html>
EOD;
}
/**
* A handy function which does exactly what it says in the method name
*/
private function block_to_html($block, $hidable=false, $salt="") {
2009-07-06 11:31:40 +00:00
$h = $block->header;
$b = $block->body;
$html = "";
$i = str_replace(' ', '_', $h) . $salt;
if($hidable) $html .= "
<script type='text/javascript'><!--
2009-07-07 12:42:34 +00:00
$(document).ready(function() {
$(\"#$i-toggle\").click(function() {
$(\"#$i\").slideToggle(\"slow\", function() {
if($(\"#$i\").is(\":hidden\")) {
$.cookie(\"$i-hidden\", 'true', {path: '/'});
}
else {
$.cookie(\"$i-hidden\", 'false', {path: '/'});
}
});
2009-07-07 12:42:34 +00:00
});
if($.cookie(\"$i-hidden\") == 'true') {
2009-07-07 13:48:59 +00:00
$(\"#$i\").hide();
}
2009-07-07 12:42:34 +00:00
});
2009-07-19 07:56:24 +00:00
//--></script>
";
if(!is_null($h)) $html .= "
2010-04-20 01:24:36 +00:00
<h3 id='$i-toggle' class='hrr'>$h</h3>
2009-07-06 11:31:40 +00:00
";
if(!is_null($b)) {
2010-04-20 01:24:36 +00:00
if(strpos($b, "<!-- cancel border -->") === FALSE) {
$html .= "<div class='blockbody brr' id='$i'>$b</div>";
2009-07-06 11:31:40 +00:00
}
else {
2010-04-20 01:24:36 +00:00
$html .= "<div class='blockbody' id='$i'>$b</div>";
2009-07-06 11:31:40 +00:00
}
}
return $html;
}
}
?>