Skip to content

Commit

Permalink
Merge branch '4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
bobdenotter committed Mar 23, 2021
2 parents c7f2586 + e8b16ea commit 36d1824
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/behavioural_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ jobs:
php-version: ${{ matrix.php-version }}
extensions: json, mbstring, pdo, curl, pdo_sqlite
coverage: none
# See https://github.saobby.my.eu.orgmunity/t/sudo-apt-install-fails-with-failed-to-fetch-http-security-ubuntu-com-404-not-found-ip/17075
- run: sudo apt update
- name: Install dependencies
run: |
sudo composer self-update -q
Expand Down Expand Up @@ -69,6 +71,8 @@ jobs:
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
# See https://github.saobby.my.eu.orgmunity/t/sudo-apt-install-fails-with-failed-to-fetch-http-security-ubuntu-com-404-not-found-ip/17075
- run: sudo apt update
- name: Install dependencies
run: |
sudo composer self-update -q
Expand Down
31 changes: 21 additions & 10 deletions src/Controller/Frontend/ListingController.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,7 @@ public function listing(ContentRepository $contentRepository, string $contentTyp

$page = (int) $this->getFromRequest('page', '1');
$amountPerPage = $contentType->get('listing_records');
$order = $this->getFromRequest('order', $contentType->get('order'));
$queryParams = $this->parseQueryParams($this->request, $contentType);

$params = array_merge($queryParams, [
'status' => 'published',
'order' => $order,
]);
$params = $this->parseQueryParams($this->request, $contentType);

/** @var Content|Pagerfanta $content */
$content = $this->query->getContent($contentTypeSlug, $params);
Expand Down Expand Up @@ -105,14 +99,22 @@ public function listing(ContentRepository $contentRepository, string $contentTyp
private function parseQueryParams(Request $request, ContentType $contentType): array
{
if ($this->config->get('general/query_search') === false) {
return [];
return [
'order' => $contentType->get('order'),
'status' => 'published',
];
}

$queryParams = collect($request->query->all());

$allowedParams = array_merge($contentType['fields']->keys()->all(), $contentType['taxonomy']->all(), ['order']);
// Note, we're not including 'limit', 'printquery', 'returnsingle' or 'returnmultiple' on purpose
$allowedParams = array_merge(
$contentType['fields']->keys()->all(),
$contentType['taxonomy']->all(),
['order', 'earliest', 'latest', 'offset', 'page', 'random', 'author']
);

return $queryParams->mapWithKeys(function ($value, $key) use ($allowedParams) {
$params = $queryParams->mapWithKeys(function ($value, $key) use ($allowedParams) {
// Ensure we don't have arrays, if we get something like `title[]=…` passed in.
if (is_array($value)) {
$value = current($value);
Expand All @@ -125,6 +127,15 @@ private function parseQueryParams(Request $request, ContentType $contentType): a

return in_array($key, $allowedParams, true) ? [$key => $value] : [];
})->toArray();

if (! array_key_exists('order', $params)) {
$params['order'] = $contentType->get('order');
}

// Ensure we only list things that are 'published'
$params['status'] = 'published';

return $params;
}

private function setRecords($content, int $amountPerPage, int $page): Pagerfanta
Expand Down
5 changes: 5 additions & 0 deletions src/Repository/ContentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Bolt\Repository;

use Bolt\Common\Str;
use Bolt\Configuration\Content\ContentType;
use Bolt\Doctrine\JsonHelper;
use Bolt\Entity\Content;
Expand Down Expand Up @@ -99,6 +100,10 @@ public function searchNaive(string $searchTerm, int $page, int $amountPerPage, C
$connection = $qb->getEntityManager()->getConnection();
[$where] = JsonHelper::wrapJsonFunction('t.value', $searchTerm, $connection);

// Rather than searching for '%foo bar%', search '%foo%bar%' which doesn't require
// an exact match, but requires 'foo' to appear before 'bar'.
$searchTerm = str_replace(' ', '%', Str::cleanWhitespace($searchTerm));

// The search term must match the format of the content in the database
// Therefore, it is JSON encoded and escaped with backslashes
$encodedSearchTerm = addslashes(trim(json_encode($searchTerm), '"'));
Expand Down
2 changes: 1 addition & 1 deletion src/Twig/ContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public function getExcerpt($content, int $length = 280, bool $includeTitle = fal
}

if (ContentHelper::isSuitable($content, 'excerpt_format')) {
$excerpt = $this->contentHelper->get($content, $content->getDefinition()->get('excerpt_format'));
$excerpt = $this->contentHelper->get($content, $content->getDefinition()->get('excerpt_format'), $this->request->getLocale());
} else {
$excerpt = $this->getFieldBasedExcerpt($content, $length, $includeTitle);
}
Expand Down

0 comments on commit 36d1824

Please sign in to comment.