[+FEATURE] Fluid (ViewHelpers): prepend URIs with scheme if it's not specified in...
[Packages/TYPO3.CMS.git] / typo3 / sysext / fluid / Classes / ViewHelpers / Link / ExternalViewHelper.php
1 <?php
2
3 /* *
4 * This script belongs to the FLOW3 package "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 as published by the *
8 * Free Software Foundation, either version 3 of the License, or (at your *
9 * option) any later version. *
10 * *
11 * This script is distributed in the hope that it will be useful, but *
12 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
13 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
14 * General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Lesser General Public *
17 * License along with the script. *
18 * If not, see http://www.gnu.org/licenses/lgpl.html *
19 * *
20 * The TYPO3 project - inspiring people to share! *
21 * */
22
23 /**
24 * A view helper for creating links to external targets.
25 *
26 * = Examples =
27 *
28 * <code>
29 * <f:link.external uri="http://www.typo3.org" target="_blank">external link</f:link.external>
30 * </code>
31 * <output>
32 * <a href="http://www.typo3.org" target="_blank">external link</a>
33 * </output>
34 *
35 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
36 * @api
37 */
38 class Tx_Fluid_ViewHelpers_Link_ExternalViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper {
39
40 /**
41 * @var string
42 */
43 protected $tagName = 'a';
44
45 /**
46 * Initialize arguments
47 *
48 * @return void
49 * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
50 * @api
51 */
52 public function initializeArguments() {
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 * @author Bastian Waidelich <bastian@typo3.org>
65 * @api
66 */
67 public function render($uri, $defaultScheme = 'http') {
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
75 return $this->tag->render();
76 }
77 }
78
79
80 ?>