<?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;}

  include('./fancyurls.config.php');
  include('./cfg.php');
  setGlobalVariables('extra');
  include($DIR_PLUGINS."related/nusoap.php");

  global $_SERVER;
  $data=explode("/",_undoMagic($_SERVER['PATH_INFO']));
  $skinname=$data[1];

  $query=sql_query("select tableid, skin from ".sql_table('plug_extra_skin')." where url='$skinname'");
  if ($row=sql_fetch_object($query)) {
	// prepare skin for parsing
	$skinType='index';
    global $CONF, $blogid, $manager, $blog;
    $CONF['Self'] = './';
  	$blogid = $CONF['DefaultBlog'];
  	$b =& $manager->getBlog($blogid);
  	$blog = $b;
  	$skinid = $blog->getDefaultSkin();
  	$skin = new SKIN($skinid);
  	if (!defined('_CHARSET'))
  	  sendContentType($skin->getContentType(), 'skin', 'utf-8');
  	else
  	  sendContentType($skin->getContentType(), 'skin', _CHARSET);
    $handler = new ACTIONS($skinType);
    $parser = new PARSER(SKIN::getAllowedActionsForType($skinType), $handler);
    $parser->setProperty('IncludeMode',$skin->getIncludeMode());
    $parser->setProperty('IncludePrefix',$skin->getIncludePrefix());
    $handler->setSkin($skin);
    $handler->parser =& $parser;

	// start cache
	$pluginName='NP_Cache';
	if ($manager->pluginInstalled($pluginName)) $pluginObject =& $manager->getPlugin($pluginName);
	if ($pluginObject) {
		$data['type']=$skinType;
		$data['skinid']=$skinname;
		$pluginObject->event_PreSkinParse($data);
	}
	
	// parse it
	$data = stripslashes($row->skin);
    $parser->parse($data);
	
	// stop the cache
	if ($pluginObject) $pluginObject->event_PostSkinParse($data);
  }

?>