first commit

This commit is contained in:
salam committed 2026-10-19 08:18:39 +02:00
commit 1218dd1517
12716 files changed
+989233

No files matched your search

@@ -0,0 +1,62 @@
<?php
namespace TYPO3\CMS\Belog\ViewHelpers\Be;
/*
* 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\Backend\Utility\BackendUtility;
use TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
/**
* Get page path string from page id
* @internal
*/
class PagePathViewHelper extends AbstractBackendViewHelper
{
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('pid', 'int', 'Pid of the page', true);
$this->registerArgument('titleLimit', 'int', 'Limit of the page title', false, 20);
}
/**
* Resolve page id to page path string (with automatic cropping to maximum given length).
*
* @return string Page path string
*/
public function render()
{
return static::renderStatic(
$this->arguments,
$this->buildRenderChildrenClosure(),
$this->renderingContext
);
}
/**
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
return BackendUtility::getRecordPath($arguments['pid'], '', $arguments['titleLimit']);
}
}
@@ -0,0 +1,70 @@
<?php
namespace TYPO3\CMS\Belog\ViewHelpers\Form;
/*
* 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!
*/
/**
* Extends the usual select ViewHelper, but additionally translates
* the select option labels
*
* Example:
* <belog:form.translateLabelSelect property="number" options="{settings.selectableNumberOfLogEntries}" optionLabelPrefix="numbers"
*
* Will lookup number.200 (or whatever optionValue is given) in locallang database
* @internal
*/
class TranslateLabelSelectViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\SelectViewHelper
{
/**
* Initialize arguments.
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('optionLabelPrefix', 'string', 'Prefix for locallang lookup');
}
/**
* Render the option tags.
*
* Extend the default handling by iterating over calculated options array and
* try to translate the value
*
* @return array An associative array of options, key will be the value of the option tag
*/
protected function getOptions()
{
$options = parent::getOptions();
foreach ($options as $value => $label) {
$options[$value] = $this->translateLabel($label);
}
return $options;
}
/**
* Fetches the translation for a given label. If no translation is found, the label is returned unchanged.
*
* @param string $label The label to translate
* @return string
*/
protected function translateLabel($label)
{
if ($label === '') {
return '';
}
$labelKey = $this->hasArgument('optionLabelPrefix') ? $this->arguments['optionLabelPrefix'] . $label : $label;
$translatedLabel = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate($labelKey, $this->renderingContext->getControllerContext()->getRequest()->getControllerExtensionName());
return $translatedLabel ?: $label;
}
}
@@ -0,0 +1,86 @@
<?php
namespace TYPO3\CMS\Belog\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\Belog\Domain\Model\LogEntry;
use TYPO3\CMS\Core\Utility\PathUtility;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Create detail string from log entry
* @internal
*/
class FormatDetailsViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* Initializes the arguments
*/
public function initializeArguments()
{
$this->registerArgument('logEntry', LogEntry::class, '', true);
}
/**
* Create formatted detail string from log row.
*
* The method handles two properties of the model: details and logData
* Details is a string with possible %s placeholders, and logData an array
* with the substitutions.
* Furthermore, possible files in logData are stripped to their basename if
* the action logged was a file action
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string Formatted details
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
/** @var LogEntry $logEntry */
$logEntry = $arguments['logEntry'];
$detailString = $logEntry->getDetails();
$substitutes = $logEntry->getLogData();
// Strip paths from file names if the log was a file action
if ($logEntry->getType() === 2) {
$substitutes = self::stripPathFromFilenames($substitutes);
}
// Substitute
if (!empty($substitutes)) {
$detailString = vsprintf($detailString, $substitutes);
}
// Remove possible pending other %s
$detailString = str_replace('%s', '', $detailString);
return $detailString;
}
/**
* Strips path from array of file names
*
* @param array $files
* @return array
*/
protected static function stripPathFromFilenames(array $files = [])
{
foreach ($files as $key => $file) {
$files[$key] = PathUtility::basename($file);
}
return $files;
}
}
@@ -0,0 +1,71 @@
<?php
namespace TYPO3\CMS\Belog\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\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Domain\Repository\BackendUserRepository;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Get username from backend user id
* @internal
*/
class UsernameViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* First level cache of user names
*
* @var array
*/
protected static $usernameRuntimeCache = [];
/**
* Initializes the arguments
*/
public function initializeArguments()
{
$this->registerArgument('uid', 'int', 'Uid of the user', true);
}
/**
* Resolve user name from backend user id.
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string Username or an empty string if there is no user with that UID
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$uid = $arguments['uid'];
if (isset(static::$usernameRuntimeCache[$uid])) {
return static::$usernameRuntimeCache[$uid];
}
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$backendUserRepository = $objectManager->get(BackendUserRepository::class);
/** @var \TYPO3\CMS\Extbase\Domain\Model\BackendUser $user */
$user = $backendUserRepository->findByUid($uid);
// $user may be NULL if user was deleted from DB, set it to empty string to always return a string
static::$usernameRuntimeCache[$uid] = $user === null ? '' : $user->getUserName();
return static::$usernameRuntimeCache[$uid];
}
}
@@ -0,0 +1,89 @@
<?php
namespace TYPO3\CMS\Belog\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\Belog\Domain\Repository\WorkspaceRepository;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Fluid\Core\Rendering\RenderingContext;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Get workspace title from workspace id
* @internal
*/
class WorkspaceTitleViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* First level cache of workspace titles
*
* @var array
*/
protected static $workspaceTitleRuntimeCache = [];
/**
* Initializes the arguments
*/
public function initializeArguments()
{
$this->registerArgument('uid', 'int', 'UID of the workspace', true);
}
/**
* Resolve workspace title from UID.
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string workspace title or UID
* @throws \InvalidArgumentException
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
if (!$renderingContext instanceof RenderingContext) {
throw new \InvalidArgumentException('The given rendering context is not of type "TYPO3\CMS\Fluid\Core\Rendering\RenderingContext"', 1468363946);
}
$uid = $arguments['uid'];
if (isset(static::$workspaceTitleRuntimeCache[$uid])) {
return static::$workspaceTitleRuntimeCache[$uid];
}
if ($uid === 0) {
static::$workspaceTitleRuntimeCache[$uid] = LocalizationUtility::translate(
'live',
$renderingContext->getControllerContext()->getRequest()->getControllerExtensionName()
);
} elseif (!ExtensionManagementUtility::isLoaded('workspaces')) {
static::$workspaceTitleRuntimeCache[$uid] = '';
} else {
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$workspaceRepository = $objectManager->get(WorkspaceRepository::class);
/** @var \TYPO3\CMS\Belog\Domain\Model\Workspace $workspace */
$workspace = $workspaceRepository->findByUid($uid);
// $workspace may be null, force empty string in this case
static::$workspaceTitleRuntimeCache[$uid] = $workspace === null ? '' : $workspace->getTitle();
}
return static::$workspaceTitleRuntimeCache[$uid];
}
}