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