mirror of
https://github.com/humhub/humhub.git
synced 2025-01-16 21:58:17 +01:00
Render emojis in email content (#7062)
* Render emojis in email content * Cache emoji data and display emoji on email subject * Fix finding emoji in content
This commit is contained in:
parent
ab03007f7b
commit
ee3a5bf0ba
@ -56,6 +56,7 @@
|
||||
"npm-asset/socket.io-client": "^2.0",
|
||||
"npm-asset/swiped-events": "^1.0.9",
|
||||
"npm-asset/timeago": "^1.6.3",
|
||||
"npm-asset/unicode-emoji-json": "^0.5.0",
|
||||
"phpoffice/phpspreadsheet": "^2.0",
|
||||
"raoul2000/yii2-jcrop-widget": "^1.0",
|
||||
"symfony/amazon-mailer": "^5.4",
|
||||
|
14
composer.lock
generated
14
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "1999d0a4f117ac2c69cf9743553d7b08",
|
||||
"content-hash": "54bec7841b0d448a8ad955ef8ff41b07",
|
||||
"packages": [
|
||||
{
|
||||
"name": "async-aws/core",
|
||||
@ -4115,6 +4115,18 @@
|
||||
},
|
||||
"type": "npm-asset"
|
||||
},
|
||||
{
|
||||
"name": "npm-asset/unicode-emoji-json",
|
||||
"version": "0.5.0",
|
||||
"dist": {
|
||||
"type": "tar",
|
||||
"url": "https://registry.npmjs.org/unicode-emoji-json/-/unicode-emoji-json-0.5.0.tgz"
|
||||
},
|
||||
"type": "npm-asset",
|
||||
"license": [
|
||||
"MIT"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "npm-asset/ws",
|
||||
"version": "7.4.6",
|
||||
|
50
protected/humhub/modules/content/helpers/EmojiHelper.php
Normal file
50
protected/humhub/modules/content/helpers/EmojiHelper.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\modules\content\helpers;
|
||||
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* @since 1.16
|
||||
*/
|
||||
class EmojiHelper
|
||||
{
|
||||
public const DATA_PATH = '@npm/unicode-emoji-json/data-by-emoji.json';
|
||||
|
||||
public static function getData(): array
|
||||
{
|
||||
return Yii::$app->runtimeCache->getOrSet('emoji-helper-data', function () {
|
||||
$dataPath = Yii::getAlias(self::DATA_PATH);
|
||||
|
||||
if (!is_file($dataPath)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$data = (array) json_decode(file_get_contents($dataPath));
|
||||
|
||||
$emojis = [];
|
||||
foreach ($data as $e => $emoji) {
|
||||
$emojis[$emoji->name] = $e;
|
||||
}
|
||||
|
||||
return $emojis;
|
||||
});
|
||||
}
|
||||
|
||||
public static function getUnicode(string $name): ?string
|
||||
{
|
||||
return self::getData()[$name] ?? null;
|
||||
}
|
||||
|
||||
public static function findEmoji(string $content): ?string
|
||||
{
|
||||
return preg_match('/:([a-z\d\-\+][a-z\d\-\+\s_]*):/i', $content, $matches)
|
||||
? $matches[1]
|
||||
: null;
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@
|
||||
namespace humhub\modules\content\widgets\richtext\converter;
|
||||
|
||||
use humhub\libs\Html;
|
||||
use humhub\modules\content\helpers\EmojiHelper;
|
||||
use humhub\modules\content\widgets\richtext\extensions\link\LinkParserBlock;
|
||||
use humhub\modules\file\actions\DownloadAction;
|
||||
use humhub\modules\file\models\File;
|
||||
@ -123,4 +124,20 @@ class RichTextToEmailHtmlConverter extends RichTextToHtmlConverter
|
||||
{
|
||||
return '<p>' . nl2br($this->renderAbsy($block['content'])) . "</p>\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* @marker :
|
||||
*/
|
||||
protected function parseEmoji($markdown)
|
||||
{
|
||||
return ($emoji = EmojiHelper::findEmoji($markdown))
|
||||
? [['emoji', [['text', $emoji]]], strlen($emoji) + 2]
|
||||
: [['text', ':'], 1];
|
||||
}
|
||||
|
||||
protected function renderEmoji($element)
|
||||
{
|
||||
$emojiName = $this->renderAbsy($element[1]);
|
||||
return EmojiHelper::getUnicode($emojiName) ?? ':' . $emojiName . ':';
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace humhub\modules\content\widgets\richtext\converter;
|
||||
|
||||
use humhub\libs\Helpers;
|
||||
use humhub\modules\content\helpers\EmojiHelper;
|
||||
use humhub\modules\content\widgets\richtext\extensions\link\LinkParserBlock;
|
||||
use humhub\modules\content\widgets\richtext\extensions\link\RichTextLinkExtension;
|
||||
use humhub\modules\content\widgets\richtext\ProsemirrorRichText;
|
||||
@ -187,4 +188,20 @@ class RichTextToPlainTextConverter extends RichTextToMarkdownConverter
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @marker :
|
||||
*/
|
||||
protected function parseEmoji($markdown)
|
||||
{
|
||||
return ($emoji = EmojiHelper::findEmoji($markdown))
|
||||
? [['emoji', [['text', $emoji]]], strlen($emoji) + 2]
|
||||
: [['text', ':'], 1];
|
||||
}
|
||||
|
||||
protected function renderEmoji($element)
|
||||
{
|
||||
$emojiName = $this->renderAbsy($element[1]);
|
||||
return EmojiHelper::getUnicode($emojiName) ?? ':' . $emojiName . ':';
|
||||
}
|
||||
}
|
||||
|
@ -8,9 +8,10 @@
|
||||
|
||||
namespace humhub\modules\notification\targets;
|
||||
|
||||
use Yii;
|
||||
use humhub\modules\content\widgets\richtext\converter\RichTextToPlainTextConverter;
|
||||
use humhub\modules\notification\components\BaseNotification;
|
||||
use humhub\modules\user\models\User;
|
||||
use Yii;
|
||||
use yii\helpers\ArrayHelper;
|
||||
use yii\helpers\Url;
|
||||
|
||||
@ -70,7 +71,7 @@ class MailTarget extends BaseTarget
|
||||
|
||||
$mail = Yii::$app->mailer->compose($this->view, $viewParams)
|
||||
->setTo($recipient->email)
|
||||
->setSubject(str_replace("\n", " ", trim($notification->getMailSubject())));
|
||||
->setSubject(RichTextToPlainTextConverter::process($notification->getMailSubject()));
|
||||
if ($replyTo = Yii::$app->settings->get('mailer.systemEmailReplyTo')) {
|
||||
$mail->setReplyTo($replyTo);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user