Initial commit - Typo3 11.5.41

This commit is contained in:
Matteo Gallo
2026-07-03 17:53:31 +02:00
commit 5ca4743197
6811 changed files with 568848 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
<?php
declare(strict_types=1);
namespace GeorgRinger\News\DataProcessing;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\Exception\AspectNotFoundException;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
/**
* Add the current news record to any menu, e.g. breadcrumb
*
* 20 = GeorgRinger\News\DataProcessing\AddNewsToMenuProcessor
* 20.menus = breadcrumbMenu,specialMenu
*/
class AddNewsToMenuProcessor implements DataProcessorInterface
{
/**
* @param ContentObjectRenderer $cObj
* @param array $contentObjectConfiguration
* @param array $processorConfiguration
* @param array $processedData
* @return array
*/
public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData): array
{
if (!$processorConfiguration['menus']) {
return $processedData;
}
$newsRecord = $this->getNewsRecord();
if ($newsRecord) {
$menus = GeneralUtility::trimExplode(',', $processorConfiguration['menus'], true);
foreach ($menus as $menu) {
if (isset($processedData[$menu])) {
$this->addNewsRecordToMenu($newsRecord, $processedData[$menu]);
}
}
}
return $processedData;
}
/**
* Add the news record to the menu items
*
* @param array $newsRecord
* @param array $menu
*
* @return void
*/
protected function addNewsRecordToMenu(array $newsRecord, array &$menu): void
{
foreach ($menu as &$menuItem) {
$menuItem['current'] = 0;
}
$menu[] = [
'data' => $newsRecord,
'title' => $newsRecord['title'],
'active' => 1,
'current' => 1,
'link' => GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'),
'isNews' => true
];
}
/**
* Get the news record including possible translations
*
* @return array
*/
protected function getNewsRecord(): array
{
$newsId = 0;
$vars = GeneralUtility::_GET('tx_news_pi1');
if (isset($vars['news'])) {
$newsId = (int)$vars['news'];
}
if ($newsId) {
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable('tx_news_domain_model_news');
$row = $queryBuilder
->select('*')
->from('tx_news_domain_model_news')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($newsId, \PDO::PARAM_INT))
)
->execute()
->fetch();
if ($row) {
$row = $this->getTsfe()->sys_page->getRecordOverlay('tx_news_domain_model_news', $row, $this->getCurrentLanguage());
}
if (is_array($row) && !empty($row)) {
return $row;
}
}
return [];
}
/**
* Get current language
*
* @return int
*/
protected function getCurrentLanguage(): int
{
$languageId = 0;
$context = GeneralUtility::makeInstance(Context::class);
try {
$languageId = $context->getPropertyFromAspect('language', 'contentId');
} catch (AspectNotFoundException $e) {
// do nothing
}
return (int)$languageId;
}
/**
* @return TypoScriptFrontendController
*/
protected function getTsfe(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
}

View File

@@ -0,0 +1,101 @@
<?php
declare(strict_types=1);
namespace GeorgRinger\News\DataProcessing;
use GeorgRinger\News\Seo\NewsAvailability;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\Routing\PageArguments;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\ContentObject\DataProcessorInterface;
/**
* This file is part of the "news" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/
/**
* Disable language item on a detail page if the news is not translated
*
* 20 = GeorgRinger\News\DataProcessing\DisableLanguageMenuProcessor
* 20.menus = languageMenu
*/
class DisableLanguageMenuProcessor implements DataProcessorInterface
{
/**
* @param ContentObjectRenderer $cObj
* @param array $contentObjectConfiguration
* @param array $processorConfiguration
* @param array $processedData
* @return array
*/
public function process(ContentObjectRenderer $cObj, array $contentObjectConfiguration, array $processorConfiguration, array $processedData): array
{
if (!$processorConfiguration['menus']) {
return $processedData;
}
$newsId = $this->getNewsId();
if ($newsId === 0) {
return $processedData;
}
$menus = GeneralUtility::trimExplode(',', $processorConfiguration['menus'], true);
foreach ($menus as $menu) {
if (isset($processedData[$menu])) {
$this->handleMenu($newsId, $processedData[$menu]);
}
}
return $processedData;
}
/**
* @param int $newsId
* @param array $menu
*/
protected function handleMenu(int $newsId, array &$menu): void
{
$newsAvailability = GeneralUtility::makeInstance(NewsAvailability::class);
foreach ($menu as &$item) {
if (!$item['available']) {
continue;
}
try {
$availability = $newsAvailability->check((int)$item['languageId'], $newsId);
if (!$availability) {
$item['available'] = false;
$item['availableReason'] = 'news';
}
} catch (\Exception $e) {
}
}
}
/**
* @return int
*/
protected function getNewsId(): int
{
$newsId = 0;
/** @var PageArguments $pageArguments */
$pageArguments = $this->getRequest()->getAttribute('routing');
if (isset($pageArguments->getRouteArguments()['tx_news_pi1']['news'])) {
$newsId = (int)$pageArguments->getRouteArguments()['tx_news_pi1']['news'];
} elseif (isset($this->getRequest()->getQueryParams()['tx_news_pi1']['news'])) {
$newsId = (int)$this->getRequest()->getQueryParams()['tx_news_pi1']['news'];
}
return $newsId;
}
/**
* @return ServerRequestInterface
*/
protected function getRequest(): ServerRequestInterface
{
return $GLOBALS['TYPO3_REQUEST'];
}
}