Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
mail.php
1<?php
9
13
17
18Loc::loadMessages(__FILE__);
19
24class Mail
25{
26 const LOCAL_DIR = '/modules/sender/preset/template_v2/';
27
36 public static function onPresetTemplateList($templateType = null, $templateId = null, $messageCode = null)
37 {
38 if($templateType && $templateType !== 'BASE')
39 {
40 return array();
41 }
42 if($messageCode && $messageCode !== Message\iBase::CODE_MAIL)
43 {
44 return array();
45 }
46
47 return self::getTemplates($templateId);
48 }
49
50 private static function getFileContent($fileName)
51 {
52 $path = Loader::getLocal(self::LOCAL_DIR . bx_basename($fileName) . '.php');
53 if ($path && File::isFileExists($path))
54 {
55 return File::getFileContents($path);
56 }
57
58 return '';
59 }
60
67 public static function replaceTemplateHtml($content, $replace = [])
68 {
69 $content = str_replace(
70 array(
71 '%TEXT%',
72 '%IMAGE_PATH%',
73 '%BUTTON_TEXT%',
74 '%UNSUB_LINK%',
75 ),
76 array(
77 $replace['TEXT'],
78 '/bitrix/images/sender/preset/template_v2/banner.png?1',
79 Loc::getMessage('SENDER_PRESET_TEMPLATE_MAIL_BUTTON_GO'),
81 'SENDER_PRESET_TEMPLATE_MAIL_UNSUBSCRIBE',
82 array(
83 '%btn_start%' => '<a style="color: #0054a5;" href="#' . 'UNSUBSCRIBE_LINK' . '#">',
84 '%btn_end%' => '</a>',
85 )
86 )
87 ),
88 $content
89 );
90
91 return Texts::replace($content);
92 }
93
99 public static function getTemplateHtml()
100 {
101 $fileTheme = self::getFileContent('theme');
102 $fileSimple = self::getFileContent('image_text_button');
103
104 if (!$fileTheme || !$fileSimple)
105 {
106 return null;
107 }
108
109 $fileSocial = self::getFileContent('social');
110 $fileSocialRu = self::getFileContent('social_ru');
111 $fileSocialEn = '';
112 if (Integration\Bitrix24\Service::isCloud() && !Integration\Bitrix24\Service::isCloudRegionRussian())
113 {
114 $fileSocialRu = '';
115 $fileSocialEn = self::getFileContent('social_en');
116 }
117
118 $fileSocial = str_replace(
119 ['%SOCIAL_RU%', '%SOCIAL_EN%'],
120 [$fileSocialRu, $fileSocialEn],
121 $fileSocial
122 );
123 $fileContent = str_replace(
124 ['%TEMPLATE_CONTENT%', '%TEMPLATE_SOCIAL%'],
125 [$fileSimple, $fileSocial],
126 $fileTheme
127 );
128
129 return $fileContent;
130 }
131
132 private static function getTemplates($templateId = null)
133 {
134 $fileContent = self::getTemplateHtml();
135 if (!$fileContent)
136 {
137 return [];
138 }
139
140 $result = [
141 [
142 'ID' => 'empty',
143 'TYPE' => Type::getCode(Type::BASE),
144 'MESSAGE_CODE' => Message\iBase::CODE_MAIL,
145 'VERSION' => 2,
146 'HOT' => false,
147 'ICON' => '',
148
149 'NAME' => Loc::getMessage('SENDER_PRESET_TEMPLATE_MAIL_HTML_NAME'),
150 'DESC' => Loc::getMessage('SENDER_PRESET_TEMPLATE_MAIL_HTML_DESC'),
151 'FIELDS' => array(
152 'SUBJECT' => array(
153 'CODE' => 'SUBJECT',
154 'VALUE' => Loc::getMessage('SENDER_PRESET_TEMPLATE_MAIL_HTML_SUBJECT'),
155 ),
156 'MESSAGE' => array(
157 'CODE' => 'MESSAGE',
158 'VALUE' => '<html><body></body></html>',
159 'ON_DEMAND' => false
160 ),
161 ),
162 ]
163 ];
164
165 $result = array_merge(
166 $result,
167 Integration\EventHandler::onTemplateList(Message\iBase::CODE_MAIL)
168 );
169
170 foreach (Texts::getListByType(Message\iBase::CODE_MAIL) as $item)
171 {
172 $code = mb_strtolower("mail_".$item['CODE']);
173 if($templateId && $code !== $templateId)
174 {
175 continue;
176 }
177
178 $fileContent = self::replaceTemplateHtml(
179 $fileContent,
180 [
181 'TEXT' => "<br><h2>{$item['TEXT_HEAD']}</h2><br>{$item['TEXT_BODY']}<br><br>"
182 ]
183 );
184
185 $result[] = array(
186 'ID' => $code,
187 'TYPE' => Type::getCode(Type::BASE),
188 'MESSAGE_CODE' => Message\iBase::CODE_MAIL,
189 'VERSION' => 2,
190 'HOT' => $item['HOT'],
191 'ICON' => $item['ICON'],
192
193 'NAME' => $item['NAME'],
194 'DESC' => $item['DESC'],
195 'FIELDS' => array(
196 'SUBJECT' => array(
197 'CODE' => 'SUBJECT',
198 'VALUE' => $item['SUBJECT'],
199 ),
200 'MESSAGE' => array(
201 'CODE' => 'MESSAGE',
202 'VALUE' => $fileContent,
203 'ON_DEMAND' => true
204 ),
205 ),
206 );
207 }
208
209 return $result;
210 }
211}
static getLocal($path, $root=null)
Definition loader.php:529
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static replaceTemplateHtml($content, $replace=[])
Definition mail.php:67
static onPresetTemplateList($templateType=null, $templateId=null, $messageCode=null)
Definition mail.php:36