Fixed time zone calculation issue
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / bbcode / BBCodeHandler.class.php
1 <?php
2 namespace wcf\system\bbcode;
3 use wcf\data\bbcode\BBCodeCache;
4 use wcf\system\SingletonFactory;
5
6 /**
7 * Handles BBCodes displayed as buttons within the WYSIWYG editor.
8 *
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
15 */
16 class BBCodeHandler extends SingletonFactory {
17 /**
18 * list of BBCodes allowed for usage
19 * @var array<\wcf\data\bbcode\BBCode>
20 */
21 protected $allowedBBCodes = array();
22
23 /**
24 * list of BBCodes displayed as buttons
25 * @var array<\wcf\data\bbcode\BBCode>
26 */
27 protected $buttonBBCodes = array();
28
29 /**
30 * @see \wcf\system\SingletonFactory::init()
31 */
32 protected function init() {
33 foreach (BBCodeCache::getInstance()->getBBCodes() as $bbcode) {
34 if ($bbcode->showButton) {
35 $this->buttonBBCodes[] = $bbcode;
36 }
37 }
38 }
39
40 /**
41 * Returns true if the BBCode with the given tag is available in the WYSIWYG editor.
42 *
43 * @param string $bbCodeTag
44 * @return boolean
45 */
46 public function isAvailableBBCode($bbCodeTag) {
47 $bbCode = BBCodeCache::getInstance()->getBBCodeByTag($bbCodeTag);
48 if ($bbCode === null || $bbCode->isDisabled) {
49 return false;
50 }
51
52 if (in_array('all', $this->allowedBBCodes)) {
53 return true;
54 }
55 else if (in_array('none', $this->allowedBBCodes)) {
56 return false;
57 }
58
59 return in_array($bbCodeTag, $this->allowedBBCodes);
60 }
61
62 /**
63 * Returns a list of BBCodes displayed as buttons.
64 *
65 * @return array<\wcf\data\bbcode\BBCode>
66 */
67 public function getButtonBBCodes() {
68 $buttons = array();
69 foreach ($this->buttonBBCodes as $bbcode) {
70 if ($this->isAvailableBBCode($bbcode->bbcodeTag)) {
71 $buttons[] = $bbcode;
72 }
73 }
74
75 return $buttons;
76 }
77
78 /**
79 * Sets the allowed BBCodes.
80 *
81 * @param array<string>
82 */
83 public function setAllowedBBCodes(array $bbCodes) {
84 $this->allowedBBCodes = $bbCodes;
85 }
86 }