first commit

This commit is contained in:
Sven Wappler
2021-04-17 00:26:33 +02:00
commit 866c63cc63
813 changed files with 100696 additions and 0 deletions

View File

@@ -0,0 +1,68 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers;
/*
* 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!
*/
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use WapplerSystems\Meilisearch\Mvc\Controller\SolrControllerContext;
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrTagBasedViewHelper;
/**
* Class AbstractSolrFrontendTagBasedViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
abstract class AbstractSolrFrontendTagBasedViewHelper extends AbstractSolrTagBasedViewHelper
{
/**
* @var SolrControllerContext
*/
protected $controllerContext;
/**
* @return TypoScriptConfiguration
*/
protected function getTypoScriptConfiguration()
{
return $this->getControllerContext()->getTypoScriptConfiguration();
}
/**
* @return SearchResultSet
*/
protected function getSearchResultSet()
{
return $this->getControllerContext()->getSearchResultSet();
}
/**
* @return SolrControllerContext
* @throws \InvalidArgumentException
*/
protected function getControllerContext()
{
$controllerContext = null;
if (method_exists($this->renderingContext, 'getControllerContext')) {
$controllerContext = $this->renderingContext->getControllerContext();
}
if (!$controllerContext instanceof SolrControllerContext) {
throw new \InvalidArgumentException('No valid SolrControllerContext found', 1512998673);
}
return $controllerContext;
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers;
/*
* 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!
*/
use WapplerSystems\Meilisearch\System\Configuration\TypoScriptConfiguration;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use WapplerSystems\Meilisearch\Mvc\Controller\SolrControllerContext;
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class AbstractSolrFrontendViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
abstract class AbstractSolrFrontendViewHelper extends AbstractSolrViewHelper
{
/**
* @var SolrControllerContext
*/
protected $controllerContext;
/**
* @return TypoScriptConfiguration
*/
protected function getTypoScriptConfiguration()
{
return $this->getControllerContext()->getTypoScriptConfiguration();
}
/**
* @return SearchResultSet
*/
protected function getSearchResultSet()
{
return $this->getControllerContext()->getSearchResultSet();
}
/**
* @return SolrControllerContext
* @throws \InvalidArgumentException
*/
protected function getControllerContext()
{
$controllerContext = null;
if (method_exists($this->renderingContext, 'getControllerContext')) {
$controllerContext = $this->renderingContext->getControllerContext();
}
if (!$controllerContext instanceof SolrControllerContext) {
throw new \InvalidArgumentException('No valid SolrControllerContext found', 1512998673);
}
return $controllerContext;
}
/**
* @param RenderingContextInterface $renderingContext
* @return SearchResultSet
*/
protected static function getUsedSearchResultSetFromRenderingContext(RenderingContextInterface $renderingContext)
{
$resultSet = $renderingContext->getVariableProvider()->get('resultSet');
return $resultSet;
}
}

View File

@@ -0,0 +1,42 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) 2015-2016 Timo Schmidt <timo.schmidt@dkd.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use \TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
abstract class AbstractSolrTagBasedViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var bool
*/
protected $escapeChildren = true;
/**
* @var bool
*/
protected $escapeOutput = true;
}

View File

@@ -0,0 +1,42 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers;
/***************************************************************
* Copyright notice
*
* (c) 2015-2016 Timo Schmidt <timo.schmidt@dkd.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
abstract class AbstractSolrViewHelper extends AbstractViewHelper
{
/**
* @var bool
*/
protected $escapeChildren = true;
/**
* @var bool
*/
protected $escapeOutput = true;
}

View File

@@ -0,0 +1,69 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Backend\Button;
/***************************************************************
* Copyright notice
*
* (c) 2013-2015 Ingo Renner <ingo@typo3.org>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrViewHelper;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\ViewHelperInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* View helper to return a help button
*
*/
class HelpButtonViewHelper extends AbstractSolrViewHelper implements ViewHelperInterface
{
use CompileWithRenderStatic;
/**
* @var bool
*/
protected $escapeOutput = false;
/**
*/
public function initializeArguments()
{
$this->registerArgument('title', 'string', 'Title', true);
$this->registerArgument('description', 'string', 'Description', true);
}
/**
* Render a help button wit the given title and content
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
return BackendUtility::wrapInHelp('', '', '', [
'title' => $arguments['title'],
'description' => $arguments['description']
]);
}
}

View File

@@ -0,0 +1,57 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Backend;
/***************************************************************
* Copyright notice
*
* (c) 2017 Rafael Kähm <rafael.kaehm@dkd.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
/**
* Condition for checking if type is a string.
*/
class IsStringViewHelper extends AbstractConditionViewHelper
{
/**
* Initialize ViewHelper arguments
*
* @return void
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('value', 'mixed', 'Value to be verified.', true);
}
/**
* This method decides if the condition is true or false
*
* @param array $arguments ViewHelper arguments to evaluate the condition for this ViewHelper.
* @return bool
*/
protected static function evaluateCondition($arguments = null)
{
return (isset($arguments['value']) && is_string($arguments['value']));
}
}

View File

@@ -0,0 +1,136 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Backend\Security;
/***************************************************************
* Copyright notice
*
* (c) 2010-2017 dkd Internet Service GmbH <solr-support@dkd.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractConditionViewHelper;
/**
* This view helper implements an ifHasAccessToModule/else condition for BE users/groups.
*
* Class IfHasAccessToModuleViewHelper
*/
class IfHasAccessToModuleViewHelper extends AbstractConditionViewHelper
{
/**
* Message for that case, if $arguments['signature'] was used and module does not exist
* @var string
*/
const ERROR_APPENDIX_FOR_WRONG_SIGNATURE_ARGUMENT = 'Please check spelling and style by setting signature="mainName_ExtKeySubmoduleName".';
/**
* Message for that case, if $arguments['extension'], $arguments['main'] and $arguments['sub'] are used and module couldn't be resolved
* @var string
*/
const ERROR_APPENDIX_FOR_SIGNATURE_RESOLUTION = 'It was generated by setting extension="%s", main="%s", sub="%s", please check spelling and style by setting this arguments.';
/**
* Initializes following arguments: extension, main, sub, signature
* Renders <f:then> child if the current logged in BE user belongs to the specified role (aka usergroup)
* otherwise renders <f:else> child.
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('extension', 'string', 'The extension key.');
$this->registerArgument('main', 'string', 'The main module name.');
$this->registerArgument('sub', 'string', 'The sub module name.');
$this->registerArgument('signature', 'string', 'The full signature of module. Simply mainmodulename_submodulename in most cases.');
}
/**
* Evaluate condition
*
* @param null $arguments
* @return bool
*/
protected static function evaluateCondition($arguments = null)
{
/* @var BackendUserAuthentication $beUser */
$beUser = $GLOBALS['BE_USER'];
try {
$hasAccessToModule = $beUser->modAccess(
self::getModuleConfiguration(self::getModuleSignatureFromArguments($arguments))
);
} catch (\RuntimeException $exception) {
return false;
}
return $hasAccessToModule;
}
/**
* Returns the backend module configuration
*
* @param string $moduleSignature
* @return mixed
*/
protected static function getModuleConfiguration(string $moduleSignature)
{
return $GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature];
}
/**
* Resolves
*
* @param array $arguments
* @return mixed|string
*/
protected static function getModuleSignatureFromArguments(array $arguments)
{
$moduleSignature = $arguments['signature'];
$possibleErrorMessageAppendix = self::ERROR_APPENDIX_FOR_WRONG_SIGNATURE_ARGUMENT;
$possibleErrorCode = 1496311009;
if (!is_string($moduleSignature)) {
$moduleSignature = $arguments['main'];
$subModuleName = $arguments['extension'] . GeneralUtility::underscoredToUpperCamelCase($arguments['sub']);
$moduleSignature .= '_' . $subModuleName;
$possibleErrorMessageAppendix = vsprintf(self::ERROR_APPENDIX_FOR_SIGNATURE_RESOLUTION, [$arguments['extension'], $arguments['main'], $arguments['sub']]);
$possibleErrorCode = 1496311010;
}
if (!isset($GLOBALS['TBE_MODULES']['_configuration'][$moduleSignature])) {
throw new \RuntimeException(vsprintf('Module with signature "%s" is not configured or couldn\'t be resolved. ' . $possibleErrorMessageAppendix, [$moduleSignature]), $possibleErrorCode);
}
return $moduleSignature;
}
/**
* Validates arguments given to this view helper.
*
* It checks if either signature or extension and main and sub are set.
*/
public function validateArguments()
{
parent::validateArguments();
if (empty($this->arguments['signature'])
&& (empty($this->arguments['extension']) || empty($this->arguments['main']) || empty($this->arguments['sub'])
)
) {
throw new \InvalidArgumentException('ifHasAccessToModule view helper requires either "signature" or all three other arguments: "extension", "main" and "sub". Please set arguments properly.', 1496314352);
}
}
}

View File

@@ -0,0 +1,97 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Debug;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Result\SearchResult;
use WapplerSystems\Meilisearch\Domain\Search\Score\ScoreCalculationService;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrFrontendViewHelper;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Class DocumentScoreAnalyzerViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class DocumentScoreAnalyzerViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;
/**
* @var ScoreCalculationService
*/
protected static $scoreService;
/**
* @var bool
*/
protected $escapeOutput = false;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('document', SearchResult::class, 'The solr document', true);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$content = '';
// only check whether a BE user is logged in, don't need to check
// for enabled score analysis as we wouldn't be here if it was disabled
$backendUserIsLoggedIn = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('backend.user', 'isLoggedIn');
if ($backendUserIsLoggedIn === false) {
return $content;
}
$document = $arguments['document'];
/** @var $resultSet SearchResultSet */
$resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
$debugData = $resultSet->getUsedSearch()->getDebugResponse()->explain->{$document->getId()};
/** @var $scoreService ScoreCalculationService */
$scoreService = self::getScoreService();
$queryFields = $resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchQueryQueryFields();
$content = $scoreService->getRenderedScores($debugData, $queryFields);
return '<div class="document-score-analysis">' . $content . '</div>';
}
/**
* @return ScoreCalculationService
*/
protected static function getScoreService()
{
if (isset(self::$scoreService)) {
return self::$scoreService;
}
self::$scoreService = GeneralUtility::makeInstance(ScoreCalculationService::class);
return self::$scoreService;
}
}

View File

@@ -0,0 +1,54 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Debug;
/*
* 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!
*/
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrFrontendViewHelper;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Class QueryViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class QueryViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;
/**
* @var bool
*/
protected $escapeOutput = false;
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$content = '';
$resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
$backendUserIsLoggedIn = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('backend.user', 'isLoggedIn');
if ($backendUserIsLoggedIn === true && $resultSet && $resultSet->getUsedSearch() !== null) {
$content = '<br><strong>Parsed Query:</strong><br>' . htmlspecialchars($resultSet->getUsedSearch()->getDebugResponse()->parsedquery);
}
return $content;
}
}

View File

@@ -0,0 +1,110 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Document;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Result\SearchResult;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrFrontendViewHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Class HighlightResultViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class HighlightResultViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;
/**
* @var bool
*/
protected $escapeOutput = false;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('resultSet', SearchResultSet::class, 'The context searchResultSet', true);
$this->registerArgument('document', SearchResult::class, 'The document to highlight', true);
$this->registerArgument('fieldName', 'string', 'The fieldName', true);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
/** @var $resultSet SearchResultSet */
$resultSet = $arguments['resultSet'];
$fieldName = $arguments['fieldName'];
$document = $arguments['document'];
$content = self::getHighlightedContent($resultSet, $document, $fieldName);
return self::escapeEverythingExceptAllowedTags($resultSet, $content);
}
/**
* @param SearchResultSet $resultSet
* @param $document
* @param $fieldName
* @return mixed|string
*/
protected static function getHighlightedContent(SearchResultSet $resultSet, $document, $fieldName)
{
$fragmentSeparator = $resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchResultsHighlightingFragmentSeparator();
$content = call_user_func([$document, 'get' . $fieldName]);
$highlightedContent = $resultSet->getUsedSearch()->getHighlightedContent();
if (!empty($highlightedContent->{$document->getId()}->{$fieldName}[0])) {
$content = implode(' ' . $fragmentSeparator . ' ', $highlightedContent->{$document->getId()}->{$fieldName});
return $content;
}
return $content;
}
/**
* @param SearchResultSet $resultSet
* @param $content
* @return string
*/
protected static function escapeEverythingExceptAllowedTags(SearchResultSet $resultSet, $content)
{
$wrap = $resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchResultsHighlightingWrap();
if ($wrap === '') {
return htmlspecialchars($content);
}
$wrapParts = GeneralUtility::trimExplode("|", $wrap);
if (count($wrapParts) !== 2) {
return htmlspecialchars($content);
}
$substitutedContent = str_replace($wrapParts[0], '___highlight_begin___', $content);
$substitutedContent = str_replace($wrapParts[1], '___highlight_end___', $substitutedContent);
$output = htmlspecialchars($substitutedContent);
$output = str_replace('___highlight_begin___', $wrapParts[0], $output);
$output = str_replace('___highlight_end___', $wrapParts[1], $output);
return $output;
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Document;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Result\SearchResult;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrFrontendViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Class RelevanceViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class RelevanceViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('resultSet', SearchResultSet::class, 'The context searchResultSet', true);
$this->registerArgument('document', SearchResult::class, 'The document to highlight', true);
$this->registerArgument('maximumScore', 'float', 'The maximum score that should be used for percentage calculation, if nothing is passed the maximum from the resultSet is used', false);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
/** @var $document SearchResult */
$document = $arguments['document'];
/** @var $resultSet SearchResultSet */
$resultSet = $arguments['resultSet'];
$maximumScore = $arguments['maximumScore'] ?? $resultSet->getMaximumScore();
$content = 0;
if ($maximumScore <= 0) {
return $content;
}
$documentScore = $document->getScore();
$score = floatval($documentScore);
$multiplier = 100 / $maximumScore;
$scorePercentage = round($score * $multiplier);
$content = $scorePercentage;
return $content;
}
}

View File

@@ -0,0 +1,67 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Facet\Area;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\FacetCollection;
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrFrontendViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Class GroupViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de> *
*/
class GroupViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;
/**
* @var bool
*/
protected $escapeOutput = false;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('facets', FacetCollection::class, 'The facets that should be filtered', true);
$this->registerArgument('groupName', 'string', 'The groupName that should be shown', false, 'main');
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
/** @var $facets FacetCollection */
$facets = $arguments['facets'];
$requiredGroup = isset($arguments['groupName']) ? $arguments['groupName'] : 'main';
$filtered = $facets->getByGroupName($requiredGroup);
$templateVariableProvider = $renderingContext->getVariableProvider();
$templateVariableProvider->add('areaFacets', $filtered);
$content = $renderChildrenClosure();
$templateVariableProvider->remove('areaFacets');
return $content;
}
}

View File

@@ -0,0 +1,76 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Facet\Options\Group\Prefix;
/***************************************************************
* Copyright notice
*
* (c) 2017 Timo Hund <timo.hund@dkd.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\OptionBased\OptionCollection;
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrFrontendViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Class LabelFilterViewHelper
*
* @author Timo Hund <timo.hund@dkd.de>
*/
class LabelFilterViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;
/**
* @var bool
*/
protected $escapeOutput = false;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('options', OptionCollection::class, 'The facets that should be filtered', true);
$this->registerArgument('prefix', 'string', 'The prefix where options should be filtered on', true);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
/** @var $options OptionCollection */
$options = $arguments['options'];
$requiredPrefix = mb_strtolower($arguments['prefix']);
$filtered = $options->getByLowercaseLabelPrefix($requiredPrefix);
$templateVariableProvider = $renderingContext->getVariableProvider();
$templateVariableProvider->add('filteredOptions', $filtered);
$content = $renderChildrenClosure();
$templateVariableProvider->remove('filteredOptions');
return $content;
}
}

View File

@@ -0,0 +1,102 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Facet\Options\Group\Prefix;
/***************************************************************
* Copyright notice
*
* (c) 2017 Timo Hund <timo.hund@dkd.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\OptionBased\OptionCollection;
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrFrontendViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Class LabelPrefixesViewHelper
*
* @author Timo Hund <timo.hund@dkd.de>
*/
class LabelPrefixesViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;
/**
* @var bool
*/
protected $escapeOutput = false;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('options', OptionCollection::class, 'The options where prefixed should be available', true);
$this->registerArgument('length', 'int', 'The length of the prefixed that should be retrieved', false, 1);
$this->registerArgument('sortBy', 'string', 'The sorting mode (count,alpha)', false, 'count');
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
/** @var $options OptionCollection */
$options = $arguments['options'];
$length = isset($arguments['length']) ? $arguments['length'] : 1;
$sortBy = isset($arguments['sortBy']) ? $arguments['sortBy'] : 'count';
$prefixes = $options->getLowercaseLabelPrefixes($length);
$prefixes = static::applySortBy($prefixes, $sortBy);
$templateVariableProvider = $renderingContext->getVariableProvider();
$templateVariableProvider->add('prefixes', $prefixes);
$content = $renderChildrenClosure();
$templateVariableProvider->remove('prefixes');
return $content;
}
/**
* Applies the configured sortBy.
*
* @param array $prefixes
* @param string $sortBy
* @return array
*/
protected static function applySortBy(array $prefixes, $sortBy): array
{
if($sortBy === 'count' || $sortBy === '')
{
return $prefixes;
}
if($sortBy === 'alpha')
{
sort($prefixes);
return $prefixes;
}
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Format;
/*
* 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!
*/
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
/**
* Class ArrayViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class ArrayViewHelper extends AbstractViewHelper
{
/**
* Make sure values is a array else convert
*
* @param string|array $value
* @return array
*/
public function render($value)
{
return (array)$value;
}
}

View File

@@ -0,0 +1,75 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers;
/*
* 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!
*/
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Class PageBrowserRangeViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class PageBrowserRangeViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('from', 'string', 'from', false, 'from');
$this->registerArgument('to', 'string', 'to', false, 'to');
$this->registerArgument('total', 'string', 'total', false, 'total');
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$from = $arguments['from'];
$to = $arguments['to'];
$total = $arguments['total'];
$resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
$search = $resultSet->getUsedSearch();
$variableProvider = $renderingContext->getVariableProvider();
$numberOfResultsOnPage = $resultSet->getSearchResults()->getCount();
$numberOfAllResults = $resultSet->getAllResultCount();
$resultsFrom = $search->getResponseBody()->start + 1;
$resultsTo = $resultsFrom + $numberOfResultsOnPage - 1;
$variableProvider->add($from, $resultsFrom);
$variableProvider->add($to, $resultsTo);
$variableProvider->add($total, $numberOfAllResults);
$content = $renderChildrenClosure();
$variableProvider->remove($from);
$variableProvider->remove($to);
$variableProvider->remove($total);
return $content;
}
}

View File

@@ -0,0 +1,257 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers;
/*
* 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!
*/
use WapplerSystems\Meilisearch\System\Url\UrlHelper;
use WapplerSystems\Meilisearch\System\Util\SiteUtility;
use WapplerSystems\Meilisearch\Util;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* Class SearchFormViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class SearchFormViewHelper extends AbstractSolrFrontendTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'form';
/**
* @var TypoScriptFrontendController
*/
protected $frontendController;
/**
* @var bool
*/
protected $escapeChildren = true;
/**
* @var bool
*/
protected $escapeOutput = false;
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->frontendController = $GLOBALS['TSFE'];
}
/**
* Initialize arguments.
*
* @return void
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerTagAttribute('enctype', 'string', 'MIME type with which the form is submitted');
$this->registerTagAttribute('method', 'string', 'Transfer type (GET or POST)', false, 'get');
$this->registerTagAttribute('name', 'string', 'Name of form');
$this->registerTagAttribute('onreset', 'string', 'JavaScript: On reset of the form');
$this->registerTagAttribute('onsubmit', 'string', 'JavaScript: On submit of the form');
$this->registerUniversalTagAttributes();
$this->registerArgument('pageUid', 'integer', 'When not set current page is used', false);
$this->registerArgument('additionalFilters', 'array', 'Additional filters', false);
$this->registerArgument('additionalParams', 'array', 'Query parameters to be attached to the resulting URI', false, []);
$this->registerArgument('pageType', 'integer', 'Type of the target page. See typolink.parameter', false, 0);
$this->registerArgument('noCache', 'boolean', 'Set this to disable caching for the target page. You should not need this.', false, false);
$this->registerArgument('noCacheHash', 'boolean', 'Set this to supress the cHash query parameter created by TypoLink. You should not need this.', false, false);
$this->registerArgument('section', 'string', 'The anchor to be added to the action URI (only active if $actionUri is not set)', false, '');
$this->registerArgument('absolute', 'boolean', 'If set, the URI of the rendered link is absolute', false, false);
$this->registerArgument('addQueryString', 'boolean', 'If set, the current query parameters will be kept in the URI', false, false);
$this->registerArgument('argumentsToBeExcludedFromQueryString', 'array', 'arguments to be removed from the URI. Only active if $addQueryString = TRUE', false, []);
$this->registerArgument('addQueryStringMethod', 'string', 'Set which parameters will be kept. Only active if $addQueryString = TRUE', false);
$this->registerArgument('addSuggestUrl', 'boolean', 'Indicates if suggestUrl should be rendered or not', false, true);
$this->registerArgument('suggestHeader', 'string', 'The header for the top results', false, 'Top Results');
$this->registerArgument('suggestPageType', 'integer', 'The page type that should be used for the suggest', false, 7384);
}
/**
* Render search form tag
*
* @return string
*/
public function render()
{
$pageUid = $this->arguments['pageUid'];
if ($pageUid === null && !empty($this->getTypoScriptConfiguration()->getSearchTargetPage())) {
$pageUid = $this->getTypoScriptConfiguration()->getSearchTargetPage();
}
$uri = $this->buildUriFromPageUidAndArguments($pageUid);
$this->tag->addAttribute('action', trim($uri));
if ($this->arguments['addSuggestUrl']) {
$this->tag->addAttribute('data-suggest', $this->getSuggestUrl($this->arguments['additionalFilters'], $pageUid));
}
$this->tag->addAttribute('data-suggest-header', htmlspecialchars($this->arguments['suggestHeader']));
$this->tag->addAttribute('accept-charset', $this->frontendController->metaCharset);
// Get search term
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->add('q', $this->getQueryString());
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->add('pageUid', $pageUid);
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->add('languageUid', Util::getLanguageUid());
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->add('existingParameters', $this->getExistingSearchParameters());
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->add('addPageAndLanguageId', !$this->getIsSiteManagedSite($pageUid));
$formContent = $this->renderChildren();
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->remove('addPageAndLanguageId');
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->remove('q');
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->remove('pageUid');
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->remove('languageUid');
// @extensionScannerIgnoreLine
$this->getTemplateVariableContainer()->remove('existingParameters');
$this->tag->setContent($formContent);
return $this->tag->render();
}
/**
* Get the existing search parameters in an array
* Returns an empty array if search.keepExistingParametersForNewSearches is not set
*
* @return array
*/
protected function getExistingSearchParameters()
{
$searchParameters = [];
if ($this->getTypoScriptConfiguration()->getSearchKeepExistingParametersForNewSearches()) {
$arguments = GeneralUtility::_GPmerged($this->getTypoScriptConfiguration()->getSearchPluginNamespace());
unset($arguments['q'], $arguments['id'], $arguments['L']);
$searchParameters = $this->translateSearchParametersToInputTagAttributes($arguments);
}
return $searchParameters;
}
/**
* Translate the multi-dimensional array of existing arguments into a flat array of name-value pairs for the input tags
*
* @param $arguments
* @param string $nameAttributePrefix
* @return array
*/
protected function translateSearchParametersToInputTagAttributes($arguments, $nameAttributePrefix = '')
{
$attributes = [];
foreach ($arguments as $key => $value) {
$name = $nameAttributePrefix . '[' . $key . ']';
if (is_array($value)) {
$attributes = array_merge(
$attributes,
$this->translateSearchParametersToInputTagAttributes($value, $name)
);
} else {
$attributes[$name] = $value;
}
}
return $attributes;
}
/**
* When a site is managed with site management the language and the id are encoded in the path segment of the url.
* When no speaking urls are active (e.g. with TYPO3 8 and no realurl) this information is passed as query parameter
* and would get lost when it is only part of the query arguments in the action parameter of the form.
*
* @return boolean
*/
protected function getIsSiteManagedSite($pageId)
{
return SiteUtility::getIsSiteManagedSite($pageId);
}
/**
* @return \TYPO3Fluid\Fluid\Core\Variables\VariableProviderInterface
*/
protected function getTemplateVariableContainer()
{
return $this->templateVariableContainer;
}
/**
* @return string
*/
protected function getQueryString()
{
$resultSet = $this->getSearchResultSet();
if ($resultSet === null) {
return '';
}
return trim($this->getSearchResultSet()->getUsedSearchRequest()->getRawUserQuery());
}
/**
* @param NULL|array $additionalFilters
* @param int $pageUid
* @return string
*/
protected function getSuggestUrl($additionalFilters, $pageUid)
{
$uriBuilder = $this->getControllerContext()->getUriBuilder();
$pluginNamespace = $this->getTypoScriptConfiguration()->getSearchPluginNamespace();
$suggestUrl = $uriBuilder->reset()->setTargetPageUid($pageUid)->setTargetPageType($this->arguments['suggestPageType'])->setUseCacheHash(false)->setArguments([$pluginNamespace => ['additionalFilters' => $additionalFilters]])->build();
/* @var UrlHelper $urlService */
$urlService = GeneralUtility::makeInstance(UrlHelper::class, $suggestUrl);
$suggestUrl = $urlService->removeQueryParameter('cHash')->getUrl();
return $suggestUrl;
}
/**
* @param int|null $pageUid
* @return string
*/
protected function buildUriFromPageUidAndArguments($pageUid): string
{
$uriBuilder = $this->getControllerContext()->getUriBuilder();
$uri = $uriBuilder
->reset()
->setTargetPageUid($pageUid)
->setTargetPageType($this->arguments['pageType'] ?? 0)
->setNoCache($this->arguments['noCache'] ?? false)
->setUseCacheHash(!$this->arguments['noCacheHash'])
->setArguments($this->arguments['additionalParams'] ?? [])
->setCreateAbsoluteUri($this->arguments['absolute'] ?? false)
->setAddQueryString($this->arguments['addQueryString'] ?? false)
->setArgumentsToBeExcludedFromQueryString($this->arguments['argumentsToBeExcludedFromQueryString'] ?? [])
->setAddQueryStringMethod($this->arguments['addQueryStringMethod'] ?? '')
->setSection($this->arguments['section'] ?? '')
->build();
return $uri;
}
}

View File

@@ -0,0 +1,94 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers;
/*
* 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!
*/
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Fluid\ViewHelpers\TranslateViewHelper as CoreTranslateViewHelper;
use TYPO3Fluid\Fluid\Core\Parser\SyntaxTree\ViewHelperNode;
use TYPO3Fluid\Fluid\Core\Compiler\TemplateCompiler;
/**
* Class TranslateViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class TranslateViewHelper extends CoreTranslateViewHelper
{
/**
* @var bool
*/
protected $escapeChildren = true;
/**
* @return string|null
*/
public function render()
{
$result = parent::render();
$result = self::replaceTranslationPrefixesWithAtWithStringMarker($result);
$result = vsprintf($result, $this->arguments['arguments']);
return $result;
}
/**
* Wrapper call to static LocalizationUtility
*
* @param string $id Translation Key compatible to TYPO3 Flow
* @param string $extensionName UpperCamelCased extension key (for example BlogExample)
* @param array $arguments Arguments to be replaced in the resulting string
* @param string $languageKey Language key to use for this translation
* @param string[] $alternativeLanguageKeys Alternative language keys if no translation does exist
*
* @return string|null
*/
public static function translateAndReplaceMarkers($id, $extensionName, $arguments, $languageKey, $alternativeLanguageKeys)
{
$result = LocalizationUtility::translate($id, $extensionName, $arguments, $languageKey, $alternativeLanguageKeys);
$result = self::replaceTranslationPrefixesWithAtWithStringMarker($result);
$result = vsprintf($result, $arguments);
return $result;
}
/**
* @param string $argumentsName
* @param string $closureName
* @param string $initializationPhpCode
* @param ViewHelperNode $node
* @param TemplateCompiler $compiler
* @return string
*/
public function compile($argumentsName, $closureName, &$initializationPhpCode, ViewHelperNode $node, TemplateCompiler $compiler)
{
return sprintf(
'\\%1$s::translateAndReplaceMarkers(%2$s[\'key\'] ?? %2$s[\'id\'], %2$s[\'extensionName\'] ?? $renderingContext->getControllerContext()->getRequest()->getControllerExtensionName(), %2$s[\'arguments\'], %2$s[\'languageKey\'], %2$s[\'alternativeLanguageKeys\']) ?? %2$s[\'default\'] ?? %3$s()',
static::class,
$argumentsName,
$closureName
);
}
/**
* @param $result
* @return mixed
*/
protected static function replaceTranslationPrefixesWithAtWithStringMarker($result)
{
if (strpos($result, '@') !== false) {
$result = preg_replace('~\"?@[a-zA-Z]*\"?~', '%s', $result);
}
return $result;
}
}

View File

@@ -0,0 +1,79 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use WapplerSystems\Meilisearch\Domain\Search\Uri\SearchUriBuilder;
use WapplerSystems\Meilisearch\Mvc\Controller\SolrControllerContext;
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrFrontendViewHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Class AbstractUriViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
abstract class AbstractUriViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;
/**
* @var SearchUriBuilder
*/
protected static $searchUriBuilder;
/**
* @param SearchUriBuilder $searchUriBuilder
*/
public function injectSearchUriBuilder(SearchUriBuilder $searchUriBuilder)
{
self::$searchUriBuilder = $searchUriBuilder;
}
/**
* @param RenderingContextInterface|null $renderingContext
* @return SearchUriBuilder|object
*/
protected static function getSearchUriBuilder(RenderingContextInterface $renderingContext = null)
{
if (!isset(self::$searchUriBuilder)) {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
self::$searchUriBuilder = $objectManager->get(SearchUriBuilder::class);
}
if ($renderingContext && method_exists($renderingContext, 'getControllerContext')) {
self::$searchUriBuilder->injectUriBuilder($renderingContext->getControllerContext()->getUriBuilder());
}
return self::$searchUriBuilder;
}
/**
* @param RenderingContextInterface $renderingContext
* @return mixed
*/
protected static function getUsedSearchRequestFromRenderingContext(RenderingContextInterface $renderingContext) {
$resultSet = static::getUsedSearchResultSetFromRenderingContext($renderingContext);
if (!$resultSet instanceof SearchResultSet) {
throw new \InvalidArgumentException("The variable resultSet need to be defined in the scope of " . static::class);
}
return $resultSet->getUsedSearchRequest();
}
}

View File

@@ -0,0 +1,102 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Facet;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\AbstractFacet;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\AbstractFacetItem;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use WapplerSystems\Meilisearch\ViewHelpers\Uri\AbstractUriViewHelper;
/**
* Class AbstractValueViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
abstract class AbstractValueViewHelper extends AbstractUriViewHelper
{
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('facet', AbstractFacet::class, 'The facet', false, null);
$this->registerArgument('facetName', 'string', 'The facet name', false, null);
$this->registerArgument('facetItem', AbstractFacetItem::class, 'The facet item', false, null);
$this->registerArgument('facetItemValue', 'string', 'The facet item', false, null);
$this->registerArgument('resultSet', SearchResultSet::class, 'The result set', false, null);
}
/**
* @param $arguments
* @return string
* @throws \InvalidArgumentException
*/
protected static function getValueFromArguments($arguments)
{
if (isset($arguments['facetItem'])) {
/** @var $facetItem AbstractFacetItem */
$facetItem = $arguments['facetItem'];
$facetValue = $facetItem->getUriValue();
} elseif (isset($arguments['facetItemValue'])) {
$facetValue = $arguments['facetItemValue'];
} else {
throw new \InvalidArgumentException('No facetItem was passed, please pass either facetItem or facetItemValue');
}
return $facetValue;
}
/**
* @param $arguments
* @return string
* @throws \InvalidArgumentException
*/
protected static function getNameFromArguments($arguments)
{
if (isset($arguments['facet'])) {
/** @var $facet AbstractFacet */
$facet = $arguments['facet'];
$facetName = $facet->getName();
} elseif (isset($arguments['facetName'])) {
$facetName = $arguments['facetName'];
} else {
throw new \InvalidArgumentException('No facet was passed, please pass either facet or facetName');
}
return $facetName;
}
/**
* @param $arguments
* @return string
* @throws \InvalidArgumentException
*/
protected static function getResultSetFromArguments($arguments)
{
if (isset($arguments['facet'])) {
/** @var $facet AbstractFacet */
$facet = $arguments['facet'];
$resultSet = $facet->getResultSet();
} elseif (isset($arguments['facetName'])) {
$resultSet = $arguments['resultSet'];
} else {
throw new \InvalidArgumentException('No facet was passed, please pass either facet or resultSet');
}
return $resultSet;
}
}

View File

@@ -0,0 +1,45 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Facet;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class AddFacetItemViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class AddFacetItemViewHelper extends AbstractValueViewHelper
{
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
* @throws \InvalidArgumentException
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
/** @var $resultSet SearchResultSet */
$name = self::getNameFromArguments($arguments);
$itemValue = self::getValueFromArguments($arguments);
$resultSet = self::getResultSetFromArguments($arguments);
$previousRequest = $resultSet->getUsedSearchRequest();
$uri = self::getSearchUriBuilder($renderingContext)->getAddFacetValueUri($previousRequest, $name, $itemValue);
return $uri;
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Facet;
/*
* 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!
*/
use WapplerSystems\Meilisearch\ViewHelpers\Uri\AbstractUriViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class RemoveAllFacetsViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class RemoveAllFacetsViewHelper extends AbstractUriViewHelper
{
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
* @throws \InvalidArgumentException
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$previousRequest = static::getUsedSearchRequestFromRenderingContext($renderingContext);
$uri = self::getSearchUriBuilder($renderingContext)->getRemoveAllFacetsUri($previousRequest);
return $uri;
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Facet;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class RemoveFacetItemViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class RemoveFacetItemViewHelper extends AbstractValueViewHelper
{
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
* @throws \InvalidArgumentException
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
/** @var $resultSet SearchResultSet */
$name = self::getNameFromArguments($arguments);
$itemValue = self::getValueFromArguments($arguments);
$resultSet = self::getResultSetFromArguments($arguments);
$previousRequest = $resultSet->getUsedSearchRequest();
$uri = self::getSearchUriBuilder($renderingContext)->getRemoveFacetValueUri($previousRequest, $name, $itemValue);
return $uri;
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Facet;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Facets\AbstractFacet;
use WapplerSystems\Meilisearch\ViewHelpers\Uri\AbstractUriViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class RemoveFacetViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class RemoveFacetViewHelper extends AbstractUriViewHelper
{
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('facet', AbstractFacet::class, 'The facet', true);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
* @throws \InvalidArgumentException
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
/** @var $facet AbstractFacet */
$facet = $arguments['facet'];
$previousRequest = $facet->getResultSet()->getUsedSearchRequest();
$uri = self::getSearchUriBuilder($renderingContext)->getRemoveFacetUri($previousRequest, $facet->getName());
return $uri;
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Facet;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class SetFacetItemViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class SetFacetItemViewHelper extends AbstractValueViewHelper
{
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
* @throws \InvalidArgumentException
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
/** @var $resultSet SearchResultSet */
$name = self::getNameFromArguments($arguments);
$itemValue = self::getValueFromArguments($arguments);
$resultSet = self::getResultSetFromArguments($arguments);
$previousRequest = $resultSet->getUsedSearchRequest();
$uri = self::getSearchUriBuilder($renderingContext)->getSetFacetValueUri($previousRequest, $name, $itemValue);
return $uri;
}
}

View File

@@ -0,0 +1,55 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Paginate;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Grouping\GroupItem;
use WapplerSystems\Meilisearch\ViewHelpers\Uri\AbstractUriViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class GroupItemPageViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class GroupItemPageViewHelper extends AbstractUriViewHelper
{
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('page', 'int', 'The page', false, 0);
$this->registerArgument('groupItem', GroupItem::class, 'The group item', true);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$page = $arguments['page'];
$groupItem = $arguments['groupItem'];
$previousRequest = static::getUsedSearchRequestFromRenderingContext($renderingContext);
$uri = self::getSearchUriBuilder($renderingContext)->getResultGroupItemPageUri($previousRequest, $groupItem, (int)$page);
return $uri;
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Paginate;
/*
* 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!
*/
use WapplerSystems\Meilisearch\ViewHelpers\Uri\AbstractUriViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class ResultPageViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class ResultPageViewHelper extends AbstractUriViewHelper
{
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('page', 'int', 'The page', false, 0);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$page = $arguments['page'];
$previousRequest = static::getUsedSearchRequestFromRenderingContext($renderingContext);
$uri = self::getSearchUriBuilder($renderingContext)->getResultPageUri($previousRequest, $page);
return $uri;
}
}

View File

@@ -0,0 +1,70 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Result;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\Highlight\SiteHighlighterUrlModifier;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use WapplerSystems\Meilisearch\ViewHelpers\AbstractSolrFrontendViewHelper;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Class AddSearchWordListViewHelper
*
* @author Timo Hund <timo.hund@dkd.de>
*/
class AddSearchWordListViewHelper extends AbstractSolrFrontendViewHelper
{
use CompileWithRenderStatic;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('url', 'string', 'The context searchResultSet', true);
$this->registerArgument('searchWords', 'string', 'The document to highlight', true);
$this->registerArgument('addNoCache', 'boolean', 'Should no_cache=1 be added or not', false, true);
$this->registerArgument('keepCHash', 'boolean', 'Should cHash be kept or not', false, false);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$url = $arguments['url'];
/** @var $resultSet SearchResultSet */
$resultSet = self::getUsedSearchResultSetFromRenderingContext($renderingContext);
if (!$resultSet->getUsedSearchRequest()->getContextTypoScriptConfiguration()->getSearchResultsSiteHighlighting()) {
return $url;
}
$searchWords = $arguments['searchWords'];
$addNoCache = $arguments['addNoCache'];
$keepCHash = $arguments['keepCHash'];
/** @var $siteHighlighterUrlModifier SiteHighlighterUrlModifier */
$siteHighlighterUrlModifier = GeneralUtility::makeInstance(SiteHighlighterUrlModifier::class);
return $siteHighlighterUrlModifier->modify($url, $searchWords, $addNoCache, $keepCHash);
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Search;
/*
* 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!
*/
use WapplerSystems\Meilisearch\ViewHelpers\Uri\AbstractUriViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class CurrentSearchViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class CurrentSearchViewHelper extends AbstractUriViewHelper
{
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$previousRequest = static::getUsedSearchRequestFromRenderingContext($renderingContext);
$uri = self::getSearchUriBuilder($renderingContext)->getCurrentSearchUri($previousRequest);
return $uri;
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Search;
/*
* 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!
*/
use WapplerSystems\Meilisearch\ViewHelpers\Uri\AbstractUriViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class StartNewSearchViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class StartNewSearchViewHelper extends AbstractUriViewHelper
{
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('queryString', 'string', 'The query string', false, '');
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$queryString = $arguments['queryString'];
$previousRequest = static::getUsedSearchRequestFromRenderingContext($renderingContext);
$uri = self::getSearchUriBuilder($renderingContext)->getNewSearchUri($previousRequest, $queryString);
return $uri;
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Sorting;
/*
* 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!
*/
use WapplerSystems\Meilisearch\ViewHelpers\Uri\AbstractUriViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class RemoveSortingViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class RemoveSortingViewHelper extends AbstractUriViewHelper
{
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$previousRequest = static::getUsedSearchRequestFromRenderingContext($renderingContext);
$uri = self::getSearchUriBuilder($renderingContext)->getRemoveSortingUri($previousRequest);
return $uri;
}
}

View File

@@ -0,0 +1,53 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Uri\Sorting;
/*
* 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!
*/
use WapplerSystems\Meilisearch\ViewHelpers\Uri\AbstractUriViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Class SetSortingViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class SetSortingViewHelper extends AbstractUriViewHelper
{
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('sortingName', 'string', 'The sortingName', true);
$this->registerArgument('sortingDirection', 'string', 'The sortingDirection', true);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$sortingName = $arguments['sortingName'];
$sortingDirection = $arguments['sortingDirection'];
$previousRequest = static::getUsedSearchRequestFromRenderingContext($renderingContext);
$uri = self::getSearchUriBuilder($renderingContext)->getSetSortingUri($previousRequest, $sortingName, $sortingDirection);
return $uri;
}
}

View File

@@ -0,0 +1,136 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Widget\Controller;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Widget\AbstractWidgetController;
use TYPO3\CMS\Core\Utility\ArrayUtility;
/**
* Class AbstractPaginateWidgetController
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
abstract class AbstractPaginateWidgetController extends AbstractWidgetController
{
/**
* @var array
*/
protected $configuration = [
'insertAbove' => true,
'insertBelow' => true,
'maximumNumberOfLinks' => 10,
'addQueryStringMethod' => '',
'templatePath' => ''
];
/**
* @var int
*/
protected $currentPage = 1;
/**
* @var int
*/
protected $displayRangeStart;
/**
* @var int
*/
protected $displayRangeEnd;
/**
* @var int
*/
protected $maximumNumberOfLinks = 99;
/**
* @var int
*/
protected $numberOfPages = 1;
/**
* @var string
*/
protected $templatePath = '';
/**
* @return void
*/
public function initializeAction() {
$configuration = is_array($this->widgetConfiguration['configuration']) ? $this->widgetConfiguration['configuration'] : [];
ArrayUtility::mergeRecursiveWithOverrule($this->configuration, $configuration, false);
$this->maximumNumberOfLinks = (int)$this->configuration['maximumNumberOfLinks'];
if (!empty($this->configuration['templatePath'])) {
$this->templatePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName($this->configuration['templatePath']);
}
}
/**
* If a certain number of links should be displayed, adjust before and after
* amounts accordingly.
*
* @return void
*/
protected function calculateDisplayRange()
{
$maximumNumberOfLinks = $this->maximumNumberOfLinks;
if ($maximumNumberOfLinks > $this->numberOfPages) {
$maximumNumberOfLinks = $this->numberOfPages;
}
$delta = floor($maximumNumberOfLinks / 2);
$this->displayRangeStart = $this->currentPage - $delta;
$this->displayRangeEnd = $this->currentPage + $delta - ($maximumNumberOfLinks % 2 === 0 ? 1 : 0);
if ($this->displayRangeStart < 1) {
$this->displayRangeEnd -= $this->displayRangeStart - 1;
}
if ($this->displayRangeEnd > $this->numberOfPages) {
$this->displayRangeStart -= $this->displayRangeEnd - $this->numberOfPages;
}
$this->displayRangeStart = (int)max($this->displayRangeStart, 1);
$this->displayRangeEnd = (int)min($this->displayRangeEnd, $this->numberOfPages);
}
/**
* Returns an array with the keys "pages", "current", "numberOfPages", "nextPage" & "previousPage"
*
* @return array
*/
protected function buildPagination()
{
$this->calculateDisplayRange();
$pages = [];
for ($i = $this->displayRangeStart; $i <= $this->displayRangeEnd; $i++) {
$pages[] = ['number' => $i, 'isCurrent' => $i === $this->currentPage];
}
$pagination = ['pages' => $pages, 'current' => $this->currentPage, 'numberOfPages' => $this->numberOfPages, 'displayRangeStart' => $this->displayRangeStart, 'displayRangeEnd' => $this->displayRangeEnd, 'hasLessPages' => $this->displayRangeStart > 2, 'hasMorePages' => $this->displayRangeEnd + 1 < $this->numberOfPages];
if ($this->currentPage < $this->numberOfPages) {
$pagination['nextPage'] = $this->currentPage + 1;
}
if ($this->currentPage > 1) {
$pagination['previousPage'] = $this->currentPage - 1;
}
// calculate starting count for <ol> (items per page multiplied by (number of pages -1) and adding +1)
$pagination['resultCountStart'] = (($this->getItemsPerPage() * ($this->currentPage - 1)) + 1);
return $pagination;
}
/**
* @return int
*/
abstract protected function getItemsPerPage();
}

View File

@@ -0,0 +1,114 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Widget\Controller;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\FrequentSearches\FrequentSearchesService;
use WapplerSystems\Meilisearch\Widget\AbstractWidgetController;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class FrequentlySearchedController
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class FrequentlySearchedController extends AbstractWidgetController implements LoggerAwareInterface
{
use LoggerAwareTrait;
/**
* Initializes the cache for this command.
*
* @return FrontendInterface|null
*/
protected function getInitializedCache(): ?FrontendInterface
{
$cacheIdentifier = 'tx_meilisearch';
/* @var FrontendInterface $cacheInstance */
try {
$cacheInstance = GeneralUtility::makeInstance(CacheManager::class)->getCache($cacheIdentifier);
} catch (NoSuchCacheException $exception) {
$this->logger->error('Getting cache failed: ' . $exception->getMessage());
return null;
}
return $cacheInstance;
}
/**
* Last searches
*/
public function indexAction()
{
$tsfe = $GLOBALS['TSFE'];
$cache = $this->getInitializedCache();
$configuration = $this->controllerContext->getTypoScriptConfiguration();
/* @var FrequentSearchesService $frequentSearchesService */
$frequentSearchesService = GeneralUtility::makeInstance(
FrequentSearchesService::class,
/** @scrutinizer ignore-type */ $configuration,
/** @scrutinizer ignore-type */ $cache,
/** @scrutinizer ignore-type */ $tsfe
);
$frequentSearches = $frequentSearchesService->getFrequentSearchTerms();
$minimumSize = $configuration->getSearchFrequentSearchesMinSize();
$maximumSize = $configuration->getSearchFrequentSearchesMaxSize();
$this->view->assign(
'contentArguments',
[
'frequentSearches' => $this->enrichFrequentSearchesInfo($frequentSearches, $minimumSize, $maximumSize)
]
);
}
/**
* Enrich the frequentSearches
*
* @param array Frequent search terms as array with terms as keys and hits as the value
* @param int $minimumSize
* @param int $maximumSize
* @return array An array with content for the frequent terms markers
*/
protected function enrichFrequentSearchesInfo(array $frequentSearchTerms, int $minimumSize, int $maximumSize): array
{
$frequentSearches = [];
if (count($frequentSearchTerms)) {
$maximumHits = max(array_values($frequentSearchTerms));
$minimumHits = min(array_values($frequentSearchTerms));
$spread = $maximumHits - $minimumHits;
$step = ($spread == 0) ? 1 : ($maximumSize - $minimumSize) / $spread;
foreach ($frequentSearchTerms as $term => $hits) {
$size = round($minimumSize + (($hits - $minimumHits) * $step));
$frequentSearches[] = [
'q' => htmlspecialchars_decode($term),
'hits' => $hits,
'style' => 'font-size: ' . $size . 'px', 'class' => 'tx-solr-frequent-term-' . $size,
'size' => $size
];
}
}
return $frequentSearches;
}
}

View File

@@ -0,0 +1,95 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Widget\Controller;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Grouping\GroupItem;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
/**
* Class GroupItemPaginateController
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class GroupItemPaginateController extends AbstractPaginateWidgetController
{
/**
* @var SearchResultSet
*/
protected $resultSet;
/**
* @var GroupItem
*/
protected $groupItem;
/**
* @return void
*/
public function initializeAction()
{
parent::initializeAction();
$this->resultSet = $this->widgetConfiguration['resultSet'];
$this->groupItem = $this->widgetConfiguration['groupItem'];
$this->configuration['itemsPerPage'] = $this->getItemsPerPage();
$this->numberOfPages = (int)ceil($this->groupItem->getAllResultCount() / $this->configuration['itemsPerPage']);
}
/**
* Determines the number of results per page. When nothing is configured 10 will be returned.
*
* @return int
*/
protected function getItemsPerPage()
{
$perPage = (int)$this->groupItem->getGroup()->getResultsPerPage();
return $perPage > 0 ? $perPage : 10;
}
/**
* @param \WapplerSystems\Meilisearch\Mvc\Controller\SolrControllerContext $controllerContext
* @return \WapplerSystems\Meilisearch\Mvc\Controller\SolrControllerContext
*/
protected function setActiveSearchResultSet($controllerContext) {
$controllerContext->setSearchResultSet($this->resultSet);
return $controllerContext;
}
/**
* @return void
*/
public function indexAction()
{
// set current page
$groupName = $this->groupItem->getGroup()->getGroupName();
$groupItemValue = $this->groupItem->getGroupValue();
$this->currentPage = $this->resultSet->getUsedSearchRequest()->getGroupItemPage($groupName, $groupItemValue);
if ($this->currentPage < 1) {
$this->currentPage = 1;
}
$this->view->assign('contentArguments', [$this->widgetConfiguration['as'] => $this->groupItem->getSearchResults(), 'pagination' => $this->buildPagination()]);
$this->view->assign('configuration', $this->configuration);
$this->view->assign('resultSet', $this->resultSet);
$this->view->assign('groupItem', $this->groupItem);
if (!empty($this->templatePath)) {
$this->view->setTemplatePathAndFilename($this->templatePath);
}
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Widget\Controller;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\LastSearches\LastSearchesService;
use WapplerSystems\Meilisearch\Widget\AbstractWidgetController;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class LastSearchesController
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class LastSearchesController extends AbstractWidgetController
{
/**
* Last searches
*/
public function indexAction()
{
$typoScriptConfiguration = $this->controllerContext->getTypoScriptConfiguration();
$lastSearchesService = GeneralUtility::makeInstance(
LastSearchesService::class,
/** @scrutinizer ignore-type */ $typoScriptConfiguration
);
$this->view->assign('contentArguments', ['lastSearches' => $lastSearchesService->getLastSearches()]);
}
}

View File

@@ -0,0 +1,84 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Widget\Controller;
/*
* 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!
*/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
/**
* Class ResultPaginateController
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class ResultPaginateController extends AbstractPaginateWidgetController
{
/**
* @var SearchResultSet
*/
protected $resultSet;
/**
* @return void
*/
public function initializeAction()
{
parent::initializeAction();
$this->resultSet = $this->widgetConfiguration['resultSet'];
$this->configuration['itemsPerPage'] = $this->getItemsPerPage();
$this->numberOfPages = (int)ceil($this->resultSet->getAllResultCount() / $this->configuration['itemsPerPage']);
}
/**
* Determines the number of results per page. When nothing is configured 10 will be returned.
*
* @return int
*/
protected function getItemsPerPage()
{
$perPage = (int)$this->resultSet->getUsedSearch()->getQuery()->getRows();
return $perPage > 0 ? $perPage : 10;
}
/**
* @param \WapplerSystems\Meilisearch\Mvc\Controller\SolrControllerContext $controllerContext
* @return \WapplerSystems\Meilisearch\Mvc\Controller\SolrControllerContext
*/
protected function setActiveSearchResultSet($controllerContext) {
$controllerContext->setSearchResultSet($this->resultSet);
return $controllerContext;
}
/**
* @return void
*/
public function indexAction()
{
// set current page
$this->currentPage = $this->resultSet->getUsedPage();
if ($this->currentPage < 1) {
$this->currentPage = 1;
}
$this->view->assign('contentArguments', [$this->widgetConfiguration['as'] => $this->resultSet->getSearchResults(), 'pagination' => $this->buildPagination()]);
$this->view->assign('configuration', $this->configuration);
$this->view->assign('resultSet', $this->resultSet);
if (!empty($this->templatePath)) {
$this->view->setTemplatePathAndFilename($this->templatePath);
}
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Widget;
/*
* 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!
*/
use WapplerSystems\Meilisearch\ViewHelpers\Widget\Controller\FrequentlySearchedController;
use WapplerSystems\Meilisearch\Widget\AbstractWidgetViewHelper;
/**
* Class FrequentlySearchedViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class FrequentlySearchedViewHelper extends AbstractWidgetViewHelper
{
/**
* @var FrequentlySearchedController
*/
protected $controller;
/**
* @param FrequentlySearchedController $controller
*/
public function injectFrequentlySearchedController(FrequentlySearchedController $controller)
{
$this->controller = $controller;
}
/**
* @return \TYPO3\CMS\Extbase\Mvc\ResponseInterface
* @throws \TYPO3\CMS\Fluid\Core\Widget\Exception\MissingControllerException
*/
public function render()
{
return $this->initiateSubRequest();
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Widget;
/***************************************************************
* Copyright notice
*
* (c) 2016 Frans Saris <frans@beech.it> & Timo Hund <timo.hund@dkd.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\Grouping\GroupItem;
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use WapplerSystems\Meilisearch\ViewHelpers\Widget\Controller\GroupItemPaginateController;
use WapplerSystems\Meilisearch\Widget\AbstractWidgetViewHelper;
/**
* Class GroupItemPaginateViewHelper
*/
class GroupItemPaginateViewHelper extends AbstractWidgetViewHelper
{
/**
* @var GroupItemPaginateController
*/
protected $controller;
/**
* @param GroupItemPaginateController $groupItemPaginateController
*/
public function injectGroupItemPaginateController(GroupItemPaginateController $groupItemPaginateController)
{
$this->controller = $groupItemPaginateController;
}
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('resultSet', SearchResultSet::class, 'resultSet', true);
$this->registerArgument('groupItem', GroupItem::class, 'groupItem', true);
$this->registerArgument('as', 'string', 'as', false, 'documents');
$this->registerArgument('configuration', 'array', 'configuration', false, ['insertAbove' => true, 'insertBelow' => true, 'maximumNumberOfLinks' => 10, 'templatePath' => '']);
}
/**
* @return \TYPO3\CMS\Extbase\Mvc\ResponseInterface
* @throws \TYPO3\CMS\Fluid\Core\Widget\Exception\MissingControllerException
*/
public function render()
{
return $this->initiateSubRequest();
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Widget;
/*
* 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!
*/
use WapplerSystems\Meilisearch\ViewHelpers\Widget\Controller\LastSearchesController;
use WapplerSystems\Meilisearch\Widget\AbstractWidgetViewHelper;
/**
* Class LastSearchesViewHelper
*
* @author Frans Saris <frans@beech.it>
* @author Timo Hund <timo.hund@dkd.de>
*/
class LastSearchesViewHelper extends AbstractWidgetViewHelper
{
/**
* @var LastSearchesController
*/
protected $controller;
/**
* @param LastSearchesController $lastSearchesController
*/
public function injectLastSearchesController(LastSearchesController $lastSearchesController)
{
$this->controller = $lastSearchesController;
}
/**
* @return \TYPO3\CMS\Extbase\Mvc\ResponseInterface
* @throws \TYPO3\CMS\Fluid\Core\Widget\Exception\MissingControllerException
*/
public function render()
{
return $this->initiateSubRequest();
}
}

View File

@@ -0,0 +1,69 @@
<?php
namespace WapplerSystems\Meilisearch\ViewHelpers\Widget;
/***************************************************************
* Copyright notice
*
* (c) 2016 Frans Saris <frans@beech.it> & Timo Hund <timo.hund@dkd.de>
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
use WapplerSystems\Meilisearch\Domain\Search\ResultSet\SearchResultSet;
use WapplerSystems\Meilisearch\ViewHelpers\Widget\Controller\ResultPaginateController;
use WapplerSystems\Meilisearch\Widget\AbstractWidgetViewHelper;
/**
* Class ResultPaginateViewHelper
*/
class ResultPaginateViewHelper extends AbstractWidgetViewHelper
{
/**
* @var ResultPaginateController
*/
protected $controller;
/**
* @param ResultPaginateController $resultPaginateController
*/
public function injectResultPaginateController(ResultPaginateController $resultPaginateController)
{
$this->controller = $resultPaginateController;
}
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('resultSet', SearchResultSet::class, 'resultSet', true);
$this->registerArgument('as', 'string', 'as', false, 'documents');
$this->registerArgument('configuration', 'array', 'configuration', false, ['insertAbove' => true, 'insertBelow' => true, 'maximumNumberOfLinks' => 10, 'templatePath' => '']);
}
/**
* @return \TYPO3\CMS\Extbase\Mvc\ResponseInterface
* @throws \TYPO3\CMS\Fluid\Core\Widget\Exception\MissingControllerException
*/
public function render()
{
return $this->initiateSubRequest();
}
}