function autoinclude($path = __DIR__, $recursive = false)
{
if (!file_exists($path)) {
js_console('[FAIL] not exists '.$path);
return false;
}
if (!is_dir($path)) {
include $path;
js_console('[OKAY] included '.$path);
return true;
}
$files = scandir($path);
foreach ($files as $name) {
if ($name === '.' || $name === '..') {
continue;
}
$fullpath = (substr($path, -1) === '/' ? $path : $path . '/') . $name;
if (!file_exists($fullpath)) {
js_console('[FAIL] not exists '.$fullpath);
} elseif ($recursive && is_dir($fullpath)) {
autoinclude($fullpath, true);
} else {
include $fullpath;
js_console('[OKAY] included '.$fullpath);
}
}
return true;
}