CBlogPost::CheckFields: Bitrix method

      
<?php 
//  CBlogPost :: CheckFields()
//  /dist/bitrix/modules/blog/general/blog_post.php:185

    
public static function CheckFields($ACTION, &$arFields$ID 0)
    {
        global 
$DB$APPLICATION;

        if ((
is_set($arFields"DETAIL_TEXT") || $ACTION=="ADD") && strlen(trim(str_replace("\xc2\xa0"' '$arFields["DETAIL_TEXT"]), " \t\n\r\0\x0B\xA0")) <= 0)
        {
            
$APPLICATION->ThrowException(GetMessage("BLG_GP_EMPTY_DETAIL_TEXT"), "EMPTY_DETAIL_TEXT");
            return 
false;
        }

        if ((
is_set($arFields"TITLE") || $ACTION=="ADD") && strlen($arFields["TITLE"]) <= 0)
        {
            
$APPLICATION->ThrowException(GetMessage("BLG_GP_EMPTY_TITLE"), "EMPTY_TITLE");
            return 
false;
        }

        if ((
is_set($arFields"BLOG_ID") || $ACTION=="ADD") && IntVal($arFields["BLOG_ID"]) <= 0)
        {
            
$APPLICATION->ThrowException(GetMessage("BLG_GP_EMPTY_BLOG_ID"), "EMPTY_BLOG_ID");
            return 
false;
        }
        elseif (
is_set($arFields"BLOG_ID"))
        {
            
$arResult CBlog::GetByID($arFields["BLOG_ID"]);
            if (!
$arResult)
            {
                
$APPLICATION->ThrowException(str_replace("#ID#"$arFields["BLOG_ID"], GetMessage("BLG_GP_ERROR_NO_BLOG")), "ERROR_NO_BLOG");
                return 
false;
            }
        }

        if ((
is_set($arFields"AUTHOR_ID") || $ACTION=="ADD") && IntVal($arFields["AUTHOR_ID"]) <= 0)
        {
            
$APPLICATION->ThrowException(GetMessage("BLG_GP_EMPTY_AUTHOR_ID"), "EMPTY_AUTHOR_ID");
            return 
false;
        }
        elseif (
is_set($arFields"AUTHOR_ID"))
        {
            
$dbResult CUser::GetByID($arFields["AUTHOR_ID"]);
            if (!
$dbResult->Fetch())
            {
                
$APPLICATION->ThrowException(GetMessage("BLG_GP_ERROR_NO_AUTHOR"), "ERROR_NO_AUTHOR");
                return 
false;
            }
        }

        if (
is_set($arFields"DATE_CREATE") && (!$DB->IsDate($arFields["DATE_CREATE"], falseLANG"FULL")))
        {
            
$APPLICATION->ThrowException(GetMessage("BLG_GP_ERROR_DATE_CREATE"), "ERROR_DATE_CREATE");
            return 
false;
        }

        if (
is_set($arFields"DATE_PUBLISH") && (!$DB->IsDate($arFields["DATE_PUBLISH"], falseLANG"FULL")))
        {
            
$APPLICATION->ThrowException(GetMessage("BLG_GP_ERROR_DATE_PUBLISH"), "ERROR_DATE_PUBLISH");
            return 
false;
        }


        
$arFields["PREVIEW_TEXT_TYPE"] = strtolower($arFields["PREVIEW_TEXT_TYPE"]);
        if ((
is_set($arFields"PREVIEW_TEXT_TYPE") || $ACTION=="ADD") && $arFields["PREVIEW_TEXT_TYPE"] != "text" && $arFields["PREVIEW_TEXT_TYPE"] != "html")
            
$arFields["PREVIEW_TEXT_TYPE"] = "text";

        
//$arFields["DETAIL_TEXT_TYPE"] = strtolower($arFields["DETAIL_TEXT_TYPE"]);
        
if ((is_set($arFields"DETAIL_TEXT_TYPE") || $ACTION=="ADD") && strtolower($arFields["DETAIL_TEXT_TYPE"]) != "text" && strtolower($arFields["DETAIL_TEXT_TYPE"]) != "html")
            
$arFields["DETAIL_TEXT_TYPE"] = "text";
        if(
strlen($arFields["DETAIL_TEXT_TYPE"]) > 0)
            
$arFields["DETAIL_TEXT_TYPE"] = strtolower($arFields["DETAIL_TEXT_TYPE"]);

        
$arStatus array_keys($GLOBALS["AR_BLOG_PUBLISH_STATUS"]);
        if ((
is_set($arFields"PUBLISH_STATUS") || $ACTION=="ADD") && !in_array($arFields["PUBLISH_STATUS"], $arStatus))
            
$arFields["PUBLISH_STATUS"] = $arStatus[0];

        if ((
is_set($arFields"ENABLE_TRACKBACK") || $ACTION=="ADD") && $arFields["ENABLE_TRACKBACK"] != "Y" && $arFields["ENABLE_TRACKBACK"] != "N")
            
$arFields["ENABLE_TRACKBACK"] = "Y";

        if ((
is_set($arFields"ENABLE_COMMENTS") || $ACTION=="ADD") && $arFields["ENABLE_COMMENTS"] != "Y" && $arFields["ENABLE_COMMENTS"] != "N")
            
$arFields["ENABLE_COMMENTS"] = "Y";

        if (!empty(
$arFields["ATTACH_IMG"]))
        {
            
$res CFile::CheckImageFile($arFields["ATTACH_IMG"], 000);
            if (
strlen($res) > 0)
            {
                
$APPLICATION->ThrowException(GetMessage("BLG_GP_ERROR_ATTACH_IMG").": ".$res"ERROR_ATTACH_IMG");
                return 
false;
            }
        }
        else
            
$arFields["ATTACH_IMG"] = false;

        if (
is_set($arFields"NUM_COMMENTS"))
            
$arFields["NUM_COMMENTS"] = IntVal($arFields["NUM_COMMENTS"]);
        if (
is_set($arFields"NUM_COMMENTS_ALL"))
            
$arFields["NUM_COMMENTS_ALL"] = IntVal($arFields["NUM_COMMENTS_ALL"]);
        if (
is_set($arFields"NUM_TRACKBACKS"))
            
$arFields["NUM_TRACKBACKS"] = IntVal($arFields["NUM_TRACKBACKS"]);
        if (
is_set($arFields"FAVORITE_SORT"))
        {
            
$arFields["FAVORITE_SORT"] = IntVal($arFields["FAVORITE_SORT"]);
            if(
$arFields["FAVORITE_SORT"] <= 0)
                
$arFields["FAVORITE_SORT"] = false;
        }

        if (
is_set($arFields"CODE") && strlen($arFields["CODE"]) > 0)
        {
            
$arFields["CODE"] = preg_replace("/[^a-zA-Z0-9_-]/is"""Trim($arFields["CODE"]));
//            preserve collision between numeric code and post ID.
            
$arFields["CODE"] = is_numeric($arFields["CODE"]) ? "_".$arFields["CODE"] : $arFields["CODE"];
            
            if (
in_array(strtolower($arFields["CODE"]), $GLOBALS["AR_BLOG_POST_RESERVED_CODES"]))
            {
                
$APPLICATION->ThrowException(str_replace("#CODE#"$arFields["CODE"], GetMessage("BLG_GP_RESERVED_CODE")), "CODE_RESERVED");
                return 
false;
            }

            
$arFilter = Array(
                
"CODE" => $arFields["CODE"]
            );
            if(
IntVal($ID) > 0)
            {
                
$arPost CBlogPost::GetByID($ID);
                
$arFilter["!ID"] = $arPost["ID"];
                
$arFilter["BLOG_ID"] = $arPost["BLOG_ID"];
            }
            else
            {
                if(
IntVal($arFields["BLOG_ID"]) > 0)
                    
$arFilter["BLOG_ID"] = $arFields["BLOG_ID"];
            }

            
$dbItem CBlogPost::GetList(Array(), $arFilterfalse, Array("nTopCount" => 1), Array("ID""CODE""BLOG_ID"));
            if(
$dbItem->Fetch())
            {
                
$APPLICATION->ThrowException(GetMessage("BLG_GP_CODE_EXIST", Array("#CODE#" => $arFields["CODE"])), "CODE_EXIST");
                return 
false;
            }
        }
        return 
True;
    }