/themes/flat/layout.class.php

https://github.com/snowstrypes/shimmie2 · PHP · 136 lines · 113 code · 13 blank · 10 comment · 10 complexity · 080fe4d0c33a82db14f335db697930fa MD5 · raw file

  1. <?php
  2. /**
  3. * A class to turn a Page data structure into a blob of HTML
  4. */
  5. class Layout {
  6. /**
  7. * turns the Page into HTML
  8. */
  9. public function display_page(Page $page) {
  10. global $config;
  11. $theme_name = $config->get_string('theme', 'default');
  12. $data_href = get_base_href();
  13. $contact_link = $config->get_string('contact_link');
  14. $header_html = "";
  15. ksort($page->html_headers);
  16. foreach($page->html_headers as $line) {
  17. $header_html .= "\t\t$line\n";
  18. }
  19. $left_block_html = "";
  20. $main_block_html = "";
  21. $sub_block_html = "";
  22. foreach($page->blocks as $block) {
  23. switch($block->section) {
  24. case "left":
  25. $left_block_html .= $this->block_to_html($block, true, "left");
  26. break;
  27. case "main":
  28. $main_block_html .= $this->block_to_html($block, false, "main");
  29. break;
  30. case "subheading":
  31. $sub_block_html .= $this->block_to_html($block, false, "main");
  32. break;
  33. default:
  34. print "<p>error: {$block->header} using an unknown section ({$block->section})";
  35. break;
  36. }
  37. }
  38. $debug = get_debug_info();
  39. $contact = empty($contact_link) ? "" : "<br><a href='$contact_link'>Contact</a>";
  40. $subheading = empty($page->subheading) ? "" : "<div id='subtitle'>{$page->subheading}</div>";
  41. $wrapper = "";
  42. if(strlen($page->heading) > 100) {
  43. $wrapper = ' style="height: 3em; overflow: auto;"';
  44. }
  45. print <<<EOD
  46. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
  47. <html>
  48. <head>
  49. <title>{$page->title}</title>
  50. <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
  51. <link rel="stylesheet" href="$data_href/themes/$theme_name/style.css" type="text/css">
  52. $header_html
  53. </head>
  54. <body>
  55. <h1$wrapper>{$page->heading}</h1>
  56. $subheading
  57. $sub_block_html
  58. <div id="nav">$left_block_html</div>
  59. <div id="body">$main_block_html</div>
  60. <div id="footer">
  61. Images &copy; their respective owners,
  62. <a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy;
  63. <a href="http://www.shishnet.org/">Shish</a> &amp; Co 2007-2011,
  64. based on the Danbooru concept.
  65. $debug
  66. $contact
  67. </div>
  68. </body>
  69. </html>
  70. EOD;
  71. }
  72. /**
  73. * A handy function which does exactly what it says in the method name
  74. */
  75. private function block_to_html($block, $hidable=false, $salt="") {
  76. $h = $block->header;
  77. $b = $block->body;
  78. $html = "";
  79. $i = str_replace(' ', '_', $h) . $salt;
  80. if($hidable) $html .= "
  81. <script type='text/javascript'><!--
  82. $(document).ready(function() {
  83. $(\"#$i-toggle\").click(function() {
  84. $(\"#$i\").slideToggle(\"slow\", function() {
  85. if($(\"#$i\").is(\":hidden\")) {
  86. $.cookie(\"$i-hidden\", 'true', {path: '/'});
  87. }
  88. else {
  89. $.cookie(\"$i-hidden\", 'false', {path: '/'});
  90. }
  91. });
  92. });
  93. if($.cookie(\"$i-hidden\") == 'true') {
  94. $(\"#$i\").hide();
  95. }
  96. });
  97. //--></script>
  98. ";
  99. if(!is_null($h)) $html .= "
  100. <div class='hrr' id='$i-toggle'>
  101. <div class='hrrtop'><div></div></div>
  102. <div class='hrrcontent'><h3>$h</h3></div>
  103. <div class='hrrbot'><div></div></div>
  104. </div>
  105. ";
  106. if(!is_null($b)) {
  107. if(strpos($b, "<!-- cancel border -->")) {
  108. $html .= "<div class='blockbody' id='$i'>$b</div>";
  109. }
  110. else {
  111. $html .= "
  112. <div class='rr' id='$i'>
  113. <div class='rrtop'><div></div></div>
  114. <div class='rrcontent'><div class='blockbody'>$b</div></div>
  115. <div class='rrbot'><div></div></div>
  116. </div>
  117. ";
  118. }
  119. }
  120. return $html;
  121. }
  122. }
  123. ?>