Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
EmojiConverter.php
1<?php
2
4
6
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}
convertFooterSection(?array $footerSection, string $type)
convertHeaderSection(?array $headerSection, string $type)
convertEmojiInTemplate(array $messageTemplate, string $type)
convertKeyboardSection(?array $keyboardSection, string $type)