CModule::IncludeModule("socialnetwork");
$arFields = array(
"TITLE" => "Заголовок записи",
"DETAIL_TEXT" => "Тело сообщения",
"BLOG_ID" => 1, //ID отправителя
"AUTHOR_ID" => 1, //ID блога, в котором будет запись
"DATE_PUBLISH" => '11.02.2014 09:08', // дада
"PUBLISH_STATUS" => BLOG_PUBLISH_STATUS_PUBLISH, // Читаем в API
"ENABLE_TRACKBACK" => 'N',
"ENABLE_COMMENTS" => 'Y'
);
$arEvent = array (
'EVENT_ID' => 'blog_post',
'=LOG_DATE' => 'now()',
'TITLE_TEMPLATE' => '#USER_NAME# добавил(а) сообщение "#TITLE#" в блог',
'TITLE' => "Заголовок записи",
'MESSAGE' => "Текст записи",
'TEXT_MESSAGE' => "Текст записи",
'MODULE_ID' => 'blog',
'CALLBACK_FUNC' => false,
'SOURCE_ID' => $ID,
'ENABLE_COMMENTS' => 'Y',
'RATING_TYPE_ID' => 'BLOG_POST',
'RATING_ENTITY_ID' => $newID,
'ENTITY_TYPE' => 'U',
'ENTITY_ID' => '1',
'USER_ID' => '1',
'URL' => '/company/personal/user/1/blog/'.$ID.'/',
);
// Выдает права
CSocNetLogRights::Add ( $eventID, array ("G3") );
// Отправляет уведомление о новом сообщении
CSocNetLog::SendEvent ( $eventID, 'SONET_NEW_EVENT' );
function postToGroup($blogid, $authorid, $message_title, $message_body){
CModule::IncludeModule("blog");
$arFields = array (
'TITLE' => $message_title,
'DETAIL_TEXT' => $message_body,
'DETAIL_TEXT_TYPE' => 'text',
'DATE_PUBLISH' => ConvertTimeStamp(time() + CTimeZone::GetOffset(), "FULL"),
'PUBLISH_STATUS' => 'P',
'PATH' => '/company/personal/user/4438/blog/#post_id#/',
'URL' => 'u4438-blog-s11',
'BACKGROUND_CODE' => false,
'PERMS_POST' =>
array (
),
'PERMS_COMMENT' =>
array (
),
'MICRO' => 'N',
'CATEGORY_ID' => '',
'SOCNET_RIGHTS' =>
array (
0 => 'SG48',
),
'UF_BLOG_POST_FILE' =>
array (
0 => '',
),
'UF_BLOG_POST_IMPRTNT' => '0',
'UF_IMPRTANT_DATE_END' => null, // Bitrix\Main\Type\DateTime::__set_state
'UF_BLOG_POST_VOTE' => 'n0',
'SEARCH_GROUP_ID' => '1',
'=DATE_CREATE' => 'now()',
'AUTHOR_ID' => $authorid,
'BLOG_ID' => $blogid,
);
$ID = CBlogPost::Add($arFields);
$arEvent = array (
'EVENT_ID' => 'blog_post',
'=LOG_DATE' => 'now()',
'TITLE_TEMPLATE' => '#USER_NAME# добавил(а) сообщение "#TITLE#" в блог',
'TITLE' => $message_title,
'MESSAGE' => $message_body,
'TEXT_MESSAGE' => $message_body,
'MODULE_ID' => 'blog',
'CALLBACK_FUNC' => false,
'SOURCE_ID' => $ID,
'ENABLE_COMMENTS' => 'Y',
'RATING_TYPE_ID' => 'BLOG_POST',
'RATING_ENTITY_ID' => $ID,
'ENTITY_TYPE' => 'U',
'ENTITY_ID' => $authorid,
'URL' => '/company/personal/user/4438/blog/'.$ID.'/',
'USER_ID' => $authorid,
'TAG' =>
array (
),
);
$logID = CSocNetLog::Add($arEvent, false);
$rights = array (
0 => 'OSG48_L',
1 => 'SG48',
2 => 'SG48_A',
3 => 'SG48_E',
4 => 'SG48_K',
5 => 'U4438',
6 => 'SA',
);
if (intval($logID) > 0)
{
CSocNetLog::Update($logID, array('TMP_ID' => $logID));
CSocNetLogRights::Add($logID, $rights);
CSocNetLog::SendEvent($logID, 'SONET_NEW_EVENT');
}
}
//title: CBlogPost ADD 3
\Bitrix\Main\Loader::includeModule('blog');
$userId = 980;
$groupId = 165;
global $APPLICATION;
$arBlog = CBlog::GetList(array(), array('OWNER_ID'=>$userId))->Fetch();
$arFields = array(
"TITLE" => 'Сообщение для теста 2',
"DETAIL_TEXT" => 'работает, работает!',
"DETAIL_TEXT_TYPE" => 'text',
"DATE_PUBLISH" => (new DateTime())->format('d.m.Y H:m:s'),
"PUBLISH_STATUS" => 'P',
"CATEGORY_ID" => '',
"PATH" => '/company/personal/user/'.$userId.'/blog/#post_id#/',
"URL" => 'u'.$userId.'-blog-s1',
"PERMS_POST" => array(),
"PERMS_COMMENT" => array(),
"MICRO" => 'N',
"SOCNET_RIGHTS" => array('SG'.$groupId),
//"SOCNET_RIGHTS" => array('SG'.$groupId, 'U732'),
"=DATE_CREATE" => 'now()',
"AUTHOR_ID" => $userId,
"BLOG_ID" => $arBlog['ID'],
);
$newID = CBlogPost::Add($arFields);
if(IntVal($newID)>0)
{
$arFields["ID"] = $newID;
$arParamsNotify = array(
"bSoNet"=>true,
'UserID'=>$userId,
'user_id'=>$userId,
'SOCNET_GROUP_ID'=>$groupId,
'PATH_TO_POST'=>'/company/personal/user/#user_id#/blog/#post_id#/'
);
$notify = CBlogPost::Notify($arFields, $arBlog, $arParamsNotify);
echo "Новое сообщение [".$newID."] добавлено. ".$notify;
}
else
{
if ($ex = $APPLICATION->GetException())
echo $ex->GetString();
}