Mowie/index.php

120 lines
3.3 KiB
PHP
Raw Normal View History

2016-08-02 21:13:25 +00:00
<?php
2016-08-02 21:13:25 +00:00
//Check if installed
2017-05-08 09:43:02 +00:00
if (file_exists('config/config.yml'))
2016-08-02 21:13:25 +00:00
{
//Require Libs
2017-10-04 18:46:49 +00:00
require_once 'vendor/autoload.php';
2016-08-02 21:13:25 +00:00
require_once 'inc/config.php';
require_once 'inc/libs/functions.php';
require_once 'inc/page.php';
require_once 'inc/apps.php';
2016-08-02 21:13:25 +00:00
//Under Construction?
if (file_exists('content/.system/construction.txt'))
2016-08-02 21:13:25 +00:00
{
echo file_get_contents('content/.system/construction.txt');
} else
2016-08-02 21:13:25 +00:00
{
//Page
$page = new page();
$page->caching = false;
$page->error_reporting = E_ALL & ~E_NOTICE;
2016-08-02 21:13:25 +00:00
//Set Url
2017-10-08 12:06:09 +00:00
$url = str_replace_first($MCONF['home_uri'], '', $_SERVER['REQUEST_URI']);
$page->setUrl($url);
$base = explode('/', $url);
2016-08-02 21:13:25 +00:00
$page->setBaseUrl('/');
if (count($base) > 1)
2016-08-02 21:13:25 +00:00
{
$page->setBaseUrl($base[0] . '/');
2016-08-02 21:13:25 +00:00
}
$page->setResponseCode(404);
$apps = new apps();
2016-08-02 21:13:25 +00:00
//Search apps and execute them if necessary
foreach ($apps->getApps() as $app => $appconf)
2016-08-02 21:13:25 +00:00
{
2017-05-07 19:48:33 +00:00
$appUri = 'apps/' . $appconf['app_path'] . '/';
//Check App dependencies
if($apps->checkDependencies($appconf['app_name']))
{
//If the App should run from one domain only
if ((isset($appconf['domain']) && $page->getDomain() == $appconf['domain']) || !isset($appconf['domain']) || (isset($appconf['domain']) && $appconf['domain'] === ''))
{
//If we have an alias which equals the current url, execute it
if (isset($appconf['alias']))
{
if (array_key_exists($page->getUrl(), $appconf['alias']))
{
require $appUri . $appconf['alias'][$page->getUrl()];
}
}
//If we have a type
if (isset($appconf['type']))
2016-08-02 21:13:25 +00:00
{
//Page for (more or less) dynamic content
if ($appconf['type'] == 'page')
2016-08-02 21:13:25 +00:00
{
//If we have a base_url_file and the current url equals base_url, execute base_url_file
if (isset($appconf['base_url_file']))
{
if ($appconf['base_url'] == $page->getUrl())
{
require $appUri . $appconf['base_url_file'];
}
}
//if we have a base_url and a base_file which exists and the current baseUrl equals base_url, execute base_file
if (isset($appconf['base_url']) && file_exists($appUri . '/' . $appconf['base_file']))
{
if ($appconf['base_url'] == $page->getBaseUrl())
{
require $appUri . $appconf['base_file'];
}
}
}
//Static
if ($appconf['type'] == 'static' && isset($appconf['base_file']) && file_exists($appUri . '/' . $appconf['base_file']))
{
require $appUri . $appconf['base_file'];
}
}
2016-08-02 21:13:25 +00:00
}
}
$appconf = [];
2016-08-02 21:13:25 +00:00
}
if ($page->getResponseCode() == 404)
2016-08-02 21:13:25 +00:00
{
$page->setTitle('404');
$page->setContent(file_get_contents('content/.system/404.txt'));
2016-08-02 21:13:25 +00:00
}
2017-04-29 22:12:32 +00:00
//Build Copyright
2017-05-08 09:43:02 +00:00
$founded = date('Y', filemtime('config/config.yml'));
2016-08-02 21:13:25 +00:00
$copy = $founded;
if ($founded != date('Y'))
2016-08-02 21:13:25 +00:00
{
$copy = $founded . ' - ' . date('Y');
2016-08-02 21:13:25 +00:00
}
$page->assign('copyright', $copy);
2017-04-29 22:12:32 +00:00
//Finally render everything
http_response_code($page->getResponseCode());
$page->assign('page_title', $page->getTitle());
$page->assign($MCONF['tpl_title'], $page->getTitle() . ' | ' . $MCONF['title']);
2016-08-02 21:13:25 +00:00
$page->assign($MCONF['tpl_content'], $page->getContent());
$page->assign($MCONF['tpl_webUri'], $MCONF['web_uri']);
2017-04-29 22:12:32 +00:00
$page->assign('template', $page->getTemplate());
2016-08-02 21:13:25 +00:00
$page->display($MCONF['template']);
}
} else
2016-08-02 21:13:25 +00:00
{
2017-04-29 20:39:26 +00:00
header('Location: admin/install.php');
2016-08-02 21:13:25 +00:00
}