- Модуль: socialnetwork
- Путь к файлу: ~/bitrix/modules/socialnetwork/lib/componenthelper.php
- Класс: BitrixSocialnetworkComponentHelper
- Вызов: ComponentHelper::checkBlogPostDestinationList
static function checkBlogPostDestinationList($params, &$resultFields)
{
global $USER;
$destinationList = (
isset($params["DEST"])
&& is_array($params["DEST"])
? $params["DEST"]
: array()
);
$siteId = (
!empty($params['SITE_ID'])
? $params['SITE_ID']
: SITE_ID
);
$currentUserId = $USER->getId();
if (!$currentUserId)
{
return false;
}
$extranetUser = (
$params['IS_EXTRANET_USER'] ?? self::isCurrentUserExtranet([
'siteId' => SITE_ID,
'userId' => $USER->getId()
])
);
$postId = (
isset($params['POST_ID'])
&& (int)$params['POST_ID'] > 0
? (int)$params['POST_ID']
: false
);
$postFields = [];
$oldSonetGroupIdList = [];
if ($postId)
{
$socNetPermsListOld = CBlogPost::getSocNetPerms($postId);
$postFields = BitrixBlogItemPost::getById($postId)->getFields();
if (!empty($socNetPermsListOld['SG']))
{
$oldSonetGroupIdList = array_keys($socNetPermsListOld['SG']);
}
}
$userAdmin = CSocNetUser::isUserModuleAdmin($currentUserId, $siteId);
$allowToAll = self::getAllowToAllDestination();
$newSonetGroupIdList = [];
$newUserIdList = [];
foreach($destinationList as $code)
{
if (preg_match('/^SG(d+)/i', $code, $matches))
{
$newSonetGroupIdList[] = (int)$matches[1];
}
elseif (preg_match('/^U(d+)/i', $code, $matches))
{
$newUserIdList[] = (int)$matches[1];
}
}
if (!empty($newSonetGroupIdList))
{
$oneSG = false;
$firstSG = true;
$premoderateSGList = [];
$canPublish = true;
foreach ($newSonetGroupIdList as $groupId)
{
if (
!empty($postFields)
&& $postFields["PUBLISH_STATUS"] === BLOG_PUBLISH_STATUS_PUBLISH
&& in_array($groupId, $oldSonetGroupIdList)
)
{
continue;
}
$canPublishToGroup = (
$userAdmin
|| CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $groupId, 'blog', 'write_post')
|| CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $groupId, 'blog', 'full_post')
|| CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $groupId, 'blog', 'moderate_post')
);
$canPremoderateToGroup = CSocNetFeaturesPerms::canPerformOperation($currentUserId, SONET_ENTITY_GROUP, $groupId, 'blog', 'premoderate_post');
if (
!$canPublishToGroup
&& $canPremoderateToGroup
)
{
$premoderateSGList[] = $groupId;
}
$canPublish = (
$canPublish
&& $canPublishToGroup
);
if($firstSG)
{
$oneSG = true;
$firstSG = false;
}
else
{
$oneSG = false;
}
}
if (!$canPublish)
{
if (!empty($premoderateSGList))
{
if ($oneSG)
{
if ($resultFields['PUBLISH_STATUS'] === BLOG_PUBLISH_STATUS_PUBLISH)
{
if (!$postId) // new post
{
$resultFields['PUBLISH_STATUS'] = BLOG_PUBLISH_STATUS_READY;
}
elseif ($postFields['PUBLISH_STATUS'] !== BLOG_PUBLISH_STATUS_PUBLISH)
{
$resultFields['PUBLISH_STATUS'] = $postFields['PUBLISH_STATUS'];
}
else
{
$resultFields['ERROR_MESSAGE'] = Loc::getMessage('SBPE_EXISTING_POST_PREMODERATION');
$resultFields['ERROR_MESSAGE_PUBLIC'] = $resultFields['ERROR_MESSAGE'];
}
}
}
else
{
$groupNameList = [];
$groupUrl = Option::get('socialnetwork', 'workgroups_page', SITE_DIR.'workgroups/', SITE_ID).'group/#group_id#/';
$res = WorkgroupTable::getList([
'filter' => [
'@ID' => $premoderateSGList
],
'select' => [ 'ID', 'NAME' ]
]);
while ($groupFields = $res->fetch())
{
$groupNameList[] = (
isset($params['MOBILE']) && $params['MOBILE'] === 'Y'
? $groupFields['NAME']
: '' . htmlspecialcharsEx($groupFields['NAME']) . ''
);
}
$resultFields['ERROR_MESSAGE'] = Loc::getMessage('SBPE_MULTIPLE_PREMODERATION2', [
'#GROUPS_LIST#' => implode(', ', $groupNameList)
]);
$resultFields['ERROR_MESSAGE_PUBLIC'] = $resultFields['ERROR_MESSAGE'];
}
}
else
{
$resultFields['ERROR_MESSAGE'] = Loc::getMessage('SONET_HELPER_NO_PERMISSIONS');
}
}
}
if ($extranetUser)
{
$destinationList = array_filter($destinationList, static function ($code) {
return (!preg_match('/^(DR|D)(d+)$/i', $code, $matches));
});
if (
!empty($newUserIdList)
&& Loader::includeModule('extranet')
)
{
$visibleUserIdList = CExtranet::getMyGroupsUsersSimple(SITE_ID);
if (!empty(array_diff($newUserIdList, $visibleUserIdList)))
{
$resultFields['ERROR_MESSAGE'] = Loc::getMessage('SONET_HELPER_NO_PERMISSIONS');
}
}
}
if (
!$allowToAll
&& in_array("UA", $destinationList, true)
)
{
foreach ($destinationList as $key => $value)
{
if ($value === "UA")
{
unset($destinationList[$key]);
break;
}
}
}
if ($extranetUser)
{
if (
empty($destinationList)
|| in_array("UA", $destinationList, true)
)
{
$resultFields["ERROR_MESSAGE"] .= Loc::getMessage("BLOG_BPE_EXTRANET_ERROR");
}
}
elseif (empty($destinationList))
{
$resultFields["ERROR_MESSAGE"] .= Loc::getMessage("BLOG_BPE_DESTINATION_EMPTY");
}
return $destinationList;
}