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-2018 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.
62 protected function loadBBCodeSelection() {
63 $this->bbCodes
= array_keys(BBCodeCache
::getInstance()->getBBCodes());
64 $this->bbCodes
= array_diff($this->bbCodes
, self
::$alwaysAvailable);
66 asort($this->bbCodes
);
72 public function merge($defaultValue, $groupValue) {
73 if ($this->bbCodes
=== null) {
74 $this->loadBBCodeSelection();
77 if (empty($defaultValue)) {
81 $defaultValue = explode(',', StringUtil
::unifyNewlines($defaultValue));
84 if (empty($groupValue)) {
88 $groupValue = explode(',', StringUtil
::unifyNewlines($groupValue));
91 $newValue = array_intersect($defaultValue, $groupValue);
94 return implode(',', $newValue);
100 public function validate(Option
$option, $newValue) {
101 if (!is_array($newValue)) {
105 if ($this->bbCodes
=== null) {
106 $this->loadBBCodeSelection();
109 foreach ($newValue as $tag) {
110 if (!in_array($tag, $this->bbCodes
)) {
111 throw new UserInputException($option->optionName
, 'validationFailed');
119 public function compare($value1, $value2) {
120 // handle special case where no disallowed BBCodes have been set
121 if (empty($value1)) {
122 if (empty($value2)) {
128 else if (empty($value2)) {
132 $value1 = explode(',', $value1);
133 $value2 = explode(',', $value2);
135 // check if value1 disallows more BBCodes than value2
136 $diff = array_diff($value1, $value2);
141 // check if value1 disallows less BBCodes than value2
142 $diff = array_diff($value2, $value1);
147 // both lists of BBCodes are equal