[TASK] Namespace classes
[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 script is backported from the FLOW3 package "TYPO3.Fluid". *
6 * *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License, either version 3 *
9 * of the License, or (at your option) any later version. *
10 * *
11 * The TYPO3 project - inspiring people to share! *
12 * */
13 /**
14 * A view helper for creating links to external targets.
15 *
16 * = Examples =
17 *
18 * <code>
19 * <f:link.external uri="http://www.typo3.org" target="_blank">external link</f:link.external>
20 * </code>
21 * <output>
22 * <a href="http://www.typo3.org" target="_blank">external link</a>
23 * </output>
24 *
25 * <code title="custom default scheme">
26 * <f:link.external uri="typo3.org" defaultScheme="ftp">external ftp link</f:link.external>
27 * </code>
28 * <output>
29 * <a href="ftp://typo3.org">external ftp link</a>
30 * </output>
31 *
32 * @api
33 */
34 class ExternalViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper {
35
36 /**
37 * @var string
38 */
39 protected $tagName = 'a';
40
41 /**
42 * Initialize arguments
43 *
44 * @return void
45 * @api
46 */
47 public function initializeArguments() {
48 $this->registerUniversalTagAttributes();
49 $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
50 $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
51 $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
52 $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
53 }
54
55 /**
56 * @param string $uri the URI that will be put in the href attribute of the rendered link tag
57 * @param string $defaultScheme scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already
58 * @return string Rendered link
59 * @api
60 */
61 public function render($uri, $defaultScheme = 'http') {
62 $scheme = parse_url($uri, PHP_URL_SCHEME);
63 if ($scheme === NULL && $defaultScheme !== '') {
64 $uri = ($defaultScheme . '://') . $uri;
65 }
66 $this->tag->addAttribute('href', $uri);
67 $this->tag->setContent($this->renderChildren());
68 $this->tag->forceClosingTag(TRUE);
69 return $this->tag->render();
70 }
71
72 }
73
74
75 ?>