Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
util.php
1<?php
2
4
9
10class Util
11{
12 public static function getPermissionsByExternalAuthId($authId)
13 {
14 $result = array(
15 'message' => true
16 );
17
18 if ($authId == 'email')
19 {
20 $result['message'] = (!ModuleManager::isModuleInstalled('mail'));
21 }
22
23 return $result;
24 }
25
26 public static function getSiteIdByLogId($logId)
27 {
28 $extranetSiteId = false;
29 if (Loader::includeModule('extranet'))
30 {
31 $extranetSiteId = \CExtranet::getExtranetSiteId();
32 }
33
34 $logSiteId = array();
35 $res = \CSocNetLog::getSite($logId);
36 while ($logSite = $res->fetch())
37 {
38 $logSiteId[] = $logSite["LID"];
39 }
40
41 return (
42 $extranetSiteId
43 && count($logSiteId) == 1
44 && $logSiteId[0] == $extranetSiteId
45 ? $extranetSiteId
46 : $logSiteId[0]
47 );
48 }
49
50 public static function notifyMail($fields)
51 {
52 if (!Loader::includeModule('mail'))
53 {
54 return false;
55 }
56
57 if (
58 !isset($fields["logEntryId"])
59 || intval($fields["logEntryId"]) <= 0
60 || !isset($fields["userId"])
61 || !isset($fields["logEntryUrl"])
62 || $fields["logEntryUrl"] == ''
63 )
64 {
65 return false;
66 }
67
68 if (!is_array($fields["userId"]))
69 {
70 $fields["userId"] = array($fields["userId"]);
71 }
72
73 if (!isset($fields["siteId"]))
74 {
75 $fields["siteId"] = SITE_ID;
76 }
77
78 $nameTemplate = \CSite::getNameFormat("", $fields["siteId"]);
79 $authorName = "";
80
81 if (!empty($fields["authorId"]))
82 {
83 $res = \CUser::getById($fields["authorId"]);
84 if ($author = $res->fetch())
85 {
86 $authorName = \CUser::formatName(
87 $nameTemplate,
88 $author,
89 true,
90 false
91 );
92 }
93 else
94 {
95 $authorName = '';
96 }
97
98 if (check_email($authorName))
99 {
100 $authorName = '"'.$authorName.'"';
101 }
102
103 foreach($fields["userId"] as $key => $val)
104 {
105 if (intval($val) == intval($fields["authorId"]))
106 {
107 unset($fields["userId"][$key]);
108 }
109 }
110 }
111
112 if (empty($fields["userId"]))
113 {
114 return false;
115 }
116
117 if (
118 !isset($fields["type"])
119 || !in_array(mb_strtoupper($fields["type"]), array("LOG_ENTRY", "LOG_COMMENT"))
120 )
121 {
122 $fields["type"] = "LOG_COMMENT";
123 }
124
125 $arEmail = \Bitrix\Mail\User::getUserData($fields["userId"], $nameTemplate);
126 if (empty($arEmail))
127 {
128 return false;
129 }
130
131 $arLogEntry = \CSocNetLog::getByID(intval($fields["logEntryId"]));
132 if (!$arLogEntry)
133 {
134 return false;
135 }
136
137 $logEntryTitle = str_replace(array("\r\n", "\n"), " ", ($arLogEntry["TITLE"] != '__EMPTY__' ? $arLogEntry["TITLE"] : $arLogEntry["MESSAGE"]));
138 $logEntryTitle = truncateText($logEntryTitle, 100);
139
140 switch(mb_strtoupper($fields["type"]))
141 {
142 case "LOG_COMMENT":
143 $mailMessageId = "<LOG_COMMENT_".$fields["logCommentId"]."@".$GLOBALS["SERVER_NAME"].">";
144 $mailTemplateType = "SONET_LOG_NEW_COMMENT";
145 break;
146 default:
147 $mailMessageId = "<LOG_ENTRY_".$fields["logEntryId"]."@".$GLOBALS["SERVER_NAME"].">";
148 $mailTemplateType = "SONET_LOG_NEW_ENTRY";
149 }
150
151 $mailMessageInReplyTo = "<LOG_ENTRY_".$fields["logEntryId"]."@".$GLOBALS["SERVER_NAME"].">";
152 $defaultEmailFrom = \Bitrix\Mail\User::getDefaultEmailFrom();
153
154 foreach ($arEmail as $userId => $user)
155 {
156 $email = $user["EMAIL"];
157 $nameFormatted = str_replace(array('<', '>', '"'), '', $user["NAME_FORMATTED"]);
158
159 if (
160 intval($userId) <= 0
161 && $email == ''
162 )
163 {
164 continue;
165 }
166
167 $res = \Bitrix\Mail\User::getReplyTo(
168 $fields["siteId"],
169 $userId,
170 'LOG_ENTRY',
171 $fields["logEntryId"],
172 $fields["logEntryUrl"]
173 );
174 if (is_array($res))
175 {
176 list($replyTo, $backUrl) = $res;
177
178 if (
179 $replyTo
180 && $backUrl
181 )
182 {
183 $authorName = str_replace(array('<', '>', '"'), '', $authorName);
184 \CEvent::send(
185 $mailTemplateType,
186 $fields["siteId"],
187 array(
188 "=Reply-To" => $authorName.' <'.$replyTo.'>',
189 "=Message-Id" => $mailMessageId,
190 "=In-Reply-To" => $mailMessageInReplyTo,
191 "EMAIL_FROM" => $authorName.' <'.$defaultEmailFrom.'>',
192 "EMAIL_TO" => (!empty($nameFormatted) ? ''.$nameFormatted.' <'.$email.'>' : $email),
193 "RECIPIENT_ID" => $userId,
194 "COMMENT_ID" => (isset($fields["logCommentId"]) ? intval($fields["logCommentId"]) : false),
195 "LOG_ENTRY_ID" => intval($fields["logEntryId"]),
196 "LOG_ENTRY_TITLE" => $logEntryTitle,
197 "URL" => $fields["logEntryUrl"]
198 )
199 );
200 }
201 }
202 }
203
204 return true;
205 }
206
207 public static function getEqualityFields(&$fields)
208 {
209 $fields1 = array();
210 foreach ($fields as $key => $value)
211 {
212 if (mb_substr($key, 0, 1) == "=")
213 {
214 $fields1[mb_substr($key, 1)] = $value;
215 unset($fields[$key]);
216 }
217 }
218
219 return $fields1;
220 }
221
222 public static function processEqualityFieldsToInsert($fields1, &$insert)
223 {
224 foreach ($fields1 as $key => $value)
225 {
226 if ($insert[0] <> '')
227 {
228 $insert[0] .= ", ";
229 }
230 $insert[0] .= $key;
231 if ($insert[1] <> '')
232 {
233 $insert[1] .= ", ";
234 }
235 $insert[1] .= $value;
236 }
237 }
238
239 public static function processEqualityFieldsToUpdate($fields1, &$update)
240 {
241 foreach ($fields1 as $key => $value)
242 {
243 if ($update <> '')
244 {
245 $update .= ", ";
246 }
247 $update .= $key."=".$value." ";
248 }
249 }
250
251 public static function detectTags($fieldList, $codeList = array())
252 {
253 static $parser = null;
254
255 $result = array();
256
257 if (
258 !is_array($fieldList)
259 || !is_array($codeList)
260 )
261 {
262 return false;
263 }
264
265 foreach($codeList as $code)
266 {
267 if (
268 empty($code)
269 || empty($fieldList[$code])
270 )
271 {
272 continue;
273 }
274
275 if ($parser === null)
276 {
277 $parser = new \CTextParser();
278 }
279
280 $result = array_merge($result, $parser->detectTags($fieldList[$code]));
281 }
282
283 return array_unique($result);
284 }
285}
286?>
static processEqualityFieldsToUpdate($fields1, &$update)
Definition util.php:239
static getSiteIdByLogId($logId)
Definition util.php:26
static getPermissionsByExternalAuthId($authId)
Definition util.php:12
static detectTags($fieldList, $codeList=array())
Definition util.php:251
static getEqualityFields(&$fields)
Definition util.php:207
static processEqualityFieldsToInsert($fields1, &$insert)
Definition util.php:222
static notifyMail($fields)
Definition util.php:50
$GLOBALS['____1444769544']
Definition license.php:1