From: joshuaruesweg Date: Sun, 8 Nov 2020 11:09:43 +0000 (+0100) Subject: Add labeledUrl user option type X-Git-Tag: 5.4.0_Alpha_1~604^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=b1ffe40c4f251ff3d0ef4a377b250227386c3abf;p=GitHub%2FWoltLab%2FWCF.git Add labeledUrl user option type Closes #3651 --- diff --git a/wcfsetup/install/files/acp/templates/userOptionAdd.tpl b/wcfsetup/install/files/acp/templates/userOptionAdd.tpl index 01c50aed84..37eeb263ec 100644 --- a/wcfsetup/install/files/acp/templates/userOptionAdd.tpl +++ b/wcfsetup/install/files/acp/templates/userOptionAdd.tpl @@ -139,6 +139,23 @@ + +
+
+ + {if $errorField == 'labeledUrl'} + + {if $errorType == 'empty'} + {lang}wcf.global.form.error.empty{/lang} + {else} + {lang}wcf.acp.user.option.labeledUrl.error.{@$errorType}{/lang} + {/if} + + {/if} + {lang}wcf.acp.user.option.labeledUrl.description{/lang} +
+ +
diff --git a/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php b/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php index 231b16ccce..b01e20792d 100644 --- a/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserOptionAddForm.class.php @@ -9,6 +9,7 @@ use wcf\form\AbstractForm; use wcf\system\exception\UserInputException; use wcf\system\language\I18nHandler; use wcf\system\option\user\DateUserOptionOutput; +use wcf\system\option\user\LabeledUrlUserOptionOutput; use wcf\system\option\user\SelectOptionsUserOptionOutput; use wcf\system\option\user\URLUserOptionOutput; use wcf\system\request\LinkHandler; @@ -76,6 +77,12 @@ class UserOptionAddForm extends AbstractForm { */ public $selectOptions = ''; + /** + * @var string + * @since 5.4 + */ + public $labeledUrl = ''; + /** * field is required * @var boolean @@ -154,7 +161,8 @@ class UserOptionAddForm extends AbstractForm { 'text', 'textarea', 'message', - 'URL' + 'URL', + 'labeledUrl', ]; /** @@ -206,6 +214,7 @@ class UserOptionAddForm extends AbstractForm { if (isset($_POST['searchable'])) $this->searchable = intval($_POST['searchable']); if (isset($_POST['showOrder'])) $this->showOrder = intval($_POST['showOrder']); if (isset($_POST['outputClass'])) $this->outputClass = StringUtil::trim($_POST['outputClass']); + if (isset($_POST['labeledUrl'])) $this->labeledUrl = StringUtil::trim($_POST['labeledUrl']); if ($this->optionType == 'boolean' || $this->optionType == 'integer') { $this->defaultValue = intval($this->defaultValue); @@ -238,6 +247,10 @@ class UserOptionAddForm extends AbstractForm { if ($this->optionType == 'URL') { $this->outputClass = URLUserOptionOutput::class; } + + if ($this->optionType == 'labeledUrl') { + $this->outputClass = LabeledUrlUserOptionOutput::class; + } } } @@ -282,6 +295,10 @@ class UserOptionAddForm extends AbstractForm { if (!in_array($this->editable, $this->validEditableBits)) { $this->editable = UserOption::EDITABILITY_ALL; } + + if ($this->optionType == 'labeledUrl' && strpos($this->labeledUrl, '%s') === false) { + throw new UserInputException('labeledUrl', 'invalid'); + } } /** @@ -309,7 +326,8 @@ class UserOptionAddForm extends AbstractForm { 'editable' => $this->editable, 'visible' => $this->visible, 'packageID' => 1, - 'additionalData' => !empty($additionalData) ? serialize($additionalData) : '' + 'additionalData' => !empty($additionalData) ? serialize($additionalData) : '', + 'labeledUrl' => $this->labeledUrl, ])]); $this->objectAction->executeAction(); @@ -366,7 +384,8 @@ class UserOptionAddForm extends AbstractForm { 'outputClass' => $this->outputClass, 'action' => 'add', 'availableCategories' => $this->availableCategories, - 'availableOptionTypes' => self::$availableOptionTypes + 'availableOptionTypes' => self::$availableOptionTypes, + 'labeledUrl' => $this->labeledUrl, ]); } } diff --git a/wcfsetup/install/files/lib/acp/form/UserOptionEditForm.class.php b/wcfsetup/install/files/lib/acp/form/UserOptionEditForm.class.php index 1c05d541b9..340b3fa018 100644 --- a/wcfsetup/install/files/lib/acp/form/UserOptionEditForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/UserOptionEditForm.class.php @@ -89,7 +89,8 @@ class UserOptionEditForm extends UserOptionAddForm { 'searchable' => $this->searchable, 'editable' => $this->editable, 'visible' => $this->visible, - 'additionalData' => !empty($additionalData) ? serialize($additionalData) : '' + 'additionalData' => !empty($additionalData) ? serialize($additionalData) : '', + 'labeledUrl' => $this->labeledUrl, ])]); $this->objectAction->executeAction(); $this->saved(); @@ -119,6 +120,7 @@ class UserOptionEditForm extends UserOptionAddForm { $this->searchable = $this->userOption->searchable; $this->showOrder = $this->userOption->showOrder; $this->outputClass = $this->userOption->outputClass; + $this->labeledUrl = $this->userOption->labeledUrl; } } diff --git a/wcfsetup/install/files/lib/data/user/option/UserOption.class.php b/wcfsetup/install/files/lib/data/user/option/UserOption.class.php index c4731bb8d1..ac5c8a1e5f 100644 --- a/wcfsetup/install/files/lib/data/user/option/UserOption.class.php +++ b/wcfsetup/install/files/lib/data/user/option/UserOption.class.php @@ -22,6 +22,7 @@ use wcf\system\WCF; * @property-read integer $searchable is `1` if the user option can be searched, otherwise `0` * @property-read integer $isDisabled is `1` if the user option is disabled and thus neither shown nor editable, otherwise `0` * @property-read integer $originIsSystem is `1` if the user option was created by the system and not manually by an administrator, otherwise `0` + * @property-read string $labeledUrl the url, if the option type is `labeledUrl` */ class UserOption extends Option implements ITitledObject { /** diff --git a/wcfsetup/install/files/lib/system/option/LabeledUrlOptionType.class.php b/wcfsetup/install/files/lib/system/option/LabeledUrlOptionType.class.php new file mode 100644 index 0000000000..f461045916 --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/LabeledUrlOptionType.class.php @@ -0,0 +1,12 @@ + + * @package WoltLabSuite\Core\System\Option + * @since 5.4 + */ +class LabeledUrlOptionType extends TextOptionType { } diff --git a/wcfsetup/install/files/lib/system/option/user/LabeledUrlUserOptionOutput.class.php b/wcfsetup/install/files/lib/system/option/user/LabeledUrlUserOptionOutput.class.php new file mode 100644 index 0000000000..d91a104c1e --- /dev/null +++ b/wcfsetup/install/files/lib/system/option/user/LabeledUrlUserOptionOutput.class.php @@ -0,0 +1,30 @@ + + * @package WoltLabSuite\Core\System\Option\User + * @since 5.4 + */ +class LabeledUrlUserOptionOutput implements IUserOptionOutput { + /** + * @inheritDoc + */ + public function getOutput(User $user, UserOption $option, $value) { + return StringUtil::getAnchorTag(self::getURL($option, $value), $value, true, true); + } + + /** + * Formats the URL. + */ + private static function getURL(UserOption $option, string $value): string { + return sprintf($option->labeledUrl, rawurlencode($value)); + } +} diff --git a/wcfsetup/install/lang/de.xml b/wcfsetup/install/lang/de.xml index 97ceff7f38..73829ea4ec 100644 --- a/wcfsetup/install/lang/de.xml +++ b/wcfsetup/install/lang/de.xml @@ -3084,6 +3084,9 @@ Wenn {if LANGUAGE_USE_INFORMAL_VARIANT}du{else}Sie{/if} unter „Konfiguration + + %s als Platzhalter für die Eingabe des Benutzers.]]> + %s fehlt in der URL.]]> diff --git a/wcfsetup/install/lang/en.xml b/wcfsetup/install/lang/en.xml index de66107977..ea0a7d7120 100644 --- a/wcfsetup/install/lang/en.xml +++ b/wcfsetup/install/lang/en.xml @@ -3012,6 +3012,9 @@ You can define the default sender in “Configuration » Options » General » E + + %s as placeholder for the user input.]]> + %s.]]> diff --git a/wcfsetup/setup/db/install.sql b/wcfsetup/setup/db/install.sql index 939404fe15..99a0e86205 100644 --- a/wcfsetup/setup/db/install.sql +++ b/wcfsetup/setup/db/install.sql @@ -1762,6 +1762,7 @@ CREATE TABLE wcf1_user_option ( validationPattern TEXT, selectOptions MEDIUMTEXT, enableOptions MEDIUMTEXT, + labeledUrl MEDIUMTEXT, required TINYINT(1) NOT NULL DEFAULT 0, askDuringRegistration TINYINT(1) NOT NULL DEFAULT 0, editable TINYINT(1) NOT NULL DEFAULT 0,