<?php error_reporting(E_ALL & ~E_NOTICE); date_default_timezone_set('UTC'); header("Content-Type: text/xml"); $siteurl = K_Registry::get('site'); $sitemap = new Sitemap(); //настройки источников и для формирования ссылок $TypesPlases = array('articles' => array('/articles/' => array("source" => '/articles/', "opt" => array('direct' => true)))); // Добавляем главную страницу $sitemap->addUrl($siteurl, $update, 'daily', '0.9'); $noInSitemap = array('baseblocks', '404', 'index', 'search', 'articlepage', 'object', 'print', 'articles'); //кастомные страницы // учитывать страницы с листалкой $staticPages = K_TreeQuery::crt("/pages/")->types('page')->go(); $pagesForCount = array_keys($pagesCounts); foreach ($staticPages as $v) { if (!in_array($v['tree_name'], $noInSitemap)) { /* if (in_array($v['tree_name'],$pagesForCount)){ if($pagesCounts[$v['tree_name']] && count($pagesCounts[$v['tree_name']])){ // статические страницы с листалкой - начальная страница echo "<url>\n<loc>".$siteurl.'/'.$v['tree_name']."</loc> <lastmod>$update</lastmod> <changefreq>daily</changefreq> <priority>0.5</priority> </url>\n"; $pCount = ceil($pagesCounts[$v['tree_name']]/10); for($i=2;$i<$pCount;$i++){ // статические страницы с листалкой - сама листалка echo "<url>\n<loc>".$siteurl.'/'.$v['tree_name'].'.list.'.$i.".10</loc> <lastmod>$update</lastmod>
/** * Renders and prints sitemap XML. * For gzip compression add paramter "compression" with compression method "bzip" or "gzip" as value. * Appending a name paramter with a file name will name your download file if you request via browser. * @access public * @return void * @todo Create zend route from ./sitemap.xml to site/sitemap * @todo Create zend route from ./sitemap.xml.gz to site/sitemap/compression/gzip/name/sitemap.xml.gz * @todo Create zend route from ./sitemap.xml.bz2 to site/sitemap/compression/bzip/name/sitemap.xml.bz2 * @todo add support for sitemap index */ public function sitemapAction() { $compression = $this->getParam('compression'); # $page = (integer) $this->getParam( 'page' ); $pathGenerator = __DIR__ . '/libraries/SitemapGenerator/classes/'; require_once $pathGenerator . 'Sitemap.php'; require_once $pathGenerator . 'Sitemap/URL.php'; require_once $pathGenerator . 'XML/Builder.php'; require_once $pathGenerator . 'XML/Node.php'; // Here we start the object cache id $sitemapObjectCacheIdSource = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $sitemapObjectCacheId = 'sitemap_' . md5($sitemapObjectCacheIdSource); // try to load the cached value $erfurtObjectCache = OntoWiki::getInstance()->erfurt->getCache(); $erfurtQueryCache = OntoWiki::getInstance()->erfurt->getQueryCache(); $sitemapXml = $erfurtObjectCache->load($sitemapObjectCacheId); if ($sitemapXml === false) { $erfurtQueryCache->startTransaction($sitemapObjectCacheId); $siteConfig = $this->_getSiteConfig(); $this->_loadModel(); $query = ' SELECT DISTINCT ?resourceUri ?modified WHERE { ?resourceUri <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> ?type. OPTIONAL {?resourceUri <http://purl.org/dc/terms/modified> ?modified } FILTER strstarts(str(?resourceUri), "' . $siteConfig['model'] . '") } '; //OPTIONAL {?resourceUri <http://purl.org/dc/terms/modified> ?modified } //?resourceUri <http://purl.org/dc/terms/modified> ?modified $results = $this->_model->sparqlQuery($query); $sitemap = new Sitemap(); foreach ($results as $result) { $url = new Sitemap_URL($result['resourceUri']); if (isset($result['modified']) && strlen($result['modified'])) { $url->setDatetime($result['modified']); } $sitemap->addUrl($url); } $sitemapXml = $sitemap->render(); // save the page body as an object value for the object cache $erfurtObjectCache->save($sitemapXml, $sitemapObjectCacheId); // close the object cache transaction $erfurtQueryCache->endTransaction($sitemapObjectCacheId); } $contentType = "application/xml"; // compression has been requested if (strlen(trim($compression))) { switch (strtolower($compression)) { case 'bzip': $sitemapXml = bzcompress($sitemapXml); $contentType = "application/x-bzip"; header('Content-Encoding: bzip2'); break; case 'gzip': $sitemapXml = gzencode($sitemapXml); $contentType = "application/x-gzip"; header('Content-Encoding: gzip'); break; } } header('Content-Length: ' . strlen($sitemapXml)); header("Content-Type: " . $contentType); print $sitemapXml; exit; }