<?PHP if (!defined('PmWiki')) exit();

## Examples taken from blogger sitemap structure
# you can configure it further with pmwiki feed features
# like : group, name, list, count ...

# I configure it like this for sitemapindex:
# http://website/wiki/index.php?group=*&name=RecentChanges&action=sitemapindex

# to keep short on robots.txt, you can buffer 
# the content of the url above, send a text/xml
# header and feed it to the robots

# apparently google don't like anything other than this
SDV($RSSTimeFmt , 'Y-m-d');

# replace priority for certain pages
SDV($GFeedPriorityBypass , array(
  'Main.HomePage' => '8.0',
  'Main.WikiSandbox' => '0.2',
  'PmWiki' => '0.5',
  'PmWikiPtBr' => '1.0',
));

# yearly, monthly, weekly and daily change frequency
SDV($FmtPV['$ItemChangeFreq'] , "GFeedChangeFreq(\$page)");

function GFeedChangeFreq($c){
global $Now;

$c = $c['time'];
$r = $Now - $c;
 
return GFeedChangeFreqGrader($r);

}

# grade priority, priorities can be changed
SDV($FmtPV['$ItemPriority'] , "GFeedPriority(\$page)");

# this shows priority using age
function GFeedPriority($p){
global $GFeedPriorityBypass, $Now;

$pag = $p['pagename'];
$bps = $GFeedPriorityBypass;
$rtr = '';

foreach($bps as $pat => $rep){
  if(stripos($pag,$pat) !== false){
    $rtr = $rep;
  }
}

if($rtr != '') return $rtr;

$age = GFeedPriorityAge($p); 
$rev = GFeedPriorityRevs($p);
$nor = GFeedPriorityNoRev($p);
$rpt = GFeedPriorityPerRev($p);

# now the formulae ^^
$total = ($age + $rev + $rpt + $nor) / 4;
$total = substr("$total",0,3);

return $total;

}

# this shows priority using age
function GFeedPriorityAge($p){
global $Now;

$t = $p['time'];
$c = $p['ctime'];
$a = $t - $c;

return GFeedTimeGrader($a);

}

# time without revisions - graded
function GFeedPriorityNoRev($p){
global $Now;

$t = $Now - $p['time'];

return GFeedTimeGrader($t);

}

# total number of revisions - graded
function GFeedPriorityRevs($p){
global $Now;

$r = $p['rev'];

return GFeedQuantityGrader($r);

}

# time between revisions - graded
function GFeedPriorityPerRev($p){

$t = $p['time']; # creation to last edit
$r = $p['rev'];
$rt = $t / $r;

return GFeedTimeGrader($rt);

}

function GFeedTimeGrader($t){

$t = $t;

if($t > 0 && $t <= 86400) return "1.0";
if($t >= 86400 && $t >= 604800) return "0.8";
if($t >= 604800 && $t >= 2419800) return "0.6";
if($t >= 2419800 && $t <= 29030400) return "0.4";
if($t >= 29030400) return "0.2";

}

function GFeedQuantityGrader($r){

$r = $r;

if($r >= 50) return "1.0";
if($r >= 40 && $r >=  49) return "0.8";
if($r >= 30 && $r >=  39) return "0.6";
if($r >= 20 && $r <=  29) return "0.4";
if($r >=  0 && $r <=  19) return "0.2";

}

function GFeedChangeFreqGrader($c){

$c = $c;

if($c >= 0 && $c <= '86400') return "daily";
if($c > '86400' && $c <= '604800') return "weekly";
if($c > '604800' && $c <= '2419800') return "monthly";
if($c > '2419800') return "yearly";

}

## Sitemapindex 0.9 settings for ?action=sitemapindex
SDVA($FeedFmt['sitemapindex']['feed'], array(
  '_header' => 'Content-type: text/xml; charset="$Charset"',
  '_start' => '<?xml version="1.0" encoding="$Charset"?>'."\n".
     '<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n",
  '_end' => "\n</sitemapindex>\n",
));

SDVA($FeedFmt['sitemapindex']['item'], array(
  '_start' => "<sitemap>\n",
  '_end' => "</sitemap>\n",
  'loc' => ($EnablePathInfo == 1) 
         ? '{$ScriptUrl}/?group={$Group}&amp;action=sitemap'
         : '{$ScriptUrl}?group={$Group}&amp;action=sitemap'
));

## Sitemap 0.9 settings for ?action=sitemap
SDVA($FeedFmt['sitemap']['feed'], array(
  '_header' => 'Content-type: text/xml; charset="$Charset"',
  '_start' => '<?xml version="1.0" encoding="$Charset"?>'."\n".
     '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">'."\n",
  '_end' => "</urlset>\n",
));

SDVA($FeedFmt['sitemap']['item'], array(
  '_start' => "<url>\n",
  '_end' => "</url>\n",
  'loc' => '{$PageUrl}',
  'lastmod' => '$ItemRSSTime',
  'changefreq' => '$ItemChangeFreq',
  'priority' => '$ItemPriority',
));