From be1814094440664543a2438eb11c0f8336942fac Mon Sep 17 00:00:00 2001 From: Daku Date: Mon, 6 Apr 2015 17:04:46 +0100 Subject: [PATCH] added option to hide random link on paginator (only post/list should show now) --- core/basethemelet.class.php | 15 ++++++++++----- ext/index/theme.php | 4 ++-- themes/danbooru/themelet.class.php | 2 +- themes/danbooru2/themelet.class.php | 2 +- themes/futaba/comment.theme.php | 2 +- themes/futaba/themelet.class.php | 4 ++-- themes/lite/themelet.class.php | 13 +++++++++---- 7 files changed, 26 insertions(+), 16 deletions(-) diff --git a/core/basethemelet.class.php b/core/basethemelet.class.php index f9ad10f2..77e2e775 100644 --- a/core/basethemelet.class.php +++ b/core/basethemelet.class.php @@ -84,9 +84,9 @@ class BaseThemelet { * @param int $page_number * @param int $total_pages */ - public function display_paginator(Page $page, $base, $query, $page_number, $total_pages) { + public function display_paginator(Page $page, $base, $query, $page_number, $total_pages, $show_random) { if($total_pages == 0) $total_pages = 1; - $body = $this->build_paginator($page_number, $total_pages, $base, $query); + $body = $this->build_paginator($page_number, $total_pages, $base, $query, $show_random); $page->add_block(new Block(null, $body, "main", 90, "paginator")); } @@ -129,17 +129,22 @@ class BaseThemelet { * @param string $query * @return string */ - private function build_paginator($current_page, $total_pages, $base_url, $query) { + private function build_paginator($current_page, $total_pages, $base_url, $query, $show_random = FALSE) { $next = $current_page + 1; $prev = $current_page - 1; - $rand = mt_rand(1, $total_pages); $at_start = ($current_page <= 1 || $total_pages <= 1); $at_end = ($current_page >= $total_pages); $first_html = $at_start ? "First" : $this->gen_page_link($base_url, $query, 1, "First"); $prev_html = $at_start ? "Prev" : $this->gen_page_link($base_url, $query, $prev, "Prev"); - $random_html = $this->gen_page_link($base_url, $query, $rand, "Random"); + + $random_html = "-"; + if($show_random) { + $rand = mt_rand(1, $total_pages); + $random_html = $this->gen_page_link($base_url, $query, $rand, "Random"); + } + $next_html = $at_end ? "Next" : $this->gen_page_link($base_url, $query, $next, "Next"); $last_html = $at_end ? "Last" : $this->gen_page_link($base_url, $query, $total_pages, "Last"); diff --git a/ext/index/theme.php b/ext/index/theme.php index 05e62ab1..1cacd4e2 100644 --- a/ext/index/theme.php +++ b/ext/index/theme.php @@ -106,10 +106,10 @@ and of course start organising your images :-) if (count($this->search_terms) > 0) { $query = url_escape(implode(' ', $this->search_terms)); $page->add_block(new Block("Images", $this->build_table($images, "#search=$query"), "main", 10, "image-list")); - $this->display_paginator($page, "post/list/$query", null, $this->page_number, $this->total_pages); + $this->display_paginator($page, "post/list/$query", null, $this->page_number, $this->total_pages, TRUE); } else { $page->add_block(new Block("Images", $this->build_table($images, null), "main", 10, "image-list")); - $this->display_paginator($page, "post/list", null, $this->page_number, $this->total_pages); + $this->display_paginator($page, "post/list", null, $this->page_number, $this->total_pages, TRUE); } } } diff --git a/themes/danbooru/themelet.class.php b/themes/danbooru/themelet.class.php index 3a853c24..11122f3e 100644 --- a/themes/danbooru/themelet.class.php +++ b/themes/danbooru/themelet.class.php @@ -7,7 +7,7 @@ class Themelet extends BaseThemelet { * @param int $page_number * @param int $total_pages */ - public function display_paginator(Page $page, $base, $query, $page_number, $total_pages) { + public function display_paginator(Page $page, $base, $query, $page_number, $total_pages, $show_random) { if($total_pages == 0) $total_pages = 1; $body = $this->build_paginator($page_number, $total_pages, $base, $query); $page->add_block(new Block(null, $body, "main", 90)); diff --git a/themes/danbooru2/themelet.class.php b/themes/danbooru2/themelet.class.php index 3a853c24..11122f3e 100644 --- a/themes/danbooru2/themelet.class.php +++ b/themes/danbooru2/themelet.class.php @@ -7,7 +7,7 @@ class Themelet extends BaseThemelet { * @param int $page_number * @param int $total_pages */ - public function display_paginator(Page $page, $base, $query, $page_number, $total_pages) { + public function display_paginator(Page $page, $base, $query, $page_number, $total_pages, $show_random) { if($total_pages == 0) $total_pages = 1; $body = $this->build_paginator($page_number, $total_pages, $base, $query); $page->add_block(new Block(null, $body, "main", 90)); diff --git a/themes/futaba/comment.theme.php b/themes/futaba/comment.theme.php index 2b4c3518..3406a1d5 100644 --- a/themes/futaba/comment.theme.php +++ b/themes/futaba/comment.theme.php @@ -15,7 +15,7 @@ class CustomCommentListTheme extends CommentListTheme { $page->disable_left(); $page->add_block(new Block(null, $this->build_upload_box(), "main", 0)); $page->add_block(new Block(null, "
", "main", 80)); - $this->display_paginator($page, "comment/list", null, $page_number, $total_pages, 90); + $this->display_paginator($page, "comment/list", null, $page_number, $total_pages); // parts for each image $position = 10; diff --git a/themes/futaba/themelet.class.php b/themes/futaba/themelet.class.php index 3f38fdfc..96a5f64f 100644 --- a/themes/futaba/themelet.class.php +++ b/themes/futaba/themelet.class.php @@ -11,10 +11,10 @@ class Themelet extends BaseThemelet { * @param int $total_pages * @param int $position */ - public function display_paginator(Page $page, $base, $query, $page_number, $total_pages, $position=90) { + public function display_paginator(Page $page, $base, $query, $page_number, $total_pages, $show_random) { if($total_pages == 0) $total_pages = 1; $body = $this->futaba_build_paginator($page_number, $total_pages, $base, $query); - $page->add_block(new Block(null, $body, "main", $position)); + $page->add_block(new Block(null, $body, "main", 90)); } /** diff --git a/themes/lite/themelet.class.php b/themes/lite/themelet.class.php index c7892405..c3f7f4c2 100644 --- a/themes/lite/themelet.class.php +++ b/themes/lite/themelet.class.php @@ -28,9 +28,9 @@ class Themelet extends BaseThemelet { * @param int $page_number * @param int $total_pages */ - public function display_paginator(Page $page, $base, $query, $page_number, $total_pages) { + public function display_paginator(Page $page, $base, $query, $page_number, $total_pages, $show_random) { if($total_pages == 0) $total_pages = 1; - $body = $this->litetheme_build_paginator($page_number, $total_pages, $base, $query); + $body = $this->litetheme_build_paginator($page_number, $total_pages, $base, $query, $show_random); $page->add_block(new Block(null, $body, "main", 90)); } @@ -74,14 +74,19 @@ class Themelet extends BaseThemelet { public function litetheme_build_paginator($current_page, $total_pages, $base_url, $query) { $next = $current_page + 1; $prev = $current_page - 1; - $rand = mt_rand(1, $total_pages); $at_start = ($current_page <= 1 || $total_pages <= 1); $at_end = ($current_page >= $total_pages); $first_html = $at_start ? "First" : $this->litetheme_gen_page_link($base_url, $query, 1, "First"); $prev_html = $at_start ? "Prev" : $this->litetheme_gen_page_link($base_url, $query, $prev, "Prev"); - $random_html = $this->litetheme_gen_page_link($base_url, $query, $rand, "Random"); + + $random_html = ""; + if($show_random) { + $rand = mt_rand(1, $total_pages); + $random_html = $this->litetheme_gen_page_link($base_url, $query, $rand, "Random"); + } + $next_html = $at_end ? "Next" : $this->litetheme_gen_page_link($base_url, $query, $next, "Next"); $last_html = $at_end ? "Last" : $this->litetheme_gen_page_link($base_url, $query, $total_pages, "Last");