2015-04-22 18:24:10 +02:00
|
|
|
<?php namespace Todaymade\Daux\Tree;
|
|
|
|
|
|
|
|
use Todaymade\Daux\Daux;
|
|
|
|
use Todaymade\Daux\DauxHelper;
|
|
|
|
|
2015-04-23 00:32:30 +02:00
|
|
|
class Builder
|
|
|
|
{
|
|
|
|
public static function build($dir, $ignore, $params, $parents = null)
|
|
|
|
{
|
2015-04-22 18:24:10 +02:00
|
|
|
if (!$dh = opendir($dir)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$node = new Directory($dir, $parents);
|
|
|
|
|
|
|
|
$new_parents = $parents;
|
|
|
|
if (is_null($new_parents)) {
|
|
|
|
$new_parents = array();
|
2015-04-23 00:32:30 +02:00
|
|
|
} else {
|
2015-04-22 18:24:10 +02:00
|
|
|
$new_parents[] = $node;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (($file = readdir($dh)) !== false) {
|
|
|
|
if ($file == '.' || $file == '..') {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-04-23 00:32:30 +02:00
|
|
|
$path = $dir . DS . $file;
|
2015-04-22 18:24:10 +02:00
|
|
|
|
2015-04-23 00:32:30 +02:00
|
|
|
if (is_dir($path) && in_array($file, $ignore['folders'])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!is_dir($path) && in_array($file, $ignore['files'])) {
|
2015-04-22 18:24:10 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$entry = null;
|
|
|
|
if (is_dir($path)) {
|
2015-04-23 00:32:30 +02:00
|
|
|
$entry = static::build($path, $ignore, $params, $new_parents);
|
2015-04-23 21:04:00 +02:00
|
|
|
} elseif (in_array(pathinfo($path, PATHINFO_EXTENSION), Daux::$VALID_MARKDOWN_EXTENSIONS)) {
|
2015-04-22 18:24:10 +02:00
|
|
|
$entry = new Content($path, $new_parents);
|
|
|
|
|
2015-04-23 00:32:30 +02:00
|
|
|
if ($params['mode'] === Daux::STATIC_MODE) {
|
|
|
|
$entry->setUri($entry->getUri() . '.html');
|
2015-04-22 18:24:10 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$entry = new Raw($path, $new_parents);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($entry instanceof Entry) {
|
2015-04-23 00:32:30 +02:00
|
|
|
$node->value[$entry->getUri()] = $entry;
|
2015-04-22 18:24:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$node->sort();
|
2015-04-23 00:32:30 +02:00
|
|
|
if (isset($node->value[$params['index_key']])) {
|
|
|
|
$node->value[$params['index_key']]->setFirstPage($node->getFirstPage());
|
|
|
|
$node->setIndexPage($node->value[$params['index_key']]);
|
|
|
|
} else {
|
|
|
|
$node->setIndexPage(false);
|
|
|
|
}
|
2015-04-22 18:24:10 +02:00
|
|
|
return $node;
|
|
|
|
}
|
|
|
|
}
|