CBlogPost::NotifyImPublish: Bitrix method

      
<?php 
//  CBlogPost :: NotifyImPublish()
//  /dist/bitrix/modules/blog/general/blog_post.php:2989

    
public static function NotifyImPublish($arParams = array())
    {
        if (
            !
Loader::includeModule("im")
            || !
Loader::includeModule("socialnetwork")
        )
        {
            return 
false;
        }

        if (!
in_array($arParams['TYPE'], array('POST''COMMENT')))
        {
            return 
false;
        }

        
$arTitle self::processNotifyTitle($arParams["TITLE"]);
        
$arParams["TITLE"] = $arTitle['TITLE'];
        
$arParams["TITLE_OUT"] = $arTitle['TITLE_OUT'];
        
$bTitleEmpty $arTitle['IS_TITLE_EMPTY'];
        
$serverName = (CMain::IsHTTPS() ? "https" "http")."://".((defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0) ? SITE_SERVER_NAME COption::GetOptionString("main""server_name"""));

        
$arMessageFields = array(
            
"MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
            
"NOTIFY_TYPE" => IM_NOTIFY_SYSTEM,
            
"NOTIFY_MODULE" => "blog",
            
"TO_USER_ID" => $arParams["TO_USER_ID"]
        );

        if (
$arParams["TYPE"] == "POST")
        {
            
$arMessageFields["NOTIFY_EVENT"] = "published_post";
            
$arMessageFields["NOTIFY_TAG"] = "BLOG|POST|".$arParams["POST_ID"];

            
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                (!
$bTitleEmpty "SONET_IM_NEW_POST_PUBLISHED_W_TITLE" "SONET_IM_NEW_POST_PUBLISHED_WO_TITLE"),
                array(
                    
"#link_post_start#" => "<a href=\"#POST_URL#\" class=\"bx-notifier-item-action\">",
                    
"#link_post_end#" => "</a>",
                    
"#title#" => htmlspecialcharsbx($arParams["TITLE"])
                )
            );

            
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                    (!
$bTitleEmpty "SONET_IM_NEW_POST_PUBLISHED_W_TITLE" "SONET_IM_NEW_POST_PUBLISHED_WO_TITLE"),
                    array(
                        
"#link_post_start#" => "",
                        
"#link_post_end#" => "",
                        
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])
                    )
                ).
" #SERVER_NAME##POST_URL#";
        }
        else
        {
            
$arMessageFields["NOTIFY_EVENT"] = "published_comment";
            
$arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT|".$arParams["POST_ID"]."|".$arParams["COMMENT_ID"];

            
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                (!
$bTitleEmpty "SONET_IM_NEW_COMMENT_PUBLISHED_W_TITLE" "SONET_IM_NEW_COMMENT_PUBLISHED_WO_TITLE"),
                array(
                    
"#link_com_start#" => "<a href=\"#COMMENT_URL#\" class=\"bx-notifier-item-action\">",
                    
"#link_com_end#" => "</a>",
                    
"#title#" => htmlspecialcharsbx($arParams["TITLE"])
                )
            );

            
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                    (!
$bTitleEmpty "SONET_IM_NEW_COMMENT_PUBLISHED_W_TITLE" "SONET_IM_NEW_COMMENT_PUBLISHED_WO_TITLE"),
                    array(
                        
"#link_com_start#" => "",
                        
"#link_com_end#" => "",
                        
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])
                    )
                ).
" #SERVER_NAME##COMMENT_URL#";
        }

        
$userPostUrl = (isset($arParams['POST_URL']) ? $arParams['POST_URL'] : '');
        
$userCommentUrl = (isset($arParams['POST_URL']) ? $arParams['COMMENT_URL'] : '');

        if (
IsModuleInstalled("extranet"))
        {
            
$arTmp CSocNetLogTools::ProcessPath(
                array(
                    
"POST_URL" => $userPostUrl,
                    
"COMMENT_URL" => $userCommentUrl
                
),
                
$arParams["TO_USER_ID"],
                
SITE_ID
            
);

            
$userPostUrl $arTmp["URLS"]["POST_URL"];
            
$userCommentUrl $arTmp["URLS"]["COMMENT_URL"];

            
$serverName = (
                
strpos($userPostUrl"http://") === 0
                
|| strpos($userPostUrl"https://") === 0
                    
""
                    
$arTmp["SERVER_NAME"]
            );
        }

        
$arMessageFields["NOTIFY_MESSAGE"] = str_replace(
            array(
'#POST_URL#''#COMMENT_URL#'),
            array(
$userPostUrl$userCommentUrl),
            
$arMessageFields["NOTIFY_MESSAGE"]
        );
        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = str_replace(
            array(
'#POST_URL#''#SERVER_NAME#''#COMMENT_URL#'),
            array(
$userPostUrl$serverName$userCommentUrl),
            
$arMessageFields["NOTIFY_MESSAGE_OUT"]
        );

        
CIMNotify::Add($arMessageFields);

        return 
true;
    }