2017-11-29 10:01:48 +00:00
|
|
|
<?php
|
|
|
|
|
2017-12-05 11:49:05 +00:00
|
|
|
$lang = isset($_SESSION['lang']) ? $_SESSION['lang'] : 'en';
|
2017-12-04 18:22:58 +00:00
|
|
|
$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));
|
2017-11-29 10:01:48 +00:00
|
|
|
else
|
2017-12-05 11:49:05 +00:00
|
|
|
$fileVersion = $version;
|
2017-11-29 10:01:48 +00:00
|
|
|
|
2017-12-05 11:49:05 +00:00
|
|
|
return "$fileName?$fileVersion";
|
2017-11-29 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function js($fileName) {
|
|
|
|
return '<script type="text/javascript" src="'. getUrl("$fileName.js") .'"></script>'."\n";
|
2017-11-29 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function css($fileName) {
|
|
|
|
return '<link rel="stylesheet" type="text/css" href="'. getUrl("$fileName.css") .'"/>'."\n";
|
2017-11-29 10:01:48 +00:00
|
|
|
}
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
function getWebpackAssets() {
|
|
|
|
$wpConfig = json_decode(file_get_contents('webpack.config.json'));
|
2017-11-29 10:01:48 +00:00
|
|
|
$buildDir = $wpConfig->buildDir;
|
|
|
|
$devServerPort = $wpConfig->devServerPort;
|
|
|
|
|
|
|
|
$host = $_SERVER['SERVER_NAME'];
|
|
|
|
$assets = new stdClass();
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
if (!_DEV_MODE) {
|
|
|
|
$wpAssets = json_decode(file_get_contents("$buildDir/webpack-assets.json"));
|
2017-11-29 10:01:48 +00:00
|
|
|
|
|
|
|
$manifestJs = $wpAssets->manifest->js;
|
|
|
|
$mainJs = $wpAssets->main->js;
|
2018-05-23 10:14:20 +00:00
|
|
|
unset($wpAssets->manifest);
|
|
|
|
unset($wpAssets->main);
|
2017-11-29 10:01:48 +00:00
|
|
|
|
2018-06-06 11:08:17 +00:00
|
|
|
foreach ($wpAssets as $name => $asset)
|
2018-05-23 10:14:20 +00:00
|
|
|
if (property_exists($asset, 'js'))
|
2017-11-29 10:01:48 +00:00
|
|
|
$assets->$name = $asset->js;
|
2018-05-23 11:09:55 +00:00
|
|
|
} else {
|
2017-11-29 10:01:48 +00:00
|
|
|
$devServerPath = "http://$host:$devServerPort/$buildDir";
|
|
|
|
$manifestJs = "$devServerPath/manifest.js";
|
|
|
|
$mainJs = "$devServerPath/main.js";
|
|
|
|
|
2018-05-23 10:14:20 +00:00
|
|
|
unset($wpConfig->entry->main);
|
2017-11-29 10:01:48 +00:00
|
|
|
|
2018-06-06 11:08:17 +00:00
|
|
|
foreach ($wpConfig->entry as $asset => $files)
|
2017-11-29 10:01:48 +00:00
|
|
|
$assets->$asset = "$devServerPath/$asset.js";
|
|
|
|
}
|
|
|
|
|
|
|
|
$jsFiles = [];
|
|
|
|
$jsFiles[] = $manifestJs;
|
|
|
|
|
2018-06-06 11:08:17 +00:00
|
|
|
foreach ($assets as $jsFile)
|
2017-11-29 10:01:48 +00:00
|
|
|
$jsFiles[] = $jsFile;
|
|
|
|
|
|
|
|
$jsFiles[] = $mainJs;
|
|
|
|
|
|
|
|
return $jsFiles;
|
|
|
|
}
|