Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
templatebase.php
1<?php
9
14use Bitrix\Fileman\Block\Editor as BlockEditor;
15
17
18Loc::loadMessages(__FILE__);
19
27{
28 const LOCAL_DIR_TMPL = '/modules/sender/preset/template/';
29 const LOCAL_DIR_IMG = '/images/sender/preset/template/';
30
38 public static function onPresetTemplateList($templateType = null, $templateId = null)
39 {
40 $resultList = array();
41
42 $templateList = static::getListName();
43
44
45 foreach ($templateList as $templateName)
46 {
47 if($templateName !== $templateId && $templateId)
48 {
49 continue;
50 }
51
52 $template = static::getById($templateName);
53 if($template)
54 {
55 $template['VERSION'] = 1;
56 if($template['TYPE'] === $templateType || !$templateType)
57 {
58 $resultList[] = $template;
59 }
60 }
61 }
62
63 return $resultList;
64 }
65
74 public static function onPresetTemplateListSite($templateType = null, $templateId = null)
75 {
76 $resultList = array();
77
78 if (Integration\Bitrix24\Service::isPortal())
79 {
80 return $resultList;
81 }
82
83 if($templateType && $templateType !== 'SITE_TMPL')
84 {
85 return $resultList;
86 }
87
88 $by = 'SORT';
89 $order = 'ASC';
90 $filter = array('TYPE' => 'mail');
91 if($templateId)
92 {
93 $filter['ID'] = $templateId;
94 }
95
96 $templateDb = \CSiteTemplate::GetList(array($by => $order), $filter, array("ID", "NAME", "CONTENT", "SCREENSHOT"));
97 Loader::includeModule('fileman');
99 $replaceText = '<div style="padding: 20px; border: 2px dashed #868686;"><span style="color: #868686; font-size: 20px;">' . Loc::getMessage('PRESET_TEMPLATE_LIST_SITE_DEF_TEXT') . '</span></div>';
100 while($template = $templateDb->Fetch())
101 {
102 if($template['ID'] == 'mail_user')
103 {
104 continue;
105 }
106
107 $replaceTo = $replaceText;
108 $html = $template['CONTENT'];
109
110 $html = preg_replace('/<\?[\w\w].*?B_PROLOG_INCLUDED[^>].*?\?>/is', '', $html);
111 if(mb_stripos($html, $replaceAttr) === false)
112 {
113 $replaceTo = '<div id="bxStylistBody" ' . $replaceAttr . '>' . $replaceText . '</div>';
114 }
115
116 $html = str_replace(
117 '#WORK_AREA#',
118 $replaceTo,
119 $html
120 );
121
122 $resultList[] = array(
123 'TYPE' => 'SITE_TMPL',
124 'ID' => $template['ID'],
125 'NAME' => $template['NAME'],
126 'HTML' => $html
127 );
128 }
129
130 return $resultList;
131 }
132
136 public static function getListName()
137 {
138 $templateNameList = array(
139 'empty',
140 '1column1',
141 '1column2',
142 '2column1',
143 '2column2',
144 '2column3',
145 '2column4',
146 '2column5',
147 '2column6',
148 '2column7',
149 'dynamic1',
150 'dynamic2',
151 );
152
153 return $templateNameList;
154 }
155
160 public static function getById($templateName)
161 {
162 $result = null;
163
164 $localPathOfIcon = static::LOCAL_DIR_IMG . bx_basename($templateName) . '.png';
165 $fullPathOfIcon = Loader::getLocal($localPathOfIcon);
166
167 $fullPathOfFile = Loader::getLocal(static::LOCAL_DIR_TMPL . bx_basename($templateName) . '.php');
168 if ($fullPathOfFile && File::isFileExists($fullPathOfFile))
169 {
170 $fileContent = File::getFileContents($fullPathOfFile);
171 }
172 else
173 {
174 $fileContent = '';
175 }
176
177 if (!empty($fileContent) || $templateName == 'empty')
178 {
179 Loader::includeModule('fileman');
180 if(BlockEditor::isContentSupported($fileContent))
181 {
182 $fileContent = static::replaceTemplateByDefaultData($fileContent);
183 }
184
185 $fileContent = str_replace(
186 array('%TEXT_UNSUB_TEXT%', '%TEXT_UNSUB_LINK%'),
187 array(
188 Loc::getMessage('PRESET_MAILBLOCK_unsub_TEXT_UNSUB_TEXT'),
189 Loc::getMessage('PRESET_MAILBLOCK_unsub_TEXT_UNSUB_LINK')
190 ),
191 $fileContent
192 );
193
194 $result = array(
195 'TYPE' => 'BASE',
196 'ID' => $templateName,
197 'NAME' => Loc::getMessage('PRESET_TEMPLATE_' . $templateName),
198 'HTML' => $fileContent,
199 );
200 }
201
202 return $result;
203 }
204
209 protected static function replaceTemplateByDefaultData($template)
210 {
211 $phone = '8 495 212-85-06';
212 $phonePath = Application::getDocumentRoot() . '/include/telephone.php';
213 $logoHeader = '/include/logo.png';
214 $logoFooter = '/include/logo_mobile.png';
215 if(!File::isFileExists(Application::getDocumentRoot() . $logoHeader))
216 {
217 $logoHeader = '/bitrix/images/sender/preset/blocked1/logo.png';
218 }
219 if(!File::isFileExists(Application::getDocumentRoot() . $logoFooter))
220 {
221 $logoFooter = '/bitrix/images/sender/preset/blocked1/logo_m.png';;
222 }
223
224 if(File::isFileExists($phonePath))
225 {
226 $phone = File::getFileContents($phonePath);
227 }
228
229 $themeContent = File::getFileContents(Loader::getLocal(static::LOCAL_DIR_TMPL . 'theme.php'));
230 return str_replace(
231 array(
232 '%TEMPLATE_CONTENT%', '%LOGO_PATH_HEADER%', '%LOGO_PATH_FOOTER%', '%PHONE%',
233 '%UNSUB_LINK%', '%MENU_CONTACTS%',
234 '%MENU_HOWTO%', '%MENU_DELIVERY%',
235 '%MENU_ABOUT%', '%MENU_GUARANTEE%',
236 '%SCHEDULE_NAME%', '%SCHEDULE_DETAIL%',
237
238 '%BUTTON%', '%HEADER%',
239 '%TEXT1%', '%TEXT2%',
240 '%TEXT3%', '%TEXT4%',
241 '%TEXT5%', '%TEXT6%',
242 ),
243 array(
244 $template, $logoHeader, $logoFooter, $phone,
245 Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_UNSUB_LINK'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_MENU_CONTACTS'),
246 Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_MENU_HOWTO'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_MENU_DELIVERY'),
247 Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_MENU_ABOUT'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_MENU_GUARANTEE'),
248 Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_SCHEDULE_NAME'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_SCHEDULE_DETAIL'),
249
250 Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_BUTTON'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_HEADER'),
251 Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT1'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT2'),
252 Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT3'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT4'),
253 Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT5'), Loc::getMessage('PRESET_TEMPLATE_LIST_BLANK_TEXT6'),
254 ),
255 $themeContent
256 );
257 }
258
264 public static function update($templateName, $html)
265 {
266 $result = false;
267 $fullPathOfFile = Loader::getLocal(static::LOCAL_DIR_TMPL . bx_basename($templateName) . '.php');
268 if ($fullPathOfFile)
269 $result = File::putFileContents($fullPathOfFile, $html);
270
271 return $result;
272 }
273}
static isContentSupported($content)
Definition editor.php:1183
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static replaceTemplateByDefaultData($template)
static onPresetTemplateList($templateType=null, $templateId=null)
static update($templateName, $html)
static onPresetTemplateListSite($templateType=null, $templateId=null)