1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
mail.php
См. документацию.
1<?php
8namespace Bitrix\Sender\Preset\Templates;
9
10use Bitrix\Main\IO\File;
11use Bitrix\Main\Loader;
12use Bitrix\Main\Localization\Loc;
13
14use Bitrix\Sender\Message;
15use Bitrix\Sender\Templates\Type;
16use Bitrix\Sender\Integration;
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'),
80 Loc::getMessage(
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 ),
89 );
90
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,
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(
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}
$path
Определения access_edit.php:21
getCode()
Определения error.php:54
static getLocal($path, $root=null)
Определения loader.php:572
static onTemplateList($messageType)
Определения eventhandler.php:151
static replaceTemplateHtml($content, $replace=[])
Определения mail.php:67
static getTemplateHtml()
Определения mail.php:99
const LOCAL_DIR
Определения mail.php:26
static onPresetTemplateList($templateType=null, $templateId=null, $messageCode=null)
Определения mail.php:36
static replace($text='')
Определения texts.php:94
$content
Определения commerceml.php:144
$templateId
Определения component_props2.php:51
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$fileContent
Определения file_property.php:47
$result
Определения get_property_values.php:14
const CODE_MAIL
Определения ibase.php:17
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
bx_basename($path, $ext="")
Определения tools.php:3269
Определения address.php:8
Определения adapter.php:9
$fileName
Определения quickway.php:305