add get_filever()

This commit is contained in:
maxpozdeev 2025-04-08 00:03:30 +03:00
parent d34378032f
commit 0c451ee8ee
2 changed files with 25 additions and 6 deletions

View file

@ -129,6 +129,17 @@ abstract class MTTExtension
return $url;
}
public static function getFileVer(string $filename): string
{
return (string)get_filever('ext', $filename, static::bundleId);
}
public static function getFileUri(string $filename, bool $versioned = true): string
{
$version = ($versioned) ? '?v='. htmlspecialchars(static::getFileVer($filename)) : '';
return get_mttinfo('mtt_uri'). htmlspecialchars('ext/'. static::bundleId. '/'. $filename) . $version;
}
}
interface MTTHttpApiExtender

View file

@ -477,10 +477,10 @@ function loadExtensions()
}
}
function filever(string $dir, string $filename)
function get_filever(string $dir, string $filename, ?string $ext = null)
{
if (!MTT_DEBUG) {
return mttinfo('version');
return get_mttinfo('version');
}
$prefix = get_mttinfo('version'). '-'. time();
$path = null;
@ -490,16 +490,24 @@ function filever(string $dir, string $filename)
else if ($dir == 'theme') {
$path = MTTPATH. 'content/'. MTT_THEME. '/';
}
else if ($dir == 'ext') {
$path = MTT_EXT. $ext. '/';
}
else {
return print($prefix. '-unknown');
return $prefix. '-unknown';
}
$fullPath = $path. $filename;
if (!file_exists($fullPath)) {
return print($prefix. '-not-found');
return $prefix. '-not-found';
}
$mtime = filemtime($fullPath);
if ($mtime === false) {
return print($prefix. '-no-access');
return $prefix. '-no-access';
}
return print($mtime);
return $mtime;
}
function filever(string $dir, string $filename)
{
print get_filever($dir, $filename);
}