b2evolution PHP Cross Reference Blogging Systems

Source: /skins/_sitemap/index.main.php - 109 lines - 3478 bytes - Text - Print

Description: This template generates a sitemap feed for the requested blog's latest posts

   1  <?php
   2  /**
   3   * This template generates a sitemap feed for the requested blog's latest posts
   4   *
   5   * For a quick explanation of b2evo 2.0 skins, please start here:
   6   * {@link http://b2evolution.net/man/skin-structure}
   7   *
   8   * @package evoskins
   9   * @subpackage rss
  10   *
  11   * @version $Id: index.main.php 3157 2013-03-06 04:34:44Z fplanque $
  12   */
  13  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  14  
  15  $Timer->resume( 'prepare list' );
  16  
  17  load_class( '/items/model/_itemlistlight.class.php', 'ItemListLight' );
  18  
  19  // Use a LIGHT Item List:  (Sitemap = 50000 entries max)
  20  $MainList = new ItemListLight( $Blog, $Blog->get_timestamp_min(), $Blog->get_timestamp_max(), 50000 );
  21  
  22  // By default we only want items that have the MAIN cat in this blog,
  23  // i-e with its canonical URL in this blog (cross posted stuff will be listed in its main blog)
  24  // However this may be overriden in a stub (or param)
  25  param( 'cat_focus', 'string', 'main' );
  26  
  27  // Filter list:
  28  $MainList->set_filters( array(
  29          'visibility_array' => array( 'published' ),  // We only want to advertised published items
  30          'types' =>  '-'.implode(',',$posttypes_nopermanentURL),    // keep normal posts & pages BUT STILL EXCLUDE intros and sidebar links
  31        'unit' => 'all',                        // We want to advertise all items (not just a page or a day)
  32        'cat_focus' => $cat_focus,
  33      ) );
  34  
  35  // pre_dump( $cat_focus, $MainList->filters );
  36  
  37  // Run the query:
  38  $MainList->query();
  39  
  40  // Old style globals for category.funcs:
  41  // TODO: dh> check if still required.
  42  $postIDlist = $MainList->get_page_ID_list();
  43  $postIDarray = $MainList->get_page_ID_array();
  44  
  45  $Timer->stop( 'prepare list' );
  46  
  47  $Timer->resume( 'display list' );
  48  
  49  // TODO: dh> add entry for homepage (lastmod of latest item)
  50  // TODO: dh> take comments into consideration for prio
  51  // TODO: dh> use main Blog URL only, since google requires them to be on the same domain/path
  52  // (see sitemap_plugin)
  53  
  54  // Note: since URLs are likely to be clean ASCII, $io_charset can probably be faked to UTF-8 here
  55  headers_content_mightcache( 'application/xml', '#', 'UTF-8' );        // In most situations, you do NOT want to cache dynamic content!
  56  
  57  echo '<?xml version="1.0" encoding="UTF-8"?'.'>';
  58  ?>
  59  
  60  <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  61  <?php
  62  while( $Item = & mainlist_get_item() )
  63  {    // For each blog post, do everything below up to the closing curly brace "}"
  64  
  65      // Age in days of the post
  66      $age = ($localtimenow - mysql2timestamp($Item->datemodified)) / 86400;
  67  
  68      // Prio: Recent posts will get higher priority compared to older posts, in case the SE doesn't want to index all posts!
  69      // Change frequency: recent posts are more likely to change often than older posts, especially regarding comments.
  70      // We hint SEs to check back more often (and not to waste indexing credits on old stuff).
  71      if( $age < 8 )
  72      {
  73          $prio = 0.9;
  74          $changefreq = 'hourly';
  75      }
  76      elseif( $age < 30 )
  77      {
  78          $prio = 0.8;
  79          $changefreq = 'daily';
  80      }
  81      elseif( $age < 90 )
  82      {
  83          $prio = 0.7;
  84          $changefreq = 'daily';
  85      }
  86      elseif( $age < 365 )
  87      {
  88          $prio = 0.6;
  89          $changefreq = 'weekly';
  90      }
  91      else
  92      {
  93          $prio = 0.5;
  94          $changefreq = 'monthly';
  95      }
  96      ?>
  97      <url>
  98          <loc><?php $Item->permanent_url( 'single' ) ?></loc>
  99          <lastmod><?php $Item->mod_date( 'isoZ', true ) /* fp> date_touched including comments would be even better */ ?></lastmod>
 100          <priority><?php echo $prio; ?></priority>
 101          <changefreq><?php echo $changefreq; ?></changefreq>
 102      </url>
 103      <?php
 104  } ?>
 105  </urlset>
 106  <?php
 107  
 108  $Timer->stop( 'display list' );
 109  ?>

title

Description

title

Description

title

Description

title

title

Body