Initial commit
This commit is contained in:
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Page\Header;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use FluidTYPO3\Vhs\Service\PageSelectService;
|
||||
use TYPO3\CMS\Core\Page\PageRenderer;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
|
||||
/**
|
||||
* Returns the all alternate urls.
|
||||
*
|
||||
* @author Danilo Bürger <danilo.buerger@hmspl.de>, Heimspiel GmbH
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Page\Header
|
||||
*/
|
||||
class AlternateViewHelper extends AbstractViewHelper {
|
||||
|
||||
/**
|
||||
* @var PageSelectService
|
||||
*/
|
||||
protected $pageSelect;
|
||||
|
||||
/**
|
||||
* @var ObjectManagerInterface
|
||||
*/
|
||||
protected $objectManager;
|
||||
|
||||
/**
|
||||
* @var \TYPO3\CMS\Fluid\Core\ViewHelper\TagBuilder
|
||||
*/
|
||||
protected $tagBuilder;
|
||||
|
||||
/**
|
||||
* @param PageSelectService $pageSelectService
|
||||
* @return void
|
||||
*/
|
||||
public function injectPageSelectService(PageSelectService $pageSelectService) {
|
||||
$this->pageSelect = $pageSelectService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ObjectManagerInterface $objectManager
|
||||
* @return void
|
||||
*/
|
||||
public function injectObjectManager(ObjectManagerInterface $objectManager) {
|
||||
$this->objectManager = $objectManager;
|
||||
$this->tagBuilder = $this->objectManager->get('TYPO3\\CMS\\Fluid\\Core\\ViewHelper\\TagBuilder');
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
$this->registerArgument('languages', 'mixed', 'The languages (either CSV, array or implementing Traversable)', TRUE);
|
||||
$this->registerArgument('pageUid', 'integer', 'The page uid to check', FALSE, 0);
|
||||
$this->registerArgument('normalWhenNoLanguage', 'boolean', 'If TRUE, a missing page overlay should be ignored', FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function render() {
|
||||
if ('BE' === TYPO3_MODE) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$languages = $this->arguments['languages'];
|
||||
if (TRUE === $languages instanceof \Traversable) {
|
||||
$languages = iterator_to_array($languages);
|
||||
} elseif (TRUE === is_string($languages)) {
|
||||
$languages = GeneralUtility::trimExplode(',', $languages, TRUE);
|
||||
} else {
|
||||
$languages = (array) $languages;
|
||||
}
|
||||
|
||||
$pageUid = intval($this->arguments['pageUid']);
|
||||
$normalWhenNoLanguage = $this->arguments['normalWhenNoLanguage'];
|
||||
|
||||
if (0 === $pageUid) {
|
||||
$pageUid = $GLOBALS['TSFE']->id;
|
||||
}
|
||||
|
||||
/** @var UriBuilder $uriBuilder */
|
||||
$uriBuilder = $this->controllerContext->getUriBuilder();
|
||||
$uriBuilder = $uriBuilder->reset()
|
||||
->setTargetPageUid($pageUid)
|
||||
->setCreateAbsoluteUri(TRUE);
|
||||
|
||||
$this->tagBuilder->reset();
|
||||
$this->tagBuilder->setTagName('link');
|
||||
$this->tagBuilder->addAttribute('rel', 'alternate');
|
||||
|
||||
/** @var PageRenderer $pageRenderer */
|
||||
$pageRenderer = $GLOBALS['TSFE']->getPageRenderer();
|
||||
$usePageRenderer = (1 !== intval($GLOBALS['TSFE']->config['config']['disableAllHeaderCode']));
|
||||
$output = '';
|
||||
|
||||
foreach ($languages as $languageUid => $languageName) {
|
||||
if (FALSE === $this->pageSelect->hidePageForLanguageUid($pageUid, $languageUid, $normalWhenNoLanguage)) {
|
||||
$uri = $uriBuilder->setArguments(array('L' => $languageUid))->build();
|
||||
$this->tagBuilder->addAttribute('href', $uri);
|
||||
$this->tagBuilder->addAttribute('hreflang', $languageName);
|
||||
|
||||
$renderedTag = $this->tagBuilder->render();
|
||||
if (TRUE === $usePageRenderer) {
|
||||
$pageRenderer->addMetaTag($renderedTag);
|
||||
} else {
|
||||
$output .= $renderedTag . LF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (FALSE === $usePageRenderer) {
|
||||
return trim($output);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Page\Header;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use FluidTYPO3\Vhs\Service\PageSelectService;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
|
||||
|
||||
/**
|
||||
* Returns the current canonical url in a link tag.
|
||||
*
|
||||
* @author Danilo Bürger <danilo.buerger@hmspl.de>, Heimspiel GmbH
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Page\Header
|
||||
*/
|
||||
class CanonicalViewHelper extends AbstractTagBasedViewHelper {
|
||||
|
||||
/**
|
||||
* @var PageSelectService
|
||||
*/
|
||||
protected $pageSelect;
|
||||
|
||||
/**
|
||||
* @param PageSelectService $pageSelectService
|
||||
* @return void
|
||||
*/
|
||||
public function injectPageSelectService(PageSelectService $pageSelectService) {
|
||||
$this->pageSelect = $pageSelectService;
|
||||
}
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tagName = 'link';
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
$this->registerUniversalTagAttributes();
|
||||
$this->registerArgument('pageUid', 'integer', 'The page uid to check', FALSE, 0);
|
||||
$this->registerArgument('normalWhenNoLanguage', 'boolean', 'DEPRECATED: Visibility is now handled by core\'s typolink function.', FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function render() {
|
||||
if ('BE' === TYPO3_MODE) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$pageUid = $this->arguments['pageUid'];
|
||||
if (0 === $pageUid) {
|
||||
$pageUid = $GLOBALS['TSFE']->id;
|
||||
}
|
||||
|
||||
$configuration = array(
|
||||
'parameter' => $pageUid,
|
||||
'forceAbsoluteUrl' => 1,
|
||||
);
|
||||
|
||||
$uri = $GLOBALS['TSFE']->cObj->typoLink_URL($configuration);
|
||||
|
||||
if (TRUE === empty($uri)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$uri = $GLOBALS['TSFE']->baseUrlWrap($uri);
|
||||
|
||||
$this->tag->addAttribute('rel', 'canonical');
|
||||
$this->tag->addAttribute('href', $uri);
|
||||
|
||||
$renderedTag = $this->tag->render();
|
||||
|
||||
if (1 === intval($GLOBALS['TSFE']->config['config']['disableAllHeaderCode'])) {
|
||||
return $renderedTag;
|
||||
}
|
||||
|
||||
$GLOBALS['TSFE']->getPageRenderer()->addMetaTag($renderedTag);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Page\Header;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use FluidTYPO3\Vhs\Traits\TagViewHelperTrait;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
|
||||
|
||||
/**
|
||||
* ViewHelper used to render a link tag in the `<head>` section of the page.
|
||||
* If you use the ViewHelper in a plugin, the plugin and its action have to
|
||||
* be cached!
|
||||
*
|
||||
* @author Georg Ringer
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Page\Header
|
||||
*/
|
||||
class LinkViewHelper extends AbstractTagBasedViewHelper {
|
||||
|
||||
use TagViewHelperTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tagName = 'link';
|
||||
|
||||
/**
|
||||
* Arguments initialization
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
$this->registerTagAttribute('rel', 'string', 'Property: rel');
|
||||
$this->registerTagAttribute('href', 'string', 'Property: href');
|
||||
$this->registerTagAttribute('type', 'string', 'Property: type');
|
||||
$this->registerTagAttribute('lang', 'string', 'Property: lang');
|
||||
$this->registerTagAttribute('dir', 'string', 'Property: dir');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render() {
|
||||
if ('BE' === TYPO3_MODE) {
|
||||
return;
|
||||
}
|
||||
$GLOBALS['TSFE']->getPageRenderer()->addMetaTag($this->renderTag($this->tagName));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Page\Header;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use FluidTYPO3\Vhs\Traits\TagViewHelperTrait;
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
|
||||
|
||||
/**
|
||||
* ViewHelper used to render a meta tag
|
||||
*
|
||||
* If you use the ViewHelper in a plugin it has to be USER
|
||||
* not USER_INT, what means it has to be cached!
|
||||
*
|
||||
* @author Georg Ringer
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Page\Header
|
||||
*/
|
||||
class MetaViewHelper extends AbstractTagBasedViewHelper {
|
||||
|
||||
use TagViewHelperTrait;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $tagName = 'meta';
|
||||
|
||||
/**
|
||||
* Arguments initialization
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
$this->registerTagAttribute('name', 'string', 'Name property of meta tag');
|
||||
$this->registerTagAttribute('property', 'string', 'Property of meta tag');
|
||||
$this->registerTagAttribute('content', 'string', 'Content of meta tag');
|
||||
$this->registerTagAttribute('http-equiv', 'string', 'Property: http-equiv');
|
||||
$this->registerTagAttribute('scheme', 'string', 'Property: scheme');
|
||||
$this->registerTagAttribute('lang', 'string', 'Property: lang');
|
||||
$this->registerTagAttribute('dir', 'string', 'Property: dir');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render() {
|
||||
if ('BE' === TYPO3_MODE) {
|
||||
return;
|
||||
}
|
||||
if (TRUE === isset($this->arguments['content']) && FALSE === empty($this->arguments['content'])) {
|
||||
$GLOBALS['TSFE']->getPageRenderer()
|
||||
->addMetaTag($this->renderTag($this->tagName, NULL, array('content' => $this->arguments['content'])));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace FluidTYPO3\Vhs\ViewHelpers\Page\Header;
|
||||
|
||||
/*
|
||||
* This file is part of the FluidTYPO3/Vhs project under GPLv2 or later.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.md file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;
|
||||
|
||||
/**
|
||||
* ### ViewHelper used to override page title
|
||||
*
|
||||
* This ViewHelper uses the TYPO3 PageRenderer to set the
|
||||
* page title - with everything this implies regarding
|
||||
* support for TypoScript settings.
|
||||
*
|
||||
* Specifically you should note the setting `config.noPageTitle`
|
||||
* which must be set to either 1 (one) in case no other source
|
||||
* defines the page title (it's likely that at least one does),
|
||||
* or 2 (two) to indicate that the TS-controlled page title
|
||||
* must be disabled. A value of 2 (two) ensures that the title
|
||||
* used in this ViewHelper will be used in the rendered page.
|
||||
*
|
||||
* If you use the ViewHelper in a plugin it has to be USER
|
||||
* not USER_INT, what means it has to be cached!
|
||||
*
|
||||
* #### Why can I not forcibly override the title?
|
||||
*
|
||||
* This has been opted out with full intention. The reasoning
|
||||
* behind not allowing a Fluid template to forcibly override the
|
||||
* page title that may be set through TypoScript is that many
|
||||
* other extensions (mainly SEO-focused ones) will be setting
|
||||
* and manipulating the page title - and if overridden in a
|
||||
* template file using a ViewHelper, it would be almost impossible
|
||||
* to detect unless you already know exactly where to look.
|
||||
* Enforcing use of the core behavior is the only way to ensure
|
||||
* that this ViewHelper can coexist with other extensions in
|
||||
* a fully controllable way.
|
||||
*
|
||||
* @author Georg Ringer
|
||||
* @package Vhs
|
||||
* @subpackage ViewHelpers\Page\Header
|
||||
*/
|
||||
class TitleViewHelper extends AbstractViewHelper {
|
||||
|
||||
/**
|
||||
* Arguments initialization
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function initializeArguments() {
|
||||
$this->registerArgument('title', 'string', 'Title tag content');
|
||||
$this->registerArgument('whitespaceString', 'string', 'String used to replace groups of white space characters, one replacement inserted per group', FALSE, ' ');
|
||||
$this->registerArgument('setIndexedDocTitle', 'boolean', 'Set indexed doc title to title', FALSE, FALSE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Render method
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render() {
|
||||
if ('BE' === TYPO3_MODE) {
|
||||
return;
|
||||
}
|
||||
if (FALSE === empty($this->arguments['title'])) {
|
||||
$title = $this->arguments['title'];
|
||||
} else {
|
||||
$title = $this->renderChildren();
|
||||
}
|
||||
$title = trim(preg_replace('/\s+/', $this->arguments['whitespaceString'], $title), $this->arguments['whitespaceString']);
|
||||
$GLOBALS['TSFE']->getPageRenderer()->setTitle($title);
|
||||
if (TRUE === $this->arguments['setIndexedDocTitle']) {
|
||||
$GLOBALS['TSFE']->indexedDocTitle = $title;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user