forked from joomla/joomla-cms
/
indexmaker.php
34 lines (27 loc) · 896 Bytes
/
indexmaker.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/php
<?php
if (php_sapi_name() != "cli")
{
echo "Error: phptidy has to be run on command line with CLI SAPI\n";
exit(1);
}
function getDirectory($path = '.', $level = 0)
{
$iterator = new RecursiveDirectoryIterator($path, FilesystemIterator::KEY_AS_PATHNAME | FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::SKIP_DOTS);
$flattened = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
foreach ($flattened as $path => $dir)
{
if (!$dir->isDir())
{
continue;
}
// Add an index.html if neither an index.html nor an index.php exist
if (!(file_exists($path . '/index.html') || file_exists($path . '/index.php')))
{
file_put_contents($path . '/index.html', '<!DOCTYPE html><title></title>' . "\n");
}
}
}
$work = $_SERVER['argv'][1];
echo "Working on directory " . $work . "\n";
getDirectory($_SERVER['argv'][1]);