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