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