<?php
  require_once('tiki-setup.php');
  require_once('lib/tikilib.php'); # httpScheme()
  include_once('lib/wiki/histlib.php');

  if($rss_wiki != 'y') {
   die;
  }
  
  if($tiki_p_view != 'y') {
    $smarty->assign('msg',tra("Permission denied you cannot view this section"));
    $smarty->display("styles/$style_base/error.tpl");
    die;  
  }

  header("content-type: text/xml");
  $foo = parse_url($_SERVER["REQUEST_URI"]);
  $foo1=str_replace("tiki-wiki_rss.php","tiki-index.php",$foo["path"]);
  $foo2=str_replace("tiki-wiki_rss.php","img/tiki.jpg",$foo["path"]);
  $foo3=str_replace("tiki-wiki_rss.php","lib/rss/rss-style.css",$foo["path"]);
  $home = httpPrefix().$foo1;
  $img = httpPrefix().$foo2;
  $css = httpPrefix().$foo3;
  $title = $tikilib->get_preference("title","Tiki RSS feed for the wiki pages");
  $title = "Tiki RSS feed for the wiki pages";
  $desc = "Last modifications to the Wiki.";
  $changes =   $histlib->get_last_changes(999, 0, $max_rss_wiki, $sort_mode = 'lastModif_desc');

  print '<?xml version="1.0" encoding="UTF-8"?>'."\n";
  print '<?xml-stylesheet href="'.$css.'" type="text/css"?>'."\n";
?>
<rdf:RDF xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:h="http://www.w3.org/1999/xhtml" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://purl.org/rss/1.0/">
<channel rdf:about="<?php echo htmlspecialchars($home); ?>">
  <title><?php echo htmlspecialchars($title); ?></title>
  <link><?php echo htmlspecialchars($home); ?></link>
  <description>
    <?php echo htmlspecialchars($desc); ?>
  </description>

  <image rdf:about="<?php echo htmlspecialchars($img); ?>">
    <title><?php echo htmlspecialchars($title); ?></title>
    <link><?php echo htmlspecialchars($home); ?></link>
    <url><?php echo htmlspecialchars($img); ?></url>
  </image>

  <items>
    <rdf:Seq>
      <?php
        // LOOP collecting last changes to the wiki pages (index)
        foreach($changes["data"] as $chg) {
          print('        <rdf:li resource="'.$home.'?page='.urlencode($chg["pageName"]).'" />'."\n");
        }        
      ?>
    </rdf:Seq>  
  </items>
</channel>

<?php
  // LOOP collecting last changes to the wiki pages
  foreach($changes["data"] as $chg) {
    print('<item rdf:about="'.$home.'?page='.urlencode($chg["pageName"]).'">'."\n");
    print('  <title>'.htmlspecialchars($chg["pageName"].' '.$chg["action"]).'</title>'."\n");
    print('  <link>'.$home.'?page='.urlencode($chg["pageName"]).'</link>'."\n");
    $date = $tikilib->date_format($tikilib->get_short_datetime_format(),$chg["lastModif"]);
    if(!empty($chg["comment"])) {
      $comment="(".htmlspecialchars($chg["comment"]).")";
    } else {
      $comment='';
    }
    print('  <description>'.htmlspecialchars("[$date]: ".$chg["action"]." ".$chg["pageName"]).$comment.'</description>'."\n");
    print('</item>'."\n\n");
  }        
?>

</rdf:RDF>       
