<?php

function k_files($dir = null) {
    global $set;
    $db = new db;
    if ($dir != null) {
        $path = (function_exists('iconv')) ? iconv('windows-1251', 'utf-8', $dir) : $dir;
        $path = '/' . preg_replace('#^/+|/+$#i', null, $path) . '/';
        $q = $db->super_query("SELECT COUNT(*) as count FROM `loads_list` WHERE `path` LIKE '" . $db->safesql($path) . "%'");
        $all = $q['count'];
        $q = $db->super_query("SELECT COUNT(*) as count FROM `loads_list` WHERE `path` LIKE '" . $db->safesql($path) . "%' AND `time` > '" . (time() - 60 * 60 * $set['loads_new_file_hour']) . "'");
        $new = $q['count'];
        unset($q);
    } else {
        $q = $db->super_query("SELECT COUNT(*) as count FROM `loads_list`");
        $all = $q['count'];
        $q = $db->super_query("SELECT COUNT(*) as count FROM `loads_list` WHERE `time` > '" . (time() - 60 * 60 * $set['loads_new_file_hour']) . "'");
        $new = $q['count'];
        unset($q);
    }

    return ($new == 0) ? $all : '' . $all . ' +' . $new . '';
}

?>