Skip to content

Commit b03b71d

Browse files
committed
Add multilingual support for button labels in XML schema and update BBCode-PIP
1 parent 9989701 commit b03b71d

File tree

3 files changed

+88
-28
lines changed

3 files changed

+88
-28
lines changed

XSD/bbcode.xsd

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,29 +32,29 @@
3232
<xs:complexType name="bbcode_delete">
3333
<xs:attribute name="name" type="woltlab_varchar" use="required" />
3434
</xs:complexType>
35-
36-
<xs:complexType name="bbcode_icon">
37-
<xs:simpleContent>
38-
<xs:extension base="woltlab_varchar">
39-
<xs:attribute name="solid" type="xs:boolean" />
40-
</xs:extension>
41-
</xs:simpleContent>
42-
</xs:complexType>
4335

4436
<!-- imported/updated page menu item element -->
4537
<xs:complexType name="bbcode_import">
4638
<xs:complexContent>
4739
<xs:extension base="bbcode_delete">
48-
<xs:all>
40+
<xs:choice maxOccurs="unbounded">
4941
<xs:element name="htmlopen" type="woltlab_varchar_nullable" minOccurs="0" />
5042
<xs:element name="htmlclose" type="woltlab_varchar_nullable" minOccurs="0" />
5143
<xs:element name="classname" type="woltlab_varchar_nullable" minOccurs="0" />
5244
<xs:element name="attributes" type="attributes_element" minOccurs="0" />
5345
<xs:element name="sourcecode" type="woltlab_boolean" minOccurs="0" />
54-
<xs:element name="wysiwygicon" type="bbcode_icon" minOccurs="0" />
55-
<xs:element name="buttonlabel" type="woltlab_varchar_nullable" minOccurs="0" />
46+
<xs:element name="buttonlabel" minOccurs="0" maxOccurs="unbounded">
47+
<xs:complexType>
48+
<xs:simpleContent>
49+
<xs:extension base="woltlab_varchar">
50+
<xs:attribute name="language" type="xs:string" use="optional" />
51+
</xs:extension>
52+
</xs:simpleContent>
53+
</xs:complexType>
54+
</xs:element>
55+
<xs:element name="wysiwygicon" type="woltlab_varchar" minOccurs="0" />
5656
<xs:element name="isBlockElement" type="woltlab_boolean" minOccurs="0" />
57-
</xs:all>
57+
</xs:choice>
5858
</xs:extension>
5959
</xs:complexContent>
6060
</xs:complexType>

com.woltlab.wcf/bbcode.xml

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/6.0/bbcode.xsd">
2+
<data xmlns="http://www.woltlab.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.woltlab.com http://www.woltlab.com/XSD/6.2/bbcode.xsd">
33
<import>
44
<bbcode name="b">
55
<htmlopen><![CDATA[b]]></htmlopen>
@@ -81,19 +81,21 @@
8181
</attributes>
8282
</bbcode>
8383
<bbcode name="quote">
84+
<buttonlabel language="de">Zitat</buttonlabel>
85+
<buttonlabel language="en">Quote</buttonlabel>
8486
<isBlockElement>1</isBlockElement>
85-
<buttonlabel>wcf.editor.button.quote</buttonlabel>
86-
<wysiwygicon solid="true">quote-left</wysiwygicon>
87+
<wysiwygicon>quote-left;true</wysiwygicon>
8788
<attributes>
8889
<attribute name="0"/>
8990
<attribute name="1"/>
9091
</attributes>
9192
</bbcode>
9293
<bbcode name="code">
94+
<buttonlabel language="de">Code</buttonlabel>
95+
<buttonlabel language="en">Code</buttonlabel>
9396
<isBlockElement>1</isBlockElement>
9497
<sourcecode>1</sourcecode>
95-
<buttonlabel>wcf.editor.button.code</buttonlabel>
96-
<wysiwygicon>code</wysiwygicon>
98+
<wysiwygicon>code;false</wysiwygicon>
9799
<attributes>
98100
<attribute name="0"/>
99101
<attribute name="1"/>
@@ -153,19 +155,21 @@
153155
</attributes>
154156
</bbcode>
155157
<bbcode name="spoiler">
158+
<buttonlabel language="de">Spoiler</buttonlabel>
159+
<buttonlabel language="en">Spoiler</buttonlabel>
156160
<isBlockElement>1</isBlockElement>
157-
<buttonlabel>wcf.editor.button.spoiler</buttonlabel>
158-
<wysiwygicon>eye-slash</wysiwygicon>
161+
<wysiwygicon>eye-slash;false</wysiwygicon>
159162
<attributes>
160163
<attribute name="0"/>
161164
</attributes>
162165
</bbcode>
163166
<bbcode name="tt">
167+
<buttonlabel language="de">Inline-Code</buttonlabel>
168+
<buttonlabel language="en">Inline-Code</buttonlabel>
164169
<htmlopen><![CDATA[kbd]]></htmlopen>
165170
<htmlclose><![CDATA[kbd]]></htmlclose>
166171
<sourcecode>1</sourcecode>
167-
<buttonlabel>wcf.editor.button.inlineCode</buttonlabel>
168-
<wysiwygicon>terminal</wysiwygicon>
172+
<wysiwygicon>terminal;true</wysiwygicon>
169173
</bbcode>
170174
<bbcode name="attach">
171175
<classname>wcf\system\bbcode\AttachmentBBCode</classname>
@@ -227,8 +231,9 @@
227231
<bbcode name="html">
228232
<isBlockElement>1</isBlockElement>
229233
<sourcecode>1</sourcecode>
230-
<buttonlabel>wcf.editor.button.woltlabHtml</buttonlabel>
231-
<wysiwygicon>file-code</wysiwygicon>
234+
<buttonlabel language="de">Unsicheres HTML</buttonlabel>
235+
<buttonlabel language="en">Unsafe HTML</buttonlabel>
236+
<wysiwygicon>file-code;false</wysiwygicon>
232237
</bbcode>
233238
<bbcode name="wsa">
234239
<classname>wcf\system\bbcode\WoltLabSuiteArticleBBCode</classname>

wcfsetup/install/files/lib/system/package/plugin/BBCodePackageInstallationPlugin.class.php

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use wcf\data\bbcode\BBCodeEditor;
88
use wcf\data\bbcode\BBCodeList;
99
use wcf\data\package\PackageCache;
10+
use wcf\system\bbcode\command\SaveContent;
1011
use wcf\system\bbcode\IBBCode;
1112
use wcf\system\database\util\PreparedStatementConditionBuilder;
1213
use wcf\system\devtools\pip\IDevtoolsPipEntryList;
@@ -27,6 +28,7 @@
2728
use wcf\system\form\builder\field\validation\FormFieldValidator;
2829
use wcf\system\form\builder\field\validation\FormFieldValidatorUtil;
2930
use wcf\system\form\builder\IFormDocument;
31+
use wcf\system\language\LanguageFactory;
3032
use wcf\system\WCF;
3133
use wcf\util\StringUtil;
3234

@@ -64,6 +66,11 @@ class BBCodePackageInstallationPlugin extends AbstractXMLPackageInstallationPlug
6466
*/
6567
protected $attributes = [];
6668

69+
/**
70+
* @var array<int, array<string, string>>
71+
*/
72+
protected array $buttonLabels = [];
73+
6774
/**
6875
* @inheritDoc
6976
*/
@@ -104,13 +111,22 @@ protected function getElement(\DOMXPath $xpath, array &$elements, \DOMElement $e
104111
$nodeValue[$attributeNo][$attributeValue->tagName] = $attributeValue->nodeValue;
105112
}
106113
}
107-
} elseif ($element->tagName === 'wysiwygicon' && !\str_contains($element->nodeValue, '.')) {
114+
} elseif ($element->tagName === 'wysiwygicon' && !\str_contains($element->nodeValue, '.') && !\str_contains($element->nodeValue, ';')) {
115+
// backwards compatibility
108116
$solid = $element->getAttribute('solid');
109117
$nodeValue = \sprintf(
110118
"%s;%s",
111119
$element->nodeValue,
112120
$solid === 'true' ? 'true' : 'false'
113121
);
122+
} elseif ($element->tagName === 'buttonlabel') {
123+
if (!isset($elements[$element->tagName])) {
124+
$elements[$element->tagName] = [];
125+
}
126+
127+
$elements[$element->tagName][$element->getAttribute('language') ?: ''] = $element->nodeValue;
128+
129+
return;
114130
}
115131

116132
$elements[$element->tagName] = $nodeValue;
@@ -130,7 +146,7 @@ protected function prepareImport(array $data)
130146
'className' => !empty($data['elements']['classname']) ? $data['elements']['classname'] : '',
131147
'isBlockElement' => !empty($data['elements']['isBlockElement']) ? 1 : 0,
132148
'isSourceCode' => !empty($data['elements']['sourcecode']) ? 1 : 0,
133-
'buttonLabel' => $data['elements']['buttonlabel'] ?? '',
149+
'buttonLabel' => $data['elements']['buttonlabel'] ?? [],
134150
'originIsSystem' => 1,
135151
];
136152

@@ -188,13 +204,15 @@ protected function import(array $row, array $data)
188204
{
189205
// extract attributes
190206
$attributes = $data['attributes'];
207+
$buttonLabel = $data['buttonLabel'] ?? [];
191208
unset($data['attributes']);
209+
unset($data['buttonLabel']);
192210

193211
if (!empty($row)) {
194212
// allow updating of all values except for those controlling the editor button
195213
unset($data['wysiwygIcon']);
196-
unset($data['buttonLabel']);
197214
unset($data['showButton']);
215+
unset($buttonLabel);
198216
}
199217

200218
/** @var BBCode $bbcode */
@@ -203,6 +221,10 @@ protected function import(array $row, array $data)
203221
// store attributes for later import
204222
$this->attributes[$bbcode->bbcodeID] = $attributes;
205223

224+
if (isset($buttonLabel) && $buttonLabel !== []) {
225+
$this->buttonLabels[$bbcode->bbcodeID] = $buttonLabel;
226+
}
227+
206228
return $bbcode;
207229
}
208230

@@ -238,6 +260,16 @@ protected function postImport()
238260
}
239261
}
240262
}
263+
264+
foreach ($this->buttonLabels as $bbcodeID => $buttonLabels) {
265+
$labels = [];
266+
foreach ($buttonLabels as $languageCode => $buttonLabel) {
267+
$languageID = $languageCode !== '' ? LanguageFactory::getInstance()->getLanguageByCode($languageCode)->languageID : 0;
268+
$labels[$languageID] = $buttonLabel;
269+
}
270+
271+
(new SaveContent($bbcodeID, $labels))();
272+
}
241273
}
242274

243275
/**
@@ -271,10 +303,18 @@ protected function fetchElementData(\DOMElement $element, $saveData)
271303
'bbcodeTag' => $element->getAttribute('name'),
272304
'packageID' => $this->installation->getPackage()->packageID,
273305
'originIsSystem' => 1,
306+
'buttonLabel' => [],
274307
];
275308

309+
/** @var \DOMElement $name */
310+
foreach ($element->getElementsByTagName('buttonlabel') as $name) {
311+
$langaugeCode = $name->getAttribute('language');
312+
$languageID = $langaugeCode !== '' ? LanguageFactory::getInstance()->getLanguageByCode($langaugeCode)->languageID : 0;
313+
314+
$data['buttonLabel'][$languageID] = $name->nodeValue;
315+
}
316+
276317
$optionalElements = [
277-
'buttonLabel' => 'buttonlabel',
278318
'className' => 'classname',
279319
'htmlClose' => 'htmlclose',
280320
'htmlOpen' => 'htmlopen',
@@ -467,6 +507,7 @@ protected function addFormFields(IFormDocument $form)
467507
->description('wcf.acp.pip.bbcode.buttonLabel.description')
468508
->required()
469509
->maximumLength(255)
510+
->i18n()
470511
->addDependency(
471512
NonEmptyFormFieldDependency::create('showButton')
472513
->fieldId('showButton')
@@ -555,11 +596,26 @@ protected function setEntryListKeys(IDevtoolsPipEntryList $entryList)
555596
*/
556597
protected function prepareXmlElement(\DOMDocument $document, IFormDocument $form)
557598
{
599+
$formData = $form->getData();
558600
$data = $form->getData()['data'];
559601

560602
$bbcode = $document->createElement($this->tagName);
561603
$bbcode->setAttribute('name', $data['name']);
562604

605+
if (isset($formData['buttonlabel'])) {
606+
foreach ($formData['buttonlabel'] as $languageID => $buttonLabel) {
607+
$buttonLabelElement = $document->createElement('buttonlabel', $this->getAutoCdataValue($buttonLabel));
608+
if ($languageID !== 0) {
609+
$buttonLabelElement->setAttribute(
610+
'language',
611+
LanguageFactory::getInstance()->getLanguage($languageID)->languageCode
612+
);
613+
}
614+
615+
$bbcode->appendChild($buttonLabelElement);
616+
}
617+
}
618+
563619
$this->appendElementChildren(
564620
$bbcode,
565621
[
@@ -574,7 +630,6 @@ protected function prepareXmlElement(\DOMDocument $document, IFormDocument $form
574630
],
575631
'isBlockElement' => 0,
576632
'sourcecode' => 0,
577-
'buttonlabel' => '',
578633
'wysiwygicon' => '',
579634
],
580635
$form

0 commit comments

Comments
 (0)