<?php
require_once(dirname(dirname(__FILE__)) . "/global.php");
clearstatcache();
$info = parse_url($_SET['net_static_host']);
define('SYN_P', substr($info['path'], 1) . '/' );

$key = "api_syn_" . $_SET['net_static_host'] . SYN_P;
if(false === ($string = cache::get($key))){
	$allow_dir = array($_SET['admin_path'] . '/images/', 'images/');
	$allow_ext = array('png', 'gif', 'jpg', 'jpeg', 'bmp', 'html', 'htm', 'css', 'js', 'xml', 'swf', 'htc', 'txt','shtml','ini');
	$data = array('status'=>200, 'map'=>array(), 'root'=>SYN_P);
	foreach($allow_dir as $dir){
		getDirFile("../" . $dir);
	}
	$string = qbase::jsonencode($data);
	cache::set($key, $string, 60);
}
echo $string;

function getDirFile($file){
	global $data, $allow_ext;
	if (is_dir($file)){
		$handle = @opendir($file);
		while (false !== ($filename = @readdir($handle))){
			if ($filename == "." || $filename == "..") continue;
			if (is_dir($file . $filename . '/')){
				getDirFile($file . $filename . '/');
			}else{
				$ext = qbase::fileext($filename);
				if(!in_array($ext, $allow_ext)) continue;
				$data['map'][] = array(
					'file'=>  substr($file . $filename, 3),
					'time'=> filemtime($file . $filename),
					'md5'=> md5_file($file . $filename)
				);
			}
		}
		@closedir($handle);
		return true;
	}else{
		return false;
	}
}
?>