PHP Classes

File: engine/modules/core/sitemap/sitemap.hook.inc

Recommend this page to a friend!
  Classes of Aldo Tripiciano   Quanta CMS   engine/modules/core/sitemap/sitemap.hook.inc   Download  
File: engine/modules/core/sitemap/sitemap.hook.inc
Role: Example script
Content type: text/plain
Description: Example script
Class: Quanta CMS
Manage content that works without a database
Author: By
Last change:
Date: 5 years ago
Size: 1,565 bytes
 

Contents

Class file image Download
<?php
/**
 * Implements hook_boot().
 *
 * @param Environment $env
 * The Environment.
 * @param array $vars
 * An array of variables.
 */
function sitemap_boot($env, $vars) {
 
// TODO: object oriented, using templates, etc. etc.
 
if ($env->getRequestedPath() == 'google_sitemap') {
   
header("Content-type: text/xml");

    print
"<?xml version=\"1.0\" encoding=\"utf-8\" ?>" . "\n";
    echo
"<urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">\n";
   
$site_pages = $env->scanDirectoryDeep($env->dir['docroot'], '', array(), array(
     
'exclude_dirs' => DIR_INACTIVE,
     
'symlinks' => FALSE,
     
DIR_ALL,
     
'level' => 'tree'
   
));

   
$already_done = array();
    foreach (
$site_pages as $item) {
     
$node = NodeFactory::load($env, $item['name']);
     
$modtime = (file_exists($item['path'] . '/data.json') ? filemtime($item['path'] . '/data.json') : filemtime($item['path']));

      if (!(
$node->isPublished()) || isset($already_done[$item['name']]) || $node->getAttributeJSON('sitemap_exclude')) {
        continue;
      }
     
$already_done[$item['name']] = TRUE;
     
$priority = ($item['name'] == '') ? 1 : 0.7;
     
$freq = ($item['name'] == '' ? 'daily' : 'weekly');

      echo
"<url>\n";
      echo
"<loc>" . $env->getBaseUrl() . "/" . $item['name'] . "</loc>";
      echo
"<lastmod>" . date('Y-m-d', $modtime) . "</lastmod>\n";
      echo
"<changefreq>" . $freq . "</changefreq>\n";
      echo
"<priority>" . $priority . "</priority>\n";
      echo
"</url>\n";
    }
    print
"</urlset>\n";

    exit();
  }
}