function print_link($version, $folder, $files, $changes)
{
echo "<a href=\"$folder/$files[$version]\">$version</a> ";
if (array_key_exists($version, $changes))
echo ":: <a href=\"$folder/$changes[$version]\">changes</a> ";
echo "<small>";
echo date("/d.m.Y H:i/", filemtime("$folder/$files[$version]"));
echo "</small><br>\n";
}
function extract_version($str)
{
$version_mask = "/\d+\.\d+\.\d+\.\d+/";
$version = "(no-version-found)";
$regmatch = array();
if (preg_match($version_mask, $str, $regmatch)) $version = $regmatch[0];
return $version;
}
function print_dl($title, $folder, $mask_files, $mask_changes)
{
$files = array();
$changes = array();
foreach(scandir("$folder") as $file)
{
if ($file == "." || $file == ".." || !is_file("$folder/$file")) continue;
if (preg_match($mask_files, $file)) $files[extract_version($file)] = $file;
// if (preg_match($mask_changes, $file)) $changes[extract_version($file)] = $file;
}
if (!empty($files))
{
echo "<h2>$title</h2><p>\n";
$versions_backup = array_keys($files);
natsort($versions_backup);
$versions = array_reverse($versions_backup, true);
foreach($versions as $version)
{
echo "<a href=\"$folder/$files[$version]\">$version</a> ";
if (array_key_exists($version, $changes))
echo ":: <a href=\"$folder/$changes[$version]\">changes</a> ";
echo "<small>";
echo date("/d.m.Y H:i/", filemtime("$folder/$files[$version]"));
echo "</small><br>\n";
/*if ($_SERVER["QUERY_STRING"] != "all") break;*/
}
echo "</p>\n\n";
}
}
print_dl("Анализ 3.1", ".", "/analysis-3\.1\.\d+\.\d+\.exe/", "");