148 lines
4.2 KiB
PHP
148 lines
4.2 KiB
PHP
|
|
<?php
|
||
|
|
require_once($_SERVER['DOCUMENT_ROOT'] . '/rss/php/autoload.php');
|
||
|
|
use Vor\core\Sys;
|
||
|
|
use Vor\application\Users;
|
||
|
|
|
||
|
|
// Set up class map
|
||
|
|
$classList = array(
|
||
|
|
'Sys' => Sys::class,
|
||
|
|
'Users' => Users::class
|
||
|
|
);
|
||
|
|
|
||
|
|
|
||
|
|
$page = getPage();
|
||
|
|
$res = array();
|
||
|
|
$userConfigs = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/rss/json/config/groups.json'), true);
|
||
|
|
|
||
|
|
if(isset($page['init']) && !empty($page['init'])){
|
||
|
|
foreach($page['init'] as $func){
|
||
|
|
$res[$func['return']] = initCaller($func);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
// Create init function based on json files
|
||
|
|
if($page){
|
||
|
|
if(!isset($_GET['page'])){
|
||
|
|
$usr = new Users();
|
||
|
|
$sys = new Sys();
|
||
|
|
$myInfo = $usr->getMyself();
|
||
|
|
if($usr->isAuth()){
|
||
|
|
header('location: /'. $sys::getUserConfigs()[$myInfo['user_type']]['home'].'/');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function getPage(){
|
||
|
|
$sys = new Sys();
|
||
|
|
$user = new Users();
|
||
|
|
global $myInfo;
|
||
|
|
if(isset($_GET['page']) && !empty($_GET['page'])){
|
||
|
|
if($conf = pages($_GET['page'])){
|
||
|
|
if(validatePage($conf)){
|
||
|
|
return $conf;
|
||
|
|
}else{
|
||
|
|
$usr = new Users();
|
||
|
|
if($usr->isAuth()){
|
||
|
|
if(file_exists($_SERVER['DOCUMENT_ROOT'] . '/rss/json/pages/'.$sys::getUserConfigs()[$myInfo['user_type']]['home'].'.json')){
|
||
|
|
header('location: /'.$sys::getUserConfigs()[$myInfo['user_type']]['home'].'/');
|
||
|
|
}else{
|
||
|
|
header('location: /');
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
header('location: /');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
header('location: /404/');
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
return pages('index');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function pages($p){
|
||
|
|
if(file_exists($_SERVER['DOCUMENT_ROOT'] . '/rss/json/pages/' . $p . '.json')){
|
||
|
|
return(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . '/rss/json/pages/' . $p . '.json'), true));
|
||
|
|
}else{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function validatePage($c){
|
||
|
|
if($c['rules']['restricted'] === true){
|
||
|
|
if($c['rules']['loginCookie'] == true){
|
||
|
|
$usr = new Users();
|
||
|
|
if($usr->isAuth()){
|
||
|
|
$ui = $usr->getMyself();
|
||
|
|
$allowed_user_types = $c['rules']['userTypes'];
|
||
|
|
$allowed_user_groups = $c['rules']['userGroups'];
|
||
|
|
|
||
|
|
if(in_array($ui['user_type'], $allowed_user_groups) || in_array('*', $allowed_user_groups)){
|
||
|
|
return true;
|
||
|
|
}else{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}else{
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function loadModals(){
|
||
|
|
global $page;
|
||
|
|
global $res;
|
||
|
|
if(isset($page['modals']) && !empty($page['modals'])){
|
||
|
|
foreach($page['modals'] as $modal){
|
||
|
|
if(file_exists($_SERVER['DOCUMENT_ROOT'] . '/rss/php/models/components/modals/' . $modal . '.php')){
|
||
|
|
include($_SERVER['DOCUMENT_ROOT'] . '/rss/php/models/components/modals/' . $modal . '.php');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function getCanonical(){
|
||
|
|
$scheme = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') ? "https" : "http";
|
||
|
|
$host = $_SERVER['HTTP_HOST'];
|
||
|
|
$requestUri = $_SERVER['REQUEST_URI'];
|
||
|
|
$canonicalUrl = $scheme . "://" . $host . $requestUri;
|
||
|
|
return $canonicalUrl;
|
||
|
|
}
|
||
|
|
|
||
|
|
function loadScripts(){
|
||
|
|
if(isset($_GET['page']) && !empty($_GET['page'])){
|
||
|
|
$page_name = $_GET['page'];
|
||
|
|
}else{
|
||
|
|
$page_name = 'index';
|
||
|
|
}
|
||
|
|
if(file_exists($_SERVER['DOCUMENT_ROOT'] . '/rss/js/' . $page_name . '.js')){
|
||
|
|
echo '<script src="/rss/js/'.$page_name.'.js"></script>';
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function initCaller($func){
|
||
|
|
global $classList;
|
||
|
|
$class = $func['class'];
|
||
|
|
$method = $func['function'];
|
||
|
|
$cl = new $classList[$class];
|
||
|
|
|
||
|
|
// Set get parameters
|
||
|
|
$run = true;
|
||
|
|
if(isset($func['getValues']) && !empty($func['getValues'])){
|
||
|
|
$run = false;
|
||
|
|
foreach($func['getValues'] as $get){
|
||
|
|
if(isset($_GET[$get]) && !empty($_GET[$get])){
|
||
|
|
$run = true;
|
||
|
|
$cl->$get = $_GET[$get];
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
if($run){
|
||
|
|
$rs = $cl->$method();
|
||
|
|
return $rs;
|
||
|
|
}
|
||
|
|
}
|