Skip to content
Snippets Groups Projects
Commit 6222eea7 authored by Kevin Ditscheid's avatar Kevin Ditscheid
Browse files

[BUGFIX] Remove the usage of GeneralUtility::_GETset

Alterring GET parameters should never be done. Instead using method
parameters to alter functionality.
This fixes side effects on the canonical URL generation, if the news
plugin is present with one of the list-Actions assigned.
parent 407d1746
No related branches found
Tags 5.1.0
No related merge requests found
...@@ -52,15 +52,28 @@ class ListByCategoryController extends AbstractController { ...@@ -52,15 +52,28 @@ class ListByCategoryController extends AbstractController {
*/ */
protected $newsRepository; protected $newsRepository;
/**
* Initialize the indexAction to set the currentPageBrowserPage parameter
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
*/
public function initializeIndexAction(){
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'];
if($currentPageBrowserPage > 0){
$this->request->setArgument('currentPageBrowserPage', $currentPageBrowserPage);
}
}
/** /**
* Renders the news list of a category * Renders the news list of a category
* *
* @param array $newsMetaData * @param array $newsMetaData
* @param int $currentPageBrowserPage
* @return void * @return void
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/ */
public function indexAction(array $newsMetaData = []) { public function indexAction(array $newsMetaData = [], $currentPageBrowserPage = 0) {
$filterByCategories = FALSE; $filterByCategories = FALSE;
$categoryUids = GeneralUtility::intExplode(',', $this->settings['categories']); $categoryUids = GeneralUtility::intExplode(',', $this->settings['categories']);
$tagUids = GeneralUtility::intExplode(',', $this->settings['tags'], TRUE); $tagUids = GeneralUtility::intExplode(',', $this->settings['tags'], TRUE);
...@@ -85,7 +98,6 @@ class ListByCategoryController extends AbstractController { ...@@ -85,7 +98,6 @@ class ListByCategoryController extends AbstractController {
$offset = 0; $offset = 0;
$newsPerPage = (int) $this->settings['newsLimitPerPage']; $newsPerPage = (int) $this->settings['newsLimitPerPage'];
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'];
if ($currentPageBrowserPage && $newsPerPage) { if ($currentPageBrowserPage && $newsPerPage) {
$offset = $currentPageBrowserPage * $newsPerPage; $offset = $currentPageBrowserPage * $newsPerPage;
} }
...@@ -116,8 +128,7 @@ class ListByCategoryController extends AbstractController { ...@@ -116,8 +128,7 @@ class ListByCategoryController extends AbstractController {
if (count($newsMetaData) < $newsPerPage) { if (count($newsMetaData) < $newsPerPage) {
$nextPage = $currentPageBrowserPage + 1; $nextPage = $currentPageBrowserPage + 1;
if ($nextPage <= $numberOfPages) { if ($nextPage <= $numberOfPages) {
GeneralUtility::_GETset(['tx_sgnews_pagebrowser' => ['currentPage' => $nextPage]]); $this->indexAction($newsMetaData, $nextPage);
$this->indexAction($newsMetaData);
return; return;
} }
} }
......
...@@ -56,22 +56,35 @@ class OverviewController extends AbstractController { ...@@ -56,22 +56,35 @@ class OverviewController extends AbstractController {
*/ */
protected $newsRepository; protected $newsRepository;
/**
* Initialize the overviewAction to set the currentPageBrowserPage parameter
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
*/
public function initializeOverviewAction(){
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'];
if($currentPageBrowserPage > 0){
$this->request->setArgument('currentPageBrowserPage', $currentPageBrowserPage);
}
}
/** /**
* Renders the news overview * Renders the news overview
* *
* @param array $newsFilter * @param array $newsFilter
* @param int $currentPageBrowserPage
* @return void * @return void
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException * @throws \TYPO3\CMS\Extbase\Mvc\Exception\StopActionException
*/ */
public function overviewAction(array $newsFilter = []) { public function overviewAction(array $newsFilter = [], $currentPageBrowserPage = 0) {
switch ((int) $this->settings['groupBy']) { switch ((int) $this->settings['groupBy']) {
case 1: case 1:
$this->overviewWithCategories([], [], $newsFilter); $this->overviewWithCategories([], [], $newsFilter, $currentPageBrowserPage);
break; break;
case 2: case 2:
$this->overviewWithTags([], [], $newsFilter); $this->overviewWithTags([], [], $newsFilter, $currentPageBrowserPage);
break; break;
default: default:
$this->forward('overviewWithoutCategories', NULL, NULL, $this->request->getArguments()); $this->forward('overviewWithoutCategories', NULL, NULL, $this->request->getArguments());
...@@ -121,19 +134,19 @@ class OverviewController extends AbstractController { ...@@ -121,19 +134,19 @@ class OverviewController extends AbstractController {
* @param array $allNews * @param array $allNews
* @param array $newsFilter * @param array $newsFilter
* @param boolean $isInitialCall * @param boolean $isInitialCall
* @param int $currentPageBrowserPage
* @return void * @return void
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/ */
protected function overviewWithCategories( protected function overviewWithCategories(
array $newsByCategory = [], array $allNews = [], array $newsFilter = [], $isInitialCall = TRUE array $newsByCategory = [], array $allNews = [], array $newsFilter = [], $isInitialCall = TRUE, $currentPageBrowserPage = 0
) { ) {
$newsLimitPerCategory = (int) $this->settings['newsLimit']; $newsLimitPerCategory = (int) $this->settings['newsLimit'];
$this->categoryRepository->setDefaultOrderings(['sorting' => Query::ORDER_ASCENDING]); $this->categoryRepository->setDefaultOrderings(['sorting' => Query::ORDER_ASCENDING]);
$offset = 0; $offset = 0;
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'];
if ($currentPageBrowserPage && $newsLimitPerCategory) { if ($currentPageBrowserPage && $newsLimitPerCategory) {
$offset = ($currentPageBrowserPage * $newsLimitPerCategory) - ($isInitialCall ? 0 : 1); $offset = ($currentPageBrowserPage * $newsLimitPerCategory) - ($isInitialCall ? 0 : 1);
} }
...@@ -233,8 +246,7 @@ class OverviewController extends AbstractController { ...@@ -233,8 +246,7 @@ class OverviewController extends AbstractController {
if ($maxNewsPerCategory < $newsLimitPerCategory && count($allNews) < $newsLimitPerCategory) { if ($maxNewsPerCategory < $newsLimitPerCategory && count($allNews) < $newsLimitPerCategory) {
$nextPage = $currentPageBrowserPage + 1; $nextPage = $currentPageBrowserPage + 1;
if ($nextPage <= $numberOfPages) { if ($nextPage <= $numberOfPages) {
GeneralUtility::_GETset(['tx_sgnews_pagebrowser' => ['currentPage' => $nextPage]]); $this->overviewWithCategories($newsByCategory, $allNews, $newsFilter, FALSE, $nextPage);
$this->overviewWithCategories($newsByCategory, $allNews, $newsFilter, FALSE);
return; return;
} }
} }
...@@ -267,18 +279,18 @@ class OverviewController extends AbstractController { ...@@ -267,18 +279,18 @@ class OverviewController extends AbstractController {
* @param array $allNews * @param array $allNews
* @param array $newsFilter * @param array $newsFilter
* @param boolean $isInitialCall * @param boolean $isInitialCall
* @param int $currentPageBrowserPage
* @return void * @return void
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/ */
protected function overviewWithTags( protected function overviewWithTags(
array $newsByTag = [], array $allNews = [], array $newsFilter = [], $isInitialCall = TRUE array $newsByTag = [], array $allNews = [], array $newsFilter = [], $isInitialCall = TRUE, $currentPageBrowserPage = 0
) { ) {
$newsLimitPerTag = (int) $this->settings['newsLimit']; $newsLimitPerTag = (int) $this->settings['newsLimit'];
$this->tagRepository->setDefaultOrderings(['sorting' => Query::ORDER_ASCENDING]); $this->tagRepository->setDefaultOrderings(['sorting' => Query::ORDER_ASCENDING]);
$offset = 0; $offset = 0;
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'];
if ($currentPageBrowserPage && $newsLimitPerTag) { if ($currentPageBrowserPage && $newsLimitPerTag) {
$offset = ($currentPageBrowserPage * $newsLimitPerTag) - ($isInitialCall ? 0 : 1); $offset = ($currentPageBrowserPage * $newsLimitPerTag) - ($isInitialCall ? 0 : 1);
} }
...@@ -387,8 +399,7 @@ class OverviewController extends AbstractController { ...@@ -387,8 +399,7 @@ class OverviewController extends AbstractController {
if ($maxNewsPerTag < $newsLimitPerTag && count($allNews) < $newsLimitPerTag) { if ($maxNewsPerTag < $newsLimitPerTag && count($allNews) < $newsLimitPerTag) {
$nextPage = $currentPageBrowserPage + 1; $nextPage = $currentPageBrowserPage + 1;
if ($nextPage <= $numberOfPages) { if ($nextPage <= $numberOfPages) {
GeneralUtility::_GETset(['tx_sgnews_pagebrowser' => ['currentPage' => $nextPage]]); $this->overviewWithTags($newsByTag, $allNews, $newsFilter, FALSE, $nextPage);
$this->overviewWithTags($newsByTag, $allNews, $newsFilter, FALSE);
return; return;
} }
} }
...@@ -412,19 +423,32 @@ class OverviewController extends AbstractController { ...@@ -412,19 +423,32 @@ class OverviewController extends AbstractController {
$this->view->assign('tagTabs', TRUE); $this->view->assign('tagTabs', TRUE);
} }
/**
* Initialize the overviewWithoutCategoriesAction to set the currentPageBrowserPage parameter
*
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentNameException
*/
public function initializeOverviewWithoutCategoriesAction(){
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'];
if($currentPageBrowserPage > 0){
$this->request->setArgument('currentPageBrowserPage', $currentPageBrowserPage);
}
}
/** /**
* Renders the news in a paginated list * Renders the news in a paginated list
* *
* @param array $newsMetaData * @param array $newsMetaData
* @param array $newsFilter * @param array $newsFilter
* @param boolean $isInitialCall * @param boolean $isInitialCall
* @param int $currentPageBrowserPage
* @return void * @return void
* @throws \InvalidArgumentException * @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException * @throws \TYPO3\CMS\Extbase\Mvc\Exception\NoSuchArgumentException
*/ */
protected function overviewWithoutCategoriesAction( protected function overviewWithoutCategoriesAction(
array $newsMetaData = [], array $newsFilter = NULL, $isInitialCall = TRUE array $newsMetaData = [], array $newsFilter = NULL, $isInitialCall = TRUE, $currentPageBrowserPage = 0
) { ) {
// remember selection of the filter values, if any // remember selection of the filter values, if any
$selectedTag = $this->tagRepository->findByUid((int) $newsFilter['tag']); $selectedTag = $this->tagRepository->findByUid((int) $newsFilter['tag']);
...@@ -434,7 +458,6 @@ class OverviewController extends AbstractController { ...@@ -434,7 +458,6 @@ class OverviewController extends AbstractController {
$offset = 0; $offset = 0;
$newsPerPage = (int) $this->settings['newsLimit']; $newsPerPage = (int) $this->settings['newsLimit'];
$currentPageBrowserPage = (int) GeneralUtility::_GP('tx_sgnews_pagebrowser')['currentPage'];
if ($currentPageBrowserPage && $newsPerPage) { if ($currentPageBrowserPage && $newsPerPage) {
// might be necessary for the recursive calling performance wise // might be necessary for the recursive calling performance wise
$offset = ($currentPageBrowserPage * $newsPerPage) - ($isInitialCall ? 0 : 1); $offset = ($currentPageBrowserPage * $newsPerPage) - ($isInitialCall ? 0 : 1);
...@@ -505,8 +528,7 @@ class OverviewController extends AbstractController { ...@@ -505,8 +528,7 @@ class OverviewController extends AbstractController {
if (count($newsMetaData) < $newsPerPage) { if (count($newsMetaData) < $newsPerPage) {
$nextPage = $currentPageBrowserPage + 1; $nextPage = $currentPageBrowserPage + 1;
if ($nextPage <= $numberOfPages) { if ($nextPage <= $numberOfPages) {
GeneralUtility::_GETset(['tx_sgnews_pagebrowser' => ['currentPage' => $nextPage]]); $this->overviewWithoutCategoriesAction($newsMetaData, $newsFilter, FALSE, $nextPage);
$this->overviewWithoutCategoriesAction($newsMetaData, $newsFilter, FALSE);
return; return;
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment