2 namespace wcf\system\option\user\group
;
3 use wcf\data\bbcode\BBCodeCache
;
4 use wcf\data\option\Option
;
5 use wcf\system\exception\UserInputException
;
6 use wcf\system\option\AbstractOptionType
;
8 use wcf\util\StringUtil
;
11 * User group option type implementation for BBCode select lists.
13 * @author Matthias Schmidt
14 * @copyright 2001-2017 WoltLab GmbH
15 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
16 * @package WoltLabSuite\Core\System\Option
18 class BBCodeSelectUserGroupOptionType
extends AbstractOptionType
implements IUserGroupOptionType
{
26 * list of bbcode tags that are always available
29 protected static $alwaysAvailable = ['align', 'attach', 'b', 'code', 'i', 'list', 'quote', 's', 'sub', 'sup', 'table', 'td', 'tr', 'tt', 'u', 'user', 'wsm', 'wsmg', 'wsp'];
34 public function getData(Option
$option, $newValue) {
35 if (!is_array($newValue)) {
39 return implode(',', $newValue);
45 public function getFormElement(Option
$option, $value) {
46 if ($this->bbCodes
=== null) {
47 $this->loadBBCodeSelection();
50 WCF
::getTPL()->assign([
51 'bbCodes' => $this->bbCodes
,
53 'selectedBBCodes' => explode(',', $value)
56 return WCF
::getTPL()->fetch('bbCodeSelectOptionType');
60 * Loads the list of BBCodes for the HTML select element.
64 protected function loadBBCodeSelection() {
65 $this->bbCodes
= array_keys(BBCodeCache
::getInstance()->getBBCodes());
66 $this->bbCodes
= array_diff($this->bbCodes
, self
::$alwaysAvailable);
68 asort($this->bbCodes
);
74 public function merge($defaultValue, $groupValue) {
75 if ($this->bbCodes
=== null) {
76 $this->loadBBCodeSelection();
79 if (empty($defaultValue)) {
83 $defaultValue = explode(',', StringUtil
::unifyNewlines($defaultValue));
86 if (empty($groupValue)) {
90 $groupValue = explode(',', StringUtil
::unifyNewlines($groupValue));
93 $newValue = array_intersect($defaultValue, $groupValue);
96 return implode(',', $newValue);
102 public function validate(Option
$option, $newValue) {
103 if (!is_array($newValue)) {
107 if ($this->bbCodes
=== null) {
108 $this->loadBBCodeSelection();
111 foreach ($newValue as $tag) {
112 if (!in_array($tag, $this->bbCodes
)) {
113 throw new UserInputException($option->optionName
, 'validationFailed');
121 public function compare($value1, $value2) {
122 // handle special case where no disallowed BBCodes have been set
123 if (empty($value1)) {
124 if (empty($value2)) {
130 else if (empty($value2)) {
134 $value1 = explode(',', $value1);
135 $value2 = explode(',', $value2);
137 // check if value1 disallows more BBCodes than value2
138 $diff = array_diff($value1, $value2);
143 // check if value1 disallows less BBCodes than value2
144 $diff = array_diff($value2, $value1);
149 // both lists of BBCodes are equal