55 lines
1.3 KiB
PHP
55 lines
1.3 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;
|
|
|
|
if (isset($wpAssets->_empty_))
|
|
$jsFiles[] = $serverPath . $wpAssets->_empty_->js[0];
|
|
if (isset($wpAssets->{''}))
|
|
$jsFiles[] = $serverPath . $wpAssets->{''}->js[0];
|
|
|
|
$jsFiles[] = $serverPath . $wpAssets->main->js;
|
|
|
|
return $jsFiles;
|
|
}
|