<?php
/**
  * BLOG:CMS: PHP/MySQL Personal Content Management System (CMS)
  * http://blogcms.com/
  * ----------------------------------------------------------------
  *
  * Copyright (C) 2003-2005 Radek HULN
  * http://hulan.cz/contact/
  *
  * ----------------------------------------------------------------
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
**/

  function _undoMagic($data) {return get_magic_quotes_gpc() ? stripslashes($data) : $data;}
  global $_SERVER;
  $data=explode("/",_undoMagic($_SERVER['PATH_INFO']));
  $skinname=$data[1];

  if (strpos($skinname,'.xml')!==false) $skinname=substr($skinname,0,strpos($skinname,'.xml'));

  $_feeds = array(
    'atom' => 'atom.php',
    'rss' => 'xml-rss.php',
    'rss1' => 'xml-rss1.php',
    'rss2' => 'xml-rss2.php',
    'comment' => '',
    'comments' => '',
    'pending' => ''
    );
  if (isset($_feeds[$skinname])){
    if (!empty($_feeds[$skinname])){
      header("Pragma: no-cache");
      global $CONF;
      $CONF = array();
      include('./cfg.php');
	  $CONF['ItemURL']=$CONF['IndexURL'];
      if (!$CONF['DisableSite']) {
  	    ob_start();
        $_skins = array(
          'atom' => 'atom',
          'rss' => 'xmlrss',
          'rss1' => 'xmlrss1',
          'rss2' => 'xmlrss2'
        );
        setGlobalVariables('feed');
  		  selectSkin($_skins[$skinname]);
  		  selector();
  	    $feed = ob_get_contents();
  	    ob_end_clean();
  	    $eTag = '"'.md5($feed).'"';
  	    header('Etag: '.$eTag);
  	    if ($eTag == serverVar('HTTP_IF_NONE_MATCH')) {
  		    header("HTTP/1.0 304 Not Modified");
  		    header('Content-Length: 0');
  	    } else
  		    echo $feed;
      }
    } else {
      $CONF = array();
      include('./cfg.php');
      setGlobalVariables('feed');
    	global $manager;
    	if ($skinname=='pending')
    	  $pluginName = 'NP_CommentControl';
  	    else
    	  $pluginName = 'NP_RSSBlog';
    	if (!$manager->pluginInstalled($pluginName)) doError(_ERROR_NOSUCHPLUGIN);
    	$pluginObject =& $manager->getPlugin($pluginName);
    	if ($pluginObject)
    		$error = $pluginObject->doAction('rss');
    	else
    		$error = 'Could not load plugin (see actionlog)';
    	if ($error) doError($error);

    }
    exit;
  }
?>