Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
share.php
1<?php
2
4
10
11Loc::loadMessages(__FILE__);
12
13final class Share extends Base
14{
15 public const TYPE = 'SHARE';
16 public const POST_TEXT = 'commentAuxShare';
17
18 public function getParamsFromFields($fields = []): array
19 {
20 $params = [];
21
22 if (!empty($fields['SHARE_DEST']))
23 {
24 $params['mention'] = $shareDestValue = false;
25 $valuesList = explode('|', $fields['SHARE_DEST']);
26 foreach ($valuesList as $value)
27 {
28 if ($value !== 'mention')
29 {
30 $shareDestValue = $value;
31 }
32 else
33 {
34 $params['mention'] = true;
35 }
36 }
37
38 if ($shareDestValue)
39 {
40 $destinationList = explode(',', $shareDestValue);
41 if (!empty($destinationList))
42 {
43 foreach ($destinationList as $key => $value)
44 {
45 $destinationList[$key] = trim($value);
46 }
47 $params['destinationList'] = $destinationList;
48 }
49 }
50 }
51
52 if (!empty($fields['HIDDEN_DEST']))
53 {
54 $params['hiddenDestinationList'] = $fields['HIDDEN_DEST'];
55 }
56
57 if (
58 !empty($fields['PATH_ENTITY_TYPE'])
59 && !empty($fields['PATH_ENTITY_ID'])
60 )
61 {
62 $params['pathEntityType'] = $fields['PATH_ENTITY_TYPE'];
63 $params['pathEntityId'] = (int)$fields['PATH_ENTITY_ID'];
64 }
65
66 return $params;
67 }
68
69 public function getText(): string
70 {
71 static $parser = null;
72 static $availableUsersList = null;
73
74 $result = '';
77 $newRightsNameList = [];
78
79 if (
80 empty($params['destinationList'])
81 || !is_array($params['destinationList'])
82 )
83 {
84 return $result;
85 }
86
87 $currentUserExtranet = (
88 (!isset($options['bPublicPage']) || !$options['bPublicPage'])
90 );
91 if (
92 $availableUsersList === null
93 && Loader::includeModule('extranet')
94 )
95 {
96 $availableUsersList = ($currentUserExtranet ? \CExtranet::getMyGroupsUsers(SITE_ID) : []);
97 }
98
99 foreach ($params['destinationList'] as $destinationCode)
100 {
101 $hiddenDestination = (
102 isset($params['hiddenDestinationList'])
103 && is_array($params['hiddenDestinationList'])
104 && in_array($destinationCode, $params['hiddenDestinationList'])
105 );
106
107 if (
108 !$hiddenDestination
109 || (
110 isset($params['mention'])
111 && $params['mention']
112 )
113 )
114 {
115 if (preg_match('/^(SG|U||UA|DR)(\d*)$/', $destinationCode, $matches))
116 {
117 $entityType = $matches[1];
118 $entityId = ($matches[2] ?? false);
119 $hiddenEntity = $renderParts = false;
120
121 switch($entityType)
122 {
123 case 'SG':
124 $renderParts = new Livefeed\RenderParts\SonetGroup($options);
125 break;
126 case 'U':
127 case 'UA':
128 if (
129 $currentUserExtranet
130 && $entityType === 'U'
131 && (
132 !isset($params['mention'])
133 || !$params['mention']
134 )
135 && !in_array($entityId, $availableUsersList)
136 )
137 {
138 $hiddenEntity = true;
139 }
140 else
141 {
142 $renderParts = new Livefeed\RenderParts\User(array_merge($options, [ 'skipLink' => $hiddenDestination ]));
143 }
144 break;
145 case 'DR':
146 $renderParts = new Livefeed\RenderParts\Department($options);
147 break;
148 default:
149 $renderParts = false;
150 }
151
152 $entityDataFormatted = ($renderParts ? $renderParts->getData((int)$entityId) : false);
153
154 if (
155 $entityDataFormatted
156 && isset($entityDataFormatted['name'])
157 && $entityDataFormatted['name'] <> ''
158 )
159 {
160 $newRightsNameList[] = (
161 isset($entityDataFormatted['link'])
162 && $entityDataFormatted['link'] <> ''
163 && (!isset($options['bPublicPage']) || !$options['bPublicPage'])
164 && (!isset($options['mail']) || !$options['mail'])
165 ? (
166 $entityType === 'U'
167 && (int)$entityId > 0
168 ? '[USER=' . $entityId . ']' . htmlspecialcharsback($entityDataFormatted['name']) . '[/USER]'
169 : '[URL=' . $entityDataFormatted['link'] . ']' . htmlspecialcharsback($entityDataFormatted['name']) . '[/URL]'
170 )
171 : htmlspecialcharsback($entityDataFormatted['name'])
172 );
173 }
174 elseif ($hiddenEntity)
175 {
176 $newRightsNameList[] = Loc::getMessage('SONET_COMMENTAUX_SHARE_HIDDEN');
177 }
178 }
179 }
180 else
181 {
182 $newRightsNameList[] = Loc::getMessage('SONET_COMMENTAUX_SHARE_HIDDEN');
183 }
184 }
185
186 if (empty($newRightsNameList))
187 {
188 return $result;
189 }
190
191 $result .= Loc::getMessage(count($params['destinationList']) > 1 ? 'SONET_COMMENTAUX_SHARE_TEXT_1' : 'SONET_COMMENTAUX_SHARE_TEXT', [
192 '#SHARE_LIST#' => implode(', ', $newRightsNameList)
193 ]);
194
195 if ($parser === null)
196 {
197 $parser = new \CTextParser();
198 $parser->allow = [
199 'HTML' => 'N',
200 'ANCHOR' => 'Y',
201 'USER' => 'Y'
202 ];
203 }
204
205 if (
206 !empty($params['pathEntityType'])
207 && !empty($params['pathEntityId'])
208 )
209 {
210 $parser->pathToUserEntityType = $params['pathEntityType'];
211 $parser->pathToUserEntityId = (int)$params['pathEntityId'];
212 }
213 else
214 {
215 $parser->pathToUserEntityType = false;
216 $parser->pathToUserEntityId = false;
217 }
218
219 return $parser->convertText($result);
220 }
221
222 protected function setRatingNotificationParams(array $fields = []): bool
223 {
224 $dest = explode('|', $fields['SHARE_DEST']);
225 $dest = array_values(array_filter($dest, static function ($item) { return ($item !== 'mention'); }));
226 $dest = explode(',', $dest[0]);
227
228 if (empty($dest))
229 {
230 return false;
231 }
232
233 $this->setParams([
234 'destinationList' => $dest,
235 'hiddenDestinationList' => []
236 ]);
237
238 return true;
239 }
240
241 protected function checkRatingNotificationData(int $userId = 0, array $fields = []): bool
242 {
243 return (
244 $userId > 0
245 && is_array($fields)
246 && isset($fields['SHARE_DEST'])
247 && Loader::includeModule('im')
248 );
249 }
250
251 protected function getRatingNotificationFollowValue(int $userId = 0, array $ratingVoteParams = [], array $fields = [])
252 {
253 return \CSocNetLogFollow::getExactValueByRating(
254 $userId,
255 ((!empty($fields['BLOG_ID'])) ? 'BLOG_COMMENT' : 'LOG_COMMENT'),
256 $fields['ID']
257 );
258 }
259
260 protected function getRatingNotificationNotigyTag(array $ratingVoteParams = [], array $fields = []): string
261 {
262 return 'RATING|' . ($ratingVoteParams['VALUE'] >= 0 ? '' : 'DL|') . (!empty($fields['BLOG_ID']) ? 'BLOG_COMMENT|' : 'LOG_COMMENT|') . $fields['ID'];
263 }
264
265 public function checkRecalcNeeded($fields, $params): bool
266 {
267 $result = false;
268
269 if (!empty($fields['SHARE_DEST']))
270 {
272 {
273 $result = true;
274 }
275 elseif (
276 !empty($params['POST_DATA'])
277 && !empty($params['POST_DATA']['SPERM_HIDDEN'])
278 )
279 {
280 $shareDestValue = false;
281 $valuesList = explode('|', $fields['SHARE_DEST']);
282 foreach ($valuesList as $value)
283 {
284 if ($value !== 'mention')
285 {
286 $shareDestValue = $value;
287 break;
288 }
289 }
290
291 if ($shareDestValue)
292 {
293 $dest = explode(',', $shareDestValue);
294 if (!empty($dest))
295 {
296 foreach ($dest as $destId)
297 {
298 if (in_array($destId, $params['POST_DATA']['SPERM_HIDDEN']))
299 {
300 $result = true;
301 break;
302 }
303 }
304 }
305 }
306 }
307 }
308
309 return $result;
310 }
311}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
getRatingNotificationFollowValue(int $userId=0, array $ratingVoteParams=[], array $fields=[])
Definition share.php:251
checkRecalcNeeded($fields, $params)
Definition share.php:265
checkRatingNotificationData(int $userId=0, array $fields=[])
Definition share.php:241
setRatingNotificationParams(array $fields=[])
Definition share.php:222
getRatingNotificationNotigyTag(array $ratingVoteParams=[], array $fields=[])
Definition share.php:260