[TASK] Add stack to mark external links
This commit is contained in:
parent
57b04f3245
commit
ea847996cf
78
Classes/UserFunc/ParseExternalLinks.php
Normal file
78
Classes/UserFunc/ParseExternalLinks.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
namespace Cjel\TemplatesAide\UserFunc;
|
||||
|
||||
/**
|
||||
* This file is part of the "Site Templates" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* (c) 2021 Philipp Dieter <philipp@glanzstueck.agency>, Glanzstück GmbH
|
||||
*/
|
||||
|
||||
use DiDom\Document;
|
||||
use DiDom\Element;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
|
||||
class ParseExternalLinks
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function render($content, $conf = [])
|
||||
{
|
||||
$domDocument = new \DOMDocument();
|
||||
$testdocument = $domDocument->loadXML($content);
|
||||
if ($testdocument === false) {
|
||||
return $content;
|
||||
}
|
||||
$document = new Document($content);
|
||||
$a = $document->find('a')[0];
|
||||
$href = $a->getAttribute('href');
|
||||
if (substr($href, 0, 7) != "http://"
|
||||
&& substr($href, 0, 8) != "https://"
|
||||
) {
|
||||
return $content;
|
||||
}
|
||||
$parsedHref = parse_url($href);
|
||||
if ($_SERVER['SERVER_NAME'] == $parsedHref['host']) {
|
||||
return $content;
|
||||
}
|
||||
if ($a->getAttribute('target') == '_blank') {
|
||||
$a->setAttribute('rel', 'noopener');
|
||||
}
|
||||
$class = $a->getAttribute('class');
|
||||
if ($class) {
|
||||
$class .= ' link link-external';
|
||||
} else {
|
||||
$class = 'link link-external';
|
||||
}
|
||||
$a->setAttribute('class', $class);
|
||||
if ($conf['linkText']) {
|
||||
$screenreaderHint = new Element('span', $conf['linkText'] . ' ');
|
||||
$screenreaderHint->setAttribute('class', 'link-external-sr-only');
|
||||
$a->prependChild($screenreaderHint);
|
||||
}
|
||||
if ($conf['iconFile']) {
|
||||
$iconDataFile = GeneralUtility::getFileAbsFileName(
|
||||
$conf['iconFile']
|
||||
);
|
||||
$iconData = file_get_contents($iconDataFile);
|
||||
$icon = new Element('span');
|
||||
$icon->setInnerHtml($iconData);
|
||||
$icon->setAttribute('class', 'icon-link-external');
|
||||
if ($iconPosition == 'start') {
|
||||
$a->prepentChild($icon);
|
||||
} else {
|
||||
$a->appendChild($icon);
|
||||
}
|
||||
}
|
||||
$innerHtml = $a->innerHtml();
|
||||
$a->setInnerHtml(
|
||||
'<span class="link-external-inner">'
|
||||
. $innerHtml
|
||||
. '</span>'
|
||||
);
|
||||
return $document->find('body')[0]->innerHtml();
|
||||
}
|
||||
}
|
78
Classes/ViewHelpers/ImageAppendViewHelper.php
Normal file
78
Classes/ViewHelpers/ImageAppendViewHelper.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
namespace Cjel\TemplatesAide\ViewHelpers;
|
||||
|
||||
/***
|
||||
*
|
||||
* This file is part of the "Templates Aide" Extension for TYPO3 CMS.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* (c) 2021 Philipp Dieter <philippdieter@attic-media.net>
|
||||
*
|
||||
***/
|
||||
|
||||
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
|
||||
use TYPO3\CMS\Extbase\Service\ImageService;
|
||||
use TYPO3\CMS\Core\Imaging\ImageMagickFile;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
class ImageAppendViewHelper extends AbstractTagBasedViewHelper
|
||||
{
|
||||
|
||||
/**
|
||||
* ImageService
|
||||
*
|
||||
* @var ImageService
|
||||
*/
|
||||
protected $imageService;
|
||||
|
||||
/**
|
||||
* @param
|
||||
*/
|
||||
public function injectImageService(
|
||||
ImageService $imageService
|
||||
) {
|
||||
$this->imageService = $imageService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize arguments.
|
||||
*/
|
||||
public function initializeArguments()
|
||||
{
|
||||
parent::initializeArguments();
|
||||
$this->registerUniversalTagAttributes();
|
||||
$this->registerArgument('images', 'array', '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizes a given image (if required) and renders the respective img tag
|
||||
*
|
||||
* @see https://docs.typo3.org/typo3cms/TyposcriptReference/ContentObjects/Image/
|
||||
*
|
||||
* @throws Exception
|
||||
* @return string Rendered tag
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
foreach ($this->arguments['images'] as $image) {
|
||||
$imagePath = $image->getForLocalProcessing(false);
|
||||
//$image = $this->imageService->getImage('', $imageArgument, true);
|
||||
//$image = $this->imageService->getImageUri($image);
|
||||
|
||||
$imageMagickFile = ImageMagickFile::fromFilePath($imagePath, 0);
|
||||
|
||||
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump(
|
||||
$imageMagickFile, null, 3
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
12
Resources/Private/TypoScript/Setup/parseExternalLinks.ts
Normal file
12
Resources/Private/TypoScript/Setup/parseExternalLinks.ts
Normal file
@ -0,0 +1,12 @@
|
||||
page.10.stdWrap.parseFunc {
|
||||
htmlSanitize = 0
|
||||
externalBlocks = a
|
||||
externalBlocks {
|
||||
a.stdWrap.postUserFunc = Cjel\TemplatesAide\UserFunc\ParseExternalLinks->render
|
||||
a.stdWrap.postUserFunc {
|
||||
iconFile = EXT:site_templates/Resources/Private/Partials/Atoms/IconExternalLinkFill.html
|
||||
iconPosistion = end
|
||||
linkText = Externer Link zu
|
||||
}
|
||||
}
|
||||
}
|
34
src/styles/link-external.sass
Normal file
34
src/styles/link-external.sass
Normal file
@ -0,0 +1,34 @@
|
||||
.link-external
|
||||
.link-external-inner
|
||||
position: relative
|
||||
.icon-circle-right
|
||||
display: none
|
||||
.icon-link-external
|
||||
display: inline-block
|
||||
position: relative
|
||||
top: 2px
|
||||
margin-left: 4px
|
||||
//right: 2px
|
||||
width: 16px
|
||||
line-height: 1
|
||||
div
|
||||
display: inline-block
|
||||
.svg-icon-element,
|
||||
.svg-icon
|
||||
display: block
|
||||
width: 16px
|
||||
height: 16px
|
||||
.link-external-sr-only
|
||||
position: absolute !important
|
||||
margin: 0
|
||||
border: 0
|
||||
padding: 0
|
||||
width: 1px
|
||||
height: 1px
|
||||
overflow: hidden
|
||||
white-space: nowrap
|
||||
clip: rect(1px 1px 1px 1px)
|
||||
clip: rect(1px, 1px, 1px, 1px)
|
||||
clip-path: inset(50%)
|
||||
&.imagelink
|
||||
padding-left: 0
|
Loading…
x
Reference in New Issue
Block a user