PageRenderTime 25ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/themes/danbooru/layout.class.php

https://gitlab.com/dali99/shimmie2-Material-Theme
PHP | 267 lines | 183 code | 25 blank | 59 comment | 21 complexity | 4f39abba764f52c53b2680800006025c MD5 | raw file
  1. <?php
  2. /**
  3. * Name: Danbooru Theme
  4. * Author: Bzchan <bzchan@animemahou.com>
  5. * Link: http://trac.shishnet.org/shimmie2/
  6. * License: GPLv2
  7. * Description: This is a simple theme changing the css to make shimme
  8. * look more like danbooru as well as adding a custom links
  9. * bar and title to the top of every page.
  10. */
  11. //Small changes added by zshall <http://seemslegit.com>
  12. //Changed CSS and layout to make shimmie look even more like danbooru
  13. /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  14. Danbooru Theme - Notes (Bzchan)
  15. Files: default.php, style.css
  16. How to use a theme
  17. - Copy the danbooru folder with all its contained files into the "themes"
  18. directory in your shimmie installation.
  19. - Log into your shimmie and change the Theme in the Board Config to your
  20. desired theme.
  21. Changes in this theme include
  22. - Adding and editing various elements in the style.css file.
  23. - $site_name and $front_name retreival from config added.
  24. - $custom_link and $title_link preparation just before html is outputed.
  25. - Altered outputed html to include the custom links and removed heading
  26. from being displayed (subheading is still displayed)
  27. - Note that only the sidebar has been left aligned. Could not properly
  28. left align the main block because blocks without headers currently do
  29. not have ids on there div elements. (this was a problem because
  30. paginator block must be centered and everything else left aligned)
  31. Tips
  32. - You can change custom links to point to whatever pages you want as well as adding
  33. more custom links.
  34. - The main title link points to the Front Page set in your Board Config options.
  35. - The text of the main title is the Title set in your Board Config options.
  36. - Themes make no changes to your database or main code files so you can switch
  37. back and forward to other themes all you like.
  38. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
  39. class Layout {
  40. public function display_page($page) {
  41. global $config, $user;
  42. $theme_name = $config->get_string('theme');
  43. //$base_href = $config->get_string('base_href');
  44. $data_href = get_base_href();
  45. $contact_link = $config->get_string('contact_link');
  46. $header_html = "";
  47. ksort($page->html_headers);
  48. foreach($page->html_headers as $line) {
  49. $header_html .= "\t\t$line\n";
  50. }
  51. $left_block_html = "";
  52. $user_block_html = "";
  53. $main_block_html = "";
  54. $sub_block_html = "";
  55. foreach($page->blocks as $block) {
  56. switch($block->section) {
  57. case "left":
  58. $left_block_html .= $block->get_html(true);
  59. break;
  60. case "user":
  61. $user_block_html .= $block->body; // $this->block_to_html($block, true);
  62. break;
  63. case "subheading":
  64. $sub_block_html .= $block->body; // $this->block_to_html($block, true);
  65. break;
  66. case "main":
  67. if($block->header == "Images") {
  68. $block->header = "&nbsp;";
  69. }
  70. $main_block_html .= $block->get_html(false);
  71. break;
  72. default:
  73. print "<p>error: {$block->header} using an unknown section ({$block->section})";
  74. break;
  75. }
  76. }
  77. $debug = get_debug_info();
  78. $contact = empty($contact_link) ? "" : "<br><a href='mailto:$contact_link'>Contact</a>";
  79. if(empty($this->subheading)) {
  80. $subheading = "";
  81. }
  82. else {
  83. $subheading = "<div id='subtitle'>{$this->subheading}</div>";
  84. }
  85. $site_name = $config->get_string('title'); // bzchan: change from normal default to get title for top of page
  86. $main_page = $config->get_string('main_page'); // bzchan: change from normal default to get main page for top of page
  87. // bzchan: CUSTOM LINKS are prepared here, change these to whatever you like
  88. $custom_links = "";
  89. if($user->is_anonymous()) {
  90. $custom_links .= $this->navlinks(make_link('user_admin/login'), "My Account", array("user", "user_admin", "setup", "admin"));
  91. }
  92. else {
  93. $custom_links .= $this->navlinks(make_link('user'), "My Account", array("user", "user_admin", "setup", "admin"));
  94. }
  95. $custom_links .= $this->navlinks(make_link('post/list'), "Posts", array("post"));
  96. $custom_links .= $this->navlinks(make_link('comment/list'), "Comments", array("comment"));
  97. $custom_links .= $this->navlinks(make_link('tags'), "Tags", array("tags"));
  98. if(class_exists("Pools")) {
  99. $custom_links .= $this->navlinks(make_link('pool/list'), "Pools", array("pool"));
  100. }
  101. $custom_links .= $this->navlinks(make_link('upload'), "Upload", array("upload"));
  102. if(class_exists("Wiki")) {
  103. $custom_links .= $this->navlinks(make_link('wiki'), "Wiki", array("wiki"));
  104. $custom_links .= $this->navlinks(make_link('wiki/more'), "More &raquo;", array("wiki/more"));
  105. }
  106. $custom_sublinks = "";
  107. // hack
  108. $username = url_escape($user->name);
  109. // hack
  110. $qp = explode("/", ltrim(_get_query(), "/"));
  111. // php sucks
  112. switch($qp[0]) {
  113. default:
  114. $custom_sublinks .= $user_block_html;
  115. break;
  116. case "":
  117. # FIXME: this assumes that the front page is
  118. # post/list; in 99% of case it will either be
  119. # post/list or home, and in the latter case
  120. # the subnav links aren't shown, but it would
  121. # be nice to be correct
  122. case "post":
  123. case "upload":
  124. if(class_exists("NumericScore")){ $custom_sublinks .= "<li><b>Popular by </b><a href='".make_link('popular_by_day')."'>Day</a>/<a href='".make_link('popular_by_month')."'>Month</a>/<a href='".make_link('popular_by_year')."'>Year</a></li>";}
  125. $custom_sublinks .= "<li><a href='".make_link('post/list')."'>All</a></li>";
  126. if(class_exists("Favorites")){ $custom_sublinks .= "<li><a href='".make_link("post/list/favorited_by={$username}/1")."'>My Favorites</a></li>";}
  127. if(class_exists("RSS_Images")){ $custom_sublinks .= "<li><a href='".make_link('rss/images')."'>Feed</a></li>";}
  128. if(class_exists("RandomImage")){ $custom_sublinks .= "<li><a href='".make_link("random_image/view")."'>Random Image</a></li>";}
  129. if(class_exists("Wiki")){ $custom_sublinks .= "<li><a href='".make_link("wiki/posts")."'>Help</a></li>";
  130. }else{ $custom_sublinks .= "<li><a href='".make_link("ext_doc/index")."'>Help</a></li>";}
  131. break;
  132. case "comment":
  133. $custom_sublinks .= "<li><a href='".make_link('comment/list')."'>All</a></li>";
  134. $custom_sublinks .= "<li><a href='".make_link("ext_doc/comment")."'>Help</a></li>";
  135. break;
  136. case "pool":
  137. $custom_sublinks .= "<li><a href='".make_link('pool/list')."'>List</a></li>";
  138. $custom_sublinks .= "<li><a href='".make_link("pool/new")."'>Create</a></li>";
  139. $custom_sublinks .= "<li><a href='".make_link("pool/updated")."'>Changes</a></li>";
  140. $custom_sublinks .= "<li><a href='".make_link("ext_doc/pools")."'>Help</a></li>";
  141. break;
  142. case "wiki":
  143. $custom_sublinks .= "<li><a href='".make_link('wiki')."'>Index</a></li>";
  144. $custom_sublinks .= "<li><a href='".make_link("wiki/rules")."'>Rules</a></li>";
  145. $custom_sublinks .= "<li><a href='".make_link("ext_doc/wiki")."'>Help</a></li>";
  146. break;
  147. case "tags":
  148. case "alias":
  149. $custom_sublinks .= "<li><a href='".make_link('tags/map')."'>Map</a></li>";
  150. $custom_sublinks .= "<li><a href='".make_link('tags/alphabetic')."'>Alphabetic</a></li>";
  151. $custom_sublinks .= "<li><a href='".make_link('tags/popularity')."'>Popularity</a></li>";
  152. $custom_sublinks .= "<li><a href='".make_link('tags/categories')."'>Categories</a></li>";
  153. $custom_sublinks .= "<li><a href='".make_link('alias/list')."'>Aliases</a></li>";
  154. $custom_sublinks .= "<li><a href='".make_link("ext_doc/tag_edit")."'>Help</a></li>";
  155. break;
  156. }
  157. // bzchan: failed attempt to add heading after title_link (failure was it looked bad)
  158. //if($this->heading==$site_name)$this->heading = '';
  159. //$title_link = "<h1><a href='".make_link($main_page)."'>$site_name</a>/$this->heading</h1>";
  160. // bzchan: prepare main title link
  161. $title_link = "<h1 id='site-title'><a href='".make_link($main_page)."'>$site_name</a></h1>";
  162. if($page->left_enabled) {
  163. $left = "<nav>$left_block_html</nav>";
  164. $withleft = "withleft";
  165. }
  166. else {
  167. $left = "";
  168. $withleft = "noleft";
  169. }
  170. $flash = $page->get_cookie("flash_message");
  171. $flash_html = "";
  172. if($flash) {
  173. $flash_html = "<b id='flash'>".nl2br(html_escape($flash))." <a href='#' onclick=\"\$('#flash').hide(); return false;\">[X]</a></b>";
  174. }
  175. print <<<EOD
  176. <!doctype html>
  177. <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
  178. <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
  179. <!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
  180. <!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
  181. <head>
  182. <title>{$page->title}</title>
  183. $header_html
  184. <script src='$data_href/themes/$theme_name/script.js' type='text/javascript'></script>
  185. </head>
  186. <body>
  187. <header>
  188. $title_link
  189. <ul id="navbar" class="flat-list">
  190. $custom_links
  191. </ul>
  192. <ul id="subnavbar" class="flat-list">
  193. $custom_sublinks
  194. </ul>
  195. </header>
  196. $subheading
  197. $sub_block_html
  198. $left
  199. <article class="$withleft">
  200. $flash_html
  201. $main_block_html
  202. </article>
  203. <footer><em>
  204. Images &copy; their respective owners,
  205. <a href="http://code.shishnet.org/shimmie2/">Shimmie</a> &copy;
  206. <a href="http://www.shishnet.org/">Shish</a> &amp;
  207. <a href="https://github.com/shish/shimmie2/graphs/contributors">The Team</a>
  208. 2007-2014,
  209. based on the Danbooru concept.
  210. $debug
  211. $contact
  212. </em></footer>
  213. </body>
  214. </html>
  215. EOD;
  216. }
  217. private function navlinks($link, $desc, $pages_matched) {
  218. /**
  219. * Woo! We can actually SEE THE CURRENT PAGE!! (well... see it highlighted in the menu.)
  220. */
  221. $html = null;
  222. $url = ltrim(_get_query(), "/");
  223. $re1='.*?';
  224. $re2='((?:[a-z][a-z_]+))';
  225. if (preg_match_all("/".$re1.$re2."/is", $url, $matches)) {
  226. $url=$matches[1][0];
  227. }
  228. $count_pages_matched = count($pages_matched);
  229. for($i=0; $i < $count_pages_matched; $i++) {
  230. if($url == $pages_matched[$i]) {
  231. $html = "<li class='current-page'><a href='$link'>$desc</a></li>";
  232. }
  233. }
  234. if(is_null($html)) {$html = "<li><a class='tab' href='$link'>$desc</a></li>";}
  235. return $html;
  236. }
  237. }