6 Commits

Author SHA1 Message Date
GamerClassN7
0045bdeb84 Google API change Fix 2021-04-11 10:40:32 +02:00
GamerClassN7
9c565d90fa Minor Bug Fixes 2021-04-05 20:02:11 +02:00
GamerClassN7
f80b9a6b43 Fix 2021-04-05 10:46:27 +02:00
GamerClassN7
49f2354908 Empty log file Fix 2021-04-05 10:46:16 +02:00
GamerClassN7
541ea0002f Simple Home (Google Oauth 2.0) Flow type - code 2021-04-05 10:43:30 +02:00
GamerClassN7
135dfcb666 Settings Page Fix 2021-03-01 17:41:43 +01:00
18 changed files with 279 additions and 76 deletions

View File

@@ -18,5 +18,6 @@ RewriteRule (.*) ./public/$1 [L]
# serve all other request as query parameters
RewriteRule (.*) ./public/index.php?url=$1 [L,QSA]
#RewriteRule ^(.*?\.php)/([^/]*)/([^/]*)(/.+)? ./public/index.php?url=$1&$2&$3 [NC,N,QSA]
AddType application/x-httpd-php .php .phtml

View File

@@ -3,6 +3,8 @@
error_reporting(E_ALL);
ini_set( 'display_errors','1');
//setup
parse_str($_SERVER['QUERY_STRING'], $params);
if (defined ("BASEDIR")) {

View File

@@ -10,6 +10,7 @@ $router->setDefault(function(){
unset($logManager);
});
//Pages
$router->any('/', 'Log');
$router->any('/log', 'Log');
@@ -46,6 +47,7 @@ $router->get('/api/server/log', 'ServerApi@logStatus');
$router->post('/api/widgets/{widgetId}/run', 'WidgetApi@run');
$router->get('/api/widgets/{widgetId}/detail', 'WidgetApi@detail');
$router->get('/api/widgets/{widgetId}/detail/{period}', 'WidgetApi@detail');
$router->post('/api/widgets/{widgetId}/edit', 'WidgetApi@edit');
//Vue APP - Automations Endpoints
$router->get('/api/automations', 'AutomationsApi@default');
@@ -61,8 +63,10 @@ $router->post('/cron/automations', 'CronApi@automations');
//Google Home - API
$router->any('/api/HA/auth', 'Oauth');
$router->any('/api/HA/auth', 'Oauth@default');
$router->any('/api/HA/token', 'Oauth@token');
$router->any('/api/HA', 'GoogleHomeApi@response');
$router->any('/api/HA/', 'GoogleHomeApi@response');
//Endpoints API
@@ -71,6 +75,9 @@ $router->any('/api/update/', 'UpdatesApi@default');
$router->any('/api/users/status', 'UsersApi@status');
$router->any('/api/users/subscribe', 'UsersApi@subscribe');
//Endpoints API - V2
$router->post('/api/v2/endpoint/', 'EndpointsApi@default_v2');
$router->post('/api/v2/endpoint/cofiguration', 'EndpointsApi@cofiguration_v2');
// examples
$router->any('/api/example', 'ExampleApi@example');

View File

@@ -1,6 +1,8 @@
<?php
class EndpointsApi extends ApiController{
public function default(){
class EndpointsApi extends ApiController
{
public function default()
{
// $this->requireAuth();
$obj = $this->input;
@@ -8,7 +10,7 @@ class EndpointsApi extends ApiController{
$command = "null";
//Log
$logManager = new LogManager('../logs/api/'. date("Y-m-d").'.log');
$logManager = new LogManager('../logs/api/' . date("Y-m-d") . '.log');
$logManager->setLevel(LOGLEVEL);
//Token Checks
@@ -65,7 +67,7 @@ class EndpointsApi extends ApiController{
DeviceManager::setHeartbeat($device['device_id']);
//Diagnostic
if (isset($obj['settings'])){
if (isset($obj['settings'])) {
$data = ['mac' => $obj['settings']["network"]["mac"], 'ip_address' => $obj['settings']["network"]["ip"]];
if (array_key_exists("firmware_hash", $obj['settings'])) {
$data['firmware_hash'] = $obj['settings']["firmware_hash"];
@@ -74,11 +76,11 @@ class EndpointsApi extends ApiController{
}
//Log Data Save
if (isset($obj['logs'])){
if (isset($obj['logs'])) {
foreach ($obj['logs'] as $log) {
$deviceLogManager = new LogManager('../logs/devices/'. date("Y-m-d").'.log');
$deviceLogManager = new LogManager('../logs/devices/' . date("Y-m-d") . '.log');
$deviceLogManager->setLevel(LOGLEVEL);
if ($log != 'HTTP_UPDATE_FAILD code-102 messageFile Not Found (404)'){
if ($log != 'HTTP_UPDATE_FAILD code-102 messageFile Not Found (404)') {
$deviceLogManager->write("[Device Log Msg] Device_ID " . $device['device_id'] . "->" . $log, LogRecordTypes::ERROR);
}
unset($deviceLogManager);
@@ -91,13 +93,12 @@ class EndpointsApi extends ApiController{
}
// Issuing command
if ($command == "null"){
if ($command == "null") {
$deviceCommand = $device["command"];
if ($deviceCommand != '' && $deviceCommand != null && $deviceCommand != "null")
{
if ($deviceCommand != '' && $deviceCommand != null && $deviceCommand != "null") {
$command = $deviceCommand;
$data = [
'command'=>'null'
'command' => 'null'
];
DeviceManager::editByToken($obj['token'], $data);
$logManager->write("[API] Device_ID " . $device['device_id'] . " executing command " . $command, LogRecordTypes::INFO);
@@ -115,7 +116,7 @@ class EndpointsApi extends ApiController{
}
$subDeviceLastReordValue[$key] = $value['value'];
RecordManager::create($device['device_id'], $key, round($value['value'],3), 'device');
RecordManager::create($device['device_id'], $key, round($value['value'], 3), 'device');
$logManager->write("[API] Device_ID " . $device['device_id'] . " writed value " . $key . ' ' . $value['value'], LogRecordTypes::INFO);
//notification
@@ -127,20 +128,20 @@ class EndpointsApi extends ApiController{
case 'door':
$notificationData = [
'title' => 'Info',
'body' => 'Someone just open up '.$device['name'],
'body' => 'Someone just open up ' . $device['name'],
'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
];
break;
break;
case 'water':
$notificationData = [
'title' => 'Alert',
'body' => 'Wather leak detected by '.$device['name'],
'body' => 'Wather leak detected by ' . $device['name'],
'icon' => BASEDIR . '/app/templates/images/icon-192x192.png',
];
break;
break;
}
if (DEBUGMOD) $notificationData['body'] .= ' value='.$value['value'];
if (DEBUGMOD) $notificationData['body'] .= ' value=' . $value['value'];
if ($notificationData != []) {
$subscribers = $notificationMng::getSubscription();
foreach ($subscribers as $key => $subscriber) {
@@ -169,9 +170,9 @@ class EndpointsApi extends ApiController{
foreach ($subDevicesData as $key => $subDeviceData) {
$subDeviceId = $subDeviceData['subdevice_id'];
$subDeviceLastReord = RecordManager::getLastRecord($subDeviceId);
if (!empty ($subDeviceLastReord)) {
if (!empty($subDeviceLastReord)) {
$subDeviceLastReordValue[$subDeviceData['type']] = $subDeviceLastReord['value'];
if ($subDeviceLastReord['execuded'] == 0){
if ($subDeviceLastReord['execuded'] == 0) {
$logManager->write("[API] subDevice_ID " . $subDeviceId . " executed comand with value " . json_encode($subDeviceLastReordValue) . " executed " . $subDeviceLastReord['execuded'], LogRecordTypes::INFO);
RecordManager::setExecuted($subDeviceLastReord['record_id']);
}
@@ -193,4 +194,77 @@ class EndpointsApi extends ApiController{
//unset($logManager); //TODO: Opravit
die();
}
protected function requireAuth()
{
if (isset($_SERVER['HTTP_AUTHORIZATION'])) {
// TODO: call appropriate class/method
$deviceManager = new DeviceManager();
list($type, $hash) = explode(' ', $_SERVER['HTTP_AUTHORIZATION']);
$this->authenticated = $deviceManager->approved($hash);
return $hash;
if (!$this->authenticated) {
throw new Exception("Authorization required", 401);
}
} else {
throw new Exception("Authorization required", 401);
}
}
public function default_v2()
{
$token = $this->requireAuth();
$obj = $this->input;
$response = [];
$device = DeviceManager::getDeviceByToken($token);
DeviceManager::setHeartbeat($device['device_id']);
// Issue command
$deviceCommand = $device["command"];
if ($deviceCommand != '' && $deviceCommand != null && $deviceCommand != "null") {
$response['command'] = $deviceCommand;
DeviceManager::editByToken($obj['token'], ['command' => 'null']);
}
$subDevicesData = SubDeviceManager::getAllSubDevices($device['device_id']);
if (count($subDevicesData) > 0) {
foreach ($subDevicesData as $key => $subDeviceData) {
$subDeviceId = $subDeviceData['subdevice_id'];
$subDeviceLastReord = RecordManager::getLastRecord($subDeviceId);
if (!empty($subDeviceLastReord)) {
$response['values'][$subDeviceData['type']] = $subDeviceLastReord['value'];
if ($subDeviceLastReord['execuded'] == 0) {
RecordManager::setExecuted($subDeviceLastReord['record_id']);
}
}
}
}
$this->response($response, 200);
}
public function cofiguration_v2()
{
$token = $this->requireAuth();
$response = [];
$device = DeviceManager::getDeviceByToken($token);
DeviceManager::setHeartbeat($device['device_id']);
if (!empty($device["name"]) && isset($device["name"])) $response["nettwork"]['hostname'] = $this->nameToHostname($device["name"]);
if (!empty($device["ip_address"]) && isset($device["ip_address"])) $response["nettwork"]['ip'] = $device["ip_address"];
if (!empty($device["gateway"]) && isset($device["gateway"])) $response["nettwork"]['gateway'] = $device["gateway"];
if (!empty($device["dns"]) && isset($device["dns"])) $response["nettwork"]['dns'] = $device["dns"];
if (!empty($device["sleep_time"]) && isset($device["sleep_time"])) $response["sleep"] = $device["sleep_time"];
$this->response($response, 200);
}
private function nameToHostname(string $name = null)
{
$hostname = "";
$hostname = strtolower($name);
return str_replace(' ', '_', $hostname);
}
}

View File

@@ -2,18 +2,18 @@
class RoomsApi extends ApiController
{
public function default()
{
//$this->requireAuth();
$response = [];
$roomIds = [];
$roomsData = RoomManager::getRoomsDefault();
foreach ($roomsData as $roomKey => $room) {
$roomIds[] = $room['room_id'];
}
//Translation Of Numeric Walues
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds($roomIds);
foreach ($subDevicesData as $subDeviceKey => $subDevice) {
@@ -25,14 +25,21 @@ class RoomsApi extends ApiController
} else if (strpos(SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'], '-') !== false) {
$type = SubDeviceManager::getSubDeviceMaster($subDevicesData[$subDeviceKey][$key]['subdevice_id'])['type'];
}
//Connection Error Creation
$connectionError = true;
$LastRecordTime = new DateTime($subDevicesData[$subDeviceKey][$key]['time']);
$LastRecordTime = new DateTime($subDevicesData[$subDeviceKey][$key]['heartbeat']);
$interval = $LastRecordTime->diff(new DateTime());
$lastSeen = ($interval->format('%h') * 60 + $interval->format('%i'));
if ($subDevicesData[$subDeviceKey][$key]['sleep_time'] == NULL || $subDevicesData[$subDeviceKey][$key]['sleep_time'] == 0 || $lastSeen < $subDevicesData[$subDeviceKey][$key]['sleep_time']) {
$lastSeen = $interval->days * 24 * 60;
$lastSeen += $interval->h * 60;
$lastSeen += $interval->i;
//$lastSeen = ($interval->format('%h') * 60 + $interval->format('%i'));
if ($lastSeen < ($subDevicesData[$subDeviceKey][$key]['sleep_time'] == 0 ? 15 : $subDevicesData[$subDeviceKey][$key]['sleep_time'])) {
$connectionError = false;
}
$subDevicesData[$subDeviceKey][$key]['connection_error'] = $connectionError;
@@ -50,7 +57,7 @@ class RoomsApi extends ApiController
}
}
}
foreach ($roomsData as $roomKey => $roomData) {
if ($roomData['device_count'] == 0) continue;
$subDevicesSorted = isset($subDevicesData[$roomData['room_id']]) ? Utilities::sortArrayByKey($subDevicesData[$roomData['room_id']], 'connection_error', 'asc') : [];
@@ -64,11 +71,11 @@ class RoomsApi extends ApiController
$this->response($response);
}
public function update($roomId)
{
//$this->requireAuth();
$subDevicesData = SubDeviceManager::getSubdevicesByRoomIds([$roomId]);
$this->response($subDevicesData);
}

View File

@@ -134,4 +134,30 @@ class WidgetApi extends ApiController
}
return RANGES[''];
}
public function edit($subDeviceId)
{
$this->requireAuth();
$allow = ["icon", "name"];
$response = null;
$obj = $this->input;
foreach ($obj as $key => $value) {
if (!in_array($key, $allow)){
unset($obj[$key]);
}
}
echo $subDeviceId;
echo SubDeviceManager::edit($subDeviceId, $obj);
$response = [
"value" => "OK"
];
$this->response($response);
}
}

View File

@@ -14,19 +14,33 @@ if (
$state = $_POST["state"];
$clientId = $_POST["clientId"];
$ota = $userManager->haveOtaEnabled($userName);
if ($ota == "") {
$token = (new AuthManager)->getToken($userName,$userPassword, $clientId);
if (!$token) {
throw new Exception("Auth failed", 401);
}
$get = [
"access_token"=>$token,
"token_type"=>"Bearer",
"state"=>$state,
];
header('Location: ' . $_POST["redirectUrl"] . '#' . http_build_query($get));
$get=[];
if ($_POST['response_type'] = 'code') {
$get = [
"state"=>$state,
"code"=>$token,
"state"=>$state,
];
} else {
$get = [
"access_token"=>$token,
"token_type"=>"Bearer",
"state"=>$state,
];
}
//Log
$logManager = new LogManager(__DIR__ . '/../../logs/auth/' . date("Y-m-d") . '.log');
$logManager->setLevel(LOGLEVEL);
$logManager->write("[OAUTH] Response " . $_POST["redirectUrl"] . '?' . http_build_query($get), LogRecordTypes::WARNING);
header('Location: ' . $_POST["redirectUrl"] . '?' . http_build_query($get));
die();
}

View File

@@ -1,4 +1,5 @@
<?php
https://console.cloud.google.com/logs/query;cursorTimestamp=2021-04-11T07:51:16.567357750Z?project=simple-home-79188
class GoogleHome
{
static function sync($requestId)
@@ -42,7 +43,10 @@ class GoogleHome
],
'willReportState' => false,
'roomHint' => $roomData['name']
'roomHint' => $roomData['name'],
"otherDeviceIds" => [
["deviceId" => "SH#".(string) $deviceData['device_id']]
]
];
if ($tempDevice['attributes'] == null) unset($tempDevice['attributes']);

View File

@@ -8,6 +8,7 @@
class LogManager
{
private $logFile;
private $filePath = null;
private $logLevel = 1;
public function __construct($fileName = "")
@@ -15,12 +16,13 @@ class LogManager
if ($fileName == ""){
$fileName = '../logs/'. date("Y-m-d").'.log';
}
if(!is_dir("../logs/"))
{
mkdir("../logs/");
}
$this->logFile = fopen($fileName, "a") or die("Unable to open file!");
$this->filePath = $fileName;
}
public function setLevel($type = LogRecordTypess::WARNING){
@@ -28,6 +30,10 @@ class LogManager
}
public function write($value, $type = LogRecordTypess::ERROR){
if ($this->logFile == null) {
$this->logFile = fopen($this->filePath, "a") or die("Unable to open file!");
}
if ($type['level'] <= $this->logLevel) {
$record = "[".date("H:m:s")."][".$type['identifier']."]" . $value . "\n";
fwrite($this->logFile, $record);

View File

@@ -66,6 +66,20 @@ class SubDeviceManager
}
}
public static function edit($subDeviceId, $values)
{
$record = [];
foreach ($values as $key => $value) {
$record[$key] = $value;
}
try {
Db::edit('subdevices', $record, 'WHERE subdevice_id = ?', array ($subDeviceId));
} catch (PDOException $error) {
echo $error->getMessage();
die();
}
}
public static function remove($subDeviceId)
{
RecordManager::cleanSubdeviceRecords($subDeviceId);
@@ -78,7 +92,7 @@ class SubDeviceManager
//TODO: @Patrik Check line 89
$rows = Db::loadAll("
SELECT d.room_id, d.sleep_time, sd.subdevice_id, sd.device_id, d.icon, d.name, sd.type, sd.unit, r.value, r.time FROM subdevices sd
SELECT d.room_id, d.sleep_time, d.heartbeat, sd.subdevice_id, sd.device_id, COALESCE(sd.icon, d.icon) AS icon, COALESCE(sd.name, d.name) AS name, sd.type, sd.unit, r.value, r.time FROM subdevices sd
JOIN devices d ON sd.device_id = d.device_id
JOIN records r ON r.subdevice_id = sd.subdevice_id
WHERE d.room_id IN (" . str_repeat("?,", count($roomIds) - 1) . "?)

View File

@@ -1,5 +1,6 @@
<?php
class GoogleHomeDeviceTypes {
class GoogleHomeDeviceTypes
{
/*const AirConditioningUnit = 'action.devices.types.AC_UNIT';
const AirFreshener = 'action.devices.types.AIRFRESHENER';
const AirPurifier = 'action.devices.types.AIRPURIFIER';
@@ -107,7 +108,7 @@ class GoogleHomeDeviceTypes {
'commandOnlyOnOff' => false,
],
'temp_cont' => [
'availableThermostatModes' => 'off,heat',
'availableThermostatModes' => ['off', 'heat'],
'thermostatTemperatureUnit' => 'C',
],
'vol_cont' => [
@@ -117,7 +118,7 @@ class GoogleHomeDeviceTypes {
'levelStepSize' => 2,
'commandOnlyVolume' => false,
],
'media_cont'=> [
'media_cont' => [
'transportControlSupportedCommands' => [
"NEXT",
"PREVIOUS",
@@ -127,7 +128,7 @@ class GoogleHomeDeviceTypes {
"CAPTION_CONTROL"
],
],
'media_status'=> [
'media_status' => [
'supportActivityState' => true,
'supportPlaybackState' => true,
],
@@ -159,27 +160,32 @@ class GoogleHomeDeviceTypes {
],
];
static function getAction($deviceType){
static function getAction($deviceType)
{
if (!isset(self::$actionWordBook[$deviceType])) return;
return self::$actionWordBook[$deviceType];
}
static function getTraid($subDeviceType){
static function getTraid($subDeviceType)
{
if (!isset(self::$traidWordBook[$subDeviceType])) return;
return self::$traidWordBook[$subDeviceType];
}
static function getType($subDeviceCommand){
static function getType($subDeviceCommand)
{
if (!isset(self::$commandWordBook[$subDeviceCommand])) return;
return self::$commandWordBook[$subDeviceCommand];
}
static function getAttribute($subDeviceType){
static function getAttribute($subDeviceType)
{
if (!isset(self::$attributeWordBook[$subDeviceType])) return;
return self::$attributeWordBook[$subDeviceType];
}
static function getQueryJson($deviceType, $type){
static function getQueryJson($deviceType, $type)
{
return self::$wordBook[$type];
}
}

View File

@@ -1,9 +1,19 @@
<?php
class Oauth extends Template
//https://developers.google.com/oauthplayground/
//https://developer.okta.com/blog/2018/04/10/oauth-authorization-code-grant-type
class Oauth
{
function __construct()
function default()
{
$userManager = new UserManager ();
//Log
$logManager = new LogManager(__DIR__ . '/../../logs/auth/' . date("Y-m-d") . '.log');
$logManager->setLevel(LOGLEVEL);
$logManager->write("[OAUTH] GET " . json_encode($_GET), LogRecordTypes::WARNING);
$logManager->write("[OAUTH] DATA " . file_get_contents('php://input'), LogRecordTypes::WARNING);
$logManager->write("[OAUTH] URL " . $_SERVER['REQUEST_URI'], LogRecordTypes::WARNING);
$userManager = new UserManager();
$langMng = new LanguageManager('en');
$template = new Template('oauth');
@@ -11,18 +21,56 @@ class Oauth extends Template
$template->prepare('baseUrl', BASEURL);
$template->prepare('title', 'Simple Home - Oauth');
if (isset($_GET['redirect_uri'])) {
if (isset($_GET['response_type']) && $_GET['response_type'] == 'code') {
$template->prepare('responseType', $_GET['response_type']);
$template->prepare('redirectUrl', $_GET['redirect_uri']);
$template->prepare('clientId', $_GET['client_id']);
$template->prepare('scope', $_GET['scope']);
$template->prepare('state', $_GET['state']);
} else {
$template->prepare('responseType', $_POST['responseType']);
$template->prepare('redirectUrl', $_POST['redirectUrl']);
$template->prepare('clientId', $_POST['clientId']);
$template->prepare('state', $_POST['state']);
if (isset($_GET['redirect_uri'])) {
$template->prepare('responseType', $_GET['response_type']);
$template->prepare('redirectUrl', $_GET['redirect_uri']);
$template->prepare('clientId', $_GET['client_id']);
$template->prepare('state', $_GET['state']);
} else {
$template->prepare('responseType', $_POST['responseType']);
$template->prepare('redirectUrl', $_POST['redirectUrl']);
$template->prepare('clientId', $_POST['clientId']);
$template->prepare('state', $_POST['state']);
}
}
$template->render();
}
function token()
{
//Log
$logManager = new LogManager(__DIR__ . '/../../logs/auth/' . date("Y-m-d") . '.log');
$logManager->setLevel(LOGLEVEL);
$logManager->write("[OAUTH] GET " . json_encode($_GET), LogRecordTypes::WARNING);
$logManager->write("[OAUTH] POST " . json_encode($_POST), LogRecordTypes::WARNING);
$logManager->write("[OAUTH] DATA " . file_get_contents('php://input'), LogRecordTypes::WARNING);
$logManager->write("[OAUTH] URL " . $_SERVER['REQUEST_URI'], LogRecordTypes::WARNING);
// $template = new Template('oauth');
// $template->prepare('baseDir', BASEDIR);
// $template->prepare('baseUrl', BASEURL);
// $template->prepare('title', 'Simple Home - Oauth');
// $template->render();
$token = $_POST["code"];
$get = [
"access_token" => $token,
"token_type" => "Bearer",
"refresh_token" => $token,
"scope" => 'user',
//"expires_in" => 63113851,
];
$logManager->write("[OAUTH] Response " . json_encode($get), LogRecordTypes::WARNING);
echo json_encode($get);
die();
}
}

View File

@@ -10,24 +10,12 @@ class Setting extends Template
header('Location: ' . BASEURL . 'login');
}
$automations = [];
$automationsData = AutomationManager::getAll();
foreach ($automationsData as $automationKey => $automationData) {
$automations[$automationData['automation_id']] = [
'name' => '',
'onDays' => $automationData['on_days'],
'ifSomething' => $automationData['if_something'],
'doSomething' => $automationData['do_something'],
];
}
$template = new Template('setting');
$template->prepare('baseDir', BASEDIR);
$template->prepare('baseUrl', BASEURL);
$template->prepare('debugMod', DEBUGMOD);
$template->prepare('title', 'Automation');
$template->prepare('title', 'Settings');
$template->prepare('langMng', $langMng);
$template->prepare('automations', $automations);
$users = $userManager->getUsers();
foreach ($users as $key => $value) {

View File

@@ -4,6 +4,7 @@
<?php
$partial = new Partial('head');
$partial->prepare('baseDir',$BASEDIR);
$partial->prepare('baseUrl',$BASEURL);
$partial->render();
?>
<title><?php echo $TITLE ?></title>

View File

@@ -7,10 +7,12 @@ class Template{
function __construct($path = "", $debug = false) {
$this->debug = $debug;
if (!empty('../app/views/templates/' . $path . '.phtml') && file_exists('../app/views/templates/' . $path . '.phtml')) {
if (!empty(__DIR__ . '/../app/views/templates/' . $path . '.phtml') && file_exists(__DIR__ . '/../app/views/templates/' . $path . '.phtml')) {
$this->path = $path;
} else {
echo '<pre>';
echo __DIR__ . '/../app/views/templates/' . $path . '.phtml</br>';
echo 'PHTML: Template File ' . $path . ' not found';
echo '</pre>';
die();
@@ -26,9 +28,9 @@ class Template{
function render() {
extract($this->assignedValues);
if (!empty('../app/controllers/' . $this->path . 'Controller.php') && file_exists('../app/controllers/' . $this->path . 'Controller.php')) {
include('../app/controllers/' . $this->path . 'Controller.php');
if (!empty(__DIR__ . '/../app/controllers/' . $this->path . 'Controller.php') && file_exists(__DIR__ . '/../app/controllers/' . $this->path . 'Controller.php')) {
include(__DIR__ . '/../app/controllers/' . $this->path . 'Controller.php');
}
require_once('../app/views/templates/' . $this->path . '.phtml');
require_once(__DIR__ . '/../app/views/templates/' . $this->path . '.phtml');
}
}

View File

@@ -5,7 +5,7 @@ RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !.css
RewriteCond %{REQUEST_FILENAME} !.js
RewriteRule (.*) ./index.php?url=$1#$2 [QSA,L]
RewriteRule (.*) ./index.php?url=$1 [QSA,L]
#token to HTTP_AUTHORIZATION
RewriteCond %{HTTP:Authorization} ^(.*)

View File

@@ -1,3 +1,4 @@
<?php
require_once __DIR__ . '/../app/Bootstrap.php';

2
test.php Normal file
View File

@@ -0,0 +1,2 @@
<?php
echo $_GET;