本文整理汇总了PHP中Sitemap::addUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Sitemap::addUrl方法的具体用法?PHP Sitemap::addUrl怎么用?PHP Sitemap::addUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sitemap
的用法示例。
在下文中一共展示了Sitemap::addUrl方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Sitemap
<?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>
示例2: sitemapAction
/**
* 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;
}