Skip to content

Commit 4b4730d

Browse files
authored
Merge pull request #28 from iMattPro/issue-27
Support emoji
2 parents c2c0f82 + b7d4e94 commit 4b4730d

File tree

4 files changed

+53
-0
lines changed

4 files changed

+53
-0
lines changed

message/manager.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ public function save_message($cannedmessage_data)
129129

130130
$action = ($cannedmessage_data['cannedmessage_id'] > 0) ? 'update' : 'insert';
131131

132+
// Handle emojis in canned message
133+
if (!empty($cannedmessage_data['cannedmessage_content']))
134+
{
135+
$cannedmessage_data['cannedmessage_content'] = utf8_encode_ucr($cannedmessage_data['cannedmessage_content']);
136+
}
137+
132138
if ($error = $this->{$action}($cannedmessage_data))
133139
{
134140
return $error;

migrations/emoji_support.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
*
4+
* Canned Messages. An extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) 2017 phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\cannedmessages\migrations;
12+
13+
class emoji_support extends \phpbb\db\migration\migration
14+
{
15+
public static function depends_on()
16+
{
17+
return [
18+
'\phpbb\cannedmessages\migrations\install_cannedmessages_schema',
19+
'\phpbb\cannedmessages\migrations\update_cannedmessages_schema',
20+
];
21+
}
22+
23+
public function update_schema()
24+
{
25+
return [
26+
'change_columns' => [
27+
$this->table_prefix . 'cannedmessages' => [
28+
'cannedmessage_content' => ['MTEXT_UNI', ''],
29+
],
30+
],
31+
];
32+
}
33+
34+
public function revert_schema()
35+
{
36+
}
37+
}

styles/all/template/js/cannedmessages_mcp.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ text_name = 'cannedmessage_content';
3030
$(this).parents('li').remove();
3131
});
3232

33+
// Remove emoji and other non-standard characters from title
34+
document.getElementById('cannedmessage_name').addEventListener('input', function(e) {
35+
const noEmoji = e.target.value.replace(/[\u{1F300}-\u{1F9FF}]|[\u{2700}-\u{27BF}]|[\u{2600}-\u{26FF}]|[\u{2300}-\u{23FF}]|[\u{1F000}-\u{1F6FF}]|[\u{2B00}-\u{2BFF}]/gu, '');
36+
37+
if (e.target.value !== noEmoji) {
38+
e.target.value = noEmoji;
39+
}
40+
});
41+
3342
$(function() {
3443
var $add_edit = $('#cannedmessage_add_edit'),
3544
$content = $('#cannedmessage_content_section'),

tests/manager/save_message_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function data_insert_message()
3030
array(array_merge($this->get_data_template(), array('is_cat' => 1))), // add new category
3131
array(array_merge($this->get_data_template(), array('parent_id' => 1))), // add new message to Category 1
3232
array(array_merge($this->get_data_template(), array('parent_id' => 1, 'is_cat' => 1))), // add new category to Category 1
33+
array(array_merge($this->get_data_template(), array('cannedmessage_content' => 'Test content 😀'))), // add message with emoji
3334
);
3435
}
3536

0 commit comments

Comments
 (0)