<?php


function out_file($cat, $count = 5, $time) {
    $out = '';
    $total = mysql_result(mysql_query("SELECT COUNT(*) FROM `downfiles` WHERE `type` != '1' AND `pathid` = '$cat' AND `status` = 1"), 0);
    $req = mysql_query("SELECT * FROM `downfiles` WHERE `type` != '1' AND `pathid` = '$cat' AND `status` = 1 ORDER BY `time` DESC LIMIT " . $count);
    if ($total > 0) {
        while ($res = mysql_fetch_array($req)) {
            $ft = functions::format($res['way']);
            switch ($ft) {
                case "mp3":
                    $imt = "mp3.png";
                break;
                
                case "3gp":
                    $imt = "video.png";
                break;
                
                case "mp4":
                    $imt = "video.png";
                break;
                

                case "zip":
                    $imt = "rar.png";
                break;

                case "jar":
                    $imt = "jar.png";
                break;

                case "gif":
                    $imt = "gif.png";
                break;

                case "jpg":
                    $imt = "jpg.png";
                break;

                case "png":
                    $imt = "png.png";
                break;
                
                default :
                    $imt = "file.gif";
                break;
            }
            
$out .= $i % 2 ? '<div class="menu">' : '<div class="menu">';
            $name = explode('||||', $res['name']);
            $out .= '<img src="' . $set['homeurl'] . '/download/img/' . $imt . '" alt="" style="margin-bottom: -3px; width: 16px;/> <a href="' . $set['homeurl'] . '/download/' . 
            name_replace($name[0]).'_' . $res['id'] . '.html">' . htmlentities($name[0], ENT_QUOTES, 'UTF-8') . '</a><hr>';
            $out .= '</div>';
            $i++;
        }
        
        $file_cache = './files/cache/download_cat_' . $cat . '.dat';        
        if (!file_exists($file_cache) || time() - filemtime($file_cache) > $time)
            file_put_contents($file_cache, $out);                
    } else 
        return FALSE;
    
    return file_get_contents($file_cache);
}