</dd>
</dl>
+ <dl{if $errorField == 'labeledUrl'} class="formError"{/if}>
+ <dt><label for="labeledUrl">{lang}wcf.acp.user.option.labeledUrl{/lang}</label></dt>
+ <dd>
+ <input type="text" id="labeledUrl" name="labeledUrl" value="{$labeledUrl}" class="long">
+ {if $errorField == 'labeledUrl'}
+ <small class="innerError">
+ {if $errorType == 'empty'}
+ {lang}wcf.global.form.error.empty{/lang}
+ {else}
+ {lang}wcf.acp.user.option.labeledUrl.error.{@$errorType}{/lang}
+ {/if}
+ </small>
+ {/if}
+ <small>{lang}wcf.acp.user.option.labeledUrl.description{/lang}</small>
+ </dd>
+ </dl>
+
<dl{if $errorField == 'outputClass'} class="formError"{/if}>
<dt><label for="outputClass">{lang}wcf.acp.user.option.outputClass{/lang}</label></dt>
<dd>
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;
*/
public $selectOptions = '';
+ /**
+ * @var string
+ * @since 5.4
+ */
+ public $labeledUrl = '';
+
/**
* field is required
* @var boolean
'text',
'textarea',
'message',
- 'URL'
+ 'URL',
+ 'labeledUrl',
];
/**
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);
if ($this->optionType == 'URL') {
$this->outputClass = URLUserOptionOutput::class;
}
+
+ if ($this->optionType == 'labeledUrl') {
+ $this->outputClass = LabeledUrlUserOptionOutput::class;
+ }
}
}
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');
+ }
}
/**
'editable' => $this->editable,
'visible' => $this->visible,
'packageID' => 1,
- 'additionalData' => !empty($additionalData) ? serialize($additionalData) : ''
+ 'additionalData' => !empty($additionalData) ? serialize($additionalData) : '',
+ 'labeledUrl' => $this->labeledUrl,
])]);
$this->objectAction->executeAction();
'outputClass' => $this->outputClass,
'action' => 'add',
'availableCategories' => $this->availableCategories,
- 'availableOptionTypes' => self::$availableOptionTypes
+ 'availableOptionTypes' => self::$availableOptionTypes,
+ 'labeledUrl' => $this->labeledUrl,
]);
}
}
'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();
$this->searchable = $this->userOption->searchable;
$this->showOrder = $this->userOption->showOrder;
$this->outputClass = $this->userOption->outputClass;
+ $this->labeledUrl = $this->userOption->labeledUrl;
}
}
* @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 {
/**
--- /dev/null
+<?php
+namespace wcf\system\option;
+/**
+ * Option type implementation for url input fields.
+ *
+ * @author Joshua Ruesweg
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Option
+ * @since 5.4
+ */
+class LabeledUrlOptionType extends TextOptionType { }
--- /dev/null
+<?php
+namespace wcf\system\option\user;
+use wcf\data\user\option\UserOption;
+use wcf\data\user\User;
+use wcf\util\StringUtil;
+
+/**
+ * User option output implementation for the output of an url.
+ *
+ * @author Joshua Ruesweg
+ * @copyright 2001-2020 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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));
+ }
+}
<item name="wcf.acp.user.option.editable.2"><![CDATA[Administrator]]></item>
<item name="wcf.acp.user.option.editable.3"><![CDATA[Eigentümer und Administrator]]></item>
<item name="wcf.acp.user.option.editable.6"><![CDATA[Eigentümer bei Erstanmeldung und Administrator]]></item>
+ <item name="wcf.acp.user.option.labeledUrl"><![CDATA[URL]]></item>
+ <item name="wcf.acp.user.option.labeledUrl.description"><![CDATA[Wenn der Feldtyp „labeledUrl“ ist, muss hier die URL hinterlegt werden, auf die verlinkt werden soll. {if LANGUAGE_USE_INFORMAL_VARIANT}Nutze{else}Nutzen Sie{/if} <span class="inlineCode">%s</span> als Platzhalter für die Eingabe des Benutzers.]]></item>
+ <item name="wcf.acp.user.option.labeledUrl.error.invalid"><![CDATA[Der Platzhalter <span class="inlineCode">%s</span> fehlt in der URL.]]></item>
<item name="wcf.acp.user.option.optionType"><![CDATA[Feldtyp]]></item>
<item name="wcf.acp.user.option.optionType.description"><![CDATA[Die Namen entsprechen in der Regel den HTML-Elementen, die benötigt werden, um so ein Feld beim Benutzer abzufragen.]]></item>
<item name="wcf.acp.user.option.askDuringRegistration"><![CDATA[Das Feld wird im Registrierungs-Formular angezeigt.]]></item>
<item name="wcf.acp.user.option.editable.2"><![CDATA[Administrator]]></item>
<item name="wcf.acp.user.option.editable.3"><![CDATA[Owner and Administrator]]></item>
<item name="wcf.acp.user.option.editable.6"><![CDATA[Owner during registration and Administrator]]></item>
+ <item name="wcf.acp.user.option.labeledUrl"><![CDATA[URL]]></item>
+ <item name="wcf.acp.user.option.labeledUrl.description"><![CDATA[If the field type is “labeledUrl”, the URL to be linked to must be entered here. Use <span class="inlineCode">%s</span> as placeholder for the user input.]]></item>
+ <item name="wcf.acp.user.option.labeledUrl.error.invalid"><![CDATA[The URL does not contain the placeholder <span class="inlineCode">%s</span>.]]></item>
<item name="wcf.acp.user.option.optionType"><![CDATA[Option Type]]></item>
<item name="wcf.acp.user.option.optionType.description"><![CDATA[The option names usually equal the HTML-tag used as input element.]]></item>
<item name="wcf.acp.user.option.askDuringRegistration"><![CDATA[Field will be visible during registration]]></item>
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,