Skip to content

Commit

Permalink
Merge pull request #386 from t3solution/5.3.6
Browse files Browse the repository at this point in the history
New release v5.3.6
  • Loading branch information
t3solution authored Feb 25, 2024
2 parents 390eb29 + 9ba60ed commit f693152
Show file tree
Hide file tree
Showing 34 changed files with 772 additions and 641 deletions.
5 changes: 1 addition & 4 deletions Classes/Controller/AbstractController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use TYPO3\CMS\Core\Routing\SiteMatcher;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
#use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Domain\Repository\PageRepository;
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
Expand All @@ -42,7 +41,7 @@ abstract class AbstractController extends ActionController
/**
* init all actions
*/
public function initializeAction()
public function initializeAction(): void
{
$site = $this->request->getAttribute('site');
$this->rootPageId = $site->getRootPageId();
Expand All @@ -62,8 +61,6 @@ public function initializeAction()
$queryBuilder->expr()->eq('root', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)
->executeQuery()->fetchOne();

# $pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
}


Expand Down
4 changes: 2 additions & 2 deletions Classes/Controller/ConfigController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
final class ConfigController extends AbstractController
{
public function __construct(
private ModuleTemplateFactory $moduleTemplateFactory
protected readonly ModuleTemplateFactory $moduleTemplateFactory
) {
}

/**
* Init all actions.
*/
public function initializeAction()
public function initializeAction(): void
{
parent::initializeAction();
}
Expand Down
5 changes: 2 additions & 3 deletions Classes/DataProcessing/BootstrapProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,13 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
$processedData['lightBox'] = true;
}
// lightbox
if ($cType == 't3sbs_gallery' || !empty($processedData['data']['image_zoom'])) {
if ($cType === 't3sbs_gallery' || !empty($processedData['data']['image_zoom'])) {
$processedData['lightBox'] = true;
}
}

// child of autoLayout_row
if ($parentCType == 'autoLayout_row') {
if ($parentCType === 'autoLayout_row') {
$processedData['newLine'] = $flexconf['newLine'] ? true : false;
$processedData['class'] .= $classHelper->getAutoLayoutClass($flexconf);
}
Expand Down Expand Up @@ -376,7 +376,6 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
}



/**
* @param array $animationSettingsArray
* @return string
Expand Down
11 changes: 5 additions & 6 deletions Classes/DataProcessing/ConfigProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
if (!$frontendController) {
$frontendController = self::getFrontendController();
}

if (!empty($contentObjectConfiguration['settings.']['config.']['uid'])
&& is_numeric($contentObjectConfiguration['settings.']['config.']['uid'])) {
$processedRecordVariables = $contentObjectConfiguration['settings.']['config.'];
Expand Down Expand Up @@ -179,10 +178,10 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
if (!empty($navbarMenu['data']['tx_t3sbootstrap_fontawesome_icon'])) {
$mainMenu[$key]['faIcon'] = '<i class="'.$navbarMenu['data']['tx_t3sbootstrap_fontawesome_icon'].'"></i> ';
}
$mainMenu[$key]['linkTitle'] = $navbarMenu['data']['title'];
if (!empty($settings['navbar.']['noLinkTitle'])) {
$mainMenu[$key]['linkTitle'] = '';
}
$mainMenu[$key]['linkTitle'] = $navbarMenu['data']['title'];
if (!empty($settings['navbar.']['noLinkTitle'])) {
$mainMenu[$key]['linkTitle'] = '';
}
if ($navbarMenu['data']['tx_t3sbootstrap_icon_only']) {
$mainMenu[$key]['linkTitle'] = $navbarMenu['data']['title'];
$mainMenu[$key]['title'] = '';
Expand Down Expand Up @@ -385,7 +384,7 @@ public function process(ContentObjectRenderer $cObj, array $contentObjectConfigu
$processedData['config']['navbar']['sbmauto'] = ' ms-auto';
}
if ($processedData['config']['navbar']['mauto'] == ' ms-auto') {
$processedData['config']['navbar']['sbmauto'] = ' float-right ms-3';
$processedData['config']['navbar']['sbmauto'] = ' float-end ms-3';
}
if ($processedData['config']['navbar']['mauto'] == 'center') {
$processedData['config']['navbar']['sbmauto'] = '';
Expand Down
279 changes: 164 additions & 115 deletions Classes/ViewHelpers/PageBrowsingViewHelper.php
Original file line number Diff line number Diff line change
@@ -1,127 +1,176 @@
<?php

declare(strict_types=1);

/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/

namespace T3SBS\T3sbootstrap\ViewHelpers;

use TYPO3\CMS\Core\Page\AssetCollector;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\MathUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;

/**
* This file is part of the TYPO3 extension t3sbootstrap.
* Page browser for indexed search, and only useful here, as the regular pagebrowser.
* This is a cleaner "pi_browsebox" but not a real page browser functionality.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
* @internal
*/
class PageBrowsingViewHelper extends AbstractViewHelper
final class PageBrowsingViewHelper extends AbstractTagBasedViewHelper
{
use CompileWithRenderStatic;

/**
* As this ViewHelper renders HTML, the output must not be escaped.
*
* @var bool
*/
protected $escapeOutput = false;

/**
* @var string
*/
protected static $prefixId = 'tx_indexedsearch';

/**
* Initialize arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('maximumNumberOfResultPages', 'int', '', true);
$this->registerArgument('numberOfResults', 'int', '', true);
$this->registerArgument('resultsPerPage', 'int', '', true);
$this->registerArgument('currentPage', 'int', '', false, 0);
$this->registerArgument('freeIndexUid', 'int', '');
}


public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
{
$maximumNumberOfResultPages = $arguments['maximumNumberOfResultPages'];
$numberOfResults = $arguments['numberOfResults'];
$resultsPerPage = $arguments['resultsPerPage'];
$currentPage = $arguments['currentPage'];
$freeIndexUid = $arguments['freeIndexUid'];

if ($resultsPerPage <= 0) {
$resultsPerPage = 10;
}
$pageCount = (int)ceil($numberOfResults / $resultsPerPage);
// only show the result browser if more than one page is needed
if ($pageCount === 1) {
return '';
}

// Check if $currentPage is in range
$currentPage = MathUtility::forceIntegerInRange($currentPage, 0, $pageCount - 1);

$content = '';
// prev page
// show on all pages after the 1st one
if ($currentPage > 0 && !empty($freeIndexUid)) {
$label = LocalizationUtility::translate('displayResults.previous', 'IndexedSearch');
$content .= '<li>' . self::makecurrentPageSelector_link((string) $label, $currentPage - 1, (string) $freeIndexUid) . '</li>';
}
// Check if $maximumNumberOfResultPages is in range
$maximumNumberOfResultPages = MathUtility::forceIntegerInRange($maximumNumberOfResultPages, 1, $pageCount, 10);
// Assume $currentPage is in the middle and calculate the index limits of the result page listing
$minPage = $currentPage - (int)floor($maximumNumberOfResultPages / 2);
$maxPage = $minPage + $maximumNumberOfResultPages - 1;
// Check if the indexes are within the page limits
if ($minPage < 0) {
$maxPage -= $minPage;
$minPage = 0;
} elseif ($maxPage >= $pageCount) {
$minPage -= $maxPage - $pageCount + 1;
$maxPage = $pageCount - 1;
}
$pageLabel = '';

for ($a = $minPage; $a <= $maxPage; $a++) {
$label = trim($pageLabel . ' ' . ($a + 1));
if (!empty($freeIndexUid)) {
$label = self::makecurrentPageSelector_link((string) $label, (int) $a, (string) $freeIndexUid);
}
if ($a === $currentPage) {
$content .= '<li class="tx-indexedsearch-browselist-currentPage page-item"><strong>' . $label . '</strong></li>';
} else {
$content .= '<li class="page-item">' . $label . '</li>';
}
}


// next link
if ($currentPage < $pageCount - 1 && !empty($freeIndexUid)) {
$label = LocalizationUtility::translate('displayResults.next', 'IndexedSearch');
$content .= '<li>' . self::makecurrentPageSelector_link((string) $label, ($currentPage + 1), (string) $freeIndexUid) . '</li>';
}
return '<ul class="tx-indexedsearch-browsebox pagination">' . $content . '</ul>';
}

/**
* Used to make the link for the result-browser.
* Notice how the links must resubmit the form after setting the new currentPage-value in a hidden formfield.
*
* $str String to wrap in <a> tag
* $p currentPage value
* $freeIndexUid List of integers pointing to free indexing configurations to search. -1 represents no filtering, 0 represents TYPO3 pages only, any number above zero is a uid of an indexing configuration!
*/
protected static function makecurrentPageSelector_link(string $str, int $p, string $freeIndexUid): string
{
$onclick = 'document.getElementById(' . GeneralUtility::quoteJSvalue(self::$prefixId . '_pointer') . ').value=' . GeneralUtility::quoteJSvalue($p) . ';';
if ($freeIndexUid !== null) {
$onclick .= 'document.getElementById(' . GeneralUtility::quoteJSvalue(self::$prefixId . '_freeIndexUid') . ').value=' . GeneralUtility::quoteJSvalue($freeIndexUid) . ';';
}
$onclick .= 'document.getElementById(' . GeneralUtility::quoteJSvalue(self::$prefixId) . ').submit();return false;';
return '<a class="page-link" href="#" onclick="' . htmlspecialchars($onclick) . '">' . htmlspecialchars($str) . '</a>';
}
protected static string $prefixId = 'tx_indexedsearch';

/**
* @var string
*/
protected $tagName = 'ul';

public function __construct(private readonly AssetCollector $assetCollector)
{
parent::__construct();
}

public function initializeArguments(): void
{
$this->registerArgument('maximumNumberOfResultPages', 'int', '', true);
$this->registerArgument('numberOfResults', 'int', '', true);
$this->registerArgument('resultsPerPage', 'int', '', true);
$this->registerArgument('currentPage', 'int', '', false, 0);
$this->registerArgument('freeIndexUid', 'int', '');
$this->registerUniversalTagAttributes();
}

public function render(): string
{
$maximumNumberOfResultPages = $this->arguments['maximumNumberOfResultPages'];
$numberOfResults = $this->arguments['numberOfResults'];
$resultsPerPage = $this->arguments['resultsPerPage'];
$currentPage = $this->arguments['currentPage'];
$freeIndexUid = $this->arguments['freeIndexUid'];

if ($resultsPerPage <= 0) {
$resultsPerPage = 10;
}
$pageCount = (int)ceil($numberOfResults / $resultsPerPage);
// only show the result browser if more than one page is needed
if ($pageCount === 1) {
return '';
}

// Check if $currentPage is in range
$currentPage = MathUtility::forceIntegerInRange($currentPage, 0, $pageCount - 1);

$content = '';
// prev page
// show on all pages after the 1st one
if ($currentPage > 0) {
$label = LocalizationUtility::translate('displayResults.previous', 'IndexedSearch') ?? '';
$content .= '<li class="tx-indexedsearch-browselist-prev page-item">' . $this->makecurrentPageSelector_link($label, $currentPage - 1, $freeIndexUid) . '</li>';
}
// Check if $maximumNumberOfResultPages is in range
$maximumNumberOfResultPages = MathUtility::forceIntegerInRange($maximumNumberOfResultPages, 1, $pageCount, 10);
// Assume $currentPage is in the middle and calculate the index limits of the result page listing
$minPage = $currentPage - (int)floor($maximumNumberOfResultPages / 2);
$maxPage = $minPage + $maximumNumberOfResultPages - 1;
// Check if the indexes are within the page limits
if ($minPage < 0) {
$maxPage -= $minPage;
$minPage = 0;
} elseif ($maxPage >= $pageCount) {
$minPage -= $maxPage - $pageCount + 1;
$maxPage = $pageCount - 1;
}
$pageLabel = LocalizationUtility::translate('displayResults.page', 'IndexedSearch');
for ($a = $minPage; $a <= $maxPage; $a++) {
$isCurrentPage = $a === $currentPage;
$label = trim($pageLabel . ' ' . ($a + 1));
$label = $this->makecurrentPageSelector_link($label, $a, $freeIndexUid, $isCurrentPage);
if ($isCurrentPage) {
$content .= '<li class="tx-indexedsearch-browselist-currentPage page-item"><strong>' . $label . '</strong></li>';
} else {
$content .= '<li class="page-item">' . $label . '</li>';
}
}
// next link
if ($currentPage < $pageCount - 1) {
$label = LocalizationUtility::translate('displayResults.next', 'IndexedSearch') ?? '';
$content .= '<li class="tx-indexedsearch-browselist-next page-item">' . $this->makecurrentPageSelector_link($label, $currentPage + 1, $freeIndexUid) . '</li>';
}

if (!$this->tag->hasAttribute('class')) {
$this->tag->addAttribute('class', 'tx-indexedsearch-browsebox pagination');
}

$this->tag->setContent($content);

return $this->tag->render();
}

/**
* Used to make the link for the result-browser.
* Notice how the links must resubmit the form after setting the new currentPage-value in a hidden formfield.
*
* @param string $str String to wrap in <a> tag
* @param int $p currentPage value
* @param string $freeIndexUid List of integers pointing to free indexing configurations to search. -1 represents no filtering, 0 represents TYPO3 pages only, any number above zero is a uid of an indexing configuration!
* @param bool $isCurrentPage
* @return string Input string wrapped in <a> tag with onclick event attribute set.
*/
protected function makecurrentPageSelector_link($str, $p, $freeIndexUid, bool $isCurrentPage = false)
{
$this->providePageSelectorJavaScript();
$attributes = [
'href' => '#',
'class' => 'tx-indexedsearch-page-selector page-link',
'data-prefix' => self::$prefixId,
'data-pointer' => $p,
'data-free-index-uid' => $freeIndexUid,
];
if ($isCurrentPage) {
$attributes['aria-current'] = 'page';
}
return sprintf(
'<a %s>%s</a>',
GeneralUtility::implodeAttributes($attributes, true),
htmlspecialchars($str)
);
}

private function providePageSelectorJavaScript(): void
{
if ($this->assetCollector->hasInlineJavaScript(self::class)) {
return;
}

$this->assetCollector->addInlineJavaScript(
'vanilla_indexSearch',
implode(' ', [
"document.addEventListener('click', (evt) => {",
"if (!evt.target.classList.contains('tx-indexedsearch-page-selector')) {",
'return;',
'}',
'evt.preventDefault();',
'var data = evt.target.dataset;',
"document.getElementById(data.prefix + '_pointer').value = data.pointer;",
"document.getElementById(data.prefix + '_freeIndexUid').value = data.freeIndexUid;",
'document.getElementById(data.prefix).submit();',
'});',
]),
[],
['useNonce' => true],
);
}
}
Loading

0 comments on commit f693152

Please sign in to comment.