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 * list of BBCodes which contain raw code (disabled BBCode parsing)
31 * @var array<\wcf\data\bbcode\BBCode>
33 protected $sourceBBCodes = null;
36 * @see \wcf\system\SingletonFactory::init()
38 protected function init() {
39 foreach (BBCodeCache
::getInstance()->getBBCodes() as $bbcode) {
40 if ($bbcode->showButton
) {
41 $this->buttonBBCodes
[] = $bbcode;
47 * Returns true if the BBCode with the given tag is available in the WYSIWYG editor.
49 * @param string $bbCodeTag
52 public function isAvailableBBCode($bbCodeTag) {
53 $bbCode = BBCodeCache
::getInstance()->getBBCodeByTag($bbCodeTag);
54 if ($bbCode === null ||
$bbCode->isDisabled
) {
58 if (in_array('all', $this->allowedBBCodes
)) {
61 else if (in_array('none', $this->allowedBBCodes
)) {
65 return in_array($bbCodeTag, $this->allowedBBCodes
);
69 * Returns a list of BBCodes displayed as buttons.
71 * @return array<\wcf\data\bbcode\BBCode>
73 public function getButtonBBCodes() {
75 foreach ($this->buttonBBCodes
as $bbcode) {
76 if ($this->isAvailableBBCode($bbcode->bbcodeTag
)) {
85 * Sets the allowed BBCodes.
87 * @param array<string>
89 public function setAllowedBBCodes(array $bbCodes) {
90 $this->allowedBBCodes
= $bbCodes;
94 * Returns a list of BBCodes which contain raw code (disabled BBCode parsing)
96 * @return array<\wcf\data\bbcode\BBCode>
98 public function getSourceBBCodes() {
99 if (empty($this->allowedBBCodes
)) {
103 if ($this->sourceBBCodes
=== null) {
104 $this->sourceBBCodes
= array();
106 foreach (BBCodeCache
::getInstance()->getBBCodes() as $bbcode) {
107 if (!$bbcode->isSourceCode
) {
111 if ($this->isAvailableBBCode($bbcode->bbcodeTag
)) {
112 $this->sourceBBCodes
[] = $bbcode;
117 return $this->sourceBBCodes
;