B0Bka / box

0 stars 0 forks source link

карта сайту #29

Open B0Bka opened 6 years ago

B0Bka commented 6 years ago

`<? ini_set("memory_limit", "512M"); if (!$_SERVER["DOCUMENT_ROOT"]) { require_once dirname(FILE) . '/../../config.php'; // забираем отсюда конфиг } use Bitrix\Highloadblock as HL; use Bitrix\Main; use Bitrix\Main\IO; use Bitrix\Main\SiteTable; use Bitrix\Main\Localization\Loc; use Bitrix\Seo\RobotsFile; use Bitrix\Seo\SitemapIblock; use Bitrix\Seo\SitemapTable; use Bitrix\Seo\SitemapIndex; use Bitrix\Seo\SitemapRuntime; use Bitrix\Seo\SitemapRuntimeTable; require_once($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");

if (!CModule::IncludeModule('iblock')) { return false; } define('PROTOCOL', ($_SERVER['HTTPS'] === true) ? 'https' : 'http'); // Catalog - sitemap_000 $urlTemplate = "

%s%s %s %s %s
";

$prefix = CNext::siteUrl(); $content = $filterContent = ''; // main page $content .= sprintf($urlTemplate ,$prefix.'/' ,null , date('c') ,'1', 'Weekly' ); Main\Loader::includeModule('seo'); $PID = 3; $dbSitemap = SitemapTable::getById($PID); $arSitemap = $dbSitemap->fetch();

$dbSite = SiteTable::getByPrimary($arSitemap['SITE_ID']); $arSitemap['SITE'] = $dbSite->fetch(); $arSitemap['SETTINGS'] = unserialize($arSitemap['SETTINGS']);

$PID2 = 2; $dbSitemapOdessa = SitemapTable::getById($PID2); $arSitemapOdessa = $dbSitemapOdessa->fetch();

$dbSiteOdessa = SiteTable::getByPrimary($arSitemapOdessa['SITE_ID']); $arSitemapOdessa['SITE'] = $dbSiteOdessa->fetch(); $arSitemapOdessa['SETTINGS'] = unserialize($arSitemapOdessa['SETTINGS']);

$sections = getStruct($arSitemap); foreach($sections as $section) { $url = $prefix.$section.'/'; $content .= sprintf($urlTemplate ,$url ,null ,$date ? $date : date('c') ,'0.9', 'Weekly' ); } foreach($arSitemapOdessa['SETTINGS']['IBLOCK_SECTION'] as $key => $val) if($val == 'Y') { $arSiteIb[$key] = $arSitemapOdessa['SITE']['DIR']; $arSectionIbId[$key] = $key; } foreach($arSitemap['SETTINGS']['IBLOCK_SECTION'] as $key => $val) if($val == 'Y') { $arSiteIb[$key] = $arSitemap['SITE']['DIR']; $arSectionIbId[$key] = $key; }

$content .= getIbSection($arSectionIbId, $arSiteIb, $urlTemplate);

foreach($arSitemapOdessa['SETTINGS']['IBLOCK_ELEMENT'] as $key => $val) if($val == 'Y') { $arElIb[$key] = $arSitemapOdessa['SITE']['DIR']; $arElIbId[$key] = $key; } foreach($arSitemap['SETTINGS']['IBLOCK_ELEMENT'] as $key => $val) if($val == 'Y') { $arElIb[$key] = $arSitemap['SITE']['DIR']; $arElIbId[$key] = $key; } $content .= getIbEl($arElIbId, $arElIb, $urlTemplate);

$startMap = '<?xml version="1.0" encoding="UTF-8"?>'; $endMap = '';

// Write to file $CATALOG_FILE_PATH = rel2abs($_SERVER['DOCUMENT_ROOT'], 'sitemap.xml'); $contentMap = $startMap . $content . $endMap; if ($file_000 = fopen($CATALOG_FILE_PATH, "wb")) { $int_content = fwrite($file_000, $contentMap ); fclose($file_000); } else { echo 'Ошибка записи в файл '.$CATALOG_FILE_PATH; }

function getStruct($arSitemap, $dir = '/') { $list = \CSeoUtils::getDirStructure( $arSitemap['SETTINGS']['logical'] == 'Y', $arSitemap['SITE_ID'], $dir ); foreach($list as $dir) { $dirKey = "/".ltrim($dir['DATA']['ABS_PATH'], "/");

    if($dir['TYPE'] != 'F')
    {
        if(!isset($arSitemap['SETTINGS']['DIR'][$dirKey])
            || $arSitemap['SETTINGS']['DIR'][$dirKey] == 'Y')
        {
            $arDirList[] = $dirKey;
            foreach($arSitemap['SETTINGS']['FILE'] as $dirKeySettting => $checked)
            {
                if($checked == 'Y')
                {
                    if(strncmp($arCurrentDir['ITEM_PATH'], $dirKeySettting, $len) === 0)
                    {
                        $fileName = IO\Path::combine(
                            SiteTable::getDocumentRoot($arSitemap['SITE_ID']),
                            $dirKeySettting
                        );

                        if(!is_dir($fileName))
                        {
                            $f = new IO\File($fileName, $arSitemap['SITE_ID']);
                            if($f->isExists()
                                && !$f->isSystem()
                                && preg_match($arSitemap['SETTINGS']['FILE_MASK_REGEXP'], $f->getName())
                            )
                            {
                                $sitemapFile->addFileEntry($f);
                                $NS['files_count']++;
                            }
                        }
                    }
                }
            }
            $child = getStruct($arSitemap, $dirKey);
            if(count($child) > 0) $arDirList = array_merge($arDirList, $child);             
        }
    }
}
return $arDirList;

}

function getIbSection($arSettingsIds, $arSite, $urlTemplate) { $content = ''; foreach($arSettingsIds as $ibId) { $sort = Array('SORT' => 'ASC'); $filter = Array('IBLOCK_ID' => $ibId, 'ACTIVE' => 'Y', 'GLOBAL_ACTIVE' => 'Y', 'DEPTH_LEVEL' => 1); $select = Array('ID', 'TIMESTAMP_X', 'SECTION_PAGE_URL', 'CODE'); $resDbSections = CIBlockSection::GetList($sort, $filter, false, $select); $sections = $filterMap = Array(); while ($arSec = $resDbSections->GetNext()) { $sections[$arSec['ID']] = $arSec; if ($stmp = MakeTimeStamp($arSec['TIMESTAMP_X'])) { $date = date("c", $stmp); } $content .= sprintf($urlTemplate ,CNext::siteUrl().setSiteDir($arSite[$arSec['IBLOCK_ID']], $arSec['SECTION_PAGE_URL']) ,null ,$date ? $date : date('c') ,'0.9', 'Weekly' ); //echo '

'; print_r($content); echo '
'; }
}

return $content;

}

function getIbEl($arSettingsIds, $arSite, $urlTemplate) { $content = ''; foreach($arSettingsIds as $ibId) { $sort = Array('SORT' => 'ASC'); $filter = Array( 'IBLOCK_ID' => $ibId, 'ACTIVE'=>'Y', 'SECTION_ACTIVE' => 'Y', 'SECTION_GLOBAL_ACTIVE' => 'Y' ); $select = Array('ID', 'TIMESTAMP_X', 'DETAIL_PAGE_URL'); $resDbProducts = CIBlockElement::GetList($sort, $filter, false, false, $select); while ($arEl = $resDbProducts->GetNext()) { if ($stmp = MakeTimeStamp($arEl['TIMESTAMP_X'])) { $date = date("c", $stmp); }

        $content .= sprintf($urlTemplate
            ,CNext::siteUrl().setSiteDir($arSite[$arEl['IBLOCK_ID']], $arEl['DETAIL_PAGE_URL'])
            ,null
            ,$date ? $date : date('c')
            ,'0.7',
            'Monthly'
        );
    }
}

return $content;    

} function setSiteDir($siteDir, $url) { return substr_replace($url, $siteDir, 0, 1); } ?> `