[view] don't show prev/next when the user has searched for order:... - fixes #790
This commit is contained in:
parent
e3febc5488
commit
b060accc44
2 changed files with 48 additions and 7 deletions
|
@ -66,6 +66,24 @@ class ViewPostTest extends ShimmiePHPUnitTestCase
|
|||
$this->assertEquals(404, $page->code);
|
||||
}
|
||||
|
||||
public function testPrevNextDisabledWhenOrdered()
|
||||
{
|
||||
$this->log_in_as_user();
|
||||
$image_id = $this->post_image("tests/pbx_screenshot.jpg", "test");
|
||||
|
||||
$this->get_page("post/view/$image_id");
|
||||
$this->assert_text("Prev");
|
||||
|
||||
$this->get_page("post/view/$image_id", ["search" => "test"]);
|
||||
$this->assert_text("Prev");
|
||||
|
||||
$this->get_page("post/view/$image_id", ["search" => "cake_order:_the_cakening"]);
|
||||
$this->assert_text("Prev");
|
||||
|
||||
$this->get_page("post/view/$image_id", ["search" => "order:score"]);
|
||||
$this->assert_no_text("Prev");
|
||||
}
|
||||
|
||||
public function testView404()
|
||||
{
|
||||
$this->log_in_as_user();
|
||||
|
|
|
@ -35,8 +35,10 @@ class ViewPostTheme extends Themelet
|
|||
//$page->add_block(new Block(null, $this->build_pin($image), "main", 11));
|
||||
|
||||
$query = $this->get_query();
|
||||
$page->add_html_header("<link id='nextlink' rel='next' href='".make_link("post/next/{$image->id}", $query)."'>");
|
||||
$page->add_html_header("<link id='prevlink' rel='previous' href='".make_link("post/prev/{$image->id}", $query)."'>");
|
||||
if(!$this->is_ordered_search()) {
|
||||
$page->add_html_header("<link id='nextlink' rel='next' href='".make_link("post/next/{$image->id}", $query)."'>");
|
||||
$page->add_html_header("<link id='prevlink' rel='previous' href='".make_link("post/prev/{$image->id}", $query)."'>");
|
||||
}
|
||||
}
|
||||
|
||||
public function display_admin_block(Page $page, $parts)
|
||||
|
@ -56,14 +58,35 @@ class ViewPostTheme extends Themelet
|
|||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* prev/next only work for default-ordering searches - if the user
|
||||
* has specified a custom order, we can't show prev/next.
|
||||
*/
|
||||
protected function is_ordered_search(): bool
|
||||
{
|
||||
if(isset($_GET['search'])) {
|
||||
$tags = Tag::explode($_GET['search']);
|
||||
foreach($tags as $tag) {
|
||||
if(preg_match("/^order[=:]/", $tag) == 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected function build_pin(Image $image): HTMLElement
|
||||
{
|
||||
$query = $this->get_query();
|
||||
return joinHTML(" | ", [
|
||||
A(["href" => make_link("post/prev/{$image->id}", $query), "id" => "prevlink"], "Prev"),
|
||||
A(["href" => make_link()], "Index"),
|
||||
A(["href" => make_link("post/next/{$image->id}", $query), "id" => "nextlink"], "Next"),
|
||||
]);
|
||||
if($this->is_ordered_search()) {
|
||||
return A(["href" => make_link()], "Index");
|
||||
} else {
|
||||
return joinHTML(" | ", [
|
||||
A(["href" => make_link("post/prev/{$image->id}", $query), "id" => "prevlink"], "Prev"),
|
||||
A(["href" => make_link()], "Index"),
|
||||
A(["href" => make_link("post/next/{$image->id}", $query), "id" => "nextlink"], "Next"),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function build_navigation(Image $image): string
|
||||
|
|
Reference in a new issue