Skip to content

Commit

Permalink
update html input processor bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanashi committed Aug 8, 2024
1 parent 6fdc6c7 commit 79d8bf7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 66 deletions.
22 changes: 11 additions & 11 deletions files/lib/acp/form/FaqQuestionAddForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use wcf\system\form\builder\field\SingleSelectionFormField;
use wcf\system\form\builder\field\TextFormField;
use wcf\system\form\builder\IFormDocument;
use wcf\system\html\input\HtmlInputProcessor;
use wcf\system\language\LanguageFactory;
use wcf\system\request\IRouteController;
use wcf\system\request\LinkHandler;
Expand Down Expand Up @@ -59,8 +60,6 @@ class FaqQuestionAddForm extends AbstractFormBuilderForm

protected $isMultilingual = 0;

protected $multiLingualAnswers = [];

/**
* @inheritDoc
*/
Expand Down Expand Up @@ -185,20 +184,21 @@ public function buildForm()
static function (IFormDocument $document, array $parameters) {
foreach ($parameters['data'] as $key => $val) {
if (\str_starts_with($key, 'answer_i18n_')) {
$languageID = (int)\substr($key, 12);
$parameters['answer_i18n'][$languageID] = $val;
unset($parameters['data'][$key]);
}
}

return $parameters;
},
function (IFormDocument $document, array $data, IStorableObject $object) {
foreach ($this->multiLingualAnswers as $languageID => $answer) {
$data['answer_i18n_' . $languageID] = $answer;
foreach ($parameters as $key => $val) {
if (
\str_starts_with($key, 'answer_i18n')
&& \str_ends_with($key, 'htmlInputProcessor')
&& $val instanceof HtmlInputProcessor
) {
$parts = \explode('_', $key);
$parameters['answer_i18n'][(int)$parts[2]] = $val->getHtml();
}
}

return $data;
return $parameters;
}
));
}
Expand Down
75 changes: 22 additions & 53 deletions files/lib/data/faq/QuestionAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,7 @@ public function create()
{
//prepare answer
if (isset($this->parameters['answer_i18n'])) {
$answers = '';
foreach ($this->parameters['answer_i18n'] as $languageID => $answer) {
$processor = new HtmlInputProcessor();
$processor->process($answer, 'dev.tkirch.wsc.faq.question', 0);
$this->parameters['answer_i18n'][$languageID] = $processor->getHtml();
$answers .= $answer;
}
$inputProcessor = new HtmlInputProcessor();
$inputProcessor->process($answers, 'dev.tkirch.wsc.faq.question', 0);
$this->parameters['data']['isMultilingual'] = 1;
} else {
$inputProcessor = new HtmlInputProcessor();
$inputProcessor->process($this->parameters['data']['answer'], 'dev.tkirch.wsc.faq.question', 0);
$this->parameters['data']['answer'] = $inputProcessor->getHtml();
}

//get question
Expand Down Expand Up @@ -91,20 +78,17 @@ public function create()
$this->updateSearchIndex($question);

foreach ($this->parameters as $parameter) {
if (!($parameter instanceof AttachmentHandler)) {
continue;
}
$parameter->updateObjectID($question->questionID);
}

if (!empty($inputProcessor)) {
$inputProcessor->setObjectID($question->questionID);
if (
MessageEmbeddedObjectManager::getInstance()->registerObjects(
$inputProcessor
)
) {
$updateData['hasEmbeddedObjects'] = 1;
if ($parameter instanceof AttachmentHandler) {
$parameter->updateObjectID($question->questionID);
} elseif ($parameter instanceof HtmlInputProcessor) {
$parameter->setObjectID($question->questionID);
if (
MessageEmbeddedObjectManager::getInstance()->registerObjects(
$parameter
)
) {
$updateData['hasEmbeddedObjects'] = 1;
}
}
}

Expand Down Expand Up @@ -132,20 +116,7 @@ public function update()

//prepare answer
if (isset($this->parameters['answer_i18n'])) {
$answers = '';
foreach ($this->parameters['answer_i18n'] as $languageID => $answer) {
$processor = new HtmlInputProcessor();
$processor->process($answer, 'dev.tkirch.wsc.faq.question', 0);
$this->parameters['answer_i18n'][$languageID] = $processor->getHtml();
$answers .= $answer;
}
$inputProcessor = new HtmlInputProcessor();
$inputProcessor->process($answers, 'dev.tkirch.wsc.faq.question', 0);
$this->parameters['data']['isMultilingual'] = 1;
} else {
$inputProcessor = new HtmlInputProcessor();
$inputProcessor->process($this->parameters['data']['answer'], 'dev.tkirch.wsc.faq.question', 0);
$this->parameters['data']['answer'] = $inputProcessor->getHtml();
}

parent::update();
Expand Down Expand Up @@ -202,20 +173,18 @@ public function update()
}

foreach ($this->parameters as $parameter) {
if (!($parameter instanceof AttachmentHandler)) {
continue;
if ($parameter instanceof AttachmentHandler) {
$parameter->updateObjectID($object->questionID);
} elseif ($parameter instanceof HtmlInputProcessor) {
$parameter->setObjectID($object->questionID);
if (
$object->hasEmbeddedObjects != MessageEmbeddedObjectManager::getInstance()->registerObjects(
$parameter
)
) {
$updateData['hasEmbeddedObjects'] = $object->hasEmbeddedObjects ? 0 : 1;
}
}
$parameter->updateObjectID($object->questionID);
}

$inputProcessor->setObjectID($object->questionID);

if (
$object->hasEmbeddedObjects != MessageEmbeddedObjectManager::getInstance()->registerObjects(
$inputProcessor
)
) {
$updateData['hasEmbeddedObjects'] = $object->hasEmbeddedObjects ? 0 : 1;
}

if (!empty($updateData)) {
Expand Down
4 changes: 2 additions & 2 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<packagedescription>A simple and powerful FAQ for your WSC.</packagedescription>
<packagedescription language="de">Ein simples und leistungsstarkes FAQ für Ihr WSC.</packagedescription>
<version>2.1.2</version>
<date>2024-04-15</date>
<date>2024-08-09</date>
</packageinformation>
<authorinformation>
<author>Hanashi Development, Titus Kirch</author>
<authorurl>https://hanashi.dev</authorurl>
</authorinformation>
<requiredpackages>
<requiredpackage minversion="6.0.11">com.woltlab.wcf</requiredpackage>
<requiredpackage minversion="6.0.16">com.woltlab.wcf</requiredpackage>
</requiredpackages>
<excludedpackages>
<excludedpackage version="6.1.0 Alpha 1">com.woltlab.wcf</excludedpackage>
Expand Down

0 comments on commit 79d8bf7

Please sign in to comment.