Changed last search query tracking to server-side
Recent changes to last search query handling still haven't fixed all possible routes, so I've simplified the whole thing at expense of clean URLs.
This commit is contained in:
parent
1ea7c187ab
commit
a9a5bea1c7
5 changed files with 23 additions and 34 deletions
|
@ -25,12 +25,6 @@ function getCookie(name)
|
||||||
return unescape(value.substring(start, end));
|
return unescape(value.substring(start, end));
|
||||||
}
|
}
|
||||||
|
|
||||||
function rememberLastSearchQuery()
|
|
||||||
{
|
|
||||||
var lastSearchQuery = $('#settings').attr('data-last-search-query');
|
|
||||||
setCookie('last-search-query', lastSearchQuery);
|
|
||||||
}
|
|
||||||
|
|
||||||
//core functionalities, prototypes
|
//core functionalities, prototypes
|
||||||
function getJSON(data)
|
function getJSON(data)
|
||||||
{
|
{
|
||||||
|
@ -52,7 +46,6 @@ function postJSON(data)
|
||||||
|
|
||||||
function getHtml(data)
|
function getHtml(data)
|
||||||
{
|
{
|
||||||
rememberLastSearchQuery();
|
|
||||||
return $.get(data);
|
return $.get(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,19 +70,6 @@ $.fn.bindOnce = function(name, eventName, callback)
|
||||||
//basic event listeners
|
//basic event listeners
|
||||||
$(function()
|
$(function()
|
||||||
{
|
{
|
||||||
$(window).on('beforeunload', function()
|
|
||||||
{
|
|
||||||
rememberLastSearchQuery();
|
|
||||||
});
|
|
||||||
if (window.history && window.history.pushState)
|
|
||||||
{
|
|
||||||
$(window).on('popstate', function()
|
|
||||||
{
|
|
||||||
rememberLastSearchQuery();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
rememberLastSearchQuery();
|
|
||||||
|
|
||||||
$('body').bind('dom-update', function()
|
$('body').bind('dom-update', function()
|
||||||
{
|
{
|
||||||
//event confirmations
|
//event confirmations
|
||||||
|
|
|
@ -11,7 +11,6 @@ class PostController extends AbstractController
|
||||||
{
|
{
|
||||||
$query = trim($query);
|
$query = trim($query);
|
||||||
$context->transport->searchQuery = $query;
|
$context->transport->searchQuery = $query;
|
||||||
$context->transport->lastSearchQuery = $query;
|
|
||||||
if ($source == 'mass-tag')
|
if ($source == 'mass-tag')
|
||||||
{
|
{
|
||||||
Access::assert(new Privilege(Privilege::MassTag));
|
Access::assert(new Privilege(Privilege::MassTag));
|
||||||
|
@ -49,7 +48,6 @@ class PostController extends AbstractController
|
||||||
$additionalInfo = trim(InputHelper::get('tag'));
|
$additionalInfo = trim(InputHelper::get('tag'));
|
||||||
|
|
||||||
$context->transport->searchQuery = $query;
|
$context->transport->searchQuery = $query;
|
||||||
$context->transport->lastSearchQuery = $query;
|
|
||||||
if (strpos($query, '/') !== false)
|
if (strpos($query, '/') !== false)
|
||||||
throw new SimpleException('Search query contains invalid characters');
|
throw new SimpleException('Search query contains invalid characters');
|
||||||
|
|
||||||
|
@ -284,7 +282,7 @@ class PostController extends AbstractController
|
||||||
$this->redirectToGenericView($identifier);
|
$this->redirectToGenericView($identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function genericView($identifier)
|
public function genericView($identifier, $query = null)
|
||||||
{
|
{
|
||||||
$context = Core::getContext();
|
$context = Core::getContext();
|
||||||
|
|
||||||
|
@ -294,17 +292,17 @@ class PostController extends AbstractController
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$context->transport->lastSearchQuery = InputHelper::get('last-search-query');
|
$context->transport->searchQuery = $query;
|
||||||
list ($prevPostId, $nextPostId) =
|
list ($prevPostId, $nextPostId) =
|
||||||
PostSearchService::getPostIdsAround(
|
PostSearchService::getPostIdsAround(
|
||||||
$context->transport->lastSearchQuery, $identifier);
|
$context->transport->searchQuery, $identifier);
|
||||||
}
|
}
|
||||||
#search for some reason was invalid, e.g. tag was deleted in the meantime
|
#search for some reason was invalid, e.g. tag was deleted in the meantime
|
||||||
catch (Exception $e)
|
catch (Exception $e)
|
||||||
{
|
{
|
||||||
$context->transport->lastSearchQuery = '';
|
$context->transport->searchQuery = '';
|
||||||
list ($prevPostId, $nextPostId) =
|
list ($prevPostId, $nextPostId) =
|
||||||
PostSearchService::getPostIdsAround($context->transport->lastSearchQuery, $identifier);
|
PostSearchService::getPostIdsAround($context->transport->searchQuery, $identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
$isUserFavorite = Auth::getCurrentUser()->hasFavorited($post);
|
$isUserFavorite = Auth::getCurrentUser()->hasFavorited($post);
|
||||||
|
|
|
@ -63,8 +63,9 @@ class Router extends \Chibi\Routing\Router
|
||||||
$this->register(['PostController', 'listView'], 'GET', '/{source}/{query}/{additionalInfo}/{page}', $postValidation);
|
$this->register(['PostController', 'listView'], 'GET', '/{source}/{query}/{additionalInfo}/{page}', $postValidation);
|
||||||
$this->register(['PostController', 'listRedirectAction'], 'POST', '/{source}-redirect', $postValidation);
|
$this->register(['PostController', 'listRedirectAction'], 'POST', '/{source}-redirect', $postValidation);
|
||||||
|
|
||||||
$this->register(['PostController', 'genericView'], 'GET', '/post/{identifier}', $postValidation);
|
|
||||||
$this->register(['PostController', 'fileView'], 'GET', '/post/{name}/retrieve', $postValidation);
|
$this->register(['PostController', 'fileView'], 'GET', '/post/{name}/retrieve', $postValidation);
|
||||||
|
$this->register(['PostController', 'genericView'], 'GET', '/post/{identifier}', $postValidation);
|
||||||
|
$this->register(['PostController', 'genericView'], 'GET', '/post/{identifier}/search={query}', $postValidation);
|
||||||
$this->register(['PostController', 'thumbnailView'], 'GET', '/post/{name}/thumb', $postValidation);
|
$this->register(['PostController', 'thumbnailView'], 'GET', '/post/{name}/thumb', $postValidation);
|
||||||
|
|
||||||
$this->register(['PostController', 'toggleTagAction'], null, '/post/{identifier}/toggle-tag/{tag}/{enable}', $postValidation);
|
$this->register(['PostController', 'toggleTagAction'], null, '/post/{identifier}/toggle-tag/{tag}/{enable}', $postValidation);
|
||||||
|
|
|
@ -45,7 +45,11 @@ if ($masstag)
|
||||||
<?php if (Auth::getCurrentUser()->getSettings()->hasEnabledPostTagTitles()): ?>
|
<?php if (Auth::getCurrentUser()->getSettings()->hasEnabledPostTagTitles()): ?>
|
||||||
title="<?= TextHelper::reprTags($this->context->post->getTags()) ?>"
|
title="<?= TextHelper::reprTags($this->context->post->getTags()) ?>"
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
href="<?= Core::getRouter()->linkTo(['PostController', 'genericView'], ['identifier' => $this->context->post->getId()]) ?>">
|
href="<?= Core::getRouter()->linkTo(['PostController', 'genericView'],
|
||||||
|
empty($this->context->transport->searchQuery)
|
||||||
|
? ['identifier' => $this->context->post->getId()]
|
||||||
|
: ['identifier' => $this->context->post->getId(),
|
||||||
|
'query' => $this->context->transport->searchQuery]) ?>">
|
||||||
|
|
||||||
<img
|
<img
|
||||||
class="thumb"
|
class="thumb"
|
||||||
|
|
|
@ -33,7 +33,10 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
|
||||||
<?php if ($this->context->transport->nextPostId): ?>
|
<?php if ($this->context->transport->nextPostId): ?>
|
||||||
<a href="<?= Core::getRouter()->linkTo(
|
<a href="<?= Core::getRouter()->linkTo(
|
||||||
['PostController', 'genericView'],
|
['PostController', 'genericView'],
|
||||||
['identifier' => $this->context->transport->nextPostId]) ?>">
|
empty($this->context->transport->searchQuery)
|
||||||
|
? ['identifier' => $this->context->transport->nextPostId]
|
||||||
|
: ['identifier' => $this->context->transport->nextPostId,
|
||||||
|
'query' => $this->context->transport->searchQuery]) ?>">
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<a class="disabled">
|
<a class="disabled">
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
@ -46,7 +49,10 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
|
||||||
<?php if ($this->context->transport->prevPostId): ?>
|
<?php if ($this->context->transport->prevPostId): ?>
|
||||||
<a href="<?= Core::getRouter()->linkTo(
|
<a href="<?= Core::getRouter()->linkTo(
|
||||||
['PostController', 'genericView'],
|
['PostController', 'genericView'],
|
||||||
['identifier' => $this->context->transport->prevPostId]) ?>">
|
empty($this->context->transport->searchQuery)
|
||||||
|
? ['identifier' => $this->context->transport->prevPostId]
|
||||||
|
: ['identifier' => $this->context->transport->prevPostId,
|
||||||
|
'query' => $this->context->transport->searchQuery]) ?>">
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
<a class="disabled">
|
<a class="disabled">
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
@ -57,13 +63,13 @@ $canEditAnything = count(array_filter($editPostPrivileges)) > 0;
|
||||||
|
|
||||||
<div class="clear"></div>
|
<div class="clear"></div>
|
||||||
|
|
||||||
<?php if (!empty($this->context->transport->lastSearchQuery)): ?>
|
<?php if (!empty($this->context->transport->searchQuery)): ?>
|
||||||
<div class="text">
|
<div class="text">
|
||||||
Current search:<br/>
|
Current search:<br/>
|
||||||
<a href="<?= Core::getRouter()->linkTo(
|
<a href="<?= Core::getRouter()->linkTo(
|
||||||
['PostController', 'listView'],
|
['PostController', 'listView'],
|
||||||
['query' => $this->context->transport->lastSearchQuery]) ?>">
|
['query' => $this->context->transport->searchQuery]) ?>">
|
||||||
<?= $this->context->transport->lastSearchQuery ?>
|
<?= $this->context->transport->searchQuery ?>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<?php endif ?>
|
<?php endif ?>
|
||||||
|
|
Loading…
Reference in a new issue