1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
iblockrss.php
См. документацию.
1<?php
2
4{
5 public static function GetRSSNodes()
6 {
7 return array("title", "link", "description", "enclosure", "enclosure_length", "enclosure_type", "category", "pubDate");
8 }
9
10 public static function Delete($IBLOCK_ID)
11 {
12 global $DB;
13
14 $DB->Query("DELETE FROM b_iblock_rss WHERE IBLOCK_ID = ".(int)$IBLOCK_ID);
15 }
16
17 public static function GetNodeList($IBLOCK_ID)
18 {
19 global $DB;
20 $IBLOCK_ID = intval($IBLOCK_ID);
21 $arCurNodesRSS = array();
22 $db_res = $DB->Query(
23 "SELECT NODE, NODE_VALUE ".
24 "FROM b_iblock_rss ".
25 "WHERE IBLOCK_ID = ".$IBLOCK_ID);
26 while ($db_res_arr = $db_res->Fetch())
27 {
28 $arCurNodesRSS[$db_res_arr["NODE"]] = $db_res_arr["NODE_VALUE"];
29 }
30 return $arCurNodesRSS;
31 }
32
33 public static function GetNewsEx($SITE, $PORT, $PATH, $QUERY_STR, $bOutChannel = False)
34 {
35 $text = "";
36
37 $cacheKey = md5($SITE.$PORT.$PATH.$QUERY_STR);
38
39 $bValid = False;
40 $bUpdate = False;
41 if ($db_res_arr = CIBlockRSS::GetCache($cacheKey))
42 {
43 $bUpdate = True;
44 if ($db_res_arr["CACHE"] <> '')
45 {
46 if ($db_res_arr["VALID"]=="Y")
47 {
48 $bValid = True;
49 $text = $db_res_arr["CACHE"];
50 }
51 }
52 }
53
54 if (!$bValid)
55 {
56 $http = new \Bitrix\Main\Web\HttpClient(array(
57 "socketTimeout" => 120,
58 ));
59 $http->setHeader("User-Agent", "BitrixSMRSS");
60 $text = $http->get($SITE.":".$PORT.$PATH.($QUERY_STR <> ''? "?".$QUERY_STR: ""));
61
62 if ($text)
63 {
64 $rss_charset = "windows-1251";
65 if (preg_match("/<"."\?XML[^>]{1,}encoding=[\"']([^>\"']{1,})[\"'][^>]{0,}\?".">/i", $text, $matches))
66 {
67 $rss_charset = Trim($matches[1]);
68 }
69 else
70 {
71 $headers = $http->getHeaders();
72 $ct = $headers->get("Content-Type");
73 if (preg_match("#charset=([a-zA-Z0-9-]+)#m", $ct, $match))
74 $rss_charset = $match[1];
75 }
76
77 $text = preg_replace("/<!DOCTYPE.*?>/i", "", $text);
78 $text = preg_replace("/<"."\\?XML.*?\\?".">/i", "", $text);
80 }
81 }
82
83 if ($text != "")
84 {
85 $objXML = new CDataXML();
86 $res = $objXML->LoadString($text);
87 if($res !== false)
88 {
89 $ar = $objXML->GetArray();
90 if (!$bOutChannel)
91 {
92 if (
93 is_array($ar) && isset($ar["rss"])
94 && is_array($ar["rss"]) && isset($ar["rss"]["#"])
95 && is_array($ar["rss"]["#"]) && isset($ar["rss"]["#"]["channel"])
96 && is_array($ar["rss"]["#"]["channel"]) && isset($ar["rss"]["#"]["channel"][0])
97 && is_array($ar["rss"]["#"]["channel"][0]) && isset($ar["rss"]["#"]["channel"][0]["#"])
98 )
99 $arRes = $ar["rss"]["#"]["channel"][0]["#"];
100 else
101 $arRes = array();
102 }
103 else
104 {
105 if (
106 is_array($ar) && isset($ar["rss"])
107 && is_array($ar["rss"]) && isset($ar["rss"]["#"])
108 )
109 $arRes = $ar["rss"]["#"];
110 else
111 $arRes = array();
112 }
113
114 $arRes["rss_charset"] = mb_strtolower(SITE_CHARSET);
115
116 if (!$bValid)
117 {
118 $ttl = ($arRes["ttl"][0]["#"] <> '')? intval($arRes["ttl"][0]["#"]): 60;
119 CIBlockRSS::UpdateCache($cacheKey, $text, array("minutes" => $ttl), $bUpdate);
120 }
121 }
122 return $arRes;
123 }
124 else
125 {
126 return array();
127 }
128 }
129
130 public static function GetNews($ID, $LANG, $TYPE, $SITE, $PORT, $PATH, $LIMIT = 0)
131 {
132 if (intval($ID)>0)
133 {
134 $ID = intval($ID);
135 }
136 else
137 {
138 $ID = Trim($ID);
139 }
140 $LANG = Trim($LANG);
141 $TYPE = Trim($TYPE);
142 $LIMIT = intval($LIMIT);
143
144 return CIBlockRSS::GetNewsEx($SITE, $PORT, $PATH, "ID=".$ID."&LANG=".$LANG."&TYPE=".$TYPE."&LIMIT=".$LIMIT);
145 }
146
147 public static function FormatArray(&$arRes, $bOutChannel=false)
148 {
149 if (!$bOutChannel)
150 {
151 if(is_array($arRes["title"][0]["#"]))
152 $arRes["title"][0]["#"] = $arRes["title"][0]["#"]["cdata-section"][0]["#"];
153 if(is_array($arRes["link"][0]["#"]))
154 $arRes["link"][0]["#"] = $arRes["link"][0]["#"]["cdata-section"][0]["#"];
155 if(is_array($arRes["description"][0]["#"]))
156 $arRes["description"][0]["#"] = $arRes["description"][0]["#"]["cdata-section"][0]["#"];
157
159 "title" => $arRes["title"][0]["#"],
160 "link" => $arRes["link"][0]["#"],
161 "description" => $arRes["description"][0]["#"],
162 "lastBuildDate" => $arRes["lastBuildDate"][0]["#"],
163 "ttl" => $arRes["ttl"][0]["#"],
164 );
165
166 if ($arRes["image"])
167 {
168 if(is_array($arRes["image"][0]["#"]))
169 {
170 $arResult["image"]["title"] = $arRes["image"][0]["#"]["title"][0]["#"];
171 $arResult["image"]["url"] = $arRes["image"][0]["#"]["url"][0]["#"];
172 $arResult["image"]["link"] = $arRes["image"][0]["#"]["link"][0]["#"];
173 $arResult["image"]["width"] = $arRes["image"][0]["#"]["width"][0]["#"];
174 $arResult["image"]["height"] = $arRes["image"][0]["#"]["height"][0]["#"];
175 }
176 elseif(is_array($arRes["image"][0]["@"]))
177 {
178 $arResult["image"]["title"] = $arRes["image"][0]["@"]["title"];
179 $arResult["image"]["url"] = $arRes["image"][0]["@"]["url"];
180 $arResult["image"]["link"] = $arRes["image"][0]["@"]["link"];
181 $arResult["image"]["width"] = $arRes["image"][0]["@"]["width"];
182 $arResult["image"]["height"] = $arRes["image"][0]["@"]["height"];
183 }
184 }
185
186 if (!empty($arRes["item"]) && is_array($arRes["item"]))
187 {
188 foreach ($arRes["item"] as $i => $arItem)
189 {
190 if (!is_array($arItem) || !is_array($arItem["#"]))
191 continue;
192
193 if (is_array($arItem["#"]["title"][0]["#"]))
194 $arItem["#"]["title"][0]["#"] = $arItem["#"]["title"][0]["#"]["cdata-section"][0]["#"];
195
196 if (is_array($arItem["#"]["description"][0]["#"]))
197 $arItem["#"]["description"][0]["#"] = $arItem["#"]["description"][0]["#"]["cdata-section"][0]["#"];
198 elseif (is_array($arItem["#"]["encoded"][0]["#"]))
199 $arItem["#"]["description"][0]["#"] = $arItem["#"]["encoded"][0]["#"]["cdata-section"][0]["#"];
200 $arResult["item"][$i]["description"] = $arItem["#"]["description"][0]["#"];
201
202 if (is_array($arItem["#"]["title"][0]["#"]))
203 $arItem["#"]["title"][0]["#"] = $arItem["#"]["title"][0]["#"]["cdata-section"][0]["#"];
204 $arResult["item"][$i]["title"] = $arItem["#"]["title"][0]["#"];
205
206 if (is_array($arItem["#"]["link"][0]["#"]))
207 $arItem["#"]["link"][0]["#"] = $arItem["#"]["link"][0]["#"]["cdata-section"][0]["#"];
208 $arResult["item"][$i]["link"] = $arItem["#"]["link"][0]["#"];
209
210 if ($arItem["#"]["enclosure"])
211 {
212 $arResult["item"][$i]["enclosure"]["url"] = $arItem["#"]["enclosure"][0]["@"]["url"];
213 $arResult["item"][$i]["enclosure"]["length"] = $arItem["#"]["enclosure"][0]["@"]["length"];
214 $arResult["item"][$i]["enclosure"]["type"] = $arItem["#"]["enclosure"][0]["@"]["type"];
215 if ($arItem["#"]["enclosure"][0]["@"]["width"])
216 {
217 $arResult["item"][$i]["enclosure"]["width"] = $arItem["#"]["enclosure"][0]["@"]["width"];
218 }
219 if ($arItem["#"]["enclosure"][0]["@"]["height"])
220 {
221 $arResult["item"][$i]["enclosure"]["height"] = $arItem["#"]["enclosure"][0]["@"]["height"];
222 }
223 }
224 $arResult["item"][$i]["category"] = $arItem["#"]["category"][0]["#"];
225 $arResult["item"][$i]["pubDate"] = $arItem["#"]["pubDate"][0]["#"];
226
227 $arRes["item"][$i] = $arItem;
228 }
229 }
230 }
231 else
232 {
234 "title" => $arRes["channel"][0]["#"]["title"][0]["#"],
235 "link" => $arRes["channel"][0]["#"]["link"][0]["#"],
236 "description" => $arRes["channel"][0]["#"]["description"][0]["#"],
237 "lastBuildDate" => $arRes["channel"][0]["#"]["lastBuildDate"][0]["#"],
238 "ttl" => $arRes["channel"][0]["#"]["ttl"][0]["#"],
239 );
240
241 if ($arRes["image"])
242 {
243 $arResult["image"]["title"] = $arRes["image"][0]["#"]["title"][0]["#"];
244 $arResult["image"]["url"] = $arRes["image"][0]["#"]["url"][0]["#"];
245 $arResult["image"]["link"] = $arRes["image"][0]["#"]["link"][0]["#"];
246 $arResult["image"]["width"] = $arRes["image"][0]["#"]["width"][0]["#"];
247 $arResult["image"]["height"] = $arRes["image"][0]["#"]["height"][0]["#"];
248 }
249
250 if (!empty($arRes["item"]) && is_array($arRes["item"]))
251 {
252 foreach ($arRes["item"] as $i => $arItem)
253 {
254 if (!is_array($arItem) || !is_array($arItem["#"]))
255 continue;
256
257 if (is_array($arItem["#"]["title"][0]["#"]))
258 $arItem["#"]["title"][0]["#"] = $arItem["#"]["title"][0]["#"]["cdata-section"][0]["#"];
259
260 if (is_array($arItem["#"]["description"][0]["#"]))
261 $arItem["#"]["description"][0]["#"] = $arItem["#"]["description"][0]["#"]["cdata-section"][0]["#"];
262 elseif (is_array($arItem["#"]["encoded"][0]["#"]))
263 $arItem["#"]["description"][0]["#"] = $arItem["#"]["encoded"][0]["#"]["cdata-section"][0]["#"];
264 $arResult["item"][$i]["description"] = $arItem["#"]["description"][0]["#"];
265
266 $arResult["item"][$i]["title"] = $arItem["#"]["title"][0]["#"];
267 $arResult["item"][$i]["link"] = $arItem["#"]["link"][0]["#"];
268 if ($arItem["#"]["enclosure"])
269 {
270 $arResult["item"][$i]["enclosure"]["url"] = $arItem["#"]["enclosure"][0]["@"]["url"];
271 $arResult["item"][$i]["enclosure"]["length"] = $arItem["#"]["enclosure"][0]["@"]["length"];
272 $arResult["item"][$i]["enclosure"]["type"] = $arItem["#"]["enclosure"][0]["@"]["type"];
273 if ($arItem["#"]["enclosure"][0]["@"]["width"])
274 {
275 $arResult["item"][$i]["enclosure"]["width"] = $arItem["#"]["enclosure"][0]["@"]["width"];
276 }
277 if ($arItem["#"]["enclosure"][0]["@"]["height"])
278 {
279 $arResult["item"][$i]["enclosure"]["height"] = $arItem["#"]["enclosure"][0]["@"]["height"];
280 }
281 }
282 $arResult["item"][$i]["category"] = $arItem["#"]["category"][0]["#"];
283 $arResult["item"][$i]["pubDate"] = $arItem["#"]["pubDate"][0]["#"];
284
285 $arRes["item"][$i] = $arItem;
286 }
287 }
288 }
289 return $arResult;
290 }
291
292 public static function XMLDate2Dec($date_XML, $dateFormat = "DD.MM.YYYY")
293 {
294 static $MonthChar2Num = Array("","jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
295
296 if(preg_match("/(\\d+)\\s+(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\\s+(\\d+)/i", $date_XML, $match))
297 $timestamp = mktime(0, 0, 0, array_search(mb_strtolower($match[2]), $MonthChar2Num), $match[1], $match[3]);
298 else
299 $timestamp = time();
300
301 return date(CDatabase::DateFormatToPHP($dateFormat), $timestamp);
302 }
303
304 public static function ExtractProperties($str, &$arProps, &$arItem)
305 {
306 reset($arProps);
307 foreach ($arProps as $key => $val)
308 $str = str_replace("#".$key."#", $val["VALUE"], $str);
309 reset($arItem);
310 foreach ($arItem as $key => $val)
311 $str = str_replace("#".$key."#", $val, $str);
312 return $str;
313 }
314
315 public static function GetRSS($ID, $LANG, $TYPE, $LIMIT_NUM = false, $LIMIT_DAY = false, $yandex = false)
316 {
317 echo "<"."?xml version=\"1.0\" encoding=\"".LANG_CHARSET."\"?".">\n";
318 echo "<rss version=\"2.0\"";
319 echo ">\n";
320
322 "=ID" => $TYPE,
323 ));
324 $arType = $dbr->Fetch();
325 if ($arType && ($arType["IN_RSS"] == "Y"))
326 {
327 $dbr = CIBlock::GetList(array(), array(
328 "type" => $TYPE,
329 "LID" => $LANG,
330 "ACTIVE" => "Y",
331 "ID" => $ID,
332 ));
333 $arIBlock = $dbr->Fetch();
334 if ($arIBlock && ($arIBlock["RSS_ACTIVE"] == "Y"))
335 {
336 echo CIBlockRSS::GetRSSText($arIBlock, $LIMIT_NUM, $LIMIT_DAY, $yandex);
337 }
338 }
339
340 echo "</rss>\n";
341 }
342}
$db_res
Определения options_user_settings.php:8
$arResult
Определения generate_coupon.php:16
static convertEncoding($data, $charsetFrom, $charsetTo)
Определения encoding.php:17
Определения iblockrss.php:4
static XMLDate2Dec($date_XML, $dateFormat="DD.MM.YYYY")
Определения iblockrss.php:292
static GetNodeList($IBLOCK_ID)
Определения iblockrss.php:17
static GetNewsEx($SITE, $PORT, $PATH, $QUERY_STR, $bOutChannel=False)
Определения iblockrss.php:33
static GetNews($ID, $LANG, $TYPE, $SITE, $PORT, $PATH, $LIMIT=0)
Определения iblockrss.php:130
static Delete($IBLOCK_ID)
Определения iblockrss.php:10
static GetRSS($ID, $LANG, $TYPE, $LIMIT_NUM=false, $LIMIT_DAY=false, $yandex=false)
Определения iblockrss.php:315
static GetRSSNodes()
Определения iblockrss.php:5
static FormatArray(&$arRes, $bOutChannel=false)
Определения iblockrss.php:147
static ExtractProperties($str, &$arProps, &$arItem)
Определения iblockrss.php:304
Определения xml.php:396
static GetRSSText($arIBLOCK, $LIMIT_NUM=false, $LIMIT_DAY=false, $yandex=false)
Определения iblockrss.php:55
static UpdateCache($cacheKey, $CACHE, $HOURS_CACHE, $bCACHED)
Определения iblockrss.php:27
static GetCache($cacheKey)
Определения iblockrss.php:5
static GetList($arOrder=array("SORT"=> "ASC"), $arFilter=array())
Определения iblocktype.php:53
$str
Определения commerceml2.php:63
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
if($ajaxMode) $ID
Определения get_user.php:27
global $DB
Определения cron_frame.php:29
$IBLOCK_ID
Определения csv_new_run.php:168
const SITE_CHARSET
Определения include.php:62
const LANG_CHARSET
Определения include.php:65
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
$ar
Определения options.php:199
if(empty($signedUserToken)) $key
Определения quickway.php:257
$text
Определения template_pdf.php:79
$LIMIT
Определения rss.php:28
$TYPE
Определения rss.php:27
$LANG
Определения rss.php:26
$i
Определения factura.php:643
$val
Определения options.php:1793
$matches
Определения index.php:22
$arRes
Определения options.php:104
$arIBlock['PROPERTY']
Определения yandex_detail.php:172