PageRenderTime 54ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/themes/iui/themelet.class.php

https://github.com/zshall/kimica
PHP | 278 lines | 231 code | 25 blank | 22 comment | 16 complexity | 3bbf16f098ccbbcb0f15cd7725d7f99a MD5 | raw file
  1. <?php
  2. class Themelet {
  3. /**
  4. * Generic error message display
  5. */
  6. public function display_error(Page $page, $title, $message) {
  7. $page->set_title($title);
  8. $page->set_heading($title);
  9. $page->add_block(new NavBlock());
  10. $page->add_block(new Block("Error", $message));
  11. }
  12. /**
  13. * A specific, common error message
  14. */
  15. public function display_permission_denied(Page $page) {
  16. header("HTTP/1.0 403 Permission Denied");
  17. $this->display_error($page, "Permission Denied", "You do not have permission to access this page");
  18. }
  19. /**
  20. * Generic thumbnail code; returns HTML rather than adding
  21. * a block since thumbs tend to go inside blocks...
  22. */
  23. public function build_thumb_html(Image $image, $query=null) {
  24. global $config;
  25. $i_id = int_escape($image->id);
  26. $h_view_link = make_link("post/view/$i_id", $query);
  27. $h_tip = html_escape($image->get_tooltip());
  28. $h_thumb_link = $image->get_thumb_link();
  29. $tsize = get_thumbnail_size($image->width, $image->height);
  30. return "<a href='$h_view_link'><img id='$i_id' title='$h_tip' alt='$h_tip' style='height: {$tsize[1]}px; width: {$tsize[0]}px;' src='$h_thumb_link' /></a>";
  31. }
  32. /**
  33. * Add a generic paginator
  34. */
  35. public function display_paginator(Page $page, $base, $query, $page_number, $total_pages) {
  36. if($total_pages == 0) $total_pages = 1;
  37. $body = $this->build_paginator($page_number, $total_pages, $base, $query);
  38. $page->add_block(new Block(null, $body, "main", 90));
  39. }
  40. private function gen_page_link($base_url, $query, $page, $name) {
  41. $link = make_link("$base_url/$page", $query);
  42. return "<a href='$link'>$name</a>";
  43. }
  44. private function gen_page_link_block($base_url, $query, $page, $current_page, $name) {
  45. $paginator = "";
  46. if($page == $current_page) $paginator .= "<b>";
  47. $paginator .= $this->gen_page_link($base_url, $query, $page, $name);
  48. if($page == $current_page) $paginator .= "</b>";
  49. return $paginator;
  50. }
  51. private function build_paginator($current_page, $total_pages, $base_url, $query) {
  52. $next = $current_page + 1;
  53. $prev = $current_page - 1;
  54. $rand = rand(1, $total_pages);
  55. $at_start = ($current_page <= 1 || $total_pages <= 1);
  56. $at_end = ($current_page >= $total_pages);
  57. $first_html = $at_start ? "First" : $this->gen_page_link($base_url, $query, 1, "First");
  58. $prev_html = $at_start ? "Prev" : $this->gen_page_link($base_url, $query, $prev, "Prev");
  59. $random_html = $this->gen_page_link($base_url, $query, $rand, "Random");
  60. $next_html = $at_end ? "Next" : $this->gen_page_link($base_url, $query, $next, "Next");
  61. $last_html = $at_end ? "Last" : $this->gen_page_link($base_url, $query, $total_pages, "Last");
  62. $start = $current_page-5 > 1 ? $current_page-5 : 1;
  63. $end = $start+10 < $total_pages ? $start+10 : $total_pages;
  64. $pages = array();
  65. foreach(range($start, $end) as $i) {
  66. $pages[] = $this->gen_page_link_block($base_url, $query, $i, $current_page, $i);
  67. }
  68. $pages_html = implode(" | ", $pages);
  69. return "<p class='paginator'>$first_html | $prev_html | $random_html | $next_html | $last_html".
  70. "<br>&lt;&lt; $pages_html &gt;&gt;</p>";
  71. }
  72. }
  73. /**
  74. * Name: iNterface
  75. * Author: Zach Hall <zach@sosguy.net>
  76. * Link: http://seemslegit.com
  77. * License: GPLv2
  78. * Description: The frontend for the iui theme.
  79. */
  80. class iui_interface extends SimpleExtension {
  81. public function onPageRequest($event) {
  82. // general
  83. if($event->page_matches("i")) {
  84. global $page;
  85. $page->add_block(new Block("iNterface", $this->get_interface(), "main", 10));
  86. }
  87. if($event->page_matches("i/o/o")) {
  88. global $page;
  89. setcookie("shimmie_mobile_optout", true, NULL, "/");
  90. $page->set_mode("redirect");
  91. $page->set_redirect(make_link(""));
  92. }
  93. // specific functions
  94. if($event->page_matches("ir/t/a")) {
  95. global $database;
  96. global $config;
  97. global $page;
  98. $tags_min = $config->get_int('tags_min');
  99. $result = $database->execute(
  100. "SELECT tag,count FROM tags WHERE count >= ? ORDER BY tag",
  101. array($tags_min));
  102. $tag_data = $result->GetArray();
  103. $html1 = "<ul id='tag_list_alpha' selected='true'>";
  104. $html2 = "";
  105. $grouplist = "";
  106. $lastLetter = "";
  107. foreach($tag_data as $row) {
  108. $h_tag = html_escape($row['tag']);
  109. $count = $row['count'];
  110. if($lastLetter != strtolower(substr($h_tag, 0, 1))) {
  111. $lastLetter = strtolower(substr($h_tag, 0, 1));
  112. $html2 .= "</ul><ul id='$lastLetter'><li class='group'>$lastLetter</li>";
  113. $grouplist .= "<li><a href='#$lastLetter'>$lastLetter</a></li>";
  114. }
  115. $link = $this->tag_link($row['tag']);
  116. $html2 .= "<li><a href='$link'>$h_tag&nbsp;($count)</a></li>\n";
  117. }
  118. $grouplist .= "</ul>";
  119. $html2 .= "</ul>";
  120. $html = $html1 . $grouplist . $html2;
  121. $page->set_mode("data");
  122. $page->set_data($html);
  123. }
  124. if($event->page_matches("ir/t/p")) {
  125. global $database;
  126. global $config;
  127. global $page;
  128. $tags_min = $config->get_int('tags_min');
  129. $result = $database->execute(
  130. "SELECT tag,count,FLOOR(LOG(count)) AS scaled FROM tags WHERE count >= ? ORDER BY count DESC, tag ASC",
  131. array($tags_min));
  132. $tag_data = $result->GetArray();
  133. $html1 = "<ul id='tag_list_popular' selected='true'>
  134. <li>Results grouped by log<sub>e</sub>(n)</li>";
  135. $html2 = "";
  136. $grouplist = "";
  137. $lastLog = "";
  138. foreach($tag_data as $row) {
  139. $h_tag = html_escape($row['tag']);
  140. $count = $row['count'];
  141. $scaled = $row['scaled'];
  142. if($lastLog != $scaled) {
  143. $lastLog = $scaled;
  144. $html2 .= "</ul><ul id='$lastLog'><li class='group'>$lastLog</li>";
  145. $grouplist .= "<li><a href='#$lastLog'>$lastLog</a></li>";
  146. }
  147. $link = $this->tag_link($row['tag']);
  148. $html2 .= "<li><a href='$link'>$h_tag&nbsp;($count)</a></li>\n";
  149. }
  150. $grouplist .= "</ul>";
  151. $html2 .= "</ul>";
  152. $html = $html1 . $grouplist . $html2;
  153. $page->set_mode("data");
  154. $page->set_data($html);
  155. }
  156. }
  157. private function tag_link($tag) {
  158. $u_tag = url_escape($tag);
  159. return make_link("post/list/$u_tag/1");
  160. }
  161. private function get_interface() {
  162. global $database, $page, $config;
  163. $debug = get_debug_info();
  164. $contact_link = $config->get_string('contact_link');
  165. $contact = empty($contact_link) ? "" : "<br><a class='whiteButton iui-cache-update-button' type='button' target='_blank' href='$contact_link'>Contact</a>";
  166. $stat = array();
  167. $stat['images'] = $database->db->GetOne("SELECT COUNT(*) FROM images");
  168. $stat['comments'] = $database->db->GetOne("SELECT COUNT(*) FROM comments");
  169. $stat['users'] = $database->db->GetOne("SELECT COUNT(*) FROM users");
  170. $stat['tags'] = $database->db->GetOne("SELECT COUNT(*) FROM tags");
  171. $stat['image_tags'] = $database->db->GetOne("SELECT COUNT(*) FROM image_tags");
  172. $sitename = $config->get_string("site_title");
  173. $html = "";
  174. $html .= "
  175. <ul id='home' title='$sitename' selected='true'>
  176. <li><a href='#images'>Images</a></li>
  177. <li><a href='#tags'>Tags</a></li>
  178. <li><a href='#comments'>Comments</a></li>
  179. <li><a href='#account'>Account</a></li>
  180. <li><a href='#stats'>Stats / About</a></li>
  181. <li><span style='color:red'>Full Site</span> (Locked for testing)</li>
  182. </ul>
  183. <ul id='images' title='Images'>
  184. <li><a href='/post/list'>Newest</a></li>
  185. <li><a href='/featured_image/view'>Featured</a></li>
  186. <li><a href='/random_image/view'>Random</a></li>
  187. </ul>
  188. <ul id='tags' title='Tags'>
  189. <li><a href='/ir/t/a'>List</a></li>
  190. <li><a href='/ir/t/p'>Popular</a></li>
  191. </ul>
  192. <div id='stats' class='panel' title='Stats / About'>
  193. <h2>Shimmie 2.3</h2>
  194. <fieldset>
  195. <div class='row'>
  196. <label>Images</label>
  197. <span>{$stat['images']}</span>
  198. </div>
  199. <div class='row'>
  200. <label>Comments</label>
  201. <span>{$stat['comments']}</span>
  202. </div>
  203. <div class='row'>
  204. <label>Users</label>
  205. <span>{$stat['users']}</span>
  206. </div>
  207. <div class='row'>
  208. <label>Tags</label>
  209. <span>{$stat['tags']}</span>
  210. </div>
  211. <div class='row'>
  212. <label>Image Tags</label>
  213. <span>{$stat['image_tags']}</span>
  214. </div>
  215. </fieldset>
  216. <h2>Copyright Info</h2>
  217. <fieldset>
  218. <div class='row'>
  219. <p>
  220. Images &copy; their respective owners,
  221. <a href='http://code.shishnet.org/shimmie2/'>Shimmie</a> &copy;
  222. <a href='http://www.shishnet.org/'>Shish</a> &amp; Co 2007-2010,
  223. based on the Danbooru concept.
  224. </p>
  225. </div>
  226. </fieldset>
  227. $contact
  228. $debug
  229. </div>
  230. <form id='optout' class='dialog' action='/ir/o/o'>
  231. <fieldset>
  232. <h1>Leaving Mobile Site</h1>
  233. <a class='button leftButton' type='cancel'>Cancel</a>
  234. <a class='button blueButton' href='iphone/optout' target='_blank'>OK</a>
  235. <label>You can return to the mobile site by rebooting your browser. (Clearing cookies)</label>
  236. </fieldset>
  237. </form>
  238. <form id='searchForm' class='dialog' action='/post/list' method='GET'>
  239. <fieldset>
  240. <h1>Image Search</h1>
  241. <a class='button leftButton' type='cancel'>Cancel</a>
  242. <a class='button blueButton' type='submit'>Search</a>
  243. <label>Tags:</label>
  244. <input id='search_input' name='search' type='text'
  245. value='' autocomplete='off' />
  246. <input type='hidden' name='q' value='/post/list'>
  247. </fieldset>
  248. </form>
  249. ";
  250. return $html;
  251. }
  252. }
  253. ?>