CBlogPost :: AddSocNetPerms: Bitrix method

      
<?php 
//  CBlogPost :: AddSocNetPerms()
//  /dist/bitrix/modules/blog/general/blog_post.php:1121

    
public static function AddSocNetPerms($ID$perms = array(), $arPost = array())
    {
        global 
$CACHE_MANAGER;

        if(
IntVal($ID) <= 0)
            return 
false;

        
$arResult = Array();

        
// D - department
        // U - user
        // SG - socnet group
        // DR - department and hier
        // G - user group
        // AU - authorized user
        // CRMCONTACT - CRM contact
        //$bAU = false;

        
if(
            empty(
$perms)
            || 
in_array("UA"$perms)
        ) 
//if default rights or for everyone
        
{
            
CBlogPost::__AddSocNetPerms($ID"U"$arPost["AUTHOR_ID"], "US".$arPost["AUTHOR_ID"]); // for myself
            
$perms1 CBlogPost::GetSocnetGroups("U"$arPost["AUTHOR_ID"]);
            foreach(
$perms1 as $val)
            {
                if(
strlen($val) > 0)
                {
                    
CBlogPost::__AddSocNetPerms($ID"U"$arPost["AUTHOR_ID"], $val);

                    if(!
in_array($val$arResult))
                    {
                        
$arResult[] = $val;
                    }
                }
            }
        }
        if(!empty(
$perms))
        {
            
$perms array_unique($perms);

            foreach(
$perms as $val)
            {
                if(
$val == "UA")
                {
                    continue;
                }

                if(
strlen($val) > 0)
                {
                    if (
                        
preg_match('/^(CRMCONTACT)(\d+)$/i'$val$matches)
                        || 
preg_match('/^(DR)(\d+)$/i'$val$matches)
                        || 
preg_match('/^(SG)(\d+)$/i'$val$matches)
                        || 
preg_match('/^(AU)(\d+)$/i'$val$matches)
                        || 
preg_match('/^(U)(\d+)$/i'$val$matches)
                        || 
preg_match('/^(UP)(\d+)$/i'$val$matches)
                        || 
preg_match('/^(D)(\d+)$/i'$val$matches)
                        || 
preg_match('/^(G)(\d+)$/i'$val$matches)
                    )
                    {
                        
$scT $matches[1];
                        
$scID $matches[2];
                    }
                    else
                    {
                        continue;
                    }

                    if(
$scT == "SG")
                    {
                        
$permsNew CBlogPost::GetSocnetGroups("G"$scID);
                        foreach(
$permsNew as $val1)
                        {
                            
CBlogPost::__AddSocNetPerms($ID$scT$scID$val1);
                            if(!
in_array($val1$arResult))
                            {
                                
$arResult[] = $val1;
                            }
                        }
                    }

                    
CBlogPost::__AddSocNetPerms($ID$scT$scID$val);
                    if(!
in_array($val$arResult))
                    {
                        
$arResult[] = $val;
                    }
                }
            }
        }

        
BXClearCache(true"/blog/getsocnetperms/".$ID);
        if(
defined("BX_COMP_MANAGED_CACHE"))
        {
            
$CACHE_MANAGER->ClearByTag("blog_post_getsocnetperms_".$ID);
        }

        return 
$arResult;
    }