<?php
/*
 *
 * sflog!
 * Copyright (C) 2005 Alberto Sfolcini <a.sfolcini@gmail.com>
 *
 * This file is a part of sflog!.
 *
 * sflog! 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.
 *
 * sflog! is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

require_once(dirname(__FILE__)."/../common/Ini.class.php");
require_once(dirname(__FILE__)."/../cms/Constants.inc.php");
require_once(dirname(__FILE__)."/../cms/themeConstants.inc.php");
require_once(dirname(__FILE__)."/../common/utils.func.php");
require_once(dirname(__FILE__)."/../common/WriteFile.class.php");
	
/**
 * @title			: Theme
 * @description			: Manages Themes   
 * @date			: 8-Mar-2012   
 * @author			: Alberto Sfolcini  <a.sfolcini@gmail.com>
 */
class Theme {

	var $themeName = "";
	var $templateFileName = "template.php";

	/**
	 * Constructor 1
	 */
	function Theme($themeName){
	  $this->themeName = $themeName;
	}

	function install($fn){
	   $f = $fn.'/'.$this->templateFileName;
	   if (file_exists($f)){
	   	$file = file_get_contents($f);

		$css = './themes/'.$this->themeName.'/'.$this->themeName.'.css';

		// replacing...
		$file = str_replace(TEMPLATE_PAGE_HEADER	, TEMPLATE_PAGE_HEADER_CONTENT		, $file);
		$file = str_replace(TEMPLATE_PAGE_TITLE		, TEMPLATE_PAGE_TITLE_CONTENT		, $file);
		$file = str_replace(TEMPLATE_SITE_LOGO		, TEMPLATE_SITE_LOGO_CONTENT		, $file);
		$file = str_replace(TEMPLATE_SITE_BLOGSBAR	, TEMPLATE_SITE_BLOGSBAR_CONTENT	, $file);
		$file = str_replace(TEMPLATE_SITE_PATHBAR	, TEMPLATE_SITE_PATHBAR_CONTENT		, $file);
		$file = str_replace(TEMPLATE_SITE_ENTRIES	, TEMPLATE_SITE_ENTRIES_CONTENT		, $file);
		$file = str_replace(TEMPLATE_SITE_SIDEBAR	, TEMPLATE_SITE_SIDEBAR_CONTENT		, $file);
		$file = str_replace(TEMPLATE_SITE_FOOTER	, TEMPLATE_SITE_FOOTER_CONTENT		, $file);				
		$file = str_replace(TEMPLATE_SITE_TRACKER	, TEMPLATE_SITE_TRACKER_CONTENT		, $file);				
		$file = str_replace(TEMPLATE_SITE_CSS		, $css					, $file);
		
		// writing...
	   	$wf = new WriteFile($fn.'/index.php',REWRITE);
	   	$wf->writeStr($file);
	   	$wf->closeFile();
	   	copy($fn.'/index.php','../index.php');
	   	return true;
	   }else{
		return false;
	   }
	}


} // end class
?>