danbooru theme to 2.1

git-svn-id: file:///home/shish/svn/shimmie2/trunk@467 7f39781d-f577-437e-ae19-be835c7a54ca
This commit is contained in:
shish 2007-08-23 11:15:18 +00:00
parent 862e647365
commit 4191df847f
7 changed files with 16 additions and 428 deletions

View file

@ -1,6 +1,6 @@
<?php
class CommentListTheme extends Themelet {
class CustomCommentListTheme extends CommentListTheme {
public function display_page_start($page, $page_number, $total_pages) {
$prev = $page_number - 1;
$next = $page_number + 1;
@ -40,15 +40,7 @@ class CommentListTheme extends Themelet {
}
private function comments_to_html($comments, $trim=false) {
$html = "";
foreach($comments as $comment) {
$html .= $this->comment_to_html($comment, $trim);
}
return $html;
}
private function comment_to_html($comment, $trim=false) {
protected function comment_to_html($comment, $trim=false) {
global $user;
$tfe = new TextFormattingEvent($comment->comment);
@ -71,19 +63,6 @@ class CommentListTheme extends Themelet {
return "<p class='comment'>$h_userlink $h_dellink<br/><b>Posted on $h_posted</b><br/>$h_comment</p>";
}
// FIXME: privatise this
public function build_postbox($image_id) {
$i_image_id = int_escape($image_id);
return "
<form action='".make_link("comment/add")."' method='POST'>
<input type='hidden' name='image_id' value='$i_image_id' />
<textarea name='comment' rows='5' cols='50'></textarea>
<br><input type='submit' value='Post' />
</form>
";
}
public function add_comment_list($page, $image, $comments, $position, $with_postbox) {
$count = count($comments);

View file

@ -1,12 +1,6 @@
<?php
class IndexTheme extends Themelet {
public function set_page($page_number, $total_pages, $search_terms) {
$this->page_number = $page_number;
$this->total_pages = $total_pages;
$this->search_terms = $search_terms;
}
class CustomIndexTheme extends IndexTheme {
public function display_page($page, $images) {
global $config;
@ -40,7 +34,7 @@ class IndexTheme extends Themelet {
}
private function build_navigation($page_number, $total_pages, $search_terms) {
protected function build_navigation($page_number, $total_pages, $search_terms) {
$h_search_string = count($search_terms) == 0 ? "" : html_escape(implode(" ", $search_terms));
$h_search_link = make_link();
$h_search = "
@ -53,30 +47,5 @@ class IndexTheme extends Themelet {
return $h_search;
}
private function build_table($images, $query) {
global $config;
$width = $config->get_int('index_width');
$height = $config->get_int('index_height');
$table = "<table>\n";
for($i=0; $i<$height; $i++) {
$table .= "<tr>\n";
for($j=0; $j<$width; $j++) {
$image = isset($images[$i*$width+$j]) ? $images[$i*$width+$j] : null;
if(!is_null($image)) {
$table .= "\t<td>" . build_thumb_html($image, $query) . "</td>\n";
}
else {
$table .= "\t<td>&nbsp;</td>\n";
}
}
$table .= "</tr>\n";
}
$table .= "</table>\n";
return $table;
}
}
?>

View file

@ -156,6 +156,9 @@ A:hover {text-decoration: underline;}
padding: 8px 4px 8px 4px;
}
#large_upload_form {
width: 600px;
}
.setupblock {
border: 1px solid #AAA;
padding: 8px;

View file

@ -1,21 +1,9 @@
<?php
class TagListTheme extends Themelet {
class CustomTagListTheme extends TagListTheme {
var $heading = "";
var $list = "";
public function set_heading($text) {
$this->heading = $text;
}
public function set_tag_list($list) {
$this->list = $list;
}
public function set_navigation($nav) {
$this->navigation = $nav;
}
public function display_page($page) {
$page->disable_left();
$page->set_title("Tag List");
@ -23,145 +11,5 @@ class TagListTheme extends Themelet {
$page->add_block(new Block("Navigation", str_replace("<br>", ", ", $this->navigation), "main", 0));
$page->add_block(new Block("&nbsp;", $this->list));
}
// =======================================================================
/*
* $tag_infos = array(
* array('tag' => $tag, 'count' => $number_of_uses),
* ...
* )
*/
public function display_related_block($page, $tag_infos) {
global $config;
$html = "";
$n = 0;
foreach($tag_infos as $row) {
$tag = $row['tag'];
$h_tag = html_escape($tag);
$h_tag_no_underscores = str_replace("_", " ", $h_tag);
$count = $row['count'];
if($n++) $html .= "\n<br/>";
if(!is_null($config->get_string('info_link'))) {
$link = str_replace('$tag', $tag, $config->get_string('info_link'));
$html .= " <a class='tag_info_link' href='$link'>?</a>";
}
$link = $this->tag_link($row['tag']);
$html .= " <a class='tag_name' href='$link'>$h_tag_no_underscores</a>";
}
$page->add_block(new Block("Related", $html, "left"));
}
/*
* $tag_infos = array(
* array('tag' => $tag, 'count' => $number_of_uses),
* ...
* )
*/
public function display_popular_block($page, $tag_infos) {
global $config;
$html = "";
$n = 0;
foreach($tag_infos as $row) {
$tag = $row['tag'];
$h_tag = html_escape($tag);
$h_tag_no_underscores = str_replace("_", " ", $h_tag);
$count = $row['count'];
if($n++) $html .= "\n<br/>";
if(!is_null($config->get_string('info_link'))) {
$link = str_replace('$tag', $tag, $config->get_string('info_link'));
$html .= " <a class='tag_info_link' href='$link'>?</a>";
}
$link = $this->tag_link($row['tag']);
$html .= " <a class='tag_name' href='$link'>$h_tag_no_underscores</a>";
if($config->get_bool("tag_list_numbers")) {
$html .= " <span class='tag_count'>$count</span>";
}
}
$html .= "<p><a class='more' href='".make_link("tags")."'>Full List</a>\n";
$page->add_block(new Block("Popular Tags", $html, "left", 60));
}
/*
* $tag_infos = array(
* array('tag' => $tag),
* ...
* )
* $search = the current array of tags being searched for
*/
public function display_refine_block($page, $tag_infos, $search) {
global $config;
$html = "";
$n = 0;
foreach($tag_infos as $row) {
$tag = $row['tag'];
$h_tag = html_escape($tag);
$h_tag_no_underscores = str_replace("_", " ", $h_tag);
if($n++) $html .= "\n<br/>";
if(!is_null($config->get_string('info_link'))) {
$link = str_replace('$tag', $tag, $config->get_string('info_link'));
$html .= " <a class='tag_info_link' href='$link'>?</a>";
}
$link = $this->tag_link($row['tag']);
$html .= " <a class='tag_name' href='$link'>$h_tag_no_underscores</a>";
$html .= $this->ars($tag, $search);
}
$page->add_block(new Block("Refine Search", $html, "left", 60));
}
private function ars($tag, $tags) {
$html = "";
$html .= " <span class='ars'>(";
$html .= $this->get_add_link($tags, $tag);
$html .= $this->get_remove_link($tags, $tag);
$html .= $this->get_subtract_link($tags, $tag);
$html .= ")</span>";
return $html;
}
private function get_remove_link($tags, $tag) {
if(!in_array($tag, $tags) && !in_array("-$tag", $tags)) {
return "";
}
else {
$tags = array_remove($tags, $tag);
$tags = array_remove($tags, "-$tag");
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Remove' rel='nofollow'>R</a>";
}
}
private function get_add_link($tags, $tag) {
if(in_array($tag, $tags)) {
return "";
}
else {
$tags = array_remove($tags, "-$tag");
$tags = array_add($tags, $tag);
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Add' rel='nofollow'>A</a>";
}
}
private function get_subtract_link($tags, $tag) {
if(in_array("-$tag", $tags)) {
return "";
}
else {
$tags = array_remove($tags, $tag);
$tags = array_add($tags, "-$tag");
return "<a href='".$this->tag_link(join(' ', $tags))."' title='Subtract' rel='nofollow'>S</a>";
}
}
private function tag_link($tag) {
$u_tag = url_escape($tag);
return make_link("post/list/$u_tag/1");
}
}
?>

View file

@ -1,6 +1,6 @@
<?php
class UploadTheme extends Themelet {
class CustomUploadTheme extends UploadTheme {
public function display_block($page) {
// this theme links to /upload
// $page->add_block(new Block("Upload", $this->build_upload_block(), "left", 20));
@ -8,86 +8,7 @@ class UploadTheme extends Themelet {
public function display_page($page) {
$page->disable_left();
global $config;
$tl_enabled = ($config->get_string("transload_engine", "none") != "none");
$upload_list = "";
for($i=0; $i<$config->get_int('upload_count'); $i++) {
$n = $i + 1;
$width = $tl_enabled ? "35%" : "80%";
$upload_list .= "
<tr>
<td>File $n</td>
<td style='width: $width;'><input accept='image/jpeg,image/png,image/gif' id='data$i' name='data$i' type='file'></td>
";
if($tl_enabled) {
$upload_list .= "
<td>URL $n</td>
<td><input id='url$i' name='url$i' type='text'></td>
";
}
$upload_list .= "
</tr>
";
}
$max_size = $config->get_int('upload_size');
$max_kb = to_shorthand_int($max_size);
$html = "
<form enctype='multipart/form-data' action='".make_link("upload")."' method='POST'>
<table id='large_upload_form'>
$upload_list
<tr><td>Tags</td><td colspan='3'><input id='tagBox' name='tags' type='text' value='tagme' autocomplete='off'></td></tr>
<tr><td>Source</td><td colspan='3'><input name='source' type='text'></td></tr>
<tr><td colspan='4'><input type='submit' value='Post'></td></tr>
</table>
</form>
<div id='upload_completions' style='clear: both;'><small>(Max file size is $max_kb)</small></div>
";
$page->set_title("Upload");
$page->set_heading("Upload");
$page->add_block(new NavBlock());
$page->add_block(new Block("Upload", $html, "main", 20));
}
public function display_upload_status($page, $ok) {
if($ok) {
$page->set_mode("redirect");
$page->set_redirect(make_link());
}
else {
$page->set_title("Upload Status");
$page->set_heading("Upload Status");
$page->add_block(new NavBlock());
}
}
public function display_upload_error($page, $title, $message) {
$page->add_block(new Block($title, $message));
}
private function build_upload_block() {
global $config;
$upload_list = "";
for($i=0; $i<$config->get_int('upload_count'); $i++) {
if($i == 0) $style = ""; // "style='display:visible'";
else $style = "style='display:none'";
$upload_list .= "<input accept='image/jpeg,image/png,image/gif' size='10' ".
"id='data$i' name='data$i' $style onchange=\"showUp('data".($i+1)."')\" type='file'>\n";
}
$max_size = $config->get_int('upload_size');
$max_kb = to_shorthand_int($max_size);
// <input type='hidden' name='max_file_size' value='$max_size' />
return "
<form enctype='multipart/form-data' action='".make_link("upload")."' method='POST'>
$upload_list
<input id='tagBox' name='tags' type='text' value='tagme' autocomplete='off'>
<input type='submit' value='Post'>
</form>
<div id='upload_completions' style='clear: both;'><small>(Max file size is $max_kb)</small></div>
";
parent::display_page($page);
}
}
?>

View file

@ -1,6 +1,6 @@
<?php
class UserPageTheme extends Themelet {
class CustomUserPageTheme extends UserPageTheme {
public function display_login_page($page) {
$page->set_title("Login");
$page->set_heading("Login");
@ -49,31 +49,6 @@ class UserPageTheme extends Themelet {
$page->add_block(new Block("Signup", $html));
}
public function display_signups_disabled($page) {
$page->set_title("Signups Disabled");
$page->set_heading("Signups Disabled");
$page->add_block(new NavBlock());
$page->add_block(new Block("Signups Disabled",
"The board admin has disabled the ability to create new accounts~"));
}
public function display_login_block($page) {
global $config;
$html = "
<form action='".make_link("user_admin/login")."' method='POST'>
<table border='1' summary='Login Form'>
<tr><td width='70'>Name</td><td width='70'><input type='text' name='user'></td></tr>
<tr><td>Password</td><td><input type='password' name='pass'></td></tr>
<tr><td colspan='2'><input type='submit' name='gobu' value='Log In'></td></tr>
</table>
</form>
";
if($config->get_bool("login_signup_enabled")) {
$html .= "<small><a href='".make_link("user_admin/create")."'>Create Account</a></small>";
}
$page->add_block(new Block("Login", $html, "left", 90));
}
public function display_ip_list($page, $uploads, $comments) {
$html = "<table id='ip-history' style='width: 400px;'>";
$html .= "<tr><td>Uploaded from: ";
@ -91,47 +66,11 @@ class UserPageTheme extends Themelet {
}
public function display_user_page($page, $duser, $user) {
$page->set_title("{$duser->name}'s Page");
$page->set_heading("{$duser->name}'s Page");
$page->add_block(new NavBlock());
$page->add_block(new Block("Stats", $this->build_stats($duser)));
$page->disable_left();
if(!$user->is_anonymous()) {
if($user->id == $duser->id || $user->is_admin()) {
$page->add_block(new Block("Options", $this->build_options($duser), "main", 20));
}
if($user->is_admin()) {
$page->add_block(new Block("More Options", $this->build_more_options($duser)));
}
}
parent::display_user_page($page, $duser, $user);
}
private function build_stats($duser) {
global $database;
global $config;
$i_days_old = int_escape($duser->get_days_old());
$h_join_date = html_escape($duser->join_date);
$i_image_count = int_escape($duser->get_image_count());
$i_comment_count = int_escape($duser->get_comment_count());
$i_days_old2 = ($i_days_old == 0) ? 1 : $i_days_old;
$h_image_rate = sprintf("%3.1f", ($i_image_count / $i_days_old2));
$h_comment_rate = sprintf("%3.1f", ($i_comment_count / $i_days_old2));
$u_name = url_escape($duser->name);
$images_link = make_link("post/list/user=$u_name/1");
return "
Join date: $h_join_date ($i_days_old days old)
<br><a href='$images_link'>Images uploaded</a>: $i_image_count ($h_image_rate / day)
<br>Comments made: $i_comment_count ($h_comment_rate / day)
";
}
private function build_options($duser) {
protected function build_options($duser) {
global $database;
global $config;
@ -150,25 +89,6 @@ class UserPageTheme extends Themelet {
";
return $html;
}
private function build_more_options($duser) {
global $database;
global $config;
$i_user_id = int_escape($duser->id);
$h_is_admin = $duser->is_admin() ? " checked" : "";
$h_is_enabled = $duser->is_enabled() ? " checked" : "";
$html = "
<form action='".make_link("user_admin/set_more")."' method='POST'>
<input type='hidden' name='id' value='$i_user_id'>
Admin: <input name='admin' type='checkbox'$h_is_admin>
<br>Enabled: <input name='enabled' type='checkbox'$h_is_enabled>
<p><input type='submit' value='Set'>
</form>
";
return $html;
}
// }}}
}
?>

View file

@ -1,6 +1,6 @@
<?php
class ViewTheme extends Themelet {
class CustomViewTheme extends ViewTheme {
public function display_image_not_found($page, $image_id) {
$page->set_title("Image not found");
$page->set_heading("Image not found");
@ -9,64 +9,12 @@ class ViewTheme extends Themelet {
"No image in the database has the ID #$image_id"));
}
public function display_page($page, $image) {
$page->set_title("Image {$image->id}: ".html_escape($image->get_tag_list()));
$page->set_heading(html_escape($image->get_tag_list()));
$page->add_block(new Block("Navigation", $this->build_navigation($image->id), "left", 0));
$page->add_block(new Block("Image", $this->build_image_view($image), "main", 0));
$page->add_block(new Block(null, $this->build_info($image), "main", 10));
}
var $pin = null;
private function build_pin($image_id) {
if(!is_null($this->pin)) {
return $this->pin;
}
global $database;
if(isset($_GET['search'])) {
$search_terms = explode(' ', $_GET['search']);
$query = "search=".url_escape($_GET['search']);
}
else {
$search_terms = array();
$query = null;
}
$next = $database->get_next_image($image_id, $search_terms);
$prev = $database->get_prev_image($image_id, $search_terms);
$h_prev = (!is_null($prev) ? "<a href='".make_link("post/view/{$prev->id}", $query)."'>Prev</a>" : "Prev");
$h_index = "<a href='".make_link()."'>Index</a>";
$h_next = (!is_null($next) ? "<a href='".make_link("post/view/{$next->id}", $query)."'>Next</a>" : "Next");
$this->pin = "$h_prev | $h_index | $h_next";
return $this->pin;
}
private function build_navigation($image_id) {
$h_pin = $this->build_pin($image_id);
$h_search = "
<p><form action='".make_link()."' method='GET'>
<input id='search_input' name='search' type='text'
value='Search' autocomplete='off'>
<input type='submit' value='Find' style='display: none;'>
</form>
<div id='search_completions'></div>";
return "$h_pin<br>$h_search";
}
private function build_image_view($image) {
$ilink = $image->get_image_link();
return "<img id='main_image' src='$ilink'>";
}
private function build_info($image) {
protected function build_info($image) {
global $user;
$owner = $image->get_owner();
$h_owner = html_escape($owner->name);
@ -112,7 +60,7 @@ class ViewTheme extends Themelet {
</div>
";
}
return $html;
}
}