Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
logevent.php
1<?php
2
4
9
10Loc::loadMessages(__FILE__);
11
12final class LogEvent extends Provider
13{
14 public const PROVIDER_ID = 'SONET_LOG';
15 public const CONTENT_TYPE_ID = 'LOG_ENTRY';
16
17 public static function getId(): string
18 {
19 return static::PROVIDER_ID;
20 }
21
22 public function getEventId(): array
23 {
24 return [ 'data' ];
25 }
26
27 public function getType(): string
28 {
30 }
31
32 public static function canRead($params): bool
33 {
34 return true;
35 }
36
37 protected function getPermissions(array $post): string
38 {
40 }
41
42 public function getCommentProvider(): Provider
43 {
44 return new LogComment();
45 }
46
47 public function initSourceFields()
48 {
49 static $cache = [];
50 static $schemeCache = [];
51
53
54 if ($logId <= 0)
55 {
56 return;
57 }
58
59 if (isset($cache[$logId]))
60 {
61 $logEntryFields = $cache[$logId];
62 }
63 else
64 {
65 $res = LogTable::getList([
66 'filter' => [
67 '=ID' => $logId,
68 '@EVENT_ID' => $this->getEventId(),
69 ],
70 'select' => [ 'ID', 'TITLE', 'MESSAGE', 'PARAMS' ]
71 ]);
72
73 $logEntryFields = $res->fetch();
74 $cache[$logId] = $logEntryFields;
75 }
76
77 if (empty($logEntryFields))
78 {
79 return;
80 }
81
82 $entryParams = unserialize($logEntryFields['PARAMS'], [ 'allowed_classes' => false ]);
83
84 if (
85 !is_array($entryParams)
86 && !empty($logEntryFields['PARAMS'])
87 )
88 {
89 $tmp = explode("&", $logEntryFields['PARAMS']);
90 if (is_array($tmp) && count($tmp) > 0)
91 {
92 $entryParams = array();
93 foreach($tmp as $pair)
94 {
95 [$key, $value] = explode("=", $pair);
96 $entryParams[$key] = $value;
97 }
98 }
99 }
100
101 $html = false;
102 $logEntryFields['SCHEME_FIELDS'] = [];
103
104 $schemeId = (is_array($entryParams) && isset($entryParams['SCHEME_ID']) ? (int)$entryParams['SCHEME_ID'] : 0);
105 if ($schemeId > 0)
106 {
107 $schemeFields = [];
108 if (isset($schemeCache[$schemeId]))
109 {
110 $schemeFields = $schemeCache[$schemeId];
111 }
112 elseif (Loader::includeModule('xdimport'))
113 {
114 $res = \CXDILFScheme::getById($schemeId);
115 $schemeFields = $res->fetch();
116 $schemeCache[$schemeId] = $schemeFields;
117 }
118
119 $logEntryFields['SCHEME_FIELDS'] = $schemeFields;
120 }
121
122 $this->setLogId($logEntryFields['ID']);
123 $this->setSourceFields($logEntryFields);
124 $this->setSourceTitle($logEntryFields['TITLE']);
125
126 if (
127 !empty($logEntryFields['SCHEME_FIELDS'])
128 && isset($logEntryFields['SCHEME_FIELDS']['IS_HTML'])
129 )
130 {
131 $html = ($logEntryFields['SCHEME_FIELDS']['IS_HTML'] === "Y");
132 }
133
134 if ($html)
135 {
136 $description = htmlspecialcharsback($logEntryFields['MESSAGE']);
137 $sanitizer = new \CBXSanitizer();
138 $sanitizer->applyDoubleEncode(false);
139 $sanitizer->setLevel(\CBXSanitizer::SECURE_LEVEL_LOW);
140 $this->setSourceDescription($sanitizer->sanitizeHtml($description));
141 }
142 else
143 {
144 $this->setSourceDescription(htmlspecialcharsEx($logEntryFields['MESSAGE']));
145 }
146 }
147
148 public function getPinnedTitle(): string
149 {
150 $result = '';
151
152 if (empty($this->sourceFields))
153 {
154 $this->initSourceFields();
155 }
156
157 $logEntryFields = $this->getSourceFields();
158 if (empty($logEntryFields))
159 {
160 return $result;
161 }
162
163 $result = Loc::getMessage('SONET_LIVEFEED_LOG_DATA_PINNED_TITLE');
164
165 if (
166 !empty($logEntryFields['SCHEME_FIELDS'])
167 && isset($logEntryFields['SCHEME_FIELDS']['NAME'])
168 )
169 {
170 $result = Loc::getMessage('SONET_LIVEFEED_LOG_DATA_PINNED_TITLE2', [
171 '#TITLE#' => $logEntryFields['SCHEME_FIELDS']['NAME']
172 ]);
173 }
174
175 return $result;
176 }
177
178 public function getPinnedDescription()
179 {
180 $result = '';
181
182 if (empty($this->sourceFields))
183 {
184 $this->initSourceFields();
185 }
186
187 $logEntryFields = $this->getSourceFields();
188 if (empty($logEntryFields))
189 {
190 return $result;
191 }
192
193 $html = false;
194
195 if (
196 !empty($logEntryFields['SCHEME_FIELDS'])
197 && isset($logEntryFields['SCHEME_FIELDS']['IS_HTML'])
198 )
199 {
200 $html = ($logEntryFields['SCHEME_FIELDS']['IS_HTML'] === "Y");
201 }
202
203 if ($html)
204 {
205 $result = htmlspecialcharsback($logEntryFields['MESSAGE']);
206 $result = truncateText(\CTextParser::clearAllTags($result), 100);
207 }
208 else
209 {
210 $result = truncateText(htmlspecialcharsEx($logEntryFields['MESSAGE']), 100);
211 }
212
213 return $result;
214 }
215
216 public function getLiveFeedUrl(): string
217 {
218 $pathToLogEntry = '';
219
220 $logId = $this->getLogId();
221 if ($logId)
222 {
223 $pathToLogEntry = Option::get('socialnetwork', 'log_entry_page', '', $this->getSiteId());
224 if (!empty($pathToLogEntry))
225 {
226 $pathToLogEntry = \CComponentEngine::makePathFromTemplate($pathToLogEntry, array("log_id" => $logId));
227 }
228 }
229
230 return $pathToLogEntry;
231 }
232
233 public function getSuffix(): string
234 {
235 return '2';
236 }
237}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static getList(array $parameters=array())