Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
editormail.php
1<?
9
16
17Loc::loadMessages(__FILE__);
18
20{
27 public static function createInstance($params)
28 {
29 $params['componentFilter'] = array('TYPE' => 'mail');
30 if (!isset($params['previewUrl']))
31 {
32 $params['previewUrl'] = '/bitrix/admin/fileman_block_editor.php?action=preview_mail';
33 }
34 if (!isset($params['saveFileUrl']))
35 {
36 $params['saveFileUrl'] = '/bitrix/admin/fileman_block_editor.php?action=save_file';
37 }
38
39 $editor = new Editor($params);
40
41 $editor->componentsAsBlocks = array(
42 'bitrix:sale.basket.basket.small.mail' => array('NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_COMPONENT_BASKET_NAME')),
43 'bitrix:sale.personal.order.detail.mail' => array('NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_COMPONENT_ORDER_NAME')),
44 'bitrix:catalog.top.mail' => array('NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_COMPONENT_CATALOG_NAME')),
45 'bitrix:sale.discount.coupon.mail' => array('NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_COMPONENT_COUPON_NAME')),
46 'bitrix:bigdata.recommends.mail' => array('NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_COMPONENT_BIGDATA_NAME')),
47 );
48
49 $editor->setBlockList(self::getBlockList());
50
51 return $editor;
52 }
53
60 public static function show(array $params)
61 {
62 $result = self::createInstance($params)->show();
63 \CJSCore::RegisterExt('block_editor_mail', array(
64 'js' => array('/bitrix/js/fileman/block_editor/mail_handlers.js'),
65 'rel' => array('core', 'block_editor')
66 ));
67 \CJSCore::Init(array('block_editor_mail'));
68
69 return $result;
70 }
71
81 public static function removePhpFromHtml($html, $previousHtml = null, $canEditPhp = false, $canUseLpa = false)
82 {
83 if (!$canEditPhp && $canUseLpa)
84 {
85 $html = \LPA::Process($html, $previousHtml);
86 }
87 else if (!$canEditPhp)
88 {
89 $phpList = \PHPParser::ParseFile($html);
90 foreach($phpList as $php)
91 {
92 $surrogate = '<span class="bxhtmled-surrogate" title="">'
93 . htmlspecialcharsbx(Loc::getMessage('BLOCK_EDITOR_BLOCK_DYNAMIC_CONTENT'))
94 .'</span>';
95 $html = str_replace($php[2], $surrogate, $html);
96 }
97
98 $html = str_replace(['<?', '?>'], ['< ?', '? >'], $html);
99 }
100
101 return $html;
102 }
103
110 public static function getPreview(array $params)
111 {
112 $site = $params['SITE'];
113 $html = $params['HTML'];
114
115 if(isset($params['FIELDS']))
116 {
117 $fields = $params['FIELDS'];
118 }
119 else
120 {
121 $fields = array();
122 }
123
124 $canEditPhp = (isset($params['CAN_EDIT_PHP']) && $params['CAN_EDIT_PHP']);
125 $canUseLpa = (isset($params['CAN_USE_LPA']) && $params['CAN_USE_LPA']);
126 $html = static::removePhpFromHtml($html, null, $canEditPhp, $canUseLpa);
127
128 if(is_object($GLOBALS["USER"]))
129 {
130 /* @var $GLOBALS["USER"] \CUser */
131 $fields['EMAIL_TO'] = htmlspecialcharsbx($GLOBALS["USER"]->GetEmail());
132 $fields['USER_ID'] = $GLOBALS["USER"]->GetID();
133 $fields['NAME'] = htmlspecialcharsbx($GLOBALS["USER"]->GetFirstName() ?: $GLOBALS["USER"]->GetLastName());
134 }
135
136 $siteDb = SiteTable::getList(array(
137 'select' => array('LID', 'SERVER_NAME', 'SITE_NAME', 'CULTURE_CHARSET'=>'CULTURE.CHARSET'),
138 'filter' => array('LID' => $site)
139 ));
140 if(!$siteRow = $siteDb->fetch())
141 {
142 $siteDb = SiteTable::getList(array(
143 'select' => array('LID', 'SERVER_NAME', 'SITE_NAME', 'CULTURE_CHARSET'=>'CULTURE.CHARSET'),
144 'filter' => array('DEF' => true)
145 ));
146 $siteRow = $siteDb->fetch();
147 }
148
149 $fields['SITE_NAME'] = $siteRow['SITE_NAME'];
150 $fields['SERVER_NAME'] = $siteRow['SERVER_NAME'];
151 $charset = $siteRow['CULTURE_CHARSET'];
152
153 $messageParams = array(
154 'FIELDS' => $fields,
155 'MESSAGE' => array(
156 'BODY_TYPE' => 'html',
157 'EMAIL_TO' => '#EMAIL_TO#',
158 'MESSAGE' => $html,
159 ),
160 'SITE' => $siteRow['LID'],
161 'CHARSET' => $charset,
162 );
163
164 $event = new Event("main", "OnBeforeBlockEditorMailPreview", $messageParams);
165 $event->send();
166 foreach ($event->getResults() as $eventResult)
167 {
168 if($eventResult->getType() !== EventResult::ERROR)
169 {
170 $messageParams = array_merge($messageParams, $eventResult->getParameters());
171 }
172 }
173
174 $message = EventMessageCompiler::createInstance($messageParams);
175 $message->compile();
176 $html = $message->getMailBody();
177 $inlineHtml = StyleInliner::inlineHtml($html);
178
179 $eventParams = array('HTML' => $html, 'INLINE_HTML' => $inlineHtml);
180 $event = new Event("main", "OnAfterBlockEditorMailPreview", $eventParams);
181 $event->send();
182 foreach ($event->getResults() as $eventResult)
183 {
184 if($eventResult->getType() !== EventResult::ERROR)
185 {
186 $eventParams = array_merge($eventParams, $eventResult->getParameters());
187 }
188 }
189
190 //return $eventParams['HTML'];
191 return $eventParams['INLINE_HTML'];
192 }
193
199 public static function getBlockList()
200 {
201 return array(
202 array(
203 'CODE' => 'text', 'NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_TEXT_NAME'),
204 'DESC' => Loc::getMessage('BLOCK_EDITOR_BLOCK_TEXT_DESC'),
205 'HTML' => '
206 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockText">
207 <tbody class="bxBlockOut">
208 <tr>
209 <td valign="top" class="bxBlockInn bxBlockInnText">
210 <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%">
211 <tbody>
212 <tr>
213 <td valign="top" class="bxBlockPadding bxBlockContentText">
214 ' . Loc::getMessage('BLOCK_EDITOR_BLOCK_TEXT_EXAMPLE') . '
215 </td>
216 </tr>
217 </tbody>
218 </table>
219 </td>
220 </tr>
221 </tbody>
222 </table>
223 '
224 ),
225 array(
226 'CODE' => 'boxedtext', 'NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_BOXEDTEXT_NAME'),
227 'DESC' => Loc::getMessage('BLOCK_EDITOR_BLOCK_BOXEDTEXT_DESC'),
228 'HTML' => '
229 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockBoxedText">
230 <tbody class="bxBlockOut">
231 <tr>
232 <td valign="top" class="bxBlockInn bxBlockInnBoxedText" >
233 <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%">
234 <tbody>
235 <tr>
236 <td valign="top" class="bxBlockPadding">
237 <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockContentEdge" style="border: 1px solid rgb(153, 153, 153); background-color: rgb(235, 235, 235);">
238 <tbody>
239 <tr>
240 <td valign="top" class="bxBlockPadding bxBlockContentText">
241 ' . Loc::getMessage('BLOCK_EDITOR_BLOCK_BOXEDTEXT_EXAMPLE') . '
242 </td>
243 </tr>
244 </tbody>
245 </table>
246 </td>
247 </tr>
248 </tbody>
249 </table>
250 </td>
251 </tr>
252 </tbody>
253 </table>
254 '
255 ),
256 array(
257 'CODE' => 'line', 'NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_LINE_NAME'),
258 'DESC' => Loc::getMessage('BLOCK_EDITOR_BLOCK_LINE_DESC'),
259 'HTML' => '
260 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockLine">
261 <tbody class="bxBlockOut">
262 <tr>
263 <td valign="top" class="bxBlockInn bxBlockInnLine">
264 <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%">
265 <tbody>
266 <tr>
267 <td valign="top" class="bxBlockPadding">
268 <span class="bxBlockContentLine" style="height: 2px; background-color: #EBEBEB; display: block;"></span>
269 </td>
270 </tr>
271 </tbody>
272 </table>
273 </td>
274 </tr>
275 </tbody>
276 </table>
277 '
278 ),
279 array(
280 'CODE' => 'image', 'NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_IMAGE_NAME'),
281 'DESC' => Loc::getMessage('BLOCK_EDITOR_BLOCK_IMAGE_DESC'),
282 'HTML' => '
283 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockImage">
284 <tbody class="bxBlockOut">
285 <tr>
286 <td valign="top" class="bxBlockInn bxBlockInnImage">
287 <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%">
288 <tbody>
289 <tr>
290 <td valign="top" class="bxBlockPadding bxBlockContentImage" style="text-align: center">
291 <a href="#">
292 <img align="center" data-bx-editor-def-image="1" src="/bitrix/images/fileman/block_editor/photo-default.png" class="bxImage">
293 </a>
294 </td>
295 </tr>
296 </tbody>
297 </table>
298 </td>
299 </tr>
300 </tbody>
301 </table>
302 '
303 ),
304 array(
305 'CODE' => 'imagegroup', 'NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_IMAGEGROUP_NAME'),
306 'DESC' => Loc::getMessage('BLOCK_EDITOR_BLOCK_IMAGEGROUP_DESC'),
307 'HTML' => '
308 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockImageGroup">
309 <tbody class="bxBlockOut">
310 <tr>
311 <td valign="top" class="bxBlockInn bxBlockInnImageGroup">
312 <table align="left" border="0" cellpadding="0" cellspacing="0">
313 <tbody>
314 <tr>
315 <td valign="top" class="bxBlockContentImageGroup">
316 <table align="left" border="0" cellpadding="0" cellspacing="0" width="260" >
317 <tbody>
318 <tr>
319 <td valign="top" class="bxBlockPadding bxBlockContentImage">
320 <img align="left" data-bx-editor-def-image="1" src="/bitrix/images/fileman/block_editor/photo-default.png" class="bxImage">
321 </td>
322 </tr>
323 </tbody>
324 </table><table align="left" border="0" cellpadding="0" cellspacing="0" width="260">
325 <tbody>
326 <tr>
327 <td valign="top" class="bxBlockPadding bxBlockContentImage">
328 <img align="left" data-bx-editor-def-image="1" src="/bitrix/images/fileman/block_editor/photo-default.png" class="bxImage">
329 </td>
330 </tr>
331 </tbody>
332 </table>
333 </td>
334 </tr>
335 </tbody>
336 </table>
337 </td>
338 </tr>
339 </tbody>
340 </table>
341 '
342 ),
343 array(
344 'CODE' => 'boxedimage', 'NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_BOXEDIMAGE_NAME'),
345 'DESC' => Loc::getMessage('BLOCK_EDITOR_BLOCK_BOXEDIMAGE_DESC'),
346 'HTML' => '
347 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockBoxedImage">
348 <tbody class="bxBlockOut">
349 <tr>
350 <td valign="top" class="bxBlockInn bxBlockInnBoxedImage">
351 <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%">
352 <tbody>
353 <tr>
354 <td valign="top" class="bxBlockPadding">
355 <table width="100%" align="left" border="0" cellpadding="0" cellspacing="0" class="bxBlockContentEdge" style="border: 1px solid rgb(153, 153, 153); background-color: rgb(235, 235, 235);">
356 <tbody>
357 <tr>
358 <td valign="top" class="bxBlockPadding bxBlockContentImage" style="text-align: center;">
359 <a href="#">
360 <img align="center" data-bx-editor-def-image="1" src="/bitrix/images/fileman/block_editor/photo-default.png" class="bxImage">
361 </a>
362 </td>
363 </tr>
364 <tr>
365 <td valign="top" class="bxBlockPadding bxBlockContentText" style="text-align: center;">
366 ' . Loc::getMessage('BLOCK_EDITOR_BLOCK_TEXT_EXAMPLE') . '
367 </td>
368 </tr>
369 </tbody>
370 </table>
371 </td>
372 </tr>
373 </tbody>
374 </table>
375 </td>
376 </tr>
377 </tbody>
378 </table>
379 '
380 ),
381 array(
382 'CODE' => 'imagetext', 'NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_IMAGETEXT_NAME'),
383 'DESC' => Loc::getMessage('BLOCK_EDITOR_BLOCK_IMAGETEXT_DESC'),
384 'HTML' => '
385 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockImageText">
386 <tbody class="bxBlockOut">
387 <tr>
388 <td valign="top" class="bxBlockInn bxBlockInnImageText">
389 <table align="left" border="0" cellpadding="0" cellspacing="0" class="bxBlockContentItemImageText" width="290">
390 <tbody>
391 <tr>
392 <td valign="top" class="bxBlockPadding bxBlockContentImage">
393 <a href="#">
394 <img data-bx-editor-def-image="1" src="/bitrix/images/fileman/block_editor/photo-default.png" class="bxImage">
395 </a>
396 </td>
397 </tr>
398 </tbody>
399 </table>
400
401 <table align="left" border="0" cellpadding="0" cellspacing="0" class="bxBlockContentItemImageText" width="290">
402 <tbody>
403 <tr>
404 <td valign="top" class="bxBlockPadding bxBlockContentText">
405 ' . Loc::getMessage('BLOCK_EDITOR_BLOCK_TEXT_EXAMPLE') . '
406 </td>
407 </tr>
408 </tbody>
409 </table>
410 </td>
411 </tr>
412 </tbody>
413 </table>
414 '
415 ),
416 array(
417 'CODE' => 'button', 'NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_BUTTON_NAME'),
418 'DESC' => Loc::getMessage('BLOCK_EDITOR_BLOCK_BUTTON_DESC'),
419 'HTML' => '
420 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockButton">
421 <tbody class="bxBlockOut">
422 <tr>
423 <td valign="top" class="bxBlockPadding bxBlockInn bxBlockInnButton">
424 <table align="center" border="0" cellpadding="0" cellspacing="0" class="bxBlockContentButtonEdge">
425 <tbody>
426 <tr>
427 <td valign="top">
428 <a
429 class="bxBlockContentButton"
430 title="' . Loc::getMessage('BLOCK_EDITOR_BLOCK_BUTTON_EXAMPLE') . '"
431 href="/"
432 target="_blank"
433 >
434 ' . Loc::getMessage('BLOCK_EDITOR_BLOCK_BUTTON_EXAMPLE') . '
435 </a>
436 </td>
437 </tr>
438 </tbody>
439 </table>
440 </td>
441 </tr>
442 </tbody>
443 </table>
444 '
445 ),
446 array(
447 'CODE' => 'code', 'NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_CODE_NAME'),
448 'DESC' => Loc::getMessage('BLOCK_EDITOR_BLOCK_CODE_DESC'),
449 'HTML' => '
450 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockCode">
451 <tbody class="bxBlockOut">
452 <tr>
453 <td valign="top" class="bxBlockPadding bxBlockInn bxBlockInnCode">
454 ' . Loc::getMessage('BLOCK_EDITOR_BLOCK_CODE_EXAMPLE') . '
455 </td>
456 </tr>
457 </tbody>
458 </table>'
459 ),
460 array(
461 'CODE' => 'footer', 'TYPE' => 'text', 'NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_FOOTER_NAME'),
462 'DESC' => Loc::getMessage('BLOCK_EDITOR_BLOCK_FOOTER_DESC'),
463 'HTML' => '
464 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockText">
465 <tbody class="bxBlockOut">
466 <tr>
467 <td valign="top" class="bxBlockInn bxBlockInnText" >
468 <table align="left" border="0" cellpadding="0" cellspacing="0" width="100%">
469 <tbody>
470 <tr>
471 <td valign="top" class="bxBlockPadding bxBlockContentText" style="text-align: center;">
472 <br><a href="#UNSUBSCRIBE_LINK#">' . Loc::getMessage('BLOCK_EDITOR_BLOCK_FOOTER_EXAMPLE') . '</a>
473 <br><a href="#CONSENT_LINK#">' . Loc::getMessage('BLOCK_EDITOR_BLOCK_FOOTER_CONSENT_EXAMPLE') . '</a>
474 </td>
475 </tr>
476 </tbody>
477 </table>
478 </td>
479 </tr>
480 </tbody>
481 </table>
482 '
483 ),
484 array(
485 'CODE' => 'social', 'NAME' => Loc::getMessage('BLOCK_EDITOR_BLOCK_SOCIAL_NAME'),
486 'DESC' => Loc::getMessage('BLOCK_EDITOR_BLOCK_SOCIAL_DESC'),
487 'HTML' => '
488 <table border="0" cellpadding="0" cellspacing="0" width="100%" class="bxBlockSocial">
489 <tbody class="bxBlockOut">
490 <tr>
491 <td valign="top" class="bxBlockInn bxBlockInnSocial" >
492
493 <table align="center" border="0" cellpadding="0" cellspacing="0" class="bxBlockContentEdgeSocial">
494 <tbody>
495 <tr>
496 <td valign="top" class="bxBlockPadding">
498 <table align="left" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate !important; margin-right: 10px;">
499 <tbody>
500 <tr>
501 <td valign="top" class="" style="padding-top: 5px; padding-right: 10px; padding-bottom: 5px; padding-left: 10px;">
502 <a
503 class="bxBlockContentSocial"
504 href="http://vk.com/"
505 target="_blank"
506 style="font-weight: bold; color: #626262; letter-spacing: normal;line-height: 100%;text-align: center; text-decoration: underline; font-size: 12px;"
507 >' . Loc::getMessage('BLOCK_EDITOR_BLOCK_SOCIAL_VK') . '</a>
508 </td>
509 </tr>
510 </tbody>
511 </table>
512 ' : '') . '
513
514 <table align="left" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate !important; margin-right: 10px;">
515 <tbody>
516 <tr>
517 <td valign="top" class="" style="padding-top: 5px; padding-right: 10px; padding-bottom: 5px; padding-left: 10px; font-size: 12px;">
518 <a
519 class="bxBlockContentSocial"
520 href="http://facebook.com/"
521 target="_blank"
522 style="font-weight: bold; color: #626262; letter-spacing: normal;line-height: 100%;text-align: center; text-decoration: underline; font-size: 12px;"
523 >' . Loc::getMessage('BLOCK_EDITOR_BLOCK_SOCIAL_FACEBOOK') . '</a>
524 </td>
525 </tr>
526 </tbody>
527 </table>
528
529 <table align="left" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate !important; margin-right: 10px;">
530 <tbody>
531 <tr>
532 <td valign="top" class="" style="padding-top: 5px; padding-right: 10px; padding-bottom: 5px; padding-left: 10px; font-size: 12px;">
533 <a
534 class="bxBlockContentSocial"
535 href="http://www.instagram.com/"
536 target="_blank"
537 style="font-weight: bold; color: #626262; letter-spacing: normal;line-height: 100%;text-align: center; text-decoration: underline; font-size: 12px;"
538 >' . Loc::getMessage('BLOCK_EDITOR_BLOCK_SOCIAL_INSTAGRAM') . '</a>
539 </td>
540 </tr>
541 </tbody>
542 </table>
543
545 <table align="left" border="0" cellpadding="0" cellspacing="0" style="border-collapse: separate !important; margin-right: 10px;">
546 <tbody>
547 <tr>
548 <td valign="top" class="" style="padding-top: 5px; padding-right: 10px; padding-bottom: 5px; padding-left: 10px; font-size: 12px;">
549 <a
550 class="bxBlockContentSocial"
551 href="http://twitter.com/"
552 target="_blank"
553 style="font-weight: bold; color: #626262; letter-spacing: normal;line-height: 100%;text-align: center; text-decoration: underline; font-size: 12px;"
554 >' . Loc::getMessage('BLOCK_EDITOR_BLOCK_SOCIAL_TWITTER') . '</a>
555 </td>
556 </tr>
557 </tbody>
558 </table>
559 ' : '') . '
560
561 </td>
562 </tr>
563 </tbody>
564 </table>
565
566 </td>
567 </tr>
568 </tbody>
569 </table>
570 '
571 ),
572 );
573 }
574}
static removePhpFromHtml($html, $previousHtml=null, $canEditPhp=false, $canUseLpa=false)
static getPreview(array $params)
static show(array $params)
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static createInstance(array $arMessageParams)
static inlineHtml($html, array $styleList=null)