- Модуль: subscribe
- Путь к файлу: ~/bitrix/modules/subscribe/classes/general/template.php
- Класс: CPostingTemplate
- Вызов: CPostingTemplate::AddPosting
static function AddPosting($arRubric)
{
global $DB, $USER, $MESS;
if(!is_object($USER)) $USER = new CUser;
//Include language file for template.php
$rsSite = CSite::GetByID($arRubric["SITE_ID"]);
$arSite = $rsSite->Fetch();
$rsLang = CLanguage::GetByID($arSite["LANGUAGE_ID"]);
$arLang = $rsLang->Fetch();
$strBody="";
$arFields=false;
if(CPostingTemplate::IsExists($arRubric["TEMPLATE"]))
{
$strFileName= $_SERVER["DOCUMENT_ROOT"]."/".$arRubric["TEMPLATE"]."/lang/".$arSite["LANGUAGE_ID"]."/template.php";
if(file_exists($strFileName))
include($strFileName);
//Execute template
$strFileName= $_SERVER["DOCUMENT_ROOT"]."/".$arRubric["TEMPLATE"]."/template.php";
if(file_exists($strFileName))
{
ob_start();
$arFields = @include($strFileName);
$strBody = ob_get_contents();
ob_end_clean();
}
}
$ID = false;
//If there was an array returned then add posting
if(is_array($arFields))
{
$arFields["BODY"] = $strBody;
$cPosting=new CPosting;
$arFields["AUTO_SEND_TIME"]=$arRubric["END_TIME"];
$arFields["RUB_ID"]=array($arRubric["ID"]);
$arFields["MSG_CHARSET"] = $arLang["CHARSET"];
$ID = $cPosting->Add($arFields);
if($ID)
{
if(array_key_exists("FILES", $arFields))
{
foreach($arFields["FILES"] as $arFile)
$cPosting->SaveFile($ID, $arFile);
}
if(!array_key_exists("DO_NOT_SEND", $arFields) || $arFields["DO_NOT_SEND"]!="Y")
{
$cPosting->ChangeStatus($ID, "P");
if(COption::GetOptionString("subscribe", "subscribe_auto_method")!=="cron")
CAgent::AddAgent("CPosting::AutoSend(".$ID.",true,"".$arRubric["LID"]."");", "subscribe", "N", 0, $arRubric["END_TIME"], "Y", $arRubric["END_TIME"]);
}
}
}
//Update last execution time mark
$strSql = "UPDATE b_list_rubric SET LAST_EXECUTED=".$DB->CharToDateFunction($arRubric["END_TIME"])." WHERE ID=".intval($arRubric["ID"]);
$DB->Query($strSql, false, "File: ".__FILE__."
Line: ".__LINE__);
return $ID;
}