Skip to content

Commit 9989701

Browse files
committed
Store bbcode button label in wcf1_bbcode_content
1 parent e4bc9c4 commit 9989701

File tree

9 files changed

+269
-66
lines changed

9 files changed

+269
-66
lines changed

wcfsetup/install/files/acp/database/update_com.woltlab.wcf_6.2_step1.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,30 @@
8787
->referencedColumns(['languageID'])
8888
->onDelete('CASCADE'),
8989
]),
90+
DatabaseTable::create('wcf1_bbcode_content')
91+
->columns([
92+
ObjectIdDatabaseTableColumn::create('contentID'),
93+
IntDatabaseTableColumn::create('bbcodeID')
94+
->notNull(),
95+
IntDatabaseTableColumn::create('languageID'),
96+
NotNullVarchar255DatabaseTableColumn::create('buttonLabel'),
97+
])
98+
->indices([
99+
DatabaseTablePrimaryIndex::create()
100+
->columns(['contentID']),
101+
DatabaseTableIndex::create('id')
102+
->columns(['bbcodeID', 'languageID']),
103+
])
104+
->foreignKeys([
105+
DatabaseTableForeignKey::create()
106+
->columns(['bbcodeID'])
107+
->referencedTable('wcf1_bbcode')
108+
->referencedColumns(['bbcodeID'])
109+
->onDelete('CASCADE'),
110+
DatabaseTableForeignKey::create()
111+
->columns(['languageID'])
112+
->referencedTable('wcf1_language')
113+
->referencedColumns(['languageID'])
114+
->onDelete('CASCADE'),
115+
]),
90116
];

wcfsetup/install/files/acp/templates/bbcodeAdd.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
<dl class="jsButtonSetting{if $errorField == 'buttonLabel'} formError{/if}">
173173
<dt><label for="buttonLabel">{lang}wcf.acp.bbcode.buttonLabel{/lang}</label></dt>
174174
<dd>
175-
<input type="text" id="buttonLabel" name="buttonLabel" value="{$i18nPlainValues['buttonLabel']}" class="long">
175+
<input type="text" id="buttonLabel" name="buttonLabel" value="{if !$buttonLabel|is_array}{$buttonLabel}{/if}" class="long">
176176
{if $errorField == 'buttonLabel'}
177177
<small class="innerError">
178178
{if $errorType == 'empty'}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
use wcf\system\database\util\PreparedStatementConditionBuilder;
4+
use wcf\system\language\LanguageFactory;
5+
use wcf\system\WCF;
6+
7+
$sql = "SELECT bbcodeID, buttonLabel
8+
FROM wcf1_bbcode
9+
WHERE showButton = ?
10+
OR buttonLabel <> ''";
11+
$statement = WCF::getDB()->prepare($sql);
12+
$statement->execute([1]);
13+
$buttonLabels = $statement->fetchMap('bbcodeID', 'buttonLabel');
14+
15+
$sql = "INSERT INTO wcf1_bbcode_content
16+
(bbcodeID, languageID, buttonLabel)
17+
VALUES (?, ?, ?)";
18+
$statement = WCF::getDB()->prepare($sql);
19+
20+
$languageItems = [];
21+
foreach ($buttonLabels as $bbcodeID => $buttonLabel) {
22+
if (\preg_match('~^\w+(\.\w+){2,}$~', $buttonLabel, $matches)) {
23+
$languageItems[] = $buttonLabel;
24+
25+
foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
26+
$statement->execute([
27+
$bbcodeID,
28+
$language->languageID,
29+
$language->get($buttonLabel),
30+
]);
31+
}
32+
} else {
33+
$statement->execute([
34+
$bbcodeID,
35+
LanguageFactory::getInstance()->getDefaultLanguageID(),
36+
$buttonLabel,
37+
]);
38+
}
39+
}
40+
41+
if ($languageItems !== []) {
42+
$conditionBuilder = new PreparedStatementConditionBuilder();
43+
$conditionBuilder->add('languageItem IN (?)', [$languageItems]);
44+
45+
$sql = "DELETE FROM wcf1_language_item
46+
{$conditionBuilder}";
47+
$statement = WCF::getDB()->prepare($sql);
48+
$statement->execute($conditionBuilder->getParameters());
49+
}

wcfsetup/install/files/lib/acp/form/BBCodeAddForm.class.php

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@
55
use wcf\data\bbcode\attribute\BBCodeAttributeAction;
66
use wcf\data\bbcode\BBCode;
77
use wcf\data\bbcode\BBCodeAction;
8-
use wcf\data\bbcode\BBCodeEditor;
98
use wcf\form\AbstractForm;
9+
use wcf\system\bbcode\command\SaveContent;
1010
use wcf\system\exception\UserInputException;
11-
use wcf\system\language\I18nHandler;
11+
use wcf\system\language\LanguageFactory;
1212
use wcf\system\Regex;
1313
use wcf\system\request\LinkHandler;
1414
use wcf\system\WCF;
15+
use wcf\util\ArrayUtil;
1516
use wcf\util\StringUtil;
1617

1718
/**
@@ -42,7 +43,8 @@ class BBCodeAddForm extends AbstractForm
4243

4344
/**
4445
* editor button label
45-
* @var string
46+
*
47+
* @var string|string[]
4648
*/
4749
public $buttonLabel = '';
4850

@@ -98,16 +100,6 @@ class BBCodeAddForm extends AbstractForm
98100
*/
99101
public $wysiwygIcon = '';
100102

101-
/**
102-
* @inheritDoc
103-
*/
104-
public function readParameters()
105-
{
106-
parent::readParameters();
107-
108-
I18nHandler::getInstance()->register('buttonLabel');
109-
}
110-
111103
/**
112104
* @inheritDoc
113105
*/
@@ -151,7 +143,6 @@ public function readFormParameters()
151143
$this->attributes[$key] = (object)$val;
152144
}
153145

154-
I18nHandler::getInstance()->readValues();
155146
$this->readButtonLabelFormParameter();
156147
}
157148

@@ -162,8 +153,10 @@ public function readFormParameters()
162153
*/
163154
protected function readButtonLabelFormParameter()
164155
{
165-
if (I18nHandler::getInstance()->isPlainValue('buttonLabel')) {
166-
$this->buttonLabel = I18nHandler::getInstance()->getValue('buttonLabel');
156+
if (isset($_POST['buttonLabel_i18n']) && \is_array($_POST['buttonLabel_i18n'])) {
157+
$this->buttonLabel = ArrayUtil::trim($_POST['buttonLabel_i18n']);
158+
} elseif (isset($_POST['buttonLabel'])) {
159+
$this->buttonLabel = StringUtil::trim($_POST['buttonLabel']);
167160
}
168161
}
169162

@@ -208,12 +201,14 @@ public function validate()
208201
// button
209202
if ($this->showButton) {
210203
// validate label
211-
if (!I18nHandler::getInstance()->validateValue('buttonLabel')) {
212-
if (I18nHandler::getInstance()->isPlainValue('buttonLabel')) {
213-
throw new UserInputException('buttonLabel');
214-
} else {
215-
throw new UserInputException('buttonLabel', 'multilingual');
204+
if (\is_array($this->buttonLabel)) {
205+
foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
206+
if (empty($this->buttonLabel[$language->languageID])) {
207+
throw new UserInputException('buttonLabel', 'multilingual');
208+
}
216209
}
210+
} elseif ($this->buttonLabel === '') {
211+
throw new UserInputException('buttonLabel');
217212
}
218213

219214
// validate image path
@@ -250,7 +245,6 @@ public function save()
250245
$this->objectAction = new BBCodeAction([], 'create', [
251246
'data' => \array_merge($this->additionalFields, [
252247
'bbcodeTag' => $this->bbcodeTag,
253-
'buttonLabel' => $this->buttonLabel,
254248
'className' => $this->className,
255249
'htmlOpen' => $this->htmlOpen,
256250
'htmlClose' => $this->htmlClose,
@@ -262,10 +256,14 @@ public function save()
262256
]),
263257
]);
264258
$returnValues = $this->objectAction->executeAction();
259+
$bbcodeID = $returnValues['returnValues']->bbcodeID;
260+
261+
$this->saveButtonLabel($bbcodeID);
262+
265263
foreach ($this->attributes as $attribute) {
266264
$attributeAction = new BBCodeAttributeAction([], 'create', [
267265
'data' => [
268-
'bbcodeID' => $returnValues['returnValues']->bbcodeID,
266+
'bbcodeID' => $bbcodeID,
269267
'attributeNo' => $attribute->attributeNo,
270268
'attributeHtml' => $attribute->attributeHtml,
271269
'validationPattern' => $attribute->validationPattern,
@@ -276,26 +274,13 @@ public function save()
276274
$attributeAction->executeAction();
277275
}
278276

279-
if ($this->showButton && !I18nHandler::getInstance()->isPlainValue('buttonLabel')) {
280-
$bbcodeID = $returnValues['returnValues']->bbcodeID;
281-
I18nHandler::getInstance()->save('buttonLabel', 'wcf.editor.button.button' . $bbcodeID, 'wcf.editor', 1);
282-
283-
// update button label
284-
$bbcodeEditor = new BBCodeEditor($returnValues['returnValues']);
285-
$bbcodeEditor->update([
286-
'buttonLabel' => 'wcf.editor.button.button' . $bbcodeID,
287-
]);
288-
}
289-
290277
$this->saved();
291278

292279
// reset values
293280
$this->bbcodeTag = $this->htmlOpen = $this->htmlClose = $this->className = $this->buttonLabel = $this->wysiwygIcon = '';
294281
$this->attributes = [];
295282
$this->isBlockElement = $this->isSourceCode = $this->showButton = false;
296283

297-
I18nHandler::getInstance()->reset();
298-
299284
// show success message
300285
WCF::getTPL()->assign([
301286
'success' => true,
@@ -313,13 +298,13 @@ public function assignVariables()
313298
{
314299
parent::assignVariables();
315300

316-
I18nHandler::getInstance()->assignVariables();
317-
318301
WCF::getTPL()->assign([
319302
'action' => 'add',
320303
'attributes' => $this->attributes,
321304
'bbcodeTag' => $this->bbcodeTag,
322305
'buttonLabel' => $this->buttonLabel,
306+
'availableLanguages' => LanguageFactory::getInstance()->getLanguages(),
307+
'i18nValues' => ['buttonLabel' => \is_array($this->buttonLabel) ? $this->buttonLabel : []],
323308
'className' => $this->className,
324309
'htmlOpen' => $this->htmlOpen,
325310
'htmlClose' => $this->htmlClose,
@@ -329,4 +314,17 @@ public function assignVariables()
329314
'wysiwygIcon' => $this->wysiwygIcon,
330315
]);
331316
}
317+
318+
protected function saveButtonLabel(int $bbcodeID): void
319+
{
320+
if ($this->showButton) {
321+
if (\is_array($this->buttonLabel)) {
322+
$buttonLabels = $this->buttonLabel;
323+
} else {
324+
$buttonLabels = [0 => $this->buttonLabel];
325+
}
326+
327+
(new SaveContent($bbcodeID, $buttonLabels))();
328+
}
329+
}
332330
}

wcfsetup/install/files/lib/acp/form/BBCodeEditForm.class.php

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use wcf\data\bbcode\BBCodeAction;
99
use wcf\form\AbstractForm;
1010
use wcf\system\exception\IllegalLinkException;
11-
use wcf\system\language\I18nHandler;
1211
use wcf\system\WCF;
1312

1413
/**
@@ -78,10 +77,6 @@ public function readParameters()
7877
if (!$this->bbcode->bbcodeID) {
7978
throw new IllegalLinkException();
8079
}
81-
82-
if (!\in_array($this->bbcode->bbcodeTag, self::$nativeBBCodes)) {
83-
I18nHandler::getInstance()->register('buttonLabel');
84-
}
8580
}
8681

8782
/**
@@ -111,21 +106,10 @@ public function save()
111106
{
112107
AbstractForm::save();
113108

114-
if ($this->showButton) {
115-
$this->buttonLabel = 'wcf.editor.button.button' . $this->bbcode->bbcodeID;
116-
if (I18nHandler::getInstance()->isPlainValue('buttonLabel')) {
117-
I18nHandler::getInstance()->remove($this->buttonLabel);
118-
$this->buttonLabel = I18nHandler::getInstance()->getValue('buttonLabel');
119-
} else {
120-
I18nHandler::getInstance()->save('buttonLabel', $this->buttonLabel, 'wcf.editor', 1);
121-
}
122-
}
123-
124109
// update bbcode
125110
$this->objectAction = new BBCodeAction([$this->bbcodeID], 'update', [
126111
'data' => \array_merge($this->additionalFields, [
127112
'bbcodeTag' => $this->bbcodeTag,
128-
'buttonLabel' => $this->buttonLabel,
129113
'className' => $this->className,
130114
'htmlClose' => $this->htmlClose,
131115
'htmlOpen' => $this->htmlOpen,
@@ -137,6 +121,8 @@ public function save()
137121
]);
138122
$this->objectAction->executeAction();
139123

124+
$this->saveButtonLabel($this->bbcodeID);
125+
140126
// clear existing attributes
141127
$sql = "DELETE FROM wcf1_bbcode_attribute
142128
WHERE bbcodeID = ?";
@@ -171,13 +157,18 @@ public function readData()
171157
parent::readData();
172158

173159
if (empty($_POST)) {
174-
I18nHandler::getInstance()->setOptions(
175-
'buttonLabel',
176-
1,
177-
$this->bbcode->buttonLabel,
178-
'wcf.editor.button.button\d+'
179-
);
180-
$this->buttonLabel = $this->bbcode->buttonLabel;
160+
$sql = "SELECT buttonLabel, languageID
161+
FROM wcf1_bbcode_content
162+
WHERE bbcodeID = ?";
163+
$statement = WCF::getDB()->prepare($sql);
164+
$statement->execute([$this->bbcodeID]);
165+
166+
$this->buttonLabel = $statement->fetchMap('languageID', 'buttonLabel');
167+
if (\count($this->buttonLabel) === 1) {
168+
$this->buttonLabel = \reset($this->buttonLabel);
169+
} elseif ($this->buttonLabel === []) {
170+
$this->buttonLabel = '';
171+
}
181172

182173
$this->attributes = BBCodeAttribute::getAttributesByBBCode($this->bbcode);
183174
$this->bbcodeTag = $this->bbcode->bbcodeTag;
@@ -198,8 +189,6 @@ public function assignVariables()
198189
{
199190
parent::assignVariables();
200191

201-
I18nHandler::getInstance()->assignVariables(!empty($_POST));
202-
203192
WCF::getTPL()->assign([
204193
'bbcode' => $this->bbcode,
205194
'action' => 'edit',

0 commit comments

Comments
 (0)