CBPHelper :: ConvertTextForMail: Bitrix method

      
<?php 
//  CBPHelper :: ConvertTextForMail()
//  /dist/bitrix/modules/bizproc/classes/general/helper.php:1676

    
public static function ConvertTextForMail($text$siteId false)
    {
        if (
is_array($text))
        {
            
$text implode(', '$text);
        }

        
$text trim($text);
        if (
strlen($text) <= 0)
        {
            return 
"";
        }

        if (!
$siteId)
        {
            
$siteId SITE_ID;
        }

        
$arPattern $arReplace = [];

        
$arPattern[] = "/\[(code|quote)(.*?)\]/is".BX_UTF_PCRE_MODIFIER;
        
$arReplace[] = "\n>================== \\1 ===================\n";

        
$arPattern[] = "/\[\/(code|quote)(.*?)\]/is".BX_UTF_PCRE_MODIFIER;
        
$arReplace[] = "\n>===========================================\n";

        
$arPattern[] = "/\<WBR[\s\/]?\>/is".BX_UTF_PCRE_MODIFIER;
        
$arReplace[] = "";

        
$arPattern[] = "/^(\r|\n)+?(.*)$/";
        
$arReplace[] = "\\2";

        
$arPattern[] = "/\[b\](.+?)\[\/b\]/is".BX_UTF_PCRE_MODIFIER;
        
$arReplace[] = "\\1";

        
$arPattern[] = "/\[i\](.+?)\[\/i\]/is".BX_UTF_PCRE_MODIFIER;
        
$arReplace[] = "\\1";

        
$arPattern[] = "/\[u\](.+?)\[\/u\]/is".BX_UTF_PCRE_MODIFIER;
        
$arReplace[] = "_\\1_";

        
$arPattern[] = "/\[s\](.+?)\[\/s\]/is".BX_UTF_PCRE_MODIFIER;
        
$arReplace[] = "_\\1_";

        
$arPattern[] = "/\[(\/?)(color|font|size)([^\]]*)\]/is".BX_UTF_PCRE_MODIFIER;
        
$arReplace[] = "";

        
//$arPattern[] = "/\[url\](\S+?)\[\/url\]/is".BX_UTF_PCRE_MODIFIER;
        //$arReplace[] = "(URL: \\1)";

        //$arPattern[] = "/\[url\s*=\s*(\S+?)\s*\](.*?)\[\/url\]/is".BX_UTF_PCRE_MODIFIER;
        //$arReplace[] = "\\2 (URL: \\1)";

        
$arPattern[] = "/\[img\](.+?)\[\/img\]/is".BX_UTF_PCRE_MODIFIER;
        
$arReplace[] = "(IMAGE: \\1)";

        
$arPattern[] = "/\[video([^\]]*)\](.+?)\[\/video[\s]*\]/is".BX_UTF_PCRE_MODIFIER;
        
$arReplace[] = "(VIDEO: \\2)";

        
$arPattern[] = "/\[(\/?)list\]/is".BX_UTF_PCRE_MODIFIER;
        
$arReplace[] = "\n";

        
$text preg_replace($arPattern$arReplace$text);


        
$dbSite CSite::GetByID($siteId);
        
$arSite $dbSite->Fetch();
        static::
$serverName $arSite["SERVER_NAME"];
        if (
strLen(static::$serverName) <= 0)
        {
            if (
defined("SITE_SERVER_NAME") && strlen(SITE_SERVER_NAME) > 0)
            {
                static::
$serverName SITE_SERVER_NAME;
            }
            else
            {
                static::
$serverName COption::GetOptionString("main""server_name""");
            }
        }

        
$text preg_replace_callback(
            
"/\[url\]([^\]]+?)\[\/url\]/i".BX_UTF_PCRE_MODIFIER,
            array(
"CBPHelper""__ConvertAnchorTag"),
            
$text
        
);
        
$text preg_replace_callback(
            
"/\[url\s*=\s*([^\]]+?)\s*\](.*?)\[\/url\]/is".BX_UTF_PCRE_MODIFIER,
            array(
"CBPHelper""__ConvertAnchorTag"),
            
$text
        
);

        return 
$text;
    }