• Модуль: socialnetwork
  • Путь к файлу: ~/bitrix/modules/socialnetwork/lib/commentaux/share.php
  • Класс: BitrixSocialnetworkCommentAuxShare
  • Вызов: Share::getText
public function getText(): string
{
	static $parser = null;
	static $availableUsersList = null;

	$result = '';
	$params = $this->params;
	$options = $this->options;
	$newRightsNameList = [];

	if (
		empty($params['destinationList'])
		|| !is_array($params['destinationList'])
	)
	{
		return $result;
	}

	$currentUserExtranet = (
		(!isset($options['bPublicPage']) || !$options['bPublicPage'])
		&& ComponentHelper::isCurrentUserExtranet()
	);
	if (
		$availableUsersList === null
		&& Loader::includeModule('extranet')
	)
	{
		$availableUsersList = ($currentUserExtranet ? CExtranet::getMyGroupsUsers(SITE_ID) : []);
	}

	foreach ($params['destinationList'] as $destinationCode)
	{
		$hiddenDestination = (
			isset($params['hiddenDestinationList'])
			&& is_array($params['hiddenDestinationList'])
			&& in_array($destinationCode, $params['hiddenDestinationList'])
		);

		if (
			!$hiddenDestination
			|| (
				isset($params['mention'])
				&& $params['mention']
			)
		)
		{
			if (preg_match('/^(SG|U||UA|DR)(d*)$/', $destinationCode, $matches))
			{
				$entityType = $matches[1];
				$entityId = ($matches[2] ?? false);
				$hiddenEntity = $renderParts = false;

				switch($entityType)
				{
					case 'SG':
						$renderParts = new LivefeedRenderPartsSonetGroup($options);
						break;
					case 'U':
					case 'UA':
						if (
							$currentUserExtranet
							&& $entityType === 'U'
							&& (
								!isset($params['mention'])
								|| !$params['mention']
							)
							&& !in_array($entityId, $availableUsersList)
						)
						{
							$hiddenEntity = true;
						}
						else
						{
							$renderParts = new LivefeedRenderPartsUser(array_merge($options, [ 'skipLink' => $hiddenDestination ]));
						}
						break;
					case 'DR':
						$renderParts = new LivefeedRenderPartsDepartment($options);
						break;
					default:
						$renderParts = false;
				}

				$entityDataFormatted = ($renderParts ? $renderParts->getData((int)$entityId) : false);

				if (
					$entityDataFormatted
					&& isset($entityDataFormatted['name'])
					&& $entityDataFormatted['name'] <> ''
				)
				{
					$newRightsNameList[] = (
						isset($entityDataFormatted['link'])
						&& $entityDataFormatted['link'] <> ''
						&& (!isset($options['bPublicPage']) || !$options['bPublicPage'])
						&& (!isset($options['mail']) || !$options['mail'])
							? (
								$entityType === 'U'
								&& (int)$entityId > 0
									? '[USER=' . $entityId . ']' . htmlspecialcharsback($entityDataFormatted['name']) . '[/USER]'
									: '[URL=' . $entityDataFormatted['link'] . ']' . htmlspecialcharsback($entityDataFormatted['name']) . '[/URL]'
							)
							: htmlspecialcharsback($entityDataFormatted['name'])
					);
				}
				elseif ($hiddenEntity)
				{
					$newRightsNameList[] = Loc::getMessage('SONET_COMMENTAUX_SHARE_HIDDEN');
				}
			}
		}
		else
		{
			$newRightsNameList[] = Loc::getMessage('SONET_COMMENTAUX_SHARE_HIDDEN');
		}
	}

	if (empty($newRightsNameList))
	{
		return $result;
	}

	$result .= Loc::getMessage(count($params['destinationList']) > 1 ? 'SONET_COMMENTAUX_SHARE_TEXT_1' : 'SONET_COMMENTAUX_SHARE_TEXT', [
		'#SHARE_LIST#' => implode(', ', $newRightsNameList)
	]);

	if ($parser === null)
	{
		$parser = new CTextParser();
		$parser->allow = [
			'HTML' => 'N',
			'ANCHOR' => 'Y',
			'USER' => 'Y'
		];
	}

	if (
		!empty($params['pathEntityType'])
		&& !empty($params['pathEntityId'])
	)
	{
		$parser->pathToUserEntityType = $params['pathEntityType'];
		$parser->pathToUserEntityId = (int)$params['pathEntityId'];
	}
	else
	{
		$parser->pathToUserEntityType = false;
		$parser->pathToUserEntityId = false;
	}

	return $parser->convertText($result);
}