CBlogPost :: NotifyImReady: Bitrix method

      
<?php 
//  CBlogPost :: NotifyImReady()
//  /dist/bitrix/modules/blog/general/blog_post.php:2795

    
public static function NotifyImReady($arParams = array())
    {
        
$arUserIDSent = array();
        
$moderatorList = array();

        if (
            !
Loader::includeModule("im")
            || !
Loader::includeModule("socialnetwork")
        )
        {
            return 
$arUserIDSent;
        }

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

        if (
            isset(
$arParams["TO_SOCNET_RIGHTS"])
            && 
is_array($arParams["TO_SOCNET_RIGHTS"])
            && !empty(
$arParams["TO_SOCNET_RIGHTS"])
        )
        {
            
$arGroupChecked = array();
            foreach(
$arParams["TO_SOCNET_RIGHTS"] as $code)
            {

                if (
preg_match('/^SG(\d+)/'$code$matches))
                {
                    
$sonetGroupId intval($matches[1]);

                    if (
in_array($sonetGroupId$arGroupChecked))
                    {
                        break;
                    }
                    else
                    {
                        
$arGroupChecked[] = $sonetGroupId;
                    }

                    if (
$sonetGroupId 0)
                    {
                        
$featureOperationPerms CSocNetFeaturesPerms::GetOperationPerm(
                            
SONET_ENTITY_GROUP,
                            
$sonetGroupId,
                            
'blog',
                            (
$arParams['TYPE'] == 'POST' 'moderate_post' 'moderate_comment')
                        );

                        if (
$featureOperationPerms)
                        {
                            
$res = \Bitrix\Socialnetwork\UserToGroupTable::getList(array(
                                
'filter' => array(
                                    
'<=ROLE' => $featureOperationPerms,
                                    
'GROUP_ID' => $sonetGroupId,
                                    
'=GROUP.ACTIVE' => 'Y'
                                
),
                                
'select' => array('USER_ID')
                            ));
                            while (
$relation $res->fetch())
                            {
                                if (!isset(
$moderatorList[$relation['USER_ID']]))
                                {
                                    
$moderatorList[$relation['USER_ID']] = array(
                                        
'USER_ID' => $relation['USER_ID'],
                                        
'GROUP_ID' => $sonetGroupId
                                    
);
                                }
                            }
                        }
                    }
                }
            }
        }

        if (!empty(
$moderatorList))
        {
            
$arMessageFields = array(
                
"MESSAGE_TYPE" => IM_MESSAGE_SYSTEM,
                
"NOTIFY_TYPE" => IM_NOTIFY_SYSTEM,
                
"NOTIFY_MODULE" => "blog",
            );

            
$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"""));
            
$moderationUrl = \Bitrix\Main\Config\Option::get('socialnetwork''workgroups_page'SITE_DIR.'workgroups/').'group/#group_id#/blog/moderation/';

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

                
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                    (!
$bTitleEmpty "SONET_IM_NEW_POST_TO_MODERATE_W_TITLE" "SONET_IM_NEW_POST_TO_MODERATE_WO_TITLE"),
                    array(
                        
"#link_mod_start#" => "<a href=\"#MODERATION_URL#\" class=\"bx-notifier-item-action\">",
                        
"#link_mod_end#" => "</a>",
                        
"#title#" => htmlspecialcharsbx($arParams["TITLE"])
                    )
                );

                
$arMessageFields["NOTIFY_MESSAGE_OUT"] = GetMessage(
                    (!
$bTitleEmpty "SONET_IM_NEW_POST_TO_MODERATE_W_TITLE" "SONET_IM_NEW_POST_TO_MODERATE_WO_TITLE"),
                    array(
                        
"#link_mod_start#" => "",
                        
"#link_mod_end#" => "",
                        
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])
                    )
                ).
" #SERVER_NAME##MODERATION_URL#";
            }
            else
            {
                
$arMessageFields["NOTIFY_EVENT"] = "moderate_comment";
                
$arMessageFields["NOTIFY_TAG"] = "BLOG|COMMENT|".$arParams["POST_ID"].'|'.$arParams["COMMENT_ID"];

                
$arMessageFields["NOTIFY_MESSAGE"] = GetMessage(
                    (!
$bTitleEmpty "SONET_IM_NEW_COMMENT_TO_MODERATE_W_TITLE" "SONET_IM_NEW_COMMENT_TO_MODERATE_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_TO_MODERATE_W_TITLE" "SONET_IM_NEW_COMMENT_TO_MODERATE_WO_TITLE"),
                        array(
                            
"#link_com_start#" => "",
                            
"#link_com_end#" => "",
                            
"#title#" => htmlspecialcharsbx($arParams["TITLE_OUT"])
                        )
                    ).
" #SERVER_NAME##COMMENT_URL#";
            }

            foreach(
$moderatorList as $moderator)
            {
                
$moderatorId $moderator['USER_ID'];
                
$groupId $moderator['GROUP_ID'];

                if (
$moderatorId != $arParams["FROM_USER_ID"])
                {
                    
$arMessageFieldsCurrent $arMessageFields;
                    
$arMessageFieldsCurrent["TO_USER_ID"] = $moderatorId;

                    
$userModerationUrl str_replace('#group_id#'$groupId$moderationUrl);
                    
$userCommentUrl $arParams['COMMENT_URL'];

                    if (
IsModuleInstalled("extranet"))
                    {
                        
$arTmp CSocNetLogTools::ProcessPath(
                            array(
                                
"MODERATION_URL" => $userModerationUrl,
                                
"COMMENT_URL" => (isset($arParams['COMMENT_URL']) ? $arParams['COMMENT_URL'] : '')
                            ),
                            
$moderatorId,
                            
SITE_ID
                        
);

                        
$userModerationUrl $arTmp["URLS"]["MODERATION_URL"];
                        
$userCommentUrl $arTmp["URLS"]["COMMENT_URL"];

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

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

                    
CIMNotify::Add($arMessageFieldsCurrent);

                    
$arUserIDSent[] = $moderatorId;
                }
            }
        }

        return 
$arUserIDSent;
    }