Bitrix-D7
23.9
Загрузка...
Поиск...
Не найдено
EmojiConverter.php
1
<?php
2
3
namespace
Bitrix\MessageService\Providers\Edna\WhatsApp
;
4
5
use
Bitrix\MessageService\Providers\Constants\InternalOption
;
6
7
class
EmojiConverter
8
{
9
public
function
convertEmojiInTemplate
(array $messageTemplate,
string
$type): array
10
{
11
$template = $messageTemplate;
12
if
(isset($template[
'text'
]))
13
{
14
$template[
'text'
] = $this->
convertTextSection
($template[
'text'
], $type);
15
}
16
if
(isset($template[
'header'
]))
17
{
18
$template[
'header'
] = $this->
convertHeaderSection
($template[
'header'
], $type);
19
}
20
if
(isset($template[
'footer'
]))
21
{
22
$template[
'footer'
] = $this->
convertFooterSection
($template[
'footer'
], $type);
23
}
24
if
(isset($template[
'keyboard'
]))
25
{
26
$template[
'keyboard'
] = $this->
convertKeyboardSection
($template[
'keyboard'
], $type);
27
}
28
29
return
$template;
30
}
31
32
public
function
convertEmoji
(
string
$text,
string
$type): string
33
{
34
if
(!in_array($type, [InternalOption::EMOJI_DECODE, InternalOption::EMOJI_ENCODE],
true
))
35
{
36
return
$text;
37
}
38
39
return \Bitrix\Main\Text\Emoji::$type($text);
40
}
41
42
protected
function
convertTextSection
(?
string
$textSection,
string
$type): string
43
{
44
if
(is_string($textSection))
45
{
46
$textSection = $this->
convertEmoji
($textSection, $type);
47
}
48
49
return
$textSection;
50
}
51
52
protected
function
convertHeaderSection
(?array $headerSection,
string
$type): array
53
{
54
if
(isset($headerSection[
'text'
]))
55
{
56
$headerSection[
'text'
] = $this->
convertEmoji
($headerSection[
'text'
], $type);
57
}
58
59
return
$headerSection;
60
}
61
62
protected
function
convertFooterSection
(?array $footerSection,
string
$type): array
63
{
64
if
(isset($footerSection[
'text'
]))
65
{
66
$footerSection[
'text'
] = $this->
convertEmoji
($footerSection[
'text'
], $type);
67
}
68
69
return
$footerSection;
70
}
71
97
protected
function
convertKeyboardSection
(?array $keyboardSection,
string
$type): array
98
{
99
if
(isset($keyboardSection[
'rows'
]) && is_array($keyboardSection[
'rows'
]))
100
{
101
foreach
($keyboardSection[
'rows'
] as $rowIndex => $row)
102
{
103
if
(isset($row[
'buttons'
]) && is_array($row[
'buttons'
]))
104
{
105
foreach
($row[
'buttons'
] as $buttonIndex => $button)
106
{
107
if
(isset($button[
'text'
]))
108
{
109
$keyboardSection[
'rows'
][$rowIndex][
'buttons'
][$buttonIndex][
'text'
] =
110
$this->
convertEmoji
($button[
'text'
], $type);
111
}
112
}
113
}
114
}
115
}
116
117
return
$keyboardSection;
118
}
119
}
Bitrix\MessageService\Providers\Constants\InternalOption
Definition
InternalOption.php:6
Bitrix\MessageService\Providers\Edna\WhatsApp\EmojiConverter
Definition
EmojiConverter.php:8
Bitrix\MessageService\Providers\Edna\WhatsApp\EmojiConverter\convertFooterSection
convertFooterSection(?array $footerSection, string $type)
Definition
EmojiConverter.php:62
Bitrix\MessageService\Providers\Edna\WhatsApp\EmojiConverter\convertHeaderSection
convertHeaderSection(?array $headerSection, string $type)
Definition
EmojiConverter.php:52
Bitrix\MessageService\Providers\Edna\WhatsApp\EmojiConverter\convertEmojiInTemplate
convertEmojiInTemplate(array $messageTemplate, string $type)
Definition
EmojiConverter.php:9
Bitrix\MessageService\Providers\Edna\WhatsApp\EmojiConverter\convertTextSection
convertTextSection(?string $textSection, string $type)
Definition
EmojiConverter.php:42
Bitrix\MessageService\Providers\Edna\WhatsApp\EmojiConverter\convertKeyboardSection
convertKeyboardSection(?array $keyboardSection, string $type)
Definition
EmojiConverter.php:97
Bitrix\MessageService\Providers\Edna\WhatsApp\EmojiConverter\convertEmoji
convertEmoji(string $text, string $type)
Definition
EmojiConverter.php:32
Bitrix\MessageService\Providers\Edna\WhatsApp
Definition
ConnectorLine.php:3
modules
messageservice
lib
Providers
Edna
WhatsApp
EmojiConverter.php
Создано системой
1.10.0