Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,9 @@
->columns([
DefaultFalseBooleanDatabaseTableColumn::create('showOnUserCard'),
]),
PartialDatabaseTable::create('wcf1_smiley')
->columns([
NotNullVarchar255DatabaseTableColumn::create('emoji')
->defaultValue(''),
]),
];
16 changes: 15 additions & 1 deletion wcfsetup/install/files/acp/templates/smileyAdd.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,28 @@
<dt><label for="aliases">{lang}wcf.acp.smiley.aliases{/lang}</label></dt>
<dd>
<textarea id="aliases" name="aliases" cols="40" rows="10">{$aliases}</textarea>

{if $errorField == 'aliases'}
<small class="innerError">
{lang}wcf.acp.smiley.aliases.error.{$errorType}{/lang}
</small>
{/if}
</dd>
</dl>

<dl{if $errorField == 'emoji'} class="formError"{/if}>
<dt><label for="emoji">{lang}wcf.acp.smiley.emoji{/lang}</label></dt>
<dd>
<input type="text" id="emoji" name="emoji" value="{$emoji}" class="short" maxlength="64">

{if $errorField == 'emoji'}
<small class="innerError">
{lang}wcf.acp.smiley.emoji.error.{$errorType}{/lang}
</small>
{/if}
<small>{lang}wcf.acp.smiley.emoji.description{/lang}</small>
</dd>
</dl>

<dl{if $errorField == 'showOrder'} class="formError"{/if}>
<dt><label for="showOrder">{lang}wcf.global.showOrder{/lang}</label></dt>
Expand Down
11 changes: 11 additions & 0 deletions wcfsetup/install/files/lib/acp/form/SmileyAddForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ class SmileyAddForm extends AbstractForm
*/
public $aliases = '';

/**
* unicode emoji that replaces this smiley during message reprocessing
*/
public string $emoji = '';

/**
* path to the smiley file
* @var string
Expand Down Expand Up @@ -140,6 +145,7 @@ public function assignVariables()
'categoryID' => $this->categoryID,
'smileyCode' => $this->smileyCode,
'aliases' => $this->aliases,
'emoji' => $this->emoji,
'smileyPath' => $this->smileyPath,
'smileyPath2x' => $this->smileyPath2x,
'categoryNodeList' => $this->categoryNodeTree->getIterator(),
Expand Down Expand Up @@ -187,6 +193,9 @@ public function readFormParameters()
if (isset($_POST['aliases'])) {
$this->aliases = StringUtil::unifyNewlines(StringUtil::trim($_POST['aliases']));
}
if (isset($_POST['emoji'])) {
$this->emoji = StringUtil::trim($_POST['emoji']);
}
if (isset($_POST['smileyPath'])) {
$this->smileyPath = FileUtil::removeLeadingSlash(StringUtil::trim($_POST['smileyPath']));
}
Expand Down Expand Up @@ -217,6 +226,7 @@ public function save()
'smileyTitle' => $this->smileyTitle,
'smileyCode' => $this->smileyCode,
'aliases' => $this->aliases,
'emoji' => $this->emoji,
'smileyPath' => $this->smileyPath,
'smileyPath2x' => $this->smileyPath2x,
'showOrder' => $this->showOrder,
Expand Down Expand Up @@ -246,6 +256,7 @@ public function save()
$this->showOrder = 0;
$this->smileyPath = $this->smileyPath2x = '';
$this->aliases = '';
$this->emoji = '';
$this->uploadedFilename = $this->uploadedFilename2x = '';

I18nHandler::getInstance()->reset();
Expand Down
2 changes: 2 additions & 0 deletions wcfsetup/install/files/lib/acp/form/SmileyEditForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function save()
'smileyTitle' => $this->smileyTitle,
'smileyCode' => $this->smileyCode,
'aliases' => $this->aliases,
'emoji' => $this->emoji,
'smileyPath' => $this->smileyPath,
'smileyPath2x' => $this->smileyPath2x,
'showOrder' => $this->showOrder,
Expand Down Expand Up @@ -106,6 +107,7 @@ public function readData()

$this->smileyCode = $this->smiley->smileyCode;
$this->aliases = $this->smiley->aliases;
$this->emoji = $this->smiley->emoji;
$this->smileyPath = $this->smiley->smileyPath;
$this->smileyPath2x = $this->smiley->smileyPath2x;
$this->showOrder = $this->smiley->showOrder;
Expand Down
1 change: 1 addition & 0 deletions wcfsetup/install/files/lib/data/smiley/Smiley.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @property-read string $smileyCode code used for displaying the smiley
* @property-read string $aliases alternative codes used for displaying the smiley
* @property-read int $showOrder position of the smiley in relation to the other smileys in the same category
* @property-read string $emoji unicode emoji that replaces this smiley when content is reprocessed
*/
class Smiley extends DatabaseObject implements ITitledObject
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ protected function handleSmiley(\DOMElement $element)
$code = $element->getAttribute('alt');

$smiley = SmileyCache::getInstance()->getSmileyByCode($code);

// Migrate legacy smiley element to the mapped unicode emoji.
if ($smiley !== null && $smiley->emoji !== '') {
$element->parentNode->insertBefore(
$element->ownerDocument->createTextNode($smiley->emoji),
$element
);
$element->parentNode->removeChild($element);

return;
}

if ($smiley === null || $this->smiliesFound === 50) {
$element->parentNode->insertBefore($element->ownerDocument->createTextNode($code), $element);
$element->parentNode->removeChild($element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -607,12 +607,19 @@ protected function parseSmiley(\DOMText $text, string $value)
foreach ($smileyPatterns as $smileyPattern) {
$value = \preg_replace_callback($smileyPattern, function ($matches) use ($text) {
$smileyCode = $matches[0];
$smiley = self::$smilies[$smileyCode];

// Replace smiley with mapped unicode emoji so legacy smiley codes
// get migrated to native emojis whenever a message is reprocessed.
if ($smiley->emoji !== '') {
return $smiley->emoji;
}

if ($this->smileyCount === 50) {
return $smileyCode;
}

$this->smileyCount++;
$smiley = self::$smilies[$smileyCode];
$element = $text->ownerDocument->createElement('img');
$element->setAttribute('src', $smiley->getURL());
$element->setAttribute('class', 'smiley');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ public function process(array $elements, AbstractHtmlNodeProcessor $htmlNodeProc
$code = $element->getAttribute('alt');

$smiley = SmileyCache::getInstance()->getSmileyByCode($code);

// Render the mapped unicode emoji instead of the legacy smiley image.
if ($smiley !== null && $smiley->emoji !== '') {
$htmlNodeProcessor->replaceElementWithText($element, $smiley->emoji, false);
continue;
}

if ($smiley === null || $this->outputType === 'text/plain') {
// output as raw code instead
$htmlNodeProcessor->replaceElementWithText($element, ' ' . $code . ' ', false);
Expand Down
2 changes: 2 additions & 0 deletions wcfsetup/install/lang/de.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2855,6 +2855,8 @@ Abschnitte dürfen nicht leer sein und nur folgende Zeichen enthalten: <kbd>[a-z
<item name="wcf.acp.smiley.smileyCode.error.notUnique"><![CDATA[Dieser Smiley-Code wird bereits von einem anderen Smiley verwendet]]></item>
<item name="wcf.acp.smiley.aliases"><![CDATA[Alternative Smiley-Codes]]></item>
<item name="wcf.acp.smiley.aliases.error.notUnique"><![CDATA[Mindestens ein alternativer Smiley-Code wird bereits von einem anderen Smiley verwendet]]></item>
<item name="wcf.acp.smiley.emoji"><![CDATA[Emoji]]></item>
<item name="wcf.acp.smiley.emoji.description"><![CDATA[Optionales Emoji, das diesen Smiley ersetzt, sobald eine bestehende Nachricht aktualisiert wird. Leer lassen, um den Smiley nicht zu ersetzen.]]></item>
<item name="wcf.acp.smiley.smileyPath"><![CDATA[Smiley-Pfad]]></item>
<item name="wcf.acp.smiley.smileyPath.description"><![CDATA[Der Smiley-Pfad wird relativ zu „{$__wcf->getPath()}“ interpretiert.]]></item>
<item name="wcf.acp.smiley.smileyPath.error.notFound"><![CDATA[Es wurde keine Datei unter dem angegebenen Pfad gefunden]]></item>
Expand Down
2 changes: 2 additions & 0 deletions wcfsetup/install/lang/en.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2784,6 +2784,8 @@ If you have <strong>already bought the licenses for the listed apps</strong>, th
<item name="wcf.acp.smiley.smileyCode.error.notUnique"><![CDATA[This smiley code is already in use by another smiley.]]></item>
<item name="wcf.acp.smiley.aliases"><![CDATA[Alternative Smiley Codes]]></item>
<item name="wcf.acp.smiley.aliases.error.notUnique"><![CDATA[At least one alternative smiley code is already in use by another smiley.]]></item>
<item name="wcf.acp.smiley.emoji"><![CDATA[Emoji]]></item>
<item name="wcf.acp.smiley.emoji.description"><![CDATA[Optional emoji that replaces this smiley when an existing message is updated. Leave empty to keep the smiley unchanged.]]></item>
<item name="wcf.acp.smiley.smileyPath"><![CDATA[Smiley Path]]></item>
<item name="wcf.acp.smiley.smileyPath.description"><![CDATA[The smiley path is relative to “{$__wcf->getPath()}”.]]></item>
<item name="wcf.acp.smiley.smileyPath.error.notFound"><![CDATA[Unable to find a file on entered path.]]></item>
Expand Down
2 changes: 2 additions & 0 deletions wcfsetup/setup/db/install_com.woltlab.wcf.php
Original file line number Diff line number Diff line change
Expand Up @@ -3293,6 +3293,8 @@
->notNull(),
NotNullInt10DatabaseTableColumn::create('showOrder')
->defaultValue(0),
NotNullVarchar255DatabaseTableColumn::create('emoji')
->defaultValue(''),
])
->indices([
DatabaseTablePrimaryIndex::create()
Expand Down
Loading