<?php
/*
* [ Author: Sir Akaya ]
* [ Version: 1.0 ]
* [ Copyright: (c) 2015, Sir Akaya ]
*/
namespace System\Controllers;
use System\Controllers\PageController;
class RouteController extends BaseController
{
private $view;
private $model;
private $route;
public function __construct($config)
{
parent::__construct($config);
if(isset($_GET['page'])) {
$this->route = $this->getFilter()->url($_GET['page']);
$this->route = explode('/', rtrim($this->route, '/'));
} else {
$this->route = null;
}
if(isset($this->route[0]) && !empty($this->route[0])) {
if(file_exists($this->getConfig()['app']['root'] . '/System/Views/' . $this->getConfig()['site']['theme'] . '/' . ucfirst($this->route[0]) . '.php')) {
$this->view = $this->route[0];
$this->model = $this->route[0] . 'Model';
} else {
$this->view = 'Error';
$this->model = 'ErrorModel';
}
} else {
$this->view = 'Index';
$this->model = 'IndexModel';
}
$this->getLog()->Logged(ucfirst($this->view), 'kite.log');
new PageController($this->getConfig(), ucfirst($this->view), ucfirst($this->model));
}
public function __destruct()
{
$this->view = null;
$this->model = null;
$this->route = null;
}
}
?>
Alles anzeigen
<?php
/*
* [ Author: Sir Akaya ]
* [ Version: 1.0 ]
* [ Copyright: (c) 2015, Sir Akaya ]
*/
namespace System\Controllers;
class PageController extends BaseController
{
private $view;
private $model;
private $object;
private $language;
public function __construct($config, $view, $model)
{
parent::__construct($config);
$this->view = $view;
$this->model = $model;
$this->object = $this->getModel();
$this->language = $this->getLanguage();
$this->getOutput();
}
public function getModel()
{
if(file_exists($this->getConfig()['app']['root'] . '/System/Models/' . $this->model . '.php')) {
$this->object = 'System\Models\\' . $this->model;
$this->object = new $this->object($this->getConfig());
return $this->object;
}
}
public function getLanguage()
{
if(file_exists($this->getConfig()['app']['root'] . '/App/Langs/' . $this->getConfig()['site']['language'] . '.json')) {
$this->language = json_decode(file_get_contents($this->getConfig()['app']['root'] . '/App/Langs/' . $this->getConfig()['site']['language'] . '.json'), true);
$this->language = str_replace(['{site_url}', '{site_name}'], [$this->getConfig()['site']['url'], $this->getConfig()['site']['name']], $this->language);
return $this->language;
} else {
die('Language file not found.');
exit;
}
}
public function getOutput()
{
ob_start();
if(file_exists($this->getConfig()['app']['root'] . '/System/Views/' . $this->getConfig()['site']['theme'] . '/' . $this->view . '.php')) {
require_once $this->getConfig()['app']['root'] . '/System/Views/' . $this->getConfig()['site']['theme'] . '/' . $this->view . '.php';
}
$output = ob_get_contents();
foreach($this->language as $key => $value) {
$output = str_replace('{lang.' . $key . '}', $value, $output);
}
ob_end_clean();
echo $output;
}
public function __destruct()
{
$this->view = null;
$this->model = null;
$this->object = null;
$this->language = null;
}
}
?>
Alles anzeigen
<?php
/*
* [ Author: Sir Akaya ]
* [ Version: 1.0 ]
* [ Copyright: (c) 2015, Sir Akaya ]
*/
namespace System\Librarys;
use System\App;
class Log extends App
{
public function __construct($config)
{
parent::__construct($config);
}
public function ClearLogs()
{
$files = glob($this->getConfig()['app']['root'] . '/System/Storage/Logs/*');
foreach($files as $file) {
if(time() - filemtime($file) >= 86400) {
unlink($file);
fopen($file, 'w');
}
}
}
public function Logged($log, $file)
{
if($this->getConfig()['logs']['clear'] === true) {
$this->ClearLogs();
}
if(file_exists($this->getConfig()['app']['root'] . '/System/Storage/Logs/' . $file)) {
$logged = '[' . date('d/m/y - H:i:s') . '] ' . $this->getUser()->getUserIp() . ' [**] GET /System/Views/' . $this->getConfig()['site']['theme'] . '/' . $log . '.php' . "\n";
file_put_contents($this->getConfig()['app']['root'] . '/System/Storage/Logs/' . $file, $logged, FILE_APPEND | LOCK_EX);
}
}
}
?>
Alles anzeigen