Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions XSD/bbcode.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,29 @@
<xs:complexType name="bbcode_delete">
<xs:attribute name="name" type="woltlab_varchar" use="required" />
</xs:complexType>

<xs:complexType name="bbcode_icon">
<xs:simpleContent>
<xs:extension base="woltlab_varchar">
<xs:attribute name="solid" type="xs:boolean" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>

<!-- imported/updated page menu item element -->
<xs:complexType name="bbcode_import">
<xs:complexContent>
<xs:extension base="bbcode_delete">
<xs:all>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks incorrect because those other elements are not supposed to appear multiple times?

<xs:choice maxOccurs="unbounded">
<xs:element name="htmlopen" type="woltlab_varchar_nullable" minOccurs="0" />
<xs:element name="htmlclose" type="woltlab_varchar_nullable" minOccurs="0" />
<xs:element name="classname" type="woltlab_varchar_nullable" minOccurs="0" />
<xs:element name="attributes" type="attributes_element" minOccurs="0" />
<xs:element name="sourcecode" type="woltlab_boolean" minOccurs="0" />
<xs:element name="wysiwygicon" type="bbcode_icon" minOccurs="0" />
<xs:element name="buttonlabel" type="woltlab_varchar_nullable" minOccurs="0" />
<xs:element name="buttonlabel" minOccurs="0" maxOccurs="unbounded">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="woltlab_varchar">
<xs:attribute name="language" type="xs:string" use="optional" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
<xs:element name="wysiwygicon" type="woltlab_varchar" minOccurs="0" />
<xs:element name="isBlockElement" type="woltlab_boolean" minOccurs="0" />
</xs:all>
</xs:choice>
</xs:extension>
</xs:complexContent>
</xs:complexType>
Expand Down
27 changes: 16 additions & 11 deletions com.woltlab.wcf/bbcode.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<import>
<bbcode name="b">
<htmlopen><![CDATA[b]]></htmlopen>
Expand Down Expand Up @@ -81,19 +81,21 @@
</attributes>
</bbcode>
<bbcode name="quote">
<buttonlabel language="de">Zitat</buttonlabel>
<buttonlabel language="en">Quote</buttonlabel>
<isBlockElement>1</isBlockElement>
<buttonlabel>wcf.editor.button.quote</buttonlabel>
<wysiwygicon solid="true">quote-left</wysiwygicon>
<wysiwygicon>quote-left;true</wysiwygicon>
<attributes>
<attribute name="0"/>
<attribute name="1"/>
</attributes>
</bbcode>
<bbcode name="code">
<buttonlabel language="de">Code</buttonlabel>
<buttonlabel language="en">Code</buttonlabel>
<isBlockElement>1</isBlockElement>
<sourcecode>1</sourcecode>
<buttonlabel>wcf.editor.button.code</buttonlabel>
<wysiwygicon>code</wysiwygicon>
<wysiwygicon>code;false</wysiwygicon>
<attributes>
<attribute name="0"/>
<attribute name="1"/>
Expand Down Expand Up @@ -153,19 +155,21 @@
</attributes>
</bbcode>
<bbcode name="spoiler">
<buttonlabel language="de">Spoiler</buttonlabel>
<buttonlabel language="en">Spoiler</buttonlabel>
<isBlockElement>1</isBlockElement>
<buttonlabel>wcf.editor.button.spoiler</buttonlabel>
<wysiwygicon>eye-slash</wysiwygicon>
<wysiwygicon>eye-slash;false</wysiwygicon>
<attributes>
<attribute name="0"/>
</attributes>
</bbcode>
<bbcode name="tt">
<buttonlabel language="de">Inline-Code</buttonlabel>
<buttonlabel language="en">Inline-Code</buttonlabel>
<htmlopen><![CDATA[kbd]]></htmlopen>
<htmlclose><![CDATA[kbd]]></htmlclose>
<sourcecode>1</sourcecode>
<buttonlabel>wcf.editor.button.inlineCode</buttonlabel>
<wysiwygicon>terminal</wysiwygicon>
<wysiwygicon>terminal;true</wysiwygicon>
</bbcode>
<bbcode name="attach">
<classname>wcf\system\bbcode\AttachmentBBCode</classname>
Expand Down Expand Up @@ -227,8 +231,9 @@
<bbcode name="html">
<isBlockElement>1</isBlockElement>
<sourcecode>1</sourcecode>
<buttonlabel>wcf.editor.button.woltlabHtml</buttonlabel>
<wysiwygicon>file-code</wysiwygicon>
<buttonlabel language="de">Unsicheres HTML</buttonlabel>
<buttonlabel language="en">Unsafe HTML</buttonlabel>
<wysiwygicon>file-code;false</wysiwygicon>
</bbcode>
<bbcode name="wsa">
<classname>wcf\system\bbcode\WoltLabSuiteArticleBBCode</classname>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,30 @@
->referencedColumns(['languageID'])
->onDelete('CASCADE'),
]),
DatabaseTable::create('wcf1_bbcode_content')
->columns([
ObjectIdDatabaseTableColumn::create('contentID'),
IntDatabaseTableColumn::create('bbcodeID')
->notNull(),
IntDatabaseTableColumn::create('languageID'),
NotNullVarchar255DatabaseTableColumn::create('buttonLabel'),
])
->indices([
DatabaseTablePrimaryIndex::create()
->columns(['contentID']),
DatabaseTableIndex::create('id')
->columns(['bbcodeID', 'languageID']),
])
->foreignKeys([
DatabaseTableForeignKey::create()
->columns(['bbcodeID'])
->referencedTable('wcf1_bbcode')
->referencedColumns(['bbcodeID'])
->onDelete('CASCADE'),
DatabaseTableForeignKey::create()
->columns(['languageID'])
->referencedTable('wcf1_language')
->referencedColumns(['languageID'])
->onDelete('CASCADE'),
]),
];
2 changes: 1 addition & 1 deletion wcfsetup/install/files/acp/templates/bbcodeAdd.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
<dl class="jsButtonSetting{if $errorField == 'buttonLabel'} formError{/if}">
<dt><label for="buttonLabel">{lang}wcf.acp.bbcode.buttonLabel{/lang}</label></dt>
<dd>
<input type="text" id="buttonLabel" name="buttonLabel" value="{$i18nPlainValues['buttonLabel']}" class="long">
<input type="text" id="buttonLabel" name="buttonLabel" value="{if !$buttonLabel|is_array}{$buttonLabel}{/if}" class="long">
{if $errorField == 'buttonLabel'}
<small class="innerError">
{if $errorType == 'empty'}
Expand Down
49 changes: 49 additions & 0 deletions wcfsetup/install/files/acp/update_com.woltlab.wcf_6.2_bbcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\language\LanguageFactory;
use wcf\system\WCF;

$sql = "SELECT bbcodeID, buttonLabel
FROM wcf1_bbcode
WHERE showButton = ?
OR buttonLabel <> ''";
$statement = WCF::getDB()->prepare($sql);
$statement->execute([1]);
$buttonLabels = $statement->fetchMap('bbcodeID', 'buttonLabel');

$sql = "INSERT INTO wcf1_bbcode_content
(bbcodeID, languageID, buttonLabel)
VALUES (?, ?, ?)";
$statement = WCF::getDB()->prepare($sql);

$languageItems = [];
foreach ($buttonLabels as $bbcodeID => $buttonLabel) {
if (\preg_match('~^\w+(\.\w+){2,}$~', $buttonLabel, $matches)) {
$languageItems[] = $buttonLabel;

foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
$statement->execute([
$bbcodeID,
$language->languageID,
$language->get($buttonLabel),
]);
}
} else {
$statement->execute([
$bbcodeID,
LanguageFactory::getInstance()->getDefaultLanguageID(),
$buttonLabel,
]);
}
}

if ($languageItems !== []) {
$conditionBuilder = new PreparedStatementConditionBuilder();
$conditionBuilder->add('languageItem IN (?)', [$languageItems]);

$sql = "DELETE FROM wcf1_language_item
{$conditionBuilder}";
$statement = WCF::getDB()->prepare($sql);
$statement->execute($conditionBuilder->getParameters());
}
74 changes: 36 additions & 38 deletions wcfsetup/install/files/lib/acp/form/BBCodeAddForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
use wcf\data\bbcode\attribute\BBCodeAttributeAction;
use wcf\data\bbcode\BBCode;
use wcf\data\bbcode\BBCodeAction;
use wcf\data\bbcode\BBCodeEditor;
use wcf\form\AbstractForm;
use wcf\system\bbcode\command\SaveContent;
use wcf\system\exception\UserInputException;
use wcf\system\language\I18nHandler;
use wcf\system\language\LanguageFactory;
use wcf\system\Regex;
use wcf\system\request\LinkHandler;
use wcf\system\WCF;
use wcf\util\ArrayUtil;
use wcf\util\StringUtil;

/**
Expand Down Expand Up @@ -42,7 +43,8 @@ class BBCodeAddForm extends AbstractForm

/**
* editor button label
* @var string
*
* @var string|string[]
*/
public $buttonLabel = '';

Expand Down Expand Up @@ -98,16 +100,6 @@ class BBCodeAddForm extends AbstractForm
*/
public $wysiwygIcon = '';

/**
* @inheritDoc
*/
public function readParameters()
{
parent::readParameters();

I18nHandler::getInstance()->register('buttonLabel');
}

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -151,7 +143,6 @@ public function readFormParameters()
$this->attributes[$key] = (object)$val;
}

I18nHandler::getInstance()->readValues();
$this->readButtonLabelFormParameter();
}

Expand All @@ -162,8 +153,10 @@ public function readFormParameters()
*/
protected function readButtonLabelFormParameter()
{
if (I18nHandler::getInstance()->isPlainValue('buttonLabel')) {
$this->buttonLabel = I18nHandler::getInstance()->getValue('buttonLabel');
if (isset($_POST['buttonLabel_i18n']) && \is_array($_POST['buttonLabel_i18n'])) {
$this->buttonLabel = ArrayUtil::trim($_POST['buttonLabel_i18n']);
} elseif (isset($_POST['buttonLabel'])) {
$this->buttonLabel = StringUtil::trim($_POST['buttonLabel']);
}
}

Expand Down Expand Up @@ -208,12 +201,14 @@ public function validate()
// button
if ($this->showButton) {
// validate label
if (!I18nHandler::getInstance()->validateValue('buttonLabel')) {
if (I18nHandler::getInstance()->isPlainValue('buttonLabel')) {
throw new UserInputException('buttonLabel');
} else {
throw new UserInputException('buttonLabel', 'multilingual');
if (\is_array($this->buttonLabel)) {
foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
if (empty($this->buttonLabel[$language->languageID])) {
throw new UserInputException('buttonLabel', 'multilingual');
}
}
} elseif ($this->buttonLabel === '') {
throw new UserInputException('buttonLabel');
}

// validate image path
Expand Down Expand Up @@ -250,7 +245,6 @@ public function save()
$this->objectAction = new BBCodeAction([], 'create', [
'data' => \array_merge($this->additionalFields, [
'bbcodeTag' => $this->bbcodeTag,
'buttonLabel' => $this->buttonLabel,
'className' => $this->className,
'htmlOpen' => $this->htmlOpen,
'htmlClose' => $this->htmlClose,
Expand All @@ -262,10 +256,14 @@ public function save()
]),
]);
$returnValues = $this->objectAction->executeAction();
$bbcodeID = $returnValues['returnValues']->bbcodeID;

$this->saveButtonLabel($bbcodeID);

foreach ($this->attributes as $attribute) {
$attributeAction = new BBCodeAttributeAction([], 'create', [
'data' => [
'bbcodeID' => $returnValues['returnValues']->bbcodeID,
'bbcodeID' => $bbcodeID,
'attributeNo' => $attribute->attributeNo,
'attributeHtml' => $attribute->attributeHtml,
'validationPattern' => $attribute->validationPattern,
Expand All @@ -276,26 +274,13 @@ public function save()
$attributeAction->executeAction();
}

if ($this->showButton && !I18nHandler::getInstance()->isPlainValue('buttonLabel')) {
$bbcodeID = $returnValues['returnValues']->bbcodeID;
I18nHandler::getInstance()->save('buttonLabel', 'wcf.editor.button.button' . $bbcodeID, 'wcf.editor', 1);

// update button label
$bbcodeEditor = new BBCodeEditor($returnValues['returnValues']);
$bbcodeEditor->update([
'buttonLabel' => 'wcf.editor.button.button' . $bbcodeID,
]);
}

$this->saved();

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

I18nHandler::getInstance()->reset();

// show success message
WCF::getTPL()->assign([
'success' => true,
Expand All @@ -313,13 +298,13 @@ public function assignVariables()
{
parent::assignVariables();

I18nHandler::getInstance()->assignVariables();

WCF::getTPL()->assign([
'action' => 'add',
'attributes' => $this->attributes,
'bbcodeTag' => $this->bbcodeTag,
'buttonLabel' => $this->buttonLabel,
'availableLanguages' => LanguageFactory::getInstance()->getLanguages(),
'i18nValues' => ['buttonLabel' => \is_array($this->buttonLabel) ? $this->buttonLabel : []],
'className' => $this->className,
'htmlOpen' => $this->htmlOpen,
'htmlClose' => $this->htmlClose,
Expand All @@ -329,4 +314,17 @@ public function assignVariables()
'wysiwygIcon' => $this->wysiwygIcon,
]);
}

protected function saveButtonLabel(int $bbcodeID): void
{
if ($this->showButton) {
if (\is_array($this->buttonLabel)) {
$buttonLabels = $this->buttonLabel;
} else {
$buttonLabels = [0 => $this->buttonLabel];
}

(new SaveContent($bbcodeID, $buttonLabels))();
}
}
}
Loading