public static function CronRun($profileID, $in_cron = "N") { define("path2export", "/bitrix/php_interface/include/catalog_export/"); $pr = CProfileAdmin::GetByID($profileID)->Fetch(); $cron_period = intval($pr['PERIOD']); $cron_period = $cron_period <= 0 ? 86400 : $cron_period; $data = date("d.m.Y H:i:s", $pr['DATA_START']); $d = explode(" ", $data); $t = explode(":", $d[1]); $cron_hour = intval($t[0]); $cron_minute = intval($t[1]); $cron_hour = $cron_hour <= 0 ? 0 : $cron_hour; $cron_minute = $cron_minute <= 0 ? 0 : $cron_minute; $cron_php_path = COption::GetOptionString("acrit.googlemerchant", "php_path"); $cron_php_path = strlen($cron_php_path) > 0 ? $cron_php_path : getPHPExecutableFromPath(); if (file_exists($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php")) { CheckDirPath($_SERVER["DOCUMENT_ROOT"] . path2export); $tmp_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php"); $fp = fopen($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php", "rb"); $tmp_data = fread($fp, $tmp_file_size); fclose($fp); $tmp_data = str_replace("#DOCUMENT_ROOT#", $_SERVER["DOCUMENT_ROOT"], $tmp_data); $tmp_data = str_replace("#PHP_PATH#", $cron_php_path, $tmp_data); $fp = fopen($_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php", "w+"); fwrite($fp, $tmp_data); fclose($fp); } $cfg_data = ""; if (file_exists($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg")) { $cfg_file_size = filesize($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg"); $cfg_file_size = $cfg_file_size != 0 ? $cfg_file_size : 1; $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "rb"); $cfg_data = fread($fp, $cfg_file_size); fclose($fp); } CheckDirPath($_SERVER["DOCUMENT_ROOT"] . path2export . "logs/"); if ($in_cron == "Y") { $cfg_data = preg_replace("#^.*?" . preg_quote(path2export) . "acrit_gm_cron.php " . $profileID . " *>.*?\$#im", "", $cfg_data); } else { if ($cron_period > 0) { $strTime = "0 */" . $cron_period . " * * * "; } else { $strTime = intval($cron_minute) . " " . intval($cron_hour) . " * * * "; } if (strlen($cfg_data) > 0) { $cfg_data .= "\n"; } $cfg_data = preg_replace("#^.*?" . preg_quote(path2export) . "acrit_gm_cron.php " . $profileID . " *>.*?\$#im", "", $cfg_data); $cfg_data .= $strTime . $cron_php_path . " -f " . $_SERVER["DOCUMENT_ROOT"] . path2export . "acrit_gm_cron.php " . $profileID . " >" . $_SERVER["DOCUMENT_ROOT"] . path2export . "logs/" . $profileID . ".txt\n"; } CheckDirPath($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/"); $cfg_data = preg_replace("#[\r\n]{2,}#im", "\n", $cfg_data); $fp = fopen($_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", "wb"); fwrite($fp, $cfg_data); fclose($fp); $arRetval = array(); @exec("crontab " . $_SERVER["DOCUMENT_ROOT"] . "/bitrix/crontab/crontab.cfg", $arRetval, $return_var); }
} if ($iIblock) { $db_iblock_type = CIBlockType::GetList(); while ($ar_iblock_type = $db_iblock_type->Fetch()) { if ($arIBType = CIBlockType::GetByIDLang($ar_iblock_type["ID"], LANG)) { $arIBlockType[$arIBType["ID"]] = "[" . $arIBType["ID"] . "] " . htmlspecialcharsEx($arIBType["NAME"]); } } } $ID = intval($ID); // Id of the edited record $bCopy = $action == "copy"; $message = null; $bVarsFromForm = false; if ($REQUEST_METHOD == "POST" && ($save != "" || $apply != "") && $POST_RIGHT == "W" && check_bitrix_sessid()) { $profile = new CProfileAdmin(); $profile->SetSettings($IBLOCK_ID); $profile->SetSettings($SECTION_ID); $profile->SetSettings($GOOGLE_CATEGORY); $profile->SetSettings($CONDITION_RULE); $profile->SetSettings($XML_DATA); $arFields = array("NAME" => $NAME, "TYPE_RUN" => $TYPE_RUN, "FEED" => $FEED, "COMPANY" => $COMPANY, "SHOPNAME" => $SHOPNAME, "DESCRIPTION" => $DESCRIPTION, "DOMAIN_NAME" => $DOMAIN_NAME, "NAMESCHEMA" => $NAMESCHEMA, "ACTIVE" => $ACTIVE != "Y" ? "N" : "Y", "ENCODING" => $ENCODING, "IBLOCK_ID" => base64_encode(serialize($IBLOCK_ID)), "SECTION_ID" => base64_encode(serialize($SECTION_ID)), "GOOGLE_CATEGORY" => base64_encode(serialize($GOOGLE_CATEGORY)), "CONDITIONS" => $CONDITIONS, "LID" => $LID, "DETAIL_PAGE_URL" => $DETAIL_PAGE_URL, "USE_SKU" => $USE_SKU != "Y" ? "N" : "Y", "CHECK_INCLUDE" => $CHECK_INCLUDE != "Y" ? "N" : "Y", "FORORDER" => $FORORDER != "Y" ? "N" : "Y", "OTHER" => $OTHER != "Y" ? "N" : "Y", "CONDITION_RULE" => base64_encode(serialize($CONDITION_RULE)), "PRICE" => $PRICE, "XML_DATA" => base64_encode(serialize($XML_DATA)), "DATA_START" => strtotime($DATA_START), "PERIOD" => $PERIOD, "START_LAST_TIME" => $START_LAST_TIME, "USE_XML_FILE" => $USE_XML_FILE != "Y" ? "N" : "Y", "URL_DATA_FILE" => $URL_DATA_FILE, "AGELEVEL" => $AGELEVEL); if ($ID > 0) { $res = $profile->Update($ID, $arFields); } else { $ID = $profile->Add($arFields); $res = $ID > 0; } if ($res) { if ($apply != "") { LocalRedirect("/bitrix/admin/acrit_googlemerchant_edit.php?ID=" . $ID . "&mess=ok&lang=" . LANG . "&tabControl_active_tab=" . $_POST["tabControl_active_tab"]);
public function ReturnXMLData($ID) { $l = new CGM($ID); if (!is_object($l)) { ShowMessage(GetMessage("ACRIT_GOOGLEMERCHANT_NOT_PROFILE")); exit; } $MS = CGMExport::ReturnMas(); $arResult = $l->GetElement('gm', $MS); if (strlen($arResult) > 0) { if ($l->USE_XML_FILE) { if (strlen($l->URL_DATA_FILE) <= 0) { ShowMessage(GetMessage('ACRIT_GOOGLEMERCHANT_BAD_FILENAME')); exit; } else { $FILE_PATH = Rel2Abs("/", $l->URL_DATA_FILE); CheckDirPath($_SERVER["DOCUMENT_ROOT"] . $FILE_PATH); if (!($fp = @fopen($_SERVER["DOCUMENT_ROOT"] . $FILE_PATH, "wb"))) { ShowMessage(GetMessage('ACRIT_GOOGLEMERCHANT_BAD_OPENFILE')); exit; } else { $strXMLDATA = ''; $strXMLDATA .= '<?xml version="1.0" encoding="' . $l->ENCODING . '"?>' . PHP_EOL; $strXMLDATA .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">' . PHP_EOL; $strXMLDATA .= '<title>' . $l->FEED . '</title>' . PHP_EOL; $strXMLDATA .= '<link rel="self" href="http://' . $l->DOMAIN_NAME . '"/>' . PHP_EOL; $strXMLDATA .= '<updated>' . date('c') . '</updated>' . PHP_EOL; $strXMLDATA .= '<author><name>' . $l->SHOPNAME . '</name></author>' . PHP_EOL; $strXMLDATA .= $arResult; $strXMLDATA .= "</feed>" . PHP_EOL; fwrite($fp, $strXMLDATA); @fclose($fp); } } } elseif (!$l->USE_XML_FILE) { header("Content-Type: text/xml; charset='" . $l->ENCODING . "'"); header("Pragma: no-cache"); echo '<?xml version="1.0" encoding="' . $l->ENCODING . '"?>' . PHP_EOL; echo '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:g="http://base.google.com/ns/1.0">' . PHP_EOL; echo '<title>' . $l->FEED . '</title>' . PHP_EOL; echo '<link rel="self" href="http://' . $l->DOMAIN_NAME . '"/>' . PHP_EOL; echo '<updated>' . date('c') . '</updated> ' . PHP_EOL; echo '<author><name>' . $l->SHOPNAME . '</name></author>' . PHP_EOL; echo $arResult; echo "</feed>" . PHP_EOL; } } else { ShowError(GetMessage("ACRIT_GOOGLEMERCHANT_NOT_ELEMENT")); } if ($l->TYPE_RUN == 'agent') { return "CGM::ReturnXMLData(" . $ID . ");"; } global $DB; $now = time() + CTimeZone::GetOffset(); $data['START_LAST_TIME_X'] = date($DB->DateFormatToPHP(FORMAT_DATETIME), $now); CProfileAdmin::Update($ID, $data); unset($data); unset($arResult); }