Merge "[FEATURE] PaddingViewHelper: allow padding-type right/left/both"
[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 * <code title="custom default scheme">
36 * <f:link.external uri="typo3.org" defaultScheme="ftp">external ftp link</f:link.external>
37 * </code>
38 * <output>
39 * <a href="ftp://typo3.org">external ftp link</a>
40 * </output>
41 *
42 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
43 * @api
44 */
45 class Tx_Fluid_ViewHelpers_Link_ExternalViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractTagBasedViewHelper {
46
47 /**
48 * @var string
49 */
50 protected $tagName = 'a';
51
52 /**
53 * Initialize arguments
54 *
55 * @return void
56 * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
57 * @api
58 */
59 public function initializeArguments() {
60 $this->registerUniversalTagAttributes();
61 $this->registerTagAttribute('name', 'string', 'Specifies the name of an anchor');
62 $this->registerTagAttribute('rel', 'string', 'Specifies the relationship between the current document and the linked document');
63 $this->registerTagAttribute('rev', 'string', 'Specifies the relationship between the linked document and the current document');
64 $this->registerTagAttribute('target', 'string', 'Specifies where to open the linked document');
65 }
66
67 /**
68 * @param string $uri the URI that will be put in the href attribute of the rendered link tag
69 * @param string $defaultScheme scheme the href attribute will be prefixed with if specified $uri does not contain a scheme already
70 * @return string Rendered link
71 * @author Bastian Waidelich <bastian@typo3.org>
72 * @api
73 */
74 public function render($uri, $defaultScheme = 'http') {
75 $scheme = parse_url($uri, PHP_URL_SCHEME);
76 if ($scheme === NULL && $defaultScheme !== '') {
77 $uri = $defaultScheme . '://' . $uri;
78 }
79 $this->tag->addAttribute('href', $uri);
80 $this->tag->setContent($this->renderChildren());
81 $this->tag->forceClosingTag(TRUE);
82
83 return $this->tag->render();
84 }
85 }
86
87
88 ?>