<?php
/*
* @ServerMon v1.1
* @Developed by Maksa988
* @www.Server-Mon.ru
* @Copyright (C) 2014
*/
 if(!defined('SMON'))
	die('Hacking attempt!');
	
class Load extends Request {
	public function viewLoad($name, $vars = array()){
		global $config, $action;
		$path = explode("/", $action);
		if($path[0] == 'admin'){
			$file = THEME_DIR . 'admin/' . $name . '.php';
		} else {
			$file = THEME_DIR . $this->setting('theme').'/' . $name . '.php';
		}
		if(is_readable($file)){
			extract($vars);
	  		$content = include($file);
			
	  		return $content;
		}
		exit('Ошибка: Не удалось загрузить шаблон ' . $name . '!');
	}
	
	public function view($view = array(), $vars = array()) {
		foreach($view as $item) {
			$this->viewLoad($item, $vars);
		}
	}
	
	public function model($name){
		$modelClass = $name . 'Model';
		$modelPath = APPLICATION_DIR . 'models/' . $name . '.php';
		
		if(is_readable($modelPath)){
			require_once($modelPath);
			if(class_exists($modelClass)){
				$this->$modelClass = new $modelClass($this->registry);
				return true;
			}
		}
		exit('Ошибка: Не удалось загрузить модель ' . $name . '!');
	}
}