30 'ID' => intval(
$NS[
'ID']),
31 'CNT' => intval(
$NS[
'CNT']),
32 'FILE_SIZE' => intval(
$NS[
'FILE_SIZE']),
33 'FILE_ID' => intval(
$NS[
'FILE_ID']),
34 'FILE_URL_CNT' => intval(
$NS[
'FILE_URL_CNT']),
35 'ERROR_CNT' => intval(
$NS[
'ERROR_CNT']),
36 'PARAM2' => intval(
$NS[
'ID']),
56 $end_of_execution = 0;
61 $bForumTopicsOnly = CModule::IncludeModule(
'forum');
65 $bForumTopicsOnly =
false;
70 $bBlogNoComments = CModule::IncludeModule(
'blog');
74 $bBlogNoComments =
false;
79 $strProto =
'https://';
83 $strProto =
'http://';
87 if ($arSite = $rsSite->Fetch())
89 $SERVER_NAME = trim($arSite[
'SERVER_NAME']);
90 if ($SERVER_NAME ==
'')
92 $this->m_error =
GetMessage(
'SEARCH_ERROR_SERVER_NAME', [
'#SITE_ID#' =>
'<a href="site_edit.php?LID=' . urlencode(
$site_id) .
'&lang=' . urlencode(LANGUAGE_ID) .
'">' .
htmlspecialcharsbx(
$site_id) .
'</a>']) .
'<br>';
99 if (
$NS[
'ID'] == 0 &&
$NS[
'CNT'] == 0)
101 $e = fopen($arSite[
'ABS_DOC_ROOT'] . $arSite[
'DIR'] .
'sitemap_errors.xml',
'w');
102 $strBegin =
"<?xml version='1.0' encoding='UTF-8'?>\n<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
103 fwrite($e, $strBegin);
108 $e = fopen($arSite[
'ABS_DOC_ROOT'] . $arSite[
'DIR'] .
'sitemap_errors.xml',
'a');
112 $this->m_error =
GetMessage(
'SEARCH_ERROR_OPEN_FILE') .
' ' . $arSite[
'ABS_DOC_ROOT'] . $arSite[
'DIR'] .
'sitemap_errors.xml' .
'<br>';
116 if (
$NS[
'FILE_SIZE'] == 0)
118 $f = fopen($arSite[
'ABS_DOC_ROOT'] . $arSite[
'DIR'] .
'sitemap_' . sprintf(
'%03d',
$NS[
'FILE_ID']) .
'.xml',
'w');
119 $strBegin =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<urlset xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
120 fwrite(
$f, $strBegin);
121 $NS[
'FILE_SIZE'] += mb_strlen($strBegin);
125 $f = fopen($arSite[
'ABS_DOC_ROOT'] . $arSite[
'DIR'] .
'sitemap_' . sprintf(
'%03d',
$NS[
'FILE_ID']) .
'.xml',
'a');
129 $this->m_error =
GetMessage(
'SEARCH_ERROR_OPEN_FILE') .
' ' . $arSite[
'ABS_DOC_ROOT'] . $arSite[
'DIR'] .
'sitemap_' . sprintf(
'%03d',
$NS[
'FILE_ID']) .
'.xml' .
'<br>';
133 CTimeZone::Disable();
135 $bFileIsFull =
false;
136 while (!$bFileIsFull &&
$ar = $this->
Fetch())
140 if (mb_strlen(
$ar[
'URL']) < 1)
145 if ($bForumTopicsOnly && (
$ar[
'MODULE_ID'] ==
'forum'))
148 $PARAM2 = intval(
$ar[
'PARAM2']);
149 if (
$NS[
'PARAM2'] < $PARAM2)
151 $NS[
'PARAM2'] = $PARAM2;
155 $ar[
'FULL_DATE_CHANGE'] = $arTopic[
'LAST_POST_DATE'];
164 if ($bBlogNoComments && (
$ar[
'MODULE_ID'] ==
'blog'))
166 if (mb_substr(
$ar[
'ITEM_ID'], 0, 1) ===
'C')
172 if (preg_match(
'/^[a-z]+:\\/\\//',
$ar[
'URL']))
174 $strURL =
$ar[
'URL'];
178 $strURL = $strProto .
$ar[
'SERVER_NAME'] .
$ar[
'URL'];
184 $strToWrite =
"\t<url>\n\t\t<loc>" . $strURL .
"</loc>\n\t\t<lastmod>" . $strTime .
"</lastmod>\n\t</url>\n";
186 if (mb_strlen($strURL) > 2048)
188 fwrite($e, $strToWrite);
194 $NS[
'FILE_SIZE'] += fwrite(
$f, $strToWrite);
195 $NS[
'FILE_URL_CNT']++;
198 if (
$NS[
'FILE_SIZE'] > 9000000 ||
$NS[
'FILE_URL_CNT'] >= 50000)
202 elseif ($end_of_execution)
204 if (time() > $end_of_execution)
218 fwrite($e,
"</urlset>\n");
220 fwrite(
$f,
"</urlset>\n");
223 $NS[
'FILE_SIZE'] = 0;
224 $NS[
'FILE_URL_CNT'] = 0;
228 elseif ($record_limit <= 0)
234 fwrite($e,
"</urlset>\n");
236 fwrite(
$f,
"</urlset>\n");
240 $f = fopen($arSite[
'ABS_DOC_ROOT'] . $arSite[
'DIR'] .
'sitemap_index.xml',
'w');
243 $this->m_error =
GetMessage(
'SEARCH_ERROR_OPEN_FILE') .
' ' . $arSite[
'ABS_DOC_ROOT'] . $arSite[
'DIR'] .
'sitemap_index.xml' .
'<br>';
246 $strBegin =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<sitemapindex xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.sitemaps.org/schemas/sitemap/0.9\" xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
247 fwrite(
$f, $strBegin);
250 $strFile = $arSite[
'DIR'] .
'sitemap_' . sprintf(
'%03d',
$i) .
'.xml';
252 fwrite(
$f,
"\t<sitemap>\n\t\t<loc>" . $this->
URLEncode($strProto . $arSite[
'SERVER_NAME'] .
$strFile,
'UTF-8') .
"</loc>\n\t\t<lastmod>" . $strTime .
"</lastmod>\n\t</sitemap>\n");
254 fwrite(
$f,
"</sitemapindex>\n");
256 $this->m_errors_count =
$NS[
'ERROR_CNT'];
257 $this->m_errors_href = $strProto . $arSite[
'SERVER_NAME'] . $arSite[
'DIR'] .
'sitemap_errors.xml';
258 $this->m_href = $strProto . $arSite[
'SERVER_NAME'] . $arSite[
'DIR'] .
'sitemap_index.xml';
263 $this->m_error =
GetMessage(
'SEARCH_ERROR_SITE_ID') .
'<br>';
270 static $index =
false;
272 $r = parent::Fetch();
275 if ($r[
'SITE_URL'] <>
'')
277 $r[
'URL'] = $r[
'SITE_URL'];
280 if (mb_substr($r[
'URL'], 0, 1) ==
'=')
282 foreach ($this->m_events as $arEvent)
291 $r[
'URL'] = str_replace(
292 [
'#LANG#',
'#SITE_DIR#',
'#SERVER_NAME#'],
293 [$r[
'DIR'], $r[
'DIR'], $r[
'SERVER_NAME']],
296 $r[
'URL'] = preg_replace(
"'(?<!:)/+'s",
'/', $r[
'URL']);
297 if (defined(
'BX_DISABLE_INDEX_PAGE') && BX_DISABLE_INDEX_PAGE)
301 $index =
'#/(' . str_replace(
' ',
'|', preg_quote(implode(
' ',
GetDirIndexArray()),
'#')) .
')$#';
303 $r[
'URL'] = preg_replace($index,
'/', $r[
'URL']);
307 $p = mb_strpos($r[
'URL'],
'#');
310 $r[
'URL'] = mb_substr($r[
'URL'], 0,
$p);
319 $arUrlComponents = preg_split(
'#(://|/|\\?|=|&)#',
$str, -1, PREG_SPLIT_DELIM_CAPTURE);
320 foreach ($arUrlComponents as
$i => $part_of_url)
324 $strEncodedURL .= $part_of_url;
328 if (
$i > 1 && $arUrlComponents[
$i - 1] ===
'://')
331 $strEncodedURL .= $converter->Encode($part_of_url);
335 $strEncodedURL .= urlencode(\
Bitrix\Main\Text\Encoding::convertEncoding(urldecode($part_of_url),
LANG_CHARSET, $charset));
339 return $strEncodedURL;
344 static $search = [
'&',
"'",
'"',
'>',
'<'];
345 static $replace = [
'&',
''',
'"',
'>',
'<'];
346 return str_replace($search, $replace,
$str);
351 $iTZ = date(
'Z', $iTime);
352 $iTZHour = intval(abs($iTZ) / 3600);
353 $iTZMinutes = intval((abs($iTZ) - $iTZHour * 3600) / 60);
354 $strTZ = ($iTZ < 0 ?
'-' :
'+') . sprintf(
'%02d:%02d', $iTZHour, $iTZMinutes);
355 return date(
'Y-m-d', $iTime) .
'T' . date(
'H:i:s', $iTime) . $strTZ;
static GetByIDEx($ID, $arAddParams=array())
Create($site_id, $max_execution_time, $NS, $arOptions=[])
GetURLs($site_id, $ID, $limit=0)
URLEncode($str, $charset)
if(! $ar_profile) $strFile
if(!defined('NOT_CHECK_PERMISSIONS')) $NS
ConvertDateTime($datetime, $to_format=false, $from_site=false, $bSearchInSitesOnly=false)
GetDirIndexArray($strDirIndex=false)
ExecuteModuleEventEx($arEvent, $arParams=[])
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
GetMessage($name, $aReplace=null)
MakeTimeStamp($datetime, $format=false)
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)