public function index($args) { $render = new Render(); $render->add('path', $args['path']); $render->add('fullPath', $args['fullPath']); $render->add('args', $args['args']); switch (true) { case count($args['args']) == 0: case $args['args'][0] == 'pages': case $args['args'][0] == 'page': $render->view('index'); break; default: $render->view('404', true, true, "HTTP/1.0 404 Not Found"); break; } }
public function open($pagina) { if ($this->allowCrossDomain) { header('Access-Control-Allow-Origin: *'); } if ($this->onlyJson && $_SERVER["HTTP_ACCEPT"] && strpos($_SERVER["HTTP_ACCEPT"], "application/json") === false) { return false; } if ($this->onlyLocal && strpos($_SERVER['HTTP_REFERER'], getenv('HTTP_HOST')) === false) { return false; } $retorno = 200; $pagina = substr($pagina, -1) == "/" ? substr($pagina, 0, -1) : $pagina; $pedacos = explode("/", $pagina); $arg = array(); $index = $pagina; while (count($pedacos) >= 0) { if (count($pedacos) == 0 || isset($this->controller[$index]) && in_array($this->controller[$index], $this->controller)) { break; } else { $arg[] = array_pop($pedacos); $index = join("/", $pedacos); } } if (count($arg) == 0) { } $index = $index == "" ? 'index' : $index; $args = array('fullPath' => $pagina, 'path' => $index, 'args' => count($arg) > 0 && $arg[0] !== "" ? array_reverse($arg) : array()); if (!is_null($this->controller[$index]) && $index !== "") { if (file_exists($this->controller[$index]['caminho'])) { include $this->controller[$index]['caminho']; $className = $this->controller[$index]['controle']; if (class_exists($className)) { $objController = new $className(); // roda a funcao init da classe $action = $this->controller[$index]['action']; $retorno = $objController->run($action, $args); // roda a funcao run //return true; } else { $retorno = 404; //echo "Erro ao ativar o controller: ".$className."<br>"; //return false; } } else { $retorno = 404; } } else { $retorno = 404; } if ($retorno) { if (Render::templateExists($retorno)) { if (is_numeric($retorno)) { } $render = new Render(); $render->add('args', $args); $render->view($retorno); return true; } else { http_response_code($retorno); return false; } } else { return true; } }