1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
yandex.php
См. документацию.
1<?php
2
6
8set_time_limit(0);
9
10global $USER;
13{
14 $bTmpUserCreated = true;
15 if (isset($USER))
16 $USER_TMP = $USER;
17 $USER = new CUser();
18}
19
22if ($USER->IsAuthorized())
23{
25}
26
27if (!function_exists("yandex_replace_special"))
28{
29 function yandex_replace_special($arg)
30 {
31 if (in_array($arg[0], array("&quot;", "&amp;", "&lt;", "&gt;")))
32 return $arg[0];
33 else
34 return " ";
35 }
36}
37
38if (!function_exists("yandex_text2xml"))
39{
40 function yandex_text2xml($text, $bHSC = false, $bDblQuote = false)
41 {
42 $bHSC = (true == $bHSC ? true : false);
43 $bDblQuote = (true == $bDblQuote ? true: false);
44
45 if ($bHSC)
46 {
48 if ($bDblQuote)
49 $text = str_replace('&quot;', '"', $text);
50 }
51 $text = preg_replace('/[\x01-\x08\x0B-\x0C\x0E-\x1F]/', "", $text);
52 $text = str_replace("'", "&apos;", $text);
53 $text = Encoding::convertEncoding($text, LANG_CHARSET, 'windows-1251');
54 return $text;
55 }
56}
57
58$usedProtocol = (Main\Context::getCurrent()->getRequest()->isHttps() ? 'https://' : 'http://');
59
60$strAll = '<?php' . "\n";
61$strAll .= 'if (!isset($_GET["referer1"]) || $_GET["referer1"] == "") $_GET["referer1"] = "yandext";' . "\n";
62$strAll .= '$strReferer1 = htmlspecialchars($_GET["referer1"]);' . "\n";
63$strAll .= 'if (!isset($_GET["referer2"]) || $_GET["referer2"] == "") $_GET["referer2"] = "";' . "\n";
64$strAll .= '$strReferer2 = htmlspecialchars($_GET["referer2"]);' . "\n";
65$strAll .= 'header("Content-Type: text/xml; charset=windows-1251");' . "\n";
66$strAll .= '?>' . "\n";
67$strAll .= '<?xml version="1.0" encoding="windows-1251"?>' . "\n";
68$strAll .= "<!DOCTYPE yml_catalog SYSTEM \"shops.dtd\">\n";
69$strAll .= "<yml_catalog date=\"".date("Y-m-d H:i")."\">\n";
70$strAll .= "<shop>\n";
71$strAll .= "<name>".Encoding::convertEncoding(htmlspecialcharsbx(COption::GetOptionString("main", "site_name", "")), LANG_CHARSET, 'windows-1251')."</name>\n";
72$strAll .= "<company>".Encoding::convertEncoding(htmlspecialcharsbx(COption::GetOptionString("main", "site_name", "")), LANG_CHARSET, 'windows-1251')."</company>\n";
73$strAll .= "<url>".$usedProtocol.htmlspecialcharsbx(COption::GetOptionString("main", "server_name", ""))."</url>\n";
74$strAll .= "<platform>1C-Bitrix</platform>\n";
75
76//*****************************************//
77
78$BASE_CURRENCY = Currency\CurrencyManager::getBaseCurrency();
79$RUR = 'RUB';
80$currencyIterator = Currency\CurrencyTable::getList(array(
81 'select' => array('CURRENCY'),
82 'filter' => array('=CURRENCY' => 'RUR')
83));
84if ($currency = $currencyIterator->fetch())
85 $RUR = 'RUR';
86unset($currency, $currencyIterator);
87$arCurrencyAllowed = array('RUR', 'RUB', 'USD', 'EUR', 'UAH', 'BYR', 'BYN', 'KZT');
88$strTmp = "<currencies>\n";
89$currencyIterator = Currency\CurrencyTable::getList(array(
90 'select' => array('CURRENCY', 'SORT'),
91 'filter' => array('@CURRENCY' => $arCurrencyAllowed),
92 'order' => array('SORT' => 'ASC')
93));
94while ($currency = $currencyIterator->fetch())
95 $strTmp.= '<currency id="'.$currency['CURRENCY'].'" rate="'.(CCurrencyRates::ConvertCurrency(1, $currency['CURRENCY'], $RUR)).'" />'."\n";
96unset($currency, $currencyIterator);
97$strTmp.= "</currencies>\n";
98
99$strAll.= $strTmp;
100unset($strTmp);
101
102//*****************************************//
103
104$arSelect = array(
105 "ID", "LID", "IBLOCK_ID", "IBLOCK_SECTION_ID", "ACTIVE", "NAME",
106 "PREVIEW_PICTURE", "PREVIEW_TEXT", "PREVIEW_TEXT_TYPE",
107 "DETAIL_PICTURE", "LANG_DIR", "DETAIL_PAGE_URL",
108 "CATALOG_AVAILABLE"
109);
110
111$strTmpCat = "";
112$strTmpOff = "";
113
114$arSiteServers = array();
115
116$db_catalog_list = CCatalog::GetList(array(), array("YANDEX_EXPORT" => "Y", "PRODUCT_IBLOCK_ID" => 0), false, false, array('IBLOCK_ID'));
117while ($arCatalog_list = $db_catalog_list->Fetch())
118{
119 $arCatalog_list['IBLOCK_ID'] = intval($arCatalog_list['IBLOCK_ID']);
120 $arIBlock = CIBlock::GetArrayByID($arCatalog_list['IBLOCK_ID']);
121 if (empty($arIBlock) || !is_array($arIBlock))
122 continue;
123 if ('Y' != $arIBlock['ACTIVE'])
124 continue;
125 $boolRights = false;
126 if ('E' != $arIBlock['RIGHTS_MODE'])
127 {
128 $arRights = CIBlock::GetGroupPermissions($arCatalog_list['IBLOCK_ID']);
129 if (!empty($arRights) && isset($arRights[2]) && 'R' <= $arRights[2])
130 $boolRights = true;
131 }
132 else
133 {
134 $obRights = new CIBlockRights($arCatalog_list['IBLOCK_ID']);
135 $arRights = $obRights->GetGroups(array('section_read', 'element_read'));
136 if (!empty($arRights) && in_array('G2',$arRights))
137 $boolRights = true;
138 }
139 if (!$boolRights)
140 continue;
141
142 $filter = array("IBLOCK_ID"=>$arCatalog_list["IBLOCK_ID"], "ACTIVE"=>"Y", "GLOBAL_ACTIVE"=>"Y");
143 $db_acc = CIBlockSection::GetList(array("left_margin"=>"asc"), $filter);
144
145 $arAvailGroups = array();
146 while ($arAcc = $db_acc->Fetch())
147 {
148 $strTmpCat.= "<category id=\"".$arAcc["ID"]."\"".(intval($arAcc["IBLOCK_SECTION_ID"])>0?" parentId=\"".$arAcc["IBLOCK_SECTION_ID"]."\"":"").">".yandex_text2xml($arAcc["NAME"], true)."</category>\n";
149 $arAvailGroups[] = intval($arAcc["ID"]);
150 }
151
152 //*****************************************//
153
154 $filter = array("IBLOCK_ID"=>$arCatalog_list["IBLOCK_ID"], "ACTIVE"=>"Y", "ACTIVE_DATE"=>"Y");
155 $db_acc = CIBlockElement::GetList(array(), $filter, false, false, $arSelect);
156
157 $total_sum=0;
158 $is_exists=false;
159 $cnt=0;
160
161 while ($arAcc = $db_acc->GetNext())
162 {
163 $cnt++;
164 if (!array_key_exists($arAcc['LID'], $arSiteServers))
165 {
166 $rsSite = CSite::GetList('', '', array("LID" => $arAcc["LID"]));
167 if($arSite = $rsSite->Fetch())
168 $arAcc["SERVER_NAME"] = $arSite["SERVER_NAME"];
169 if($arAcc["SERVER_NAME"] == '' && defined("SITE_SERVER_NAME"))
170 $arAcc["SERVER_NAME"] = SITE_SERVER_NAME;
171 if($arAcc["SERVER_NAME"] == '')
172 $arAcc["SERVER_NAME"] = COption::GetOptionString("main", "server_name", "");
173
174 $arSiteServers[$arAcc['LID']] = $arAcc['SERVER_NAME'];
175 }
176 else
177 {
178 $arAcc['SERVER_NAME'] = $arSiteServers[$arAcc['LID']];
179 }
180 $str_AVAILABLE = ' available="'.($arAcc['CATALOG_AVAILABLE'] == 'Y' ? 'true' : 'false').'"';
181
182 $minPrice = 0;
183 $minPriceRUR = 0;
184 $minPriceGroup = 0;
185 $minPriceCurrency = "";
186
188 $arAcc['ID'],
189 1,
190 array(2), // anonymous
191 'N',
192 array(),
193 $arIBlock['LID'],
194 array()
195 ))
196 {
197 $minPrice = $arPrice['DISCOUNT_PRICE'];
198 $minPriceCurrency = $BASE_CURRENCY;
199 if ($BASE_CURRENCY != $RUR)
200 {
201 $minPriceRUR = CCurrencyRates::ConvertCurrency($minPrice, $BASE_CURRENCY, $RUR);
202 }
203 else
204 {
205 $minPriceRUR = $minPrice;
206 }
207 $minPriceGroup = $arPrice['PRICE']['CATALOG_GROUP_ID'];
208 }
209
210 if ($minPrice <= 0) continue;
211
212 $bNoActiveGroup = True;
213 $strTmpOff_tmp = "";
214 $db_res1 = CIBlockElement::GetElementGroups($arAcc["ID"], false, array('ID', 'ADDITIONAL_PROPERTY_ID'));
215 while ($ar_res1 = $db_res1->Fetch())
216 {
217 if (0 < intval($ar_res1['ADDITIONAL_PROPERTY_ID']))
218 continue;
219 $strTmpOff_tmp.= "<categoryId>".$ar_res1["ID"]."</categoryId>\n";
220 if ($bNoActiveGroup && in_array(intval($ar_res1["ID"]), $arAvailGroups))
221 {
222 $bNoActiveGroup = False;
223 }
224 }
225 if ($bNoActiveGroup) continue;
226
227 if ('' == $arAcc['DETAIL_PAGE_URL'])
228 {
229 $arAcc['DETAIL_PAGE_URL'] = '/';
230 }
231 else
232 {
233 $arAcc['DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arAcc['DETAIL_PAGE_URL']);
234 }
235 if ('' == $arAcc['~DETAIL_PAGE_URL'])
236 {
237 $arAcc['~DETAIL_PAGE_URL'] = '/';
238 }
239 else
240 {
241 $arAcc['~DETAIL_PAGE_URL'] = str_replace(' ', '%20', $arAcc['~DETAIL_PAGE_URL']);
242 }
243
244 $strTmpOff.= "<offer id=\"".$arAcc["ID"]."\"".$str_AVAILABLE.">\n";
245 $strTmpOff.= "<url>".$usedProtocol.$arAcc['SERVER_NAME'].htmlspecialcharsbx($arAcc["~DETAIL_PAGE_URL"]).(mb_strstr($arAcc['DETAIL_PAGE_URL'], '?') === false ? '?' : '&amp;')."r1=<?echo \$strReferer1; ?>&amp;r2=<?echo \$strReferer2; ?></url>\n";
246
247 $strTmpOff.= "<price>".$minPrice."</price>\n";
248 $strTmpOff.= "<currencyId>".$minPriceCurrency."</currencyId>\n";
249
250 $strTmpOff.= $strTmpOff_tmp;
251
252 if (intval($arAcc["DETAIL_PICTURE"])>0 || intval($arAcc["PREVIEW_PICTURE"])>0)
253 {
254 $pictNo = intval($arAcc["DETAIL_PICTURE"]);
255 if ($pictNo<=0) $pictNo = intval($arAcc["PREVIEW_PICTURE"]);
256
257 $arPictInfo = CFile::GetFileArray($pictNo);
258 if (is_array($arPictInfo))
259 {
260 if(mb_substr($arPictInfo["SRC"], 0, 1) == "/")
261 $strFile = $usedProtocol.$arAcc['SERVER_NAME'].CHTTP::urnEncode($arPictInfo["SRC"], 'utf-8');
262 else
263 $strFile = $arPictInfo["SRC"];
264 $strTmpOff.="<picture>".$strFile."</picture>\n";
265 }
266 }
267
268 $strTmpOff.= "<name>".yandex_text2xml($arAcc["~NAME"], true)."</name>\n";
269 $strTmpOff.=
270 "<description>".
272 ($arAcc["PREVIEW_TEXT_TYPE"]=="html"?
273 strip_tags(preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arAcc["~PREVIEW_TEXT"])) : preg_replace_callback("'&[^;]*;'", "yandex_replace_special", $arAcc["~PREVIEW_TEXT"])),
274 3000), true).
275 "</description>\n";
276 $strTmpOff.= "</offer>\n";
277 if (100 <= $cnt)
278 {
279 $cnt = 0;
281 'PRODUCT' => true,
282 'SECTIONS' => true,
283 'PROPERTIES' => true
284 ));
285 }
286 }
287}
288
289$strAll.= "<categories>\n";
290$strAll.= $strTmpCat;
291$strAll.= "</categories>\n";
292
293$strAll.= "<offers>\n";
294$strAll.= $strTmpOff;
295$strAll.= "</offers>\n";
296
297$strAll.= "</shop>\n";
298$strAll.= "</yml_catalog>\n";
299
300$boolError = true;
301$strExportPath = COption::GetOptionString("catalog", "export_default_path", CATALOG_DEFAULT_EXPORT_PATH);
302$strYandexPath = Rel2Abs('/',str_replace('//','/',$strExportPath."/yandex.php"));
303if (!empty($strYandexPath))
304{
305 CheckDirPath($_SERVER["DOCUMENT_ROOT"].$strExportPath);
306
307 if ($fp = @fopen($_SERVER["DOCUMENT_ROOT"].$strYandexPath, 'wb'))
308 {
309 fwrite($fp, $strAll);
310 fclose($fp);
311 $boolError = false;
312 }
313}
314
315if ($boolError)
316{
317 CEventLog::Log('WARNING','CAT_YAND_AGENT','catalog','YandexAgent',$strYandexPath);
318}
319
321
323{
324 if (isset($USER_TMP))
325 {
326 $USER = $USER_TMP;
327 unset($USER_TMP);
328 }
329}
global $APPLICATION
Определения include.php:80
const CATALOG_DEFAULT_EXPORT_PATH
Определения include.php:14
if($USER->IsAuthorized()) if(!function_exists("yandex_replace_special")) if(!function_exists("yandex_text2xml")) $usedProtocol
Определения yandex.php:58
$strAll
Определения yandex.php:60
static ClearCoupon()
Определения discount_coupon.php:283
static ClearCouponsByManage($intUserID)
Определения discount_coupon.php:456
static ClearDiscountCache($arTypes)
Определения discount.php:4224
static Disable()
Определения discount_save.php:38
static Enable()
Определения discount_save.php:33
static IsUserExists()
Определения catalog.php:1812
static GetOptimalPrice($intProductID, $quantity=1, $arUserGroups=array(), $renewal="N", $priceList=array(), $siteID=false, $arDiscountCoupons=false)
Определения product.php:973
static ConvertCurrency($valSum, $curFrom, $curTo, $valDate="")
Определения currency_rate.php:393
static GetElementGroups($ID, $bElementOnly=false, $arSelect=array())
Определения iblockelement.php:5618
static GetOptionString($module_id, $name, $def="", $site=false, $bExactSite=false)
Определения option.php:8
static GetList($by="sort", $order="asc", $arFilter=[])
Определения site.php:605
static GetList($arOrder=array(), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения catalog.php:15
static Log($SEVERITY, $AUDIT_TYPE_ID, $MODULE_ID, $ITEM_ID, $DESCRIPTION=false, $SITE_ID=false)
Определения event_log.php:32
static GetFileArray($fileId, $uploadDir=false)
Определения file.php:1207
static GetList($arOrder=array("SORT"=>"ASC"), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения iblockelement.php:658
static GetList($arOrder=array("SORT"=>"ASC"), $arFilter=array(), $bIncCnt=false, $arSelect=array(), $arNavStartParams=false)
Определения iblocksection.php:14
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$filter
Определения iblock_catalog_list.php:54
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
if(! $ar_profile) $strFile
Определения cron_frame.php:59
global $USER
Определения csv_new_run.php:40
$bTmpUserCreated
Определения csv_new_run.php:41
const LANG_CHARSET
Определения include.php:65
CheckDirPath($path)
Определения tools.php:2707
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
Rel2Abs($curdir, $relpath)
Определения tools.php:3297
TruncateText($strText, $intLen)
Определения tools.php:2185
$text
Определения template_pdf.php:79
$total_sum
Определения factura.php:657
$currency
Определения template.php:266
$arIBlock['PROPERTY']
Определения yandex_detail.php:172
$BASE_CURRENCY
Определения yandex_run.php:987
yandex_text2xml($text, $bHSC=false, $bDblQuote=false)
Определения yandex_simple_run.php:40
if( $USER->IsAuthorized()) yandex_replace_special($arg)
Определения yandex_simple_run.php:32