Apply PSR-12 code style (#3886)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / template / plugin / LinkBlockTemplatePlugin.class.php
CommitLineData
158bd3ca 1<?php
a9229942 2
158bd3ca 3namespace wcf\system\template\plugin;
a9229942 4
158bd3ca 5use wcf\system\request\LinkHandler;
158bd3ca 6use wcf\system\template\TemplateEngine;
490a2ce9 7use wcf\util\StringUtil;
158bd3ca
TD
8
9/**
a17de04e 10 * Template block plugin which generates a link using LinkHandler.
a9229942 11 *
158bd3ca 12 * Usage:
a9229942
TD
13 * {link application='wcf'}index.php{/link}
14 *
15 * @author Marcel Werk
16 * @copyright 2001-2019 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package WoltLabSuite\Core\System\Template\Plugin
158bd3ca 19 */
a9229942
TD
20class LinkBlockTemplatePlugin implements IBlockTemplatePlugin
21{
22 /**
23 * internal loop counter
24 * @var int
25 */
26 protected $counter = 0;
27
28 /**
29 * @inheritDoc
30 */
31 public function execute($tagArgs, $blockContent, TemplateEngine $tplObj)
32 {
33 if (!\array_key_exists('controller', $tagArgs)) {
34 $tagArgs['controller'] = null;
35 }
36
37 if (!isset($tagArgs['application']) || empty($tagArgs['application'])) {
38 $tagArgs['application'] = 'wcf';
39 }
40
41 if (isset($tagArgs['isEmail']) && $tagArgs['isEmail']) {
42 $tagArgs['encode'] = false;
43 }
44
45 if (isset($tagArgs['isHtmlEmail'])) {
46 if ($tagArgs['isHtmlEmail']) {
47 $tagArgs['isEmail'] = true;
48 $tagArgs['encode'] = true;
49 }
50
51 unset($tagArgs['isHtmlEmail']);
52 }
53
54 if (isset($tagArgs['encode'])) {
55 $encode = $tagArgs['encode'];
56 unset($tagArgs['encode']);
57
58 if (!$encode) {
59 return LinkHandler::getInstance()->getLink($tagArgs['controller'], $tagArgs, $blockContent);
60 }
61 }
62
63 return StringUtil::encodeHTML(LinkHandler::getInstance()->getLink(
64 $tagArgs['controller'],
65 $tagArgs,
66 $blockContent
67 ));
68 }
69
70 /**
71 * @inheritDoc
72 */
73 public function init($tagArgs, TemplateEngine $tplObj)
74 {
75 $this->counter = 0;
76 }
77
78 /**
79 * @inheritDoc
80 */
81 public function next(TemplateEngine $tplObj)
82 {
83 if ($this->counter == 0) {
84 $this->counter++;
85
86 return true;
87 }
62ebbb06 88
a9229942
TD
89 return false;
90 }
dcb3a44c 91}