Apply PSR-12 code style (#3886)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / bbcode / WoltLabSuitePageBBCode.class.php
1 <?php
2
3 namespace wcf\system\bbcode;
4
5 use wcf\data\page\Page;
6 use wcf\system\message\embedded\object\MessageEmbeddedObjectManager;
7 use wcf\util\StringUtil;
8
9 /**
10 * Parses the [wsp] bbcode tag.
11 *
12 * @author Alexander Ebert
13 * @copyright 2001-2019 WoltLab GmbH
14 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
15 * @package WoltLabSuite\Core\System\Bbcode
16 * @since 3.0
17 */
18 class WoltLabSuitePageBBCode extends AbstractBBCode
19 {
20 /**
21 * @inheritDoc
22 */
23 public function getParsedTag(array $openingTag, $content, array $closingTag, BBCodeParser $parser)
24 {
25 $pageID = (!empty($openingTag['attributes'][0])) ? \intval($openingTag['attributes'][0]) : 0;
26 if (!$pageID) {
27 return '';
28 }
29
30 $title = (!empty($openingTag['attributes'][1])) ? StringUtil::trim($openingTag['attributes'][1]) : '';
31
32 /** @var Page $page */
33 $page = MessageEmbeddedObjectManager::getInstance()->getObject('com.woltlab.wcf.page', $pageID);
34 if ($page !== null) {
35 return StringUtil::getAnchorTag($page->getLink(), $title ?: $page->getTitle());
36 }
37
38 return '';
39 }
40 }