Recursively generate the documentation

@param Directory $tree
@param string $output_dir
@param \Todaymade\Daux\Config $params
@param OutputInterface $output
@param int $width
@param bool $index_pages
@param string $base_url
@throws \Exception
491364
private function generateRecursive(Directory $tree, $output_dir, $params, $output, $width, $index_pages, $base_url = '')
    {
        DauxHelper::rebaseConfiguration($params, $base_url);

        if ($base_url !== '' && empty($params['entry_page'])) {
            $params['entry_page'] = $tree->getFirstPage();
        }

        foreach ($tree->getEntries() as $key => $node) {
            if ($node instanceof Directory) {
                $new_output_dir = $output_dir . DIRECTORY_SEPARATOR . $key;
                mkdir($new_output_dir);
                $this->generateRecursive($node, $new_output_dir, $params, $output, $width, $index_pages, '../' . $base_url);

                // Rebase configuration again as $params is a shared object
                DauxHelper::rebaseConfiguration($params, $base_url);
            } else {
                $this->runAction(
                    '- ' . $node->getUrl(),
                    $width,
                    function() use ($node, $output_dir, $key, $params, $index_pages) {
                        if ($node instanceof Raw) {
                            copy($node->getPath(), $output_dir . DIRECTORY_SEPARATOR . $key);

                            return;
                        }

                        $this->daux->tree->setActiveNode($node);

                        $generated = $this->generateOne($node, $params);
                        file_put_contents($output_dir . DIRECTORY_SEPARATOR . $key, $generated->getContent());
                        if ($index_pages) {
                            $this->indexed_pages[] = [
                                'title' => $node->getTitle(),
                                'text' => $this->sanitize($generated->getPureContent()),
                                'tags' =>  '',
                                'url' => $node->getUrl(),
                            ];
                        }
                    }
                );
            }
        }
    }
1185689
private function generateIndexView($dir)
    {
        $this->renderFile('views/index.html.twig', $dir.'/index.html.twig', array(
            'dir' => $this->skeletonDir,
            'document' => $this->document,
            'fields' => $this->metadata->fieldMappings,
            'actions' => $this->actions,
            'record_actions' => $this->getRecordActions(),
            'route_prefix' => $this->routePrefix,
            'route_name_prefix' => $this->routeNamePrefix,
        ));
    }
118619
private void initOutputDir(File outputDir) {

        if (!outputDir.exists()) {
            if (!outputDir.mkdirs()) {
                throw new IllegalArgumentException("Output Directory "+outputDir+" could not be created");
            }
        }
        if (!outputDir.isDirectory() || (!outputDir.canWrite())) {
            throw new IllegalArgumentException("Output Directory "+outputDir+" is not a directory or cannot be written to.");
        }
    }
1050008
public function askProjectDir(
        InputInterface $input,
        OutputInterface $output,
        $dir = null,
        SymfonyStyle $style = null
    ) {
        $question = $this->getSimpleQuestion()
            ->getQuestion('Please set your root project directory.', $dir);
        $question->setValidator(
            $this->getValidator()
        );

        $style = $style ?: new SymfonyStyle($input, $output);
        $dir   = $style->askQuestion($question);

        return rtrim($dir, '\\/');
    }
83281
public function editBlockConfiguration(Tree $tree, int $block_id): void
    {
        $num             = $this->getBlockSetting($block_id, 'num', '10');
        $count_placement = $this->getBlockSetting($block_id, 'count_placement', 'before');

        $options = [
            /* I18N: An option in a list-box */
            'before' => I18N::translate('before'),
            /* I18N: An option in a list-box */
            'after'  => I18N::translate('after'),
        ];

        echo view('modules/top10_pageviews/config', [
            'count_placement' => $count_placement,
            'num'             => $num,
            'options'         => $options,
        ]);
    }
1134146
public final void setDatabaseOutputDir(String databaseOutputDir) {
        if (DEBUG) {
            System.out.println("Setting database output directory: " + databaseOutputDir);
        }
        this.databaseOutputDir = databaseOutputDir;
    }
1009688
protected function doRawList($dir, $recursive = false)
    {
        $connection = $this->connection;

        return $this->retry(function () use ($connection, $dir, $recursive) {
            $res = @ftp_rawlist($connection, $dir, $recursive);

            if (false === $res) {
                throw new \RuntimeException("Rawlist failed: ".$dir);
            }

            $items = array();

            foreach ($res as $child) {
                $chunks = preg_split("/\s+/", $child);
                list($item['rights'], $item['number'], $item['user'], $item['group'], $item['size'], $item['month'], $item['day'], $item['time']) = $chunks;
                $item['type'] = $chunks[0]{0}
                === 'd' ? 'directory' : 'file';
                array_splice($chunks, 0, 8);
                $item['name'] = implode(" ", $chunks);
                $item['pathname'] = \rtrim($dir, '/').'/'.$item['name'];
                $items[] = $item;
            }

            return $items;
        });
    }
761145
public void dumpTo(AreaTree tree, PrintWriter out)
    {
        if (produceHeader)
        {
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>" + tree.getRoot().getPage().getTitle() + "</title>");
            out.println("<meta charset=\"utf-8\">");
            out.println("<meta name=\"generator\" content=\"FITLayout - area tree dump\">");
            out.println("</head>");
            out.println("<body>");
        }
        recursiveDumpArea(tree.getRoot(), 1, out);
        if (produceHeader)
        {
            out.println("</body>");
            out.println("</html>");
        }
    }
1191677
public function calendarUrl(string $date_format, Tree $tree): string
    {
        if ($this->day !== 0 && strpbrk($date_format, 'dDj')) {
            // If the format includes a day, and the date also includes a day, then use the day view
            $view = 'day';
        } elseif ($this->month !== 0 && strpbrk($date_format, 'FMmn')) {
            // If the format includes a month, and the date also includes a month, then use the month view
            $view = 'month';
        } else {
            // Use the year view
            $view = 'year';
        }

        return route('calendar', [
            'cal'   => $this->calendar->gedcomCalendarEscape(),
            'year'  => $this->formatGedcomYear(),
            'month' => $this->formatGedcomMonth(),
            'day'   => $this->formatGedcomDay(),
            'view'  => $view,
            'ged'   => $tree->name(),
        ]);
    }
112539
private void generateJMeterDirectoryTree() {
        File workingDirectory = new File(jmeterDirectory, "bin");
        workingDirectory.mkdirs();
        JMeterConfigurationHolder.getInstance().setWorkingDirectory(workingDirectory);
        customPropertiesDirectory = new File(jmeterDirectory, "custom_properties");
        customPropertiesDirectory.mkdirs();
        libDirectory = new File(jmeterDirectory, "lib");
        libExtDirectory = new File(libDirectory, "ext");
        libExtDirectory.mkdirs();
        libJUnitDirectory = new File(libDirectory, "junit");
        libJUnitDirectory.mkdirs();
        testFilesBuildDirectory.mkdirs();
        resultsDirectory.mkdirs();
        if (generateReports) {
            reportDirectory.mkdirs();
        }
        logsDirectory.mkdirs();
    }
22875
public function editBlockConfiguration(Tree $tree, int $block_id): void
    {
        $show_other      = $this->getBlockSetting($block_id, 'show_other', self::DEFAULT_SHOW_OTHER);
        $show_unassigned = $this->getBlockSetting($block_id, 'show_unassigned', self::DEFAULT_SHOW_UNASSIGNED);
        $show_future     = $this->getBlockSetting($block_id, 'show_future', self::DEFAULT_SHOW_FUTURE);

        echo view('modules/todo/config', [
            'show_future'     => $show_future,
            'show_other'      => $show_other,
            'show_unassigned' => $show_unassigned,
        ]);
    }
93710
private function doDump(OutputInterface $output)
    {
        if (!is_dir($dir = dirname($this->targetPath))) {
            $output->writeln('<info>[dir+]</info>  ' . $dir);
            if (false === @mkdir($dir, 0777, true)) {
                throw new \RuntimeException('Unable to create directory ' . $dir);
            }
        }

        $output->writeln('<info>[file+]</info> ' . $this->targetPath);

        $templates = [
            'js' => "this.%s = route('%s');\n",
            'es6' => "\t\t\t'%s': '%s',\n"
        ];

        $type = $this->parameterBag->get('netbull_core.js_type');

        $routes = '';
        foreach ($this->extractor->getRoutes() as $name => $route) {
            preg_match_all("/{(.*?)}/i", $route->getPath(), $routeParams);

            if (0 < count($routeParams)) {
                $parameters = array_flip($routeParams[1]);
                $normalizedRoute = preg_replace_callback("/{(.*?)}/i", function($m) use($parameters) {
                    return ':' . ($parameters[$m[1]] + 1);
                }, $route->getPath());

                $routes .= sprintf($templates[$type], $name, $normalizedRoute);
            }
        }

        $source = file_get_contents(__DIR__ . '/../Resources/js/router.' . $type . '.js');
        $content = str_replace('//<ROUTES>', $routes, $source);

        if (false === @file_put_contents($this->targetPath, $content)) {
            throw new \RuntimeException('Unable to write file ' . $this->targetPath);
        }
    }
325344
public function createSourceAction(ServerRequestInterface $request, Tree $tree): ResponseInterface
    {
        $title               = $request->get('source-title', '');
        $abbreviation        = $request->get('source-abbreviation', '');
        $author              = $request->get('source-author', '');
        $publication         = $request->get('source-publication', '');
        $repository          = $request->get('source-repository', '');
        $call_number         = $request->get('source-call-number', '');
        $text                = $request->get('source-text', '');
        $privacy_restriction = $request->get('privacy-restriction', '');
        $edit_restriction    = $request->get('edit-restriction', '');

        // Fix whitespace
        $title        = trim(preg_replace('/\s+/', ' ', $title));
        $abbreviation = trim(preg_replace('/\s+/', ' ', $abbreviation));
        $author       = trim(preg_replace('/\s+/', ' ', $author));
        $publication  = trim(preg_replace('/\s+/', ' ', $publication));
        $repository   = trim(preg_replace('/\s+/', ' ', $repository));
        $call_number  = trim(preg_replace('/\s+/', ' ', $call_number));

        // Convert line endings to GEDDCOM continuations
        $text = str_replace([
            "\r\n",
            "\r",
            "\n",
        ], "\n1 CONT ", $text);

        $gedcom = "0 @@ SOUR\n\n1 TITL " . $title;

        if ($abbreviation !== '') {
            $gedcom .= "\n1 ABBR " . $abbreviation;
        }

        if ($author !== '') {
            $gedcom .= "\n1 AUTH " . $author;
        }

        if ($publication !== '') {
            $gedcom .= "\n1 PUBL " . $publication;
        }

        if ($text !== '') {
            $gedcom .= "\n1 TEXT " . $text;
        }

        if ($repository !== '') {
            $gedcom .= "\n1 REPO @" . $repository . '@';

            if ($call_number !== '') {
                $gedcom .= "\n2 CALN " . $call_number;
            }
        }

        if (in_array($privacy_restriction, [
            'none',
            'privacy',
            'confidential',
        ])) {
            $gedcom .= "\n1 RESN " . $privacy_restriction;
        }

        if (in_array($edit_restriction, ['locked'])) {
            $gedcom .= "\n1 RESN " . $edit_restriction;
        }

        $record = $tree->createRecord($gedcom);

        // id and text are for select2 / autocomplete
        // html is for interactive modals
        return response([
            'id'   => $record->xref(),
            'text' => view('selects/source', [
                'source' => $record,
            ]),
            'html' => view('modals/record-created', [
                'title' => I18N::translate('The source has been created'),
                'name'  => $record->fullName(),
                'url'   => $record->url(),
            ]),
        ]);
    }
264976
protected static function _export($path, $tree, $coverage)
    {
        $result = [
            'TN:',
            'SF:' . $path
        ];

        $statements = [];

        $fnda = [];
        $fnf = 0;

        $fnCurr = null;

        foreach ($tree->lines['content'] as $num => $content) {
            $coverable = null;
            foreach ($content['nodes'] as $node) {
                if ($node->type === 'function' && $node->lines['start'] === $num) {
                    if ($node->isMethod || !$node->isClosure) {
                        $result[] = 'FN:' . ($num + 1) . ',' . $node->name;
                        $fnda[$node->name] = 0;
                        $fnf++;
                        $fnCurr = $node;
                    }
                }
                if ($node->coverable && $node->lines['stop'] === $num) {
                    $coverable = $node;
                    break;
                }
            }
            if (!$coverable) {
                continue;
            }
            $value = isset($coverage[$num]) ? $coverage[$num] : 0;

            $statements[] = 'DA:' . ($num + 1) . ',' . $value;

            if ($fnCurr) {
                if ($fnCurr->lines['stop'] >= $coverable->lines['stop']) {
                    $fnda[$fnCurr->name] = max($fnda[$fnCurr->name], $value);
                }
            }
        }
        foreach ($fnda as $name => $value) {
            $result[] = 'FNDA:' . $value . ',' . $name;
        }
        $result[] = 'FNF:' . $fnf;
        $result[] = 'FNH:' . count(array_filter($fnda));
        $result = array_merge($result, $statements);
        $result[] = 'LF:' . count($coverage);
        $result[] = 'LH:' . count(array_filter($coverage));
        $result[] = 'end_of_record';
        return join("\n", $result) . "\n";
    }
467529
protected function generateIndexView($dir)
    {
        $parts = explode('\\', $this->entity);
        $entityClass = array_pop($parts);

        $this->renderFile(
            'views/index.html.twig',
            $dir.'/index.html.twig',
            array(
                'dir' => $this->skeletonDir,
                'entity' => $this->entity,
                'fields' => $this->metadata->fieldMappings,
                'actions' => $this->actions,
                'record_actions' => $this->getRecordActions(),
                'route_prefix' => $this->routePrefix,
                'route_name_prefix' => $this->routeNamePrefix,
                'bundle' => $this->bundle->getName(),
                'entity_class' => $entityClass,
            )
        );
    }
922217
public function actionTree()
    {
        foreach (CmsTree::find()->each(10) as $cmsTree) {
            $this->stdout('Tree id: ' . $cmsTree->id . " - ");
            
            $redirect = CmsTreeRedirect::find()->where([
                'cms_tree_id' => $cmsTree->id
            ])->andWhere(['slug' => $cmsTree->code])->one();
            
            if ($redirect) {
                $this->stdout("exist \n", Console::FG_YELLOW);
            } else {
                $redirect = new CmsTreeRedirect();
                $redirect->cms_tree_id = $cmsTree->id;
                $redirect->slug = $cmsTree->code;

                if (!$redirect->save()) {
                    $this->stdout("Not saved redirect: {$redirect->slug} for id={$cmsTree->id}. " . print_r($redirect->errors, true) . "\n", Console::FG_RED);
                } else {
                    $this->stdout("created \n", Console::FG_GREEN);
                }
            }
        }
    }
1328605
protected function htmllize_tree($tree, $dir) {
        global $CFG;
        $yuiconfig = array();
        $yuiconfig['type'] = 'html';

        if (empty($dir['subdirs']) and empty($dir['files'])) {
            return '';
        }
        $result = '<ul>';
        foreach ($dir['subdirs'] as $subdir) {
            $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
        }
        foreach ($dir['files'] as $file) {
            $url = file_encode_url("$CFG->wwwroot/pluginfile.php", '/'.$tree->context->id.'/mod_wiki/attachments/' . $tree->subwiki->id . '/'. $file->get_filepath() . $file->get_filename(), true);
            $filename = $file->get_filename();
            $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.html_writer::link($url, $filename).'</div></li>';
        }
        $result .= '</ul>';

        return $result;
    }