146 lines
3.0 KiB
PHP
146 lines
3.0 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Vn\Web;
|
||
|
|
||
|
require_once (__DIR__.'/app.php');
|
||
|
require_once ('vn/lib/util.php');
|
||
|
require_once ('vn/lib/method.php');
|
||
|
|
||
|
use Vn\Lib\Locale;
|
||
|
|
||
|
/**
|
||
|
* Base class for services that sends response as HTML format.
|
||
|
**/
|
||
|
class HtmlApp extends App
|
||
|
{
|
||
|
function run ()
|
||
|
{
|
||
|
$this->init ();
|
||
|
$db = $this->getSysConn ();
|
||
|
|
||
|
if (!$this->isHttps ()
|
||
|
&& $db->getValue ('SELECT https FROM config'))
|
||
|
{
|
||
|
header ("Location: https://${_SERVER['SERVER_NAME']}${_SERVER['REQUEST_URI']}");
|
||
|
exit (0);
|
||
|
}
|
||
|
|
||
|
$this->startSession ();
|
||
|
|
||
|
// Getting the requested page
|
||
|
|
||
|
if (!empty ($_GET['page']) && isHyphen ($_GET['page']))
|
||
|
$page = $_GET['page'];
|
||
|
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'])))
|
||
|
{
|
||
|
$browserVersion = $browser->version;
|
||
|
set_type ($browserVersion, TYPE_DOUBLE);
|
||
|
|
||
|
$minVersion = $db->getValue (
|
||
|
'SELECT version FROM browser WHERE name = #', [$browser->browser]);
|
||
|
|
||
|
$updateBrowser = $browserVersion > 0
|
||
|
&& isset ($minVersion) && $browserVersion < $minVersion;
|
||
|
}
|
||
|
|
||
|
if ($updateBrowser)
|
||
|
{
|
||
|
header ('Location: ?page=update-browser');
|
||
|
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;
|
||
|
header ('Location: ?page=version-menu');
|
||
|
}
|
||
|
|
||
|
// Setting the version
|
||
|
|
||
|
setcookie ('vn_version', $this->getVersion ());
|
||
|
|
||
|
// Loading the requested page
|
||
|
|
||
|
$basePath = "{$this->methodDir}/$page";
|
||
|
|
||
|
if (file_exists ($basePath))
|
||
|
{
|
||
|
Locale::addPath ($basePath);
|
||
|
|
||
|
$phpFile = "$basePath/$page.php";
|
||
|
|
||
|
if (file_exists ($phpFile))
|
||
|
require ($phpFile);
|
||
|
|
||
|
$this->printHeader ();
|
||
|
include ("$basePath/html.php");
|
||
|
}
|
||
|
else
|
||
|
header ('Location: ./');
|
||
|
}
|
||
|
|
||
|
function printHeader ()
|
||
|
{
|
||
|
header ('Content-Type: text/html; charset=UTF-8');
|
||
|
}
|
||
|
|
||
|
function globalErrorHandler ()
|
||
|
{
|
||
|
$this->printHeader ();
|
||
|
include (__DIR__.'/unavailable.html');
|
||
|
exit (0);
|
||
|
}
|
||
|
|
||
|
function getUrl ($fileName)
|
||
|
{
|
||
|
return $fileName .'?'. $this->getVersion ();
|
||
|
}
|
||
|
|
||
|
function includeJs ($fileName)
|
||
|
{
|
||
|
echo '<script type="text/javascript" src="'. $this->getUrl ($fileName) .'"></script>'."\n\t\t";
|
||
|
}
|
||
|
|
||
|
function includeLib ($libName)
|
||
|
{
|
||
|
$args = func_get_args ();
|
||
|
|
||
|
$localeJs = 'locale/'. Locale::get () .'/js/'. $libName .'.js';
|
||
|
|
||
|
if (file_exists ($localeJs))
|
||
|
$this->includeJs ($localeJs);
|
||
|
|
||
|
for ($i = 1; $i < count ($args); $i++)
|
||
|
$this->includeJs ("js/$libName/${args[$i]}.js");
|
||
|
}
|
||
|
|
||
|
function includeCss ($fileName)
|
||
|
{
|
||
|
echo '<link rel="stylesheet" type="text/css" href="'. $this->getUrl ($fileName) .'"/>'."\n\t\t";
|
||
|
}
|
||
|
|
||
|
function isMobile ()
|
||
|
{
|
||
|
$re = '/(Android|webOS|iPhone|iPad|iPod|BlackBerry|Windows Phone)/i';
|
||
|
return preg_match ($re, $_SERVER['HTTP_USER_AGENT']);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
?>
|