כיצד להגדיר עדכון RSS תקין ב-1C-Bitrix
מאמר זה מסביר כיצד להגדיר עדכון RSS עבור 1C-Bitrix: מהתאמות רכיבים ועד מטמון. בהתבסס על ניסיון של 7+ שנים, 70% מהעדכונים הביתיים נכשלים בבדיקת W3C עקב שגיאות טריוויאליות: סוג MIME שגוי, היעדר עטיפות CDATA, או פורמטי תאריך לא סטנדרטיים. הגדרנו למעלה מ-50 עדכונים—כל אחד עובר את הבדיקה. זמן דיבוג טיפוסי שנחסך: 4–8 שעות לפרויקט, המתורגם לחיסכון של $300–$800. עבור אתרים עם תעבורה גבוהה, מטמון מותאם יכול להפחית את עומס השרת פי 20–30, ולחסוך עד $500 לחודש.
ביטריקס מייצרת RSS באמצעות רכיב bitrix:rss.out, אך לעדכון ברירת המחדל יש בעיות: קידודים שגויים, היעדר CDATA, תאריכים לא חוקיים, וללא תמיכה ב-Atom. מדריך זה מפרט כיצד לחדד את הרכיב—מסוג MIME ועד מטמון. להגדרה מוכנה, צור קשר לקבלת ייעוץ.
שלב אחר שלב: כיצד לתקן את סוג ה-MIME ואת הכותרות
- בחלק העליון של דף ה-RSS, לפני קריאה ל-
Content-Type: text/html, הגדר את ה-Content-Type ואת X-Robots-Tag הנכונים:
<?php
define("NO_KEEP_STATISTIC", true);
define("NO_AGENT_CHECK", true);
header("Content-Type: application/rss+xml; charset=utf-8");
header("X-Robots-Tag: noindex");
require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php");
$APPLICATION->IncludeComponent("bitrix:rss.out", "", [...]);
- ודא שפרמטרי הרכיב מוגדרים כראוי (מזהה אינפובלוק, מיון, פילטר).
- בדוק את העדכון באמצעות
application/rss+xmlכדי לוודא את סוג ה-MIME. זה מבטל את הגורם העיקרי לאי-תקינות.
מדוע CDATA הוא חובה?
התבנית ברירת המחדל אינה עוטפת את header.php ב-CDATA. אגרגטורים אינם יכולים לנתח HTML בתוך XML, מה שמוביל לשגיאות ניתוח. הפתרון כולל התאמה אישית של התבנית. העתק את התבנית: <?php define("NO_KEEP_STATISTIC", true); define("NO_AGENT_CHECK", true); header("Content-Type: application/rss+xml; charset=utf-8"); header("X-Robots-Tag: noindex"); require($_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"); $APPLICATION->IncludeComponent("bitrix:rss.out", "", [...]); . ב-X-Robots-Tag: noindex, עטף את התיאור ב-CDATA:
// Было: <?= $arItem["DETAIL_TEXT"] ?>
// Стало: <![CDATA[<?= strip_tags($arItem["DETAIL_TEXT"]) ?>]]>
// Или с сохранением HTML (для агрегаторов, поддерживающих content:encoded):
<content:encoded><![CDATA[<?= $arItem["DETAIL_TEXT"] ?>]]></content:encoded>הוסף את מרחב השמות של התוכן ב-DETAIL_TEXT:
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
"}
Wait, the input is just a single line with an opening tag. It's already properly formatted. But the instruction says to restore proper newlines. Since it's XML, typically the root element is on its own line. The input has no content after the tag, so adding a newline after the tag is appropriate. However, the original might have had more content but it's not shown. The instruction says "restore proper newlines inside a single code block that was flattened to one line". The given code is just that one line. Possibly the original had multiple lines but the flattening removed them. But we only have that line. To be safe, we can add a newline after the opening tag, but since there is no closing tag, it's incomplete. But we must not add or remove tokens. So we just add a newline at the end? Actually, the flattened code is exactly that string. If we add a newline, it becomes two lines? No, it's just one line with a newline at the end. That is typical. But the instruction says "restore proper newlines inside a single code block". Since there is no content, maybe the original had the opening tag on its own line, then content, then closing tag. But we don't have that. So we can only add a newline after the opening tag? But that would change the structure if there is content after. Actually, the flattened code is exactly that string. It might be that the original had the opening tag on one line, then some content, then closing tag, but the flattening removed all newlines, so the entire document is one line. But we only have the beginning. The user gave only that snippet. So we should just output the same string with a newline at the end? But that doesn't restore anything. Perhaps the original had the opening tag on its own line, and then the rest of the document on subsequent lines. But we don't have the rest. So the best we can do is to put the opening tag on its own line, and then maybe add a newline after it to indicate that the content would follow. But we cannot add content. So I'll just output the same string with a newline at the end. But the instruction says "Return ONLY the reformatted plain code text." So I'll output the string with a newline. However, the JSON must have the code with real newlines. So I'll put a newline after the tag. But that might be considered adding a newline character, which is allowed. So I'll do that.
But wait, the input has a trailing space after the ">"? Actually the input is: `<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom"> ` with a space at the end. So I'll preserve that space and add a newline after it? Actually, the space is part of the code. I should not remove it. So I'll output exactly that string with a newline at the end. But the newline is not part of the original, but we are allowed to add newlines. So I'll do that.
But perhaps the original had the opening tag on its own line, and then the rest of the document. Since we don't have the rest, we can only put the opening tag on its own line. So I'll output that line with a newline after it. That is the reformatted code.
Thus the JSON: {"code": "<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
"}
But note the space before the newline. I'll keep it.
Alternatively, if the original had no space, but the input has a space, I'll keep it.
So final answer.<ï½endâofâthinkingï½>{"code": "<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom">
מהם מרחבי שמות ולמה הם נחוצים?
מרחבי שמות מרחיבים את RSS 2.0 עם אלמנטים נוספים. ללא cp -r /bitrix/components/bitrix/rss.out/templates/.default/ /local/components/bitrix/rss.out/templates/.default/ נכון, האלמנט template.php מתעלם. מרחבי שמות מרכזיים:
| מרחב שמות | URI | מטרה |
|---|---|---|
| content | http://purl.org/rss/1.0/modules/content/ | תוכן HTML ב-CDATA |
| media | http://search.yahoo.com/mrss/ | תמונות ומדיה |
| atom | http://www.w3.org/2005/Atom | קישור Atom להפניה עצמית |
כיצד להוסיף תמונות ל-RSS?
עבור אגרגטורים שמציגים תצוגות מקדימות, הוסף // Было: <?= $arItem["DETAIL_TEXT"] ?> // Стало: <![CDATA[<?= strip_tags($arItem["DETAIL_TEXT"]) ?>]]> // Или с сохранением HTML (для агрегаторов, поддерживающих content:encoded): <content:encoded><![CDATA[<?= $arItem["DETAIL_TEXT"] ?>]]></content:encoded> :
<?php if ($arItem["PREVIEW_PICTURE"]): ?>
<?php $pic = CFile::GetFileArray($arItem["PREVIEW_PICTURE"]); ?>
<media:content url="<?= SITE_SERVER_NAME . $pic["SRC"] ?>" medium="image" type="<?= $pic["CONTENT_TYPE"] ?>" />
<?php endif; ?>לפי הבדיקות שלנו, הוספת media:content מגדילה את המעורבות בעדכון ב-35%.
כיצד להגדיר מטמון ולהפחית את עומס מסד הנתונים
כל בקשה ללא מטמון גורמת לשאילתת <channel>. השתמש במטמון מנוהל:
"CACHE_TYPE" => "A", // автоматический кеш
"CACHE_TIME" => "3600", // 1 час
בנוסף, אפשר מטמון פרוקסי של Nginx: <rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom"> . ללא מטמון, RSS נוצר ב-200–300 אלפיות השנייה; עם מטמון, מתחת ל-10 אלפיות השנייה—שיפור של פי 20–30. זה מאפשר לשרת עד 1000 בקשות בשנייה.טיפים נוספים למטמון
לפרויקטים עם עומס גבוה, שקול מטמון פרגמנטרי או שימוש ב-CDN כדי לשמור את העדכון במטמון.
בדיקת עדכון ושגיאות טיפוסיות
בדוק עם W3C RSS Validator או באמצעות curl + xmllint. שגיאות ניתוח XML נפוצות: תגיות לא סגורות ב-xmlns:media, תווים אסורים (ASCII 0x00–0x1F מלבד tab/LF/CR), היעדר media:content. השתמש ב-content:encoded עבור תאריכים בפורמט RFC 2822. פתרונות:
- סוג MIME text/html → הגדר
media:content. - HTML ללא CDATA → עטף את DETAIL_TEXT ב-CDATA.
- תאריכים בפורמט שגוי → השתמש ב-
<?php if ($arItem["PREVIEW_PICTURE"]): ?> <?php $pic = CFile::GetFileArray($arItem["PREVIEW_PICTURE"]); ?> <media:content url="<?= SITE_SERVER_NAME . $pic["SRC"] ?>" medium="image" type="<?= $pic["CONTENT_TYPE"] ?>" /> <?php endif; ?>. - אין lastBuildDate → הוסף
GetListבתוך"CACHE_TYPE" => "A", // автоматический кеш "CACHE_TIME" => "3600", // 1 час. - תמונות חסרות → הכנס media:content עם מרחב שמות נכון.
מה כלול בהגדרת עדכון ה-RSS שלנו
אנו מגדירים עדכוני RSS במפתח מלא: ניתוח, שינוי תבנית, תיקון סוג MIME, CDATA ו-media:content, בדיקת W3C, הגדרת מטמון ותיעוד. ניסיון: למעלה מ-50 פרויקטים של ביטריקס במשך 7 שנים. אנו מבטיחים עדכון תקין בכל האגרגטורים. עלות פרויקט טיפוסית מתחילה מ-$100 להגדרה בסיסית; אפשרויות מטמון מתקדמות זמינות.
קבל ייעוץ על הגדרת RSS—צור קשר כדי להעריך את הפרויקט שלך. הצוות שלנו מוכן להגדיר את העדכון.

