<?php
/*
 * This file is part of the easy-CMS project.
 * easy-CMS 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.
 * 
 * easy-CMS 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 easy-CMS; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/**
 * @package    Core
 * @subpackage Frames
 */

include_once('config.inc.php');
include_once('classes/system/File.class.php');
include_once('classes/core/DBAccessorObject.class.php');
include_once('classes/core/containers/ContainersManager.class.php');
include_once('classes/core/containers/Container.class.php');
include_once('classes/core/containersLists/ContainersListsManager.class.php');
include_once('classes/core/containersLists/ContainersList.class.php');
include_once('classes/core/menus/MenusManager.class.php');
include_once('classes/core/menus/Menu.class.php');
include_once('classes/core/Site.class.php');

include_once('classes/core/parser/HTMLParser.class.php');

/**
 * Interpreter for pages templates and returns webpages(complete HTML code).
 *
 * @access     public
 * @author	   Cedric Francoys <cedric.francoys@easy-cms.org>
 * @version	   Frame.class, Sun Nov 14 16:40:59 CET 2004
 * @package	   Core
 * @subpackage Frames
 */
class Frame {
	/**
	 * Frame Id
	 *
	 * @var integer
	 */
	var $id;
	
	/**
	 * Frame Name
	 *
	 * @var string
	 */
	var $name;
	
	/**
	 * Frame Associated File
	 *
	 * @var string
	 */
	var $fileName;
	
	/**
	 * Frame Associated Styles
	 *
	 * @var array
	 */
	var $styles;
	
	/**
	 * Frame Associated Scripts
	 *
	 * @var array
	 */
	var $scripts;
	
	/**
	 * Frame Associated File Content
	 *
	 * @var string
	 */
	var $xhtml;
	
	/**
	 * Constructor
	 *
	 * @param integer $id Frame Id
	 * @param string  $name Frame Name
	 * @param string  $fileName Frame File Name
	 */
	function Frame($id=0, $name='', $fileName='') {	
		$this->setFrameId($id);
		$this->setFrameName($name);
		$this->setFrameFileName($fileName);
		$this->setFrameXHTML('');
		$this->styles = array();
		$this->scripts = array();
		$this->loadFrameXHTML();
	}
	
	/**
	 * Gets Frame Id
	 *
	 * @return integer
	 */
	function getFrameId(){
		return $this->id;
	}
	
	/**
	 * Sets Frame Id
	 *
	 * @param integer $id Frame Id
	 */
	function setFrameId($id){
		$this->id = $id;
	}
	
	/**
	 * Gets Frame Name
	 *
	 * @return string
	 */
	function getFrameName(){
		return $this->name;
	}
	
	/**
	 * Sets Frame Name
	 *
	 * @param string $name Frame Name
	 */
	function setFrameName($name){
		$this->name = $name;
	}
	
	/**
	 * Gets Frame File Name
	 *
	 * @return string
	 */
	function getFrameFileName(){
		return $this->fileName;
	}
	
	/**
	 * Sets Frame File Name
	 *
	 * @param string $fileName
	 */
	function setFrameFileName($fileName) {
		$this->fileName = $fileName;
	}
	
	/**
	 * Gets Frame Associated Styles
	 *
	 * @return array
	 */
	function getFrameStyles() {
		return $this->styles;
	}
	
	/**
	 * Adds Frame Style
	 *
	 * @param integer $styleId
	 * @param string $styleFile
	 */
	function addFrameStyle($styleId, $styleFile) {
		$this->styles[$styleId] = $styleFile;
	}
	
	/**
	 * Gets Frame Associated Scripts
	 *
	 * @return array
	 */
	function getFrameScripts() {
		return $this->scripts;
	}
	
	/**
	 * Adds Frame Script
	 *
	 * @param integer $scriptId
	 * @param string $scriptFile
	 */
	function addFrameScript($scriptId, $scriptFile){
		$this->scripts[$scriptId] = $scriptFile;
	}
	
	/**
	 * Gets Frame Associated File Content
	 *
	 * @return string
	 */
	function getFrameXHTML() {
		return $this->xhtml;
	}
	
	/**
	 * Sets Frame Associated File Content
	 *
	 * @param string $xhtml Frame XHTML
	 */
	function setFrameXHTML($xhtml){
		$this->xhtml = $xhtml;
	}

	/**
	 * Loads XHTML
	 *
	 * @return boolean
	 */
	function loadFrameXHTML() {
		$path  = REPOSITORY_FOLDER;
		$path .= '/'.TEMPLATES_FOLDER;
		$path .= '/'.$this->getFrameFileName();
		$cwd   = (strpos(getcwd(), '\\')) ? getcwd() : '/'.getcwd();
		$file  = &new File('', $cwd.'/'.$path);
		if (!($xhtml = $file->read()))
			return false;
		$this->setFrameXHTML($xhtml);
		return true;
	}
	
	/**
	 * Gets HTML
	 *
	 * Computes Frame and returns corresponding HTML
	 *
	 * @return string HTML
	 */
	function &getHTML($langId){
		$xhtml = &$this->getFrameXHTML();
		$htmlParser = &new HTMLParser($xhtml);
		$html = &$htmlParser->getResult($langId);
		return $html;
	}
}
?>