CBlogPost :: NotifyMail: Bitrix method

      
<?php 
//  CBlogPost :: NotifyMail()
//  /dist/bitrix/modules/blog/general/blog_post.php:3117

    
public static function NotifyMail($arFields)
    {
        if (!
CModule::IncludeModule('mail'))
        {
            return 
false;
        }

        if (
            !isset(
$arFields["postId"])
            || 
intval($arFields["postId"]) <= 0
            
|| !isset($arFields["userId"])
            || !isset(
$arFields["postUrl"])
            || 
strlen($arFields["postUrl"]) <= 0
        
)
        {
            return 
false;
        }

        if (!
is_array($arFields["userId"]))
        {
            
$arFields["userId"] = array($arFields["userId"]);
        }

        if (!isset(
$arFields["siteId"]))
        {
            
$arFields["siteId"] = SITE_ID;
        }

        
$nameTemplate CSite::GetNameFormat(""$arFields["siteId"]);
        
$authorName "";

        if (!empty(
$arFields["authorId"]))
        {
            
$rsAuthor CUser::GetById($arFields["authorId"]);
            
$arAuthor $rsAuthor->Fetch();
            
$authorName CUser::FormatName(
                
$nameTemplate,
                
$arAuthor,
                
true,
                
false
            
);

            if (
check_email($authorName))
            {
                
$authorName '"'.$authorName.'"';
            }

            foreach(
$arFields["userId"] as $key => $val)
            {
                if (
intval($val) == intval($arFields["authorId"]))
                {
                    unset(
$arFields["userId"][$key]);
                }
            }
        }

        if (empty(
$arFields["userId"]))
        {
            return 
false;
        }

        if (
            !isset(
$arFields["type"])
            || !
in_array(strtoupper($arFields["type"]), array("POST""POST_SHARE""COMMENT"))
        )
        {
            
$arFields["type"] = "COMMENT";
        }

        
$arEmail = \Bitrix\Mail\User::getUserData($arFields["userId"], $nameTemplate);
        if (empty(
$arEmail))
        {
            return 
false;
        }

        
$arBlogPost CBlogPost::GetByID(intval($arFields["postId"]));
        if (!
$arBlogPost)
        {
            return 
false;
        }

        
$arTitle self::processNotifyTitle($arBlogPost["TITLE"]);
        
$postTitle $arTitle['TITLE'];

        switch (
strtoupper($arFields["type"]))
        {
            case 
"COMMENT":
                
$mailMessageId "<BLOG_COMMENT_".$arFields["commentId"]."@".$GLOBALS["SERVER_NAME"].">";
                
$mailTemplateType "BLOG_SONET_NEW_COMMENT";
                break;
            case 
"POST_SHARE":
                
$mailMessageId "<BLOG_POST_".$arFields["postId"]."@".$GLOBALS["SERVER_NAME"].">";
                
$mailTemplateType "BLOG_SONET_POST_SHARE";
                break;
            default:
                
$mailMessageId "<BLOG_POST_".$arFields["postId"]."@".$GLOBALS["SERVER_NAME"].">";
                
$mailTemplateType "BLOG_SONET_NEW_POST";
        }

        
$mailMessageInReplyTo "<BLOG_POST_".$arFields["postId"]."@".$GLOBALS["SERVER_NAME"].">";
        
$defaultEmailFrom = \Bitrix\Mail\User::getDefaultEmailFrom();

        foreach (
$arEmail as $userId => $arUser)
        {
            
$email $arUser["EMAIL"];
            
$nameFormatted str_replace(array('<''>''"'), ''$arUser["NAME_FORMATTED"]);

            if (
                
intval($userId) <= 0
                
&& strlen($email) <= 0
            
)
            {
                continue;
            }

            
$res = \Bitrix\Mail\User::getReplyTo(
                
$arFields["siteId"],
                
$userId,
                
'BLOG_POST',
                
$arFields["postId"],
                
$arFields["postUrl"]
            );
            if (
is_array($res))
            {
                list(
$replyTo$backUrl) = $res;

                if (
                    
$replyTo
                    
&& $backUrl
                
)
                {
                    
$authorName str_replace(array('<''>''"'), ''$authorName);
                    
CEvent::Send(
                        
$mailTemplateType,
                        
$arFields["siteId"],
                        array(
                            
"=Reply-To" => $authorName.' <'.$replyTo.'>',
                            
"=Message-Id" => $mailMessageId,
                            
"=In-Reply-To" => $mailMessageInReplyTo == $mailMessageId '' $mailMessageInReplyTo,
                            
"EMAIL_FROM" => $authorName.' <'.$defaultEmailFrom.'>',
                            
"EMAIL_TO" => (!empty($nameFormatted) ? ''.$nameFormatted.' <'.$email.'>' $email),
                            
"RECIPIENT_ID" => $userId,
                            
"COMMENT_ID" => (isset($arFields["commentId"]) ? intval($arFields["commentId"]) : false),
                            
"POST_ID" => intval($arFields["postId"]),
                            
"POST_TITLE" => $postTitle,
                            
"URL" => $arFields["postUrl"]
                        )
                    );
                }
            }
        }

        if (
            
strtoupper($arFields["type"]) == 'COMMENT'
            
&& Loader::includeModule('crm')
        )
        {
            
CCrmLiveFeedComponent::processCrmBlogComment(array(
                
"AUTHOR" => isset($arAuthor) ? $arAuthor false,
                
"POST_ID" => intval($arFields["postId"]),
                
"COMMENT_ID" => intval($arFields["commentId"]),
                
"USER_ID" => array_keys($arEmail)
            ));
        }

        return 
true;
    }