Newer
Older

Torsten Oppermann
committed
namespace SGalinski\SgNews\Controller;
/***************************************************************
* Copyright notice
*
* (c) sgalinski Internet Services (https://www.sgalinski.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 SGalinski\SgNews\Utility\BackendNewsUtility;
use TYPO3\CMS\Backend\Clipboard\Clipboard;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\Components\DocHeaderComponent;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Page\PageRenderer;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
/**
* News Controller
*/

Torsten Oppermann
committed
class BackendController extends ActionController {
* The info fields of the current page
*
* @var array
* The uid of the current root page
*
* @var int
* Command array on the form [tablename][uid][command] = value.
* This array may get additional data set internally based on clipboard commands send in CB var!
*
* @var array
* Clipboard command array. May trigger changes in "cmd"
*
* @var array
*/
private $clipboardCommandArray;
/**
* Currently selected language
*
* @var int
*/
public $language;
/**
* DocHeaderComponent
*
* @var DocHeaderComponent
*/
private $docHeaderComponent;
/**
* Initialize action for all actions
*
*/
public function initializeAction() {
$this->command = GeneralUtility::_GP('cmd');
$this->clipboardCommandArray = GeneralUtility::_GP('CB');
$this->initClipboard();
}
/**
* Initializes the view before invoking an action method.
*
* Override this method to solve assign variables common for all actions
* or prepare the view in another way before the action is called.
*
* @param ViewInterface $view The view to be initialized
*
* @return void
protected function initializeView(ViewInterface $view) {
$GLOBALS['LANG']->includeLLFile('EXT:core/Resources/Private/Language/locallang_mod_web_list.xlf');
// create doc header component
/** @var BackendUserAuthentication $backendUser */
$backendUser = $GLOBALS['BE_USER'];
$this->pageInfo = BackendUtility::readPageAccess($this->pageUid, $backendUser->getPagePermsClause(1));
if ($this->pageInfo) {
$this->docHeaderComponent = GeneralUtility::makeInstance(DocHeaderComponent::class);
if ($this->pageUid) {
$this->rootPageUid = BackendNewsUtility::getRootUidByPageUid($this->pageUid);
}
/** @var BackendUserAuthentication $backendUser */
$backendUser = $GLOBALS['BE_USER'];
$menuSettings = GeneralUtility::_GP('SET') ?: [];
foreach ($menuSettings as $key => $menuSetting) {
$backendUser->pushModuleData('tools_beuser/index.php/web_SgNewsNews_' . $key, $menuSetting);
}
if (!LicensingService::checkKey()) {
$this->view->assign('showLicenseBanner', TRUE);
} else {
$this->language = $backendUser->getModuleData(
'tools_beuser/index.php/web_SgNewsNews_language', 'ses'
) ?: 0;
$languageOptions = BackendNewsUtility::getAvailableLanguages($this->pageUid);
$currentLanguageInfo = $languageOptions[$this->language] ?? NULL;
$pageRenderer = GeneralUtility::makeInstance(PageRenderer::class);
$pageRenderer->addJsInlineCode('typo3_version', 'TYPO3.version='
. VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getCurrentTypo3Version())
. ';');
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$pageRenderer->loadExtJS();
}
$this->docHeaderComponent->setMetaInformation($this->pageInfo);
$this->makeButtons();
$this->makeLanguageMenu();
$this->view->assign('pageUid', $this->pageUid);
$this->view->assign('rootPageUid', $this->rootPageUid);
$this->view->assign('language', $this->language);
$this->view->assign('languageInfo', $currentLanguageInfo);
$this->view->assign('docHeader', $this->docHeaderComponent->docHeaderContent());
$this->view->assign('typo3Version', VersionNumberUtility::convertVersionNumberToInteger(TYPO3_version));
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
}
}
/**
* @param array $filters
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
*/
public function indexAction(array $filters = NULL) {
$showNewsList = FALSE;
if (
($this->pageUid && $this->pageUid === $this->rootPageUid) ||
(int) $this->pageInfo['doktype'] === BackendNewsUtility::CATEGORY_DOKTYPE
) {
/** @var BackendUserAuthentication $backendUser */
$backendUser = $GLOBALS['BE_USER'];
if ($filters === NULL) {
$filters = $backendUser->getModuleData('tools_beuser/index.php/web_SgNewsNews_filters', 'ses') ?: [];
} else {
$backendUser->pushModuleData('tools_beuser/index.php/web_SgNewsNews_filters', $filters);
}
if ((int) $this->pageInfo['doktype'] !== BackendNewsUtility::CATEGORY_DOKTYPE) {
$categories = BackendNewsUtility::getCategoriesForSiteRoot($this->rootPageUid);
$this->view->assign('categories', $categories);
$this->view->assign('showCategoryFilter', TRUE);
} else {
$filters['categories'] = [$this->pageUid];
}
$tags = BackendNewsUtility::getTagsForPage($this->pageUid, $this->language);
$news = BackendNewsUtility::getNewsByFilters($this->rootPageUid, $filters, $this->language);
$this->view->assign('tags', $tags);
$this->view->assign('news', $news);
$this->view->assign('filters', $filters);
$showNewsList = TRUE;
} else {
$alternativePageOptions = BackendNewsUtility::getAlternativePageOptions();
$this->view->assign('alternativePageOptions', $alternativePageOptions);
}
$this->view->assign('showNewsList', $showNewsList);
}
/**
* create buttons for the backend module header
*
* @return void
* @throws \InvalidArgumentException
* @throws \UnexpectedValueException
*/
private function makeButtons() {
/** @var ButtonBar $buttonBar */
$buttonBar = $this->docHeaderComponent->getButtonBar();
/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.0.0', '<')) {
$locallangPath = 'LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:';
} else {
$locallangPath = 'LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:';
}
// Refresh
$refreshButton = $buttonBar->makeLinkButton()
->setHref(GeneralUtility::getIndpEnv('REQUEST_URI'))
->setTitle(
LocalizationUtility::translate(
$locallangPath . 'labels.reload'
)
)
->setIcon($iconFactory->getIcon('actions-edit-undo', Icon::SIZE_SMALL));
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
$buttonBar->addButton($refreshButton, ButtonBar::BUTTON_POSITION_RIGHT);
// shortcut button
$shortcutButton = $buttonBar->makeShortcutButton()
->setModuleName($this->request->getPluginName())
->setGetVariables(
[
'id',
'M'
]
)
->setSetVariables([]);
$buttonBar->addButton($shortcutButton, ButtonBar::BUTTON_POSITION_RIGHT);
$this->docHeaderComponent->getButtonBar();
}
/**
* create buttons for the backend module header
*
* @return void
* @throws \InvalidArgumentException
*/
private function makeLanguageMenu() {
if (!LicensingService::checkKey()) {
return;
}
$languageMenu = $this->docHeaderComponent->getMenuRegistry()->makeMenu();
$languageMenu->setIdentifier('languageMenu');
$languages = BackendNewsUtility::getAvailableLanguages($this->pageUid);
foreach ($languages as $key => $language) {
$menuItem = $languageMenu
->makeMenuItem()
->setTitle($language['title'])
->setHref(
BackendUtility::getModuleUrl('web_SgNewsNews') . '&id=' . $this->pageUid . '&SET[language]=' . $key
);
if ((int) $this->language === (int) $key) {
$menuItem->setActive(TRUE);
}
$languageMenu->addMenuItem($menuItem);
}
$this->docHeaderComponent->getMenuRegistry()->addMenu($languageMenu);
}
/**
* Clipboard pasting and deleting.
*
* @throws \InvalidArgumentException
*/
public function initClipboard() {
if (\is_array($this->clipboardCommandArray)) {
$clipObj = GeneralUtility::makeInstance(Clipboard::class);
$clipObj->initializeClipboard();
if ($this->clipboardCommandArray['paste']) {
$clipObj->setCurrentPad($this->clipboardCommandArray['pad']);
$this->command = $clipObj->makePasteCmdArray(
$this->clipboardCommandArray['paste'],
$this->command,
$this->clipboardCommandArray['update'] ?? NULL
);
}
if ($this->clipboardCommandArray['delete']) {
$clipObj->setCurrentPad($this->clipboardCommandArray['pad']);
$this->command = $clipObj->makeDeleteCmdArray($this->command);
}
if ($this->clipboardCommandArray['el']) {
$this->clipboardCommandArray['setP'] = 'normal';
$clipObj->setCmd($this->clipboardCommandArray);
$clipObj->cleanCurrent();
$clipObj->endClipboard();
}
}