class AttusSite extends AttusBase {
private $_modelName;
private $_actionName;
private $_action;
private $_controller;
public function __construct()
{
parent::__construct();
$this->_startTime = microtime(true);
}
public function output()
{
$this->_loadSite();
$layout = new AttusTheme;
$layout->set("layout");
$layouthtml = $layout->output();
$header = file_get_contents("./library/defaults/view/header.phtml");
/*$header = new AttusTheme;
$header->set("header");
$layouthtml = str_replace("", $header->output(), $layouthtml);*/
$layouthtml = str_replace("", $header, $layouthtml);
$this->_checkForm();
$methodname = $this->_actionName . "Action";
if (!method_exists($this->_controller, $methodname)) {
$this->_exception("Controller Method %s::%s does not exist", Array("Controller_" . $this->_modelName, $methodname));
}
$this->_controller->$methodname();
header ("Content-Type: text/html; charset=UTF-8");
session_start();
$view = new AttusTheme;
$view->set($this->_controller->getView());
$html = str_replace("*****CONTENT*****", $view->output(), $layouthtml);
echo $html;
}
private function _loadSite()
{
if (!$this->_isInstalled()) {
$this->_install();
}
if ($this->_request("model")) {
$this->_modelName = ucfirst(strtolower($this->_request("model")));
}
else {
$this->_modelName = "Index";
}
if ($this->_request("action")) {
$this->_actionName = $this->_request("action");
}
else {
$this->_actionName = "index";
}
if (!$this->_checkAccess()) {
$this->_modelName = "Content_User";
$this->_actionName = "login";
}
$this->_store("username", $this->_stored("username"));
$this->_store("password", $this->_stored("password"));
$modelname = "Model_" . $this->_modelName;
$classname = "Controller_" . $this->_modelName;
$this->_controller = new $classname($modelname);
return "";
}
public function getModelName()
{
return $this->_modelName;
}
public function theme_preprocess()
{
if (isset($this->_controller)) {
$variables = $this->_controller->theme_preprocess();
}
else {
//echo "\n
NOT ISSET CONTROLLER";
}
$variables["language"] = $this->_language;
$variables["header_user_rendered"] = $this->_getUser()->getRendered();
return $variables;
}
private function _isInstalled()
{
return $this->_getDataBase()->checkInstall();
}
private function _install()
{
$installfile[] = "./application/settings/install.php";
$installfile[] = "./library/defaults/settings/install.php";
foreach($installfile as $install) {
if (is_file($install)) {
include($install);
}
}
$this->_getDataBase()->create($tables);
foreach($data as $table => $record) {
$qInsert = new AttusQuery;
$qInsert->setTable($table);
$qInsert->insert(Array("data" => $record));
}
}
private function _checkAccess()
{
if ($this->_getUser()->isMemberOf("admins")) {
return TRUE;
}
if (is_array($this->_access)) {
$modeldefined = false;
$actiondefined = false;
$modelenabled = false;
$actionenabled = false;
foreach ($this->_access as $rule) {
if (strtolower($rule[1]) == strtolower($this->_modelName)) {
$modeldefined = true;
}
if (strtolower($rule[1]) == strtolower($this->_modelName)
&& strtolower($rule[2]) == strtolower($this->_actionName)) {
$actiondefined = true;
}
if (strtolower($rule[1]) == strtolower($this->_modelName)
&& $this->_getUser()->isMemberOf($rule[0])) {
$modelenabled = true;
}
if (strtolower($rule[1]) == strtolower($this->_modelName)
&& strtolower($rule[2]) == strtolower($this->_actionName)
&& $this->_getUser()->isMemberOf($rule[0])) {
$actionenabled = true;
}
}
if (!$modeldefined) {
$modelenabled = TRUE;
}
if (!$actiondefined) {
$actionenabled = TRUE;
}
if ($modelenabled && $actionenabled) {
return TRUE;
}
}
else {
return TRUE;
}
return FALSE;
}
private function _checkForm()
{
if ($this->_request("formcheckid")) {
if ($this->_request("formcheckid") != $this->_stored("formcheckid_" . $this->_request("formuniqueid"))) {
$this->_exception("Illegal data posting");
exit();
}
$this->_unStore("formcheckid_" . $this->_request("formuniqueid"));
if ($this->_request("username") && $this->_request("password")) {
$this->_store("username", $this->_request("username"));
$this->_store("password", $this->_request("password"));
header("Location: " . $_SERVER["PHP_SELF"]);
}
}
}
}