2016-07-22 20:00:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Vn\Web;
|
|
|
|
|
|
|
|
use Vn\Lib\Locale;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for services that sends response as HTML format.
|
2017-11-29 10:01:48 +00:00
|
|
|
*/
|
2018-05-23 10:14:20 +00:00
|
|
|
class HtmlService extends Service {
|
|
|
|
function run() {
|
2017-11-29 10:01:48 +00:00
|
|
|
$eFlag =
|
|
|
|
E_ERROR
|
|
|
|
| E_USER_ERROR;
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
set_error_handler([$this, 'errorHandler'], $eFlag);
|
|
|
|
set_exception_handler([$this, 'errorHandler']);
|
2017-11-29 10:01:48 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$this->init();
|
2016-09-23 22:47:34 +00:00
|
|
|
$db = $this->db;
|
2016-07-22 20:00:27 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (!$this->isHttps()
|
|
|
|
&& $db->getValue('SELECT https FROM config') && !_DEV_MODE) {
|
|
|
|
header("Location: https://{$this->getUri()}");
|
|
|
|
exit(0);
|
2016-07-22 20:00:27 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$this->startSession();
|
2016-07-22 20:00:27 +00:00
|
|
|
|
|
|
|
// Getting the requested page
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (!empty($_REQUEST['method']) && isHyphen($_REQUEST['method']))
|
2016-08-26 12:43:45 +00:00
|
|
|
$page = $_REQUEST['method'];
|
2016-07-22 20:00:27 +00:00
|
|
|
else
|
|
|
|
$page = 'main';
|
|
|
|
|
|
|
|
// Checking the browser version
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (!isset($_SESSION['skipBrowser']) && $page != 'update-browser') {
|
2016-07-22 20:00:27 +00:00
|
|
|
$updateBrowser = FALSE;
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (!isset($_GET['skipBrowser'])
|
2018-04-21 13:13:05 +00:00
|
|
|
&& isset($_SERVER['HTTP_USER_AGENT'])
|
2018-05-23 10:14:20 +00:00
|
|
|
&&($browser = get_browser($_SERVER['HTTP_USER_AGENT']))) {
|
|
|
|
$browserVersion =(double) $browser->version;
|
|
|
|
$minVersion = $db->getValue(
|
2016-07-22 20:00:27 +00:00
|
|
|
'SELECT version FROM browser WHERE name = #', [$browser->browser]);
|
|
|
|
$updateBrowser = $browserVersion > 0
|
2018-05-23 10:14:20 +00:00
|
|
|
&& isset($minVersion) && $browserVersion < $minVersion;
|
2016-07-22 20:00:27 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if ($updateBrowser) {
|
|
|
|
header('Location: ?method=update-browser');
|
|
|
|
exit(0);
|
2018-05-23 11:09:55 +00:00
|
|
|
} else
|
2016-07-22 20:00:27 +00:00
|
|
|
$_SESSION['skipBrowser'] = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If enabled, requests the user to choose between two web versions
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (!isset($_SESSION['skipVersionMenu'])
|
|
|
|
&& $db->getValue('SELECT testDomain FROM config')) {
|
2016-07-22 20:00:27 +00:00
|
|
|
$_SESSION['skipVersionMenu'] = TRUE;
|
2018-05-23 10:14:20 +00:00
|
|
|
header('Location: ?method=version-menu');
|
2016-07-22 20:00:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setting the version
|
|
|
|
|
2022-11-11 14:20:48 +00:00
|
|
|
$domain = explode(':', $_SERVER['HTTP_HOST'])[0];
|
|
|
|
setcookie('vnVersion', $this->getVersion()->toString(), [
|
2022-11-11 14:46:30 +00:00
|
|
|
'samesite' => 'Lax',
|
|
|
|
'domain' => $domain
|
2022-11-11 14:20:48 +00:00
|
|
|
]);
|
2016-07-22 20:00:27 +00:00
|
|
|
|
|
|
|
// Loading the requested page
|
|
|
|
|
2016-08-30 07:43:47 +00:00
|
|
|
$basePath = "pages/$page";
|
2016-07-22 20:00:27 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (file_exists($basePath)) {
|
|
|
|
Locale::addPath($basePath);
|
2016-07-22 20:00:27 +00:00
|
|
|
|
2016-10-14 10:58:35 +00:00
|
|
|
$phpFile = "./$basePath/$page.php";
|
2016-07-22 20:00:27 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (file_exists($phpFile))
|
|
|
|
require($phpFile);
|
2016-07-22 20:00:27 +00:00
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
$this->printHeader();
|
2016-09-24 14:32:31 +00:00
|
|
|
$dir = $basePath;
|
2017-12-04 18:22:58 +00:00
|
|
|
include_once __DIR__.'/html.php';
|
2018-05-23 10:14:20 +00:00
|
|
|
include("./$basePath/ui.php");
|
2018-05-23 11:09:55 +00:00
|
|
|
} else
|
2018-05-23 10:14:20 +00:00
|
|
|
header('Location: ./');
|
2016-07-22 20:00:27 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function printHeader() {
|
|
|
|
header('Content-Type: text/html; charset=UTF-8');
|
|
|
|
//header("Content-Security-Policy: default-src *; img-src *;");
|
2016-07-22 20:00:27 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function errorHandler($err) {
|
2018-03-26 16:35:02 +00:00
|
|
|
error_log("{$err->getMessage()} {$err->getTraceAsString()}");
|
2018-05-23 10:14:20 +00:00
|
|
|
$this->printHeader();
|
|
|
|
include(__DIR__.'/unavailable.html');
|
|
|
|
exit(0);
|
2017-11-29 10:01:48 +00:00
|
|
|
return FALSE;
|
2016-07-22 20:00:27 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function isMobile() {
|
2016-07-22 20:00:27 +00:00
|
|
|
$re = '/(Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone)/i';
|
2018-05-23 10:14:20 +00:00
|
|
|
return preg_match($re, $_SERVER['HTTP_USER_AGENT']);
|
2016-07-22 20:00:27 +00:00
|
|
|
}
|
|
|
|
}
|