hedera-web/web/html.php

61 lines
1.5 KiB
PHP

<?php
$lang = isset($_SESSION['lang']) ? $_SESSION['lang'] : 'en';
$version = $this->getVersion();
function getUrl($fileName) {
global $version;
if (file_exists($fileName))
$fileVersion = strftime('%G%m%d%H%M%S', filemtime($fileName));
else
$fileVersion = $version;
return "$fileName?$fileVersion";
}
function js($fileName) {
return '<script type="text/javascript" src="'. getUrl("$fileName.js") .'"></script>'."\n";
}
function css($fileName) {
return '<link rel="stylesheet" type="text/css" href="'. getUrl("$fileName.css") .'"/>'."\n";
}
function getWebpackAssets() {
$wpConfig = json_decode(file_get_contents('webpack.config.json'));
$buildDir = $wpConfig->buildDir;
$serverPath = '';
if (_DEV_MODE) {
$devServerPort = $wpConfig->devServerPort;
$host = $_SERVER['SERVER_NAME'];
$serverPath = "http://$host:$devServerPort";
}
$wpAssets = json_decode(file_get_contents("$buildDir/webpack-assets.json"));
$jsFiles = [];
foreach ($wpAssets as $name => $asset)
if (!empty($name)
&& $name != '_empty_'
&& $name != 'main'
&& property_exists($asset, 'js'))
$jsFiles[] = $serverPath . $asset->js;
function addAssets(&$jsFiles, $assets) {
foreach ($assets->js as $asset)
if (preg_match('/^chunk\./', basename($asset)) === 0)
$jsFiles[] = $serverPath.$asset;
}
if (isset($wpAssets->_empty_))
addAssets($jsFiles, $wpAssets->_empty_);
if (isset($wpAssets->{''}))
addAssets($jsFiles, $wpAssets->{''});
$jsFiles[] = $serverPath . $wpAssets->main->js;
return $jsFiles;
}