Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
actionpreview.php
1<?php
9
11use Bitrix\Main;
18
19Loc::loadMessages(__FILE__);
20
26{
27 const NAME = 'preview';
28
35 public static function onRequest(Main\HttpRequest $request, Controller\Response $response)
36 {
37 $content = $response->initContentHtml();
38
39 Main\Loader::includeModule('fileman');
40
41 $canEditPhp = Security\User::current()->canEditPhp();
42 $canUseLpa = Security\User::current()->canUseLpa();
43
44 $tracker = (new Tracker(Tracker::TYPE_UNSUB))
45 ->setModuleId('sender')
46 ->setFields(array(
47 'RECIPIENT_ID' => 0,
48 'MAILING_ID' => 0,
49 'EMAIL' => 'test@example.com',
50 'CODE' => 'test@example.com',
51 'TEST' => 'Y'
52 ))
53 ->setHandlerUri(Option::get('sender', 'unsub_link'));
54
55 $html = $request->getPostList()->getRaw('content');
56 preg_match_all("/#([0-9a-zA-Z_.]+?)#/", $html, $personalizeFields);
57 $fieldsData = [];
58
59 if(is_object($GLOBALS["USER"]) && isset($personalizeFields[1]))
60 {
61 foreach ($personalizeFields[1] as $field)
62 {
63 $fieldArray = explode(".", $field);
64 if(count($fieldArray) > 1)
65 {
66 $document = Helper::getData(
67 $fieldArray[0], [$GLOBALS["USER"]->GetID()]
68 );
69 if(!isset($document[1]))
70 {
71 continue;
72 }
73 $document = $document[1];
74
75 $fieldsData[$field] = $document
76 && isset($document[$fieldArray[1]])
77 ? $document[$fieldArray[1]] :'';
78 }
79 }
80 }
81
82 $previewParams = array(
83 'CAN_EDIT_PHP' => $canEditPhp,
84 'CAN_USE_LPA' => $canUseLpa,
85 'SITE' => $request->get('site_id') ?: SITE_ID,
86 'HTML' => ($html && Main\Text\Encoding::detectUtf8($html))
87 ? Main\Text\Encoding::convertEncoding(
88 $html,
89 'UTF-8',
90 SITE_CHARSET
91 )
92 : $html
93 ,
94 'FIELDS' => array_merge($fieldsData, array(
95 'SENDER_CHAIN_CODE' => 'sender_chain_item_0',
96 'UNSUBSCRIBE_LINK' => $tracker->getLink()
97 )),
98 );
99
100 $html = EditorMail::getPreview($previewParams);
101 $content->set($html);
102 }
103}
static getPreview(array $params)
static loadMessages($file)
Definition loc.php:64
static onRequest(Main\HttpRequest $request, Controller\Response $response)
$GLOBALS['____1444769544']
Definition license.php:1