[!!!][FEATURE] Switch to standalone Fluid template engine
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Link / ExternalViewHelper.php
1 <?php
2 namespace TYPO3\CMS\Fluid\ViewHelpers\Link;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 /**
18 * A view helper for creating links to external targets.
19 *
20 * = Examples =
21 *
22 * <code>
23 * <f:link.external uri="http://www.typo3.org" target="_blank">external link</f:link.external>
24 * </code>
25 * <output>
26 * <a href="http://www.typo3.org" target="_blank">external link</a>
27 * </output>
28 *
29 * <code title="custom default scheme">
30 * <f:link.external uri="typo3.org" defaultScheme="ftp">external ftp link</f:link.external>
31 * </code>
32 * <output>
33 * <a href="ftp://typo3.org">external ftp link</a>
34 * </output>
35 *
36 * @api
37 */
38 class ExternalViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper
39 {
40 /**
41 * @var string
42 */
43 protected $tagName = 'a';
44
45 /**
46 * Initialize arguments
47 *
48 * @return void
49 * @api
50 */
51 public function initializeArguments()
52 {
53 $this->registerUniversalTagAttributes();
54 $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
55 $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
56 $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
57 $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
58 }
59
60 /**
61 * @param string $uri the URI that will be put in the href attribute of the rendered link tag
62 * @param string $defaultScheme scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already
63 * @return string Rendered link
64 * @api
65 */
66 public function render($uri, $defaultScheme = 'http')
67 {
68 $scheme = parse_url($uri, PHP_URL_SCHEME);
69 if ($scheme === null && $defaultScheme !== '') {
70 $uri = $defaultScheme . '://' . $uri;
71 }
72 $this->tag->addAttribute('href', $uri);
73 $this->tag->setContent($this->renderChildren());
74 $this->tag->forceClosingTag(true);
75
76 return $this->tag->render();
77 }
78 }