35 public static function getById($postId = 0, $params = array())
37 static $cachedFields = array();
40 $postId = intval($postId);
43 !empty($params[
'USE_STATIC_CACHE'])
44 && $params[
'USE_STATIC_CACHE'] === true
50 $postFields = array();
54 && isset($cachedFields[$postId])
57 $postFields = $cachedFields[$postId];
61 $select = array(
'*',
'UF_BLOG_POST_URL_PRV');
64 \
Bitrix\Main\
Config\Option::get(
'disk',
'successfully_converted',
false)
68 $select[] =
'UF_BLOG_POST_FILE';
72 Loader::includeModule(
'vote')
76 $select[] =
'UF_BLOG_POST_VOTE';
79 $res = PostTable::getList(array(
80 'filter' => array(
'=ID' => $postId),
83 if ($fields = $res->fetch())
85 $postFields = $fields;
89 $postFields[
'DATE_CREATE'] = $postFields[
'DATE_CREATE']->toString();
93 $postFields[
'DATE_PUBLISH'] = $postFields[
'DATE_PUBLISH']->toString();
97 $cachedFields[$postId] = $postFields;
100 $postItem->setFields($postFields);
102 isset($postFields[
'ID'])
103 && intval($postFields[
'ID']) > 0
106 $postItem->setId(intval($postFields[
'ID']));
137 static $cache, $userAccessCodeCache;
139 if (!Loader::includeModule(
'socialnetwork'))
147 || empty($fields[
'ID'])
148 || intval($fields[
'ID']) <= 0
154 $cacheId = md5($fields[
'ID'].serialize($params));
156 if (!empty($cache[$cacheId]))
158 return $cache[$cacheId];
161 $currentUser =
false;
162 $userId = (isset($params[
"USER_ID"]) ? intval($params[
"USER_ID"]) : 0);
165 $userId = intval($USER->getId());
170 $permsAvailable = array_keys(
$GLOBALS[
"AR_BLOG_PERMS"]);
174 if (\CSocNetUser::isCurrentUserModuleAdmin())
176 $perms = $permsAvailable[count($permsAvailable) - 1];
179 elseif(\CSocNetUser::isUserModuleAdmin($userId))
181 $perms = $permsAvailable[count($permsAvailable) - 1];
185 isset($fields[
"AUTHOR_ID"])
186 && $fields[
"AUTHOR_ID"] == $userId
192 $openedWorkgroupsList = [];
193 $readByOpenSonetGroup =
false;
194 $alreadyFound =
false;
198 $permsList = \CBlogPost::getSocNetPerms($fields[
'ID']);
205 $select = array(
"ID",
"EXTERNAL_AUTH_ID");
208 $select[] =
"UF_DEPARTMENT";
210 $res = Main\UserTable::getList(array(
217 if($userFields = $res->fetch())
219 if ($userFields[
"EXTERNAL_AUTH_ID"] ==
'email')
221 $alreadyFound =
true;
225 isset($params[
'PUBLIC']) && $params[
'PUBLIC']
226 && isset($userFields[
"UF_DEPARTMENT"])
228 !is_array($userFields[
"UF_DEPARTMENT"])
229 || empty($userFields[
"UF_DEPARTMENT"])
230 || intval($userFields[
"UF_DEPARTMENT"][0]) <= 0
232 && Loader::includeModule(
'extranet')
233 && ($extranetSiteId = \CExtranet::getExtranetSiteID())
236 if (isset($params[
'LOG_ID']) && intval($params[
'LOG_ID']) > 0)
238 $postSiteList = array();
239 $res = \CSocNetLog::getSite(intval($params[
'LOG_ID']));
240 while ($logSite = $res->fetch())
242 $postSiteList[] = $logSite[
"LID"];
245 if (!in_array($extranetSiteId, $postSiteList))
247 $alreadyFound =
true;
253 $alreadyFound =
true;
260 $alreadyFound =
true;
265 $entityList = array();
269 if (!empty($userAccessCodeCache[$userId]))
271 $entityList = $userAccessCodeCache[$userId];
275 $codeList = \CAccess::getUserCodesArray($userId);
276 foreach($codeList as $code)
279 preg_match(
'/^DR([0-9]+)/', $code, $match)
280 || preg_match(
'/^D([0-9]+)/', $code, $match)
281 || preg_match(
'/^IU([0-9]+)/', $code, $match)
284 $entityList[
"DR"][$code] = $code;
286 elseif (preg_match(
'/^SG([0-9]+)_([A-Z])/', $code, $match))
288 $entityList[
"SG"][$match[1]][$match[2]] = $match[2];
291 $userAccessCodeCache[$userId] = $entityList;
294 foreach($permsList as $key => $value)
296 foreach($value as
$id => $p)
303 if($userId > 0 && $key ==
"U" && $userId ==
$id)
306 in_array(
"US".$userId, $p)
313 if(in_array(
"G2", $p))
319 if($userId > 0 && in_array(
"AU", $p))
327 if(!empty($entityList[
"SG"][
$id]))
329 foreach($entityList[
"SG"][
$id] as $sonetGroupId)
331 if(in_array(
"SG".
$id.
"_".$sonetGroupId, $p))
340 if($key ==
"DR" && !empty($entityList[
"DR"]))
342 if(in_array(
"DR".
$id, $entityList[
"DR"]))
358 && !empty($permsList[
'SG'])
361 foreach ($permsList[
'SG'] as $sonetGroupPermList)
363 if (empty($sonetGroupPermList))
368 foreach ($sonetGroupPermList as $sonetGroupPerm)
370 if (!preg_match(
'/^OSG(\d+)_'.(!$userId ? SONET_ROLES_ALL : SONET_ROLES_AUTHORIZED).
'$/', $sonetGroupPerm, $matches))
374 $openedWorkgroupsList[] = (int)$matches[1];
379 !empty($openedWorkgroupsList)
380 && Loader::includeModule(
'socialnetwork')
381 && \Bitrix\Socialnetwork\Helper\Workgroup::checkAnyOpened($openedWorkgroupsList)
385 $readByOpenSonetGroup =
true;
390 isset($params[
'CHECK_FULL_PERMS'])
391 && $params[
'CHECK_FULL_PERMS']
395 $sonetGroupIdList = Array();
396 if(!empty($permsList[
"SG"]))
398 foreach($permsList[
"SG"] as $groupId => $val)
400 if(!empty($entityList[
"SG"][$groupId]))
402 $sonetGroupIdList[] = $groupId;
407 if(!empty($sonetGroupIdList))
409 $operationList = array(
"full_post",
"moderate_post",
"write_post",
"premoderate_post");
410 foreach($operationList as $operation)
417 $sonetGroupPermList = \CSocNetFeaturesPerms::getOperationPerm(SONET_ENTITY_GROUP, $sonetGroupIdList,
"blog", $operation);
418 if(is_array($sonetGroupPermList))
420 foreach($sonetGroupPermList as $groupId => $role)
422 if (in_array($role, $entityList[
"SG"][$groupId]))
429 case "moderate_post":
435 case "premoderate_post":
448 $cache[$cacheId] = $result = [
450 'READ_BY_OSG' => $readByOpenSonetGroup,