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,72 @@
<?php
namespace TYPO3\CMS\Extensionmanager\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\Extensionmanager\Controller\AbstractController;
/**
* Special ViewHelper for the BE module of the Extension Manager. Loads JS code for triggering
* refresh events.
*
* = Examples =
*
* <code title="Simple">
* <em:be.container triggers="{triggers}" />
* </code>
* <output>
* Writes some JS inline code
* </output>
*
* @internal
*/
class TriggerViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Be\AbstractBackendViewHelper
{
/**
* Initializes the arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('triggers', 'array', 'Defined triggers to be forwarded to client (e.g. refreshing backend widgets)', false, []);
}
/**
* Loads some JS inline code based on a list of triggers. This is used to reload the main
* menu when modules are loaded/unloaded.
*
* @return string This ViewHelper does not return any content
* @see \TYPO3\CMS\Backend\Template\DocumentTemplate
* @see \TYPO3\CMS\Core\Page\PageRenderer
*/
public function render()
{
$pageRenderer = $this->getPageRenderer();
// Handle triggers
if (!empty($this->arguments['triggers'][AbstractController::TRIGGER_RefreshModuleMenu])) {
$pageRenderer->addJsInlineCode(
AbstractController::TRIGGER_RefreshModuleMenu,
'if (top && top.TYPO3.ModuleMenu.App) { top.TYPO3.ModuleMenu.App.refreshMenu(); }'
);
}
if (!empty($this->arguments['triggers'][AbstractController::TRIGGER_RefreshTopbar])) {
$pageRenderer->addJsInlineCode(
AbstractController::TRIGGER_RefreshTopbar,
'if (top && top.TYPO3.Backend && top.TYPO3.Backend.Topbar) { top.TYPO3.Backend.Topbar.refresh(); }'
);
}
return '';
}
}
@@ -0,0 +1,114 @@
<?php
namespace TYPO3\CMS\Extensionmanager\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\Core\Utility\PathUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
/**
* Renders the distribution image
*
* @internal
*/
class DistributionImageViewHelper extends AbstractTagBasedViewHelper
{
/**
* @var string
*/
protected $tagName = 'img';
/**
* Initialize arguments.
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('extensionkey', 'string', '', true);
$this->registerArgument('width', 'int', 'width of the image');
$this->registerArgument('height', 'int', 'height of the image');
$this->registerUniversalTagAttributes();
$this->registerTagAttribute('alt', 'string', 'Specifies an alternate text for an image', false);
}
/**
* Renders the destribution preview image for the given extension
*
* @return string rendered tag.
*/
public function render()
{
$extensionKey = $this->arguments['extensionkey'];
$width = $this->arguments['width'];
$height = $this->arguments['height'];
$content = '';
$src = $this->findImage($extensionKey);
$uri = $this->getImageUri($src);
if (!empty($uri)) {
if ($width) {
$this->tag->addAttribute('width', (int)$width);
}
if ($height) {
$this->tag->addAttribute('height', (int)$height);
}
$this->tag->addAttribute('src', $uri);
$content = $this->tag->render();
}
return $content;
}
/**
* Find the distrubution image
*
* @param string $extensionKey
* @return string
*/
protected function findImage($extensionKey)
{
$paths = [];
$paths[] = 'EXT:' . $extensionKey . '/Resources/Public/Images/Distribution.svg';
$paths[] = 'EXT:' . $extensionKey . '/Resources/Public/Images/Distribution.png';
$paths[] = 'EXT:extensionmanager/Resources/Public/Images/Distribution.svg';
foreach ($paths as $path) {
$absFileName = GeneralUtility::getFileAbsFileName($path);
if (file_exists($absFileName)) {
return $absFileName;
}
}
return '';
}
/**
* Get image uri
*
* @param string $src
* @return string
*/
protected function getImageUri($src)
{
$uri = GeneralUtility::getFileAbsFileName($src);
if ($uri !== '' && !file_exists($uri)) {
$uri = '';
}
if ($uri !== '') {
$uri = '../' . PathUtility::stripPathSitePrefix($uri);
}
return $uri;
}
}
@@ -0,0 +1,146 @@
<?php
namespace TYPO3\CMS\Extensionmanager\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\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
/**
* ViewHelper
* @internal
*/
class DownloadExtensionViewHelper extends \TYPO3\CMS\Fluid\ViewHelpers\Form\AbstractFormViewHelper
{
/**
* @var string
*/
protected $tagName = 'form';
/**
* @var \TYPO3\CMS\Extbase\Service\ExtensionService
*/
protected $extensionService;
/**
* @param \TYPO3\CMS\Extbase\Service\ExtensionService $extensionService
*/
public function injectExtensionService(\TYPO3\CMS\Extbase\Service\ExtensionService $extensionService)
{
$this->extensionService = $extensionService;
}
/**
* Initialize arguments.
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('extension', Extension::class, '', true);
$this->registerTagAttribute('enctype', 'string', 'MIME type with which the form is submitted');
$this->registerTagAttribute('method', 'string', 'Transfer type (GET or POST)');
$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();
}
/**
* Renders a download link
*
* @return string the rendered a tag
*/
public function render()
{
/** @var Extension $extension */
$extension = $this->arguments['extension'];
$installPaths = Extension::returnAllowedInstallPaths();
if (empty($installPaths)) {
return '';
}
$pathSelector = '<ul class="is-hidden">';
foreach ($installPaths as $installPathType => $installPath) {
$pathSelector .= '<li>
<input type="radio" id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '" name="' . htmlspecialchars($this->getFieldNamePrefix()) . '[downloadPath]" class="downloadPath" value="' . htmlspecialchars($installPathType) . '" ' . ($installPathType === 'Local' ? 'checked="checked"' : '') . ' />
<label for="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadPath-' . htmlspecialchars($installPathType) . '">' . htmlspecialchars($installPathType) . '</label>
</li>';
}
$pathSelector .= '</ul>';
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$action = 'checkDependencies';
$uriBuilder->reset();
$uriBuilder->setFormat('json');
$uri = $uriBuilder->uriFor($action, [
'extension' => (int)$extension->getUid()
], 'Download');
$this->tag->addAttribute('data-href', $uri);
$automaticInstallation = (bool)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('extensionmanager', 'automaticInstallation');
$labelKeySuffix = $automaticInstallation ? '' : '.downloadOnly';
$label = '
<div class="btn-group">
<button
title="' . LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '"
type="submit"
class="btn btn-default"
value="' . LocalizationUtility::translate('extensionList.downloadViewHelper.submit' . $labelKeySuffix, 'extensionmanager') . '"
>
<span class="t3-icon fa fa-cloud-download"></span>
</button>
</div>';
$this->tag->setContent($label . $pathSelector);
$this->tag->addAttribute('class', 'download');
return '<div id="' . htmlspecialchars($extension->getExtensionKey()) . '-downloadFromTer" class="downloadFromTer">' . $this->tag->render() . '</div>';
}
/**
* Get the field name prefix
*
* @return string
*/
protected function getFieldNamePrefix()
{
if ($this->hasArgument('fieldNamePrefix')) {
return $this->arguments['fieldNamePrefix'];
}
return $this->getDefaultFieldNamePrefix();
}
/**
* Retrieves the default field name prefix for this form
*
* @return string default field name prefix
*/
protected function getDefaultFieldNamePrefix()
{
$request = $this->renderingContext->getControllerContext()->getRequest();
if ($this->hasArgument('extensionName')) {
$extensionName = $this->arguments['extensionName'];
} else {
$extensionName = $request->getControllerExtensionName();
}
if ($this->hasArgument('pluginName')) {
$pluginName = $this->arguments['pluginName'];
} else {
$pluginName = $request->getPluginName();
}
if ($extensionName !== null && $pluginName != null) {
return $this->extensionService->getPluginNamespace($extensionName, $pluginName);
}
return '';
}
}
@@ -0,0 +1,63 @@
<?php
namespace TYPO3\CMS\Extensionmanager\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\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Returns a string meant to be used as css class stating whether an extension is
* available or installed
* @internal
*/
class InstallationStateCssClassViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* Initialize arguments
*/
public function initializeArguments()
{
$this->registerArgument('needle', 'string', '', true);
$this->registerArgument('haystack', 'array', '', true);
}
/**
* Returns string meant to be used as css class
* 'installed' => if an extension is installed
* 'available' => if an extension is available in the system
* '' (empty string) => if neither installed nor available
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string the rendered a tag
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$needle = $arguments['needle'];
$haystack = $arguments['haystack'];
if (array_key_exists($needle, $haystack)) {
if (isset($haystack[$needle]['installed']) && $haystack[$needle]['installed'] === true) {
return 'installed';
}
return 'available';
}
return '';
}
}
@@ -0,0 +1,85 @@
<?php
namespace TYPO3\CMS\Extensionmanager\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\ViewHelper\AbstractTagBasedViewHelper;
/**
* ViewHelper to let 3rd-party extensions process the list of available
* actions for a given extension.
* @internal
*/
class ProcessAvailableActionsViewHelper extends AbstractTagBasedViewHelper
{
const SIGNAL_ProcessActions = 'processActions';
/**
* @var \TYPO3\CMS\Extbase\SignalSlot\Dispatcher
*/
protected $signalSlotDispatcher;
/**
* @param \TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher
*/
public function injectSignalSlotDispatcher(\TYPO3\CMS\Extbase\SignalSlot\Dispatcher $signalSlotDispatcher)
{
$this->signalSlotDispatcher = $signalSlotDispatcher;
}
/**
* Initialize arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('extension', 'string', '', true);
}
/**
* Processes the list of actions.
*
* @return string the rendered list of actions
*/
public function render()
{
$extension = $this->arguments['extension'];
$html = $this->renderChildren();
$actions = preg_split('#\\n\\s*#s', trim($html));
$actions = $this->emitProcessActionsSignal($extension, $actions);
return implode(' ', $actions);
}
/**
* Emits a signal after the list of actions is processed
*
* @param string $extension
* @param array $actions
* @return array Modified action array
*/
protected function emitProcessActionsSignal($extension, array $actions)
{
$this->signalSlotDispatcher->dispatch(
__CLASS__,
static::SIGNAL_ProcessActions,
[
$extension,
&$actions,
]
);
return $actions;
}
}
@@ -0,0 +1,85 @@
<?php
namespace TYPO3\CMS\Extensionmanager\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\Core\Environment;
use TYPO3\CMS\Core\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Registry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper;
/**
* ViewHelper for update script link
* @internal
*/
class ReloadSqlDataViewHelper extends ActionViewHelper
{
/**
* @var string
*/
protected static $registryNamespace = 'extensionDataImport';
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('extension', 'array', 'Extension key', true);
}
/**
* Renders a link to re-import the static SQL data of an extension
*
* @return string The rendered a tag
*/
public function render()
{
$extension = $this->arguments['extension'];
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$staticSqlDataFile = $extension['siteRelPath'] . 'ext_tables_static+adt.sql';
if (!file_exists(Environment::getPublicPath() . '/' . $staticSqlDataFile)) {
return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
}
$registry = GeneralUtility::makeInstance(Registry::class);
$oldMd5Hash = $registry->get(static::$registryNamespace, $staticSqlDataFile);
$md5HashIsEqual = true;
// We used to only store "1" in the database when data was imported
// No need to compare file content here and just show the reload icon
if (!empty($oldMd5Hash) && $oldMd5Hash !== 1) {
$currentMd5Hash = md5_file(Environment::getPublicPath() . '/' . $staticSqlDataFile);
$md5HashIsEqual = $oldMd5Hash === $currentMd5Hash;
}
if ($md5HashIsEqual) {
$iconIdentifier = 'actions-database-reload';
$languageKey = 'extensionList.databaseReload';
} else {
$iconIdentifier = 'actions-database-import';
$languageKey = 'extensionList.databaseImport';
}
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$uriBuilder->reset();
$uri = $uriBuilder->uriFor('reloadExtensionData', ['extension' => $extension['key']], 'Action');
$this->tag->addAttribute('href', $uri);
$this->tag->addAttribute('title', LocalizationUtility::translate($languageKey, 'extensionmanager'));
$this->tag->setContent($iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)->render());
return $this->tag->render();
}
}
@@ -0,0 +1,71 @@
<?php
namespace TYPO3\CMS\Extensionmanager\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\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper;
/**
* ViewHelper for displaying a remove extension link
* @internal
*/
class RemoveExtensionViewHelper extends ActionViewHelper
{
/**
* Initialize arguments
*
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('extension', 'array', '', true);
}
/**
* Renders an install link
*
* @return string the rendered a tag
*/
public function render()
{
$extension = $this->arguments['extension'];
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extension['key'])) {
return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
}
if (
!in_array($extension['type'], \TYPO3\CMS\Extensionmanager\Domain\Model\Extension::returnAllowedInstallTypes()) ||
$extension['type'] === 'System'
) {
return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
}
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$action = 'removeExtension';
$uriBuilder->reset();
$uriBuilder->setFormat('json');
$uri = $uriBuilder->uriFor($action, [
'extension' => $extension['key']
], 'Action');
$this->tag->addAttribute('href', $uri);
$cssClass = 'removeExtension btn btn-default';
$this->tag->addAttribute('class', $cssClass);
$this->tag->addAttribute('title', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('extensionList.remove', 'extensionmanager'));
$this->tag->setContent($iconFactory->getIcon('actions-edit-delete', Icon::SIZE_SMALL)->render());
return $this->tag->render();
}
}
@@ -0,0 +1,65 @@
<?php
namespace TYPO3\CMS\Extensionmanager\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\Extensionmanager\Domain\Model\Extension;
use TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper;
/**
* Display a link to show all versions of an extension
* @internal
*/
class ShowExtensionVersionsViewHelper extends ActionViewHelper
{
/**
* @var string
*/
protected $tagName = 'a';
/**
* Initialize arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('extension', Extension::class, '', true);
}
/**
* Renders an install link
*
* @return string the rendered a tag
*/
public function render()
{
/** @var Extension $extension */
$extension = $this->arguments['extension'];
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$action = 'showAllVersions';
$uri = $uriBuilder->reset()->uriFor($action, [
'extensionKey' => $extension->getExtensionKey(),
], 'List');
$this->tag->addAttribute('href', $uri);
// Set class
$this->tag->addAttribute('class', 'versions-all ui-icon ui-icon-triangle-1-s');
$label = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('extensionList.showAllVersions.label', 'extensionmanager');
$this->tag->addAttribute('title', $label);
$this->tag->setContent($label);
return $this->tag->render();
}
}
@@ -0,0 +1,87 @@
<?php
namespace TYPO3\CMS\Extensionmanager\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\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper;
/**
* Display a deactivate / activate link
* @internal
*/
class ToggleExtensionInstallationStateViewHelper extends ActionViewHelper
{
/**
* @var string
*/
protected $tagName = 'a';
/** @var \TYPO3\CMS\Extbase\Object\ObjectManager */
protected $objectManager;
/**
* @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
*/
public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
{
$this->objectManager = $objectManager;
}
/**
* Initialize arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('extension', 'array', '', true);
}
/**
* Renders an install link
*
* @return string the rendered a tag
*/
public function render()
{
$extension = $this->arguments['extension'];
// Early return if package is protected or is a runtime activated package and can not be unloaded
/** @var \TYPO3\CMS\Core\Package\PackageManager $packageManager */
$packageManager = $this->objectManager->get(PackageManager::class);
$package = $packageManager->getPackage($extension['key']);
if ($package->isProtected() || in_array($extension['key'], $GLOBALS['TYPO3_CONF_VARS']['EXT']['runtimeActivatedPackages'])) {
return '';
}
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$action = 'toggleExtensionInstallationState';
$uri = $uriBuilder->reset()->uriFor($action, [
'extensionKey' => $extension['key']
], 'Action');
$this->tag->addAttribute('href', $uri);
$label = $extension['installed'] ? 'deactivate' : 'activate';
$this->tag->addAttribute('title', LocalizationUtility::translate('extensionList.' . $label, 'extensionmanager'));
$icon = $extension['installed'] ? 'uninstall' : 'install';
$this->tag->addAttribute('class', 'onClickMaskExtensionManager btn btn-default');
/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$this->tag->setContent($iconFactory->getIcon('actions-system-extension-' . $icon, Icon::SIZE_SMALL)->render());
return $this->tag->render();
}
}
@@ -0,0 +1,92 @@
<?php
namespace TYPO3\CMS\Extensionmanager\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\MathUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extensionmanager\Domain\Model\Dependency;
use TYPO3\CMS\Extensionmanager\Domain\Model\Extension;
use TYPO3Fluid\Fluid\Core\Rendering\RenderingContextInterface;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\Traits\CompileWithRenderStatic;
/**
* Shows the version numbers of the TYPO3 dependency, if any
*
* @internal
*/
class Typo3DependencyViewHelper extends AbstractViewHelper
{
use CompileWithRenderStatic;
/**
* As this ViewHelper renders HTML, the output must not be escaped.
*
* @var bool
*/
protected $escapeOutput = false;
/**
* Initialize arguments
*
* @throws \TYPO3Fluid\Fluid\Core\ViewHelper\Exception
*/
public function initializeArguments()
{
$this->registerArgument('extension', Extension::class, '', true);
}
/**
* Finds and returns the suitable TYPO3 versions of an extension
*
* @param array $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
*
* @return string
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext)
{
$extension = $arguments['extension'];
/** @var Dependency $dependency */
foreach ($extension->getDependencies() as $dependency) {
if ($dependency->getIdentifier() === 'typo3') {
$lowestVersion = $dependency->getLowestVersion();
$highestVersion = $dependency->getHighestVersion();
$cssClass = self::isVersionSuitable($lowestVersion, $highestVersion) ? 'success' : 'default';
return
'<span class="label label-' . $cssClass . '">'
. htmlspecialchars($lowestVersion) . ' - ' . htmlspecialchars($highestVersion)
. '</span>';
}
}
return '';
}
/**
* Check if current TYPO3 version is suitable for the extension
*
* @param string $lowestVersion
* @param string $highestVersion
* @return bool
*/
protected static function isVersionSuitable($lowestVersion, $highestVersion)
{
$numericTypo3Version = VersionNumberUtility::convertVersionNumberToInteger(VersionNumberUtility::getNumericTypo3Version());
$numericLowestVersion = VersionNumberUtility::convertVersionNumberToInteger($lowestVersion);
$numericHighestVersion = VersionNumberUtility::convertVersionNumberToInteger($highestVersion);
return MathUtility::isIntegerInRange($numericTypo3Version, $numericLowestVersion, $numericHighestVersion);
}
}
@@ -0,0 +1,80 @@
<?php
namespace TYPO3\CMS\Extensionmanager\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\Imaging\Icon;
use TYPO3\CMS\Core\Imaging\IconFactory;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Fluid\ViewHelpers\Link\ActionViewHelper;
/**
* ViewHelper for update script link
* @internal
*/
class UpdateScriptViewHelper extends ActionViewHelper
{
/** @var \TYPO3\CMS\Extbase\Object\ObjectManager */
protected $objectManager;
/**
* @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
*/
public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
{
$this->objectManager = $objectManager;
}
/**
* initialize arguments
*/
public function initializeArguments()
{
parent::initializeArguments();
$this->registerArgument('extensionKey', 'string', 'Extension key', true);
}
/**
* Renders a link to the update script screen if the extension has one
*
* @return string The rendered a tag
*/
public function render()
{
$extensionKey = $this->arguments['extensionKey'];
// If the "class.ext_update.php" file exists, build link to the update script screen
/** @var \TYPO3\CMS\Extensionmanager\Utility\UpdateScriptUtility $updateScriptUtility */
$updateScriptUtility = $this->objectManager->get(\TYPO3\CMS\Extensionmanager\Utility\UpdateScriptUtility::class);
/** @var IconFactory $iconFactory */
$iconFactory = GeneralUtility::makeInstance(IconFactory::class);
if ($updateScriptUtility->checkUpdateScriptExists($extensionKey)) {
$uriBuilder = $this->renderingContext->getControllerContext()->getUriBuilder();
$action = 'show';
$uri = $uriBuilder->reset()->uriFor(
$action,
['extensionKey' => $extensionKey],
'UpdateScript'
);
$this->tag->addAttribute('href', $uri);
$this->tag->addAttribute('title', \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('extensionList.update.script', 'extensionmanager'));
$this->tag->setContent($iconFactory->getIcon('actions-refresh', Icon::SIZE_SMALL)->render());
$tag = $this->tag->render();
} else {
return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
}
return $tag;
}
}