CBlogPost :: NotifyIm: Bitrix method

      
<?php 
//  CBlogPost :: NotifyIm()
//  /dist/bitrix/modules/blog/general/blog_post.php:1839

    
public static function NotifyIm($arParams)
    {
        static 
$blogPostEventIdList null;

        
$arUserIDSent = array();

        if (!
CModule::IncludeModule("im"))
        {
            return 
$arUserIDSent;
        }

        
$arUsers = array();

        if(!empty(
$arParams["TO_USER_ID"]))
        {
            foreach(
$arParams["TO_USER_ID"] as $val)
            {
                
$val IntVal($val);
                if (
                    
$val 0
                    
&& $val != $arParams["FROM_USER_ID"]
                )
                {
                    
$arUsers[] = $val;
                }
            }
        }
        if(!empty(
$arParams["TO_SOCNET_RIGHTS"]))
        {
            foreach(
$arParams["TO_SOCNET_RIGHTS"] as $v)
            {
                if(
substr($v01) == "U")
                {
                    
$u IntVal(substr($v1));
                    if (
                        
$u 
                        
&& !in_array($u$arUsers
                        && (
                            !
array_key_exists("U"$arParams["TO_SOCNET_RIGHTS_OLD"]) 
                            || empty(
$arParams["TO_SOCNET_RIGHTS_OLD"]["U"][$u])
                        )
                        && 
$u != $arParams["FROM_USER_ID"]
                    )
                    {
                        
$arUsers[] = $u;
                    }
                }
            }
        }

        if (!empty(
$arUsers))
        {
            
$rsUser = \Bitrix\Main\UserTable::getList(array(
                
'order' => array(),
                
'filter' => array(
                    
"ID" => $arUsers,
                    
"ACTIVE" => "Y",
                    
"!=EXTERNAL_AUTH_ID" => 'email'
                
),
                
'select' => array("ID")
            ));

            
$arUsers = array();

            while (
$arUser $rsUser->fetch())
            {
                
$arUsers[] = $arUser["ID"];
            }
        }

        
$arMessageFields = array(
            
"MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
            
"TO_USER_ID" => "",
            
"FROM_USER_ID" => $arParams["FROM_USER_ID"],
            
"NOTIFY_TYPE" => IM_NOTIFY_FROM,
            
"NOTIFY_ANSWER" => "Y",
            
"NOTIFY_MODULE" => "blog",
            
"PARSE_LINK" => "N"
        
);

        
$aditGM $authorName $authorAvatarUrl "";
        if(
IntVal($arParams["FROM_USER_ID"]) > 0)
        {
            
$dbUser CUser::GetByID($arParams["FROM_USER_ID"]);
            if(
$arUser $dbUser->Fetch())
            {
                if(
$arUser["PERSONAL_GENDER"] == "F")
                {
                    
$aditGM "_FEMALE";
                }

                if (!empty(
$arUser["PERSONAL_PHOTO"]))
                {
                    
$avatarSize = (isset($arParams["PUSH_AVATAR_SIZE"]) && intval($arParams["PUSH_AVATAR_SIZE"]) > intval($arParams["PUSH_AVATAR_SIZE"]) : 100);
                    
$imageResized CFile::resizeImageGet(
                        
$arUser["PERSONAL_PHOTO"],
                        array(
                            
"width" => $avatarSize,
                            
"height" => $avatarSize
                        
),
                        
BX_RESIZE_IMAGE_EXACT
                    
);
                    if (
$imageResized)
                    {
                        
$authorAvatarUrl = \Bitrix\Im\Common::getPublicDomain().$imageResized["src"];
                    }
                }

                
$authorName = (
                    
$arUser
                        
CUser::FormatName(CSite::GetNameFormat(), $arUsertrue)
                        : 
GetMessage("BLG_GP_PUSH_USER")
                );
            }
        }

        if (
CModule::IncludeModule("socialnetwork"))
        {
            if (
$blogPostEventIdList === null)
            {
                
$blogPostLivefeedProvider = new \Bitrix\Socialnetwork\Livefeed\BlogPost;
                
$blogPostEventIdList $blogPostLivefeedProvider->getEventId();
            }

            
$rsLog CSocNetLog::GetList(
                array(),
                array(
                    
"EVENT_ID" => $blogPostEventIdList,
                    
"SOURCE_ID" => $arParams["ID"]
                ),
                
false,
                
false,
                array(
"ID")
            );
            if (
$arLog $rsLog->Fetch())
            {
                
$arMessageFields["LOG_ID"] = $arLog["ID"];
            }
        }

        
$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"""));
        
$urlOriginal $arParams["URL"];

        if (
IsModuleInstalled("extranet"))
        {
            
$user_path COption::GetOptionString("socialnetwork""user_page"falseSITE_ID);
            if (
                
strlen($user_path) > 0
                
&& strpos($arParams["URL"], $user_path) === 0
            
)
            {
                
$arParams["URL"] = str_replace($user_path"#USER_PATH#"$arParams["URL"]);
            }
        }

        
// notify mentioned users
        
if(!empty($arParams["MENTION_ID"]))
        {
            if(!
is_array($arParams["MENTION_ID_OLD"]))
            {
                
$arParams["MENTION_ID_OLD"] = Array();
            }

            
$arUserIdToMention $arNewRights = array();

            foreach(
$arParams["MENTION_ID"] as $val)
            {
                
$val IntVal($val);
                if (
                    
IntVal($val) > 0
                    
&& !in_array($val$arParams["MENTION_ID_OLD"])
                    && 
$val != $arParams["FROM_USER_ID"]
                )
                {
                    
$postPerm CBlogPost::GetSocNetPostPerms(array(
                        
"POST_ID" => $arParams["ID"],
                        
"NEED_FULL" => true,
                        
"USER_ID" => $val,
                        
"IGNORE_ADMIN" => true
                    
));

                    if (
                        
$postPerm >= BLOG_PERMS_READ
                        
|| $arParams["TYPE"] == "COMMENT"
                    
)
                    {
                        
$arUserIdToMention[] = $val;
                    }
                }
            }

            
$arUserIdToMention array_unique($arUserIdToMention);

            foreach(
$arUserIdToMention as $val)
            {
                
$val IntVal($val);
                
$arMessageFields["TO_USER_ID"] = $val;

                if (
IsModuleInstalled("extranet"))
                {
                    
$arTmp CSocNetLogTools::ProcessPath(
                        array(
                            
"URL" => $arParams["URL"],
                        ),
                        
$val,
                        
SITE_ID
                    
);
                    
$url $arTmp["URLS"]["URL"];

                    
$serverName = (
                        
strpos($url"http://") === 0
                        
|| strpos($url"https://") === 0
                            
""
                            
$arTmp["SERVER_NAME"]
                    );
                }
                else
                {
                    
$url $arParams["URL"];
                }

                
$arMessageFields["PUSH_PARAMS"] = array(
                    
"ACTION" => "mention"
                
);

                if (!empty(
$authorAvatarUrl))
                {
                    
$arMessageFields["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
                        
'avatarUrl' => $authorAvatarUrl,
                        
'senderName' => $authorName
                    
);
                }

                if (
$arParams["TYPE"] == "POST")
                {
                    
$arMessageFields["NOTIFY_EVENT"] = "mention";
                    
$arMessageFields["NOTIFY_TAG"] = "BLOG|POST_MENTION|".$arParams["ID"];
                    
$arMessageFields["NOTIFY_SUB_TAG"] = "BLOG|POST_MENTION|".$arParams["ID"].'|'.$val;

                    if (!
$bTitleEmpty)
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                            
"BLG_GP_IM_6".$aditGM,
                            array(
                                
"#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>"
                            
)
                        );
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                                
"BLG_GP_IM_6".$aditGM,
                                array(
                                    
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])
                                )
                        ).
" ".$serverName.$url."";
                        
$arMessageFields["PUSH_MESSAGE"] = GetMessage(
                            
"BLG_GP_PUSH_6".$aditGM,
                            array(
                                
"#name#" => htmlspecialcharsbx($authorName),
                                
"#title#" => htmlspecialcharsbx($arParams["TITLE"])
                            )
                        );
                    }
                    else
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                            
"BLG_GP_IM_6A".$aditGM,
                            array(
                                
"#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_6B")."</a>"
                            
)
                        );
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                            
"BLG_GP_IM_6A".$aditGM,
                            array(
                                
"#post#" => GetMessage("BLG_GP_IM_6B")
                            )
                        ).
" ".$serverName.$url."";
                        
$arMessageFields["PUSH_MESSAGE"] = GetMessage(
                            
"BLG_GP_PUSH_6A".$aditGM,
                            array(
                                
"#name#" => htmlspecialcharsbx($authorName),
                                
"#post#" => GetMessage("BLG_GP_IM_6B")
                            )
                        );
                    }
                }
                elseif (
$arParams["TYPE"] == "COMMENT")
                {
                    
$arMessageFields["NOTIFY_EVENT"] = "mention_comment";
                    
$arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT_MENTION|".$arParams["ID"].'|'.$arParams["COMMENT_ID"];
                    
$arMessageFields["NOTIFY_SUB_TAG"] = "BLOG|COMMENT_MENTION|".$arParams["COMMENT_ID"].'|'.$val;

                    
$commentCropped truncateText($arParams["BODY"], 100);

                    if (!
$bTitleEmpty)
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                            
"BLG_GP_IM_71".$aditGM,
                            array(
                                
"#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
                                
"#comment#" => $commentCropped
                            
)
                        );
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                            
"BLG_GP_IM_71".$aditGM,
                            array(
                                
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
                                
"#comment#" => $arParams["BODY"]
                            )
                        ).
" ".$serverName.$url."";
                        
$arMessageFields["PUSH_MESSAGE"] = GetMessage(
                            
"BLG_GP_PUSH_71".$aditGM,
                            array(
                                
"#name#" => htmlspecialcharsbx($authorName),
                                
"#title#" => htmlspecialcharsbx($arParams["TITLE"]),
                                
"#comment#" => $commentCropped
                            
)
                        );
                    }
                    else
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                            
"BLG_GP_IM_71A".$aditGM,
                            array(
                                
"#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_7B")."</a>",
                                
"#comment#" => $commentCropped
                            
)
                        );
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                            
"BLG_GP_IM_71A".$aditGM,
                            array(
                                
"#post#" => GetMessage("BLG_GP_IM_7B"),
                                
"#comment#" => $arParams["BODY"]
                            )
                        ).
" ".$serverName.$url."";
                        
$arMessageFields["PUSH_MESSAGE"] = GetMessage(
                            
"BLG_GP_PUSH_71A".$aditGM,
                            array(
                                
"#name#" => htmlspecialcharsbx($authorName),
                                
"#post#" => GetMessage("BLG_GP_IM_7B"),
                                
"#comment#" => $commentCropped
                            
)
                        );
                    }
                }

                
$arMessageFields["PUSH_PARAMS"]["TAG"] = $arMessageFields["NOTIFY_TAG"];

                
$ID CIMNotify::Add($arMessageFields);
                
$arUserIDSent[] = $val;

                if (
                    
intval($ID) > 0
                    
&& intval($arMessageFields["LOG_ID"]) > 0
                
)
                {
                    foreach(
GetModuleEvents("blog""OnBlogPostMentionNotifyIm"true) as $arEvent)
                    {
                        
ExecuteModuleEventEx($arEvent, Array($ID$arMessageFields));
                    }
                }
            }
        }

        
$notifySubTag false;
        
// notify 'to' users and an author
        
if (!empty($arUsers))
        {
            if(
$arParams["TYPE"] == "POST")
            {
                
$arMessageFields["PUSH_PARAMS"] = array(
                    
"ACTION" => "post"
                
);

                if (!empty(
$authorAvatarUrl))
                {
                    
$arMessageFields["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
                        
'avatarUrl' => $authorAvatarUrl,
                        
'senderName' => $authorName
                    
);
                }

                
$arMessageFields["NOTIFY_EVENT"] = "post";

                
$notifySubTag $arMessageFields["NOTIFY_TAG"] = "BLOG|POST|".$arParams["ID"];

                if (!
$bTitleEmpty)
                {
                    
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                        
"BLG_GP_IM_1".$aditGM,
                        array(
                            
"#title#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>"
                        
)
                    );
                    
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                            
"BLG_GP_IM_1".$aditGM,
                            array(
                                
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])
                            )
                        ).
" ".$serverName.$arParams["URL"]."";
                    
$arMessageFields["PUSH_MESSAGE"] = GetMessage(
                        
"BLG_GP_PUSH_1".$aditGM,
                        array(
                            
"#name#" => $authorName,
                            
"#title#" => $arParams["TITLE"]
                        )
                    );
                }
                else
                {
                    
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                        
"BLG_GP_IM_1A".$aditGM,
                        array(
                            
"#post#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_1B")."</a>"
                        
)
                    );
                    
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                            
"BLG_GP_IM_1A".$aditGM,
                            array(
                                
"#post#" => GetMessage("BLG_GP_IM_1B")
                            )
                        ).
" ".$serverName.$arParams["URL"]."";
                    
$arMessageFields["PUSH_MESSAGE"] = GetMessage(
                        
"BLG_GP_PUSH_1A".$aditGM,
                        array(
                            
"#name#" => htmlspecialcharsbx($authorName),
                            
"#post#" => GetMessage("BLG_GP_IM_1B")
                        )
                    );
                }
            }
            elseif(
$arParams["TYPE"] == "COMMENT")
            {
                
$arMessageFields["PUSH_PARAMS"] = array(
                    
"ACTION" => "comment"
                
);

                if (!empty(
$authorAvatarUrl))
                {
                    
$arMessageFields["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
                        
'avatarUrl' => $authorAvatarUrl,
                        
'senderName' => $authorName
                    
);
                }

                
$arMessageFields["NOTIFY_EVENT"] = "comment";

                
$arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT|".$arParams["ID"].'|'.$arParams["COMMENT_ID"];
                
$notifySubTag "BLOG|COMMENT|".$arParams["COMMENT_ID"];

                
$commentCropped truncateText($arParams["BODY"], 100);

                if (!
$bTitleEmpty)
                {
                    
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                        
"BLG_GP_IM_41".$aditGM,
                        array(
                            
"#title#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
                            
"#comment#" => $commentCropped
                        
)
                    );
                    
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                            
"BLG_GP_IM_41".$aditGM,
                            array(
                                
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
                                
"#comment#" => $arParams["BODY"]
                            )
                        ).
" ".$serverName.$arParams["URL"]."\n\n".$arParams["BODY"];
                    
$arMessageFields["PUSH_MESSAGE"] = GetMessage(
                        
"BLG_GP_PUSH_41".$aditGM,
                        array(
                            
"#name#" => htmlspecialcharsbx($authorName),
                            
"#title#" => htmlspecialcharsbx($arParams["TITLE"]),
                            
"#comment#" => $commentCropped
                        
)
                    );

                    
$arMessageFields["NOTIFY_MESSAGE_AUTHOR"] = GetMessage(
                        
"BLG_GP_IM_51".$aditGM,
                        array(
                            
"#title#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
                            
"#comment#" => $commentCropped
                        
)
                    );
                    
$arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"] = GetMessage(
                            
"BLG_GP_IM_51".$aditGM,
                            array(
                                
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
                                
"#comment#" => $arParams["BODY"]
                            )
                        ).
" ".$serverName.$arParams["URL"]."\n\n".$arParams["BODY"];
                    
$arMessageFields["PUSH_MESSAGE_AUTHOR"] = GetMessage(
                        
"BLG_GP_PUSH_51".$aditGM,
                        array(
                            
"#name#" => htmlspecialcharsbx($authorName),
                            
"#title#" => htmlspecialcharsbx($arParams["TITLE"]),
                            
"#comment#" => $commentCropped
                        
)
                    );
                }
                else
                {
                    
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                        
"BLG_GP_IM_41A".$aditGM,
                        array(
                            
"#post#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_4B")."</a>",
                            
"#comment#" => $commentCropped
                        
)
                    );
                    
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                            
"BLG_GP_IM_41A".$aditGM,
                            array(
                                
"#post#" => GetMessage("BLG_GP_IM_4B"),
                                
"#comment#" => $arParams["BODY"]
                            )
                        ).
" ".$serverName.$arParams["URL"]."\n\n".$arParams["BODY"];
                    
$arMessageFields["PUSH_MESSAGE"] = GetMessage(
                        
"BLG_GP_PUSH_41A".$aditGM,
                        array(
                            
"#name#" => htmlspecialcharsbx($authorName),
                            
"#post#" => GetMessage("BLG_GP_IM_4B"),
                            
"#comment#" => $commentCropped
                        
)
                    );

                    
$arMessageFields["NOTIFY_MESSAGE_AUTHOR"] = GetMessage(
                        
"BLG_GP_IM_51A".$aditGM,
                        array(
                            
"#post#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_5B")."</a>",
                            
"#comment#" => $commentCropped
                        
)
                    );
                    
$arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"] = GetMessage(
                            
"BLG_GP_IM_51A".$aditGM,
                            Array(
                                
"#post#" => GetMessage("BLG_GP_IM_5B"),
                                
"#comment#" => $arParams["BODY"]
                            )
                        ).
" ".$serverName.$arParams["URL"]."\n\n".$arParams["BODY"];
                    
$arMessageFields["PUSH_MESSAGE_AUTHOR"] = GetMessage(
                        
"BLG_GP_PUSH_51A".$aditGM,
                        array(
                            
"#name#" => htmlspecialcharsbx($authorName),
                            
"#post#" => GetMessage("BLG_GP_IM_5B"),
                            
"#comment#" => $commentCropped
                        
)
                    );
                }
            }
            elseif(
$arParams["TYPE"] == "SHARE")
            {
                
$arMessageFields["PUSH_PARAMS"] = array(
                    
"ACTION" => "share"
                
);

                if (!empty(
$authorAvatarUrl))
                {
                    
$arMessageFields["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
                        
'avatarUrl' => $authorAvatarUrl,
                        
'senderName' => $authorName
                    
);
                }

                
$arMessageFields["NOTIFY_EVENT"] = "share";
                
$arMessageFields["NOTIFY_TAG"] = "BLOG|SHARE|".$arParams["ID"];
                
$notifySubTag "BLOG|POST|".$arParams["ID"];

                if (!
$bTitleEmpty)
                {
                    
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                        
"BLG_GP_IM_8".$aditGM,
                        array(
                            
"#title#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>"
                        
)
                    );
                    
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                            
"BLG_GP_IM_8".$aditGM,
                            Array(
                                
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])
                            )
                        ).
" ".$serverName.$arParams["URL"]."";
                    
$arMessageFields["PUSHMESSAGE"] = GetMessage(
                        
"BLG_GP_PUSH_8".$aditGM,
                        array(
                            
"#name#" => htmlspecialcharsbx($authorName),
                            
"#title#" => htmlspecialcharsbx($arParams["TITLE"])
                        )
                    );
                }
                else
                {
                    
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                        
"BLG_GP_IM_8A".$aditGM,
                        array(
                            
"#post#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_8B")."</a>"
                        
)
                    );
                    
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                            
"BLG_GP_IM_8A".$aditGM,
                            array(
                                
"#post#" => GetMessage("BLG_GP_IM_8B")
                            )
                        ).
" ".$serverName.$arParams["URL"]."";
                    
$arMessageFields["PUSH_MESSAGE"] = GetMessage(
                        
"BLG_GP_PUSH_8A".$aditGM,
                        array(
                            
"#name#" => htmlspecialcharsbx($authorName),
                            
"#post#" => GetMessage("BLG_GP_IM_8B")
                        )
                    );
                }
            }
            elseif(
$arParams["TYPE"] == "SHARE2USERS")
            {
                
$arMessageFields["PUSH_PARAMS"] = array(
                    
"ACTION" => "share2users"
                
);

                if (!empty(
$authorAvatarUrl))
                {
                    
$arMessageFields["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
                        
'avatarUrl' => $authorAvatarUrl,
                        
'senderName' => $authorName
                    
);
                }

                
$arMessageFields["NOTIFY_EVENT"] = "share2users";
                
$arMessageFields["NOTIFY_TAG"] = "BLOG|SHARE2USERS|".$arParams["ID"];
                
$notifySubTag "BLOG|POST|".$arParams["ID"];

                if (!
$bTitleEmpty)
                {
                    
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                        
"BLG_GP_IM_9".$aditGM,
                        array(
                            
"#title#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>"
                        
)
                    );
                    
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                            
"BLG_GP_IM_9".$aditGM,
                            array(
                                
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])
                            )
                        ).
" ".$serverName.$arParams["URL"]."";
                    
$arMessageFields["PUSH_MESSAGE"] = GetMessage(
                        
"BLG_GP_PUSH_9".$aditGM,
                        array(
                            
"#name#" => htmlspecialcharsbx($authorName),
                            
"#title#" => htmlspecialcharsbx($arParams["TITLE"])
                        )
                    );
                }
                else
                {
                    
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                        
"BLG_GP_IM_9A".$aditGM,
                        array(
                            
"#post#" => "<a href=\"".$arParams["URL"]."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_9B")."</a>"
                        
)
                    );
                    
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                            
"BLG_GP_IM_9A".$aditGM,
                            array(
                                
"#post#" => GetMessage("BLG_GP_IM_9B")
                            )
                        ).
" ".$serverName.$arParams["URL"]."";
                    
$arMessageFields["PUSH_MESSAGE"] = GetMessage(
                        
"BLG_GP_PUSH_9A".$aditGM,
                        array(
                            
"#name#" => htmlspecialcharsbx($authorName),
                            
"#post#" => GetMessage("BLG_GP_IM_9B")
                        )
                    );
                }
            }

            
$arMessageFields["PUSH_PARAMS"]["TAG"] = $arMessageFields["NOTIFY_TAG"];
        }

        foreach(
$arUsers as $v)
        {
            if(
                
in_array($v$arUserIDSent)
                || (
                    !empty(
$arParams["EXCLUDE_USERS"])
                    && 
IntVal($arParams["EXCLUDE_USERS"][$v]) > 0
                
)
            )
            {
                continue;
            }

            if (
IsModuleInstalled("extranet"))
            {
                
$arTmp CSocNetLogTools::ProcessPath(
                    array(
                        
"URL" => $arParams["URL"],
                    ),
                    
$v,
                    
SITE_ID
                
);
                
$url $arTmp["URLS"]["URL"];

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

                if(
$arParams["TYPE"] == "POST")
                {
                    if (!
$bTitleEmpty)
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_1".$aditGM, Array("#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>"));
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_1".$aditGM, Array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])))." (".$serverName.$url.")";
                    }
                    else
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_1A".$aditGM, Array("#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_1B")."</a>"));
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_1A".$aditGM, Array("#post#" => GetMessage("BLG_GP_IM_1B")))." (".$serverName.$url.")";
                    }
                }
                elseif(
$arParams["TYPE"] == "COMMENT")
                {
                    
$commentCropped truncateText($arParams["BODY"], 100);

                    if (!
$bTitleEmpty)
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_41".$aditGM, array(
                            
"#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
                            
"#comment#" => $commentCropped
                        
));
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_41".$aditGM, array(
                                
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
                                
"#comment#" => $arParams["BODY"]
                            )).
" ".$serverName.$url;
                        
$arMessageFields["NOTIFY_MESSAGE_AUTHOR"] = GetMessage("BLG_GP_IM_51".$aditGM, array(
                            
"#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>",
                            
"#comment#" => $commentCropped
                        
));
                        
$arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"] = GetMessage("BLG_GP_IM_51".$aditGM, array(
                                
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"]),
                                
"#comment#" => $arParams["BODY"]
                            )).
" ".$serverName.$url;
                    }
                    else
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_41A".$aditGM, array(
                            
"#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_4B")."</a>",
                            
"#comment#" => $commentCropped
                        
));
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_41A".$aditGM, array(
                                
"#post#" => GetMessage("BLG_GP_IM_4B"),
                                
"#comment#" => $arParams["BODY"]
                            )).
" ".$serverName.$url;
                        
$arMessageFields["NOTIFY_MESSAGE_AUTHOR"] = GetMessage("BLG_GP_IM_51A".$aditGM, array(
                            
"#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_5B")."</a>",
                            
"#comment#" => $commentCropped
                        
));
                        
$arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"] = GetMessage("BLG_GP_IM_51A".$aditGM, array(
                                
"#post#" => GetMessage("BLG_GP_IM_5B"),
                                
"#comment#" => $arParams["BODY"]
                            )).
" ".$serverName.$url;
                    }
                }
                elseif(
$arParams["TYPE"] == "SHARE")
                {
                    if (!
$bTitleEmpty)
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_8".$aditGM, Array("#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>"));
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_8".$aditGM, Array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])))." ".$serverName.$url."";
                    }
                    else
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_8A".$aditGM, Array("#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_8B")."</a>"));
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_8A".$aditGM, Array("#post#" => GetMessage("BLG_GP_IM_8B")))." ".$serverName.$url."";
                    }
                }
                elseif(
$arParams["TYPE"] == "SHARE2USERS")
                {
                    if (!
$bTitleEmpty)
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_9".$aditGM, Array("#title#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".htmlspecialcharsbx($arParams["TITLE"])."</a>"));
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_9".$aditGM, Array("#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])))." ".$serverName.$url."";
                    }
                    else
                    {
                        
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage("BLG_GP_IM_9A".$aditGM, Array("#post#" => "<a href=\"".$url."\" class=\"bx-notifier-item-action\">".GetMessage("BLG_GP_IM_9B")."</a>"));
                        
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage("BLG_GP_IM_9A".$aditGM, Array("#post#" => GetMessage("BLG_GP_IM_9B")))." ".$serverName.$url."";
                    }
                }
            }

            
$arMessageFieldsTmp $arMessageFields;
            if(
$arParams["TYPE"] == "COMMENT")
            {
                if(
$arParams["AUTHOR_ID"] == $v)
                {
                    
$arMessageFieldsTmp["NOTIFY_MESSAGE"] = $arMessageFields["NOTIFY_MESSAGE_AUTHOR"];
                    
$arMessageFieldsTmp["NOTIFY_MESSAGE_OUT"] = $arMessageFields["NOTIFY_MESSAGE_AUTHOR_OUT"];
                    
$arMessageFieldsTmp["PUSH_MESSAGE"] = $arMessageFields["PUSH_MESSAGE_AUTHOR"];
                }
            }

            
$arMessageFieldsTmp["TO_USER_ID"] = $v;
            if (
$notifySubTag)
            {
                
$arMessageFieldsTmp["NOTIFY_SUB_TAG"] = $notifySubTag."|".$v;
            }

            
CIMNotify::Add($arMessageFieldsTmp);

            
$arUserIDSent[] = $v;
        }

        
// notify sonet groups subscribers
        
if (
            
$arParams["TYPE"] == "POST"
            
&& !empty($arParams["TO_SOCNET_RIGHTS"])
        )
        {
            
$arGroupsId = array();
            foreach(
$arParams["TO_SOCNET_RIGHTS"] as $perm_tmp)
            {
                if (
                    
preg_match('/^SG(\d+)_'.SONET_ROLES_USER.'$/'$perm_tmp$matches)
                    || 
preg_match('/^SG(\d+)$/'$perm_tmp$matches)
                )
                {
                    
$group_id_tmp $matches[1];
                    if (
                        
$group_id_tmp 
                        
&& (
                            !
array_key_exists("SG"$arParams["TO_SOCNET_RIGHTS_OLD"]) 
                            || empty(
$arParams["TO_SOCNET_RIGHTS_OLD"]["SG"][$group_id_tmp])
                        )
                    )
                    {
                        
$arGroupsId[] = $group_id_tmp;
                    }
                }
            }

            if (!empty(
$arGroupsId))
            {
                
$arTitle self::processNotifyTitle($arParams["TITLE"]);
                
$title $arTitle['TITLE'];
                
$title_out $arTitle['TITLE_OUT'];

                
$arNotifyParams = array(
                    
"LOG_ID" => $arMessageFields["LOG_ID"],
                    
"GROUP_ID" => $arGroupsId,
                    
"NOTIFY_MESSAGE" => "",
                    
"FROM_USER_ID" => $arParams["FROM_USER_ID"],
                    
"URL" => $arParams["URL"],
                    
"MESSAGE" => GetMessage("SONET_IM_NEW_POST", Array(
                        
"#title#" => "[URL=#URL#]".$title."[/URL]",
                    )),
                    
"MESSAGE_CHAT" => GetMessage("SONET_IM_NEW_POST_CHAT".$aditGM, Array(
                        
"#title#" => "[URL=#URL#]".$title_out."[/URL]",
                    )),
                    
"MESSAGE_OUT" => GetMessage("SONET_IM_NEW_POST", Array(
                        
"#title#" => $title_out
                    
))." #URL#",
                    
"EXCLUDE_USERS" => array_merge(array($arParams["FROM_USER_ID"]), array($arUserIDSent)),
                    
"PERMISSION" => array(
                        
"FEATURE" => "blog",
                        
"OPERATION" => "view_post"
                    
)
                );

                
$arUserIDSentBySubscription CSocNetSubscription::NotifyGroup($arNotifyParams);
                if (!
$arUserIDSentBySubscription)
                {
                    
$arUserIDSentBySubscription = array();
                }
                
$arUserIDSent array_merge($arUserIDSent$arUserIDSentBySubscription);
            }
        }

        if (
            !empty(
$arParams['GRAT_DATA'])
            && 
is_array($arParams['GRAT_DATA'])
            && !empty(
$arParams['GRAT_DATA']['USERS'])
            && 
is_array($arParams['GRAT_DATA']['USERS'])
        )
        {
            
$arMessageFieldsGrat $arMessageFields;
            
$arMessageFieldsGrat["NOTIFY_EVENT"] = 'grat';
            
$arMessageFieldsGrat["NOTIFY_TAG"] = "BLOG|POST|".$arParams["ID"];
            
$arMessageFieldsGrat["PUSH_PARAMS"] = [
                
"ACTION" => "post",
                
"TAG" => $arMessageFieldsGrat["NOTIFY_TAG"]
            ];
            if (!empty(
$authorAvatarUrl))
            {
                
$arMessageFields["PUSH_PARAMS"]["ADVANCED_PARAMS"] = array(
                    
'avatarUrl' => $authorAvatarUrl,
                    
'senderName' => $authorName
                
);
            }

            
$arMessageFieldsGrat["NOTIFY_MESSAGE"] = Loc::getMessage('SONET_IM_POST_GRAT'.$aditGM, [
                
"#link_post_start#" => "<a href=\"".$urlOriginal."\" class=\"bx-notifier-item-action\">",
                
"#link_post_end#" => "</a>",
                
"#title#" => htmlspecialcharsbx($arParams["TITLE"])
            ]);

            
$arMessageFieldsGrat["NOTIFY_MESSAGE_OUT"] = Loc::getMessage('SONET_IM_POST_GRAT'.$aditGM, [
                
"#link_post_start#" => "",
                
"#link_post_end#" => "",
                
"#title#" => htmlspecialcharsbx($arParams["TITLE"])
            ]).
" ".$serverName.$urlOriginal."";
            
$arMessageFieldsGrat["PUSH_MESSAGE"] = Loc::getMessage('SONET_PUSH_POST_GRAT'.$aditGM, [
                
"#name#" => htmlspecialcharsbx($authorName),
                
"#title#" => htmlspecialcharsbx($arParams["TITLE"])
            ]);

            foreach(
$arParams['GRAT_DATA']['USERS'] as $gratUserId)
            {
                if (
                    
in_array($gratUserId$arUserIDSent)
                    || 
$arParams["FROM_USER_ID"] == $gratUserId
                
)
                {
                    continue;
                }

                
$postPerm CBlogPost::GetSocNetPostPerms(array(
                    
"POST_ID" => $arParams["ID"],
                    
"NEED_FULL" => true,
                    
"USER_ID" => $gratUserId,
                    
"IGNORE_ADMIN" => true
                
));

                if (
$postPerm BLOG_PERMS_READ)
                {
                    continue;
                }

                
$arMessageFieldsTmp $arMessageFieldsGrat;
                
$arMessageFieldsTmp['TO_USER_ID'] = $gratUserId;
                
$arMessageFieldsTmp['NOTIFY_SUB_TAG'] = "BLOG|POST|".$arParams["ID"]."|".$gratUserId;

                
CIMNotify::Add($arMessageFieldsTmp);
                
$arUserIDSent[] = $gratUserId;
            }
        }

        return 
$arUserIDSent;
    }