From: Matthias Schmidt Date: Tue, 15 Jun 2021 13:10:55 +0000 (+0200) Subject: Merge branch '5.3' into 5.4 X-Git-Tag: 5.4.0_Beta_2~11 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=775fe735a67a7917e3ce0155fe1f9380d3c9548a;p=GitHub%2FWoltLab%2FWCF.git Merge branch '5.3' into 5.4 --- 775fe735a67a7917e3ce0155fe1f9380d3c9548a diff --cc wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygAttachmentFormField.class.php index 6544ca372c,ceb9b29b23..6141872e97 --- a/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygAttachmentFormField.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/field/wysiwyg/WysiwygAttachmentFormField.class.php @@@ -12,149 -10,143 +12,151 @@@ use wcf\util\StringUtil /** * Represents the form field to manage attachments for a wysiwyg form container. - * + * * If no attachment handler has been set, this field is not available. - * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @package WoltLabSuite\Core\System\Form\Builder\Field\Wysiwyg - * @since 5.2 + * + * @author Matthias Schmidt + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @package WoltLabSuite\Core\System\Form\Builder\Field\Wysiwyg + * @since 5.2 */ -class WysiwygAttachmentFormField extends AbstractFormField { - use TWysiwygFormNode; - - /** - * attachment handler - * @var null|AttachmentHandler - */ - protected $attachmentHandler; - - /** - * @inheritDoc - */ - protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/Wysiwyg/Attachment'; - - /** - * @inheritDoc - */ - protected $templateName = '__wysiwygAttachmentFormField'; - - /** - * Creates a new instance of `WysiwygAttachmentFormField`. - */ - public function __construct() { - $this->addClass('wide'); - } - - /** - * Sets the attachment handler object for the uploaded attachments. If `null` is given, - * the previously set attachment handler is unset. - * - * For the initial attachment handler set by this method, the temporary hashes will be - * automatically set by either reading them from the session variables if the form handles - * AJAX requests or by creating a new one. If the temporary hashes are read from session, - * the session variable will be unregistered afterwards. - * - * @param null|AttachmentHandler $attachmentHandler - * @return WysiwygAttachmentFormField - */ - public function attachmentHandler(AttachmentHandler $attachmentHandler = null) { - if ($attachmentHandler !== null) { - if ($this->attachmentHandler === null) { - $tmpHash = StringUtil::getRandomID(); - if ($this->getDocument()->isAjax()) { - $sessionTmpHash = WCF::getSession()->getVar('__wcfAttachmentTmpHash'); - if ($sessionTmpHash !== null) { - $tmpHash = $sessionTmpHash; - - WCF::getSession()->unregister('__wcfAttachmentTmpHash'); - } - } - - $attachmentHandler->setTmpHashes([$tmpHash]); - } - else { - // preserve temporary hashes - $attachmentHandler->setTmpHashes($this->attachmentHandler->getTmpHashes()); - } - } - - $this->attachmentHandler = $attachmentHandler; - - if ($this->attachmentHandler !== null) { - $this->description('wcf.attachment.upload.limits', [ - 'attachmentHandler' => $this->attachmentHandler - ]); - } - else { - $this->description(); - } - - return $this; - } - - /** - * Returns the attachment handler object for the uploaded attachments or `null` if no attachment - * upload is supported. - * - * @return null|AttachmentHandler - */ - public function getAttachmentHandler() { - return $this->attachmentHandler; - } - - /** - * @inheritDoc - */ - public function hasSaveValue() { - return false; - } - - /** - * @inheritDoc - */ - public function isAvailable() { - return parent::isAvailable() - && $this->getAttachmentHandler() !== null - && $this->getAttachmentHandler()->canUpload(); - } - - /** - * @inheritDoc - */ - public function populate() { - parent::populate(); - - $this->getDocument()->getDataHandler()->addProcessor(new CustomFormDataProcessor($this->getId(), function(IFormDocument $document, array $parameters) { - if ($this->getAttachmentHandler() !== null) { - $parameters[$this->getWysiwygId() . '_attachmentHandler'] = $this->getAttachmentHandler(); - } - - return $parameters; - })); - - return $this; - } - - /** - * @inheritDoc - */ - public function readValue() { - if ($this->getDocument()->hasRequestData($this->getPrefixedId() . '_tmpHash')) { - $tmpHash = $this->getDocument()->getRequestData($this->getPrefixedId() . '_tmpHash'); - if (is_string($tmpHash)) { - $this->getAttachmentHandler()->setTmpHashes([$tmpHash]); - } - else if (is_array($tmpHash)) { - $this->getAttachmentHandler()->setTmpHashes($tmpHash); - } - } - } +class WysiwygAttachmentFormField extends AbstractFormField +{ + use TWysiwygFormNode; + + /** + * attachment handler + * @var null|AttachmentHandler + */ + protected $attachmentHandler; + + /** + * @inheritDoc + */ + protected $javaScriptDataHandlerModule = 'WoltLabSuite/Core/Form/Builder/Field/Wysiwyg/Attachment'; + + /** + * @inheritDoc + */ + protected $templateName = '__wysiwygAttachmentFormField'; + + /** + * Creates a new instance of `WysiwygAttachmentFormField`. + */ + public function __construct() + { + $this->addClass('wide'); + } + + /** + * Sets the attachment handler object for the uploaded attachments. If `null` is given, + * the previously set attachment handler is unset. + * + * For the initial attachment handler set by this method, the temporary hashes will be + * automatically set by either reading them from the session variables if the form handles + * AJAX requests or by creating a new one. If the temporary hashes are read from session, + * the session variable will be unregistered afterwards. + * + * @param null|AttachmentHandler $attachmentHandler + * @return WysiwygAttachmentFormField + */ + public function attachmentHandler(?AttachmentHandler $attachmentHandler = null) + { + if ($attachmentHandler !== null) { + if ($this->attachmentHandler === null) { + $tmpHash = StringUtil::getRandomID(); + if ($this->getDocument()->isAjax()) { + $sessionTmpHash = WCF::getSession()->getVar('__wcfAttachmentTmpHash'); + if ($sessionTmpHash !== null) { + $tmpHash = $sessionTmpHash; + + WCF::getSession()->unregister('__wcfAttachmentTmpHash'); + } + } + + $attachmentHandler->setTmpHashes([$tmpHash]); + } else { + // preserve temporary hashes + $attachmentHandler->setTmpHashes($this->attachmentHandler->getTmpHashes()); + } + } + + $this->attachmentHandler = $attachmentHandler; + + if ($this->attachmentHandler !== null) { + $this->description('wcf.attachment.upload.limits', [ + 'attachmentHandler' => $this->attachmentHandler, + ]); + } else { + $this->description(); + } + + return $this; + } + + /** + * Returns the attachment handler object for the uploaded attachments or `null` if no attachment + * upload is supported. + * + * @return null|AttachmentHandler + */ + public function getAttachmentHandler() + { + return $this->attachmentHandler; + } + + /** + * @inheritDoc + */ + public function hasSaveValue() + { + return false; + } + + /** + * @inheritDoc + */ + public function isAvailable() + { - return parent::isAvailable() && $this->getAttachmentHandler() !== null; ++ return parent::isAvailable() ++ && $this->getAttachmentHandler() !== null ++ && $this->getAttachmentHandler()->canUpload(); + } + + /** + * @inheritDoc + */ + public function populate() + { + parent::populate(); + + $this->getDocument()->getDataHandler()->addProcessor(new CustomFormDataProcessor( + $this->getId(), + function (IFormDocument $document, array $parameters) { + if ($this->getAttachmentHandler() !== null) { + $parameters[$this->getWysiwygId() . '_attachmentHandler'] = $this->getAttachmentHandler(); + } + + return $parameters; + } + )); + + return $this; + } + + /** + * @inheritDoc + */ + public function readValue() + { + if ($this->getDocument()->hasRequestData($this->getPrefixedId() . '_tmpHash')) { + $tmpHash = $this->getDocument()->getRequestData($this->getPrefixedId() . '_tmpHash'); + if (\is_string($tmpHash)) { + $this->getAttachmentHandler()->setTmpHashes([$tmpHash]); + } elseif (\is_array($tmpHash)) { + $this->getAttachmentHandler()->setTmpHashes($tmpHash); + } + } + } }