hedera-web/web/html.php

61 lines
1.5 KiB
PHP
Raw Normal View History

<?php
$lang = isset($_SESSION['lang']) ? $_SESSION['lang'] : 'en';
$version = $this->getVersion();
2018-05-23 10:14:20 +00:00
function getUrl($fileName) {
2018-04-21 13:13:05 +00:00
global $version;
2018-05-23 10:14:20 +00:00
if (file_exists($fileName))
$fileVersion = strftime('%G%m%d%H%M%S', filemtime($fileName));
else
$fileVersion = $version;
return "$fileName?$fileVersion";
}
2018-05-23 10:14:20 +00:00
function js($fileName) {
return '<script type="text/javascript" src="'. getUrl("$fileName.js") .'"></script>'."\n";
}
2018-05-23 10:14:20 +00:00
function css($fileName) {
return '<link rel="stylesheet" type="text/css" href="'. getUrl("$fileName.css") .'"/>'."\n";
}
2018-05-23 10:14:20 +00:00
function getWebpackAssets() {
$wpConfig = json_decode(file_get_contents('webpack.config.json'));
$buildDir = $wpConfig->buildDir;
2019-02-05 13:11:40 +00:00
$serverPath = '';
2019-02-05 13:11:40 +00:00
if (_DEV_MODE) {
$devServerPort = $wpConfig->devServerPort;
$host = $_SERVER['SERVER_NAME'];
2022-05-21 21:31:56 +00:00
$serverPath = "http://$host:$devServerPort";
}
2019-02-05 13:11:40 +00:00
$wpAssets = json_decode(file_get_contents("$buildDir/webpack-assets.json"));
$jsFiles = [];
2019-02-05 13:11:40 +00:00
foreach ($wpAssets as $name => $asset)
2022-05-21 21:31:56 +00:00
if (!empty($name)
&& $name != '_empty_'
&& $name != 'main'
&& property_exists($asset, 'js'))
2019-02-05 13:11:40 +00:00
$jsFiles[] = $serverPath . $asset->js;
2022-11-29 18:13:32 +00:00
function addAssets($serverPath, &$jsFiles, $assets) {
2022-11-18 00:01:05 +00:00
foreach ($assets->js as $asset)
if (preg_match('/^chunk\./', basename($asset)) === 0)
2022-11-18 00:01:05 +00:00
$jsFiles[] = $serverPath.$asset;
}
2022-05-26 08:34:20 +00:00
if (isset($wpAssets->_empty_))
2022-11-29 18:13:32 +00:00
addAssets($serverPath, $jsFiles, $wpAssets->_empty_);
2022-05-26 08:34:20 +00:00
if (isset($wpAssets->{''}))
2022-11-29 18:13:32 +00:00
addAssets($serverPath, $jsFiles, $wpAssets->{''});
2022-05-26 08:34:20 +00:00
2022-05-21 21:31:56 +00:00
$jsFiles[] = $serverPath . $wpAssets->main->js;
return $jsFiles;
}