Apply PSR-12 code style (#3886)
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / cache / builder / BBCodeCacheBuilder.class.php
CommitLineData
dcc2332d 1<?php
a9229942 2
dcc2332d 3namespace wcf\system\cache\builder;
a9229942 4
dcc2332d 5use wcf\data\bbcode\attribute\BBCodeAttribute;
25863cff 6use wcf\data\bbcode\BBCodeList;
dcc2332d
MW
7use wcf\system\WCF;
8
9/**
10 * Caches the bbcodes.
a9229942
TD
11 *
12 * @author Marcel Werk
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\Cache\Builder
dcc2332d 16 */
a9229942
TD
17class BBCodeCacheBuilder extends AbstractCacheBuilder
18{
19 /**
20 * @inheritDoc
21 */
22 protected function rebuild(array $parameters)
23 {
24 $attributes = [];
25 $data = ['bbcodes' => [], 'highlighters' => []];
26
27 // get attributes
28 $sql = "SELECT attribute.*, bbcode.bbcodeTag
29 FROM wcf" . WCF_N . "_bbcode_attribute attribute
30 LEFT JOIN wcf" . WCF_N . "_bbcode bbcode
31 ON (bbcode.bbcodeID = attribute.bbcodeID)
32 ORDER BY attribute.attributeNo";
33 $statement = WCF::getDB()->prepareStatement($sql);
34 $statement->execute();
35 while ($row = $statement->fetchArray()) {
36 if (!isset($attributes[$row['bbcodeTag']])) {
37 $attributes[$row['bbcodeTag']] = [];
38 }
39
40 $attributes[$row['bbcodeTag']][$row['attributeNo']] = new BBCodeAttribute(null, $row);
41 }
42
43 // get bbcodes
44 $bbcodeList = new BBCodeList();
45 $bbcodeList->readObjects();
46 foreach ($bbcodeList as $bbcode) {
47 if (isset($attributes[$bbcode->bbcodeTag])) {
48 $bbcode->setAttributes($attributes[$bbcode->bbcodeTag]);
49 } else {
50 // set an empty array, because the internal default value of a bbcode's
51 // attributes is null, this avoid an infinite loop
52 $bbcode->setAttributes([]);
53 }
54
55 $data['bbcodes'][$bbcode->bbcodeTag] = $bbcode;
56 }
57
58 // get code highlighters
59 $highlighters = \glob(WCF_DIR . 'lib/system/bbcode/highlighter/*.class.php');
60 if (\is_array($highlighters)) {
61 foreach ($highlighters as $highlighter) {
62 if (\preg_match('~\/([a-zA-Z]+)Highlighter\.class\.php$~', $highlighter, $matches)) {
63 $data['highlighters'][] = \strtolower($matches[1]);
64 }
65 }
66 }
67
68 return $data;
69 }
dcc2332d 70}