CBlogPost::Notify: Bitrix method

      
<?php 
//  CBlogPost :: Notify()
//  /dist/bitrix/modules/blog/general/blog_post.php:660

    
public static function Notify($arPost$arBlog$arParams)
    {
        global 
$DB;
        if(empty(
$arBlog))
        {
            
$arBlog CBlog::GetByID($arPost["BLOG_ID"]);
        }

        
$siteId = (!empty($arParams['SITE_ID']) ? $arParams['SITE_ID'] : SITE_ID);

        
$arImages $arOwner = Array();
        
$parserBlog false;
        
$text4mail $serverName $AuthorName "";

        if (
            
$arParams["bSoNet"]
            || (
                
$arBlog["EMAIL_NOTIFY"] == "Y"
                
&& $arParams["user_id"] != $arBlog["OWNER_ID"]
            )
        )
        {
            
$BlogUser CBlogUser::GetByID($arParams["user_id"], BLOG_BY_USER_ID);
            
$BlogUser CBlogTools::htmlspecialcharsExArray($BlogUser);
            
$res CUser::GetByID($arBlog["OWNER_ID"]);
            
$arOwner $res->GetNext();
            
$dbUser CUser::GetByID($arParams["user_id"]);
            
$arUser $dbUser->Fetch();
            
$AuthorName CBlogUser::GetUserNameEx($arUser$BlogUser$arParams);
            
$parserBlog = new blogTextParser(false$arParams["PATH_TO_SMILE"]);
            
$text4mail $arPost["DETAIL_TEXT"];
            if(
$arPost["DETAIL_TEXT_TYPE"] == "html")
            {
                
$text4mail HTMLToTxt($text4mail);
            }

            
$res CBlogImage::GetList(array("ID"=>"ASC"),array("POST_ID"=>$arPost["ID"], "BLOG_ID"=>$arBlog["ID"], "IS_COMMENT" => "N"));
            while (
$arImage $res->Fetch())
            {
                
$arImages[$arImage['ID']] = $arImage['FILE_ID'];
            }

            
$text4mail $parserBlog->convert4mail($text4mail$arImages);
            
$serverName = ((defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0) ? SITE_SERVER_NAME COption::GetOptionString("main""server_name"""));
        }

        if (
            !
$arParams["bSoNet"]
            && 
$arBlog["EMAIL_NOTIFY"] == "Y"
            
&& $arParams["user_id"] != $arBlog["OWNER_ID"]
            && 
IntVal($arBlog["OWNER_ID"]) > 0
        
// Send notification to email
        
{
            
CEvent::Send(
                
"NEW_BLOG_MESSAGE",
                
$siteId,
                array(
                    
"BLOG_ID" => $arBlog["ID"],
                    
"BLOG_NAME" => htmlspecialcharsBack($arBlog["NAME"]),
                    
"BLOG_URL" => $arBlog["URL"],
                    
"MESSAGE_TITLE" => $arPost["TITLE"],
                    
"MESSAGE_TEXT" => $text4mail,
                    
"MESSAGE_DATE" => GetTime(MakeTimeStamp($arPost["DATE_PUBLISH"])-CTimeZone::GetOffset(), "FULL"),
                    
"MESSAGE_PATH" => "http://".$serverName.CComponentEngine::MakePathFromTemplate(htmlspecialcharsBack($arParams["PATH_TO_POST"]), array("blog" => $arBlog["URL"], "post_id" => $arPost["ID"], "user_id" => $arBlog["OWNER_ID"], "group_id" => $arParams["SOCNET_GROUP_ID"])),
                    
"AUTHOR" => $AuthorName,
                    
"EMAIL_FROM" => COption::GetOptionString("main","email_from""[email protected]"),
                    
"EMAIL_TO" => $arOwner["EMAIL"]
                )
            );
        }

        if(
            
$arParams["bSoNet"]
            && 
$arPost["ID"]
            && 
CModule::IncludeModule("socialnetwork")
            && 
$parserBlog
        
)
        {
            if(
$arPost["DETAIL_TEXT_TYPE"] == "html" && $arParams["allowHTML"] == "Y" && $arBlog["ALLOW_HTML"] == "Y")
            {
                
$arAllow = array("HTML" => "Y""ANCHOR" => "Y""IMG" => "Y""SMILES" => "N""NL2BR" => "N""VIDEO" => "Y""QUOTE" => "Y""CODE" => "Y");
                if(
$arParams["allowVideo"] != "Y")
                {
                    
$arAllow["VIDEO"] = "N";
                }
                
$text4message $parserBlog->convert($arPost["DETAIL_TEXT"], false$arImages$arAllow);
            }
            else
            {
                
$arAllow = array("HTML" => "N""ANCHOR" => "N""BIU" => "N""IMG" => "N""QUOTE" => "N""CODE" => "N""FONT" => "N""TABLE" => "N""LIST" => "N""SMILES" => "N""NL2BR" => "N""VIDEO" => "N");
                
$text4message $parserBlog->convert($arPost["DETAIL_TEXT"], false$arImages$arAllow, array("isSonetLog"=>true));
            }

            
$arSoFields = Array(
                
"EVENT_ID" => (
                    isset(
$arPost["UF_BLOG_POST_IMPRTNT"])
                    && 
intval($arPost["UF_BLOG_POST_IMPRTNT"]) > 0
                        
? \Bitrix\Blog\Integration\Socialnetwork\Log::EVENT_ID_POST_IMPORTANT
                        
: \Bitrix\Blog\Integration\Socialnetwork\Log::EVENT_ID_POST
                
),
                
"=LOG_DATE" => (
                    
strlen($arPost["DATE_PUBLISH"]) > 0
                        
? (
                            
MakeTimeStamp($arPost["DATE_PUBLISH"], CSite::GetDateFormat("FULL"SITE_ID)) > time()+CTimeZone::GetOffset()
                                ? 
$DB->CharToDateFunction($arPost["DATE_PUBLISH"], "FULL"SITE_ID)
                                : 
$DB->CurrentTimeFunction()
                        )
                        :
                        
$DB->CurrentTimeFunction()
                ),
                
"TITLE_TEMPLATE" => "#USER_NAME# ".GetMessage("BLG_SONET_TITLE"),
                
"TITLE" => $arPost["TITLE"],
                
"MESSAGE" => $text4message,
                
"TEXT_MESSAGE" => $text4mail,
                
"MODULE_ID" => "blog",
                
"CALLBACK_FUNC" => false,
                
"SOURCE_ID" => $arPost["ID"],
                
"ENABLE_COMMENTS" => (array_key_exists("ENABLE_COMMENTS"$arPost) && $arPost["ENABLE_COMMENTS"] == "N" "N" "Y")
            );

            
$arSoFields["RATING_TYPE_ID"] = "BLOG_POST";
            
$arSoFields["RATING_ENTITY_ID"] = intval($arPost["ID"]);

            if(
$arParams["bGroupMode"])
            {
                
$arSoFields["ENTITY_TYPE"] = SONET_ENTITY_GROUP;
                
$arSoFields["ENTITY_ID"] = $arParams["SOCNET_GROUP_ID"];
                
$arSoFields["URL"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_POST"], array("blog" => $arBlog["URL"], "user_id" => $arBlog["OWNER_ID"], "group_id" => $arParams["SOCNET_GROUP_ID"], "post_id" => $arPost["ID"]));
            }
            else
            {
                
$arSoFields["ENTITY_TYPE"] = SONET_ENTITY_USER;
                
$arSoFields["ENTITY_ID"] = $arBlog["OWNER_ID"];
                
$arSoFields["URL"] = CComponentEngine::MakePathFromTemplate($arParams["PATH_TO_POST"], array("blog" => $arBlog["URL"], "user_id" => $arBlog["OWNER_ID"], "group_id" => $arParams["SOCNET_GROUP_ID"], "post_id" => $arPost["ID"]));
            }

            if (
intval($arParams["user_id"]) > 0)
            {
                
$arSoFields["USER_ID"] = $arParams["user_id"];
            }

            
$post = \Bitrix\Blog\Item\Post::getById($arPost["ID"]);
            
$arSoFields["TAG"] = $post->getTags();

            
$logID CSocNetLog::Add($arSoFieldsfalse);

            if (
intval($logID) > 0)
            {
                
$socnetPerms = \Bitrix\Socialnetwork\ComponentHelper::getBlogPostSocNetPerms(array(
                    
'postId' => $arPost["ID"],
                    
'authorId' => $arPost["AUTHOR_ID"]
                ));

                \
Bitrix\Main\FinderDestTable::merge(array(
                    
"CONTEXT" => "blog_post",
                    
"CODE" => \Bitrix\Main\FinderDestTable::convertRights($socnetPerms, array("U".$arPost["AUTHOR_ID"]))
                ));

                
$postFields $post->getFields();
                
$inlineAttachedObjectsIdList = array();

                if (
preg_match_all('/\[DISK\s+FILE\s+ID\s*=\s*([n]*\d+)\s*\]/is'.BX_UTF_PCRE_MODIFIER$postFields['DETAIL_TEXT'], $matches))
                {
                    if (!empty(
$matches[1]))
                    {
                        
$inlineFileList $matches[1];

                        foreach(
$inlineFileList as $key => $value)
                        {
                            if (
                                
preg_match('/^n(\d+)/is'.BX_UTF_PCRE_MODIFIER$value$matches)
                                && !empty(
$matches[1])
                                && 
intval($matches[1]) > 0
                            
)
                            {
                                
$res = \Bitrix\Disk\AttachedObject::getList(array(
                                    
'filter' => array(
                                        
'=ENTITY_TYPE' => \Bitrix\Disk\Uf\BlogPostConnector::className(),
                                        
'ENTITY_ID' => $postFields['ID'],
                                        
'OBJECT_ID' => intval($matches[1])
                                    ),
                                    
'select' => array('ID')
                                ));
                                foreach (
$res as $attachedObjectFields)
                                {
                                    
$inlineAttachedObjectsIdList[] = $attachedObjectFields['ID'];
                                }
                            }
                        }
                    }
                }

                
CSocNetLog::Update($logID, array("TMP_ID" => $logID));

                
$hasVideoTransforming = (
                    !empty(
$inlineAttachedObjectsIdList)
                    && 
Bitrix\Blog\Integration\Disk\Transformation::getStatus(array(
                        
'attachedIdList' => $inlineAttachedObjectsIdList
                    
))
                );

                if (
$hasVideoTransforming)
                {
                    
$socnetPerms = array("SA""U".$arPost["AUTHOR_ID"]);
                }

                
CSocNetLogRights::deleteByLogID($logID);
                
CSocNetLogRights::add($logID$socnetPerms);

                
$updateFields = array(
                    
"TRANSFORM" => ($hasVideoTransforming 'Y' 'N')
                );

                if (
Loader::includeModule("extranet"))
                {
                    
$updateFields["SITE_ID"] = CExtranet::getSitesByLogDestinations($socnetPerms$arPost["AUTHOR_ID"], $siteId);
                }

                
CSocNetLog::update($logID$updateFields);

                if (
Loader::includeModule('crm'))
                {
                    
CCrmLiveFeedComponent::processCrmBlogPostRights($logID$arSoFields$arPost'new');
                }

                
Bitrix\Blog\Integration\Socialnetwork\CounterPost::increment(array(
                    
'socnetPerms' => $socnetPerms,
                    
'logId' => $logID,
                    
'logEventId' => $arSoFields["EVENT_ID"],
                    
'sendToAuthor' => (
                        !empty(
$arParams["SEND_COUNTER_TO_AUTHOR"])
                        && 
$arParams["SEND_COUNTER_TO_AUTHOR"] == "Y"
                    
)
                ));

                if (
$hasVideoTransforming)
                {
                    
CUserOptions::setOption("socialnetwork""~log_videotransform_popup_show""Y");
                    
CUserOptions::setOption("socialnetwork""~log_videotransform_post_url"$arSoFields["URL"]);
                    
CUserOptions::setOption("socialnetwork""~log_videotransform_post_id"$arPost["ID"]);
                }

                return 
$logID;
            }
        }

        return 
false;
    }