<?php
/**
 * class template
 *
 * Description for class template
 *
 * @author:
*/
namespace core;

use Smarty;
use core\response;

class template {
	private $smarty = null;

	public function __construct() {
		global $__config;

		$theme = $__config["general"]["theme"];

		$this->smarty = new Smarty();
		$this->smarty->debugging = false;
		$this->smarty->error_reporting = E_ALL;
		$this->smarty->setTemplateDir("theme/{$theme}/views");
		$this->smarty->setPluginsDir("_app/helper/smarty/plugin");
		$this->smarty->setCompileDir("_app/cache/smarty/compile");
		$this->smarty->setCacheDir("_app/cache/smarty/cache");
	}

	public function setTemplateDir($path) {
		$this->smarty->setTemplateDir($path);
	}

	public function setVariable($key, $value) {
		$this->smarty->assign($key, $value);
	}

	public function show($layout, $component) {
		$this->smarty->display("extends:{$layout}|{$component}");
	}

	public function render($layout, $component) {
		return $this->smarty->fetch("extends:{$layout}|{$component}");
	}

	public function slide_render($theme) {
		global $__routing;
		
		if(isset($__routing[0][2])) {
			return $this->smarty->fetch("../../../../".$theme);
		}

		return $this->smarty->fetch("../../../".$theme);
	}

	public function error() {
		
	}

	public function getCaptures() {
		$Captures = (array)$this->smarty->ext->_capture;

		//help: https://coderwall.com/p/36h6qa/converting-php-objects-to-arrays-to-read-private-members
		return $Captures["\0Smarty_Internal_Runtime_Capture\0namedBuffer"];
	}
}
?>