<?php
setlocale(LC_ALL, array(
    'it_IT.UTF-8',
    'it_IT@euro',
    'it_IT',
    'italian'
));
// Free PHP File Directory Listing Script - Version 1.4 - HalGatewood.com
// Edited for AVCP/ANAC XML compatiblity by MARCO MILESI - WPGOV - wpgov.it

?>
<!DOCTYPE html>
<html>

<head>
    <title>ANAC XML</title>
<?php 
$urlcompleto = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$url         = substr_replace($urlcompleto, "", -5); 
?>
    <style>
        body { font-family: 'Open Sans', sans-serif; padding: 0; margin: 0; background-color: #f5f5f5; }
        .wrap { width: 700px; margin: 0 auto 0 auto; padding: 25px;}
        h1 { margin: 0 0 5px 0; font-size:120%; font-weight:normal; color: #666; }
        h2 { margin: 0; font-size: 1.2em; }
        a { color: #399ae5; text-decoration: none; } a:hover { color: #206ba4; text-decoration: underline; }
        .note { padding:  0 5px 25px 0; font-size:80%; color: #666; line-height: 18px; }
        .media_block { clear: both;  min-height: 50px; padding: 10px 15px; border-top: solid 1px #ECE9E9; }
        .media_block_filebox { float:left; width: 30%; padding: 20px 0; min-height: 50px;}
        .media_block_date { margin-top: 4px; font-size: 70%; color: #666; }
        .jpg, .jpeg, .gif, .png { background-position: -50px 0 !important; }
        .pdf { background-position: -100px 0 !important; }
        .txt, .rtf { background-position: -150px 0 !important; }
        .xls, .xlsx { background-position: -200px 0 !important; }
        .ppt, .pptx { background-position: -250px 0 !important; }
        .doc, .docx { background-position: -300px 0 !important; }
        .zip, .rar, .tar, .gzip { background-position: -350px 0 !important; }
        .swf { background-position: -400px 0 !important; }
        .fla { background-position: -450px 0 !important; }
        .mp3 { background-position: -500px 0 !important; }
        .wav { background-position: -550px 0 !important; }
        .mp4 { background-position: -600px 0 !important; }
        .mov, .aiff, .m2v, .avi, .pict, .qif { background-position: -650px 0 !important; }
        .wmv, .avi, .mpg { background-position: -700px 0 !important; }
        .flv, .f2v { background-position: -750px 0 !important; }
        .psd { background-position: -800px 0 !important; }
        .ai { background-position: -850px 0 !important; }
        .html, .xhtml, .dhtml, .php, .asp, .css, .js, .inc { background-position: -900px 0 !important; }
        .dir { background-position: -950px 0 !important; }
        div.clear {
            clear:both;
        }
    </style>
</head>
<body>
<div style="padding:20px;box-shadow: 0 1px 3px rgba(0,0,0,0.2);background-color: #fff;">
    <div style="float:right;"><small><a href="<?php echo $url; ?>" title="Torna al sito">Torna al Sito</a></small></div>
    <h1>ANAC XML</h1>
</div>
    <div class="wrap">
<?php

function cleanTitle($title)
{
    $title = str_replace("-", " ", $title);
    $title = str_replace("_", " ", $title);
    return ucwords($title);
}

function getFileExt($filename)
{
    return substr(strrchr($filename, '.'), 1);
}

function format_size($file)
{
    $bytes = filesize($file);
    if ($bytes < 1024)
        return '<strong>' . $bytes . '</strong> byte';
    elseif ($bytes < 1048576)
        return '<strong>' . round($bytes / 1024, 2) . '</strong> KB';
    elseif ($bytes < 1073741824)
        return '<strong>' . round($bytes / 1048576, 2) . '</strong> MB';
    elseif ($bytes < 1099511627776)
        return '<strong>' . round($bytes / 1073741824, 2) . '</strong> GB';
    else
        return '<strong>' . round($bytes / 1099511627776, 2) . '</strong> TB';
}

// GET FILES AND PUT INTO AN ARRAY
$files = array();
$handle = opendir(dirname(__FILE__));
while (false !== ($file = readdir($handle)))  
    if (!is_dir($file) && getFileExt($file) == "xml") 
        $files[] = $file;
closedir($handle);
natcasesort($files);

foreach ($files as $file) 
{
    echo "<div class=\"media_block_filebox\">";
    echo "    <a href=\"$file\"><img style=\"float: left;\" src=\"" . $url . "wp-content/plugins/avcp/includes/xmlicon.png\"></a>";
    echo "        <div class=\"media_block_file\"><h2><a href=\"$file\">" . basename($file, ".xml") ."</a></h2></div>\n";
    echo "        <div class=\"media_block_date\">" . format_size($file) . "<br>" . ucwords(strftime("%d %B %Y", filemtime($file))) . "</div>\n";
    echo "</div>";
}
echo "<div class='clear'></div>"; 
?>
    </div>

<div style="text-align:center;padding:10px;font-size: 0.8em;">
    Software <a href="https://wordpress.org/plugins/avcp/" title="ANAC XML Bandi di Gara">ANAC XML Bandi di Gara</a> su piattaforma WordPress
    <br>Sviluppato da <a href="https://www.marcomilesi.com" title="Marco Milesi">Marco Milesi</a> nell'ambito del progetto <a href="https://www.wpgov.it" title="WPGov.it">WPGov.it</a>
</div>
</body>
</html>