[ PHPXref.com ] [ Generated: Sun Jul 20 21:12:30 2008 ] [ YACS 6.3.1 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/ -> sitemap.php (source)

   1  <?php
   2  /**

   3   * help Google to index this site

   4   *

   5   * To speed the indexation of your site, visit Google, and submit

   6   * result of this script.

   7   *

   8   * @link https://www.google.com/webmasters/sitemaps/docs/en/submit_mobile.html

   9   *

  10   * This script lists pages to feed Google crawler:

  11   * - the front page

  12   * - the site map

  13   * - top root sections

  14   * - the categories tree

  15   * - top root categories

  16   * - the member index

  17   * - the OMPL feed

  18   *

  19   * This script is a straightforward implementation of the XML Sitemap protocol.

  20   *

  21   * @link https://www.google.com/webmasters/sitemaps/docs/en/protocol.html Sitemap Protocol Contents

  22   *

  23   * If following features are enabled, this script will use them:

  24   * - compression - Using gzip, if accepted by user agent

  25   * - cache - Cache is supported through ETag and by setting Content-Length; Also, Cache-Control enables caching for some time, even through HTTPS

  26   *

  27   * @author Bernard Paques [email]bernard.paques@bigfoot.com[/email]

  28   * @reference

  29   * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License

  30   */
  31  
  32  // common definitions and initial processing

  33  include_once  'shared/global.php';
  34  include_once  'shared/surfer.php';
  35  include_once  'shared/cache.php';
  36  
  37  // required by Google

  38  $context['charset'] = 'utf-8';
  39  
  40  // load a skin engine

  41  load_skin('sitemap');
  42  
  43  // get the list from the cache, if possible

  44  $cache_id = 'sitemap.php#content';
  45  if(!$text = Cache::get($cache_id)) {
  46  
  47      // the preamble

  48      $text = '<?xml version="1.0" encoding="'.$context['charset'].'"?>'."\n"
  49          .'<urlset xmlns="http://www.google.com/schemas/sitemap/0.84">'."\n";
  50  
  51      // the front page

  52      $text .= '    <url>'."\n"
  53          .'        <loc>'.$context['url_to_home'].$context['url_to_root'].'</loc>'."\n"
  54          .'        <changefreq>weekly</changefreq>'."\n"
  55          .'        <priority>1.0</priority>'."\n"
  56          .'    </url>'."\n\n";
  57  
  58      // the site map

  59      $text .= '    <url>'."\n"
  60          .'        <loc>'.$context['url_to_home'].$context['url_to_root'].'sections/index.php</loc>'."\n"
  61          .'        <changefreq>weekly</changefreq>'."\n"
  62          .'        <priority>1.0</priority>'."\n"
  63          .'    </url>'."\n\n";
  64  
  65      // main sections

  66      include_once  'sections/sections.php';
  67      if($items = Sections::list_by_title_for_anchor(NULL, 0, 25, 'raw'))
  68          foreach($items as $id => $title)
  69              $text .= '    <url>'."\n"
  70                  .'        <loc>'.$context['url_to_home'].$context['url_to_root'].Sections::get_url($id, 'view').'</loc>'."\n"
  71                  .'        <changefreq>weekly</changefreq>'."\n"
  72                  .'    </url>'."\n\n";
  73  
  74      // the categories tree

  75      $text .= '    <url>'."\n"
  76          .'        <loc>'.$context['url_to_home'].$context['url_to_root'].'categories/index.php</loc>'."\n"
  77          .'        <changefreq>weekly</changefreq>'."\n"
  78          .'        <priority>0.7</priority>'."\n"
  79          .'    </url>'."\n\n";
  80  
  81      // main categories

  82      include_once  'categories/categories.php';
  83      if($items = Categories::list_by_date(0, 25, 'raw'))
  84          foreach($items as $id => $title)
  85              $text .= '    <url>'."\n"
  86                  .'        <loc>'.$context['url_to_home'].$context['url_to_root'].Categories::get_url($id, 'view').'</loc>'."\n"
  87                  .'        <changefreq>weekly</changefreq>'."\n"
  88                  .'    </url>'."\n\n";
  89  
  90      // members

  91      $text .= '    <url>'."\n"
  92          .'        <loc>'.$context['url_to_home'].$context['url_to_root'].'users/index.php</loc>'."\n"
  93          .'        <changefreq>weekly</changefreq>'."\n"
  94          .'        <priority>0.7</priority>'."\n"
  95          .'    </url>'."\n\n";
  96  
  97      // the OPML feed

  98      $text .= '    <url>'."\n"
  99          .'        <loc>'.$context['url_to_home'].$context['url_to_root'].'feeds/describe.php</loc>'."\n"
 100          .'        <changefreq>weekly</changefreq>'."\n"
 101          .'    </url>'."\n\n";
 102  
 103      // the postamble

 104      $text .= '</urlset>'."\n";
 105  
 106      // save in cache for the next request

 107      Cache::put($cache_id, $text, 'articles');
 108  }
 109  
 110  //

 111  // transfer to the user agent

 112  //

 113  
 114  // handle the output correctly

 115  if(!headers_sent() && (!function_exists('ob_list_handlers') || (array_search('yacs_handler', ob_list_handlers()) === FALSE))) {
 116  
 117      // avoid blank pages

 118      if($starter = ob_get_contents())
 119          ob_end_clean();
 120  
 121      // add our own output handler

 122      ob_start('yacs_handler');
 123      header('Content-Type: text/xml; charset='.$context['charset']);
 124  
 125      // print error messages, if any

 126      if($starter)
 127          echo $starter;
 128  
 129  }
 130  
 131  // suggest a name on download

 132  if(!headers_sent()) {
 133      $file_name = utf8::to_ascii($context['site_name'].'.sitemap.xml');
 134      header('Content-Disposition: inline; filename="'.$file_name.'"');
 135  }
 136  
 137  // enable 30-minute caching (30*60 = 1800), even through https, to help IE6 on download

 138  if(!headers_sent()) {
 139      header("Cache-Control: max-age=1800, public");
 140      header("Pragma: ");
 141  }
 142  
 143  // strong validation

 144  if((!isset($context['without_http_cache']) || ($context['without_http_cache'] != 'Y')) && !headers_sent()) {
 145  
 146      // generate some strong validator

 147      $etag = '"'.md5($text).'"';
 148      header('ETag: '.$etag);
 149  
 150      // validate the content if hash is ok

 151      if(isset($_SERVER['HTTP_IF_NONE_MATCH']) && is_array($if_none_match = explode(',', str_replace('\"', '"', $_SERVER['HTTP_IF_NONE_MATCH'])))) {
 152          foreach($if_none_match as $target) {
 153              if(trim($target) == $etag) {
 154                  header("HTTP/1.0 304 Not Modified");
 155                  return;
 156              }
 157          }
 158      }
 159  }
 160  
 161  // actual transmission except on a HEAD request

 162  if(isset($_SERVER['REQUEST_METHOD']) && ($_SERVER['REQUEST_METHOD'] != 'HEAD'))
 163      echo $text;
 164  
 165  // the post-processing hook

 166  @include_once $context['path_to_root'].'shared/hooks.include.php';
 167  if(class_exists('Hooks'))
 168      @Hooks::include_scripts('finalize');
 169  
 170  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]