2 namespace wcf\system\bbcode
;
3 use wcf\data\bbcode\BBCodeCache
;
4 use wcf\system\SingletonFactory
;
7 * Handles BBCodes displayed as buttons within the WYSIWYG editor.
9 * @author Alexander Ebert
10 * @copyright 2001-2014 WoltLab GmbH
11 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
12 * @package com.woltlab.wcf
13 * @subpackage system.bbcode
14 * @category Community Framework
16 class BBCodeHandler
extends SingletonFactory
{
18 * list of BBCodes allowed for usage
19 * @var array<\wcf\data\bbcode\BBCode>
21 protected $allowedBBCodes = array();
24 * list of BBCodes displayed as buttons
25 * @var array<\wcf\data\bbcode\BBCode>
27 protected $buttonBBCodes = array();
30 * @see \wcf\system\SingletonFactory::init()
32 protected function init() {
33 foreach (BBCodeCache
::getInstance()->getBBCodes() as $bbcode) {
34 if ($bbcode->showButton
) {
35 $this->buttonBBCodes
[] = $bbcode;
41 * Returns true if the BBCode with the given tag is available in the WYSIWYG editor.
43 * @param string $bbCodeTag
46 public function isAvailableBBCode($bbCodeTag) {
47 $bbCode = BBCodeCache
::getInstance()->getBBCodeByTag($bbCodeTag);
48 if ($bbCode === null ||
$bbCode->isDisabled
) {
52 if (in_array('all', $this->allowedBBCodes
)) {
55 else if (in_array('none', $this->allowedBBCodes
)) {
59 return in_array($bbCodeTag, $this->allowedBBCodes
);
63 * Returns a list of BBCodes displayed as buttons.
65 * @return array<\wcf\data\bbcode\BBCode>
67 public function getButtonBBCodes() {
69 foreach ($this->buttonBBCodes
as $bbcode) {
70 if ($this->isAvailableBBCode($bbcode->bbcodeTag
)) {
79 * Sets the allowed BBCodes.
81 * @param array<string>
83 public function setAllowedBBCodes(array $bbCodes) {
84 $this->allowedBBCodes
= $bbCodes;