当前位置: 首页>>代码示例>>PHP>>正文


PHP Sitemap::addUrl方法代码示例

本文整理汇总了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> 
开发者ID:CrazyBobik,项目名称:allotaxi.test,代码行数:31,代码来源:sitemap.php

示例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;
    }
开发者ID:cfrancois7,项目名称:site.ontowiki,代码行数:76,代码来源:SiteController.php


注:本文中的Sitemap::addUrl方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。